Browse Source

Generate correct names for sahara templates

Change-Id: I96a7ce8b673c07ca2a40f88e2c1a9f952113919e
Closes-Bug: #1472998
changes/59/200159/3
Tetiana Lashchova 7 years ago
parent
commit
763ad42e4a
  1. 6
      heat/engine/resources/openstack/sahara/sahara_templates.py
  2. 48
      heat/tests/test_sahara_templates.py

6
heat/engine/resources/openstack/sahara/sahara_templates.py

@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import re
from oslo_log import log as logging
from heat.common import exception
@ -163,7 +165,7 @@ class SaharaNodeGroupTemplate(resource.Resource):
name = self.properties[self.NAME]
if name:
return name
return self.physical_resource_name()
return re.sub('[^a-zA-Z0-9-]', '', self.physical_resource_name())
def handle_create(self):
plugin_name = self.properties[self.PLUGIN_NAME]
@ -352,7 +354,7 @@ class SaharaClusterTemplate(resource.Resource):
name = self.properties[self.NAME]
if name:
return name
return self.physical_resource_name()
return re.sub('[^a-zA-Z0-9-]', '', self.physical_resource_name())
def handle_create(self):
plugin_name = self.properties[self.PLUGIN_NAME]

48
heat/tests/test_sahara_templates.py

@ -57,6 +57,32 @@ resources:
neutron_management_network: some_network
"""
cluster_template_without_name = """
heat_template_version: 2013-05-23
resources:
cluster_template!:
type: OS::Sahara::ClusterTemplate
properties:
plugin_name: vanilla
hadoop_version: 2.3.0
neutron_management_network: some_network
"""
node_group_template_without_name = """
heat_template_version: 2013-05-23
resources:
node_group!:
type: OS::Sahara::NodeGroupTemplate
properties:
plugin_name: vanilla
hadoop_version: 2.3.0
flavor: m1.large
floating_ip_pool: some_pool_name
node_processes:
- namenode
- jobtracker
"""
class FakeNodeGroupTemplate(object):
def __init__(self):
@ -193,6 +219,17 @@ class SaharaNodeGroupTemplateTest(common.HeatTestCase):
u"Error validating value u'm1.large'",
six.text_type(ex))
def test_template_invalid_name(self):
tmpl = template_format.parse(node_group_template_without_name)
stack = utils.parse_stack(tmpl)
ngt = stack['node_group!']
self.ngt_mgr.create.return_value = self.fake_ngt
scheduler.TaskRunner(ngt.create)()
self.assertEqual((ngt.CREATE, ngt.COMPLETE), ngt.state)
self.assertEqual(self.fake_ngt.id, ngt.resource_id)
name = self.ngt_mgr.create.call_args[0][0]
self.assertIn('-nodegroup-', name)
class SaharaClusterTemplateTest(common.HeatTestCase):
def setUp(self):
@ -275,3 +312,14 @@ class SaharaClusterTemplateTest(common.HeatTestCase):
ct.validate)
self.assertEqual("neutron_management_network must be provided",
six.text_type(ex))
def test_template_invalid_name(self):
tmpl = template_format.parse(cluster_template_without_name)
stack = utils.parse_stack(tmpl)
ct = stack['cluster_template!']
self.ct_mgr.create.return_value = self.fake_ct
scheduler.TaskRunner(ct.create)()
self.assertEqual((ct.CREATE, ct.COMPLETE), ct.state)
self.assertEqual(self.fake_ct.id, ct.resource_id)
name = self.ct_mgr.create.call_args[0][0]
self.assertIn('-clustertemplate-', name)

Loading…
Cancel
Save