Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-storage
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Antoine R. Dumont
swh-storage
Commits
92de2589
Commit
92de2589
authored
1 year ago
by
vlorentz
Browse files
Options
Downloads
Patches
Plain Diff
Add create-keyspace CLI endpoint
parent
e22fc9f0
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
swh/storage/cassandra/cql.py
+1
-0
1 addition, 0 deletions
swh/storage/cassandra/cql.py
swh/storage/cli.py
+26
-0
26 additions, 0 deletions
swh/storage/cli.py
swh/storage/tests/test_cli.py
+30
-1
30 additions, 1 deletion
swh/storage/tests/test_cli.py
with
57 additions
and
1 deletion
swh/storage/cassandra/cql.py
+
1
−
0
View file @
92de2589
...
...
@@ -172,6 +172,7 @@ def create_keyspace(
)
session
.
execute
(
'
USE
"
%s
"'
%
keyspace
)
for
query
in
CREATE_TABLES_QUERIES
:
logger
.
debug
(
"
Running:
\n
%s
"
,
query
)
session
.
execute
(
query
)
...
...
This diff is collapsed.
Click to expand it.
swh/storage/cli.py
+
26
−
0
View file @
92de2589
...
...
@@ -65,6 +65,32 @@ def storage(ctx, config_file, check_config):
ctx
.
obj
[
"
check_config
"
]
=
check_config
@storage.command
(
name
=
"
create-keyspace
"
)
@click.pass_context
def
create_keyspace
(
ctx
):
"""
Creates a Cassandra keyspace with table definitions suitable for use
by swh-storage
'
s Cassandra backend
"""
from
swh.storage.cassandra
import
create_keyspace
config
=
ctx
.
obj
[
"
config
"
][
"
storage
"
]
for
key
in
(
"
cls
"
,
"
hosts
"
,
"
keyspace
"
,
"
auth_provider
"
):
if
key
not
in
config
:
ctx
.
fail
(
f
"
Missing
{
key
}
key in config file.
"
)
if
config
[
"
cls
"
]
!=
"
cassandra
"
:
ctx
.
fail
(
f
"
cls must be
'
cassandra
'
, not
'
{
config
[
'
cls
'
]
}
'"
)
create_keyspace
(
hosts
=
config
[
"
hosts
"
],
port
=
config
.
get
(
"
port
"
,
9042
),
keyspace
=
config
[
"
keyspace
"
],
auth_provider
=
config
[
"
auth_provider
"
],
)
print
(
"
Done.
"
)
@storage.command
(
name
=
"
rpc-serve
"
)
@click.option
(
"
--host
"
,
...
...
This diff is collapsed.
Click to expand it.
swh/storage/tests/test_cli.py
+
30
−
1
View file @
92de2589
...
...
@@ -5,6 +5,7 @@
import
copy
import
logging
import
os
import
re
import
tempfile
from
unittest.mock
import
patch
...
...
@@ -15,7 +16,7 @@ import pytest
import
yaml
from
swh.journal.serializers
import
key_to_kafka
,
value_to_kafka
from
swh.model.model
import
Snapshot
,
SnapshotBranch
,
TargetType
from
swh.model.model
import
Origin
,
Snapshot
,
SnapshotBranch
,
TargetType
from
swh.storage
import
get_storage
from
swh.storage.cli
import
storage
as
cli
from
swh.storage.replay
import
OBJECT_CONVERTERS
...
...
@@ -67,6 +68,34 @@ def invoke(*args, env=None, journal_config=None, local_config=None):
return
ret
def
test_create_keyspace
(
swh_storage_cassandra_cluster
,
cassandra_auth_provider_config
,
):
(
hosts
,
port
)
=
swh_storage_cassandra_cluster
keyspace
=
"
test
"
+
os
.
urandom
(
10
).
hex
()
storage_config
=
dict
(
cls
=
"
cassandra
"
,
hosts
=
hosts
,
port
=
port
,
keyspace
=
keyspace
,
journal_writer
=
{
"
cls
"
:
"
memory
"
},
objstorage
=
{
"
cls
"
:
"
memory
"
},
auth_provider
=
cassandra_auth_provider_config
,
)
result
=
invoke
(
"
create-keyspace
"
,
local_config
=
{
"
storage
"
:
storage_config
})
assert
result
.
exit_code
==
0
,
result
.
output
assert
result
.
output
==
"
Done.
\n
"
# Check we can write and read to it
storage
=
get_storage
(
**
storage_config
)
origin
=
Origin
(
url
=
"
http://example.org
"
)
storage
.
origin_add
([
origin
])
assert
storage
.
origin_get
([
origin
.
url
])
==
[
origin
]
def
test_replay
(
swh_storage
,
kafka_prefix
:
str
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment