1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fix incorrect use of is for comparisons.

See https://bugs.python.org/issue34850 for details.
This commit is contained in:
Matt Clay 2019-02-12 15:15:23 -08:00
parent cd7a144515
commit 0a461380a3
21 changed files with 42 additions and 42 deletions

View file

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

View file

@ -97,13 +97,13 @@ def run_commands(module, commands, check_rc=True):
def get_config(module, source='running', flags=None): def get_config(module, source='running', flags=None):
global _DEVICE_CONFIG 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 return _DEVICE_CONFIG
else: else:
conn = get_connection(module) conn = get_connection(module)
out = conn.get_config(source=source, flags=flags) out = conn.get_config(source=source, flags=flags)
cfg = to_text(out, errors='surrogate_then_replace').strip() 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 _DEVICE_CONFIG = cfg
return cfg return cfg

View file

@ -660,7 +660,7 @@ def main():
if len(instances) > count: if len(instances) > count:
for i in range(0, len(instances) - count): for i in range(0, len(instances) - count):
inst = instances[len(instances) - 1] 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, " 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)) "and please stop it or set 'force' as True.".format(inst.id))
try: try:
@ -765,7 +765,7 @@ def main():
else: else:
try: try:
for inst in instances: 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.") module.fail_json(msg="Instance is running, and please stop it or set 'force' as True.")
if inst.terminate(force=module.params['force']): if inst.terminate(force=module.params['force']):
changed = True changed = True

View file

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

View file

@ -1378,7 +1378,7 @@ def core(module):
# Set VM Host # Set VM Host
vmhost = module.params.get('vmhost') 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: if r.setVMHost(vminfo['name'], vmhost) is False:
return RHEV_FAILED, msg return RHEV_FAILED, msg

View file

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

View file

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

View file

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

View file

@ -196,7 +196,7 @@ def _choose_id_value(module):
def _choose_if_password_only(module, patch): 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']: if 'password' in patch[0]['path'] and module.params['skip_update_of_masked_password']:
# Return false to abort update as the password appears # Return false to abort update as the password appears
# to be the only element in the patch. # to be the only element in the patch.

View file

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

View file

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

View file

@ -384,7 +384,7 @@ class Migrations:
cluster_keys[cluster_key] = 1 cluster_keys[cluster_key] = 1
else: else:
cluster_keys[cluster_key] += 1 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: self._start_cluster_key in cluster_keys:
return True return True
return False return False

View file

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

View file

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

View file

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

View file

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

View file

@ -182,7 +182,7 @@ def sensu_check(module, path, name, state='present', backup=False):
stream = open(path, 'r') stream = open(path, 'r')
config = json.load(stream) config = json.load(stream)
except IOError as e: 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': if state == 'absent':
reasons.append('file did not exist and state is `absent\'') reasons.append('file did not exist and state is `absent\'')
return changed, reasons return changed, reasons

View file

@ -79,7 +79,7 @@ def sensu_subscription(module, path, name, state='present', backup=False):
try: try:
config = json.load(open(path)) config = json.load(open(path))
except IOError as e: 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': if state == 'absent':
reasons.append('file did not exist and state is `absent\'') reasons.append('file did not exist and state is `absent\'')
return changed, reasons return changed, reasons

View file

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

View file

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

View file

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