add more logging (#72)
continuous-integration/drone/push Build is passing Details

Closes #70.

Reviewed-on: #72
This commit is contained in:
Max Erenberg 2022-09-09 14:42:43 -04:00
parent 953bee549e
commit 651f4fb702
6 changed files with 24 additions and 6 deletions

View File

@ -19,8 +19,7 @@ class ICloudStackService(Interface):
The dict is mapping of usernames to account IDs. The dict is mapping of usernames to account IDs.
""" """
def delete_account(account_id: str): def delete_account(username: str, account_id: str):
""" """
Delete the given CloudStack account. Delete the given CloudStack account.
Note that a CloudStack account ID must be given, not a username.
""" """

View File

@ -35,6 +35,11 @@ def create_user():
# directly create new LDAP records. # directly create new LDAP records.
g.need_admin_creds = True g.need_admin_creds = True
if terms:
logger.info(f"Creating member {body['uid']} for terms {terms}")
else:
logger.info(f"Creating club rep {body['uid']} for non-member terms {non_member_terms}")
txn = AddMemberTransaction( txn = AddMemberTransaction(
uid=body['uid'], uid=body['uid'],
cn=body['cn'], cn=body['cn'],
@ -104,14 +109,17 @@ def renew_user(username: str):
user.set_expired(False) user.set_expired(False)
try: try:
user.subscribe_to_mailing_list(member_list) user.subscribe_to_mailing_list(member_list)
logger.debug(f'Unsubscribed {user.uid} from {member_list}')
except UserAlreadySubscribedError: except UserAlreadySubscribedError:
pass logger.debug(f'{user.uid} is already unsubscribed from {member_list}')
if body.get('terms'): if body.get('terms'):
logger.info(f"Renewing member {username} for terms {body['terms']}")
user.add_terms(body['terms']) user.add_terms(body['terms'])
unexpire(user) unexpire(user)
return {'terms_added': body['terms']} return {'terms_added': body['terms']}
elif body.get('non_member_terms'): elif body.get('non_member_terms'):
logger.info(f"Renewing club rep {username} for non-member terms {body['non_member_terms']}")
user.add_non_member_terms(body['non_member_terms']) user.add_non_member_terms(body['non_member_terms'])
unexpire(user) unexpire(user)
return {'non_member_terms_added': body['non_member_terms']} return {'non_member_terms_added': body['non_member_terms']}
@ -149,11 +157,13 @@ def expire_users():
if not dry_run: if not dry_run:
for member in members: for member in members:
logger.info(f'Expiring {member.uid}')
member.set_expired(True) member.set_expired(True)
try: try:
member.unsubscribe_from_mailing_list(member_list) member.unsubscribe_from_mailing_list(member_list)
logger.debug(f'Unsubscribed {member.uid} from {member_list}')
except UserNotSubscribedError: except UserNotSubscribedError:
pass logger.debug(f'{member.uid} is already unsubscribed from {member_list}')
return jsonify([member.uid for member in members]) return jsonify([member.uid for member in members])

View File

@ -97,7 +97,7 @@ class CloudResourceManager:
resources = accounts[username]['resources'] resources = accounts[username]['resources']
if 'cloudstack' in resources: if 'cloudstack' in resources:
account_id = accounts[username]['cloudstack_account_id'] account_id = accounts[username]['cloudstack_account_id']
cloudstack_srv.delete_account(account_id) cloudstack_srv.delete_account(username, account_id)
if 'vhost' in resources: if 'vhost' in resources:
vhost_mgr.delete_all_vhosts_for_user(username) vhost_mgr.delete_all_vhosts_for_user(username)
if 'k8s' in resources: if 'k8s' in resources:

View File

@ -76,7 +76,8 @@ class CloudStackService:
for account in d['account'] for account in d['account']
} }
def delete_account(self, account_id: str): def delete_account(self, username: str, account_id: str):
logger.info(f'Deleting CloudStack account for {username}')
url = self._create_url({ url = self._create_url({
'command': 'deleteAccount', 'command': 'deleteAccount',
'id': account_id, 'id': account_id,

View File

@ -7,6 +7,9 @@ from zope.interface import implementer
from ceo_common.errors import UserNotFoundError from ceo_common.errors import UserNotFoundError
from ceo_common.interfaces import IContainerRegistryService, IConfig from ceo_common.interfaces import IContainerRegistryService, IConfig
from ceo_common.logger_factory import logger_factory
logger = logger_factory(__name__)
@implementer(IContainerRegistryService) @implementer(IContainerRegistryService)
@ -70,6 +73,7 @@ class ContainerRegistryService:
resp.raise_for_status() resp.raise_for_status()
def delete_project_for_user(self, username: str): def delete_project_for_user(self, username: str):
logger.info(f'Deleting Harbor project for {username}')
# Delete all of the repositories inside the project first # Delete all of the repositories inside the project first
resp = self._http_get(f'/projects/{username}/repositories') resp = self._http_get(f'/projects/{username}/repositories')
if resp.status_code == 403: if resp.status_code == 403:

View File

@ -11,6 +11,9 @@ from zope import component
from zope.interface import implementer from zope.interface import implementer
from ceo_common.interfaces import IConfig, IKubernetesService from ceo_common.interfaces import IConfig, IKubernetesService
from ceo_common.logger_factory import logger_factory
logger = logger_factory(__name__)
@implementer(IKubernetesService) @implementer(IKubernetesService)
@ -100,6 +103,7 @@ class KubernetesService:
return body return body
def delete_account(self, username: str): def delete_account(self, username: str):
logger.info(f'Deleting Kubernetes namespace for {username}')
namespace = self._get_namespace(username) namespace = self._get_namespace(username)
# don't check exit code because namespace might not exist # don't check exit code because namespace might not exist
self._run(['kubectl', 'delete', 'namespace', namespace], check=False) self._run(['kubectl', 'delete', 'namespace', namespace], check=False)