Group Policy API-4 HEAT resource: Network Service Policy
This is the fourth patch in the Group Policy resources implementation series. This patch implements: Network Service Policy Change-Id: I7839d74740fd08cfa176df81cac7f5580d796740 Implements: blueprint group-based-policy-automation
This commit is contained in:
parent
ca098b6bc5
commit
12ef099a43
|
@ -110,10 +110,10 @@ class EndpointGroup(gbpresource.GBPResource):
|
||||||
|
|
||||||
PROPERTIES = (
|
PROPERTIES = (
|
||||||
TENANT_ID, NAME, DESCRIPTION, L2_POLICY_ID,
|
TENANT_ID, NAME, DESCRIPTION, L2_POLICY_ID,
|
||||||
PROVIDED_CONTRACTS, CONSUMED_CONTRACTS
|
PROVIDED_CONTRACTS, CONSUMED_CONTRACTS, NETWORK_SERVICE_POLICY_ID
|
||||||
) = (
|
) = (
|
||||||
'tenant_id', 'name', 'description', 'l2_policy_id',
|
'tenant_id', 'name', 'description', 'l2_policy_id',
|
||||||
'provided_contracts', 'consumed_contracts'
|
'provided_contracts', 'consumed_contracts', 'network_service_policy_id'
|
||||||
)
|
)
|
||||||
|
|
||||||
properties_schema = {
|
properties_schema = {
|
||||||
|
@ -145,6 +145,11 @@ class EndpointGroup(gbpresource.GBPResource):
|
||||||
properties.Schema.LIST,
|
properties.Schema.LIST,
|
||||||
_('Consumed contracts for the endpoint group.'),
|
_('Consumed contracts for the endpoint group.'),
|
||||||
update_allowed=True
|
update_allowed=True
|
||||||
|
),
|
||||||
|
NETWORK_SERVICE_POLICY_ID: properties.Schema(
|
||||||
|
properties.Schema.STRING,
|
||||||
|
_('Network service policy id of the endpoint group.'),
|
||||||
|
update_allowed=True, default=None
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -663,6 +668,73 @@ class Contract(gbpresource.GBPResource):
|
||||||
self.resource_id, {'contract': prop_diff})
|
self.resource_id, {'contract': prop_diff})
|
||||||
|
|
||||||
|
|
||||||
|
class NetworkServicePolicy(gbpresource.GBPResource):
|
||||||
|
|
||||||
|
PROPERTIES = (
|
||||||
|
TENANT_ID, NAME, DESCRIPTION, NETWORK_SERVICE_PARAMS
|
||||||
|
) = (
|
||||||
|
'tenant_id', 'name', 'description', 'network_service_params'
|
||||||
|
)
|
||||||
|
|
||||||
|
properties_schema = {
|
||||||
|
TENANT_ID: properties.Schema(
|
||||||
|
properties.Schema.STRING,
|
||||||
|
_('Tenant id of the network service policy.')
|
||||||
|
),
|
||||||
|
NAME: properties.Schema(
|
||||||
|
properties.Schema.STRING,
|
||||||
|
_('Name of the network service policy.'),
|
||||||
|
update_allowed=True
|
||||||
|
),
|
||||||
|
DESCRIPTION: properties.Schema(
|
||||||
|
properties.Schema.STRING,
|
||||||
|
_('Description of the network service policy.'),
|
||||||
|
update_allowed=True
|
||||||
|
),
|
||||||
|
NETWORK_SERVICE_PARAMS: properties.Schema(
|
||||||
|
properties.Schema.LIST,
|
||||||
|
_('List of network service policy dicts.'),
|
||||||
|
default=None, update_allowed=True
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
def _show_resource(self):
|
||||||
|
client = self.grouppolicy()
|
||||||
|
nsp_id = self.resource_id
|
||||||
|
nsp = client.show_network_service_policy(nsp_id)
|
||||||
|
return nsp['network_service_policy']
|
||||||
|
|
||||||
|
def handle_create(self):
|
||||||
|
client = self.grouppolicy()
|
||||||
|
|
||||||
|
props = {}
|
||||||
|
for key in self.properties:
|
||||||
|
if self.properties.get(key) is not None:
|
||||||
|
props[key] = self.properties.get(key)
|
||||||
|
|
||||||
|
nsp = client.create_network_service_policy(
|
||||||
|
{'network_service_policy': props})['network_service_policy']
|
||||||
|
|
||||||
|
self.resource_id_set(nsp['id'])
|
||||||
|
|
||||||
|
def handle_delete(self):
|
||||||
|
|
||||||
|
client = self.grouppolicy()
|
||||||
|
nsp_id = self.resource_id
|
||||||
|
|
||||||
|
try:
|
||||||
|
client.delete_network_service_policy(nsp_id)
|
||||||
|
except NeutronClientException as ex:
|
||||||
|
self.client_plugin().ignore_not_found(ex)
|
||||||
|
else:
|
||||||
|
return self._delete_task()
|
||||||
|
|
||||||
|
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
|
||||||
|
if prop_diff:
|
||||||
|
self.grouppolicy().update_network_service_policy(
|
||||||
|
self.resource_id, {'network_service_policy': prop_diff})
|
||||||
|
|
||||||
|
|
||||||
def resource_mapping():
|
def resource_mapping():
|
||||||
return {
|
return {
|
||||||
'OS::Neutron::Endpoint': Endpoint,
|
'OS::Neutron::Endpoint': Endpoint,
|
||||||
|
@ -672,5 +744,6 @@ def resource_mapping():
|
||||||
'OS::Neutron::PolicyClassifier': PolicyClassifier,
|
'OS::Neutron::PolicyClassifier': PolicyClassifier,
|
||||||
'OS::Neutron::PolicyAction': PolicyAction,
|
'OS::Neutron::PolicyAction': PolicyAction,
|
||||||
'OS::Neutron::PolicyRule': PolicyRule,
|
'OS::Neutron::PolicyRule': PolicyRule,
|
||||||
'OS::Neutron::Contract': Contract
|
'OS::Neutron::Contract': Contract,
|
||||||
|
'OS::Neutron::NetworkServicePolicy': NetworkServicePolicy
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,6 +184,25 @@ contract_template = '''
|
||||||
}
|
}
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
network_service_policy_template = '''
|
||||||
|
{
|
||||||
|
"AWSTemplateFormatVersion" : "2010-09-09",
|
||||||
|
"Description" : "Template to test network service policy",
|
||||||
|
"Parameters" : {},
|
||||||
|
"Resources" : {
|
||||||
|
"network_service_policy": {
|
||||||
|
"Type": "OS::Neutron::NetworkServicePolicy",
|
||||||
|
"Properties": {
|
||||||
|
"name": "test-nsp",
|
||||||
|
"description": "test NSP resource",
|
||||||
|
"network_service_params": [{'type': 'ip_single', 'name': 'vip',
|
||||||
|
'value': 'self_subnet'}]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
class EndpointTest(HeatTestCase):
|
class EndpointTest(HeatTestCase):
|
||||||
|
|
||||||
|
@ -1106,3 +1125,123 @@ class ContractTest(HeatTestCase):
|
||||||
scheduler.TaskRunner(rsrc.update, update_template)()
|
scheduler.TaskRunner(rsrc.update, update_template)()
|
||||||
|
|
||||||
self.m.VerifyAll()
|
self.m.VerifyAll()
|
||||||
|
|
||||||
|
|
||||||
|
class NetworkServicePolicyTest(HeatTestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(NetworkServicePolicyTest, self).setUp()
|
||||||
|
self.m.StubOutWithMock(gbpclient.Client,
|
||||||
|
'create_network_service_policy')
|
||||||
|
self.m.StubOutWithMock(gbpclient.Client,
|
||||||
|
'delete_network_service_policy')
|
||||||
|
self.m.StubOutWithMock(gbpclient.Client,
|
||||||
|
'show_network_service_policy')
|
||||||
|
self.m.StubOutWithMock(gbpclient.Client,
|
||||||
|
'update_network_service_policy')
|
||||||
|
self.stub_keystoneclient()
|
||||||
|
|
||||||
|
def create_network_service_policy(self):
|
||||||
|
gbpclient.Client.create_network_service_policy({
|
||||||
|
'network_service_policy': {
|
||||||
|
"name": "test-nsp",
|
||||||
|
"description": "test NSP resource",
|
||||||
|
"network_service_params": [
|
||||||
|
{'type': 'ip_single', 'name': 'vip',
|
||||||
|
'value': 'self_subnet'}]
|
||||||
|
}
|
||||||
|
}).AndReturn({'network_service_policy': {'id': '5678'}})
|
||||||
|
|
||||||
|
snippet = template_format.parse(network_service_policy_template)
|
||||||
|
stack = utils.parse_stack(snippet)
|
||||||
|
resource_defns = stack.t.resource_definitions(stack)
|
||||||
|
return grouppolicy.NetworkServicePolicy(
|
||||||
|
'network_service_policy',
|
||||||
|
resource_defns['network_service_policy'], stack)
|
||||||
|
|
||||||
|
def test_create(self):
|
||||||
|
rsrc = self.create_network_service_policy()
|
||||||
|
self.m.ReplayAll()
|
||||||
|
scheduler.TaskRunner(rsrc.create)()
|
||||||
|
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
|
||||||
|
self.m.VerifyAll()
|
||||||
|
|
||||||
|
def test_create_failed(self):
|
||||||
|
gbpclient.Client.create_network_service_policy({
|
||||||
|
'network_service_policy': {
|
||||||
|
"name": "test-nsp",
|
||||||
|
"description": "test NSP resource",
|
||||||
|
"network_service_params": [
|
||||||
|
{'type': 'ip_single', 'name': 'vip',
|
||||||
|
'value': 'self_subnet'}]
|
||||||
|
}
|
||||||
|
}).AndRaise(grouppolicy.NeutronClientException())
|
||||||
|
self.m.ReplayAll()
|
||||||
|
|
||||||
|
snippet = template_format.parse(network_service_policy_template)
|
||||||
|
stack = utils.parse_stack(snippet)
|
||||||
|
resource_defns = stack.t.resource_definitions(stack)
|
||||||
|
rsrc = grouppolicy.NetworkServicePolicy(
|
||||||
|
'network_service_policy',
|
||||||
|
resource_defns['network_service_policy'], stack)
|
||||||
|
|
||||||
|
error = self.assertRaises(exception.ResourceFailure,
|
||||||
|
scheduler.TaskRunner(rsrc.create))
|
||||||
|
self.assertEqual(
|
||||||
|
'NeutronClientException: An unknown exception occurred.',
|
||||||
|
str(error))
|
||||||
|
self.assertEqual((rsrc.CREATE, rsrc.FAILED), rsrc.state)
|
||||||
|
self.m.VerifyAll()
|
||||||
|
|
||||||
|
def test_delete(self):
|
||||||
|
gbpclient.Client.delete_network_service_policy('5678')
|
||||||
|
gbpclient.Client.show_network_service_policy('5678').AndRaise(
|
||||||
|
grouppolicy.NeutronClientException(status_code=404))
|
||||||
|
|
||||||
|
rsrc = self.create_network_service_policy()
|
||||||
|
self.m.ReplayAll()
|
||||||
|
scheduler.TaskRunner(rsrc.create)()
|
||||||
|
scheduler.TaskRunner(rsrc.delete)()
|
||||||
|
self.assertEqual((rsrc.DELETE, rsrc.COMPLETE), rsrc.state)
|
||||||
|
self.m.VerifyAll()
|
||||||
|
|
||||||
|
def test_delete_already_gone(self):
|
||||||
|
gbpclient.Client.delete_network_service_policy('5678').AndRaise(
|
||||||
|
grouppolicy.NeutronClientException(status_code=404))
|
||||||
|
|
||||||
|
rsrc = self.create_network_service_policy()
|
||||||
|
self.m.ReplayAll()
|
||||||
|
scheduler.TaskRunner(rsrc.create)()
|
||||||
|
scheduler.TaskRunner(rsrc.delete)()
|
||||||
|
self.assertEqual((rsrc.DELETE, rsrc.COMPLETE), rsrc.state)
|
||||||
|
self.m.VerifyAll()
|
||||||
|
|
||||||
|
def test_delete_failed(self):
|
||||||
|
gbpclient.Client.delete_network_service_policy('5678').AndRaise(
|
||||||
|
grouppolicy.NeutronClientException(status_code=400))
|
||||||
|
|
||||||
|
rsrc = self.create_network_service_policy()
|
||||||
|
self.m.ReplayAll()
|
||||||
|
scheduler.TaskRunner(rsrc.create)()
|
||||||
|
error = self.assertRaises(exception.ResourceFailure,
|
||||||
|
scheduler.TaskRunner(rsrc.delete))
|
||||||
|
self.assertEqual(
|
||||||
|
'NeutronClientException: An unknown exception occurred.',
|
||||||
|
str(error))
|
||||||
|
self.assertEqual((rsrc.DELETE, rsrc.FAILED), rsrc.state)
|
||||||
|
self.m.VerifyAll()
|
||||||
|
|
||||||
|
def test_update(self):
|
||||||
|
rsrc = self.create_network_service_policy()
|
||||||
|
gbpclient.Client.update_network_service_policy(
|
||||||
|
'5678', {'network_service_policy':
|
||||||
|
{'network_service_params': [{'name': 'vip-update'}]}})
|
||||||
|
self.m.ReplayAll()
|
||||||
|
scheduler.TaskRunner(rsrc.create)()
|
||||||
|
|
||||||
|
update_template = copy.deepcopy(rsrc.t)
|
||||||
|
update_template['Properties']['network_service_params'] = [
|
||||||
|
{'name': 'vip-update'}]
|
||||||
|
scheduler.TaskRunner(rsrc.update, update_template)()
|
||||||
|
|
||||||
|
self.m.VerifyAll()
|
||||||
|
|
Loading…
Reference in New Issue