Resolve name/id using translation rules
This changes the first set of neutron resouces to use translation rules to resolve name_id properties. Changed reources: - OS::Neutron::Subnet - OS::Neutron::Port - OS::Neutron:Router - OS::Neutron:FloatingIp Change-Id: I2119401e3554d0bafd34978e6c8e7610712148ac Partial-Bug: #1514680
This commit is contained in:
@@ -137,6 +137,14 @@ class FloatingIP(neutron.NeutronResource):
|
||||
translation.TranslationRule.REPLACE,
|
||||
[self.FLOATING_NETWORK],
|
||||
value_path=[self.FLOATING_NETWORK_ID]
|
||||
),
|
||||
translation.TranslationRule(
|
||||
props,
|
||||
translation.TranslationRule.RESOLVE,
|
||||
[self.FLOATING_NETWORK],
|
||||
client_plugin=self.client_plugin(),
|
||||
finder='find_resourceid_by_name_or_id',
|
||||
entity='network'
|
||||
)
|
||||
]
|
||||
|
||||
@@ -215,8 +223,7 @@ class FloatingIP(neutron.NeutronResource):
|
||||
props = self.prepare_properties(
|
||||
self.properties,
|
||||
self.physical_resource_name())
|
||||
self.client_plugin().resolve_network(props, self.FLOATING_NETWORK,
|
||||
'floating_network_id')
|
||||
props['floating_network_id'] = props.pop(self.FLOATING_NETWORK)
|
||||
fip = self.client().create_floatingip({
|
||||
'floatingip': props})['floatingip']
|
||||
self.resource_id_set(fip['id'])
|
||||
@@ -307,9 +314,7 @@ class FloatingIPAssociation(neutron.NeutronResource):
|
||||
|
||||
def handle_create(self):
|
||||
props = self.prepare_properties(self.properties, self.name)
|
||||
|
||||
floatingip_id = props.pop(self.FLOATINGIP_ID)
|
||||
|
||||
self.client().update_floatingip(floatingip_id, {
|
||||
'floatingip': props})
|
||||
self.resource_id_set(self.id)
|
||||
|
||||
@@ -341,6 +341,22 @@ class Port(neutron.NeutronResource):
|
||||
translation.TranslationRule.REPLACE,
|
||||
[self.FIXED_IPS, self.FIXED_IP_SUBNET],
|
||||
value_name=self.FIXED_IP_SUBNET_ID
|
||||
),
|
||||
translation.TranslationRule(
|
||||
props,
|
||||
translation.TranslationRule.RESOLVE,
|
||||
[self.NETWORK],
|
||||
client_plugin=self.client_plugin(),
|
||||
finder='find_resourceid_by_name_or_id',
|
||||
entity='network'
|
||||
),
|
||||
translation.TranslationRule(
|
||||
props,
|
||||
translation.TranslationRule.RESOLVE,
|
||||
[self.FIXED_IPS, self.FIXED_IP_SUBNET],
|
||||
client_plugin=self.client_plugin(),
|
||||
finder='find_resourceid_by_name_or_id',
|
||||
entity='subnet'
|
||||
)
|
||||
]
|
||||
|
||||
@@ -362,7 +378,7 @@ class Port(neutron.NeutronResource):
|
||||
props = self.prepare_properties(
|
||||
self.properties,
|
||||
self.physical_resource_name())
|
||||
self.client_plugin().resolve_network(props, self.NETWORK, 'network_id')
|
||||
props['network_id'] = props.pop(self.NETWORK)
|
||||
self._prepare_port_properties(props)
|
||||
qos_policy = props.pop(self.QOS_POLICY, None)
|
||||
if qos_policy:
|
||||
@@ -456,19 +472,6 @@ class Port(neutron.NeutronResource):
|
||||
"""Mandatory replace based on props """
|
||||
return after_props.get(self.REPLACEMENT_POLICY) == 'REPLACE_ALWAYS'
|
||||
|
||||
def needs_replace_with_prop_diff(self, changed_properties_set,
|
||||
after_props, before_props):
|
||||
"""Needs replace based on prop_diff """
|
||||
# Switching between name and ID is OK, provided the value resolves
|
||||
# to the same network. If the network changes, port is replaced.
|
||||
if self.NETWORK in changed_properties_set:
|
||||
after_id = self.client_plugin().find_neutron_resource(
|
||||
after_props, self.NETWORK, 'network')
|
||||
before_id = self.client_plugin().find_neutron_resource(
|
||||
before_props, self.NETWORK, 'network')
|
||||
changed_properties_set.remove(self.NETWORK)
|
||||
return before_id != after_id
|
||||
|
||||
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
|
||||
if prop_diff:
|
||||
self.prepare_update_properties(prop_diff)
|
||||
|
||||
@@ -164,8 +164,17 @@ class Router(neutron.NeutronResource):
|
||||
}
|
||||
|
||||
def translation_rules(self, props):
|
||||
rules = [
|
||||
translation.TranslationRule(
|
||||
props,
|
||||
translation.TranslationRule.RESOLVE,
|
||||
[self.EXTERNAL_GATEWAY, self.EXTERNAL_GATEWAY_NETWORK],
|
||||
client_plugin=self.client_plugin(),
|
||||
finder='find_resourceid_by_name_or_id',
|
||||
entity='network')
|
||||
]
|
||||
if props.get(self.L3_AGENT_ID):
|
||||
return [
|
||||
rules.extend([
|
||||
translation.TranslationRule(
|
||||
props,
|
||||
translation.TranslationRule.ADD,
|
||||
@@ -175,8 +184,8 @@ class Router(neutron.NeutronResource):
|
||||
props,
|
||||
translation.TranslationRule.DELETE,
|
||||
[self.L3_AGENT_ID]
|
||||
)
|
||||
]
|
||||
)])
|
||||
return rules
|
||||
|
||||
def validate(self):
|
||||
super(Router, self).validate()
|
||||
@@ -213,8 +222,7 @@ class Router(neutron.NeutronResource):
|
||||
def _resolve_gateway(self, props):
|
||||
gateway = props.get(self.EXTERNAL_GATEWAY)
|
||||
if gateway:
|
||||
self.client_plugin().resolve_network(
|
||||
gateway, self.EXTERNAL_GATEWAY_NETWORK, 'network_id')
|
||||
gateway['network_id'] = gateway.pop(self.EXTERNAL_GATEWAY_NETWORK)
|
||||
if gateway[self.EXTERNAL_GATEWAY_ENABLE_SNAT] is None:
|
||||
del gateway[self.EXTERNAL_GATEWAY_ENABLE_SNAT]
|
||||
return props
|
||||
@@ -386,7 +394,33 @@ class RouterInterface(neutron.NeutronResource):
|
||||
translation.TranslationRule.REPLACE,
|
||||
[self.SUBNET],
|
||||
value_path=[self.SUBNET_ID]
|
||||
),
|
||||
translation.TranslationRule(
|
||||
props,
|
||||
translation.TranslationRule.RESOLVE,
|
||||
[self.PORT],
|
||||
client_plugin=self.client_plugin(),
|
||||
finder='find_resourceid_by_name_or_id',
|
||||
entity='port'
|
||||
),
|
||||
translation.TranslationRule(
|
||||
props,
|
||||
translation.TranslationRule.RESOLVE,
|
||||
[self.ROUTER],
|
||||
client_plugin=self.client_plugin(),
|
||||
finder='find_resourceid_by_name_or_id',
|
||||
entity='router'
|
||||
),
|
||||
translation.TranslationRule(
|
||||
props,
|
||||
translation.TranslationRule.RESOLVE,
|
||||
[self.SUBNET],
|
||||
client_plugin=self.client_plugin(),
|
||||
finder='find_resourceid_by_name_or_id',
|
||||
entity='subnet'
|
||||
)
|
||||
|
||||
|
||||
]
|
||||
|
||||
def validate(self):
|
||||
@@ -406,15 +440,12 @@ class RouterInterface(neutron.NeutronResource):
|
||||
self.PORT)
|
||||
|
||||
def handle_create(self):
|
||||
router_id = self.client_plugin().resolve_router(
|
||||
dict(self.properties), self.ROUTER, 'router_id')
|
||||
router_id = dict(self.properties).get(self.ROUTER)
|
||||
key = 'subnet_id'
|
||||
value = self.client_plugin().resolve_subnet(
|
||||
dict(self.properties), self.SUBNET, key)
|
||||
value = dict(self.properties).get(self.SUBNET)
|
||||
if not value:
|
||||
key = 'port_id'
|
||||
value = self.client_plugin().resolve_port(
|
||||
dict(self.properties), self.PORT, key)
|
||||
value = dict(self.properties).get(self.PORT)
|
||||
self.client().add_interface_router(
|
||||
router_id,
|
||||
{key: value})
|
||||
@@ -488,7 +519,16 @@ class RouterGateway(neutron.NeutronResource):
|
||||
translation.TranslationRule.REPLACE,
|
||||
[self.NETWORK],
|
||||
value_path=[self.NETWORK_ID]
|
||||
),
|
||||
translation.TranslationRule(
|
||||
props,
|
||||
translation.TranslationRule.RESOLVE,
|
||||
[self.NETWORK],
|
||||
client_plugin=self.client_plugin(),
|
||||
finder='find_resourceid_by_name_or_id',
|
||||
entity='network'
|
||||
)
|
||||
|
||||
]
|
||||
|
||||
def add_dependencies(self, deps):
|
||||
@@ -519,8 +559,7 @@ class RouterGateway(neutron.NeutronResource):
|
||||
|
||||
def handle_create(self):
|
||||
router_id = self.properties[self.ROUTER_ID]
|
||||
network_id = self.client_plugin().resolve_network(
|
||||
dict(self.properties), self.NETWORK, 'network_id')
|
||||
network_id = dict(self.properties).get(self.NETWORK)
|
||||
self.client().add_gateway_router(
|
||||
router_id,
|
||||
{'network_id': network_id})
|
||||
|
||||
@@ -271,10 +271,27 @@ class Subnet(neutron.NeutronResource):
|
||||
|
||||
def translation_rules(self, props):
|
||||
return [
|
||||
translation.TranslationRule(props,
|
||||
translation.TranslationRule.REPLACE,
|
||||
[self.NETWORK],
|
||||
value_path=[self.NETWORK_ID])
|
||||
translation.TranslationRule(
|
||||
props,
|
||||
translation.TranslationRule.REPLACE,
|
||||
[self.NETWORK],
|
||||
value_path=[self.NETWORK_ID]),
|
||||
translation.TranslationRule(
|
||||
props,
|
||||
translation.TranslationRule.RESOLVE,
|
||||
[self.NETWORK],
|
||||
client_plugin=self.client_plugin(),
|
||||
finder='find_resourceid_by_name_or_id',
|
||||
entity='network'
|
||||
),
|
||||
translation.TranslationRule(
|
||||
props,
|
||||
translation.TranslationRule.RESOLVE,
|
||||
[self.SUBNETPOOL],
|
||||
client_plugin=self.client_plugin(),
|
||||
finder='find_resourceid_by_name_or_id',
|
||||
entity='subnetpool'
|
||||
)
|
||||
]
|
||||
|
||||
@classmethod
|
||||
@@ -327,12 +344,9 @@ class Subnet(neutron.NeutronResource):
|
||||
props = self.prepare_properties(
|
||||
self.properties,
|
||||
self.physical_resource_name())
|
||||
self.client_plugin().resolve_network(props, self.NETWORK,
|
||||
'network_id')
|
||||
props['network_id'] = props.pop(self.NETWORK)
|
||||
if self.SUBNETPOOL in props and props[self.SUBNETPOOL]:
|
||||
props['subnetpool_id'] = self.client_plugin(
|
||||
).find_resourceid_by_name_or_id(
|
||||
'subnetpool', props.pop('subnetpool'))
|
||||
props['subnetpool_id'] = props.pop('subnetpool')
|
||||
self._null_gateway_ip(props)
|
||||
subnet = self.client().create_subnet({'subnet': props})['subnet']
|
||||
self.resource_id_set(subnet['id'])
|
||||
|
||||
@@ -38,7 +38,7 @@ resources:
|
||||
port_floating:
|
||||
type: OS::Neutron::Port
|
||||
properties:
|
||||
network: xyz1234
|
||||
network: abcd1234
|
||||
fixed_ips:
|
||||
- subnet: sub1234
|
||||
ip_address: 10.0.0.10
|
||||
@@ -135,6 +135,13 @@ class NeutronFloatingIPTest(common.HeatTestCase):
|
||||
return_value=True)
|
||||
|
||||
def test_floating_ip_validate(self):
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'network',
|
||||
'abcd1234',
|
||||
cmd_resource=None,
|
||||
).MultipleTimes().AndReturn('abcd1234')
|
||||
self.m.ReplayAll()
|
||||
t = template_format.parse(neutron_floating_no_assoc_template)
|
||||
stack = utils.parse_stack(t)
|
||||
fip = stack['floating_ip']
|
||||
@@ -146,6 +153,7 @@ class NeutronFloatingIPTest(common.HeatTestCase):
|
||||
fip = stack['floating_ip']
|
||||
self.assertRaises(exception.ResourcePropertyDependency,
|
||||
fip.validate)
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_floating_ip_router_interface(self):
|
||||
t = template_format.parse(neutron_floating_template)
|
||||
@@ -160,26 +168,26 @@ class NeutronFloatingIPTest(common.HeatTestCase):
|
||||
def test_floating_ip_deprecated_router_interface(self):
|
||||
t = template_format.parse(neutron_floating_template_deprecated)
|
||||
del t['resources']['gateway']
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'network',
|
||||
'abcd1234',
|
||||
cmd_resource=None,
|
||||
).MultipleTimes().AndReturn('abcd1234')
|
||||
self._test_floating_ip(t, resolve_neutron=False)
|
||||
self._test_floating_ip(t)
|
||||
|
||||
def test_floating_ip_deprecated_router_gateway(self):
|
||||
t = template_format.parse(neutron_floating_template_deprecated)
|
||||
del t['resources']['router_interface']
|
||||
self._test_floating_ip(t, r_iface=False)
|
||||
|
||||
def _test_floating_ip(self, tmpl, r_iface=True):
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'network',
|
||||
'abcd1234',
|
||||
cmd_resource=None,
|
||||
).MultipleTimes().AndReturn('abcd1234')
|
||||
self._test_floating_ip(t, resolve_neutron=False, r_iface=False)
|
||||
|
||||
def _test_floating_ip(self, tmpl, resolve_neutron=True, r_iface=True):
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'subnet',
|
||||
'sub1234',
|
||||
cmd_resource=None,
|
||||
).MultipleTimes().AndReturn('sub1234')
|
||||
neutronclient.Client.create_floatingip({
|
||||
'floatingip': {'floating_network_id': u'abcd1234'}
|
||||
}).AndReturn({'floatingip': {
|
||||
@@ -203,14 +211,6 @@ class NeutronFloatingIPTest(common.HeatTestCase):
|
||||
'fc68ea2c-b60b-4b4f-bd82-94ec81110766').AndRaise(
|
||||
qe.NeutronClientException(status_code=404))
|
||||
self.stub_NetworkConstraint_validate()
|
||||
if resolve_neutron:
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'network',
|
||||
'abcd1234',
|
||||
cmd_resource=None,
|
||||
).MultipleTimes().AndReturn('abcd1234')
|
||||
|
||||
stack = utils.parse_stack(tmpl)
|
||||
|
||||
# assert the implicit dependency between the floating_ip
|
||||
@@ -247,13 +247,40 @@ class NeutronFloatingIPTest(common.HeatTestCase):
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_FnGetRefId(self):
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'network',
|
||||
'abcd1234',
|
||||
cmd_resource=None,
|
||||
).MultipleTimes().AndReturn('abcd1234')
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'subnet',
|
||||
'sub1234',
|
||||
cmd_resource=None,
|
||||
).MultipleTimes().AndReturn('sub1234')
|
||||
self.m.ReplayAll()
|
||||
t = template_format.parse(neutron_floating_template)
|
||||
stack = utils.parse_stack(t)
|
||||
rsrc = stack['floating_ip']
|
||||
rsrc.resource_id = 'xyz'
|
||||
self.assertEqual('xyz', rsrc.FnGetRefId())
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_FnGetRefId_convergence_cache_data(self):
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'network',
|
||||
'abcd1234',
|
||||
cmd_resource=None,
|
||||
).MultipleTimes().AndReturn('abcd1234')
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'subnet',
|
||||
'sub1234',
|
||||
cmd_resource=None,
|
||||
).MultipleTimes().AndReturn('sub1234')
|
||||
self.m.ReplayAll()
|
||||
t = template_format.parse(neutron_floating_template)
|
||||
template = tmpl.Template(t)
|
||||
stack = parser.Stack(utils.dummy_context(), 'test', template,
|
||||
@@ -275,12 +302,6 @@ class NeutronFloatingIPTest(common.HeatTestCase):
|
||||
'abcd1234',
|
||||
cmd_resource=None,
|
||||
).MultipleTimes().AndReturn('abcd1234')
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'network',
|
||||
'xyz1234',
|
||||
cmd_resource=None,
|
||||
).MultipleTimes().AndReturn('xyz1234')
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'subnet',
|
||||
@@ -295,7 +316,7 @@ class NeutronFloatingIPTest(common.HeatTestCase):
|
||||
}})
|
||||
|
||||
neutronclient.Client.create_port({'port': {
|
||||
'network_id': u'xyz1234',
|
||||
'network_id': u'abcd1234',
|
||||
'fixed_ips': [
|
||||
{'subnet_id': u'sub1234', 'ip_address': u'10.0.0.10'}
|
||||
],
|
||||
@@ -458,7 +479,23 @@ class NeutronFloatingIPTest(common.HeatTestCase):
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
||||
def _test_floating_dependancy(self):
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'network',
|
||||
'abcd1234',
|
||||
cmd_resource=None,
|
||||
).MultipleTimes().AndReturn('abcd1234')
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'router',
|
||||
'subnet_uuid',
|
||||
cmd_resource=None,
|
||||
).MultipleTimes().AndReturn('subnet_uuid')
|
||||
self.m.ReplayAll()
|
||||
|
||||
def test_floatip_port_dependency_subnet(self):
|
||||
self._test_floating_dependancy()
|
||||
t = template_format.parse(neutron_floating_no_assoc_template)
|
||||
stack = utils.parse_stack(t)
|
||||
|
||||
@@ -468,8 +505,10 @@ class NeutronFloatingIPTest(common.HeatTestCase):
|
||||
required_by = set(stack.dependencies.required_by(
|
||||
stack['router_interface']))
|
||||
self.assertIn(stack['floating_ip'], required_by)
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_floatip_port_dependency_network(self):
|
||||
self._test_floating_dependancy()
|
||||
t = template_format.parse(neutron_floating_no_assoc_template)
|
||||
del t['resources']['port_floating']['properties']['fixed_ips']
|
||||
stack = utils.parse_stack(t)
|
||||
@@ -492,22 +531,24 @@ class NeutronFloatingIPTest(common.HeatTestCase):
|
||||
stack['router_interface']))
|
||||
self.assertIn(stack['floating_ip'], required_by)
|
||||
p_show.assert_called_once_with('net_uuid')
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_floatingip_create_specify_ip_address(self):
|
||||
t = template_format.parse(neutron_floating_template)
|
||||
props = t['resources']['floating_ip']['properties']
|
||||
props['floating_ip_address'] = '172.24.4.98'
|
||||
stack = utils.parse_stack(t)
|
||||
|
||||
self.stub_NetworkConstraint_validate()
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'network',
|
||||
'abcd1234',
|
||||
cmd_resource=None,
|
||||
).AndReturn('xyz1234')
|
||||
).MultipleTimes().AndReturn('abcd1234')
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'subnet',
|
||||
'sub1234',
|
||||
cmd_resource=None,
|
||||
).MultipleTimes().AndReturn('sub1234')
|
||||
self.stub_NetworkConstraint_validate()
|
||||
neutronclient.Client.create_floatingip({
|
||||
'floatingip': {'floating_network_id': u'xyz1234',
|
||||
'floatingip': {'floating_network_id': u'abcd1234',
|
||||
'floating_ip_address': '172.24.4.98'}
|
||||
}).AndReturn({'floatingip': {
|
||||
'status': 'ACTIVE',
|
||||
@@ -523,6 +564,10 @@ class NeutronFloatingIPTest(common.HeatTestCase):
|
||||
}})
|
||||
|
||||
self.m.ReplayAll()
|
||||
t = template_format.parse(neutron_floating_template)
|
||||
props = t['resources']['floating_ip']['properties']
|
||||
props['floating_ip_address'] = '172.24.4.98'
|
||||
stack = utils.parse_stack(t)
|
||||
fip = stack['floating_ip']
|
||||
scheduler.TaskRunner(fip.create)()
|
||||
self.assertEqual((fip.CREATE, fip.COMPLETE), fip.state)
|
||||
|
||||
@@ -515,6 +515,12 @@ class NeutronPortTest(common.HeatTestCase):
|
||||
"ip_address": "10.0.0.2"
|
||||
}
|
||||
}})
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'network',
|
||||
'net5678',
|
||||
cmd_resource=None,
|
||||
).MultipleTimes().AndReturn('net5678')
|
||||
|
||||
call_dict = copy.deepcopy(props)
|
||||
call_dict['security_groups'] = [
|
||||
@@ -535,12 +541,6 @@ class NeutronPortTest(common.HeatTestCase):
|
||||
"id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766"
|
||||
}})
|
||||
|
||||
neutronclient.Client.show_port(
|
||||
'fc68ea2c-b60b-4b4f-bd82-94ec81110766'
|
||||
).AndReturn({'port': {
|
||||
"status": "ACTIVE",
|
||||
"id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766"
|
||||
}})
|
||||
neutronclient.Client.update_port(
|
||||
'fc68ea2c-b60b-4b4f-bd82-94ec81110766',
|
||||
{'port': {'fixed_ips': []}}
|
||||
|
||||
@@ -175,7 +175,23 @@ class NeutronRouterTest(common.HeatTestCase):
|
||||
self.assertEqual([u'792ff887-6c85-4a56-b518-23f24fa65581'],
|
||||
rsrc.properties['l3_agent_ids'])
|
||||
|
||||
def _test_validate(self):
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'network',
|
||||
'net1234',
|
||||
cmd_resource=None,
|
||||
).MultipleTimes().AndReturn('net1234')
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'subnet',
|
||||
'sub1234',
|
||||
cmd_resource=None,
|
||||
).MultipleTimes().AndReturn('sub1234')
|
||||
self.m.ReplayAll()
|
||||
|
||||
def test_router_validate_distribute_l3_agents(self):
|
||||
self._test_validate()
|
||||
t = template_format.parse(neutron_template)
|
||||
props = t['resources']['router']['properties']
|
||||
|
||||
@@ -195,8 +211,10 @@ class NeutronRouterTest(common.HeatTestCase):
|
||||
rsrc.validate)
|
||||
self.assertIn('distributed, l3_agent_id/l3_agent_ids',
|
||||
six.text_type(exc))
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_router_validate_l3_agents(self):
|
||||
self._test_validate()
|
||||
t = template_format.parse(neutron_template)
|
||||
props = t['resources']['router']['properties']
|
||||
|
||||
@@ -209,8 +227,10 @@ class NeutronRouterTest(common.HeatTestCase):
|
||||
self.assertIn('Non HA routers can only have one L3 agent',
|
||||
six.text_type(exc))
|
||||
self.assertIsNone(rsrc.properties.get(rsrc.L3_AGENT_ID))
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_router_validate_ha_distribute(self):
|
||||
self._test_validate()
|
||||
t = template_format.parse(neutron_template)
|
||||
props = t['resources']['router']['properties']
|
||||
|
||||
@@ -223,8 +243,10 @@ class NeutronRouterTest(common.HeatTestCase):
|
||||
exc = self.assertRaises(exception.ResourcePropertyConflict,
|
||||
rsrc.validate)
|
||||
self.assertIn('distributed, ha', six.text_type(exc))
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_router_validate_ha_l3_agents(self):
|
||||
self._test_validate()
|
||||
t = template_format.parse(neutron_template)
|
||||
props = t['resources']['router']['properties']
|
||||
# test non ha can not specify more than one l3 agent id
|
||||
@@ -236,6 +258,7 @@ class NeutronRouterTest(common.HeatTestCase):
|
||||
rsrc.validate)
|
||||
self.assertIn('Non HA routers can only have one L3 agent.',
|
||||
six.text_type(exc))
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_router(self):
|
||||
neutronclient.Client.create_router({
|
||||
@@ -465,6 +488,18 @@ class NeutronRouterTest(common.HeatTestCase):
|
||||
self._test_router_interface(resolve_router=False)
|
||||
|
||||
def _test_router_interface(self, resolve_router=True):
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'router',
|
||||
'3e46229d-8fce-4733-819a-b5fe630550f8',
|
||||
cmd_resource=None,
|
||||
).AndReturn('3e46229d-8fce-4733-819a-b5fe630550f8')
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'subnet',
|
||||
'91e47a57-7508-46fe-afc9-fc454e8580e1',
|
||||
cmd_resource=None,
|
||||
).AndReturn('91e47a57-7508-46fe-afc9-fc454e8580e1')
|
||||
neutronclient.Client.add_interface_router(
|
||||
'3e46229d-8fce-4733-819a-b5fe630550f8',
|
||||
{'subnet_id': '91e47a57-7508-46fe-afc9-fc454e8580e1'}
|
||||
@@ -522,14 +557,14 @@ class NeutronRouterTest(common.HeatTestCase):
|
||||
'router',
|
||||
'3e46229d-8fce-4733-819a-b5fe630550f8',
|
||||
cmd_resource=None,
|
||||
).AndReturn('3e46229d-8fce-4733-819a-b5fe630550f8')
|
||||
).MultipleTimes().AndReturn('3e46229d-8fce-4733-819a-b5fe630550f8')
|
||||
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'subnet',
|
||||
'91e47a57-7508-46fe-afc9-fc454e8580e1',
|
||||
cmd_resource=None,
|
||||
).AndReturn('91e47a57-7508-46fe-afc9-fc454e8580e1')
|
||||
).MultipleTimes().AndReturn('91e47a57-7508-46fe-afc9-fc454e8580e1')
|
||||
neutronclient.Client.add_interface_router(
|
||||
'3e46229d-8fce-4733-819a-b5fe630550f8',
|
||||
{'subnet_id': '91e47a57-7508-46fe-afc9-fc454e8580e1'}
|
||||
@@ -572,20 +607,18 @@ class NeutronRouterTest(common.HeatTestCase):
|
||||
self._test_router_interface_with_port(resolve_port=False)
|
||||
|
||||
def _test_router_interface_with_port(self, resolve_port=True):
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'router',
|
||||
'ae478782-53c0-4434-ab16-49900c88016c',
|
||||
cmd_resource=None,
|
||||
).AndReturn('ae478782-53c0-4434-ab16-49900c88016c')
|
||||
port_key = 'port'
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'port',
|
||||
'9577cafd-8e98-4059-a2e6-8a771b4d318e',
|
||||
cmd_resource=None,
|
||||
).AndReturn('9577cafd-8e98-4059-a2e6-8a771b4d318e')
|
||||
|
||||
).MultipleTimes().AndReturn('9577cafd-8e98-4059-a2e6-8a771b4d318e')
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'router',
|
||||
'ae478782-53c0-4434-ab16-49900c88016c',
|
||||
cmd_resource=None,
|
||||
).MultipleTimes().AndReturn('ae478782-53c0-4434-ab16-49900c88016c')
|
||||
neutronclient.Client.add_interface_router(
|
||||
'ae478782-53c0-4434-ab16-49900c88016c',
|
||||
{'port_id': '9577cafd-8e98-4059-a2e6-8a771b4d318e'}
|
||||
@@ -609,7 +642,7 @@ class NeutronRouterTest(common.HeatTestCase):
|
||||
rsrc = self.create_router_interface(
|
||||
t, stack, 'router_interface', properties={
|
||||
'router': 'ae478782-53c0-4434-ab16-49900c88016c',
|
||||
port_key: '9577cafd-8e98-4059-a2e6-8a771b4d318e'
|
||||
'port': '9577cafd-8e98-4059-a2e6-8a771b4d318e'
|
||||
})
|
||||
|
||||
# Ensure that properties correctly translates
|
||||
@@ -624,6 +657,25 @@ class NeutronRouterTest(common.HeatTestCase):
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_router_interface_validate(self):
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'port',
|
||||
'9577cafd-8e98-4059-a2e6-8a771b4d318e',
|
||||
cmd_resource=None,
|
||||
).MultipleTimes().AndReturn('9577cafd-8e98-4059-a2e6-8a771b4d318e')
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'router',
|
||||
'ae478782-53c0-4434-ab16-49900c88016c',
|
||||
cmd_resource=None,
|
||||
).MultipleTimes().AndReturn('ae478782-53c0-4434-ab16-49900c88016c')
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'subnet',
|
||||
'9577cafd-8e98-4059-a2e6-8a771b4d318e',
|
||||
cmd_resource=None,
|
||||
).MultipleTimes().AndReturn('9577cafd-8e98-4059-a2e6-8a771b4d318e')
|
||||
self.m.ReplayAll()
|
||||
t = template_format.parse(neutron_template)
|
||||
json = t['resources']['router_interface']
|
||||
json['properties'] = {
|
||||
@@ -666,6 +718,7 @@ class NeutronRouterTest(common.HeatTestCase):
|
||||
self.assertEqual("At least one of the following properties "
|
||||
"must be specified: subnet, port",
|
||||
six.text_type(ex))
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_gateway_router(self):
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
@@ -707,7 +760,13 @@ class NeutronRouterTest(common.HeatTestCase):
|
||||
'network',
|
||||
'public',
|
||||
cmd_resource=None,
|
||||
).MultipleTimes().AndReturn('fc68ea2c-b60b-4b4f-bd82-94ec81110766')
|
||||
).AndReturn('fc68ea2c-b60b-4b4f-bd82-94ec81110766')
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'network',
|
||||
'fc68ea2c-b60b-4b4f-bd82-94ec81110766',
|
||||
cmd_resource=None,
|
||||
).AndReturn('fc68ea2c-b60b-4b4f-bd82-94ec81110766')
|
||||
|
||||
neutronclient.Client.create_router({
|
||||
"router": {
|
||||
@@ -748,7 +807,6 @@ class NeutronRouterTest(common.HeatTestCase):
|
||||
|
||||
def test_create_router_gateway_as_property(self):
|
||||
self._create_router_with_gateway()
|
||||
|
||||
neutronclient.Client.show_router(
|
||||
'3e46229d-8fce-4733-819a-b5fe630550f8').AndReturn({
|
||||
"router": {
|
||||
@@ -770,9 +828,7 @@ class NeutronRouterTest(common.HeatTestCase):
|
||||
t = template_format.parse(neutron_external_gateway_template)
|
||||
stack = utils.parse_stack(t)
|
||||
rsrc = self.create_router(t, stack, 'router')
|
||||
|
||||
rsrc.validate()
|
||||
|
||||
ref_id = rsrc.FnGetRefId()
|
||||
self.assertEqual('3e46229d-8fce-4733-819a-b5fe630550f8', ref_id)
|
||||
gateway_info = rsrc.FnGetAtt('external_gateway_info')
|
||||
@@ -788,6 +844,12 @@ class NeutronRouterTest(common.HeatTestCase):
|
||||
'public',
|
||||
cmd_resource=None,
|
||||
).AndReturn('fc68ea2c-b60b-4b4f-bd82-94ec81110766')
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'network',
|
||||
'fc68ea2c-b60b-4b4f-bd82-94ec81110766',
|
||||
cmd_resource=None,
|
||||
).AndReturn('fc68ea2c-b60b-4b4f-bd82-94ec81110766')
|
||||
|
||||
neutronclient.Client.create_router({
|
||||
"router": {
|
||||
@@ -843,13 +905,24 @@ class NeutronRouterTest(common.HeatTestCase):
|
||||
|
||||
def test_update_router_gateway_as_property(self):
|
||||
self._create_router_with_gateway()
|
||||
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'network',
|
||||
'other_public',
|
||||
cmd_resource=None,
|
||||
).AndReturn('91e47a57-7508-46fe-afc9-fc454e8580e1')
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'network',
|
||||
'fc68ea2c-b60b-4b4f-bd82-94ec81110766',
|
||||
cmd_resource=None,
|
||||
).AndReturn('fc68ea2c-b60b-4b4f-bd82-94ec81110766')
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'network',
|
||||
'91e47a57-7508-46fe-afc9-fc454e8580e1',
|
||||
cmd_resource=None,
|
||||
).AndReturn('91e47a57-7508-46fe-afc9-fc454e8580e1')
|
||||
|
||||
neutronclient.Client.update_router(
|
||||
'3e46229d-8fce-4733-819a-b5fe630550f8',
|
||||
|
||||
@@ -128,12 +128,6 @@ class NeutronSubnetTest(common.HeatTestCase):
|
||||
{'start': '10.0.3.110', 'end': '10.0.3.200'}]}}
|
||||
|
||||
t = self._test_subnet(u_props=update_props)
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'network',
|
||||
'None',
|
||||
cmd_resource=None,
|
||||
).AndReturn('None')
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'router',
|
||||
@@ -188,12 +182,6 @@ class NeutronSubnetTest(common.HeatTestCase):
|
||||
del update_props_merged['subnet']['value_specs']
|
||||
|
||||
t = self._test_subnet(u_props=update_props_merged)
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'network',
|
||||
'None',
|
||||
cmd_resource=None,
|
||||
).AndReturn('None')
|
||||
stack = utils.parse_stack(t)
|
||||
rsrc = self.create_subnet(t, stack, 'sub_net')
|
||||
self.m.ReplayAll()
|
||||
@@ -224,13 +212,6 @@ class NeutronSubnetTest(common.HeatTestCase):
|
||||
'name': utils.PhysName('test_stack', 'test_subnet'),
|
||||
}}
|
||||
t = self._test_subnet(u_props=update_props_name)
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'network',
|
||||
'None',
|
||||
cmd_resource=None,
|
||||
).AndReturn('None')
|
||||
|
||||
stack = utils.parse_stack(t)
|
||||
rsrc = self.create_subnet(t, stack, 'sub_net')
|
||||
self.m.ReplayAll()
|
||||
@@ -277,19 +258,7 @@ class NeutronSubnetTest(common.HeatTestCase):
|
||||
'subnetpool',
|
||||
'None',
|
||||
cmd_resource=None,
|
||||
).AndReturn('None')
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'network',
|
||||
'None',
|
||||
cmd_resource=None,
|
||||
).AndReturn('None')
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'subnetpool',
|
||||
'None',
|
||||
cmd_resource=None,
|
||||
).AndReturn('None')
|
||||
).MultipleTimes().AndReturn('None')
|
||||
neutronclient.Client.create_subnet({
|
||||
'subnet': {
|
||||
'network_id': u'None',
|
||||
@@ -337,22 +306,15 @@ class NeutronSubnetTest(common.HeatTestCase):
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_subnet_deprecated(self):
|
||||
|
||||
t = self._test_subnet(resolve_neutron=False)
|
||||
stack = utils.parse_stack(t)
|
||||
rsrc = self.create_subnet(t, stack, 'sub_net')
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'network',
|
||||
'None',
|
||||
cmd_resource=None,
|
||||
).AndReturn('None')
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'router',
|
||||
'None',
|
||||
cmd_resource=None,
|
||||
).AndReturn('None')
|
||||
).MultipleTimes().AndReturn('None')
|
||||
t = self._test_subnet(resolve_neutron=False)
|
||||
stack = utils.parse_stack(t)
|
||||
rsrc = self.create_subnet(t, stack, 'sub_net')
|
||||
self.m.ReplayAll()
|
||||
scheduler.TaskRunner(rsrc.create)()
|
||||
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
|
||||
@@ -465,12 +427,6 @@ class NeutronSubnetTest(common.HeatTestCase):
|
||||
return t
|
||||
|
||||
def test_subnet_disable_dhcp(self):
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'network',
|
||||
'None',
|
||||
cmd_resource=None,
|
||||
).AndReturn('None')
|
||||
neutronclient.Client.create_subnet({
|
||||
'subnet': {
|
||||
'name': utils.PhysName('test_stack', 'test_subnet'),
|
||||
@@ -590,12 +546,6 @@ class NeutronSubnetTest(common.HeatTestCase):
|
||||
}, p)
|
||||
|
||||
def test_ipv6_subnet(self):
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'network',
|
||||
'None',
|
||||
cmd_resource=None,
|
||||
).AndReturn('None')
|
||||
neutronclient.Client.create_subnet({
|
||||
'subnet': {
|
||||
'name': utils.PhysName('test_stack', 'test_subnet'),
|
||||
@@ -686,6 +636,19 @@ class NeutronSubnetTest(common.HeatTestCase):
|
||||
"supported for ipv4.", six.text_type(ex))
|
||||
|
||||
def test_validate_both_subnetpool_cidr(self):
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'subnetpool',
|
||||
'new_pool',
|
||||
cmd_resource=None,
|
||||
).AndReturn('new_pool')
|
||||
neutronV20.find_resourceid_by_name_or_id(
|
||||
mox.IsA(neutronclient.Client),
|
||||
'subnetpool',
|
||||
'new_pool',
|
||||
cmd_resource=None,
|
||||
).AndReturn('new_pool')
|
||||
self.m.ReplayAll()
|
||||
t = template_format.parse(neutron_template)
|
||||
props = t['resources']['sub_net']['properties']
|
||||
props['subnetpool'] = 'new_pool'
|
||||
@@ -696,6 +659,7 @@ class NeutronSubnetTest(common.HeatTestCase):
|
||||
msg = ("Cannot define the following properties at the same time: "
|
||||
"subnetpool, cidr.")
|
||||
self.assertEqual(msg, six.text_type(ex))
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_validate_none_subnetpool_cidr(self):
|
||||
t = template_format.parse(neutron_template)
|
||||
|
||||
@@ -305,6 +305,9 @@ class ServersTest(common.HeatTestCase):
|
||||
self.stub_VolumeConstraint_validate()
|
||||
|
||||
def test_subnet_dependency(self):
|
||||
self.resolve = self.patchobject(neutronV20,
|
||||
'find_resourceid_by_name_or_id')
|
||||
self.resolve.return_value = '12345'
|
||||
template, stack = self._setup_test_stack('subnet-test',
|
||||
subnet_template)
|
||||
server_rsrc = stack['server']
|
||||
@@ -315,6 +318,9 @@ class ServersTest(common.HeatTestCase):
|
||||
self.assertEqual(subnet_rsrc, deps[3])
|
||||
|
||||
def test_subnet_nodeps(self):
|
||||
self.resolve = self.patchobject(neutronV20,
|
||||
'find_resourceid_by_name_or_id')
|
||||
self.resolve.return_value = '12345'
|
||||
template, stack = self._setup_test_stack('subnet-test',
|
||||
no_subnet_template)
|
||||
server_rsrc = stack['server']
|
||||
|
||||
Reference in New Issue
Block a user