Skip to content

Commit

Permalink
Merge pull request RedHatInsights#1133 from petracihalova/seeds_log_r…
Browse files Browse the repository at this point in the history
…evert

remove temporary seeding logs
  • Loading branch information
petracihalova authored Jul 2, 2024
2 parents 5a71008 + 0dcb286 commit 34cb1b4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 46 deletions.
24 changes: 2 additions & 22 deletions rbac/management/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,30 +195,10 @@ def delete_all_policies_for_tenant(self):
err_msg = f"Error deleting all policies for tenant {self.tenant}"
with self.delete_handler(err_msg):
logger.info("Deleting entire policy cache for tenant %s", self.tenant)
try:
key = self.key_for("*")
logger.info(f"value of key: {key}")
except Exception as e:
logger.error(f'error from key = self.key_for("*") with error message: {e}')

keys = []
try:
keys = self.connection.keys(key)
logger.info(f"Content of 'keys' variable: {keys}")
except Exception as e:
logger.error(f"error from keys = self.connection.keys(key): {e}")
keys = self.connection.keys(self.key_for("*"))

if keys:
try:
self.connection.delete(*keys)
except Exception as e:
logger.error(
f"An exception occurred inside delete_all_policies_for_tenant() for tenant {self.tenant} "
f"withing line 'if keys': {e}"
)

logger.info(f"End of 'with self.delete_handler' for tenant {self.tenant}")
logger.info(f"End of 'delete_all_policies_for_tenant' for tenant {self.tenant}")
self.connection.delete(*keys)

def save_policy(self, uuid, sub_key, policy):
"""Write the policy for a given user for a given sub_key (application_offset_limit) to Redis."""
Expand Down
6 changes: 1 addition & 5 deletions rbac/management/management/commands/seeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,4 @@ def handle(self, *args, **options):
group_seeding()
logger.info("*** Group seeding completed. ***\n")

try:
purge_cache()
except Exception as e:
logger.error(f"An exception occurred during purge cache: {e}")
raise e
purge_cache()
23 changes: 4 additions & 19 deletions rbac/management/seeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,9 @@
def on_complete(progress, tenant):
"""Explicitly close the connection for the thread."""
logger.info(f"Purging policy cache for tenant {tenant.org_id} [{progress}].")
try:
cache = AccessCache(tenant.org_id)
except Exception as e:
logger.error(f"An exception occurred inside on_complete() for line 1: {e}")

try:
cache.delete_all_policies_for_tenant()
except Exception as e:
logger.error(f"An exception occurred inside on_complete() for line 2: {e}")

try:
connections.close_all()
except Exception as e:
logger.error(f"An exception occurred inside on_complete() for line 3: {e}")

cache = AccessCache(tenant.org_id)
cache.delete_all_policies_for_tenant()
connections.close_all()
logger.info(f"Finished purging policy cache for tenant {tenant.org_id} [{progress}].")


Expand Down Expand Up @@ -86,7 +74,4 @@ def purge_cache():
tenant_count = tenants.count()
for idx, tenant in enumerate(list(tenants)):
progress = f"[{idx + 1} of {tenant_count}]."
try:
executor.submit(on_complete, progress, tenant)
except Exception as e:
logger.error(f"An exception occurred inside purge_cache() for {tenant}: {e}")
executor.submit(on_complete, progress, tenant)

0 comments on commit 34cb1b4

Please sign in to comment.