mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Vertica schema fix (#24915)
* replace deprecated cmp() with custom conditional cmp is not present in Python3 but several modules use it Reference 24756
This commit is contained in:
parent
9cd6f1bf91
commit
5240e5a230
4 changed files with 21 additions and 11 deletions
|
@ -141,7 +141,7 @@ def check(role_facts, role, assigned_roles):
|
||||||
role_key = role.lower()
|
role_key = role.lower()
|
||||||
if role_key not in role_facts:
|
if role_key not in role_facts:
|
||||||
return False
|
return False
|
||||||
if assigned_roles and cmp(sorted(assigned_roles), sorted(role_facts[role_key]['assigned_roles'])) != 0:
|
if assigned_roles and sorted(assigned_roles) != sorted(role_facts[role_key]['assigned_roles']):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -154,7 +154,7 @@ def present(role_facts, cursor, role, assigned_roles):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
changed = False
|
changed = False
|
||||||
if assigned_roles and cmp(sorted(assigned_roles), sorted(role_facts[role_key]['assigned_roles'])) != 0:
|
if assigned_roles and (sorted(assigned_roles) != sorted(role_facts[role_key]['assigned_roles'])):
|
||||||
update_roles(role_facts, cursor, role,
|
update_roles(role_facts, cursor, role,
|
||||||
role_facts[role_key]['assigned_roles'], assigned_roles)
|
role_facts[role_key]['assigned_roles'], assigned_roles)
|
||||||
changed = True
|
changed = True
|
||||||
|
|
|
@ -193,9 +193,9 @@ def check(schema_facts, schema, usage_roles, create_roles, owner):
|
||||||
return False
|
return False
|
||||||
if owner and owner.lower() == schema_facts[schema_key]['owner'].lower():
|
if owner and owner.lower() == schema_facts[schema_key]['owner'].lower():
|
||||||
return False
|
return False
|
||||||
if cmp(sorted(usage_roles), sorted(schema_facts[schema_key]['usage_roles'])) != 0:
|
if sorted(usage_roles) != sorted(schema_facts[schema_key]['usage_roles']):
|
||||||
return False
|
return False
|
||||||
if cmp(sorted(create_roles), sorted(schema_facts[schema_key]['create_roles'])) != 0:
|
if sorted(create_roles) != sorted(schema_facts[schema_key]['create_roles']):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -216,8 +216,9 @@ def present(schema_facts, cursor, schema, usage_roles, create_roles, owner):
|
||||||
"Changing schema owner is not supported. "
|
"Changing schema owner is not supported. "
|
||||||
"Current owner: {0}."
|
"Current owner: {0}."
|
||||||
).format(schema_facts[schema_key]['owner']))
|
).format(schema_facts[schema_key]['owner']))
|
||||||
if (cmp(sorted(usage_roles), sorted(schema_facts[schema_key]['usage_roles'])) != 0 or
|
if sorted(usage_roles) != sorted(schema_facts[schema_key]['usage_roles']) or \
|
||||||
cmp(sorted(create_roles), sorted(schema_facts[schema_key]['create_roles'])) != 0):
|
sorted(create_roles) != sorted(schema_facts[schema_key]['create_roles']):
|
||||||
|
|
||||||
update_roles(schema_facts, cursor, schema,
|
update_roles(schema_facts, cursor, schema,
|
||||||
schema_facts[schema_key]['usage_roles'], usage_roles,
|
schema_facts[schema_key]['usage_roles'], usage_roles,
|
||||||
schema_facts[schema_key]['create_roles'], create_roles)
|
schema_facts[schema_key]['create_roles'], create_roles)
|
||||||
|
|
|
@ -208,8 +208,8 @@ def check(user_facts, user, profile, resource_pool,
|
||||||
if (expired is not None and expired != (user_facts[user_key]['expired'] == 'True') or
|
if (expired is not None and expired != (user_facts[user_key]['expired'] == 'True') or
|
||||||
ldap is not None and ldap != (user_facts[user_key]['expired'] == 'True')):
|
ldap is not None and ldap != (user_facts[user_key]['expired'] == 'True')):
|
||||||
return False
|
return False
|
||||||
if (roles and (cmp(sorted(roles), sorted(user_facts[user_key]['roles'])) != 0 or
|
if roles and (sorted(roles) != sorted(user_facts[user_key]['roles']) or \
|
||||||
cmp(sorted(roles), sorted(user_facts[user_key]['default_roles'])) != 0)):
|
sorted(roles) != sorted(user_facts[user_key]['default_roles'])):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -275,8 +275,8 @@ def present(user_facts, cursor, user, profile, resource_pool,
|
||||||
changed = True
|
changed = True
|
||||||
if changed:
|
if changed:
|
||||||
cursor.execute(' '.join(query_fragments))
|
cursor.execute(' '.join(query_fragments))
|
||||||
if (roles and (cmp(sorted(roles), sorted(user_facts[user_key]['roles'])) != 0 or
|
if roles and (sorted(roles) != sorted(user_facts[user_key]['roles']) or \
|
||||||
cmp(sorted(roles), sorted(user_facts[user_key]['default_roles'])) != 0)):
|
sorted(roles) != sorted(user_facts[user_key]['default_roles'])):
|
||||||
update_roles(user_facts, cursor, user,
|
update_roles(user_facts, cursor, user,
|
||||||
user_facts[user_key]['roles'], user_facts[user_key]['default_roles'], roles)
|
user_facts[user_key]['roles'], user_facts[user_key]['default_roles'], roles)
|
||||||
changed = True
|
changed = True
|
||||||
|
|
|
@ -88,7 +88,16 @@ def compare_package(version1, version2):
|
||||||
|
|
||||||
def normalize(v):
|
def normalize(v):
|
||||||
return [int(x) for x in re.sub(r'(\.0+)*$', '', v).split(".")]
|
return [int(x) for x in re.sub(r'(\.0+)*$', '', v).split(".")]
|
||||||
return cmp(normalize(version1), normalize(version2))
|
normalized_version1 = normalize(version1)
|
||||||
|
normalized_version2 = normalize(version2)
|
||||||
|
if normalized_version1 == normalized_version2:
|
||||||
|
rc = 0
|
||||||
|
elif normalized_version1 < normalized_version2:
|
||||||
|
rc = -1
|
||||||
|
else:
|
||||||
|
rc = 1
|
||||||
|
return rc
|
||||||
|
|
||||||
|
|
||||||
def query_package(module, name, depot=None):
|
def query_package(module, name, depot=None):
|
||||||
""" Returns whether a package is installed or not and version. """
|
""" Returns whether a package is installed or not and version. """
|
||||||
|
|
Loading…
Reference in a new issue