Skip to content

Commit

Permalink
fix: parent group update fixed; logger messages updated
Browse files Browse the repository at this point in the history
  • Loading branch information
nenenko authored Jul 16, 2024
1 parent 15ce21f commit f9684be
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
17 changes: 9 additions & 8 deletions scripts/user_group_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,8 @@ def _get_gd_user_groups(self) -> list[CatalogUserGroup]:
@staticmethod
def _is_changed(group: TargetUserGroup, existing_group: CatalogUserGroup) -> bool:
"""Checks if user group has some changes and needs to be updated."""
parents_changed = (
group.parent_user_groups.sort() != existing_group.get_parents.sort()
)
group.parent_user_groups.sort()
parents_changed = group.parent_user_groups != existing_group.get_parents
name_changed = group.user_group_name != existing_group.name
return parents_changed or name_changed

Expand All @@ -246,7 +245,11 @@ def _create_or_update_user_group(
self.sdk.catalog_user.create_or_update_user_group(catalog_user_group)
logger.info(f"Succeeded to {action} user group {group_id}")
except Exception as e:
logger.error(f"Failed to {action} user group {group_id}: {e}")
if hasattr(e, "body") and e.body:
message = eval(e.body).get("detail", e)
else:
message = e.args[0] if e.args else str(e)
logger.error(f"Failed to {action} user group {group_id}: {message}")

def _create_missing_user_groups(self, group_ids_to_create) -> None:
"""Provisions user groups that don't exist."""
Expand Down Expand Up @@ -280,9 +283,7 @@ def _update_existing_user_groups(self, group_ids_to_update) -> None:
for group in groups_to_update:
existing_group = existing_groups[group.user_group_id]
if self._is_changed(group, existing_group):
logger.info(
f"Updating parent user groups of group {group.user_group_id}..."
)
logger.info(f"Updating user group {group.user_group_id}...")
self._create_or_update_user_group(
group.user_group_id,
group.user_group_name,
Expand Down Expand Up @@ -328,7 +329,7 @@ def manage_user_groups(self) -> None:
group_ids_to_delete = inactive_target_groups.intersection(gd_group_ids)
self._delete_user_group(group_ids_to_delete)

logger.info("User management run finished.")
logger.info("User group management run finished.")


def user_group_mgmt(args):
Expand Down
13 changes: 12 additions & 1 deletion tests/test_restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import os
import tempfile
import json
from pathlib import Path
from unittest import mock

Expand Down Expand Up @@ -421,7 +422,17 @@ def test_load_user_data_filters():
},
]
}
assert user_data_filters == user_data_filters_expected

# Convert both the expected and actual filter lists to sorted lists of their JSON string representations
sorted_user_data_filters = sorted(
json.dumps(d, sort_keys=True) for d in user_data_filters["userDataFilters"]
)
sorted_user_data_filters_expected = sorted(
json.dumps(d, sort_keys=True)
for d in user_data_filters_expected["userDataFilters"]
)

assert sorted_user_data_filters == sorted_user_data_filters_expected


@mock.patch("scripts.restore.create_client")
Expand Down

0 comments on commit f9684be

Please sign in to comment.