Add tags support for ProviderNet resource
Edit OS::Neutron::ProviderNet resource to add tag attribute as allowed in Neutron API Change-Id: I792dadbd671edbf1fc5706df524a5335777be800 Story: 2004181 Task: 27669
This commit is contained in:
parent
cb5dce1987
commit
8258f3f120
@ -37,11 +37,11 @@ class ProviderNet(net.Net):
|
||||
PROPERTIES = (
|
||||
NAME, PROVIDER_NETWORK_TYPE, PROVIDER_PHYSICAL_NETWORK,
|
||||
PROVIDER_SEGMENTATION_ID, ADMIN_STATE_UP, SHARED,
|
||||
PORT_SECURITY_ENABLED, ROUTER_EXTERNAL,
|
||||
PORT_SECURITY_ENABLED, ROUTER_EXTERNAL, TAGS,
|
||||
) = (
|
||||
'name', 'network_type', 'physical_network',
|
||||
'segmentation_id', 'admin_state_up', 'shared',
|
||||
'port_security_enabled', 'router_external',
|
||||
'port_security_enabled', 'router_external', 'tags',
|
||||
|
||||
)
|
||||
|
||||
@ -103,6 +103,13 @@ class ProviderNet(net.Net):
|
||||
update_allowed=True,
|
||||
support_status=support.SupportStatus(version='6.0.0')
|
||||
),
|
||||
TAGS: properties.Schema(
|
||||
properties.Schema.LIST,
|
||||
_('The tags to be added to the provider network.'),
|
||||
schema=properties.Schema(properties.Schema.STRING),
|
||||
update_allowed=True,
|
||||
support_status=support.SupportStatus(version='12.0.0')
|
||||
),
|
||||
}
|
||||
|
||||
attributes_schema = {
|
||||
@ -161,10 +168,14 @@ class ProviderNet(net.Net):
|
||||
self.physical_resource_name())
|
||||
|
||||
ProviderNet.prepare_provider_properties(props)
|
||||
tags = props.pop(self.TAGS, [])
|
||||
|
||||
prov_net = self.client().create_network({'network': props})['network']
|
||||
self.resource_id_set(prov_net['id'])
|
||||
|
||||
if tags:
|
||||
self.set_tags(tags)
|
||||
|
||||
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
|
||||
"""Updates the resource with provided properties.
|
||||
|
||||
@ -173,6 +184,9 @@ class ProviderNet(net.Net):
|
||||
if prop_diff:
|
||||
ProviderNet.prepare_provider_properties(prop_diff)
|
||||
self.prepare_update_properties(prop_diff)
|
||||
if self.TAGS in prop_diff:
|
||||
self.set_tags(prop_diff.pop(self.TAGS))
|
||||
if prop_diff:
|
||||
self.client().update_network(self.resource_id,
|
||||
{'network': prop_diff})
|
||||
|
||||
|
@ -40,6 +40,9 @@ resources:
|
||||
segmentation_id: 101
|
||||
router_external: False
|
||||
shared: true
|
||||
tags:
|
||||
- tag1
|
||||
- tag2
|
||||
'''
|
||||
|
||||
stpna = {
|
||||
@ -54,7 +57,7 @@ stpna = {
|
||||
"provider:segmentation_id": "101",
|
||||
"router:external": False,
|
||||
"tenant_id": "c1210485b2424d48804aad5d39c61b8f",
|
||||
"id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766"
|
||||
"id": "fc68ea2c-b60b-4b4f-bd82-94ec81110766",
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,6 +88,7 @@ class NeutronProviderNetTest(common.HeatTestCase):
|
||||
return rsrc
|
||||
|
||||
def test_create_provider_net(self):
|
||||
resource_type = 'networks'
|
||||
rsrc = self.create_provider_net()
|
||||
self.mockclient.show_network.side_effect = [
|
||||
stpnb,
|
||||
@ -127,6 +131,11 @@ class NeutronProviderNetTest(common.HeatTestCase):
|
||||
'shared': True
|
||||
}
|
||||
})
|
||||
self.mockclient.replace_tag.assert_called_with(
|
||||
resource_type,
|
||||
'fc68ea2c-b60b-4b4f-bd82-94ec81110766',
|
||||
{'tags': ['tag1', 'tag2']}
|
||||
)
|
||||
self.mockclient.show_network.assert_called_with(
|
||||
'fc68ea2c-b60b-4b4f-bd82-94ec81110766')
|
||||
self.assertEqual(5, self.mockclient.show_network.call_count)
|
||||
@ -135,6 +144,7 @@ class NeutronProviderNetTest(common.HeatTestCase):
|
||||
self.assertEqual(2, self.mockclient.delete_network.call_count)
|
||||
|
||||
def test_update_provider_net(self):
|
||||
resource_type = 'networks'
|
||||
rsrc = self.create_provider_net()
|
||||
self.mockclient.show_network.side_effect = [stpnb, stpna]
|
||||
self.mockclient.update_network.return_value = None
|
||||
@ -149,7 +159,8 @@ class NeutronProviderNetTest(common.HeatTestCase):
|
||||
'physical_network': 'physnet_1',
|
||||
'segmentation_id': '102',
|
||||
'port_security_enabled': False,
|
||||
'router_external': True
|
||||
'router_external': True,
|
||||
'tags': [],
|
||||
}
|
||||
update_snippet = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(),
|
||||
prop_diff)
|
||||
@ -171,6 +182,11 @@ class NeutronProviderNetTest(common.HeatTestCase):
|
||||
'router:external': False,
|
||||
'shared': True}
|
||||
})
|
||||
self.mockclient.replace_tag.assert_called_with(
|
||||
resource_type,
|
||||
'fc68ea2c-b60b-4b4f-bd82-94ec81110766',
|
||||
{'tags': []}
|
||||
)
|
||||
self.mockclient.show_network.assert_called_with(
|
||||
'fc68ea2c-b60b-4b4f-bd82-94ec81110766')
|
||||
self.assertEqual(2, self.mockclient.show_network.call_count)
|
||||
@ -214,6 +230,7 @@ class NeutronProviderNetTest(common.HeatTestCase):
|
||||
'provider:network_type': 'flat',
|
||||
'id': 'af216806-4462-4c68-bfa4-9580857e71c3',
|
||||
'provider:segmentation_id': None,
|
||||
'tags': ['tag1', 'tag2'],
|
||||
}
|
||||
}
|
||||
|
||||
@ -225,7 +242,8 @@ class NeutronProviderNetTest(common.HeatTestCase):
|
||||
'network_type': 'flat',
|
||||
'port_security_enabled': True,
|
||||
'segmentation_id': None,
|
||||
'router_external': False
|
||||
'router_external': False,
|
||||
'tags': ['tag1', 'tag2'],
|
||||
}
|
||||
|
||||
self.assertEqual(expected, reality)
|
||||
|
@ -0,0 +1,3 @@
|
||||
---
|
||||
features:
|
||||
- Add tags support for ProviderNet resource
|
Loading…
Reference in New Issue
Block a user