diff --git a/senlin/engine/actions/cluster_action.py b/senlin/engine/actions/cluster_action.py index 494745269..4fd4e44c4 100644 --- a/senlin/engine/actions/cluster_action.py +++ b/senlin/engine/actions/cluster_action.py @@ -122,7 +122,8 @@ class ClusterAction(base.Action): # We assume placement is a list kwargs['data'] = {'placement': placement['placements'][m]} - name = 'node-%s-%003d' % (self.entity.id[:8], index) + name_format = self.entity.config.get("node.name.format", "") + name = utils.format_node_name(name_format, self.entity, index) node = node_mod.Node(name, self.entity.profile_id, self.entity.id, context=self.context, **kwargs) diff --git a/senlin/tests/unit/engine/actions/test_create.py b/senlin/tests/unit/engine/actions/test_create.py index 99d4d9fce..1283e6ee8 100644 --- a/senlin/tests/unit/engine/actions/test_create.py +++ b/senlin/tests/unit/engine/actions/test_create.py @@ -45,7 +45,8 @@ class ClusterCreateTest(base.SenlinTestCase): # prepare mocks cluster = mock.Mock(id='CLUSTER_ID', profile_id='FAKE_PROFILE', user='FAKE_USER', project='FAKE_PROJECT', - domain='FAKE_DOMAIN') + domain='FAKE_DOMAIN', + config={"node.name.format": "node-$3I"}) mock_index.return_value = 123 node = mock.Mock(id='NODE_ID') mock_node.return_value = node @@ -66,7 +67,7 @@ class ClusterCreateTest(base.SenlinTestCase): self.assertEqual(action.RES_OK, res_code) self.assertEqual('All dependents completed', res_msg) mock_index.assert_called_once_with(action.context, 'CLUSTER_ID') - mock_node.assert_called_once_with('node-CLUSTER_-123', + mock_node.assert_called_once_with('node-123', 'FAKE_PROFILE', 'CLUSTER_ID', context=action.context, @@ -111,7 +112,8 @@ class ClusterCreateTest(base.SenlinTestCase): def test__create_nodes_multiple(self, mock_wait, mock_start, mock_dep, mock_node, mock_index, mock_action, mock_update, mock_load): - cluster = mock.Mock(id='01234567-123434') + cluster = mock.Mock(id='01234567-123434', + config={"node.name.format": "node-$3I"}) node1 = mock.Mock(id='01234567-abcdef', data={'placement': {'region': 'regionOne'}}) node2 = mock.Mock(id='abcdefab-123456', @@ -161,11 +163,11 @@ class ClusterCreateTest(base.SenlinTestCase): self.assertEqual({'region': 'regionOne'}, node1.data['placement']) self.assertEqual({'region': 'regionTwo'}, node2.data['placement']) mock_node_calls = [ - mock.call('node-01234567-123', mock.ANY, '01234567-123434', + mock.call('node-123', mock.ANY, '01234567-123434', user=mock.ANY, project=mock.ANY, domain=mock.ANY, index=123, context=mock.ANY, metadata={}, data={'placement': {'region': 'regionOne'}}), - mock.call('node-01234567-124', mock.ANY, '01234567-123434', + mock.call('node-124', mock.ANY, '01234567-123434', user=mock.ANY, project=mock.ANY, domain=mock.ANY, index=124, context=mock.ANY, metadata={}, data={'placement': {'region': 'regionTwo'}}) @@ -184,7 +186,7 @@ class ClusterCreateTest(base.SenlinTestCase): def test__create_nodes_multiple_failed_wait(self, mock_wait, mock_start, mock_dep, mock_node, mock_get, mock_update, mock_load): - cluster = mock.Mock(id='01234567-123434') + cluster = mock.Mock(id='01234567-123434', config={}) db_cluster = mock.Mock(next_index=1) mock_get.return_value = db_cluster node1 = mock.Mock(id='01234567-abcdef', data={})