Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
6
Merge Requests
6
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
slapos.toolbox
Commits
2b3b9318
Commit
2b3b9318
authored
Nov 02, 2018
by
Nicolas Wavrant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixup
parent
61e85392
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
14 deletions
+17
-14
slapos/resilient/runner_exporter.py
slapos/resilient/runner_exporter.py
+13
-11
slapos/test/test_runner_exporter.py
slapos/test/test_runner_exporter.py
+4
-3
No files found.
slapos/resilient/runner_exporter.py
View file @
2b3b9318
...
@@ -21,6 +21,7 @@ from zc.buildout.configparser import parse
...
@@ -21,6 +21,7 @@ from zc.buildout.configparser import parse
os
.
environ
[
'LC_ALL'
]
=
'C'
os
.
environ
[
'LC_ALL'
]
=
'C'
os
.
umask
(
0o77
)
os
.
umask
(
0o77
)
@
contextmanager
@
contextmanager
def
CwdContextManager
(
path
):
def
CwdContextManager
(
path
):
"""
"""
...
@@ -91,7 +92,7 @@ def getExcludePathList(path):
...
@@ -91,7 +92,7 @@ def getExcludePathList(path):
if
p
:
if
p
:
excluded_path_list
.
append
(
os
.
path
.
relpath
(
p
,
path
))
excluded_path_list
.
append
(
os
.
path
.
relpath
(
p
,
path
))
for
partition
in
glob
.
glob
(
path
+
"/instance/slappart*"
):
for
partition
in
glob
.
glob
(
os
.
path
.
join
(
path
,
"instance"
,
"slappart*"
)
):
if
not
os
.
path
.
isdir
(
partition
):
if
not
os
.
path
.
isdir
(
partition
):
continue
continue
...
@@ -139,7 +140,7 @@ def synchroniseRunnerConfigurationDirectory(config, backup_path):
...
@@ -139,7 +140,7 @@ def synchroniseRunnerConfigurationDirectory(config, backup_path):
def
synchroniseRunnerWorkingDirectory
(
config
,
backup_path
):
def
synchroniseRunnerWorkingDirectory
(
config
,
backup_path
):
if
os
.
path
.
exists
(
'instance'
)
and
os
.
path
.
isdir
(
'instance'
):
if
os
.
path
.
isdir
(
'instance'
):
exclude_list
=
getExcludePathList
(
'.'
)
exclude_list
=
getExcludePathList
(
'.'
)
rsync
(
rsync
(
config
.
rsync_binary
,
'instance'
,
backup_path
,
config
.
rsync_binary
,
'instance'
,
backup_path
,
...
@@ -188,18 +189,19 @@ def writeSignatureFile(slappart_signature_method_dict, runner_working_path, sign
...
@@ -188,18 +189,19 @@ def writeSignatureFile(slappart_signature_method_dict, runner_working_path, sign
signature_file
.
write
(
"
\
n
"
.
join
(
sorted
(
signature_list
)))
signature_file
.
write
(
"
\
n
"
.
join
(
sorted
(
signature_list
)))
def
backupFilesWereModifiedDuringExport
():
def
backupFilesWereModifiedDuringExport
(
export_start_date
):
process
=
subprocess
.
Popen
([
'find'
,
'-cmin'
,
'0.1'
,
'-type'
,
'f'
],
stdout
=
subprocess
.
PIPE
)
export_time
=
(
datetime
.
now
()
-
export_start_date
).
total_seconds
()
time
.
sleep
(
1
)
process
=
subprocess
.
Popen
([
'find'
,
'-cmin'
,
str
(
export_time
/
60.
),
'-type'
,
'f'
,
'!'
,
'-path'
,
'*/srv/backup/*'
],
stdout
=
subprocess
.
PIPE
)
process
.
wait
()
process
.
wait
()
changed_file_output
=
process
.
stdout
.
read
()
if
process
.
stdout
.
read
():
for
line
in
changed_file_output
.
split
(
'
\
n
'
):
return
True
if
'/srv/backup/'
in
line
:
return
True
return
False
return
False
def
runExport
():
def
runExport
():
print
(
datetime
.
now
().
isoformat
())
export_start_date
=
datetime
.
now
()
print
(
export_start_date
.
isoformat
())
args
=
parseArgumentList
()
args
=
parseArgumentList
()
...
@@ -232,7 +234,7 @@ def runExport():
...
@@ -232,7 +234,7 @@ def runExport():
# BBB: clean software folder if it was synchronized
# BBB: clean software folder if it was synchronized
# in an old instance
# in an old instance
backup_software_path
=
os
.
path
.
join
(
backup_runner_path
,
'software'
)
backup_software_path
=
os
.
path
.
join
(
backup_runner_path
,
'software'
)
if
os
.
path
.
exists
(
backup_software_path
)
and
os
.
path
.
isdir
(
backup_software_path
):
if
os
.
path
.
isdir
(
backup_software_path
):
shutil
.
rmtree
(
backup_software_path
)
shutil
.
rmtree
(
backup_software_path
)
...
@@ -241,7 +243,7 @@ def runExport():
...
@@ -241,7 +243,7 @@ def runExport():
# Check that export didn't happen during backup of instances
# Check that export didn't happen during backup of instances
with
CwdContextManager
(
backup_runner_path
):
with
CwdContextManager
(
backup_runner_path
):
if
backupFilesWereModifiedDuringExport
():
if
backupFilesWereModifiedDuringExport
(
export_start_date
):
print
(
"ERROR: Some backups are not consistent, exporter should be re-run."
print
(
"ERROR: Some backups are not consistent, exporter should be re-run."
" Let's sleep %s minutes, to let the backup end..."
%
backup_wait_time
)
" Let's sleep %s minutes, to let the backup end..."
%
backup_wait_time
)
time
.
sleep
(
backup_wait_time
*
60
)
time
.
sleep
(
backup_wait_time
*
60
)
...
...
slapos/test/test_runner_exporter.py
View file @
2b3b9318
...
@@ -4,6 +4,7 @@ import shutil
...
@@ -4,6 +4,7 @@ import shutil
import
time
import
time
import
unittest
import
unittest
from
datetime
import
datetime
,
timedelta
from
slapos.resilient
import
runner_exporter
from
slapos.resilient
import
runner_exporter
tested_instance_cfg
=
"""[buildout]
tested_instance_cfg
=
"""[buildout]
...
@@ -203,6 +204,6 @@ class TestRunnerExporter(unittest.TestCase):
...
@@ -203,6 +204,6 @@ class TestRunnerExporter(unittest.TestCase):
def
test_backupFilesWereModifiedDuringExport
(
self
):
def
test_backupFilesWereModifiedDuringExport
(
self
):
self
.
_setUpFakeInstanceFolder
()
self
.
_setUpFakeInstanceFolder
()
with
runner_exporter
.
CwdContextManager
(
'instance'
):
with
runner_exporter
.
CwdContextManager
(
'instance'
):
self
.
assertTrue
(
runner_exporter
.
backupFilesWereModifiedDuringExport
())
self
.
assertTrue
(
runner_exporter
.
backupFilesWereModifiedDuringExport
(
datetime
.
now
()
+
timedelta
(
seconds
=-
5
)
))
time
.
sleep
(
11
)
time
.
sleep
(
2
)
self
.
assertFalse
(
runner_exporter
.
backupFilesWereModifiedDuringExport
())
self
.
assertFalse
(
runner_exporter
.
backupFilesWereModifiedDuringExport
(
datetime
.
now
()
+
timedelta
(
seconds
=-
1
)
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment