Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-scrubber
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
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 Lambert
swh-scrubber
Commits
781f84a1
Commit
781f84a1
authored
1 year ago
by
David Douard
Browse files
Options
Downloads
Patches
Plain Diff
cli: add support for check-hashes and check-references flags for `check
init` command
parent
a20e6735
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
swh/scrubber/cli.py
+26
-4
26 additions, 4 deletions
swh/scrubber/cli.py
swh/scrubber/tests/test_cli.py
+78
-0
78 additions, 0 deletions
swh/scrubber/tests/test_cli.py
with
104 additions
and
4 deletions
swh/scrubber/cli.py
+
26
−
4
View file @
781f84a1
...
...
@@ -122,6 +122,8 @@ def scrubber_check_cli_group(ctx):
)
@click.option
(
"
--nb-partitions
"
,
default
=
4096
,
type
=
int
)
@click.option
(
"
--name
"
,
default
=
None
,
type
=
str
)
@click.option
(
"
--check-hashes/--no-check-hashes
"
,
default
=
True
)
@click.option
(
"
--check-references/--no-check-references
"
,
default
=
None
)
@click.pass_context
def
scrubber_check_init
(
ctx
,
...
...
@@ -129,19 +131,28 @@ def scrubber_check_init(
object_type
:
str
,
nb_partitions
:
int
,
name
:
Optional
[
str
],
check_hashes
:
bool
,
check_references
:
Optional
[
bool
],
):
"""
Initialise a scrubber check configuration for the datastore defined in the
configuration file and given object_type.
A checker configuration configuration consists simply in a set of:
- object type: the type of object being checked,
- number of partitions: the number of partitions the hash space is divided
- backend: the datastore type being scrubbed (storage or journal),
- object-type: the type of object being checked,
- nb-pertitions: the number of partitions the hash space is divided
in; must be a power of 2,
- name: an unique name for easier reference,
linked to the storage provided in the configuration file.
- check-hashes: flag (default to True) to select the hash validation step for
this scrubbing configuration,
- check-references: flag (default to True for storage and False for the journal
backend) to select the reference validation step for this scrubbing configuration.
"""
if
not
object_type
or
not
name
:
raise
click
.
ClickException
(
...
...
@@ -152,6 +163,8 @@ def scrubber_check_init(
db
=
ctx
.
obj
[
"
db
"
]
if
backend
==
"
storage
"
:
if
check_references
is
None
:
check_references
=
True
if
"
storage
"
not
in
conf
:
raise
click
.
ClickException
(
"
You must have a storage configured in your config file.
"
...
...
@@ -163,6 +176,8 @@ def scrubber_check_init(
datastore
=
get_storage_datastore
(
storage
=
get_storage
(
**
conf
[
"
storage
"
]))
db
.
datastore_get_or_add
(
datastore
)
elif
backend
==
"
journal
"
:
if
check_references
is
None
:
check_references
=
False
if
"
journal
"
not
in
conf
:
raise
click
.
ClickException
(
"
You must have a journal configured in your config file.
"
...
...
@@ -177,8 +192,15 @@ def scrubber_check_init(
if
db
.
config_get_by_name
(
name
):
raise
click
.
ClickException
(
f
"
Configuration
{
name
}
already exists
"
)
assert
check_references
is
not
None
config_id
=
db
.
config_add
(
name
,
datastore
,
getattr
(
ObjectType
,
object_type
.
upper
()),
nb_partitions
name
,
datastore
,
getattr
(
ObjectType
,
object_type
.
upper
()),
nb_partitions
,
check_hashes
=
check_hashes
,
check_references
=
check_references
,
)
click
.
echo
(
f
"
Created configuration
{
name
}
[
{
config_id
}
] for checking
{
object_type
}
"
...
...
This diff is collapsed.
Click to expand it.
swh/scrubber/tests/test_cli.py
+
78
−
0
View file @
781f84a1
...
...
@@ -154,6 +154,84 @@ def test_check_init(mocker, scrubber_db, swh_storage):
assert
result
.
output
.
strip
()
==
msg
def
test_check_init_storage_flags
(
mocker
,
scrubber_db
,
swh_storage
):
mocker
.
patch
(
"
swh.scrubber.get_scrubber_db
"
,
return_value
=
scrubber_db
)
arg_list
=
[
"
check
"
,
"
init
"
,
"
storage
"
,
"
--object-type
"
,
"
snapshot
"
,
"
--nb-partitions
"
,
"
4
"
,
"
--name
"
,
]
name
=
"
cfg1
"
result
=
invoke
(
scrubber_db
,
arg_list
+
[
name
],
storage
=
swh_storage
,
)
assert
result
.
exit_code
==
0
,
result
.
output
cfg_entry
=
scrubber_db
.
config_get
(
scrubber_db
.
config_get_by_name
(
name
))
assert
cfg_entry
.
check_hashes
is
True
assert
cfg_entry
.
check_references
is
True
name
=
"
cfg2
"
result
=
invoke
(
scrubber_db
,
arg_list
+
[
name
,
"
--no-check-references
"
],
storage
=
swh_storage
,
)
assert
result
.
exit_code
==
0
,
result
.
output
cfg_entry
=
scrubber_db
.
config_get
(
scrubber_db
.
config_get_by_name
(
name
))
assert
cfg_entry
.
check_hashes
is
True
assert
cfg_entry
.
check_references
is
False
name
=
"
cfg3
"
result
=
invoke
(
scrubber_db
,
arg_list
+
[
name
,
"
--no-check-hashes
"
],
storage
=
swh_storage
,
)
assert
result
.
exit_code
==
0
,
result
.
output
cfg_entry
=
scrubber_db
.
config_get
(
scrubber_db
.
config_get_by_name
(
name
))
assert
cfg_entry
.
check_hashes
is
False
assert
cfg_entry
.
check_references
is
True
def
test_check_init_journal_flags
(
mocker
,
scrubber_db
,
kafka_server
,
kafka_prefix
,
kafka_consumer_group
):
mocker
.
patch
(
"
swh.scrubber.get_scrubber_db
"
,
return_value
=
scrubber_db
)
arg_list
=
[
"
check
"
,
"
init
"
,
"
journal
"
,
"
--object-type
"
,
"
snapshot
"
,
"
--name
"
,
]
name
=
"
cfg1
"
result
=
invoke
(
scrubber_db
,
arg_list
+
[
name
],
kafka_server
=
kafka_server
,
kafka_prefix
=
kafka_prefix
,
kafka_consumer_group
=
kafka_consumer_group
,
)
assert
result
.
exit_code
==
0
,
result
.
output
cfg_entry
=
scrubber_db
.
config_get
(
scrubber_db
.
config_get_by_name
(
name
))
assert
cfg_entry
.
check_hashes
is
True
assert
cfg_entry
.
check_references
is
False
def
test_check_storage
(
mocker
,
scrubber_db
,
swh_storage
):
storage_checker
=
MagicMock
()
StorageChecker
=
mocker
.
patch
(
...
...
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