Support update for sahara cluster template
Change-Id: I85a878b25872048ac663c01c98953e64a2b6b68f
This commit is contained in:
parent
45140726b4
commit
ae5b07b76b
@ -299,11 +299,13 @@ class SaharaClusterTemplate(resource.Resource):
|
||||
constraints.Length(min=1, max=50),
|
||||
constraints.AllowedPattern(SAHARA_NAME_REGEX),
|
||||
],
|
||||
update_allowed=True
|
||||
),
|
||||
DESCRIPTION: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_('Description of the Sahara Group Template.'),
|
||||
default="",
|
||||
update_allowed=True
|
||||
),
|
||||
PLUGIN_NAME: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
@ -311,12 +313,14 @@ class SaharaClusterTemplate(resource.Resource):
|
||||
required=True,
|
||||
constraints=[
|
||||
constraints.CustomConstraint('sahara.plugin')
|
||||
]
|
||||
],
|
||||
update_allowed=True
|
||||
),
|
||||
HADOOP_VERSION: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_('Version of Hadoop running on instances.'),
|
||||
required=True,
|
||||
update_allowed=True
|
||||
),
|
||||
IMAGE_ID: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
@ -324,6 +328,7 @@ class SaharaClusterTemplate(resource.Resource):
|
||||
constraints=[
|
||||
constraints.CustomConstraint('sahara.image'),
|
||||
],
|
||||
update_allowed=True
|
||||
),
|
||||
MANAGEMENT_NETWORK: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
@ -331,6 +336,7 @@ class SaharaClusterTemplate(resource.Resource):
|
||||
constraints=[
|
||||
constraints.CustomConstraint('neutron.network')
|
||||
],
|
||||
update_allowed=True
|
||||
),
|
||||
ANTI_AFFINITY: properties.Schema(
|
||||
properties.Schema.LIST,
|
||||
@ -338,10 +344,12 @@ class SaharaClusterTemplate(resource.Resource):
|
||||
schema=properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
),
|
||||
update_allowed=True
|
||||
),
|
||||
CLUSTER_CONFIGS: properties.Schema(
|
||||
properties.Schema.MAP,
|
||||
_('Cluster configs dictionary.'),
|
||||
update_allowed=True
|
||||
),
|
||||
NODE_GROUPS: properties.Schema(
|
||||
properties.Schema.LIST,
|
||||
@ -369,7 +377,7 @@ class SaharaClusterTemplate(resource.Resource):
|
||||
),
|
||||
}
|
||||
),
|
||||
|
||||
update_allowed=True
|
||||
),
|
||||
USE_AUTOCONFIG: properties.Schema(
|
||||
properties.Schema.BOOLEAN,
|
||||
@ -390,39 +398,45 @@ class SaharaClusterTemplate(resource.Resource):
|
||||
return name
|
||||
return re.sub('[^a-zA-Z0-9-]', '', self.physical_resource_name())
|
||||
|
||||
def handle_create(self):
|
||||
plugin_name = self.properties[self.PLUGIN_NAME]
|
||||
hadoop_version = self.properties[self.HADOOP_VERSION]
|
||||
description = self.properties[self.DESCRIPTION]
|
||||
image_id = self.properties[self.IMAGE_ID]
|
||||
net_id = self.properties[self.MANAGEMENT_NETWORK]
|
||||
use_autoconfig = self.properties[self.USE_AUTOCONFIG]
|
||||
if net_id:
|
||||
def _prepare_properties(self):
|
||||
props = {
|
||||
'name': self._cluster_template_name(),
|
||||
'plugin_name': self.properties[self.PLUGIN_NAME],
|
||||
'hadoop_version': self.properties[self.HADOOP_VERSION],
|
||||
'description': self.properties[self.DESCRIPTION],
|
||||
'cluster_configs': self.properties[self.CLUSTER_CONFIGS],
|
||||
'node_groups': self.properties[self.NODE_GROUPS],
|
||||
'anti_affinity': self.properties[self.ANTI_AFFINITY],
|
||||
'net_id': self.properties[self.MANAGEMENT_NETWORK],
|
||||
'default_image_id': self.properties[self.IMAGE_ID],
|
||||
'use_autoconfig': self.properties[self.USE_AUTOCONFIG],
|
||||
}
|
||||
if props['net_id']:
|
||||
if self.is_using_neutron():
|
||||
net_id = self.client_plugin('neutron').find_neutron_resource(
|
||||
props['net_id'] = self.client_plugin(
|
||||
'neutron').find_neutron_resource(
|
||||
self.properties, self.MANAGEMENT_NETWORK, 'network')
|
||||
else:
|
||||
net_id = self.client_plugin('nova').get_nova_network_id(
|
||||
net_id)
|
||||
anti_affinity = self.properties[self.ANTI_AFFINITY]
|
||||
cluster_configs = self.properties[self.CLUSTER_CONFIGS]
|
||||
node_groups = self.properties[self.NODE_GROUPS]
|
||||
cluster_template = self.client().cluster_templates.create(
|
||||
self._cluster_template_name(),
|
||||
plugin_name, hadoop_version,
|
||||
description=description,
|
||||
default_image_id=image_id,
|
||||
anti_affinity=anti_affinity,
|
||||
net_id=net_id,
|
||||
cluster_configs=cluster_configs,
|
||||
node_groups=node_groups,
|
||||
use_autoconfig=use_autoconfig
|
||||
)
|
||||
props['net_id'] = self.client_plugin(
|
||||
'nova').get_nova_network_id(props['net_id'])
|
||||
return props
|
||||
|
||||
def handle_create(self):
|
||||
args = self._prepare_properties()
|
||||
cluster_template = self.client().cluster_templates.create(**args)
|
||||
LOG.info(_LI("Cluster Template '%s' has been created"),
|
||||
cluster_template.name)
|
||||
self.resource_id_set(cluster_template.id)
|
||||
return self.resource_id
|
||||
|
||||
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
|
||||
if prop_diff:
|
||||
self.properties = json_snippet.properties(
|
||||
self.properties_schema,
|
||||
self.context)
|
||||
args = self._prepare_properties()
|
||||
self.client().cluster_templates.update(self.resource_id, **args)
|
||||
|
||||
def validate(self):
|
||||
res = super(SaharaClusterTemplate, self).validate()
|
||||
if res:
|
||||
|
@ -286,18 +286,19 @@ class SaharaClusterTemplateTest(common.HeatTestCase):
|
||||
|
||||
def test_ct_create(self):
|
||||
self._create_ct(self.t)
|
||||
expected_args = ('test-cluster-template', 'vanilla',
|
||||
'2.3.0')
|
||||
expected_kwargs = {'description': '',
|
||||
'default_image_id': None,
|
||||
'net_id': 'some_network_id',
|
||||
'anti_affinity': None,
|
||||
'node_groups': None,
|
||||
'cluster_configs': None,
|
||||
'use_autoconfig': None
|
||||
}
|
||||
self.ct_mgr.create.assert_called_once_with(*expected_args,
|
||||
**expected_kwargs)
|
||||
args = {
|
||||
'name': 'test-cluster-template',
|
||||
'plugin_name': 'vanilla',
|
||||
'hadoop_version': '2.3.0',
|
||||
'description': '',
|
||||
'default_image_id': None,
|
||||
'net_id': 'some_network_id',
|
||||
'anti_affinity': None,
|
||||
'node_groups': None,
|
||||
'cluster_configs': None,
|
||||
'use_autoconfig': None
|
||||
}
|
||||
self.ct_mgr.create.assert_called_once_with(**args)
|
||||
|
||||
def test_ct_delete(self):
|
||||
ct = self._create_ct(self.t)
|
||||
@ -339,7 +340,7 @@ class SaharaClusterTemplateTest(common.HeatTestCase):
|
||||
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]
|
||||
name = self.ct_mgr.create.call_args[1]['name']
|
||||
self.assertIn('-clustertemplate-', name)
|
||||
|
||||
def test_ct_show_resource(self):
|
||||
@ -347,3 +348,25 @@ class SaharaClusterTemplateTest(common.HeatTestCase):
|
||||
self.ct_mgr.get.return_value = self.fake_ct
|
||||
self.assertEqual({"cluster-template": "info"}, ct.FnGetAtt('show'))
|
||||
self.ct_mgr.get.assert_called_once_with('some_ct_id')
|
||||
|
||||
def test_update(self):
|
||||
ct = self._create_ct(self.t)
|
||||
rsrc_defn = self.stack.t.resource_definitions(self.stack)[
|
||||
'cluster-template']
|
||||
rsrc_defn['Properties']['plugin_name'] = 'hdp'
|
||||
rsrc_defn['Properties']['hadoop_version'] = '1.3.2'
|
||||
scheduler.TaskRunner(ct.update, rsrc_defn)()
|
||||
args = {
|
||||
'name': 'test-cluster-template',
|
||||
'plugin_name': 'hdp',
|
||||
'hadoop_version': '1.3.2',
|
||||
'description': '',
|
||||
'default_image_id': None,
|
||||
'net_id': 'some_network_id',
|
||||
'anti_affinity': None,
|
||||
'node_groups': None,
|
||||
'cluster_configs': None,
|
||||
'use_autoconfig': None
|
||||
}
|
||||
self.ct_mgr.update.assert_called_once_with('some_ct_id', **args)
|
||||
self.assertEqual((ct.UPDATE, ct.COMPLETE), ct.state)
|
||||
|
Loading…
x
Reference in New Issue
Block a user