Fix ATTR_NOT_SPECIFIED comparison errors
Fixes bug #1099663 Replaced equality operators used with ATTR_NOT_SPECIFIED to 'is' or 'is not'. Used is_attr_set() where comparsion is done to None and ATTR_NOT_SPECIFIED. Change-Id: I67c87051b46ca0518fa777cbb1c3e6141a533b61
This commit is contained in:
parent
eae2ae5cc4
commit
e3721d2e05
@ -653,7 +653,7 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
|
||||
p = port['port']
|
||||
ips = []
|
||||
|
||||
fixed_configured = (p['fixed_ips'] != attributes.ATTR_NOT_SPECIFIED)
|
||||
fixed_configured = p['fixed_ips'] is not attributes.ATTR_NOT_SPECIFIED
|
||||
if fixed_configured:
|
||||
configured_ips = self._test_fixed_ips_for_port(context,
|
||||
p["network_id"],
|
||||
@ -803,7 +803,7 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
|
||||
"""
|
||||
|
||||
pools = []
|
||||
if subnet['allocation_pools'] == attributes.ATTR_NOT_SPECIFIED:
|
||||
if subnet['allocation_pools'] is attributes.ATTR_NOT_SPECIFIED:
|
||||
# Auto allocate the pool around gateway_ip
|
||||
net = netaddr.IPNetwork(subnet['cidr'])
|
||||
first_ip = net.first + 1
|
||||
@ -1008,9 +1008,7 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
|
||||
|
||||
if 'cidr' in s:
|
||||
self._validate_ip_version(ip_ver, s['cidr'], 'cidr')
|
||||
if ('gateway_ip' in s and
|
||||
s['gateway_ip'] and
|
||||
s['gateway_ip'] != attributes.ATTR_NOT_SPECIFIED):
|
||||
if attributes.is_attr_set(s.get('gateway_ip')):
|
||||
self._validate_ip_version(ip_ver, s['gateway_ip'], 'gateway_ip')
|
||||
if (cfg.CONF.force_gateway_on_subnet and
|
||||
not QuantumDbPluginV2._check_subnet_ip(s['cidr'],
|
||||
@ -1018,8 +1016,7 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
|
||||
error_message = _("Gateway is not valid on subnet")
|
||||
raise q_exc.InvalidInput(error_message=error_message)
|
||||
|
||||
if ('dns_nameservers' in s and
|
||||
s['dns_nameservers'] != attributes.ATTR_NOT_SPECIFIED):
|
||||
if attributes.is_attr_set(s.get('dns_nameservers')):
|
||||
if len(s['dns_nameservers']) > cfg.CONF.max_dns_nameservers:
|
||||
raise q_exc.DNSNameServersExhausted(
|
||||
subnet_id=id,
|
||||
@ -1033,8 +1030,7 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
|
||||
dns))
|
||||
self._validate_ip_version(ip_ver, dns, 'dns_nameserver')
|
||||
|
||||
if ('host_routes' in s and
|
||||
s['host_routes'] != attributes.ATTR_NOT_SPECIFIED):
|
||||
if attributes.is_attr_set(s.get('host_routes')):
|
||||
if len(s['host_routes']) > cfg.CONF.max_subnet_host_routes:
|
||||
raise q_exc.HostRoutesExhausted(
|
||||
subnet_id=id,
|
||||
@ -1048,7 +1044,7 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
|
||||
self._validate_subnet(s)
|
||||
|
||||
net = netaddr.IPNetwork(s['cidr'])
|
||||
if s['gateway_ip'] == attributes.ATTR_NOT_SPECIFIED:
|
||||
if s['gateway_ip'] is attributes.ATTR_NOT_SPECIFIED:
|
||||
s['gateway_ip'] = str(netaddr.IPAddress(net.first + 1))
|
||||
|
||||
tenant_id = self._get_tenant_id_for_create(context, s)
|
||||
@ -1072,13 +1068,13 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
|
||||
pools = self._allocate_pools_for_subnet(context, s)
|
||||
|
||||
context.session.add(subnet)
|
||||
if s['dns_nameservers'] != attributes.ATTR_NOT_SPECIFIED:
|
||||
if s['dns_nameservers'] is not attributes.ATTR_NOT_SPECIFIED:
|
||||
for addr in s['dns_nameservers']:
|
||||
ns = models_v2.DNSNameServer(address=addr,
|
||||
subnet_id=subnet.id)
|
||||
context.session.add(ns)
|
||||
|
||||
if s['host_routes'] != attributes.ATTR_NOT_SPECIFIED:
|
||||
if s['host_routes'] is not attributes.ATTR_NOT_SPECIFIED:
|
||||
for rt in s['host_routes']:
|
||||
route = models_v2.Route(subnet_id=subnet.id,
|
||||
destination=rt['destination'],
|
||||
@ -1206,7 +1202,7 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
|
||||
|
||||
# Ensure that a MAC address is defined and it is unique on the
|
||||
# network
|
||||
if mac_address == attributes.ATTR_NOT_SPECIFIED:
|
||||
if mac_address is attributes.ATTR_NOT_SPECIFIED:
|
||||
mac_address = QuantumDbPluginV2._generate_mac(context,
|
||||
network_id)
|
||||
else:
|
||||
|
@ -288,7 +288,7 @@ class LoadBalancerPluginDb(LoadBalancerPluginBase):
|
||||
tenant_id = self._get_tenant_id_for_create(context, v)
|
||||
|
||||
with context.session.begin(subtransactions=True):
|
||||
if v['address'] == attributes.ATTR_NOT_SPECIFIED:
|
||||
if v['address'] is attributes.ATTR_NOT_SPECIFIED:
|
||||
address = None
|
||||
else:
|
||||
address = v['address']
|
||||
|
@ -78,7 +78,7 @@ class NECPluginV2Base(db_base_plugin_v2.QuantumDbPluginV2):
|
||||
|
||||
# validate network ownership
|
||||
super(NECPluginV2Base, self).get_network(context, pf['network_id'])
|
||||
if pf.get('in_port') != attributes.ATTR_NOT_SPECIFIED:
|
||||
if pf.get('in_port') is not attributes.ATTR_NOT_SPECIFIED:
|
||||
# validate port ownership
|
||||
super(NECPluginV2Base, self).get_port(context, pf['in_port'])
|
||||
|
||||
@ -99,7 +99,7 @@ class NECPluginV2Base(db_base_plugin_v2.QuantumDbPluginV2):
|
||||
'dst_port': 0,
|
||||
'protocol': ''}
|
||||
for key, default in conditions.items():
|
||||
if pf.get(key) == attributes.ATTR_NOT_SPECIFIED:
|
||||
if pf.get(key) is attributes.ATTR_NOT_SPECIFIED:
|
||||
params.update({key: default})
|
||||
else:
|
||||
params.update({key: pf.get(key)})
|
||||
|
@ -362,7 +362,7 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2):
|
||||
self._handle_provider_create(context, net_data)
|
||||
# Replace ATTR_NOT_SPECIFIED with None before sending to NVP
|
||||
for attr, value in network['network'].iteritems():
|
||||
if value == attributes.ATTR_NOT_SPECIFIED:
|
||||
if value is attributes.ATTR_NOT_SPECIFIED:
|
||||
net_data[attr] = None
|
||||
# FIXME(arosen) implement admin_state_up = False in NVP
|
||||
if net_data['admin_state_up'] is False:
|
||||
|
@ -66,12 +66,10 @@ def _set_rules(data):
|
||||
|
||||
def _is_attribute_explicitly_set(attribute_name, resource, target):
|
||||
"""Verify that an attribute is present and has a non-default value"""
|
||||
if ('default' in resource[attribute_name] and
|
||||
target.get(attribute_name, attributes.ATTR_NOT_SPECIFIED) !=
|
||||
attributes.ATTR_NOT_SPECIFIED):
|
||||
if (target[attribute_name] != resource[attribute_name]['default']):
|
||||
return True
|
||||
return False
|
||||
return ('default' in resource[attribute_name] and
|
||||
attribute_name in target and
|
||||
target[attribute_name] is not attributes.ATTR_NOT_SPECIFIED and
|
||||
target[attribute_name] != resource[attribute_name]['default'])
|
||||
|
||||
|
||||
def _build_target(action, original_target, plugin, context):
|
||||
|
@ -24,7 +24,6 @@ from quantum import context
|
||||
from quantum.api.extensions import PluginAwareExtensionManager
|
||||
from quantum.api.extensions import ExtensionMiddleware
|
||||
from quantum.api.v2 import attributes
|
||||
from quantum.api.v2.attributes import ATTR_NOT_SPECIFIED
|
||||
from quantum.api.v2.router import APIRouter
|
||||
from quantum.common import config
|
||||
from quantum.common import exceptions as q_exc
|
||||
|
@ -249,7 +249,8 @@ class QuantumDbPluginV2TestCase(unittest2.TestCase):
|
||||
if arg in kwargs and kwargs[arg] is not None:
|
||||
data['subnet'][arg] = kwargs[arg]
|
||||
|
||||
if kwargs.get('gateway_ip', ATTR_NOT_SPECIFIED) != ATTR_NOT_SPECIFIED:
|
||||
if ('gateway_ip' in kwargs and
|
||||
kwargs['gateway_ip'] is not ATTR_NOT_SPECIFIED):
|
||||
data['subnet']['gateway_ip'] = kwargs['gateway_ip']
|
||||
|
||||
subnet_req = self.new_create_request('subnets', data, fmt)
|
||||
|
Loading…
Reference in New Issue
Block a user