From 252b2aebd619549828986de9406b37e0949f2f90 Mon Sep 17 00:00:00 2001 From: Andrew Lazarev Date: Fri, 24 Jan 2014 16:51:53 -0800 Subject: [PATCH] Forced lowercase for instance names Closes-Bug: #1232075 Closes-Bug: #1300407 Change-Id: I95ea66b82cd91fba82c85b2106713d25769d7f59 --- sahara/service/direct_engine.py | 5 ++- sahara/tests/unit/utils/test_direct_engine.py | 31 +++++++++++++++++++ sahara/tests/unit/utils/test_heat.py | 1 + sahara/utils/openstack/heat.py | 2 +- 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 sahara/tests/unit/utils/test_direct_engine.py diff --git a/sahara/service/direct_engine.py b/sahara/service/direct_engine.py index 314a9dd484..8f4abb909b 100644 --- a/sahara/service/direct_engine.py +++ b/sahara/service/direct_engine.py @@ -200,10 +200,13 @@ class DirectEngine(e.Engine): return None + def _get_inst_name(self, cluster_name, ng_name, index): + return ('%s-%s-%03d' % (cluster_name, ng_name, index)).lower() + def _run_instance(self, cluster, node_group, idx, aa_groups): """Create instance using nova client and persist them into DB.""" ctx = context.ctx() - name = '%s-%s-%03d' % (cluster.name, node_group.name, idx) + name = self._get_inst_name(cluster.name, node_group.name, idx) userdata = self._generate_user_data_script(node_group, name) diff --git a/sahara/tests/unit/utils/test_direct_engine.py b/sahara/tests/unit/utils/test_direct_engine.py new file mode 100644 index 0000000000..0ec5dbd3ee --- /dev/null +++ b/sahara/tests/unit/utils/test_direct_engine.py @@ -0,0 +1,31 @@ +# Copyright (c) 2013 Mirantis Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest2 + +from sahara.service import direct_engine as e + + +class TestDirectEngine(unittest2.TestCase): + def setUp(self): + self.engine = e.DirectEngine() + super(TestDirectEngine, self).setUp() + + def test_get_inst_name(self): + inst_name = "cluster-worker-001" + self.assertEqual( + self.engine._get_inst_name("cluster", "worker", 1), inst_name) + self.assertEqual( + self.engine._get_inst_name("CLUSTER", "WORKER", 1), inst_name) diff --git a/sahara/tests/unit/utils/test_heat.py b/sahara/tests/unit/utils/test_heat.py index 923de47943..d8fc197c34 100644 --- a/sahara/tests/unit/utils/test_heat.py +++ b/sahara/tests/unit/utils/test_heat.py @@ -29,6 +29,7 @@ class TestHeat(unittest2.TestCase): def test_gets(self): inst_name = "cluster-worker-001" self.assertEqual(h._get_inst_name("cluster", "worker", 0), inst_name) + self.assertEqual(h._get_inst_name("CLUSTER", "WORKER", 0), inst_name) self.assertEqual(h._get_port_name(inst_name), "cluster-worker-001-port") self.assertEqual(h._get_floating_name(inst_name), diff --git a/sahara/utils/openstack/heat.py b/sahara/utils/openstack/heat.py index 6fe9939fbf..46c08fbc6f 100644 --- a/sahara/utils/openstack/heat.py +++ b/sahara/utils/openstack/heat.py @@ -36,7 +36,7 @@ def client(): def _get_inst_name(cluster_name, ng_name, index): - return '%s-%s-%03d' % (cluster_name, ng_name, (index + 1)) + return ('%s-%s-%03d' % (cluster_name, ng_name, (index + 1))).lower() def _get_port_name(inst_name):