mylist = Foo().list() # OKAY, does not shadow built-in
+- Use the "is not" operator when testing for unequal identities. Example::
+
+ if not X is Y: # BAD, intended behavior is ambiguous
+ pass
+
+ if X is not Y: # OKAY, intuitive
+ pass
+
+- Use the "not in" operator for evaluating membership in a collection. Example::
+
+ if not X in Y: # BAD, intended behavior is ambiguous
+ pass
+
+ if X not in Y: # OKAY, intuitive
+ pass
+
+ if not (X in Y or X in Z): # OKAY, still better than all those 'not's
+ pass
+
Imports
-------
expl = _('Request body empty')
raise webob.exc.HTTPBadRequest(explanation=expl)
self._check_type(context, type_id)
- if not id in body:
+ if id not in body:
expl = _('Request body and URI mismatch')
raise webob.exc.HTTPBadRequest(explanation=expl)
if len(body) > 1:
class ProjectMapper(APIMapper):
def resource(self, member_name, collection_name, **kwargs):
- if not ('parent_resource' in kwargs):
+ if 'parent_resource' not in kwargs:
kwargs['path_prefix'] = '{project_id}/'
else:
parent_resource = kwargs['parent_resource']
Does not do any body introspection, only checks header
"""
- if not "Content-Type" in self.headers:
+ if "Content-Type" not in self.headers:
return None
allowed_types = SUPPORTED_CONTENT_TYPES
if not body:
raise exc.HTTPUnprocessableEntity()
- if not 'snapshot' in body:
+ if 'snapshot' not in body:
raise exc.HTTPUnprocessableEntity()
snapshot = body['snapshot']
if not body:
raise exc.HTTPUnprocessableEntity()
- if not 'volume' in body:
+ if 'volume' not in body:
raise exc.HTTPUnprocessableEntity()
volume = body['volume']
if not body:
raise exc.HTTPUnprocessableEntity()
- if not 'snapshot' in body:
+ if 'snapshot' not in body:
raise exc.HTTPUnprocessableEntity()
snapshot = body['snapshot']
if not body:
raise exc.HTTPUnprocessableEntity()
- if not 'volume' in body:
+ if 'volume' not in body:
raise exc.HTTPUnprocessableEntity()
volume = body['volume']
"""
fl = '%s_manager' % self.name
- if not fl in FLAGS:
+ if fl not in FLAGS:
return None
manager_class_name = FLAGS.get(fl, None)
def get_fake_uuid(token=0):
- if not token in FAKE_UUIDS:
+ if token not in FAKE_UUIDS:
FAKE_UUIDS[token] = str(uuid.uuid4())
return FAKE_UUIDS[token]
LOG.debug(_("%(relative_uri)s => code %(http_status)s") % locals())
if check_response_status:
- if not http_status in check_response_status:
+ if http_status not in check_response_status:
if http_status == 404:
raise OpenStackApiNotFoundException(response=response)
elif http_status == 401:
candidate = prefix + generate_random_numeric(8)
else:
candidate = prefix + generate_random_alphanumeric(8)
- if not candidate in items:
+ if candidate not in items:
return candidate
LOG.debug("Random collision on %s" % candidate)
self.assertEqual(volume_id, found_volume['id'])
- if not found_volume['status'] in continue_states:
+ if found_volume['status'] not in continue_states:
break
time.sleep(1)
return self._errors["CMMVC5701E"]
vol_name = kwargs["obj"].strip('\'\"')
- if not vol_name in self._volumes_list:
+ if vol_name not in self._volumes_list:
return self._errors["CMMVC5753E"]
if force == 0:
return self._errors["CMMVC5707E"]
mapping_info["vol"] = kwargs["obj"].strip('\'\"')
- if not mapping_info["vol"] in self._volumes_list:
+ if mapping_info["vol"] not in self._volumes_list:
return self._errors["CMMVC5753E"]
- if not mapping_info["host"] in self._hosts_list:
+ if mapping_info["host"] not in self._hosts_list:
return self._errors["CMMVC5754E"]
if mapping_info["vol"] in self._mappings_list:
return self._errors["CMMVC5701E"]
vol = kwargs["obj"].strip('\'\"')
- if not vol in self._mappings_list:
+ if vol not in self._mappings_list:
return self._errors["CMMVC5753E"]
if self._mappings_list[vol]["host"] != host:
if "source" not in kwargs:
return self._errors["CMMVC5707E"]
source = kwargs["source"].strip('\'\"')
- if not source in self._volumes_list:
+ if source not in self._volumes_list:
return self._errors["CMMVC5754E"]
if "target" not in kwargs:
return self._errors["CMMVC5707E"]
target = kwargs["target"].strip('\'\"')
- if not target in self._volumes_list:
+ if target not in self._volumes_list:
return self._errors["CMMVC5754E"]
if source == target:
l.append(val)
def _add_recorded_value(self, name, val):
- if not name in self._recorded_values:
+ if name not in self._recorded_values:
self._recorded_values[name] = []
self._recorded_values[name].append(val)
out, err = self._execute('vgs', '--noheadings', '-o', 'name',
run_as_root=True)
volume_groups = out.split()
- if not FLAGS.volume_group in volume_groups:
+ if FLAGS.volume_group not in volume_groups:
exception_message = (_("volume group %s doesn't exist")
% FLAGS.volume_group)
raise exception.VolumeBackendAPIException(data=exception_message)
def _get_lun_handle(self, name):
"""Get the details for a LUN from our cache table."""
- if not name in self.lun_table:
+ if name not in self.lun_table:
LOG.warn(_("Could not find handle for LUN named %s") % name)
return None
return self.lun_table[name].handle
"""Returns an error if prerequisites aren't met"""
(stdout, stderr) = self._execute('rados', 'lspools')
pools = stdout.split("\n")
- if not FLAGS.rbd_pool in pools:
+ if FLAGS.rbd_pool not in pools:
exception_message = (_("rbd has no pool %s") %
FLAGS.rbd_pool)
raise exception.VolumeBackendAPIException(data=exception_message)
# gives short output, but for compatibility reason we won't
# use it and just check if 'running' is in the output.
(out, err) = self._execute('collie', 'cluster', 'info')
- if not 'running' in out.split():
+ if 'running' not in out.split():
exception_message = (_("Sheepdog is not working: %s") % out)
raise exception.VolumeBackendAPIException(
data=exception_message)