Use converters and constants from neutron-lib
In continuation to change If8485cb8be33b15795cee74ce3f367339b6b531c Change-Id: Ibfff9f2b9c52482e79933bc37b6b8c1100965177
This commit is contained in:
parent
6b2c15c3b8
commit
1222c91de9
@ -11,11 +11,11 @@
|
||||
# under the License.
|
||||
|
||||
import netaddr
|
||||
from neutron.api.v2 import attributes as attr
|
||||
from neutron import context
|
||||
from neutron.db import common_db_mixin
|
||||
from neutron.db import models_v2
|
||||
from neutron_lib.api import validators
|
||||
from neutron_lib import constants
|
||||
from neutron_lib.db import model_base
|
||||
from oslo_log import helpers as log
|
||||
from oslo_utils import uuidutils
|
||||
@ -743,7 +743,7 @@ class GroupPolicyDbPlugin(gpolicy.GroupPolicyPluginBase,
|
||||
ep_db.external_segments.append(assoc)
|
||||
|
||||
def _process_segment_ers(self, context, es_db, es):
|
||||
if es['external_routes'] is not attr.ATTR_NOT_SPECIFIED:
|
||||
if es['external_routes'] is not constants.ATTR_NOT_SPECIFIED:
|
||||
es_db.external_routes = []
|
||||
for rt in es['external_routes']:
|
||||
target = ExternalRoute(
|
||||
@ -754,7 +754,7 @@ class GroupPolicyDbPlugin(gpolicy.GroupPolicyPluginBase,
|
||||
es_db.external_routes.append(target)
|
||||
|
||||
def _set_ess_for_l3p(self, context, l3p_db, es_dict):
|
||||
if es_dict is attr.ATTR_NOT_SPECIFIED:
|
||||
if es_dict is constants.ATTR_NOT_SPECIFIED:
|
||||
return
|
||||
if not es_dict:
|
||||
l3p_db.external_segments = []
|
||||
@ -1034,7 +1034,7 @@ class GroupPolicyDbPlugin(gpolicy.GroupPolicyPluginBase,
|
||||
|
||||
def _get_attribute(self, attrs, key):
|
||||
value = attrs.get(key)
|
||||
if value is attr.ATTR_NOT_SPECIFIED:
|
||||
if value is constants.ATTR_NOT_SPECIFIED:
|
||||
value = None
|
||||
return value
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
# under the License.
|
||||
|
||||
from neutron.api import extensions
|
||||
from neutron.api.v2 import attributes as attr
|
||||
from neutron_lib.api import converters
|
||||
|
||||
from gbpservice.neutron.extensions import group_policy as gp
|
||||
|
||||
@ -23,7 +23,7 @@ EXTENDED_ATTRIBUTES_2_0 = {
|
||||
'allowed_vm_names': {
|
||||
'allow_post': True, 'allow_put': True, 'default': None,
|
||||
'validate': {'type:list_of_unique_strings': None},
|
||||
'convert_to': attr.convert_none_to_empty_list,
|
||||
'convert_to': converters.convert_none_to_empty_list,
|
||||
'is_visible': True},
|
||||
},
|
||||
}
|
||||
|
@ -11,7 +11,7 @@
|
||||
# under the License.
|
||||
|
||||
from neutron.api import extensions
|
||||
from neutron.api.v2 import attributes as attr
|
||||
from neutron_lib.api import converters
|
||||
|
||||
from gbpservice.neutron.extensions import group_policy as gp
|
||||
|
||||
@ -23,7 +23,7 @@ EXTENDED_ATTRIBUTES_2_0 = {
|
||||
'segmentation_labels': {
|
||||
'allow_post': True, 'allow_put': True, 'default': None,
|
||||
'validate': {'type:list_of_unique_strings': None},
|
||||
'convert_to': attr.convert_none_to_empty_list,
|
||||
'convert_to': converters.convert_none_to_empty_list,
|
||||
'is_visible': True},
|
||||
},
|
||||
}
|
||||
|
@ -14,8 +14,8 @@
|
||||
# under the License.
|
||||
|
||||
from neutron.api import extensions
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.extensions import l3
|
||||
from neutron_lib.api import converters
|
||||
|
||||
from gbpservice.neutron.extensions import cisco_apic
|
||||
|
||||
@ -33,14 +33,14 @@ EXT_GW_ATTRIBUTES = {
|
||||
# Additional contracts provided by external network
|
||||
'allow_put': True, 'allow_post': True,
|
||||
'is_visible': True, 'default': None,
|
||||
'convert_to': attributes.convert_none_to_empty_list,
|
||||
'convert_to': converters.convert_none_to_empty_list,
|
||||
'validate': {'type:list_of_unique_strings': None},
|
||||
},
|
||||
EXTERNAL_CONSUMED_CONTRACTS: {
|
||||
# Additional contracts consumed by external network
|
||||
'allow_put': True, 'allow_post': True,
|
||||
'is_visible': True, 'default': None,
|
||||
'convert_to': attributes.convert_none_to_empty_list,
|
||||
'convert_to': converters.convert_none_to_empty_list,
|
||||
'validate': {'type:list_of_unique_strings': None},
|
||||
}
|
||||
}
|
||||
|
@ -512,10 +512,10 @@ RESOURCE_ATTRIBUTE_MAP = {
|
||||
'is_visible': True},
|
||||
'policy_target_groups': {'allow_post': False, 'allow_put': False,
|
||||
'validate': {'type:uuid_list': None},
|
||||
'convert_to': attr.convert_none_to_empty_list,
|
||||
'convert_to': conv.convert_none_to_empty_list,
|
||||
'default': None, 'is_visible': True},
|
||||
attr.SHARED: {'allow_post': True, 'allow_put': True,
|
||||
'default': False, 'convert_to': attr.convert_to_boolean,
|
||||
'default': False, 'convert_to': conv.convert_to_boolean,
|
||||
'is_visible': True, 'required_by_policy': True,
|
||||
'enforce_policy': True},
|
||||
},
|
||||
|
@ -20,6 +20,7 @@ from neutron.db import l3_db
|
||||
from neutron.db import models_v2
|
||||
from neutron.db import securitygroups_db
|
||||
from neutron.plugins.ml2 import db as ml2_db
|
||||
from neutron_lib.api import validators
|
||||
from neutron_lib import constants
|
||||
from neutron_lib import exceptions as n_exc
|
||||
from oslo_log import log
|
||||
@ -94,7 +95,7 @@ def _get_security_groups_on_port(self, context, port):
|
||||
:returns: all security groups IDs on port belonging to tenant.
|
||||
"""
|
||||
p = port['port']
|
||||
if not securitygroups_db.attributes.is_attr_set(
|
||||
if not validators.is_attr_set(
|
||||
p.get(securitygroups_db.ext_sg.SECURITYGROUPS)):
|
||||
return
|
||||
if p.get('device_owner') and p['device_owner'].startswith('network:'):
|
||||
|
@ -25,7 +25,6 @@ from aim.common import utils
|
||||
from aim import context as aim_context
|
||||
from aim import utils as aim_utils
|
||||
from neutron.agent import securitygroups_rpc
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.common import rpc as n_rpc
|
||||
from neutron.common import topics as n_topics
|
||||
from neutron.db import address_scope_db
|
||||
@ -2140,7 +2139,7 @@ class ApicMechanismDriver(api_plus.MechanismDriver):
|
||||
'tenant_id': ext_network['tenant_id'],
|
||||
'name': 'snat-pool-port:%s' % host_or_vrf,
|
||||
'network_id': ext_network['id'],
|
||||
'mac_address': attributes.ATTR_NOT_SPECIFIED,
|
||||
'mac_address': n_constants.ATTR_NOT_SPECIFIED,
|
||||
'fixed_ips': [{'subnet_id': snat_subnet.id}],
|
||||
'admin_state_up': False}
|
||||
port = self.plugin.create_port(plugin_context,
|
||||
|
@ -18,7 +18,6 @@ from aim.api import resource as aim_resource
|
||||
from aim import context as aim_context
|
||||
from aim import utils as aim_utils
|
||||
from neutron.agent.linux import dhcp
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron import context as n_context
|
||||
from neutron.db import models_v2
|
||||
from neutron import manager
|
||||
@ -460,7 +459,7 @@ class AIMMappingDriver(nrd.CommonNeutronBase, aim_rpc.AIMMappingRPCMixin):
|
||||
"l2_policy_id": l2p['id'],
|
||||
"proxied_group_id": None,
|
||||
"proxy_type": None,
|
||||
"proxy_group_id": attributes.ATTR_NOT_SPECIFIED,
|
||||
"proxy_group_id": n_constants.ATTR_NOT_SPECIFIED,
|
||||
"network_service_policy_id": None,
|
||||
"service_management": False,
|
||||
"shared": l2p['shared'],
|
||||
@ -2269,7 +2268,7 @@ class AIMMappingDriver(nrd.CommonNeutronBase, aim_rpc.AIMMappingRPCMixin):
|
||||
'fixed_ips': [{'subnet_id': subnet['id']}],
|
||||
'device_id': '',
|
||||
'device_owner': '',
|
||||
'mac_address': attributes.ATTR_NOT_SPECIFIED,
|
||||
'mac_address': n_constants.ATTR_NOT_SPECIFIED,
|
||||
'name': '%s-%s' % (router_id, subnet['id']),
|
||||
'admin_state_up': True}
|
||||
try:
|
||||
|
@ -22,7 +22,6 @@ from apic_ml2.neutron.plugins.ml2.drivers.cisco.apic import apic_model
|
||||
from apic_ml2.neutron.plugins.ml2.drivers.cisco.apic import config # noqa
|
||||
from apicapi import apic_manager
|
||||
from neutron.agent.linux import dhcp
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.common import rpc as n_rpc
|
||||
from neutron.common import topics
|
||||
from neutron import context as nctx
|
||||
@ -658,7 +657,7 @@ class ApicMappingDriver(api.ResourceMappingDriver,
|
||||
'tenant_id': network['tenant_id'],
|
||||
'name': HOST_SNAT_POOL_PORT,
|
||||
'network_id': network['id'],
|
||||
'mac_address': attributes.ATTR_NOT_SPECIFIED,
|
||||
'mac_address': n_constants.ATTR_NOT_SPECIFIED,
|
||||
'fixed_ips': [{'subnet_id': snat_subnets[0]['id']}],
|
||||
'admin_state_up': False}
|
||||
port = self._create_port(context, attrs)
|
||||
@ -2902,7 +2901,7 @@ class ApicMappingDriver(api.ResourceMappingDriver,
|
||||
"l2_policy_id": l2p['id'],
|
||||
"proxied_group_id": None,
|
||||
"proxy_type": None,
|
||||
"proxy_group_id": attributes.ATTR_NOT_SPECIFIED,
|
||||
"proxy_group_id": n_constants.ATTR_NOT_SPECIFIED,
|
||||
"network_service_policy_id": None,
|
||||
"service_management": False,
|
||||
"shared": l2p['shared'],
|
||||
@ -3001,7 +3000,7 @@ class ApicMappingDriver(api.ResourceMappingDriver,
|
||||
'name': ext_net_name,
|
||||
'admin_state_up': True,
|
||||
'router:external': True,
|
||||
'provider:network_type': attributes.ATTR_NOT_SPECIFIED,
|
||||
'provider:network_type': n_constants.ATTR_NOT_SPECIFIED,
|
||||
'shared': es.get('shared', False)}
|
||||
extnet = self._create_network(context._plugin_context, attrs)
|
||||
|
||||
@ -3020,10 +3019,10 @@ class ApicMappingDriver(api.ResourceMappingDriver,
|
||||
'cidr': ('169.254.0.0/16' if es['ip_version'] == 4
|
||||
else 'fe80::/64'),
|
||||
'enable_dhcp': False,
|
||||
'gateway_ip': attributes.ATTR_NOT_SPECIFIED,
|
||||
'allocation_pools': attributes.ATTR_NOT_SPECIFIED,
|
||||
'dns_nameservers': attributes.ATTR_NOT_SPECIFIED,
|
||||
'host_routes': attributes.ATTR_NOT_SPECIFIED}
|
||||
'gateway_ip': n_constants.ATTR_NOT_SPECIFIED,
|
||||
'allocation_pools': n_constants.ATTR_NOT_SPECIFIED,
|
||||
'dns_nameservers': n_constants.ATTR_NOT_SPECIFIED,
|
||||
'host_routes': n_constants.ATTR_NOT_SPECIFIED}
|
||||
subnet = self._create_subnet(context._plugin_context, attrs)
|
||||
return subnet
|
||||
|
||||
@ -3139,7 +3138,7 @@ class ApicMappingDriver(api.ResourceMappingDriver,
|
||||
subnet = self._get_subnet(plugin_context, subnet_id)
|
||||
attrs = {'tenant_id': subnet['tenant_id'],
|
||||
'network_id': subnet['network_id'],
|
||||
'mac_address': attributes.ATTR_NOT_SPECIFIED,
|
||||
'mac_address': n_constants.ATTR_NOT_SPECIFIED,
|
||||
'fixed_ips': [{'subnet_id': subnet_id}],
|
||||
'device_id': '',
|
||||
'device_owner': '',
|
||||
@ -3254,10 +3253,10 @@ class ApicMappingDriver(api.ResourceMappingDriver,
|
||||
'enable_dhcp': False,
|
||||
'gateway_ip': gw,
|
||||
'allocation_pools':
|
||||
attributes.ATTR_NOT_SPECIFIED,
|
||||
'dns_nameservers': attributes.ATTR_NOT_SPECIFIED,
|
||||
n_constants.ATTR_NOT_SPECIFIED,
|
||||
'dns_nameservers': n_constants.ATTR_NOT_SPECIFIED,
|
||||
'host_routes':
|
||||
attributes.ATTR_NOT_SPECIFIED,
|
||||
n_constants.ATTR_NOT_SPECIFIED,
|
||||
'tenant_id': es['tenant_id']}
|
||||
subnet = self._create_subnet(context._plugin_context,
|
||||
attrs)
|
||||
|
@ -366,12 +366,12 @@ class ImplicitResourceOperations(local_api.LocalAPI,
|
||||
'ip_version': l3p['ip_version'],
|
||||
'cidr': usable_cidr,
|
||||
'enable_dhcp': True,
|
||||
'gateway_ip': attributes.ATTR_NOT_SPECIFIED,
|
||||
'allocation_pools': attributes.ATTR_NOT_SPECIFIED,
|
||||
'gateway_ip': n_const.ATTR_NOT_SPECIFIED,
|
||||
'allocation_pools': n_const.ATTR_NOT_SPECIFIED,
|
||||
'dns_nameservers': (
|
||||
cfg.CONF.resource_mapping.dns_nameservers or
|
||||
attributes.ATTR_NOT_SPECIFIED),
|
||||
'host_routes': attributes.ATTR_NOT_SPECIFIED}
|
||||
n_const.ATTR_NOT_SPECIFIED),
|
||||
'host_routes': n_const.ATTR_NOT_SPECIFIED}
|
||||
attrs.update(subnet_specifics)
|
||||
subnet = self._create_subnet(
|
||||
context._plugin_context, attrs)
|
||||
@ -571,22 +571,22 @@ class ImplicitResourceOperations(local_api.LocalAPI,
|
||||
'network_id': l2p['network_id'],
|
||||
'ip_version': ip_version,
|
||||
'subnetpool_id': pool['id'],
|
||||
'cidr': attributes.ATTR_NOT_SPECIFIED,
|
||||
'prefixlen': attributes.ATTR_NOT_SPECIFIED,
|
||||
'cidr': n_const.ATTR_NOT_SPECIFIED,
|
||||
'prefixlen': n_const.ATTR_NOT_SPECIFIED,
|
||||
'enable_dhcp': True,
|
||||
'gateway_ip': attributes.ATTR_NOT_SPECIFIED,
|
||||
'allocation_pools': attributes.ATTR_NOT_SPECIFIED,
|
||||
'gateway_ip': n_const.ATTR_NOT_SPECIFIED,
|
||||
'allocation_pools': n_const.ATTR_NOT_SPECIFIED,
|
||||
'dns_nameservers': (
|
||||
cfg.CONF.resource_mapping.dns_nameservers or
|
||||
attributes.ATTR_NOT_SPECIFIED),
|
||||
'host_routes': attributes.ATTR_NOT_SPECIFIED}
|
||||
n_const.ATTR_NOT_SPECIFIED),
|
||||
'host_routes': n_const.ATTR_NOT_SPECIFIED}
|
||||
if ip_version == 6:
|
||||
if 'ipv6_ra_mode' not in subnet_specifics:
|
||||
subnet_specifics['ipv6_ra_mode'] = (
|
||||
attributes.ATTR_NOT_SPECIFIED)
|
||||
n_const.ATTR_NOT_SPECIFIED)
|
||||
if 'ipv6_address_mode' not in subnet_specifics:
|
||||
subnet_specifics['ipv6_address_mode'] = (
|
||||
attributes.ATTR_NOT_SPECIFIED)
|
||||
n_const.ATTR_NOT_SPECIFIED)
|
||||
attrs.update(subnet_specifics)
|
||||
subnet = self._create_subnet(context._plugin_context, attrs)
|
||||
self._mark_subnet_owned(context._plugin_context.session,
|
||||
@ -648,7 +648,7 @@ class ImplicitResourceOperations(local_api.LocalAPI,
|
||||
attrs = {'tenant_id': context.current['tenant_id'],
|
||||
'name': 'pt_' + context.current['name'],
|
||||
'network_id': l2p['network_id'],
|
||||
'mac_address': attributes.ATTR_NOT_SPECIFIED,
|
||||
'mac_address': n_const.ATTR_NOT_SPECIFIED,
|
||||
'fixed_ips': [{'subnet_id': subnet['id']}],
|
||||
'device_id': '',
|
||||
'device_owner': '',
|
||||
@ -831,10 +831,10 @@ class ImplicitResourceOperations(local_api.LocalAPI,
|
||||
'ip_version': context.current['ip_version'],
|
||||
'cidr': context.current['ip_pool'],
|
||||
'enable_dhcp': False,
|
||||
'gateway_ip': attributes.ATTR_NOT_SPECIFIED,
|
||||
'allocation_pools': attributes.ATTR_NOT_SPECIFIED,
|
||||
'dns_nameservers': attributes.ATTR_NOT_SPECIFIED,
|
||||
'host_routes': attributes.ATTR_NOT_SPECIFIED}
|
||||
'gateway_ip': n_const.ATTR_NOT_SPECIFIED,
|
||||
'allocation_pools': n_const.ATTR_NOT_SPECIFIED,
|
||||
'dns_nameservers': n_const.ATTR_NOT_SPECIFIED,
|
||||
'host_routes': n_const.ATTR_NOT_SPECIFIED}
|
||||
subnet = self._create_subnet(context._plugin_context, attrs)
|
||||
context._plugin._set_db_np_subnet(
|
||||
context._plugin_context, context.current, subnet['id'])
|
||||
|
@ -20,6 +20,7 @@ from neutron.extensions import portbindings
|
||||
from neutron import manager as n_manager
|
||||
from neutron.plugins.common import constants as pconst
|
||||
from neutron.quota import resource_registry
|
||||
from neutron_lib import constants
|
||||
from oslo_log import helpers as log
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import excutils
|
||||
@ -453,7 +454,7 @@ class GroupPolicyPlugin(group_policy_mapping_db.GroupPolicyMappingDbPlugin):
|
||||
def _add_fixed_ips_to_port_attributes(self, policy_target):
|
||||
if 'fixed_ips' in policy_target['policy_target'] and (
|
||||
policy_target['policy_target']['fixed_ips'] is not (
|
||||
nattr.ATTR_NOT_SPECIFIED)):
|
||||
constants.ATTR_NOT_SPECIFIED)):
|
||||
port_attributes = {'fixed_ips': policy_target[
|
||||
'policy_target']['fixed_ips']}
|
||||
policy_target['policy_target'].update(
|
||||
|
@ -10,8 +10,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron.api.v2 import attributes as attr
|
||||
from neutron import manager
|
||||
from neutron_lib import constants
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
|
||||
@ -177,7 +177,7 @@ class TrafficStitchingPlumber(plumber_base.NodePlumberBase):
|
||||
"l2_policy_id": None,
|
||||
"proxied_group_id": proxied['id'],
|
||||
"proxy_type": type,
|
||||
"proxy_group_id": attr.ATTR_NOT_SPECIFIED,
|
||||
"proxy_group_id": constants.ATTR_NOT_SPECIFIED,
|
||||
"network_service_policy_id": None,
|
||||
"service_management": False
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
from neutron.api import extensions
|
||||
from neutron.api.v2 import attributes as attr
|
||||
from neutron.extensions import address_scope as as_ext
|
||||
from neutron_lib import constants
|
||||
|
||||
from gbpservice._i18n import _
|
||||
|
||||
@ -24,14 +25,14 @@ EXTENDED_ATTRIBUTES_2_0 = {
|
||||
attr.SUBNETPOOLS: {
|
||||
'subnetpool_extension': {'allow_post': True,
|
||||
'allow_put': True,
|
||||
'default': attr.ATTR_NOT_SPECIFIED,
|
||||
'default': constants.ATTR_NOT_SPECIFIED,
|
||||
'is_visible': True,
|
||||
'enforce_policy': True},
|
||||
},
|
||||
as_ext.ADDRESS_SCOPES: {
|
||||
'address_scope_extension': {'allow_post': True,
|
||||
'allow_put': True,
|
||||
'default': attr.ATTR_NOT_SPECIFIED,
|
||||
'default': constants.ATTR_NOT_SPECIFIED,
|
||||
'is_visible': True,
|
||||
'enforce_policy': True},
|
||||
},
|
||||
|
@ -14,7 +14,6 @@ import copy
|
||||
import re
|
||||
|
||||
import mock
|
||||
from neutron.api.v2 import attributes as nattr
|
||||
from neutron.plugins.common import constants
|
||||
from neutron.tests import base
|
||||
from neutron.tests.unit.api.v2 import test_base
|
||||
@ -92,9 +91,9 @@ class GroupPolicyExtensionTestCase(test_extensions_base.ExtensionTestCase):
|
||||
self.assertIn('policy_target', res)
|
||||
if 'fixed_ips' in expected_value and (
|
||||
str(res['policy_target']['fixed_ips']) ==
|
||||
str(nattr.ATTR_NOT_SPECIFIED)):
|
||||
str(n_consts.ATTR_NOT_SPECIFIED)):
|
||||
default_data['policy_target']['fixed_ips'] = (
|
||||
nattr.ATTR_NOT_SPECIFIED)
|
||||
n_consts.ATTR_NOT_SPECIFIED)
|
||||
expected_value['fixed_ips'] = res['policy_target']['fixed_ips']
|
||||
|
||||
self.assertEqual(expected_value, res['policy_target'])
|
||||
|
@ -13,8 +13,8 @@
|
||||
import copy
|
||||
import six
|
||||
|
||||
from neutron.api.v2 import attributes as nattr
|
||||
from neutron.plugins.common import constants
|
||||
from neutron_lib import constants as n_constants
|
||||
|
||||
from gbpservice.neutron.extensions import group_policy as gp
|
||||
from gbpservice.neutron.extensions import group_policy_mapping as gpm
|
||||
@ -176,6 +176,6 @@ class GroupPolicyMappingExtTestCase(tgp.GroupPolicyExtensionTestCase):
|
||||
default_data['policy_target'].update(default_attrs)
|
||||
expected_value = dict(default_data['policy_target'])
|
||||
expected_value['id'] = policy_target_id
|
||||
expected_value['fixed_ips'] = nattr.ATTR_NOT_SPECIFIED
|
||||
expected_value['fixed_ips'] = n_constants.ATTR_NOT_SPECIFIED
|
||||
|
||||
self._test_create_policy_target(data, expected_value, default_data)
|
||||
|
Loading…
Reference in New Issue
Block a user