Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
envsetup
Manage
Activity
Members
Plan
Redmine
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor 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
mediaserver
envsetup
Commits
6b9c3bd4
Commit
6b9c3bd4
authored
6 years ago
by
Nicolas KAROLAK
Browse files
Options
Downloads
Patches
Plain Diff
fix(test): rewrite latest backup check for multiple paths
parent
beab86c9
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_backup.py
+31
-15
31 additions, 15 deletions
tests/test_backup.py
with
31 additions
and
15 deletions
tests/test_backup.py
+
31
−
15
View file @
6b9c3bd4
...
...
@@ -67,22 +67,38 @@ def test_last_backup_is_recent(server: str) -> bool:
print
(
"
Checking latest backup age:
"
)
client
=
socket
.
gethostname
()
path
=
"
/backup/{}/home/latest
"
.
format
(
client
)
cmd
=
"
ssh -o StrictHostKeyChecking=no {} ls -l {} | grep latest
"
.
format
(
server
,
path
)
status
,
out
=
subprocess
.
getstatusoutput
(
cmd
)
if
status
==
0
:
date
=
out
.
strip
().
split
(
"
"
)[
-
1
]
pdate
=
datetime
.
strptime
(
date
,
"
%Y-%m-%d-%H%M%S
"
)
if
(
datetime
.
now
()
-
pdate
).
days
>
MAX_AGE
:
u
.
error
(
"
older than {} days
"
.
format
(
MAX_AGE
))
return
False
u
.
success
(
"
less than {} days old
"
.
format
(
MAX_AGE
))
return
True
out
=
out
or
"
no output
"
u
.
error
(
"
SSH access not working (code: {}): {}
"
.
format
(
status
,
out
))
# set backup potential directories path
paths
=
[
"
/backup/{}/home/latest
"
.
format
(
client
),
"
/backup/data/latest
"
,
]
# test each possible path
for
path
in
paths
:
# build and run commands
find
=
"
find -L {} {} {} {} {}
"
.
format
(
path
,
"
-maxdepth 0
"
,
"
-xtype l
"
,
"
-name latest
"
,
"
-exec realpath {} +
"
# must always be last arg
)
cmd
=
"
ssh -o StrictHostKeyChecking=no {}
'
{}
'"
.
format
(
server
,
find
)
status
,
out
=
subprocess
.
getstatusoutput
(
cmd
)
if
status
==
0
:
# get directory name and convert to datetime
last
=
out
.
strip
().
split
(
"
/
"
)[
-
1
]
date
=
datetime
.
strptime
(
last
,
"
%Y-%m-%d-%H%M%S
"
)
# check age
if
(
datetime
.
now
()
-
date
).
days
>
MAX_AGE
:
u
.
error
(
"
older than {} days
"
.
format
(
MAX_AGE
))
return
False
u
.
success
(
"
less than {} days old
"
.
format
(
MAX_AGE
))
return
True
# if we reach here, nothing have been found
u
.
error
(
"
latest backup directory not found
"
)
return
False
...
...
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