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
This commit is contained in:
parent
6f0ef4240f
commit
88ccade9d5
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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']
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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}})
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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."""
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue