diff --git a/create_account.py b/create_account.py index b9b906783e99f88d51f7945a5099baca8fc84b6e..d81478079249ced461f2f53876b20456b8613130 100755 --- a/create_account.py +++ b/create_account.py @@ -13,9 +13,7 @@ parser.add_argument( parser.add_argument( "reason", nargs="?", default="", help="Reason of requesting" ) -parser.add_argument( - "--domain", default="localhost", help="domain of email" -) +parser.add_argument("--domain", default="localhost", help="domain of email") parser.add_argument( "-v", "--verbose", action="store_true", help="verbose output" ) diff --git a/dev_rmq_agents/ohpc_account_create.py b/dev_rmq_agents/ohpc_account_create.py index 206c4045094814751adc18876bf51d797911fd53..44c8f905557e74fe9cd0030c6799c1ee8ab942c5 100644 --- a/dev_rmq_agents/ohpc_account_create.py +++ b/dev_rmq_agents/ohpc_account_create.py @@ -38,9 +38,7 @@ def ohpc_account_create(ch, method, properties, body): if success: # send create message to other agent - rc_rmq.publish_msg( - {"routing_key": "create." + username, "msg": msg} - ) + rc_rmq.publish_msg({"routing_key": "create." + username, "msg": msg}) print("Start Listening to queue: {}".format(task)) diff --git a/dev_rmq_agents/ood_account_create.py b/dev_rmq_agents/ood_account_create.py index 339819ec86044ae180dfe1ecb40345ee6f3d5904..e87124f9490976f863cd16a5f930aa580377987e 100644 --- a/dev_rmq_agents/ood_account_create.py +++ b/dev_rmq_agents/ood_account_create.py @@ -18,9 +18,7 @@ def ood_account_create(ch, method, properties, body): user_gid = str(msg["gid"]) success = False try: - subprocess.call( - ["sudo", "groupadd", "-r", "-g", user_gid, username] - ) + subprocess.call(["sudo", "groupadd", "-r", "-g", user_gid, username]) subprocess.call( ["sudo", "useradd", "-u", user_uid, "-g", user_gid, username] ) diff --git a/flask_producer.py b/flask_producer.py index 1ef993ad630fb5cc1a0ba25a72b69c8a9e619471..908b57f9d9e5c6f752421dc76dc2fd472a4e2259 100755 --- a/flask_producer.py +++ b/flask_producer.py @@ -38,9 +38,7 @@ channel.basic_publish( print(" [x] Sent {}: {}".format(node, json.dumps(message))) # creates a named queue -result = channel.queue_declare( - queue=user_name, exclusive=False, durable=True -) +result = channel.queue_declare(queue=user_name, exclusive=False, durable=True) # bind the queue with exchange channel.queue_bind( @@ -50,10 +48,7 @@ channel.queue_bind( def work(ch, method, properties, body): msg = json.loads(body) - print( - "Received message from {}: \n\t{}".format(method.routing_key, msg) - ) - # queue_unbind(queue, exchange=None, routing_key=None, arguments=None, callback=None) + print("Received message from {}: \n\t{}".format(method.routing_key, msg)) channel.queue_delete(method.routing_key) diff --git a/prod_rmq_agents/dir_verify.py b/prod_rmq_agents/dir_verify.py index 89f98a4bd40892bcafaf2bd188c8188f8ee2cf5f..162dad9852f568f840cb13c1883a7d1ab11669c8 100644 --- a/prod_rmq_agents/dir_verify.py +++ b/prod_rmq_agents/dir_verify.py @@ -44,15 +44,12 @@ def dir_verify(ch, method, properties, body): mask = oct(status.st_mode)[-3:] uid = str(status.st_uid) gid = str(status.st_gid) - if ( - mask != "700" - or uid != msg["uid"] - or gid != msg["gid"] - ): + if mask != "700" or uid != msg["uid"] or gid != msg["gid"]: msg["success"] = False - msg[ - "errmsg" - ] = f"Error: dir {path} permissions or ownership are wrong" + msg["errmsg"] = ( + f"Error: dir {path} permissions or ownership are" + " wrong" + ) except Exception as exception: msg["success"] = False diff --git a/prod_rmq_agents/get-next-uid-gid.py b/prod_rmq_agents/get-next-uid-gid.py index 56b9b811ca2e4a222d304e1baefb01dda90cdf8a..714ab8c3b784607b13981e0ceebe00f5c80c2b2b 100644 --- a/prod_rmq_agents/get-next-uid-gid.py +++ b/prod_rmq_agents/get-next-uid-gid.py @@ -32,7 +32,8 @@ def create_account(msg): # Bright command to create user cmd = "/cm/local/apps/cmd/bin/cmsh -c " - cmd += f'"user; add {username}; set id {uid}; set email {email}; set commonname \\"{fullname}\\"; ' + cmd += f'"user; add {username}; set id {uid}; set email {email};' + cmd += f'set commonname \\"{fullname}\\"; ' cmd += 'commit;"' if not args.dry_run: @@ -61,13 +62,19 @@ def resolve_uid_gid(ch, method, properties, body): msg["gid"] = user_exists.split(":")[3] else: - cmd_uid = "/usr/bin/getent passwd | \ - awk -F: 'BEGIN { maxuid=10000 } ($3>10000) && ($3<20000) && ($3>maxuid) { maxuid=$3; } END { print maxuid+1; }'" + cmd_uid = ( + "/usr/bin/getent passwd | awk -F: 'BEGIN { maxuid=10000 }" + " ($3>10000) && ($3<20000) && ($3>maxuid) { maxuid=$3; } END {" + " print maxuid+1; }'" + ) msg["uid"] = popen(cmd_uid).read().rstrip() logger.info(f"UID query: {cmd_uid}") - cmd_gid = "/usr/bin/getent group | \ - awk -F: 'BEGIN { maxgid=10000 } ($3>10000) && ($3<20000) && ($3>maxgid) { maxgid=$3; } END { print maxgid+1; }'" + cmd_gid = ( + "/usr/bin/getent group | awk -F: 'BEGIN { maxgid=10000 }" + " ($3>10000) && ($3<20000) && ($3>maxgid) { maxgid=$3; } END {" + " print maxgid+1; }'" + ) msg["gid"] = popen(cmd_gid).read().rstrip() logger.info(f"GID query: {cmd_gid}") @@ -76,9 +83,10 @@ def resolve_uid_gid(ch, method, properties, body): msg["success"] = True except Exception as exception: msg["success"] = False - msg[ - "errmsg" - ] = f"Exception raised during account creation, check logs for stack trace" + msg["errmsg"] = ( + "Exception raised during account creation, check logs for stack" + " trace" + ) logger.error("", exc_info=True) # Acknowledge message diff --git a/prod_rmq_agents/git_commit.py b/prod_rmq_agents/git_commit.py index a88f55c99cf12dd774e5c29ffddb3017d4cfd825..38d6f8ee72bedca00e651986762f5d2f8d83ee9a 100644 --- a/prod_rmq_agents/git_commit.py +++ b/prod_rmq_agents/git_commit.py @@ -37,8 +37,12 @@ def git_commit(ch, method, properties, body): username = msg["username"] msg["task"] = task msg["success"] = False - branch_name = "issue-add-users-" + \ - username.lower() + "-" + time.strftime("%Y%m%d_%H%M%S") + branch_name = ( + "issue-add-users-" + + username.lower() + + "-" + + time.strftime("%Y%m%d_%H%M%S") + ) user_ldif = users_dir + f"/{username}.ldif" group_ldif = groups_dir + f"/{username}.ldif" @@ -55,14 +59,13 @@ def git_commit(ch, method, properties, body): if not branch_exists: logger.debug("git checkout -b %s", branch_name) git.checkout("-b", branch_name) - logger.debug( - "open(%s, 'w'), open(%s, 'w')", user_ldif, group_ldif - ) + logger.debug("open(%s, 'w'), open(%s, 'w')", user_ldif, group_ldif) with open(user_ldif, "w") as ldif_u, open( group_ldif, "w" ) as ldif_g: logger.debug( - f"ldapsearch -LLL -x -H ldaps://ldapserver -b 'dc=cm,dc=cluster' uid={username} > {user_ldif}" + "ldapsearch -LLL -x -H ldaps://ldapserver -b 'dc=cm,dc=clu" + f"ster' uid={username} > {user_ldif}" ) ldapsearch( "-LLL", @@ -75,7 +78,8 @@ def git_commit(ch, method, properties, body): _out=ldif_u, ) logger.debug( - f"ldapsearch -LLL -x -H ldapserver -b 'ou=Group,dc=cm,dc=cluster' cn={username} > {group_ldif}" + "ldapsearch -LLL -x -H ldapserver -b 'ou=Group,dc=cm,dc=cl" + f"uster' cn={username} > {group_ldif}" ) ldapsearch( "-LLL", @@ -93,9 +97,7 @@ def git_commit(ch, method, properties, body): git.add(user_ldif) logger.debug("git add %s", group_ldif) git.add(group_ldif) - logger.debug( - "git commit -m 'Added new cheaha user: %s'", username - ) + logger.debug("git commit -m 'Added new cheaha user: %s'", username) git.commit(m="Added new cheaha user: " + username) logger.debug("git checkout master") git.checkout("master") diff --git a/prod_rmq_agents/notify_user.py b/prod_rmq_agents/notify_user.py index 4f1dd3e47db9c07703eb1261d4ce464e35c5b1d8..5e26547c004d0e1888f62362443982a12578c86c 100644 --- a/prod_rmq_agents/notify_user.py +++ b/prod_rmq_agents/notify_user.py @@ -63,7 +63,8 @@ def notify_user(ch, method, properties, body): f"smtp.sendmail({rcfg.Sender}, {receivers}, message)" ) logger.info( - f"table.update({{'username': {username}, 'count': 1, 'sent_at': datetime.now()}}, ['username'])" + f"table.update({{'username': {username}, 'count': 1," + " 'sent_at': datetime.now()}}, ['username'])" ) else: diff --git a/prod_rmq_agents/subscribe_mail_lists.py b/prod_rmq_agents/subscribe_mail_lists.py index f0294f7158f13a541c6a588773bdfa04d1b8b911..8003ea73dd42bc127e043f99485f78e80bda18e5 100644 --- a/prod_rmq_agents/subscribe_mail_lists.py +++ b/prod_rmq_agents/subscribe_mail_lists.py @@ -32,8 +32,10 @@ def mail_list_subscription(ch, method, properties, body): mail_list_bcc = rcfg.Mail_list_bcc server = rcfg.Mail_server - listserv_cmd = f"QUIET ADD hpc-announce {email} {fullname} \ - \nQUIET ADD hpc-users {email} {fullname}" + listserv_cmd = ( + f"QUIET ADD hpc-announce {email} {fullname}\n" + f"QUIET ADD hpc-users {email} {fullname}" + ) logger.info("Adding user{} to mail list".format(username)) msg["success"] = False @@ -78,7 +80,7 @@ rc_rmq.start_consume( { "queue": task, # Define your Queue name "routing_key": "verify.*", # Define your routing key - "cb": mail_list_subscription, # Pass in callback function you just define + "cb": mail_list_subscription, # Pass callback function you just define } ) diff --git a/prod_rmq_agents/user_reg_event_logger.py b/prod_rmq_agents/user_reg_event_logger.py index 1f14ca444f6abdca90a8eb7b7080c7e1d54f092c..3223255c19825462d22b05df3fc01dc92d6815c9 100644 --- a/prod_rmq_agents/user_reg_event_logger.py +++ b/prod_rmq_agents/user_reg_event_logger.py @@ -17,9 +17,7 @@ def log_user_reg_events(ch, method, properties, body): routing_key = method.routing_key action = routing_key.split(".")[0] user = routing_key.split(".")[1] - print( - f"Got a {action} message for {user} with routing key: {routing_key}" - ) + print(f"Got a {action} message for {user} with routing key: {routing_key}") print(msg) # Acknowledge message diff --git a/rc_rmq.py b/rc_rmq.py index daa61c237e77662b86238b29c18e2afe5ba6c001..c6fdf70e5679d4d27f89d9261cbf6da7cd70d8a8 100644 --- a/rc_rmq.py +++ b/rc_rmq.py @@ -123,10 +123,7 @@ class RCRMQ(object): if self.DEBUG: print( - "Queue: " - + self.QUEUE - + "\nRouting_key: " - + self.ROUTING_KEY + "Queue: " + self.QUEUE + "\nRouting_key: " + self.ROUTING_KEY ) if self._connection is None: @@ -134,9 +131,7 @@ class RCRMQ(object): self.bind_queue() - self._consumer_tag = self._channel.basic_consume( - self.QUEUE, obj["cb"] - ) + self._consumer_tag = self._channel.basic_consume(self.QUEUE, obj["cb"]) self._consuming = True try: self._channel.start_consuming()