diff --git a/senlin/engine/health_manager.py b/senlin/engine/health_manager.py index 0c05fd96c..2f6c23241 100644 --- a/senlin/engine/health_manager.py +++ b/senlin/engine/health_manager.py @@ -132,7 +132,16 @@ class HealthManager(service.Service): :returns: Nothing. """ req = vorc.ClusterCheckRequest(identity=cluster_id) - self.rpc_client.call(self.ctx, 'cluster_check', req) + + cluster = objects.Cluster.get(self.ctx, cluster_id, project_safe=False) + if not cluster: + LOG.warning(_LW("Cluster (%s) is not found."), cluster_id) + return + + ctx = context.get_service_context(user=cluster.user, + project=cluster.project) + ctx = context.RequestContext.from_dict(ctx) + self.rpc_client.call(ctx, 'cluster_check', req) def _add_listener(self, cluster_id): """Routine to be executed for adding cluster listener. diff --git a/senlin/tests/unit/engine/test_health_manager.py b/senlin/tests/unit/engine/test_health_manager.py index 12ad37168..ac83b75a9 100644 --- a/senlin/tests/unit/engine/test_health_manager.py +++ b/senlin/tests/unit/engine/test_health_manager.py @@ -16,6 +16,7 @@ import mock from oslo_config import cfg from senlin.common import consts +from senlin.common import context from senlin.common import messaging from senlin.engine import health_manager from senlin.objects import cluster as obj_cluster @@ -297,15 +298,39 @@ class TestHealthManager(base.SenlinTestCase): }, self.hm.registries[1]) + @mock.patch.object(obj_cluster.Cluster, 'get') + @mock.patch.object(context, 'get_service_context') + @mock.patch.object(context.RequestContext, 'from_dict') @mock.patch.object(rpc_client.EngineClient, 'call') - def test__poll_cluster(self, mock_check): + def test__poll_cluster(self, mock_check, mock_ctx, mock_sctx, mock_get): + x_cluster = mock.Mock(user='USER_ID', project='PROJECT_ID') + mock_get.return_value = x_cluster + mock_sctx.return_value = {'user': 'USER_ID', + 'project': 'PROJECT_ID', } + service_ctx = mock_sctx.return_value + mock_ctx.return_value = mock.Mock(user=service_ctx['user'], + project=service_ctx['project']) + ctx = mock_ctx.return_value self.hm._poll_cluster('CLUSTER_ID') - mock_check.assert_called_once_with(self.hm.ctx, 'cluster_check', - mock.ANY) + + mock_sctx.assert_called_once_with(user=x_cluster.user, + project=x_cluster.project) + mock_ctx.assert_called_once_with(service_ctx) + self.assertEqual('USER_ID', ctx.user) + self.assertEqual('PROJECT_ID', ctx.project) + self.assertEqual(1, mock_check.call_count) request = mock_check.call_args[0][2] self.assertIsInstance(request, vorc.ClusterCheckRequest) self.assertEqual('CLUSTER_ID', request.identity) + @mock.patch.object(obj_cluster.Cluster, 'get') + @mock.patch.object(rpc_client.EngineClient, 'call') + def test__poll_cluster_not_found(self, mock_check, mock_get): + mock_get.return_value = None + self.hm._poll_cluster('CLUSTER_ID') + + self.assertEqual(0, mock_check.call_count) + @mock.patch.object(obj_cluster.Cluster, 'get') def test__add_listener(self, mock_get): cfg.CONF.set_override('nova_control_exchange', 'FAKE_NOVA_EXCHANGE',