Move deploy() out of __enter__ method
Deployment have to be done inside of `with' block. Blueprint db-status-track Change-Id: I1394fecfd38e4b2c3547697b50313e78edb92ac1
This commit is contained in:
@@ -72,13 +72,23 @@ class EngineFactory(object):
|
||||
def cleanup(self):
|
||||
"""Cleanup OpenStack deployment."""
|
||||
|
||||
def __enter__(self):
|
||||
def make(self):
|
||||
self.task.update_status(consts.TaskStatus.DEPLOY_STARTED)
|
||||
deploy = self.deploy()
|
||||
endpoints = self.deploy()
|
||||
self.task.update_status(consts.TaskStatus.DEPLOY_FINISHED)
|
||||
return deploy
|
||||
return endpoints
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, type, value, traceback):
|
||||
if type:
|
||||
self.task.set_failed()
|
||||
self.task.update_status(consts.TaskStatus.CLEANUP)
|
||||
self.cleanup()
|
||||
self.task.update_status(consts.TaskStatus.FINISHED)
|
||||
try:
|
||||
self.cleanup()
|
||||
except Exception:
|
||||
self.task.set_failed()
|
||||
raise
|
||||
finally:
|
||||
self.task.update_status(consts.TaskStatus.FINISHED)
|
||||
|
@@ -37,8 +37,9 @@ def start_task(config):
|
||||
deploy_conf)
|
||||
tester = engine.TestEngine(config['tests'], task_object)
|
||||
|
||||
with deployer as deployment:
|
||||
with tester.bind(deployment):
|
||||
with deployer:
|
||||
endpoints = deployer.make()
|
||||
with tester.bind(endpoints):
|
||||
tester.verify()
|
||||
tester.benchmark()
|
||||
|
||||
|
@@ -31,3 +31,6 @@ class Task(object):
|
||||
|
||||
def update_status(self, status):
|
||||
db.task_update(self.task['uuid'], {'status': status})
|
||||
|
||||
def set_failed(self):
|
||||
db.task_update(self.task['uuid'], {'failed': True})
|
||||
|
@@ -120,3 +120,12 @@ class TestEngineTestCase(test.NoDBTestCase):
|
||||
mock.call.update_status(s.TEST_TOOL_BENCHMARKING),
|
||||
]
|
||||
self.assertEqual(fake_task.mock_calls, expected)
|
||||
|
||||
def test_task_status_invalid_config(self):
|
||||
fake_task = mock.MagicMock()
|
||||
try:
|
||||
engine.TestEngine(self.invalid_test_config_bad_key, fake_task)
|
||||
except exceptions.InvalidConfigException:
|
||||
pass
|
||||
expected = []
|
||||
self.assertEqual(fake_task.mock_calls, expected)
|
||||
|
@@ -86,7 +86,8 @@ class EngineFactoryTestCase(test.NoDBTestCase):
|
||||
self.cleanuped = True
|
||||
|
||||
with deploy.EngineFactory.get_engine('A', mock.Mock(),
|
||||
None) as deployment:
|
||||
self.assertTrue(deployment.deployed)
|
||||
None) as deployer:
|
||||
endpoints = deployer.make()
|
||||
self.assertTrue(endpoints.deployed)
|
||||
|
||||
self.assertTrue(deployment.cleanuped)
|
||||
self.assertTrue(endpoints.cleanuped)
|
||||
|
@@ -47,8 +47,8 @@ class DeployEngineTaskStatusTestCase(test.NoDBTestCase):
|
||||
|
||||
def test_task_status_basic_chain(self):
|
||||
fake_task = mock.MagicMock()
|
||||
with get_engine('FakeEngine', fake_task, {}):
|
||||
pass
|
||||
with get_engine('FakeEngine', fake_task, {}) as deployer:
|
||||
deployer.make()
|
||||
s = consts.TaskStatus
|
||||
expected = [
|
||||
mock.call.update_status(s.DEPLOY_STARTED),
|
||||
@@ -56,22 +56,24 @@ class DeployEngineTaskStatusTestCase(test.NoDBTestCase):
|
||||
mock.call.update_status(s.CLEANUP),
|
||||
mock.call.update_status(s.FINISHED),
|
||||
]
|
||||
self.assertEqual(fake_task.mock_calls, expected)
|
||||
self.assertEqual(expected, fake_task.mock_calls)
|
||||
|
||||
def _test_failure(self, engine, expected_calls):
|
||||
fake_task = mock.MagicMock()
|
||||
engine = get_engine(engine, fake_task, {})
|
||||
try:
|
||||
with engine:
|
||||
pass
|
||||
with get_engine(engine, fake_task, {}) as deployer:
|
||||
deployer.make()
|
||||
except FakeFailure:
|
||||
pass
|
||||
self.assertEqual(fake_task.mock_calls, expected_calls)
|
||||
self.assertEqual(expected_calls, fake_task.mock_calls)
|
||||
|
||||
def test_task_status_failed_deploy(self):
|
||||
s = consts.TaskStatus
|
||||
expected = [
|
||||
mock.call.update_status(s.DEPLOY_STARTED),
|
||||
mock.call.set_failed(),
|
||||
mock.call.update_status(s.CLEANUP),
|
||||
mock.call.update_status(s.FINISHED),
|
||||
]
|
||||
self._test_failure('EngineFailedDeploy', expected)
|
||||
|
||||
@@ -81,5 +83,7 @@ class DeployEngineTaskStatusTestCase(test.NoDBTestCase):
|
||||
mock.call.update_status(s.DEPLOY_STARTED),
|
||||
mock.call.update_status(s.DEPLOY_FINISHED),
|
||||
mock.call.update_status(s.CLEANUP),
|
||||
mock.call.set_failed(),
|
||||
mock.call.update_status(s.FINISHED),
|
||||
]
|
||||
self._test_failure('EngineFailedCleanup', expected)
|
||||
|
Reference in New Issue
Block a user