Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
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
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
slapos.core
Commits
ca456d3c
Commit
ca456d3c
authored
Oct 30, 2019
by
Łukasz Nowak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
testcase: Snapshot on setUpClass failure
/reviewed-on
nexedi/slapos.core!150
parent
833e4782
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
12 deletions
+18
-12
slapos/testing/testcase.py
slapos/testing/testcase.py
+18
-12
No files found.
slapos/testing/testcase.py
View file @
ca456d3c
...
@@ -374,6 +374,7 @@ class SlapOSInstanceTestCase(unittest.TestCase):
...
@@ -374,6 +374,7 @@ class SlapOSInstanceTestCase(unittest.TestCase):
except
BaseException
:
except
BaseException
:
cls
.
logger
.
exception
(
"Error during setUpClass"
)
cls
.
logger
.
exception
(
"Error during setUpClass"
)
cls
.
_storeSnapshot
(
"{}.setUpClass"
.
format
(
cls
.
__name__
))
cls
.
_cleanup
()
cls
.
_cleanup
()
cls
.
setUp
=
lambda
self
:
self
.
fail
(
'Setup Class failed.'
)
cls
.
setUp
=
lambda
self
:
self
.
fail
(
'Setup Class failed.'
)
raise
raise
...
@@ -384,25 +385,30 @@ class SlapOSInstanceTestCase(unittest.TestCase):
...
@@ -384,25 +385,30 @@ class SlapOSInstanceTestCase(unittest.TestCase):
"""
"""
cls
.
_cleanup
()
cls
.
_cleanup
()
def
tearDown
(
self
):
@
classmethod
def
_storeSnapshot
(
cls
,
name
):
# copy log files from standalone
# copy log files from standalone
for
standalone_log
in
glob
.
glob
(
os
.
path
.
join
(
for
standalone_log
in
glob
.
glob
(
os
.
path
.
join
(
self
.
_base_directory
,
'var'
,
'log'
,
'*'
)):
cls
.
_base_directory
,
'var'
,
'log'
,
'*'
)):
self
.
_snapshot_instance_file
(
standalone_log
)
cls
.
_snapshot_instance_file
(
standalone_log
,
name
)
# copy config and log files from partitions
# copy config and log files from partitions
for
pattern
in
self
.
_save_instance_file_pattern_list
:
for
pattern
in
cls
.
_save_instance_file_pattern_list
:
for
f
in
glob
.
glob
(
os
.
path
.
join
(
self
.
slap
.
instance_directory
,
pattern
)):
for
f
in
glob
.
glob
(
os
.
path
.
join
(
cls
.
slap
.
instance_directory
,
pattern
)):
self
.
_snapshot_instance_file
(
f
)
cls
.
_snapshot_instance_file
(
f
,
name
)
def
_snapshot_instance_file
(
self
,
source_file_name
):
def
tearDown
(
self
):
self
.
_storeSnapshot
(
self
.
id
())
@
classmethod
def
_snapshot_instance_file
(
cls
,
source_file_name
,
name
):
"""Save a file for later inspection.
"""Save a file for later inspection.
The path are made relative to slapos root directory and
The path are made relative to slapos root directory and
we keep the same directory structure.
we keep the same directory structure.
"""
"""
# we cannot use os.path.commonpath on python2, so implement something similar
# we cannot use os.path.commonpath on python2, so implement something similar
common_path
=
os
.
path
.
commonprefix
((
source_file_name
,
self
.
_base_directory
))
common_path
=
os
.
path
.
commonprefix
((
source_file_name
,
cls
.
_base_directory
))
if
not
os
.
path
.
isdir
(
common_path
):
if
not
os
.
path
.
isdir
(
common_path
):
common_path
=
os
.
path
.
dirname
(
common_path
)
common_path
=
os
.
path
.
dirname
(
common_path
)
...
@@ -410,14 +416,14 @@ class SlapOSInstanceTestCase(unittest.TestCase):
...
@@ -410,14 +416,14 @@ class SlapOSInstanceTestCase(unittest.TestCase):
if
relative_path
[
0
]
==
os
.
sep
:
if
relative_path
[
0
]
==
os
.
sep
:
relative_path
=
relative_path
[
1
:]
relative_path
=
relative_path
[
1
:]
destination
=
os
.
path
.
join
(
destination
=
os
.
path
.
join
(
self
.
_test_file_snapshot_directory
,
cls
.
_test_file_snapshot_directory
,
self
.
software_id
,
cls
.
software_id
,
self
.
id
()
,
name
,
relative_path
)
relative_path
)
destination_dirname
=
os
.
path
.
dirname
(
destination
)
destination_dirname
=
os
.
path
.
dirname
(
destination
)
mkdir_p
(
destination_dirname
)
mkdir_p
(
destination_dirname
)
if
os
.
path
.
isfile
(
source_file_name
):
if
os
.
path
.
isfile
(
source_file_name
):
self
.
logger
.
debug
(
"copy %s as %s"
,
source_file_name
,
destination
)
cls
.
logger
.
debug
(
"copy %s as %s"
,
source_file_name
,
destination
)
shutil
.
copy
(
source_file_name
,
destination
)
shutil
.
copy
(
source_file_name
,
destination
)
# implementation methods
# implementation methods
...
...
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