Implement handle_check for Rackspace Cloud Servers
This allows Rackspace::Cloud::Server to perform a sanity check when doing a stack.check() Change-Id: I2300a3d1f5f83969a398e8ac11656e181bc744a6 Implements: blueprint stack-check
This commit is contained in:
parent
b36dfd335f
commit
869978606c
@ -197,7 +197,7 @@ class CloudServer(server.Server):
|
||||
|
||||
def check_create_complete(self, server):
|
||||
"""Check if server creation is complete and handle server configs."""
|
||||
if not self._check_active(server):
|
||||
if not super(CloudServer, self).check_create_complete(server):
|
||||
return False
|
||||
|
||||
self.client_plugin().refresh_server(server)
|
||||
@ -234,6 +234,26 @@ class CloudServer(server.Server):
|
||||
|
||||
return server
|
||||
|
||||
def handle_check(self):
|
||||
server = self._check_server_status()
|
||||
checks = []
|
||||
|
||||
if 'rack_connect' in self.context.roles:
|
||||
rc_status = self._check_rack_connect_complete(server)
|
||||
checks.append(
|
||||
{'attr': 'rackconnect complete', 'expected': True,
|
||||
'current': rc_status}
|
||||
)
|
||||
|
||||
if 'rax_managed' in self.context.roles:
|
||||
mc_status = self._check_managed_cloud_complete(server)
|
||||
checks.append(
|
||||
{'attr': 'managed_cloud complete', 'expected': True,
|
||||
'current': mc_status}
|
||||
)
|
||||
|
||||
self._verify_check_conditions(checks)
|
||||
|
||||
|
||||
def resource_mapping():
|
||||
return {'Rackspace::Cloud::Server': CloudServer}
|
||||
|
@ -325,6 +325,51 @@ class CloudServersTest(common.HeatTestCase):
|
||||
self.assertEqual('Error: Unknown Managed Cloud automation status: FOO',
|
||||
six.text_type(exc))
|
||||
|
||||
def _prepare_server_check(self):
|
||||
templ, stack = self._setup_test_stack('server_check')
|
||||
server = self.fc.servers.list()[1]
|
||||
res = stack['WebServer']
|
||||
res.nova = mock.Mock()
|
||||
res.nova().servers.get = mock.Mock(return_value=server)
|
||||
return res
|
||||
|
||||
def test_check_rackconnect(self):
|
||||
res = self._prepare_server_check()
|
||||
res._check_rack_connect_complete = mock.Mock(return_value=True)
|
||||
self.ctx.roles = ['rack_connect']
|
||||
|
||||
scheduler.TaskRunner(res.check)()
|
||||
self.assertEqual((res.CHECK, res.COMPLETE), res.state)
|
||||
|
||||
def test_check_rackconnect_failure(self):
|
||||
self.ctx.roles = ['rack_connect']
|
||||
res = self._prepare_server_check()
|
||||
res._check_active = mock.Mock(return_value=True)
|
||||
res._check_rack_connect_complete = mock.Mock(return_value=False)
|
||||
|
||||
exc = self.assertRaises(exception.ResourceFailure,
|
||||
scheduler.TaskRunner(res.check))
|
||||
self.assertIn('False', six.text_type(exc))
|
||||
self.assertEqual((res.CHECK, res.FAILED), res.state)
|
||||
|
||||
def test_check_managed_cloud(self):
|
||||
res = self._prepare_server_check()
|
||||
res._check_managed_cloud_complete = mock.Mock(return_value=True)
|
||||
self.ctx.roles = ['rax_managed']
|
||||
|
||||
scheduler.TaskRunner(res.check)()
|
||||
self.assertEqual((res.CHECK, res.COMPLETE), res.state)
|
||||
|
||||
def test_check_managed_cloud_failure(self):
|
||||
res = self._prepare_server_check()
|
||||
res._check_managed_cloud_complete = mock.Mock(return_value=False)
|
||||
self.ctx.roles = ['rax_managed']
|
||||
|
||||
exc = self.assertRaises(exception.ResourceFailure,
|
||||
scheduler.TaskRunner(res.check))
|
||||
self.assertIn('False', six.text_type(exc))
|
||||
self.assertEqual((res.CHECK, res.FAILED), res.state)
|
||||
|
||||
@mock.patch.object(resource.Resource, 'data_set')
|
||||
def test_create_store_admin_pass_resource_data(self,
|
||||
mock_data_set):
|
||||
|
Loading…
Reference in New Issue
Block a user