From 869978606c45745578fdc1f7806091470c58e89c Mon Sep 17 00:00:00 2001 From: Anderson Mesquita Date: Tue, 14 Oct 2014 13:40:56 -0300 Subject: [PATCH] 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 --- .../rackspace/resources/cloud_server.py | 22 ++++++++- .../tests/test_rackspace_cloud_server.py | 45 +++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/contrib/rackspace/rackspace/resources/cloud_server.py b/contrib/rackspace/rackspace/resources/cloud_server.py index f66ddfcca..f280a9efc 100644 --- a/contrib/rackspace/rackspace/resources/cloud_server.py +++ b/contrib/rackspace/rackspace/resources/cloud_server.py @@ -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} diff --git a/contrib/rackspace/rackspace/tests/test_rackspace_cloud_server.py b/contrib/rackspace/rackspace/tests/test_rackspace_cloud_server.py index 51dc4b076..00410e703 100644 --- a/contrib/rackspace/rackspace/tests/test_rackspace_cloud_server.py +++ b/contrib/rackspace/rackspace/tests/test_rackspace_cloud_server.py @@ -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):