summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlzyeval <lzyeval@gmail.com>2011-12-31 12:23:56 +0800
committerlzyeval <lzyeval@gmail.com>2012-01-04 07:32:13 +0800
commit88ccade9d5700db881f2ffc53e4a48a76e92c2db (patch)
treef8da941637a68a89705ac7e717992ac8b7d44fc7
parent6f0ef4240fc42f3bf4e7b59cd83997edddb3c985 (diff)
downloadnova-88ccade9d5700db881f2ffc53e4a48a76e92c2db.tar.gz
nova-88ccade9d5700db881f2ffc53e4a48a76e92c2db.tar.xz
nova-88ccade9d5700db881f2ffc53e4a48a76e92c2db.zip
PEP8 type comparison cleanup
Fixes bug #910295 The None, True, and False values are singletons. All variable *comparisons* to singletons should use 'is' or 'is not'. All variable *evaluations* to boolean should use 'if' or 'if not'. "== None", "== True", "== False", and "!= None" comparisons in sqlalchemy's where(), or_(), filter(), and_(), and select() functions should not be changed. Incorrect comparisons or evaluations in comments were not changed. Change-Id: I087f0883bf115b5fe714ccfda86a794b9b2a87f7
-rwxr-xr-xbin/nova-manage8
-rw-r--r--nova/api/ec2/apirequest.py2
-rw-r--r--nova/api/ec2/cloud.py6
-rw-r--r--nova/api/openstack/v2/contrib/flavorextraspecs.py2
-rw-r--r--nova/api/openstack/v2/contrib/volumetypes.py2
-rw-r--r--nova/common/cfg.py2
-rw-r--r--nova/network/manager.py2
-rw-r--r--nova/network/quantum/client.py2
-rw-r--r--nova/network/quantum/manager.py2
-rw-r--r--nova/scheduler/vsa.py3
-rw-r--r--nova/tests/db/fakes.py4
-rw-r--r--nova/tests/scheduler/test_distributed_scheduler.py12
-rw-r--r--nova/utils.py2
-rw-r--r--nova/virt/images.py2
-rw-r--r--nova/virt/xenapi/volumeops.py10
-rw-r--r--nova/volume/api.py2
-rw-r--r--nova/volume/manager.py2
-rw-r--r--nova/volume/xensm.py2
-rw-r--r--nova/vsa/api.py8
19 files changed, 37 insertions, 38 deletions
diff --git a/bin/nova-manage b/bin/nova-manage
index 7ac365950..a61b5c1dd 100755
--- a/bin/nova-manage
+++ b/bin/nova-manage
@@ -1605,7 +1605,7 @@ class VsaDriveTypeCommands(object):
if name is not None:
search_opts['extra_specs']['name'] = name
- if all == False:
+ if not all:
search_opts['extra_specs']['visible'] = '1'
drives = volume_types.get_all_types(self.context,
@@ -1973,7 +1973,7 @@ class StorageManagerCommands(object):
ctxt = context.get_admin_context()
try:
- if flavor == None:
+ if flavor is None:
flavors = db.sm_flavor_get_all(ctxt)
else:
flavors = db.sm_flavor_get(ctxt, flavor)
@@ -2015,7 +2015,7 @@ class StorageManagerCommands(object):
ctxt = context.get_admin_context()
try:
- if backend_conf_id == None:
+ if backend_conf_id is None:
backends = db.sm_backend_conf_get_all(ctxt)
else:
backends = db.sm_backend_conf_get(ctxt, backend_conf_id)
@@ -2075,7 +2075,7 @@ class StorageManagerCommands(object):
print '(WARNING: Creating will destroy all data on backend!!!)'
c = raw_input('Proceed? (y/n) ')
if c == 'y' or c == 'Y':
- if flavor_label == None:
+ if flavor_label is None:
print "error: backend needs to be associated with flavor"
sys.exit(2)
diff --git a/nova/api/ec2/apirequest.py b/nova/api/ec2/apirequest.py
index dd1692d50..f40be6e2a 100644
--- a/nova/api/ec2/apirequest.py
+++ b/nova/api/ec2/apirequest.py
@@ -99,7 +99,7 @@ class APIRequest(object):
request_id_el = xml.createElement('requestId')
request_id_el.appendChild(xml.createTextNode(request_id))
response_el.appendChild(request_id_el)
- if(response_data == True):
+ if response_data is True:
self._render_dict(xml, response_el, {'return': 'true'})
else:
self._render_dict(xml, response_el, response_data)
diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py
index dccb358aa..09324bb3c 100644
--- a/nova/api/ec2/cloud.py
+++ b/nova/api/ec2/cloud.py
@@ -884,7 +884,7 @@ class CloudController(object):
'volumeId': v['volumeId']}]
else:
v['attachmentSet'] = [{}]
- if volume.get('snapshot_id') != None:
+ if volume.get('snapshot_id') is not None:
v['snapshotId'] = ec2utils.id_to_ec2_snap_id(volume['snapshot_id'])
else:
v['snapshotId'] = None
@@ -895,7 +895,7 @@ class CloudController(object):
def create_volume(self, context, **kwargs):
size = kwargs.get('size')
- if kwargs.get('snapshot_id') != None:
+ if kwargs.get('snapshot_id') is not None:
snapshot_id = ec2utils.ec2_id_to_id(kwargs['snapshot_id'])
LOG.audit(_("Create volume from snapshot %s"), snapshot_id,
context=context)
@@ -1425,7 +1425,7 @@ class CloudController(object):
'ari': 'ramdisk',
'ami': 'machine'}
i['imageType'] = display_mapping.get(image_type)
- i['isPublic'] = image.get('is_public') == True
+ i['isPublic'] = not not image.get('is_public')
i['architecture'] = image['properties'].get('architecture')
properties = image['properties']
diff --git a/nova/api/openstack/v2/contrib/flavorextraspecs.py b/nova/api/openstack/v2/contrib/flavorextraspecs.py
index 1fbd74138..b7013a32d 100644
--- a/nova/api/openstack/v2/contrib/flavorextraspecs.py
+++ b/nova/api/openstack/v2/contrib/flavorextraspecs.py
@@ -37,7 +37,7 @@ class FlavorExtraSpecsController(object):
return dict(extra_specs=specs_dict)
def _check_body(self, body):
- if body == None or body == "":
+ if body is None or body == "":
expl = _('No Request Body')
raise exc.HTTPBadRequest(explanation=expl)
diff --git a/nova/api/openstack/v2/contrib/volumetypes.py b/nova/api/openstack/v2/contrib/volumetypes.py
index a963fdb1f..6906b522f 100644
--- a/nova/api/openstack/v2/contrib/volumetypes.py
+++ b/nova/api/openstack/v2/contrib/volumetypes.py
@@ -132,7 +132,7 @@ class VolumeTypeExtraSpecsController(object):
return dict(extra_specs=specs_dict)
def _check_body(self, body):
- if body == None or body == "":
+ if body is None or body == "":
expl = _('No Request Body')
raise exc.HTTPBadRequest(explanation=expl)
diff --git a/nova/common/cfg.py b/nova/common/cfg.py
index 68c505932..54940e7d9 100644
--- a/nova/common/cfg.py
+++ b/nova/common/cfg.py
@@ -821,7 +821,7 @@ class ConfigOpts(object):
:return: False if the opt was already register, True otherwise
:raises: DuplicateOptError, ArgsAlreadyParsedError
"""
- if self._args != None:
+ if self._args is not None:
raise ArgsAlreadyParsedError("cannot register CLI option")
if not self.register_opt(opt, group):
diff --git a/nova/network/manager.py b/nova/network/manager.py
index a86b65774..843a419a9 100644
--- a/nova/network/manager.py
+++ b/nova/network/manager.py
@@ -148,7 +148,7 @@ class RPCAllocateFixedIP(object):
if not network['multi_host']:
host = network['host']
# NOTE(vish): if there is no network host, set one
- if host == None:
+ if host is None:
host = rpc.call(context, FLAGS.network_topic,
{'method': 'set_network_host',
'args': {'network_ref': network}})
diff --git a/nova/network/quantum/client.py b/nova/network/quantum/client.py
index bcf8e1cb7..2e5d6f707 100644
--- a/nova/network/quantum/client.py
+++ b/nova/network/quantum/client.py
@@ -165,7 +165,7 @@ class Client(object):
# Open connection and send request, handling SSL certs
certs = {'key_file': self.key_file, 'cert_file': self.cert_file}
- certs = dict((x, certs[x]) for x in certs if certs[x] != None)
+ certs = dict((x, certs[x]) for x in certs if certs[x] is not None)
if self.use_ssl and len(certs):
c = connection_type(self.host, self.port, **certs)
diff --git a/nova/network/quantum/manager.py b/nova/network/quantum/manager.py
index 32e441db8..89bbb2f0d 100644
--- a/nova/network/quantum/manager.py
+++ b/nova/network/quantum/manager.py
@@ -339,7 +339,7 @@ class QuantumManager(manager.FlatManager):
if not port: # No dhcp server has been started
mac_address = self.generate_mac_address()
dev = self.driver.plug(network_ref, mac_address,
- gateway=(network_ref['gateway'] != None))
+ gateway=(network_ref['gateway'] is not None))
self.driver.initialize_gateway_device(dev, network_ref)
LOG.debug("Intializing DHCP for network: %s" %
network_ref)
diff --git a/nova/scheduler/vsa.py b/nova/scheduler/vsa.py
index 7c1670954..e4433694b 100644
--- a/nova/scheduler/vsa.py
+++ b/nova/scheduler/vsa.py
@@ -130,8 +130,7 @@ class VsaScheduler(simple.SimpleScheduler):
return filtered_hosts
def _allowed_to_use_host(self, host, selected_hosts, unique):
- if unique == False or \
- host not in [item[0] for item in selected_hosts]:
+ if not unique or host not in [item[0] for item in selected_hosts]:
return True
else:
return False
diff --git a/nova/tests/db/fakes.py b/nova/tests/db/fakes.py
index d9bdb2351..a28d6ded0 100644
--- a/nova/tests/db/fakes.py
+++ b/nova/tests/db/fakes.py
@@ -102,8 +102,8 @@ def stub_out_db_network_api(stubs):
networks = [network_fields]
def fake_floating_ip_allocate_address(context, project_id):
- ips = filter(lambda i: i['fixed_ip_id'] == None \
- and i['project_id'] == None,
+ ips = filter(lambda i: i['fixed_ip_id'] is None \
+ and i['project_id'] is None,
floating_ips)
if not ips:
raise exception.NoMoreFloatingIps()
diff --git a/nova/tests/scheduler/test_distributed_scheduler.py b/nova/tests/scheduler/test_distributed_scheduler.py
index 80781c049..047c8c51a 100644
--- a/nova/tests/scheduler/test_distributed_scheduler.py
+++ b/nova/tests/scheduler/test_distributed_scheduler.py
@@ -236,11 +236,11 @@ class DistributedSchedulerTestCase(test.TestCase):
for weighted_host in weighted_hosts:
# We set this up so remote hosts have even weights ...
if int(weighted_host.weight) % 2 == 0:
- self.assertTrue(weighted_host.zone != None)
- self.assertTrue(weighted_host.host == None)
+ self.assertTrue(weighted_host.zone is not None)
+ self.assertTrue(weighted_host.host is None)
else:
- self.assertTrue(weighted_host.host != None)
- self.assertTrue(weighted_host.zone == None)
+ self.assertTrue(weighted_host.host is not None)
+ self.assertTrue(weighted_host.zone is None)
def test_schedule_local_zone(self):
"""Test to make sure _schedule makes no call out to zones if
@@ -270,8 +270,8 @@ class DistributedSchedulerTestCase(test.TestCase):
self.assertEquals(len(weighted_hosts), 10)
for weighted_host in weighted_hosts:
# There should be no remote hosts
- self.assertTrue(weighted_host.host != None)
- self.assertTrue(weighted_host.zone == None)
+ self.assertTrue(weighted_host.host is not None)
+ self.assertTrue(weighted_host.zone is None)
def test_decrypt_blob(self):
"""Test that the decrypt method works."""
diff --git a/nova/utils.py b/nova/utils.py
index f4ee906fe..efefc5fd1 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -213,7 +213,7 @@ def execute(*cmd, **kwargs):
_returncode = obj.returncode # pylint: disable=E1101
if _returncode:
LOG.debug(_('Result was %s') % _returncode)
- if ignore_exit_code == False \
+ if not ignore_exit_code \
and _returncode not in check_exit_code:
(stdout, stderr) = result
raise exception.ProcessExecutionError(
diff --git a/nova/virt/images.py b/nova/virt/images.py
index e088a92b3..b884e5124 100644
--- a/nova/virt/images.py
+++ b/nova/virt/images.py
@@ -69,7 +69,7 @@ def fetch_to_raw(context, image_href, path, user_id, project_id):
data = _qemu_img_info(path_tmp)
fmt = data.get("file format", None)
- if fmt == None:
+ if fmt is None:
os.unlink(path_tmp)
raise exception.ImageUnacceptable(
reason=_("'qemu-img info' parsing failed."), image_id=image_href)
diff --git a/nova/virt/xenapi/volumeops.py b/nova/virt/xenapi/volumeops.py
index f9ba17fe6..0bce133ef 100644
--- a/nova/virt/xenapi/volumeops.py
+++ b/nova/virt/xenapi/volumeops.py
@@ -61,7 +61,7 @@ class VolumeOps(object):
def delete_volume_for_sm(self, vdi_uuid):
vdi_ref = self._session.call_xenapi("VDI.get_by_uuid", vdi_uuid)
- if vdi_ref == None:
+ if vdi_ref is None:
raise exception.Error(_('Could not find VDI ref'))
try:
@@ -73,10 +73,10 @@ class VolumeOps(object):
def create_sr(self, label, params):
LOG.debug(_("Creating SR %s") % label)
sr_ref = VolumeHelper.create_sr(self._session, label, params)
- if sr_ref == None:
+ if sr_ref is None:
raise exception.Error(_('Could not create SR'))
sr_rec = self._session.call_xenapi("SR.get_record", sr_ref)
- if sr_rec == None:
+ if sr_rec is None:
raise exception.Error(_('Could not retrieve SR record'))
return sr_rec['uuid']
@@ -89,7 +89,7 @@ class VolumeOps(object):
return sr_ref
sr_ref = VolumeHelper.introduce_sr(self._session, sr_uuid, label,
params)
- if sr_ref == None:
+ if sr_ref is None:
raise exception.Error(_('Could not introduce SR'))
return sr_ref
@@ -103,7 +103,7 @@ class VolumeOps(object):
# Checks if sr has been introduced
def forget_sr(self, sr_uuid):
sr_ref = VolumeHelper.find_sr_by_uuid(self._session, sr_uuid)
- if sr_ref == None:
+ if sr_ref is None:
LOG.INFO(_('SR %s not found in the xapi database') % sr_uuid)
return
try:
diff --git a/nova/volume/api.py b/nova/volume/api.py
index b4d5ac48d..1cfe8a3b6 100644
--- a/nova/volume/api.py
+++ b/nova/volume/api.py
@@ -42,7 +42,7 @@ class API(base.Base):
def create(self, context, size, snapshot_id, name, description,
volume_type=None, metadata=None, availability_zone=None):
- if snapshot_id != None:
+ if snapshot_id is not None:
snapshot = self.get_snapshot(context, snapshot_id)
if snapshot['status'] != "available":
raise exception.ApiError(
diff --git a/nova/volume/manager.py b/nova/volume/manager.py
index 5332f9d1e..19c2eb9c0 100644
--- a/nova/volume/manager.py
+++ b/nova/volume/manager.py
@@ -111,7 +111,7 @@ class VolumeManager(manager.SchedulerDependentManager):
vol_size = volume_ref['size']
LOG.debug(_("volume %(vol_name)s: creating lv of"
" size %(vol_size)sG") % locals())
- if snapshot_id == None:
+ if snapshot_id is None:
model_update = self.driver.create_volume(volume_ref)
else:
snapshot_ref = self.db.snapshot_get(context, snapshot_id)
diff --git a/nova/volume/xensm.py b/nova/volume/xensm.py
index dab14b689..a50362899 100644
--- a/nova/volume/xensm.py
+++ b/nova/volume/xensm.py
@@ -53,7 +53,7 @@ class XenSMDriver(VolumeDriver):
params['sr_type'] = backend_ref['sr_type']
- if backend_ref['sr_uuid'] == None:
+ if backend_ref['sr_uuid'] is None:
# run the sr create command
try:
LOG.debug(_('SR name = %s') % label)
diff --git a/nova/vsa/api.py b/nova/vsa/api.py
index 7635b51c5..4f6c5c271 100644
--- a/nova/vsa/api.py
+++ b/nova/vsa/api.py
@@ -68,10 +68,10 @@ class API(base.Base):
super(API, self).__init__(**kwargs)
def _check_volume_type_correctness(self, vol_type):
- if vol_type.get('extra_specs') == None or\
+ if vol_type.get('extra_specs') is None or\
vol_type['extra_specs'].get('type') != 'vsa_drive' or\
- vol_type['extra_specs'].get('drive_type') == None or\
- vol_type['extra_specs'].get('drive_size') == None:
+ vol_type['extra_specs'].get('drive_type') is None or\
+ vol_type['extra_specs'].get('drive_size') is None:
raise exception.ApiError(_("Invalid drive type %s")
% vol_type['name'])
@@ -162,7 +162,7 @@ class API(base.Base):
if storage is None:
storage = []
- if shared is None or shared == 'False' or shared == False:
+ if not shared or shared == 'False':
shared = False
else:
shared = True