Add Service Profile, shared attr, GBP namespace
Partially implements blueprint node-centric-chain-plugin Changes namespace for Service Chain resources to OS:GroupBasedPolicy Closes-bug: 1476803 Adds shared attribute for Service Chain resources Closes-bug: 1475461 Also updates test-requirements to sync with global requirements. Change-Id: I7c535dbadbe68ed5ba51f5ac63418af3100d7737
This commit is contained in:
parent
61a2c9cfb0
commit
e2d6566643
|
@ -22,9 +22,9 @@ from neutronclient.common.exceptions import NeutronClientException
|
|||
class ServiceChainNode(gbpresource.GBPResource):
|
||||
|
||||
PROPERTIES = (
|
||||
TENANT_ID, NAME, DESCRIPTION, SERVICE_TYPE, CONFIG
|
||||
TENANT_ID, NAME, DESCRIPTION, SERVICE_TYPE, CONFIG, SHARED
|
||||
) = (
|
||||
'tenant_id', 'name', 'description', 'service_type', 'config'
|
||||
'tenant_id', 'name', 'description', 'service_type', 'config', 'shared'
|
||||
)
|
||||
|
||||
properties_schema = {
|
||||
|
@ -53,6 +53,11 @@ class ServiceChainNode(gbpresource.GBPResource):
|
|||
_('Configuration of the service chain node.'),
|
||||
required=True,
|
||||
update_allowed=False
|
||||
),
|
||||
SHARED: properties.Schema(
|
||||
properties.Schema.BOOLEAN,
|
||||
_('Shared.'),
|
||||
update_allowed=True, required=True
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -95,9 +100,9 @@ class ServiceChainNode(gbpresource.GBPResource):
|
|||
class ServiceChainSpec(gbpresource.GBPResource):
|
||||
|
||||
PROPERTIES = (
|
||||
TENANT_ID, NAME, DESCRIPTION, NODES
|
||||
TENANT_ID, NAME, DESCRIPTION, NODES, SHARED
|
||||
) = (
|
||||
'tenant_id', 'name', 'description', 'nodes'
|
||||
'tenant_id', 'name', 'description', 'nodes', 'shared'
|
||||
)
|
||||
|
||||
properties_schema = {
|
||||
|
@ -120,6 +125,11 @@ class ServiceChainSpec(gbpresource.GBPResource):
|
|||
_('Nodes in the service chain spec.'),
|
||||
required=True,
|
||||
update_allowed=True
|
||||
),
|
||||
SHARED: properties.Schema(
|
||||
properties.Schema.BOOLEAN,
|
||||
_('Shared.'),
|
||||
update_allowed=True, required=True
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -159,8 +169,98 @@ class ServiceChainSpec(gbpresource.GBPResource):
|
|||
self.resource_id, {'servicechain_spec': prop_diff})
|
||||
|
||||
|
||||
class ServiceProfile(gbpresource.GBPResource):
|
||||
|
||||
PROPERTIES = (
|
||||
TENANT_ID, NAME, DESCRIPTION, SHARED, VENDOR, INSERTION_MODE,
|
||||
SERVICE_TYPE, SERVICE_FLAVOR
|
||||
) = (
|
||||
'tenant_id', 'name', 'description', 'shared', 'vendor',
|
||||
'insertion_mode', 'service_type', 'service_flavor'
|
||||
)
|
||||
|
||||
properties_schema = {
|
||||
TENANT_ID: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_('Tenant id of the service profile.')
|
||||
),
|
||||
NAME: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_('Name of the service profile.'),
|
||||
update_allowed=True
|
||||
),
|
||||
DESCRIPTION: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_('Description of the service profile.'),
|
||||
update_allowed=True
|
||||
),
|
||||
SHARED: properties.Schema(
|
||||
properties.Schema.BOOLEAN,
|
||||
_('Shared resource or not.'),
|
||||
update_allowed=True
|
||||
),
|
||||
VENDOR: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_('Vendor providing the service node'),
|
||||
update_allowed=True
|
||||
),
|
||||
INSERTION_MODE: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_('Insertion mode of the service'),
|
||||
update_allowed=True
|
||||
),
|
||||
SERVICE_TYPE: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_('Type of the service.'),
|
||||
required=True,
|
||||
update_allowed=True
|
||||
),
|
||||
SERVICE_FLAVOR: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_('Flavor of the service'),
|
||||
update_allowed=False
|
||||
)
|
||||
}
|
||||
|
||||
def _show_resource(self):
|
||||
client = self.grouppolicy()
|
||||
svc_profile_id = self.resource_id
|
||||
return client.show_service_profile(svc_profile_id)['service_profile']
|
||||
|
||||
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)
|
||||
|
||||
svc_profile = client.create_service_profile(
|
||||
{'service_profile': props})['service_profile']
|
||||
|
||||
self.resource_id_set(svc_profile['id'])
|
||||
|
||||
def handle_delete(self):
|
||||
|
||||
client = self.grouppolicy()
|
||||
svc_profile_id = self.resource_id
|
||||
|
||||
try:
|
||||
client.delete_service_profile(svc_profile_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_service_profile(
|
||||
self.resource_id, {'service_profile': prop_diff})
|
||||
|
||||
|
||||
def resource_mapping():
|
||||
return {
|
||||
'OS::ServiceChain::ServiceChainNode': ServiceChainNode,
|
||||
'OS::ServiceChain::ServiceChainSpec': ServiceChainSpec,
|
||||
'OS::GroupBasedPolicy::ServiceChainNode': ServiceChainNode,
|
||||
'OS::GroupBasedPolicy::ServiceChainSpec': ServiceChainSpec,
|
||||
'OS::GroupBasedPolicy::ServiceProfile': ServiceProfile,
|
||||
}
|
||||
|
|
|
@ -26,14 +26,15 @@ from heat.tests import utils
|
|||
servicechain_node_template = '''
|
||||
{
|
||||
"AWSTemplateFormatVersion" : "2010-09-09",
|
||||
"Description" : "Template to test neutron service chain node",
|
||||
"Description" : "Template to test GBP service chain node",
|
||||
"Parameters" : {},
|
||||
"Resources" : {
|
||||
"servicechain_node": {
|
||||
"Type": "OS::ServiceChain::ServiceChainNode",
|
||||
"Type": "OS::GroupBasedPolicy::ServiceChainNode",
|
||||
"Properties": {
|
||||
"name": "test-sc-node",
|
||||
"description": "test service chain node resource",
|
||||
"shared": True,
|
||||
"service_type": "TAP",
|
||||
"config": "{'name': 'sc_node_config'}"
|
||||
}
|
||||
|
@ -45,14 +46,15 @@ servicechain_node_template = '''
|
|||
servicechain_spec_template = '''
|
||||
{
|
||||
"AWSTemplateFormatVersion" : "2010-09-09",
|
||||
"Description" : "Template to test neutron service chain spec",
|
||||
"Description" : "Template to test GBP service chain spec",
|
||||
"Parameters" : {},
|
||||
"Resources" : {
|
||||
"servicechain_spec": {
|
||||
"Type": "OS::ServiceChain::ServiceChainSpec",
|
||||
"Type": "OS::GroupBasedPolicy::ServiceChainSpec",
|
||||
"Properties": {
|
||||
"name": "test-sc-spec",
|
||||
"description": "test service chain spec resource",
|
||||
"shared": True,
|
||||
"nodes": ["1234", "7890"]
|
||||
}
|
||||
}
|
||||
|
@ -60,6 +62,28 @@ servicechain_spec_template = '''
|
|||
}
|
||||
'''
|
||||
|
||||
service_profile_template = '''
|
||||
{
|
||||
"AWSTemplateFormatVersion" : "2010-09-09",
|
||||
"Description" : "Template to test GBP service profile",
|
||||
"Parameters" : {},
|
||||
"Resources" : {
|
||||
"service_profile": {
|
||||
"Type": "OS::GroupBasedPolicy::ServiceProfile",
|
||||
"Properties": {
|
||||
"name": "test-svc-profile",
|
||||
"description": "test service profile resource",
|
||||
"vendor": "test vendor",
|
||||
"service_type": "test type",
|
||||
"insertion_mode": "l2",
|
||||
"service_flavor": "test flavor",
|
||||
"shared": True
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'''
|
||||
|
||||
|
||||
class ServiceChainNodeTest(HeatTestCase):
|
||||
|
||||
|
@ -77,6 +101,7 @@ class ServiceChainNodeTest(HeatTestCase):
|
|||
"name": "test-sc-node",
|
||||
"description": "test service chain node resource",
|
||||
"service_type": "TAP",
|
||||
"shared": True,
|
||||
"config": "{'name': 'sc_node_config'}"
|
||||
}
|
||||
}).AndReturn({'servicechain_node': {'id': '5678'}})
|
||||
|
@ -101,6 +126,7 @@ class ServiceChainNodeTest(HeatTestCase):
|
|||
"name": "test-sc-node",
|
||||
"description": "test service chain node resource",
|
||||
"service_type": "TAP",
|
||||
"shared": True,
|
||||
"config": "{'name': 'sc_node_config'}"
|
||||
}
|
||||
}).AndRaise(servicechain.NeutronClientException())
|
||||
|
@ -190,6 +216,7 @@ class ServiceChainSpecTest(HeatTestCase):
|
|||
"servicechain_spec": {
|
||||
"name": "test-sc-spec",
|
||||
"description": "test service chain spec resource",
|
||||
"shared": True,
|
||||
"nodes": ["1234", "7890"]
|
||||
}
|
||||
}).AndReturn({'servicechain_spec': {'id': '5678'}})
|
||||
|
@ -213,6 +240,7 @@ class ServiceChainSpecTest(HeatTestCase):
|
|||
'servicechain_spec': {
|
||||
"name": "test-sc-spec",
|
||||
"description": "test service chain spec resource",
|
||||
"shared": True,
|
||||
"nodes": ["1234", "7890"]
|
||||
}
|
||||
}).AndRaise(servicechain.NeutronClientException())
|
||||
|
@ -285,3 +313,122 @@ class ServiceChainSpecTest(HeatTestCase):
|
|||
scheduler.TaskRunner(rsrc.update, update_template)()
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
||||
|
||||
class ServiceProfileTest(HeatTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(ServiceProfileTest, self).setUp()
|
||||
self.m.StubOutWithMock(gbpclient.Client, 'create_service_profile')
|
||||
self.m.StubOutWithMock(gbpclient.Client, 'delete_service_profile')
|
||||
self.m.StubOutWithMock(gbpclient.Client, 'show_service_profile')
|
||||
self.m.StubOutWithMock(gbpclient.Client, 'update_service_profile')
|
||||
self.stub_keystoneclient()
|
||||
|
||||
def create_service_profile(self):
|
||||
gbpclient.Client.create_service_profile({
|
||||
'service_profile': {
|
||||
"name": "test-svc-profile",
|
||||
"description": "test service profile resource",
|
||||
"vendor": "test vendor",
|
||||
"service_type": "test type",
|
||||
"insertion_mode": "l2",
|
||||
"service_flavor": "test flavor",
|
||||
"shared": True
|
||||
}
|
||||
}).AndReturn({'service_profile': {'id': '5678'}})
|
||||
|
||||
snippet = template_format.parse(service_profile_template)
|
||||
self.stack = utils.parse_stack(snippet)
|
||||
resource_defns = self.stack.t.resource_definitions(self.stack)
|
||||
return servicechain.ServiceProfile(
|
||||
'service_profile', resource_defns['service_profile'], self.stack)
|
||||
|
||||
def test_create(self):
|
||||
rsrc = self.create_service_profile()
|
||||
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_service_profile({
|
||||
'service_profile': {
|
||||
"name": "test-svc-profile",
|
||||
"description": "test service profile resource",
|
||||
"vendor": "test vendor",
|
||||
"service_type": "test type",
|
||||
"insertion_mode": "l2",
|
||||
"service_flavor": "test flavor",
|
||||
"shared": True
|
||||
}
|
||||
}).AndRaise(servicechain.NeutronClientException())
|
||||
self.m.ReplayAll()
|
||||
|
||||
snippet = template_format.parse(service_profile_template)
|
||||
self.stack = utils.parse_stack(snippet)
|
||||
resource_defns = self.stack.t.resource_definitions(self.stack)
|
||||
rsrc = servicechain.ServiceProfile(
|
||||
'service_profile', resource_defns['service_profile'],
|
||||
self.stack)
|
||||
|
||||
error = self.assertRaises(exception.ResourceFailure,
|
||||
scheduler.TaskRunner(rsrc.create))
|
||||
self.assertEqual(
|
||||
'NeutronClientException: resources.service_profile: '
|
||||
'An unknown exception occurred.',
|
||||
six.text_type(error))
|
||||
self.assertEqual((rsrc.CREATE, rsrc.FAILED), rsrc.state)
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_delete(self):
|
||||
gbpclient.Client.delete_service_profile('5678')
|
||||
gbpclient.Client.show_service_profile('5678').AndRaise(
|
||||
servicechain.NeutronClientException(status_code=404))
|
||||
|
||||
rsrc = self.create_service_profile()
|
||||
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_service_profile('5678').AndRaise(
|
||||
servicechain.NeutronClientException(status_code=404))
|
||||
|
||||
rsrc = self.create_service_profile()
|
||||
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_service_profile('5678').AndRaise(
|
||||
servicechain.NeutronClientException(status_code=400))
|
||||
|
||||
rsrc = self.create_service_profile()
|
||||
self.m.ReplayAll()
|
||||
scheduler.TaskRunner(rsrc.create)()
|
||||
error = self.assertRaises(exception.ResourceFailure,
|
||||
scheduler.TaskRunner(rsrc.delete))
|
||||
self.assertEqual(
|
||||
'NeutronClientException: resources.service_profile: '
|
||||
'An unknown exception occurred.',
|
||||
six.text_type(error))
|
||||
self.assertEqual((rsrc.DELETE, rsrc.FAILED), rsrc.state)
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_update(self):
|
||||
rsrc = self.create_service_profile()
|
||||
gbpclient.Client.update_service_profile(
|
||||
'5678', {'service_profile': {'name': 'profile_update'}})
|
||||
self.m.ReplayAll()
|
||||
scheduler.TaskRunner(rsrc.create)()
|
||||
|
||||
update_template = copy.deepcopy(rsrc.t)
|
||||
update_template['Properties']['name'] = 'profile_update'
|
||||
scheduler.TaskRunner(rsrc.update, update_template)()
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
|
|
@ -8,14 +8,14 @@
|
|||
hacking<0.11,>=0.10.0
|
||||
coverage>=3.6
|
||||
discover
|
||||
mock>=1.0
|
||||
python-subunit>=0.0.18
|
||||
mock<1.1.0,>=1.0
|
||||
mox>=0.5.3
|
||||
MySQL-python
|
||||
oslosphinx>=2.5.0,<2.6.0 # Apache-2.0
|
||||
oslotest>=1.5.1,<1.6.0 # Apache-2.0
|
||||
oslosphinx<2.6.0,>=2.5.0 # Apache-2.0
|
||||
oslotest<1.6.0,>=1.5.1 # Apache-2.0
|
||||
paramiko>=1.13.0
|
||||
psycopg2
|
||||
sphinx>=1.1.2,!=1.2.0,!=1.3b1,<1.3
|
||||
sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2
|
||||
testrepository>=0.0.18
|
||||
testscenarios>=0.4
|
||||
testtools>=0.9.36,!=1.2.0
|
||||
testtools!=1.2.0,>=0.9.36
|
||||
|
|
Loading…
Reference in New Issue