Merge "Translate networks and subnet in cluster template"

This commit is contained in:
Zuul
2018-01-11 13:23:31 +00:00
committed by Gerrit Code Review
2 changed files with 43 additions and 7 deletions

View File

@@ -19,6 +19,7 @@ from heat.engine import constraints
from heat.engine import properties from heat.engine import properties
from heat.engine import resource from heat.engine import resource
from heat.engine import support from heat.engine import support
from heat.engine import translation
class ClusterTemplate(resource.Resource): class ClusterTemplate(resource.Resource):
@@ -40,7 +41,7 @@ class ClusterTemplate(resource.Resource):
DOCKER_VOLUME_SIZE, DOCKER_STORAGE_DRIVER, COE, DOCKER_VOLUME_SIZE, DOCKER_STORAGE_DRIVER, COE,
NETWORK_DRIVER, VOLUME_DRIVER, HTTP_PROXY, HTTPS_PROXY, NETWORK_DRIVER, VOLUME_DRIVER, HTTP_PROXY, HTTPS_PROXY,
NO_PROXY, LABELS, TLS_DISABLED, PUBLIC, REGISTRY_ENABLED, NO_PROXY, LABELS, TLS_DISABLED, PUBLIC, REGISTRY_ENABLED,
SERVER_TYPE, MASTER_LB_ENABLED, FLOATING_IP_ENABLED SERVER_TYPE, MASTER_LB_ENABLED, FLOATING_IP_ENABLED
) = ( ) = (
'name', 'image', 'flavor', 'master_flavor', 'keypair', 'name', 'image', 'flavor', 'master_flavor', 'keypair',
'external_network', 'fixed_network', 'fixed_subnet', 'dns_nameserver', 'external_network', 'fixed_network', 'fixed_subnet', 'dns_nameserver',
@@ -93,7 +94,8 @@ class ClusterTemplate(resource.Resource):
), ),
EXTERNAL_NETWORK: properties.Schema( EXTERNAL_NETWORK: properties.Schema(
properties.Schema.STRING, properties.Schema.STRING,
_('The external neutron network to attach the Cluster.'), _('The external neutron network name or UUID to attach the '
'Cluster.'),
constraints=[ constraints=[
constraints.CustomConstraint('neutron.network') constraints.CustomConstraint('neutron.network')
], ],
@@ -101,14 +103,16 @@ class ClusterTemplate(resource.Resource):
), ),
FIXED_NETWORK: properties.Schema( FIXED_NETWORK: properties.Schema(
properties.Schema.STRING, properties.Schema.STRING,
_('The fixed neutron network to attach the Cluster.'), _('The fixed neutron network name or UUID to attach the '
'Cluster.'),
constraints=[ constraints=[
constraints.CustomConstraint('neutron.network') constraints.CustomConstraint('neutron.network')
] ]
), ),
FIXED_SUBNET: properties.Schema( FIXED_SUBNET: properties.Schema(
properties.Schema.STRING, properties.Schema.STRING,
_('The fixed neutron subnet to attach the Cluster.'), _('The fixed neutron subnet name or UUID to attach the '
'Cluster.'),
constraints=[ constraints=[
constraints.CustomConstraint('neutron.subnet') constraints.CustomConstraint('neutron.subnet')
] ]
@@ -214,6 +218,34 @@ class ClusterTemplate(resource.Resource):
), ),
} }
def translation_rules(self, props):
return [
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.EXTERNAL_NETWORK],
client_plugin=self.client_plugin('neutron'),
finder='find_resourceid_by_name_or_id',
entity='network'
),
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.FIXED_NETWORK],
client_plugin=self.client_plugin('neutron'),
finder='find_resourceid_by_name_or_id',
entity='network'
),
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.FIXED_SUBNET],
client_plugin=self.client_plugin('neutron'),
finder='find_resourceid_by_name_or_id',
entity='subnet'
)
]
def validate(self): def validate(self):
"""Validate the provided params.""" """Validate the provided params."""
super(ClusterTemplate, self).validate() super(ClusterTemplate, self).validate()

View File

@@ -13,6 +13,7 @@
import copy import copy
import mock import mock
from neutronclient.neutron import v2_0 as neutronV20
import six import six
from heat.common import exception from heat.common import exception
@@ -66,9 +67,9 @@ class TestMagnumClusterTemplate(common.HeatTestCase):
'flavor_id': 'm1.small', 'flavor_id': 'm1.small',
'master_flavor_id': 'm1.medium', 'master_flavor_id': 'm1.medium',
'keypair_id': 'heat_key', 'keypair_id': 'heat_key',
'external_network_id': '0244b54d-ae1f-44f0-a24a-442760f1d681', 'external_network_id': 'id_for_net_or_sub',
'fixed_network': '0f59a3dd-fac1-4d03-b41a-d4115fbffa89', 'fixed_network': 'id_for_net_or_sub',
'fixed_subnet': '27a8c89c-0d28-4946-8c78-82cfec1d670a', 'fixed_subnet': 'id_for_net_or_sub',
'dns_nameserver': '8.8.8.8', 'dns_nameserver': '8.8.8.8',
'docker_volume_size': 5, 'docker_volume_size': 5,
'docker_storage_driver': 'devicemapper', 'docker_storage_driver': 'devicemapper',
@@ -99,6 +100,9 @@ class TestMagnumClusterTemplate(common.HeatTestCase):
self.client = mock.Mock() self.client = mock.Mock()
self.patchobject(cluster_template.ClusterTemplate, 'client', self.patchobject(cluster_template.ClusterTemplate, 'client',
return_value=self.client) return_value=self.client)
self.find_mock = self.patchobject(neutronV20,
'find_resourceid_by_name_or_id')
self.find_mock.return_value = 'id_for_net_or_sub'
self.stub_FlavorConstraint_validate() self.stub_FlavorConstraint_validate()
self.stub_KeypairConstraint_validate() self.stub_KeypairConstraint_validate()
self.stub_ImageConstraint_validate() self.stub_ImageConstraint_validate()