From 5240e5a2304c177ff37271aa010fb34907c06cc2 Mon Sep 17 00:00:00 2001 From: kgottholm Date: Tue, 23 May 2017 13:49:54 -0400 Subject: [PATCH] Vertica schema fix (#24915) * replace deprecated cmp() with custom conditional cmp is not present in Python3 but several modules use it Reference 24756 --- lib/ansible/modules/database/vertica/vertica_role.py | 4 ++-- .../modules/database/vertica/vertica_schema.py | 9 +++++---- lib/ansible/modules/database/vertica/vertica_user.py | 8 ++++---- lib/ansible/modules/packaging/os/swdepot.py | 11 ++++++++++- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/ansible/modules/database/vertica/vertica_role.py b/lib/ansible/modules/database/vertica/vertica_role.py index faf58c85bab..5f8c06b6535 100644 --- a/lib/ansible/modules/database/vertica/vertica_role.py +++ b/lib/ansible/modules/database/vertica/vertica_role.py @@ -141,7 +141,7 @@ def check(role_facts, role, assigned_roles): role_key = role.lower() if role_key not in role_facts: 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 True @@ -154,7 +154,7 @@ def present(role_facts, cursor, role, assigned_roles): return True else: 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, role_facts[role_key]['assigned_roles'], assigned_roles) changed = True diff --git a/lib/ansible/modules/database/vertica/vertica_schema.py b/lib/ansible/modules/database/vertica/vertica_schema.py index 2cd72030f93..3a5a5e9b597 100644 --- a/lib/ansible/modules/database/vertica/vertica_schema.py +++ b/lib/ansible/modules/database/vertica/vertica_schema.py @@ -193,9 +193,9 @@ def check(schema_facts, schema, usage_roles, create_roles, owner): return False if owner and owner.lower() == schema_facts[schema_key]['owner'].lower(): 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 - 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 True @@ -216,8 +216,9 @@ def present(schema_facts, cursor, schema, usage_roles, create_roles, owner): "Changing schema owner is not supported. " "Current owner: {0}." ).format(schema_facts[schema_key]['owner'])) - if (cmp(sorted(usage_roles), sorted(schema_facts[schema_key]['usage_roles'])) != 0 or - cmp(sorted(create_roles), sorted(schema_facts[schema_key]['create_roles'])) != 0): + if sorted(usage_roles) != sorted(schema_facts[schema_key]['usage_roles']) or \ + sorted(create_roles) != sorted(schema_facts[schema_key]['create_roles']): + update_roles(schema_facts, cursor, schema, schema_facts[schema_key]['usage_roles'], usage_roles, schema_facts[schema_key]['create_roles'], create_roles) diff --git a/lib/ansible/modules/database/vertica/vertica_user.py b/lib/ansible/modules/database/vertica/vertica_user.py index f09920e8fe1..314c9dd42c6 100644 --- a/lib/ansible/modules/database/vertica/vertica_user.py +++ b/lib/ansible/modules/database/vertica/vertica_user.py @@ -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 ldap is not None and ldap != (user_facts[user_key]['expired'] == 'True')): return False - if (roles and (cmp(sorted(roles), sorted(user_facts[user_key]['roles'])) != 0 or - cmp(sorted(roles), sorted(user_facts[user_key]['default_roles'])) != 0)): + if roles and (sorted(roles) != sorted(user_facts[user_key]['roles']) or \ + sorted(roles) != sorted(user_facts[user_key]['default_roles'])): return False return True @@ -275,8 +275,8 @@ def present(user_facts, cursor, user, profile, resource_pool, changed = True if changed: cursor.execute(' '.join(query_fragments)) - if (roles and (cmp(sorted(roles), sorted(user_facts[user_key]['roles'])) != 0 or - cmp(sorted(roles), sorted(user_facts[user_key]['default_roles'])) != 0)): + if roles and (sorted(roles) != sorted(user_facts[user_key]['roles']) or \ + sorted(roles) != sorted(user_facts[user_key]['default_roles'])): update_roles(user_facts, cursor, user, user_facts[user_key]['roles'], user_facts[user_key]['default_roles'], roles) changed = True diff --git a/lib/ansible/modules/packaging/os/swdepot.py b/lib/ansible/modules/packaging/os/swdepot.py index 92ca487542b..28c98a62368 100644 --- a/lib/ansible/modules/packaging/os/swdepot.py +++ b/lib/ansible/modules/packaging/os/swdepot.py @@ -88,7 +88,16 @@ def compare_package(version1, version2): def normalize(v): 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): """ Returns whether a package is installed or not and version. """