Fix incorrect use of `is` for comparisons.

See https://bugs.python.org/issue34850 for details.
pull/52142/head
Matt Clay 6 years ago
parent cd7a144515
commit 0a461380a3

@ -154,7 +154,7 @@ def signed_request(
if session_in_query:
query["X-Amz-Security-Token"] = session_token
if method is "GET":
if method == "GET":
body = ""
# Derived data
@ -194,7 +194,7 @@ def signed_request(
url = "https://" + host + uri
if query_string is not "":
if query_string != "":
url = url + "?" + query_string
final_headers = {

@ -97,13 +97,13 @@ def run_commands(module, commands, check_rc=True):
def get_config(module, source='running', flags=None):
global _DEVICE_CONFIG
if source is 'running' and flags is None and _DEVICE_CONFIG is not None:
if source == 'running' and flags is None and _DEVICE_CONFIG is not None:
return _DEVICE_CONFIG
else:
conn = get_connection(module)
out = conn.get_config(source=source, flags=flags)
cfg = to_text(out, errors='surrogate_then_replace').strip()
if source is 'running' and flags is None:
if source == 'running' and flags is None:
_DEVICE_CONFIG = cfg
return cfg

@ -660,7 +660,7 @@ def main():
if len(instances) > count:
for i in range(0, len(instances) - count):
inst = instances[len(instances) - 1]
if inst.status is not 'stopped' and not force:
if inst.status != 'stopped' and not force:
module.fail_json(msg="That to delete instance {0} is failed results from it is running, "
"and please stop it or set 'force' as True.".format(inst.id))
try:
@ -765,7 +765,7 @@ def main():
else:
try:
for inst in instances:
if inst.status is not 'stopped' and not force:
if inst.status != 'stopped' and not force:
module.fail_json(msg="Instance is running, and please stop it or set 'force' as True.")
if inst.terminate(force=module.params['force']):
changed = True

@ -923,7 +923,7 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
if set(current_nics) != set(network_interfaces):
self.log('CHANGED: virtual machine {0} - network interfaces are different.'.format(self.name))
differences.append('Network Interfaces')
updated_nics = [dict(id=id, primary=(i is 0))
updated_nics = [dict(id=id, primary=(i == 0))
for i, id in enumerate(network_interfaces)]
vm_dict['properties']['networkProfile']['networkInterfaces'] = updated_nics
changed = True
@ -1067,7 +1067,7 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
if not self.short_hostname:
self.short_hostname = self.name
nics = [self.compute_models.NetworkInterfaceReference(id=id, primary=(i is 0))
nics = [self.compute_models.NetworkInterfaceReference(id=id, primary=(i == 0))
for i, id in enumerate(network_interfaces)]
# os disk
@ -1217,7 +1217,7 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
self.log("Update virtual machine {0}".format(self.name))
self.results['actions'].append('Updated VM {0}'.format(self.name))
nics = [self.compute_models.NetworkInterfaceReference(id=interface['id'], primary=(i is 0))
nics = [self.compute_models.NetworkInterfaceReference(id=interface['id'], primary=(i == 0))
for i, interface in enumerate(vm_dict['properties']['networkProfile']['networkInterfaces'])]
# os disk

@ -1378,7 +1378,7 @@ def core(module):
# Set VM Host
vmhost = module.params.get('vmhost')
if vmhost is not False and vmhost is not "False":
if vmhost is not False and vmhost != "False":
if r.setVMHost(vminfo['name'], vmhost) is False:
return RHEV_FAILED, msg

@ -489,22 +489,22 @@ def core(module):
module.fail_json(msg="state change requires a guest specified")
if state == 'running':
if v.status(guest) is 'paused':
if v.status(guest) == 'paused':
res['changed'] = True
res['msg'] = v.unpause(guest)
elif v.status(guest) is not 'running':
elif v.status(guest) != 'running':
res['changed'] = True
res['msg'] = v.start(guest)
elif state == 'shutdown':
if v.status(guest) is not 'shutdown':
if v.status(guest) != 'shutdown':
res['changed'] = True
res['msg'] = v.shutdown(guest)
elif state == 'destroyed':
if v.status(guest) is not 'shutdown':
if v.status(guest) != 'shutdown':
res['changed'] = True
res['msg'] = v.destroy(guest)
elif state == 'paused':
if v.status(guest) is 'running':
if v.status(guest) == 'running':
res['changed'] = True
res['msg'] = v.pause(guest)
else:

@ -509,7 +509,7 @@ def core(module):
res['changed'] = False
if state in ['active']:
if v.status(name) is not 'active':
if v.status(name) != 'active':
res['changed'] = True
res['msg'] = v.start(name)
elif state in ['present']:
@ -523,13 +523,13 @@ def core(module):
elif state in ['inactive']:
entries = v.list_nets()
if name in entries:
if v.status(name) is not 'inactive':
if v.status(name) != 'inactive':
res['changed'] = True
res['msg'] = v.destroy(name)
elif state in ['undefined', 'absent']:
entries = v.list_nets()
if name in entries:
if v.status(name) is not 'inactive':
if v.status(name) != 'inactive':
v.destroy(name)
res['changed'] = True
res['msg'] = v.undefine(name)

@ -578,7 +578,7 @@ def core(module):
res['changed'] = False
if state in ['active']:
if v.status(name) is not 'active':
if v.status(name) != 'active':
res['changed'] = True
res['msg'] = v.start(name)
elif state in ['present']:
@ -592,20 +592,20 @@ def core(module):
elif state in ['inactive']:
entries = v.list_pools()
if name in entries:
if v.status(name) is not 'inactive':
if v.status(name) != 'inactive':
res['changed'] = True
res['msg'] = v.destroy(name)
elif state in ['undefined', 'absent']:
entries = v.list_pools()
if name in entries:
if v.status(name) is not 'inactive':
if v.status(name) != 'inactive':
v.destroy(name)
res['changed'] = True
res['msg'] = v.undefine(name)
elif state in ['deleted']:
entries = v.list_pools()
if name in entries:
if v.status(name) is not 'inactive':
if v.status(name) != 'inactive':
v.destroy(name)
v.delete(name, mode)
res['changed'] = True

@ -196,7 +196,7 @@ def _choose_id_value(module):
def _choose_if_password_only(module, patch):
if len(patch) is 1:
if len(patch) == 1:
if 'password' in patch[0]['path'] and module.params['skip_update_of_masked_password']:
# Return false to abort update as the password appears
# to be the only element in the patch.

@ -259,7 +259,7 @@ def main():
timeout = module.params['timeout']
# User has reqeusted desired state to be in maintenance state.
if module.params['state'] is 'maintenance':
if module.params['state'] == 'maintenance':
module.params['maintenance'] = True
if node['provision_state'] in [

@ -92,7 +92,7 @@ def get_node_status(module, node='all'):
else:
cmd = "pcs cluster pcsd-status"
rc, out, err = module.run_command(cmd)
if rc is 1:
if rc == 1:
module.fail_json(msg="Command execution failed.\nCommand: `%s`\nError: %s" % (cmd, err))
status = []
for o in out.splitlines():
@ -103,7 +103,7 @@ def get_node_status(module, node='all'):
def clean_cluster(module, timeout):
cmd = "pcs resource cleanup"
rc, out, err = module.run_command(cmd)
if rc is 1:
if rc == 1:
module.fail_json(msg="Command execution failed.\nCommand: `%s`\nError: %s" % (cmd, err))
@ -115,7 +115,7 @@ def set_cluster(module, state, timeout, force):
if force:
cmd = "%s --force" % cmd
rc, out, err = module.run_command(cmd)
if rc is 1:
if rc == 1:
module.fail_json(msg="Command execution failed.\nCommand: `%s`\nError: %s" % (cmd, err))
t = time.time()
@ -143,7 +143,7 @@ def set_node(module, state, timeout, force, node='all'):
if node[1].strip().lower() != state:
cmd = "%s %s" % (cmd, node[0].strip())
rc, out, err = module.run_command(cmd)
if rc is 1:
if rc == 1:
module.fail_json(msg="Command execution failed.\nCommand: `%s`\nError: %s" % (cmd, err))
t = time.time()

@ -384,7 +384,7 @@ class Migrations:
cluster_keys[cluster_key] = 1
else:
cluster_keys[cluster_key] += 1
if len(cluster_keys.keys()) is 1 and \
if len(cluster_keys.keys()) == 1 and \
self._start_cluster_key in cluster_keys:
return True
return False

@ -85,7 +85,7 @@ def typedvalue(value):
def getvariable(cursor, mysqlvar):
cursor.execute("SHOW VARIABLES WHERE Variable_name = %s", (mysqlvar,))
mysqlvar_val = cursor.fetchall()
if len(mysqlvar_val) is 1:
if len(mysqlvar_val) == 1:
return mysqlvar_val[0][1]
else:
return None

@ -310,7 +310,7 @@ def main():
# Therefore a small check here to replace list(None) by None. Otherwise get_user_diff() would return sshpubkey
# as different which should be avoided.
if module.params['sshpubkey'] is not None:
if len(module.params['sshpubkey']) == 1 and module.params['sshpubkey'][0] is "":
if len(module.params['sshpubkey']) == 1 and module.params['sshpubkey'][0] == "":
module.params['sshpubkey'] = None
try:

@ -601,7 +601,7 @@ class LogicMonitor(object):
resp = self.rpc("getAgents", {})
resp_json = json.loads(resp)
if resp_json["status"] is 200:
if resp_json["status"] == 200:
self.module.debug("RPC call succeeded")
return resp_json["data"]
else:
@ -1063,7 +1063,7 @@ class Collector(LogicMonitor):
self.module.debug("Making RPC call to 'addAgent'")
create = (json.loads(self.rpc("addAgent", h)))
if create["status"] is 200:
if create["status"] == 200:
self.module.debug("RPC call succeeded")
self.info = create["data"]
self.id = create["data"]["id"]
@ -1100,7 +1100,7 @@ class Collector(LogicMonitor):
delete = json.loads(self.rpc("deleteAgent",
{"id": self.id}))
if delete["status"] is 200:
if delete["status"] == 200:
self.module.debug("RPC call succeeded")
return delete
else:

@ -185,7 +185,7 @@ class LogicMonitor(object):
resp = self.rpc("getAgents", {})
resp_json = json.loads(resp)
if resp_json["status"] is 200:
if resp_json["status"] == 200:
self.module.debug("RPC call succeeded")
return resp_json["data"]
else:

@ -182,7 +182,7 @@ def sensu_check(module, path, name, state='present', backup=False):
stream = open(path, 'r')
config = json.load(stream)
except IOError as e:
if e.errno is 2: # File not found, non-fatal
if e.errno == 2: # File not found, non-fatal
if state == 'absent':
reasons.append('file did not exist and state is `absent\'')
return changed, reasons

@ -79,7 +79,7 @@ def sensu_subscription(module, path, name, state='present', backup=False):
try:
config = json.load(open(path))
except IOError as e:
if e.errno is 2: # File not found, non-fatal
if e.errno == 2: # File not found, non-fatal
if state == 'absent':
reasons.append('file did not exist and state is `absent\'')
return changed, reasons

@ -259,7 +259,7 @@ def parse_name(line, dest):
def parse_level(line, dest):
level = None
if dest is not 'host':
if dest != 'host':
# Line for buffer logging entry in running-config is of the form:
# logging buffered <size> <level>

@ -237,7 +237,7 @@ def get_services(device, dev_group, svc_list, obj_list):
def port_in_svc(orientation, port, protocol, obj):
# Process address objects
if orientation is 'source':
if orientation == 'source':
for x in obj.source_port.split(','):
if '-' in x:
port_range = x.split('-')
@ -248,7 +248,7 @@ def port_in_svc(orientation, port, protocol, obj):
else:
if port == x and obj.protocol == protocol:
return True
elif orientation is 'destination':
elif orientation == 'destination':
for x in obj.destination_port.split(','):
if '-' in x:
port_range = x.split('-')

@ -250,8 +250,8 @@ class BE(object):
# On FreeBSD, we exclude currently mounted BE on /, as it is
# special and can be activated even if it is mounted. That is not
# possible with non-root BEs.
if line.split('\t')[2] is not '-' and \
line.split('\t')[2] is not '/':
if line.split('\t')[2] != '-' and \
line.split('\t')[2] != '/':
return True
else:
if out.split(';')[3]:

Loading…
Cancel
Save