Vertica schema fix (#24915)

* replace deprecated cmp() with custom conditional
cmp is not present in Python3 but several modules use it
Reference 24756
(cherry picked from commit 5240e5a230)
This commit is contained in:
kgottholm 2017-05-23 13:49:54 -04:00 committed by James Cammarata
parent ef40b0085b
commit 091a379da1
4 changed files with 23 additions and 11 deletions

View file

@ -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

View file

@ -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)

View file

@ -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,10 @@ 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):
==== BASE ====
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)):
==== BASE ====
update_roles(user_facts, cursor, user,
user_facts[user_key]['roles'], user_facts[user_key]['default_roles'], roles)
changed = True

View file

@ -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. """