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):
|
def cleanup(self):
|
||||||
"""Cleanup OpenStack deployment."""
|
"""Cleanup OpenStack deployment."""
|
||||||
|
|
||||||
def __enter__(self):
|
def make(self):
|
||||||
self.task.update_status(consts.TaskStatus.DEPLOY_STARTED)
|
self.task.update_status(consts.TaskStatus.DEPLOY_STARTED)
|
||||||
deploy = self.deploy()
|
endpoints = self.deploy()
|
||||||
self.task.update_status(consts.TaskStatus.DEPLOY_FINISHED)
|
self.task.update_status(consts.TaskStatus.DEPLOY_FINISHED)
|
||||||
return deploy
|
return endpoints
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
return self
|
||||||
|
|
||||||
def __exit__(self, type, value, traceback):
|
def __exit__(self, type, value, traceback):
|
||||||
|
if type:
|
||||||
|
self.task.set_failed()
|
||||||
self.task.update_status(consts.TaskStatus.CLEANUP)
|
self.task.update_status(consts.TaskStatus.CLEANUP)
|
||||||
self.cleanup()
|
try:
|
||||||
self.task.update_status(consts.TaskStatus.FINISHED)
|
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)
|
deploy_conf)
|
||||||
tester = engine.TestEngine(config['tests'], task_object)
|
tester = engine.TestEngine(config['tests'], task_object)
|
||||||
|
|
||||||
with deployer as deployment:
|
with deployer:
|
||||||
with tester.bind(deployment):
|
endpoints = deployer.make()
|
||||||
|
with tester.bind(endpoints):
|
||||||
tester.verify()
|
tester.verify()
|
||||||
tester.benchmark()
|
tester.benchmark()
|
||||||
|
|
||||||
|
@@ -31,3 +31,6 @@ class Task(object):
|
|||||||
|
|
||||||
def update_status(self, status):
|
def update_status(self, status):
|
||||||
db.task_update(self.task['uuid'], {'status': 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),
|
mock.call.update_status(s.TEST_TOOL_BENCHMARKING),
|
||||||
]
|
]
|
||||||
self.assertEqual(fake_task.mock_calls, expected)
|
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
|
self.cleanuped = True
|
||||||
|
|
||||||
with deploy.EngineFactory.get_engine('A', mock.Mock(),
|
with deploy.EngineFactory.get_engine('A', mock.Mock(),
|
||||||
None) as deployment:
|
None) as deployer:
|
||||||
self.assertTrue(deployment.deployed)
|
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):
|
def test_task_status_basic_chain(self):
|
||||||
fake_task = mock.MagicMock()
|
fake_task = mock.MagicMock()
|
||||||
with get_engine('FakeEngine', fake_task, {}):
|
with get_engine('FakeEngine', fake_task, {}) as deployer:
|
||||||
pass
|
deployer.make()
|
||||||
s = consts.TaskStatus
|
s = consts.TaskStatus
|
||||||
expected = [
|
expected = [
|
||||||
mock.call.update_status(s.DEPLOY_STARTED),
|
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.CLEANUP),
|
||||||
mock.call.update_status(s.FINISHED),
|
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):
|
def _test_failure(self, engine, expected_calls):
|
||||||
fake_task = mock.MagicMock()
|
fake_task = mock.MagicMock()
|
||||||
engine = get_engine(engine, fake_task, {})
|
|
||||||
try:
|
try:
|
||||||
with engine:
|
with get_engine(engine, fake_task, {}) as deployer:
|
||||||
pass
|
deployer.make()
|
||||||
except FakeFailure:
|
except FakeFailure:
|
||||||
pass
|
pass
|
||||||
self.assertEqual(fake_task.mock_calls, expected_calls)
|
self.assertEqual(expected_calls, fake_task.mock_calls)
|
||||||
|
|
||||||
def test_task_status_failed_deploy(self):
|
def test_task_status_failed_deploy(self):
|
||||||
s = consts.TaskStatus
|
s = consts.TaskStatus
|
||||||
expected = [
|
expected = [
|
||||||
mock.call.update_status(s.DEPLOY_STARTED),
|
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)
|
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_STARTED),
|
||||||
mock.call.update_status(s.DEPLOY_FINISHED),
|
mock.call.update_status(s.DEPLOY_FINISHED),
|
||||||
mock.call.update_status(s.CLEANUP),
|
mock.call.update_status(s.CLEANUP),
|
||||||
|
mock.call.set_failed(),
|
||||||
|
mock.call.update_status(s.FINISHED),
|
||||||
]
|
]
|
||||||
self._test_failure('EngineFailedCleanup', expected)
|
self._test_failure('EngineFailedCleanup', expected)
|
||||||
|
Reference in New Issue
Block a user