Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rwm
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
Container 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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Radoslav Bodó
rwm
Commits
8ac74064
Commit
8ac74064
authored
1 year ago
by
Radoslav Bodó
Browse files
Options
Downloads
Patches
Plain Diff
rwm: add sizes to storage_list
parent
39088cbd
No related branches found
No related tags found
No related merge requests found
Pipeline
#7580
passed
1 year ago
Stage: code_quality
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
rwm.py
+26
-7
26 additions, 7 deletions
rwm.py
tests/test_default.py
+8
-1
8 additions, 1 deletion
tests/test_default.py
tests/test_storage.py
+2
-0
2 additions, 0 deletions
tests/test_storage.py
with
36 additions
and
8 deletions
rwm.py
+
26
−
7
View file @
8ac74064
...
...
@@ -65,6 +65,16 @@ def wrap_output(process):
return
process
.
returncode
def
size_fmt
(
num
):
"""
print value formated with human readable units
"""
for
unit
in
[
'
B
'
,
'
KiB
'
,
'
MiB
'
,
'
GiB
'
,
'
TiB
'
,
'
PiB
'
,
'
EiB
'
,
'
ZiB
'
]:
if
abs
(
num
)
<
1024.0
:
return
f
'
{
num
:
0.1
f
}
{
unit
}
'
num
/=
1024.0
return
f
'
{
num
:
0.1
f
}
YiB
'
@dataclasses.dataclass
class
BackupResult
:
"""
backup results data container
"""
...
...
@@ -239,11 +249,10 @@ class StorageManager:
output
=
[]
for
bucket
in
buckets
:
result
=
{
"
name
"
:
bucket
.
name
,
"
policy
"
:
"
OK
"
if
self
.
storage_check_policy
(
bucket
.
name
)
else
"
FAILED
"
,
"
owner
"
:
self
.
bucket_owner
(
bucket
.
name
).
split
(
"
$
"
)[
-
1
]
}
result
=
{}
result
[
"
name
"
]
=
bucket
.
name
result
[
"
policy
"
]
=
"
OK
"
if
self
.
storage_check_policy
(
bucket
.
name
)
else
"
FAILED
"
result
[
"
owner
"
]
=
self
.
bucket_owner
(
bucket
.
name
).
split
(
"
$
"
)[
-
1
]
if
result
[
"
policy
"
]
==
"
OK
"
:
user_statement
=
self
.
_policy_statements_user
(
self
.
bucket_policy
(
bucket
.
name
))[
0
]
...
...
@@ -253,12 +262,22 @@ class StorageManager:
if
show_full
:
result
[
"
objects
"
]
=
0
result
[
"
old_versions
"
]
=
0
result
[
"
delete_markers
"
]
=
0
result
[
"
old_versions
"
]
=
0
result
[
"
size
"
]
=
0
result
[
"
old_size
"
]
=
0
for
page
in
paginator
.
paginate
(
Bucket
=
bucket
.
name
):
for
obj
in
page
.
get
(
"
Versions
"
,
[]):
result
[
"
objects
"
if
obj
[
"
IsLatest
"
]
else
"
old_versions
"
]
+=
1
if
obj
[
"
IsLatest
"
]:
result
[
"
objects
"
]
+=
1
result
[
"
size
"
]
+=
obj
[
"
Size
"
]
else
:
result
[
"
old_versions
"
]
+=
1
result
[
"
old_size
"
]
+=
obj
[
"
Size
"
]
result
[
"
delete_markers
"
]
+=
len
(
page
.
get
(
"
DeleteMarkers
"
,
[]))
result
[
"
size
"
]
=
size_fmt
(
result
[
"
size
"
])
result
[
"
old_size
"
]
=
size_fmt
(
result
[
"
old_size
"
])
output
.
append
(
result
)
...
...
This diff is collapsed.
Click to expand it.
tests/test_default.py
+
8
−
1
View file @
8ac74064
...
...
@@ -5,7 +5,7 @@ from subprocess import CompletedProcess
from
unittest.mock
import
Mock
,
patch
import
rwm
from
rwm
import
is_sublist
,
main
as
rwm_main
,
wrap_output
from
rwm
import
is_sublist
,
main
as
rwm_main
,
size_fmt
,
wrap_output
def
test_sublist
():
...
...
@@ -22,6 +22,13 @@ def test_wrap_output():
assert
wrap_output
(
CompletedProcess
(
args
=
'
dummy
'
,
returncode
=
11
,
stdout
=
"
dummy
"
,
stderr
=
"
dummy
"
))
==
11
def
test_size_fmt
():
"""
test sizefmt
"""
assert
size_fmt
(
1024
)
==
"
1.0 KiB
"
assert
size_fmt
(
10
**
25
)
==
"
8.3 YiB
"
def
test_main
(
tmpworkdir
:
str
):
# pylint: disable=unused-argument
"""
test main
"""
...
...
This diff is collapsed.
Click to expand it.
tests/test_storage.py
+
2
−
0
View file @
8ac74064
...
...
@@ -161,6 +161,8 @@ def test_storage_list(
radosuser_admin
.
bucket_create
(
"
no-acl-dummy
"
)
bucket
=
radosuser_admin
.
storage_create
(
bucket_name
,
target_username
)
bucket
.
upload_fileobj
(
BytesIO
(
b
"
dummydata1
"
),
"
dummykey
"
)
bucket
.
upload_fileobj
(
BytesIO
(
b
"
dummydata1
"
),
"
dummykey1
"
)
bucket
.
Object
(
"
dummykey1
"
).
delete
()
assert
len
(
radosuser_admin
.
storage_list
(
show_full
=
True
,
name_filter
=
"
a
"
))
==
2
...
...
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