Add support for External Access model
Heat resources for: External Policies External Segments Nat Pools Also, 'shared' attribute added to applicable resources. Partially Implements: blueprint external-connectivity Change-Id: I39b11c973565673313de21aa38a540173fc34628
This commit is contained in:
parent
bf941b5d4b
commit
56716b487c
|
@ -111,11 +111,11 @@ class PolicyTargetGroup(gbpresource.GBPResource):
|
|||
|
||||
PROPERTIES = (
|
||||
TENANT_ID, NAME, DESCRIPTION, L2_POLICY_ID, PROVIDED_POLICY_RULE_SETS,
|
||||
CONSUMED_POLICY_RULE_SETS, NETWORK_SERVICE_POLICY_ID
|
||||
CONSUMED_POLICY_RULE_SETS, NETWORK_SERVICE_POLICY_ID, SHARED
|
||||
) = (
|
||||
'tenant_id', 'name', 'description', 'l2_policy_id',
|
||||
'provided_policy_rule_sets', 'consumed_policy_rule_sets',
|
||||
'network_service_policy_id'
|
||||
'network_service_policy_id', 'shared'
|
||||
)
|
||||
|
||||
properties_schema = {
|
||||
|
@ -152,7 +152,13 @@ class PolicyTargetGroup(gbpresource.GBPResource):
|
|||
properties.Schema.STRING,
|
||||
_('Network service policy id of the policy target group.'),
|
||||
update_allowed=True, default=None
|
||||
),
|
||||
SHARED: properties.Schema(
|
||||
properties.Schema.BOOLEAN,
|
||||
_('Shared.'),
|
||||
update_allowed=True, required=True
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
def _show_resource(self):
|
||||
|
@ -222,9 +228,9 @@ class PolicyTargetGroup(gbpresource.GBPResource):
|
|||
class L2Policy(gbpresource.GBPResource):
|
||||
|
||||
PROPERTIES = (
|
||||
TENANT_ID, NAME, DESCRIPTION, L3_POLICY_ID
|
||||
TENANT_ID, NAME, DESCRIPTION, L3_POLICY_ID, SHARED
|
||||
) = (
|
||||
'tenant_id', 'name', 'description', 'l3_policy_id'
|
||||
'tenant_id', 'name', 'description', 'l3_policy_id', 'shared'
|
||||
)
|
||||
|
||||
properties_schema = {
|
||||
|
@ -247,6 +253,11 @@ class L2Policy(gbpresource.GBPResource):
|
|||
_('L3 policy id associated with l2 policy.'),
|
||||
required=True,
|
||||
update_allowed=True
|
||||
),
|
||||
SHARED: properties.Schema(
|
||||
properties.Schema.BOOLEAN,
|
||||
_('Shared.'),
|
||||
update_allowed=True, required=True
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -290,10 +301,10 @@ class L3Policy(gbpresource.GBPResource):
|
|||
|
||||
PROPERTIES = (
|
||||
TENANT_ID, NAME, DESCRIPTION, IP_VERSION, IP_POOL,
|
||||
SUBNET_PREFIX_LENGTH
|
||||
SUBNET_PREFIX_LENGTH, EXTERNAL_SEGMENTS, SHARED
|
||||
) = (
|
||||
'tenant_id', 'name', 'description', 'ip_version', 'ip_pool',
|
||||
'subnet_prefix_length'
|
||||
'subnet_prefix_length', 'external_segments', 'shared'
|
||||
)
|
||||
|
||||
properties_schema = {
|
||||
|
@ -325,6 +336,16 @@ class L3Policy(gbpresource.GBPResource):
|
|||
properties.Schema.INTEGER,
|
||||
_('Subnet prefix length of L3 policy.'),
|
||||
update_allowed=True
|
||||
),
|
||||
EXTERNAL_SEGMENTS: properties.Schema(
|
||||
properties.Schema.MAP,
|
||||
_('External segments of L3 policy.'),
|
||||
update_allowed=True
|
||||
),
|
||||
SHARED: properties.Schema(
|
||||
properties.Schema.BOOLEAN,
|
||||
_('Shared.'),
|
||||
update_allowed=True, required=True
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -368,10 +389,10 @@ class PolicyClassifier(gbpresource.GBPResource):
|
|||
|
||||
PROPERTIES = (
|
||||
TENANT_ID, NAME, DESCRIPTION, PROTOCOL, PORT_RANGE,
|
||||
DIRECTION
|
||||
DIRECTION, SHARED
|
||||
) = (
|
||||
'tenant_id', 'name', 'description', 'protocol', 'port_range',
|
||||
'direction'
|
||||
'direction', 'shared'
|
||||
)
|
||||
|
||||
properties_schema = {
|
||||
|
@ -409,6 +430,11 @@ class PolicyClassifier(gbpresource.GBPResource):
|
|||
constraints.AllowedValues(['in', 'out', 'bi', None])
|
||||
],
|
||||
update_allowed=True
|
||||
),
|
||||
SHARED: properties.Schema(
|
||||
properties.Schema.BOOLEAN,
|
||||
_('Shared.'),
|
||||
update_allowed=True, required=True
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -451,9 +477,10 @@ class PolicyClassifier(gbpresource.GBPResource):
|
|||
class PolicyAction(gbpresource.GBPResource):
|
||||
|
||||
PROPERTIES = (
|
||||
TENANT_ID, NAME, DESCRIPTION, ACTION_TYPE, ACTION_VALUE
|
||||
TENANT_ID, NAME, DESCRIPTION, ACTION_TYPE, ACTION_VALUE, SHARED
|
||||
) = (
|
||||
'tenant_id', 'name', 'description', 'action_type', 'action_value'
|
||||
'tenant_id', 'name', 'description', 'action_type', 'action_value',
|
||||
'shared'
|
||||
)
|
||||
|
||||
properties_schema = {
|
||||
|
@ -483,6 +510,11 @@ class PolicyAction(gbpresource.GBPResource):
|
|||
properties.Schema.STRING,
|
||||
_('Value of the action.'),
|
||||
update_allowed=True
|
||||
),
|
||||
SHARED: properties.Schema(
|
||||
properties.Schema.BOOLEAN,
|
||||
_('Shared.'),
|
||||
update_allowed=True, required=True
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -526,10 +558,10 @@ class PolicyRule(gbpresource.GBPResource):
|
|||
|
||||
PROPERTIES = (
|
||||
TENANT_ID, NAME, DESCRIPTION, ENABLED, POLICY_CLASSIFIER_ID,
|
||||
POLICY_ACTIONS
|
||||
POLICY_ACTIONS, SHARED
|
||||
) = (
|
||||
'tenant_id', 'name', 'description', 'enabled', 'policy_classifier_id',
|
||||
'policy_actions'
|
||||
'policy_actions', 'shared'
|
||||
)
|
||||
|
||||
properties_schema = {
|
||||
|
@ -561,6 +593,11 @@ class PolicyRule(gbpresource.GBPResource):
|
|||
properties.Schema.LIST,
|
||||
_('List of actions of the policy rule.'),
|
||||
default=None, update_allowed=True
|
||||
),
|
||||
SHARED: properties.Schema(
|
||||
properties.Schema.BOOLEAN,
|
||||
_('Shared.'),
|
||||
update_allowed=True, required=True
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -604,10 +641,10 @@ class PolicyRuleSet(gbpresource.GBPResource):
|
|||
|
||||
PROPERTIES = (
|
||||
TENANT_ID, NAME, DESCRIPTION, PARENT_ID, CHILD_POLICY_RULE_SETS,
|
||||
POLICY_RULES
|
||||
POLICY_RULES, SHARED
|
||||
) = (
|
||||
'tenant_id', 'name', 'description', 'parent_id',
|
||||
'child_policy_rule_sets', 'policy_rules'
|
||||
'child_policy_rule_sets', 'policy_rules', 'shared'
|
||||
)
|
||||
|
||||
properties_schema = {
|
||||
|
@ -639,6 +676,11 @@ class PolicyRuleSet(gbpresource.GBPResource):
|
|||
properties.Schema.LIST,
|
||||
_('List of policy rules.'),
|
||||
default=None, update_allowed=True
|
||||
),
|
||||
SHARED: properties.Schema(
|
||||
properties.Schema.BOOLEAN,
|
||||
_('Shared.'),
|
||||
update_allowed=True, required=True
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -681,9 +723,9 @@ class PolicyRuleSet(gbpresource.GBPResource):
|
|||
class NetworkServicePolicy(gbpresource.GBPResource):
|
||||
|
||||
PROPERTIES = (
|
||||
TENANT_ID, NAME, DESCRIPTION, NETWORK_SERVICE_PARAMS
|
||||
TENANT_ID, NAME, DESCRIPTION, NETWORK_SERVICE_PARAMS, SHARED
|
||||
) = (
|
||||
'tenant_id', 'name', 'description', 'network_service_params'
|
||||
'tenant_id', 'name', 'description', 'network_service_params', 'shared'
|
||||
)
|
||||
|
||||
properties_schema = {
|
||||
|
@ -705,6 +747,11 @@ class NetworkServicePolicy(gbpresource.GBPResource):
|
|||
properties.Schema.LIST,
|
||||
_('List of network service policy dicts.'),
|
||||
default=None, update_allowed=True
|
||||
),
|
||||
SHARED: properties.Schema(
|
||||
properties.Schema.BOOLEAN,
|
||||
_('Shared.'),
|
||||
update_allowed=True, required=True
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -745,6 +792,291 @@ class NetworkServicePolicy(gbpresource.GBPResource):
|
|||
self.resource_id, {'network_service_policy': prop_diff})
|
||||
|
||||
|
||||
class ExternalPolicy(gbpresource.GBPResource):
|
||||
|
||||
PROPERTIES = (
|
||||
TENANT_ID, NAME, DESCRIPTION, EXTERNAL_SEGMENTS,
|
||||
PROVIDED_POLICY_RULE_SETS, CONSUMED_POLICY_RULE_SETS, SHARED
|
||||
) = (
|
||||
'tenant_id', 'name', 'description', 'external_segments',
|
||||
'provided_policy_rule_sets', 'consumed_policy_rule_sets', 'shared'
|
||||
)
|
||||
|
||||
properties_schema = {
|
||||
TENANT_ID: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_('Tenant id of the external policy.')
|
||||
),
|
||||
NAME: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_('Name of the external policy.'),
|
||||
update_allowed=True
|
||||
),
|
||||
DESCRIPTION: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_('Description of the external policy.'),
|
||||
update_allowed=True
|
||||
),
|
||||
EXTERNAL_SEGMENTS: properties.Schema(
|
||||
properties.Schema.LIST,
|
||||
_('External segments of the policy.'),
|
||||
update_allowed=True
|
||||
),
|
||||
PROVIDED_POLICY_RULE_SETS: properties.Schema(
|
||||
properties.Schema.LIST,
|
||||
_('Provided policy rule sets.'),
|
||||
default=None, update_allowed=True
|
||||
),
|
||||
CONSUMED_POLICY_RULE_SETS: properties.Schema(
|
||||
properties.Schema.LIST,
|
||||
_('Consumed policy rule sets.'),
|
||||
default=None, update_allowed=True
|
||||
),
|
||||
SHARED: properties.Schema(
|
||||
properties.Schema.BOOLEAN,
|
||||
_('Shared.'),
|
||||
update_allowed=True, required=True
|
||||
)
|
||||
}
|
||||
|
||||
def _show_resource(self):
|
||||
client = self.grouppolicy()
|
||||
ext_policy_id = self.resource_id
|
||||
ext_policy = client.show_external_policy(ext_policy_id)
|
||||
return ext_policy['external_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)
|
||||
|
||||
provided_policy_rule_set_list = {}
|
||||
consumed_policy_rule_set_list = {}
|
||||
props_provided_policy_rule_sets = props.get(
|
||||
'provided_policy_rule_sets', [])
|
||||
props_consumed_policy_rule_sets = props.get(
|
||||
'consumed_policy_rule_sets', [])
|
||||
|
||||
for prop_prov_policy_rule_set in props_provided_policy_rule_sets:
|
||||
policy_rule_set_id = (
|
||||
prop_prov_policy_rule_set['policy_rule_set_id'])
|
||||
policy_rule_set_scope = (
|
||||
prop_prov_policy_rule_set['policy_rule_set_scope'])
|
||||
provided_policy_rule_set_list.update({policy_rule_set_id:
|
||||
policy_rule_set_scope})
|
||||
|
||||
for prop_cons_policy_rule_set in props_consumed_policy_rule_sets:
|
||||
policy_rule_set_id = (
|
||||
prop_cons_policy_rule_set['policy_rule_set_id'])
|
||||
policy_rule_set_scope = (
|
||||
prop_cons_policy_rule_set['policy_rule_set_scope'])
|
||||
consumed_policy_rule_set_list.update({policy_rule_set_id:
|
||||
policy_rule_set_scope})
|
||||
|
||||
if provided_policy_rule_set_list:
|
||||
props['provided_policy_rule_sets'] = provided_policy_rule_set_list
|
||||
if consumed_policy_rule_set_list:
|
||||
props['consumed_policy_rule_sets'] = consumed_policy_rule_set_list
|
||||
|
||||
ext_policy = client.create_external_policy(
|
||||
{'external_policy': props})['external_policy']
|
||||
|
||||
self.resource_id_set(ext_policy['id'])
|
||||
|
||||
def handle_delete(self):
|
||||
|
||||
client = self.grouppolicy()
|
||||
ext_policy_id = self.resource_id
|
||||
|
||||
try:
|
||||
client.delete_external_policy(ext_policy_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_external_policy(
|
||||
self.resource_id, {'external_policy': prop_diff})
|
||||
|
||||
|
||||
class ExternalSegment(gbpresource.GBPResource):
|
||||
|
||||
PROPERTIES = (
|
||||
TENANT_ID, NAME, DESCRIPTION, IP_VERSION, CIDR,
|
||||
EXTERNAL_ROUTES, PORT_ADDRESS_TRANSLATION, SHARED
|
||||
) = (
|
||||
'tenant_id', 'name', 'description', 'ip_version', 'cidr',
|
||||
'external_routes', 'port_address_translation', 'shared'
|
||||
)
|
||||
|
||||
properties_schema = {
|
||||
TENANT_ID: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_('Tenant id of the external segment.')
|
||||
),
|
||||
NAME: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_('Name of the external segment.'),
|
||||
update_allowed=True
|
||||
),
|
||||
DESCRIPTION: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_('Description of the external segment.'),
|
||||
update_allowed=True
|
||||
),
|
||||
IP_VERSION: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_('IP version of the external segment.'),
|
||||
default='4', update_allowed=False
|
||||
),
|
||||
CIDR: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_('CIDR of the external segment.'),
|
||||
default=None, update_allowed=False
|
||||
),
|
||||
EXTERNAL_ROUTES: properties.Schema(
|
||||
properties.Schema.LIST,
|
||||
_('External routes of the external segment.'),
|
||||
default=None, update_allowed=True
|
||||
),
|
||||
PORT_ADDRESS_TRANSLATION: properties.Schema(
|
||||
properties.Schema.BOOLEAN,
|
||||
_('Port address translation required for the external segment.'),
|
||||
update_allowed=True, required=True
|
||||
),
|
||||
SHARED: properties.Schema(
|
||||
properties.Schema.BOOLEAN,
|
||||
_('Shared.'),
|
||||
update_allowed=True, required=True
|
||||
)
|
||||
}
|
||||
|
||||
def _show_resource(self):
|
||||
client = self.grouppolicy()
|
||||
es_id = self.resource_id
|
||||
es = client.show_external_segment(es_id)
|
||||
return es['external_segment']
|
||||
|
||||
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)
|
||||
|
||||
es = client.create_external_segment(
|
||||
{'external_segment': props})['external_segment']
|
||||
|
||||
self.resource_id_set(es['id'])
|
||||
|
||||
def handle_delete(self):
|
||||
|
||||
client = self.grouppolicy()
|
||||
es_id = self.resource_id
|
||||
|
||||
try:
|
||||
client.delete_external_segment(es_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_external_segment(
|
||||
self.resource_id, {'external_segment': prop_diff})
|
||||
|
||||
|
||||
class NATPool(gbpresource.GBPResource):
|
||||
|
||||
PROPERTIES = (
|
||||
TENANT_ID, NAME, DESCRIPTION, IP_VERSION, IP_POOL,
|
||||
EXTERNAL_SEGMENT_ID, SHARED
|
||||
) = (
|
||||
'tenant_id', 'name', 'description', 'ip_version', 'ip_pool',
|
||||
'external_segment_id', 'shared'
|
||||
)
|
||||
|
||||
properties_schema = {
|
||||
TENANT_ID: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_('Tenant id of the NAT pool.')
|
||||
),
|
||||
NAME: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_('Name of the NAT pool.'),
|
||||
update_allowed=True
|
||||
),
|
||||
DESCRIPTION: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_('Description of the NET pool.'),
|
||||
update_allowed=True
|
||||
),
|
||||
IP_VERSION: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_('IP version of the NAT pool.'),
|
||||
default='4', update_allowed=False
|
||||
),
|
||||
IP_POOL: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_('IP pool of the NAT pool.'),
|
||||
default=None, update_allowed=False
|
||||
),
|
||||
EXTERNAL_SEGMENT_ID: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_('External segment id of the NAT pool.'),
|
||||
update_allowed=True, required=True
|
||||
),
|
||||
SHARED: properties.Schema(
|
||||
properties.Schema.BOOLEAN,
|
||||
_('Shared.'),
|
||||
update_allowed=True, required=True
|
||||
)
|
||||
}
|
||||
|
||||
def _show_resource(self):
|
||||
client = self.grouppolicy()
|
||||
nat_pool_id = self.resource_id
|
||||
nat_pool = client.show_nat_pool(nat_pool_id)
|
||||
return nat_pool['nat_pool']
|
||||
|
||||
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)
|
||||
|
||||
nat_pool = client.create_nat_pool(
|
||||
{'nat_pool': props})['nat_pool']
|
||||
|
||||
self.resource_id_set(nat_pool['id'])
|
||||
|
||||
def handle_delete(self):
|
||||
|
||||
client = self.grouppolicy()
|
||||
nat_pool_id = self.resource_id
|
||||
|
||||
try:
|
||||
client.delete_nat_pool(nat_pool_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_nat_pool(
|
||||
self.resource_id, {'nat_pool': prop_diff})
|
||||
|
||||
|
||||
def resource_mapping():
|
||||
return {
|
||||
'OS::Neutron::PolicyTarget': PolicyTarget,
|
||||
|
@ -755,5 +1087,8 @@ def resource_mapping():
|
|||
'OS::Neutron::PolicyAction': PolicyAction,
|
||||
'OS::Neutron::PolicyRule': PolicyRule,
|
||||
'OS::Neutron::PolicyRuleSet': PolicyRuleSet,
|
||||
'OS::Neutron::NetworkServicePolicy': NetworkServicePolicy
|
||||
'OS::Neutron::NetworkServicePolicy': NetworkServicePolicy,
|
||||
'OS::Neutron::ExternalPolicy': ExternalPolicy,
|
||||
'OS::Neutron::ExternalSegment': ExternalSegment,
|
||||
'OS::Neutron::NATPool': NATPool
|
||||
}
|
||||
|
|
|
@ -64,7 +64,8 @@ policy_target_group_template = '''
|
|||
"policy_rule_set_scope": "scope3"},
|
||||
{"policy_rule_set_id": "policy_rule_set4",
|
||||
"policy_rule_set_scope": "scope4"}
|
||||
]
|
||||
],
|
||||
"shared": True
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +83,8 @@ l2_policy_template = '''
|
|||
"Properties": {
|
||||
"name": "test-l2-policy",
|
||||
"description": "test L2 policy resource",
|
||||
"l3_policy_id": "l3-policy-id"
|
||||
"l3_policy_id": "l3-policy-id",
|
||||
"shared": True
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -102,7 +104,8 @@ l3_policy_template = '''
|
|||
"description": "test L3 policy resource",
|
||||
"ip_version": "4",
|
||||
"ip_pool": "10.20.20.0",
|
||||
"subnet_prefix_length": 24
|
||||
"subnet_prefix_length": 24,
|
||||
"shared": True
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -122,7 +125,8 @@ policy_classifier_template = '''
|
|||
"description": "test policy classifier resource",
|
||||
"protocol": "tcp",
|
||||
"port_range": "8000-9000",
|
||||
"direction": "bi"
|
||||
"direction": "bi",
|
||||
"shared": True
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -141,7 +145,8 @@ policy_action_template = '''
|
|||
"name": "test-policy-action",
|
||||
"description": "test policy action resource",
|
||||
"action_type": "redirect",
|
||||
"action_value": "7890"
|
||||
"action_value": "7890",
|
||||
"shared": True
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -161,7 +166,8 @@ policy_rule_template = '''
|
|||
"description": "test policy rule resource",
|
||||
"enabled": True,
|
||||
"policy_classifier_id": "7890",
|
||||
"policy_actions": ['3456', '1234']
|
||||
"policy_actions": ['3456', '1234'],
|
||||
"shared": True
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -181,7 +187,8 @@ policy_rule_set_template = '''
|
|||
"description": "test policy rule set resource",
|
||||
"parent_id": "3456",
|
||||
"child_policy_rule_sets": ["7890", "1234"],
|
||||
"policy_rules": ["2345", "6789"]
|
||||
"policy_rules": ["2345", "6789"],
|
||||
"shared": True
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -200,7 +207,90 @@ network_service_policy_template = '''
|
|||
"name": "test-nsp",
|
||||
"description": "test NSP resource",
|
||||
"network_service_params": [{'type': 'ip_single', 'name': 'vip',
|
||||
'value': 'self_subnet'}]
|
||||
'value': 'self_subnet'}],
|
||||
"shared": True
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'''
|
||||
|
||||
external_policy_template = '''
|
||||
{
|
||||
"AWSTemplateFormatVersion" : "2010-09-09",
|
||||
"Description" : "Template to test external policy",
|
||||
"Parameters" : {},
|
||||
"Resources" : {
|
||||
"external_policy": {
|
||||
"Type": "OS::Neutron::ExternalPolicy",
|
||||
"Properties": {
|
||||
"name": "test-ep",
|
||||
"description": "test EP resource",
|
||||
"external_segments": ['1234'],
|
||||
"provided_policy_rule_sets": [{
|
||||
"policy_rule_set_id": '2345',
|
||||
"policy_rule_set_scope": "scope1"
|
||||
},
|
||||
{
|
||||
"policy_rule_set_id": '8901',
|
||||
"policy_rule_set_scope": "scope2"
|
||||
}],
|
||||
"consumed_policy_rule_sets": [{
|
||||
"policy_rule_set_id": '9012',
|
||||
"policy_rule_set_scope": "scope3"
|
||||
},
|
||||
{
|
||||
"policy_rule_set_id": '9210',
|
||||
"policy_rule_set_scope": "scope4"
|
||||
}],
|
||||
"shared": True
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'''
|
||||
|
||||
external_segment_template = '''
|
||||
{
|
||||
"AWSTemplateFormatVersion" : "2010-09-09",
|
||||
"Description" : "Template to test external segment",
|
||||
"Parameters" : {},
|
||||
"Resources" : {
|
||||
"external_segment": {
|
||||
"Type": "OS::Neutron::ExternalSegment",
|
||||
"Properties": {
|
||||
"name": "test-es",
|
||||
"description": "test ES resource",
|
||||
"ip_version": '6',
|
||||
"cidr": "192.168.0.0/24",
|
||||
"external_routes": [{
|
||||
"destination": "0.0.0.0/0",
|
||||
"nexthop": "null"
|
||||
}
|
||||
],
|
||||
"port_address_translation": True,
|
||||
"shared": True
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'''
|
||||
|
||||
nat_pool_template = '''
|
||||
{
|
||||
"AWSTemplateFormatVersion" : "2010-09-09",
|
||||
"Description" : "Template to test NAT pool",
|
||||
"Parameters" : {},
|
||||
"Resources" : {
|
||||
"nat_pool": {
|
||||
"Type": "OS::Neutron::NATPool",
|
||||
"Properties": {
|
||||
"name": "test-nat-pool",
|
||||
"description": "test NP resource",
|
||||
"ip_version": '6',
|
||||
"ip_pool": "192.168.0.0/24",
|
||||
"external_segment_id": '1234',
|
||||
"shared": True
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -362,7 +452,8 @@ class PolicyTargetGroupTest(HeatTestCase):
|
|||
"consumed_policy_rule_sets": {
|
||||
"policy_rule_set3": "scope3",
|
||||
"policy_rule_set4": "scope4"
|
||||
}
|
||||
},
|
||||
"shared": True
|
||||
}
|
||||
}).AndReturn({'policy_target_group': {'id': '5678'}})
|
||||
|
||||
|
@ -393,7 +484,8 @@ class PolicyTargetGroupTest(HeatTestCase):
|
|||
"consumed_policy_rule_sets": {
|
||||
"policy_rule_set3": "scope3",
|
||||
"policy_rule_set4": "scope4"
|
||||
}
|
||||
},
|
||||
"shared": True
|
||||
}
|
||||
}).AndRaise(grouppolicy.NeutronClientException())
|
||||
self.m.ReplayAll()
|
||||
|
@ -480,7 +572,8 @@ class L2PolicyTest(HeatTestCase):
|
|||
'l2_policy': {
|
||||
"name": "test-l2-policy",
|
||||
"description": "test L2 policy resource",
|
||||
"l3_policy_id": "l3-policy-id"
|
||||
"l3_policy_id": "l3-policy-id",
|
||||
"shared": True
|
||||
}
|
||||
}).AndReturn({'l2_policy': {'id': '5678'}})
|
||||
|
||||
|
@ -502,7 +595,8 @@ class L2PolicyTest(HeatTestCase):
|
|||
'l2_policy': {
|
||||
"name": "test-l2-policy",
|
||||
"description": "test L2 policy resource",
|
||||
"l3_policy_id": "l3-policy-id"
|
||||
"l3_policy_id": "l3-policy-id",
|
||||
"shared": True
|
||||
}
|
||||
}).AndRaise(grouppolicy.NeutronClientException())
|
||||
self.m.ReplayAll()
|
||||
|
@ -590,7 +684,8 @@ class L3PolicyTest(HeatTestCase):
|
|||
"description": "test L3 policy resource",
|
||||
"ip_version": "4",
|
||||
"ip_pool": "10.20.20.0",
|
||||
"subnet_prefix_length": 24
|
||||
"subnet_prefix_length": 24,
|
||||
"shared": True
|
||||
}
|
||||
}).AndReturn({'l3_policy': {'id': '5678'}})
|
||||
|
||||
|
@ -614,7 +709,8 @@ class L3PolicyTest(HeatTestCase):
|
|||
"description": "test L3 policy resource",
|
||||
"ip_version": "4",
|
||||
"ip_pool": "10.20.20.0",
|
||||
"subnet_prefix_length": 24
|
||||
"subnet_prefix_length": 24,
|
||||
"shared": True
|
||||
}
|
||||
}).AndRaise(grouppolicy.NeutronClientException())
|
||||
self.m.ReplayAll()
|
||||
|
@ -706,7 +802,8 @@ class PolicyClassifierTest(HeatTestCase):
|
|||
"description": "test policy classifier resource",
|
||||
"protocol": "tcp",
|
||||
"port_range": "8000-9000",
|
||||
"direction": "bi"
|
||||
"direction": "bi",
|
||||
"shared": True
|
||||
}
|
||||
}).AndReturn({'policy_classifier': {'id': '5678'}})
|
||||
|
||||
|
@ -730,7 +827,8 @@ class PolicyClassifierTest(HeatTestCase):
|
|||
"description": "test policy classifier resource",
|
||||
"protocol": "tcp",
|
||||
"port_range": "8000-9000",
|
||||
"direction": "bi"
|
||||
"direction": "bi",
|
||||
"shared": True
|
||||
}
|
||||
}).AndRaise(grouppolicy.NeutronClientException())
|
||||
self.m.ReplayAll()
|
||||
|
@ -817,7 +915,8 @@ class PolicyActionTest(HeatTestCase):
|
|||
"name": "test-policy-action",
|
||||
"description": "test policy action resource",
|
||||
"action_type": "redirect",
|
||||
"action_value": "7890"
|
||||
"action_value": "7890",
|
||||
"shared": True
|
||||
}
|
||||
}).AndReturn({'policy_action': {'id': '5678'}})
|
||||
|
||||
|
@ -840,7 +939,8 @@ class PolicyActionTest(HeatTestCase):
|
|||
"name": "test-policy-action",
|
||||
"description": "test policy action resource",
|
||||
"action_type": "redirect",
|
||||
"action_value": "7890"
|
||||
"action_value": "7890",
|
||||
"shared": True
|
||||
}
|
||||
}).AndRaise(grouppolicy.NeutronClientException())
|
||||
self.m.ReplayAll()
|
||||
|
@ -928,7 +1028,8 @@ class PolicyRuleTest(HeatTestCase):
|
|||
"description": "test policy rule resource",
|
||||
"enabled": True,
|
||||
"policy_classifier_id": "7890",
|
||||
"policy_actions": ['3456', '1234']
|
||||
"policy_actions": ['3456', '1234'],
|
||||
"shared": True
|
||||
}
|
||||
}).AndReturn({'policy_rule': {'id': '5678'}})
|
||||
|
||||
|
@ -952,7 +1053,8 @@ class PolicyRuleTest(HeatTestCase):
|
|||
"description": "test policy rule resource",
|
||||
"enabled": True,
|
||||
"policy_classifier_id": "7890",
|
||||
"policy_actions": ['3456', '1234']
|
||||
"policy_actions": ['3456', '1234'],
|
||||
"shared": True
|
||||
}
|
||||
}).AndRaise(grouppolicy.NeutronClientException())
|
||||
self.m.ReplayAll()
|
||||
|
@ -1040,7 +1142,8 @@ class PolicyRuleSetTest(HeatTestCase):
|
|||
"description": "test policy rule set resource",
|
||||
"parent_id": "3456",
|
||||
"child_policy_rule_sets": ["7890", "1234"],
|
||||
"policy_rules": ["2345", "6789"]
|
||||
"policy_rules": ["2345", "6789"],
|
||||
"shared": True
|
||||
}
|
||||
}).AndReturn({'policy_rule_set': {'id': '5678'}})
|
||||
|
||||
|
@ -1064,7 +1167,8 @@ class PolicyRuleSetTest(HeatTestCase):
|
|||
"description": "test policy rule set resource",
|
||||
"parent_id": "3456",
|
||||
"child_policy_rule_sets": ["7890", "1234"],
|
||||
"policy_rules": ["2345", "6789"]
|
||||
"policy_rules": ["2345", "6789"],
|
||||
"shared": True
|
||||
}
|
||||
}).AndRaise(grouppolicy.NeutronClientException())
|
||||
self.m.ReplayAll()
|
||||
|
@ -1156,7 +1260,8 @@ class NetworkServicePolicyTest(HeatTestCase):
|
|||
"description": "test NSP resource",
|
||||
"network_service_params": [
|
||||
{'type': 'ip_single', 'name': 'vip',
|
||||
'value': 'self_subnet'}]
|
||||
'value': 'self_subnet'}],
|
||||
"shared": True
|
||||
}
|
||||
}).AndReturn({'network_service_policy': {'id': '5678'}})
|
||||
|
||||
|
@ -1181,7 +1286,8 @@ class NetworkServicePolicyTest(HeatTestCase):
|
|||
"description": "test NSP resource",
|
||||
"network_service_params": [
|
||||
{'type': 'ip_single', 'name': 'vip',
|
||||
'value': 'self_subnet'}]
|
||||
'value': 'self_subnet'}],
|
||||
"shared": True
|
||||
}
|
||||
}).AndRaise(grouppolicy.NeutronClientException())
|
||||
self.m.ReplayAll()
|
||||
|
@ -1253,3 +1359,387 @@ class NetworkServicePolicyTest(HeatTestCase):
|
|||
scheduler.TaskRunner(rsrc.update, update_template)()
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
||||
|
||||
class ExternalPolicyTest(HeatTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(ExternalPolicyTest, self).setUp()
|
||||
self.m.StubOutWithMock(gbpclient.Client,
|
||||
'create_external_policy')
|
||||
self.m.StubOutWithMock(gbpclient.Client,
|
||||
'delete_external_policy')
|
||||
self.m.StubOutWithMock(gbpclient.Client,
|
||||
'show_external_policy')
|
||||
self.m.StubOutWithMock(gbpclient.Client,
|
||||
'update_external_policy')
|
||||
self.stub_keystoneclient()
|
||||
|
||||
def create_external_policy(self):
|
||||
gbpclient.Client.create_external_policy({
|
||||
'external_policy': {
|
||||
"name": "test-ep",
|
||||
"description": "test EP resource",
|
||||
"external_segments": ['1234'],
|
||||
"provided_policy_rule_sets": {
|
||||
'2345': "scope1",
|
||||
'8901': "scope2"
|
||||
},
|
||||
"consumed_policy_rule_sets": {
|
||||
'9012': "scope3",
|
||||
'9210': "scope4"
|
||||
},
|
||||
"shared": True
|
||||
}
|
||||
}).AndReturn({'external_policy': {'id': '5678'}})
|
||||
|
||||
snippet = template_format.parse(external_policy_template)
|
||||
stack = utils.parse_stack(snippet)
|
||||
resource_defns = stack.t.resource_definitions(stack)
|
||||
return grouppolicy.ExternalPolicy(
|
||||
'external_policy',
|
||||
resource_defns['external_policy'], stack)
|
||||
|
||||
def test_create(self):
|
||||
rsrc = self.create_external_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_external_policy({
|
||||
'external_policy': {
|
||||
"name": "test-ep",
|
||||
"description": "test EP resource",
|
||||
"external_segments": ['1234'],
|
||||
"provided_policy_rule_sets": {
|
||||
'2345': "scope1",
|
||||
'8901': "scope2"
|
||||
},
|
||||
"consumed_policy_rule_sets": {
|
||||
'9012': "scope3",
|
||||
'9210': "scope4"
|
||||
},
|
||||
"shared": True
|
||||
}
|
||||
}).AndRaise(grouppolicy.NeutronClientException())
|
||||
self.m.ReplayAll()
|
||||
|
||||
snippet = template_format.parse(external_policy_template)
|
||||
stack = utils.parse_stack(snippet)
|
||||
resource_defns = stack.t.resource_definitions(stack)
|
||||
rsrc = grouppolicy.ExternalPolicy(
|
||||
'external_policy',
|
||||
resource_defns['external_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_external_policy('5678')
|
||||
gbpclient.Client.show_external_policy('5678').AndRaise(
|
||||
grouppolicy.NeutronClientException(status_code=404))
|
||||
|
||||
rsrc = self.create_external_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_external_policy('5678').AndRaise(
|
||||
grouppolicy.NeutronClientException(status_code=404))
|
||||
|
||||
rsrc = self.create_external_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_external_policy('5678').AndRaise(
|
||||
grouppolicy.NeutronClientException(status_code=400))
|
||||
|
||||
rsrc = self.create_external_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_external_policy()
|
||||
gbpclient.Client.update_external_policy(
|
||||
'5678', {'external_policy':
|
||||
{'external_segments': ['9876']}})
|
||||
self.m.ReplayAll()
|
||||
scheduler.TaskRunner(rsrc.create)()
|
||||
|
||||
update_template = copy.deepcopy(rsrc.t)
|
||||
update_template['Properties']['external_segments'] = [
|
||||
'9876']
|
||||
scheduler.TaskRunner(rsrc.update, update_template)()
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
||||
|
||||
class ExternalSegmentTest(HeatTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(ExternalSegmentTest, self).setUp()
|
||||
self.m.StubOutWithMock(gbpclient.Client,
|
||||
'create_external_segment')
|
||||
self.m.StubOutWithMock(gbpclient.Client,
|
||||
'delete_external_segment')
|
||||
self.m.StubOutWithMock(gbpclient.Client,
|
||||
'show_external_segment')
|
||||
self.m.StubOutWithMock(gbpclient.Client,
|
||||
'update_external_segment')
|
||||
self.stub_keystoneclient()
|
||||
|
||||
def create_external_segment(self):
|
||||
gbpclient.Client.create_external_segment({
|
||||
'external_segment': {
|
||||
"name": "test-es",
|
||||
"description": "test ES resource",
|
||||
"ip_version": '6',
|
||||
"cidr": "192.168.0.0/24",
|
||||
"external_routes": [{
|
||||
"destination": "0.0.0.0/0",
|
||||
"nexthop": "null"
|
||||
}],
|
||||
"port_address_translation": True,
|
||||
"shared": True
|
||||
}
|
||||
}).AndReturn({'external_segment': {'id': '5678'}})
|
||||
|
||||
snippet = template_format.parse(external_segment_template)
|
||||
stack = utils.parse_stack(snippet)
|
||||
resource_defns = stack.t.resource_definitions(stack)
|
||||
return grouppolicy.ExternalSegment(
|
||||
'external_segment',
|
||||
resource_defns['external_segment'], stack)
|
||||
|
||||
def test_create(self):
|
||||
rsrc = self.create_external_segment()
|
||||
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_external_segment({
|
||||
'external_segment': {
|
||||
"name": "test-es",
|
||||
"description": "test ES resource",
|
||||
"ip_version": '6',
|
||||
"cidr": "192.168.0.0/24",
|
||||
"external_routes": [{
|
||||
"destination": "0.0.0.0/0",
|
||||
"nexthop": "null"
|
||||
}],
|
||||
"port_address_translation": True,
|
||||
"shared": True
|
||||
}
|
||||
}).AndRaise(grouppolicy.NeutronClientException())
|
||||
self.m.ReplayAll()
|
||||
|
||||
snippet = template_format.parse(external_segment_template)
|
||||
stack = utils.parse_stack(snippet)
|
||||
resource_defns = stack.t.resource_definitions(stack)
|
||||
rsrc = grouppolicy.ExternalSegment(
|
||||
'external_segment',
|
||||
resource_defns['external_segment'], 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_external_segment('5678')
|
||||
gbpclient.Client.show_external_segment('5678').AndRaise(
|
||||
grouppolicy.NeutronClientException(status_code=404))
|
||||
|
||||
rsrc = self.create_external_segment()
|
||||
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_external_segment('5678').AndRaise(
|
||||
grouppolicy.NeutronClientException(status_code=404))
|
||||
|
||||
rsrc = self.create_external_segment()
|
||||
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_external_segment('5678').AndRaise(
|
||||
grouppolicy.NeutronClientException(status_code=400))
|
||||
|
||||
rsrc = self.create_external_segment()
|
||||
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_external_segment()
|
||||
gbpclient.Client.update_external_segment(
|
||||
'5678', {'external_segment':
|
||||
{"port_address_translation": False}})
|
||||
self.m.ReplayAll()
|
||||
scheduler.TaskRunner(rsrc.create)()
|
||||
|
||||
update_template = copy.deepcopy(rsrc.t)
|
||||
update_template['Properties']['port_address_translation'] = False
|
||||
scheduler.TaskRunner(rsrc.update, update_template)()
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
||||
|
||||
class NATPoolTest(HeatTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(NATPoolTest, self).setUp()
|
||||
self.m.StubOutWithMock(gbpclient.Client,
|
||||
'create_nat_pool')
|
||||
self.m.StubOutWithMock(gbpclient.Client,
|
||||
'delete_nat_pool')
|
||||
self.m.StubOutWithMock(gbpclient.Client,
|
||||
'show_nat_pool')
|
||||
self.m.StubOutWithMock(gbpclient.Client,
|
||||
'update_nat_pool')
|
||||
self.stub_keystoneclient()
|
||||
|
||||
def create_nat_pool(self):
|
||||
gbpclient.Client.create_nat_pool({
|
||||
'nat_pool': {
|
||||
"name": "test-nat-pool",
|
||||
"description": "test NP resource",
|
||||
"ip_version": '6',
|
||||
"ip_pool": "192.168.0.0/24",
|
||||
"external_segment_id": '1234',
|
||||
"shared": True
|
||||
}
|
||||
}).AndReturn({'nat_pool': {'id': '5678'}})
|
||||
|
||||
snippet = template_format.parse(nat_pool_template)
|
||||
stack = utils.parse_stack(snippet)
|
||||
resource_defns = stack.t.resource_definitions(stack)
|
||||
return grouppolicy.NATPool(
|
||||
'nat_pool',
|
||||
resource_defns['nat_pool'], stack)
|
||||
|
||||
def test_create(self):
|
||||
rsrc = self.create_nat_pool()
|
||||
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_nat_pool({
|
||||
'nat_pool': {
|
||||
"name": "test-nat-pool",
|
||||
"description": "test NP resource",
|
||||
"ip_version": '6',
|
||||
"ip_pool": "192.168.0.0/24",
|
||||
"external_segment_id": '1234',
|
||||
"shared": True
|
||||
}
|
||||
}).AndRaise(grouppolicy.NeutronClientException())
|
||||
self.m.ReplayAll()
|
||||
|
||||
snippet = template_format.parse(nat_pool_template)
|
||||
stack = utils.parse_stack(snippet)
|
||||
resource_defns = stack.t.resource_definitions(stack)
|
||||
rsrc = grouppolicy.NATPool(
|
||||
'nat_pool',
|
||||
resource_defns['nat_pool'], 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_nat_pool('5678')
|
||||
gbpclient.Client.show_nat_pool('5678').AndRaise(
|
||||
grouppolicy.NeutronClientException(status_code=404))
|
||||
|
||||
rsrc = self.create_nat_pool()
|
||||
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_nat_pool('5678').AndRaise(
|
||||
grouppolicy.NeutronClientException(status_code=404))
|
||||
|
||||
rsrc = self.create_nat_pool()
|
||||
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_nat_pool('5678').AndRaise(
|
||||
grouppolicy.NeutronClientException(status_code=400))
|
||||
|
||||
rsrc = self.create_nat_pool()
|
||||
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_nat_pool()
|
||||
gbpclient.Client.update_nat_pool(
|
||||
'5678', {'nat_pool':
|
||||
{"external_segment_id": '9876'}})
|
||||
self.m.ReplayAll()
|
||||
scheduler.TaskRunner(rsrc.create)()
|
||||
|
||||
update_template = copy.deepcopy(rsrc.t)
|
||||
update_template['Properties']['external_segment_id'] = '9876'
|
||||
scheduler.TaskRunner(rsrc.update, update_template)()
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
|
|
@ -10,6 +10,7 @@ coverage>=3.6
|
|||
discover
|
||||
lockfile>=0.8
|
||||
mock>=1.0
|
||||
python-neutronclient==2.3.9
|
||||
python-subunit>=0.0.18
|
||||
mox>=0.5.3
|
||||
MySQL-python
|
||||
|
|
Loading…
Reference in New Issue