From cd2d8dcf08f0fccd2371ad8d50b4034d77bbc038 Mon Sep 17 00:00:00 2001 From: Bui Doan Dang Date: Wed, 8 Mar 2023 13:31:12 +0700 Subject: [PATCH] fix wrong attribute in heat senlin client Heat has been using the deprecated interfaces of openstacksdk for some Senlin APIs but these interfaces were already removed. This fixes that problem and replace the removed interfaces by the new ones. story: 2010635 task: 47602 Change-Id: I3b18de721949f3c15c776f90720f3e994f7d6670 --- .../resources/openstack/senlin/cluster.py | 10 +++---- .../engine/resources/openstack/senlin/node.py | 4 +-- heat/tests/openstack/senlin/test_cluster.py | 28 ++++++++++--------- heat/tests/openstack/senlin/test_node.py | 8 +++--- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/heat/engine/resources/openstack/senlin/cluster.py b/heat/engine/resources/openstack/senlin/cluster.py index 6d68bb9197..57ccf7ceed 100644 --- a/heat/engine/resources/openstack/senlin/cluster.py +++ b/heat/engine/resources/openstack/senlin/cluster.py @@ -232,7 +232,7 @@ class Cluster(res_base.BaseSenlinResource): 'enabled': p[self.P_ENABLED], } action = { - 'func': 'cluster_attach_policy', + 'func': 'attach_policy_to_cluster', 'params': params, 'action_id': None, 'done': False, @@ -283,7 +283,7 @@ class Cluster(res_base.BaseSenlinResource): 'enabled': p[self.P_ENABLED] } action = { - 'func': 'cluster_update_policy', + 'func': 'update_cluster_policy', 'params': params, 'action_id': None, 'done': False, @@ -296,7 +296,7 @@ class Cluster(res_base.BaseSenlinResource): 'enabled': p[self.P_ENABLED] } action = { - 'func': 'cluster_detach_policy', + 'func': 'detach_policy_from_cluster', 'params': params, 'action_id': None, 'done': False, @@ -309,7 +309,7 @@ class Cluster(res_base.BaseSenlinResource): 'enabled': p[self.P_ENABLED] } action = { - 'func': 'cluster_attach_policy', + 'func': 'attach_policy_to_cluster', 'params': params, 'action_id': None, 'done': False, @@ -338,7 +338,7 @@ class Cluster(res_base.BaseSenlinResource): params['number'] = params.pop(self.DESIRED_CAPACITY) params['cluster'] = self.resource_id action = { - 'func': 'cluster_resize', + 'func': 'resize_cluster', 'params': params, 'action_id': None, 'done': False, diff --git a/heat/engine/resources/openstack/senlin/node.py b/heat/engine/resources/openstack/senlin/node.py index 1809eb7771..7d254cbe42 100644 --- a/heat/engine/resources/openstack/senlin/node.py +++ b/heat/engine/resources/openstack/senlin/node.py @@ -156,7 +156,7 @@ class Node(res_base.BaseSenlinResource): 'nodes': [self.resource_id], } action = { - 'func': 'cluster_del_nodes', + 'func': 'remove_nodes_from_cluster', 'action_id': None, 'params': params, 'done': False, @@ -179,7 +179,7 @@ class Node(res_base.BaseSenlinResource): 'nodes': [self.resource_id], } action = { - 'func': 'cluster_add_nodes', + 'func': 'add_nodes_to_cluster', 'action_id': None, 'params': params, 'done': False, diff --git a/heat/tests/openstack/senlin/test_cluster.py b/heat/tests/openstack/senlin/test_cluster.py index 5a451801c8..e30dd25837 100644 --- a/heat/tests/openstack/senlin/test_cluster.py +++ b/heat/tests/openstack/senlin/test_cluster.py @@ -144,7 +144,7 @@ class SenlinClusterTest(common.HeatTestCase): } self.senlin_mock.create_cluster.assert_called_once_with( **create_cluster_kwargs) - self.senlin_mock.cluster_attach_policy.assert_called_once_with( + self.senlin_mock.attach_policy_to_cluster.assert_called_once_with( **attach_policy_kwargs) def test_cluster_create_error(self): @@ -216,7 +216,7 @@ class SenlinClusterTest(common.HeatTestCase): props['desired_capacity'] = 10 rsrc_defns = template.Template(new_t).resource_definitions(self.stack) new_cluster = rsrc_defns['senlin-cluster'] - self.senlin_mock.cluster_resize.return_value = { + self.senlin_mock.resize_cluster.return_value = { 'action': 'fake-action'} self.senlin_mock.get_action.return_value = mock.Mock( status='SUCCEEDED') @@ -226,7 +226,7 @@ class SenlinClusterTest(common.HeatTestCase): 'adjustment_type': 'EXACT_CAPACITY', 'number': 10 } - self.senlin_mock.cluster_resize.assert_called_once_with( + self.senlin_mock.resize_cluster.assert_called_once_with( cluster=cluster.resource_id, **cluster_resize_kwargs) self.assertEqual(2, self.senlin_mock.get_action.call_count) @@ -243,9 +243,9 @@ class SenlinClusterTest(common.HeatTestCase): props['policies'] = [{'policy': 'new_policy'}] rsrc_defns = template.Template(new_t).resource_definitions(self.stack) new_cluster = rsrc_defns['senlin-cluster'] - self.senlin_mock.cluster_detach_policy.return_value = { + self.senlin_mock.detach_policy_from_cluster.return_value = { 'action': 'fake-action'} - self.senlin_mock.cluster_attach_policy.return_value = { + self.senlin_mock.attach_policy_to_cluster.return_value = { 'action': 'fake-action'} self.senlin_mock.get_action.return_value = mock.Mock( status='SUCCEEDED') @@ -257,10 +257,10 @@ class SenlinClusterTest(common.HeatTestCase): 'enabled': True, } self.assertEqual(2, - self.senlin_mock.cluster_attach_policy.call_count) - self.senlin_mock.cluster_detach_policy.assert_called_once_with( + self.senlin_mock.attach_policy_to_cluster.call_count) + self.senlin_mock.detach_policy_from_cluster.assert_called_once_with( **detach_policy_kwargs) - self.assertEqual(0, self.senlin_mock.cluster_update_policy.call_count) + self.assertEqual(0, self.senlin_mock.update_cluster_policy.call_count) self.assertEqual(3, self.senlin_mock.get_action.call_count) def test_cluster_update_policy_exists(self): @@ -270,7 +270,7 @@ class SenlinClusterTest(common.HeatTestCase): props['policies'] = [{'policy': 'fake_policy', 'enabled': False}] rsrc_defns = template.Template(new_t).resource_definitions(self.stack) new_cluster = rsrc_defns['senlin-cluster'] - self.senlin_mock.cluster_update_policy.return_value = { + self.senlin_mock.update_cluster_policy.return_value = { 'action': 'fake-action'} self.senlin_mock.get_action.return_value = mock.Mock( status='SUCCEEDED') @@ -281,10 +281,12 @@ class SenlinClusterTest(common.HeatTestCase): 'cluster': cluster.resource_id, 'enabled': False, } - self.senlin_mock.cluster_update_policy.assert_called_once_with( + self.senlin_mock.update_cluster_policy.assert_called_once_with( **update_policy_kwargs) - self.assertEqual(1, self.senlin_mock.cluster_attach_policy.call_count) - self.assertEqual(0, self.senlin_mock.cluster_detach_policy.call_count) + self.assertEqual(1, self.senlin_mock. + attach_policy_to_cluster.call_count) + self.assertEqual(0, self.senlin_mock. + detach_policy_from_cluster.call_count) def test_cluster_update_failed(self): cluster = self._create_cluster(self.t) @@ -293,7 +295,7 @@ class SenlinClusterTest(common.HeatTestCase): props['desired_capacity'] = 3 rsrc_defns = template.Template(new_t).resource_definitions(self.stack) update_snippet = rsrc_defns['senlin-cluster'] - self.senlin_mock.cluster_resize.return_value = { + self.senlin_mock.resize_cluster.return_value = { 'action': 'fake-action'} self.senlin_mock.get_action.return_value = mock.Mock( status='FAILED', status_reason='Unknown') diff --git a/heat/tests/openstack/senlin/test_node.py b/heat/tests/openstack/senlin/test_node.py index 108d737eaa..dc801b3304 100644 --- a/heat/tests/openstack/senlin/test_node.py +++ b/heat/tests/openstack/senlin/test_node.py @@ -180,17 +180,17 @@ class SenlinNodeTest(common.HeatTestCase): props['cluster'] = 'new_cluster' rsrc_defns = template.Template(new_t).resource_definitions(self.stack) new_node = rsrc_defns['senlin-node'] - self.senlin_mock.cluster_del_nodes.return_value = { + self.senlin_mock.remove_nodes_from_cluster.return_value = { 'action': 'remove_node_from_cluster' } - self.senlin_mock.cluster_add_nodes.return_value = { + self.senlin_mock.add_nodes_to_cluster.return_value = { 'action': 'add_node_to_cluster' } scheduler.TaskRunner(node.update, new_node)() self.assertEqual((node.UPDATE, node.COMPLETE), node.state) - self.senlin_mock.cluster_del_nodes.assert_called_once_with( + self.senlin_mock.remove_nodes_from_cluster.assert_called_once_with( cluster='fake_cluster_id', nodes=[node.resource_id]) - self.senlin_mock.cluster_add_nodes.assert_called_once_with( + self.senlin_mock.add_nodes_to_cluster.assert_called_once_with( cluster='new_cluster_id', nodes=[node.resource_id]) def test_node_update_failed(self):