Merge "Dump shotgun log at the end of snapshot creation"
This commit is contained in:
commit
25a0cc461a
|
@ -108,3 +108,10 @@ class Config(object):
|
|||
def timeout(self):
|
||||
"""Timeout for executing commands."""
|
||||
return self.data.get("timeout", settings.DEFAULT_TIMEOUT)
|
||||
|
||||
@property
|
||||
def self_log_object(self):
|
||||
return {
|
||||
"type": "file",
|
||||
"path": settings.LOG_FILE
|
||||
}
|
||||
|
|
|
@ -34,15 +34,21 @@ class Manager(object):
|
|||
utils.execute("rm -rf {0}".format(os.path.dirname(self.conf.target)))
|
||||
for obj_data in self.conf.objects:
|
||||
logger.debug("Dumping: %s", obj_data)
|
||||
driver = Driver.getDriver(obj_data, self.conf)
|
||||
try:
|
||||
driver.snapshot()
|
||||
except fabric.exceptions.NetworkError:
|
||||
self.conf.on_network_error(obj_data)
|
||||
logger.debug("Archiving dump directory: %s", self.conf.target)
|
||||
self.snapshot_single(obj_data)
|
||||
|
||||
logger.debug("Dumping shotgun log and archiving dump directory: %s",
|
||||
self.conf.target)
|
||||
self.snapshot_single(self.conf.self_log_object)
|
||||
|
||||
utils.compress(self.conf.target, self.conf.compression_level)
|
||||
|
||||
with open(self.conf.lastdump, "w") as fo:
|
||||
fo.write("{0}.tar.xz".format(self.conf.target))
|
||||
return "{0}.tar.xz".format(self.conf.target)
|
||||
|
||||
def snapshot_single(self, object):
|
||||
driver = Driver.getDriver(object, self.conf)
|
||||
try:
|
||||
driver.snapshot()
|
||||
except fabric.exceptions.NetworkError:
|
||||
self.conf.on_network_error(object)
|
||||
|
|
|
@ -40,9 +40,11 @@ class TestManager(base.BaseTestCase):
|
|||
conf.target = "/target/data"
|
||||
conf.objects = [data]
|
||||
conf.lastdump = tempfile.mkstemp()[1]
|
||||
conf.self_log_object = {"type": "file", "path": "/path"}
|
||||
manager = Manager(conf)
|
||||
manager.snapshot()
|
||||
mget.assert_called_once_with(data, conf)
|
||||
calls = [mock.call(data, conf), mock.call(conf.self_log_object, conf)]
|
||||
mget.assert_has_calls(calls, any_order=True)
|
||||
mexecute.assert_called_once_with('rm -rf /target')
|
||||
|
||||
@mock.patch('shotgun.manager.Driver.getDriver')
|
||||
|
@ -69,6 +71,7 @@ class TestManager(base.BaseTestCase):
|
|||
None,
|
||||
fabric.exceptions.NetworkError,
|
||||
None,
|
||||
None,
|
||||
]
|
||||
mget.return_value = drv
|
||||
conf = Config()
|
||||
|
@ -85,9 +88,8 @@ class TestManager(base.BaseTestCase):
|
|||
}
|
||||
manager = Manager(conf)
|
||||
manager.snapshot()
|
||||
self.assertEquals([mock.call(offline_obj, conf),
|
||||
mock.call(processed_obj, conf),
|
||||
mock.call(offline_obj, conf),
|
||||
mock.call(offline_obj, conf)],
|
||||
mget.call_args_list)
|
||||
mget.assert_has_calls([mock.call(offline_obj, conf),
|
||||
mock.call(processed_obj, conf),
|
||||
mock.call(offline_obj, conf),
|
||||
mock.call(offline_obj, conf)], any_order=True)
|
||||
mexecute.assert_called_once_with('rm -rf /tmp')
|
||||
|
|
Loading…
Reference in New Issue