diff --git a/agent_template.py b/agent_template.py index 16176c42e9f14ce9af99c5567989a9e225680a45..80e3eff4b19b9492ab045d369315f836f4f78de8 100644 --- a/agent_template.py +++ b/agent_template.py @@ -21,13 +21,13 @@ def on_message(ch, method, properties, body): print(msg) # Do Something - print("[{}]: Callback called.".format(task)) + print(f"[{task}]: Callback called.") # Acknowledge message ch.basic_ack(delivery_tag=method.delivery_tag) -print("Start listening to queue: {}".format(task)) +print(f"Start listening to queue: {task}") rc_rmq.start_consume( { "queue": task, # Define your Queue name diff --git a/dev_rmq_agents/ohpc_account_create.py b/dev_rmq_agents/ohpc_account_create.py index fa83fe63d9f1029c5a239a241d93bf99c72b9780..f15a786f9f636ba2652dde012c557f43b02f3b9d 100644 --- a/dev_rmq_agents/ohpc_account_create.py +++ b/dev_rmq_agents/ohpc_account_create.py @@ -14,16 +14,16 @@ rc_rmq = RCRMQ({"exchange": "RegUsr", "exchange_type": "topic"}) def ohpc_account_create(ch, method, properties, body): msg = json.loads(body) - print("Message received {}".format(msg)) + print(f"Message received {msg}") username = msg["username"] success = False try: subprocess.call(["sudo", "useradd", username]) - print("[{}]: User {} has been added".format(task, username)) + print(f"[{task}]: User {username} has been added") success = True except Exception: e = sys.exc_info()[0] - print("[{}]: Error: {}".format(task, e)) + print(f"[{task}]: Error: {e}") ch.basic_ack(delivery_tag=method.delivery_tag) msg["uid"] = getpwnam(username).pw_uid @@ -42,7 +42,7 @@ def ohpc_account_create(ch, method, properties, body): rc_rmq.publish_msg({"routing_key": "create." + username, "msg": msg}) -print("Start Listening to queue: {}".format(task)) +print(f"Start Listening to queue: {task}") rc_rmq.start_consume( {"queue": task, "routing_key": "request.*", "cb": ohpc_account_create} ) diff --git a/dev_rmq_agents/ood_account_create.py b/dev_rmq_agents/ood_account_create.py index 57e7a9b8119a8df0b2ecebdccb7c03ca94be20f2..482ba31efa218336d64316aa45e144b82359513c 100644 --- a/dev_rmq_agents/ood_account_create.py +++ b/dev_rmq_agents/ood_account_create.py @@ -13,7 +13,7 @@ rc_rmq = RCRMQ({"exchange": "RegUsr", "exchange_type": "topic"}) def ood_account_create(ch, method, properties, body): msg = json.loads(body) - print("Message received {}".format(msg)) + print(f"Message received {msg}") username = msg["username"] user_uid = str(msg["uid"]) user_gid = str(msg["gid"]) @@ -23,11 +23,11 @@ def ood_account_create(ch, method, properties, body): subprocess.call( ["sudo", "useradd", "-u", user_uid, "-g", user_gid, username] ) - print("[{}]: User {} has been added".format(task, username)) + print(f"[{task}]: User {username} has been added") success = True except Exception: e = sys.exc_info()[0] - print("[{}]: Error: {}".format(task, e)) + print(f"[{task}]: Error: {e}") ch.basic_ack(delivery_tag=method.delivery_tag) @@ -40,7 +40,7 @@ def ood_account_create(ch, method, properties, body): ) -print("Start listening to queue: {}".format(task)) +print(f"Start listening to queue: {task}") rc_rmq.start_consume( {"queue": task, "routing_key": "create.*", "cb": ood_account_create} ) diff --git a/dev_rmq_agents/slurm_agent.py b/dev_rmq_agents/slurm_agent.py index c40dac164d7ba985db40eab2a747ce1ec21e852c..859aa61f6c06fa5913754dd26d16a709a61bdc45 100755 --- a/dev_rmq_agents/slurm_agent.py +++ b/dev_rmq_agents/slurm_agent.py @@ -13,7 +13,7 @@ rc_rmq = RCRMQ({"exchange": "RegUsr", "exchange_type": "topic"}) def slurm_account_create(ch, method, properties, body): msg = json.loads(body) - print("Message received {}".format(msg)) + print(f"Message received {msg}") username = msg["username"] success = False try: @@ -39,11 +39,11 @@ def slurm_account_create(ch, method, properties, body): "-i", ] ) - print("SLURM account for user {} has been added".format(username)) + print(f"SLURM account for user {username} has been added") success = True except Exception: e = sys.exc_info()[0] - print("[{}]: Error: {}".format(task, e)) + print(f"[{task}]: Error: {e}") ch.basic_ack(delivery_tag=method.delivery_tag) @@ -56,7 +56,7 @@ def slurm_account_create(ch, method, properties, body): ) -print("Start listening to queue: {}".format(task)) +print(f"Start listening to queue: {task}") rc_rmq.start_consume( {"queue": task, "routing_key": "create.*", "cb": slurm_account_create} ) diff --git a/flask_producer.py b/flask_producer.py index 8cea3af6c97dcba1ff4450e5ff816872cf9fdc67..b44f5cbb22ccba0684f7739a008c1a00d0f0a2a1 100755 --- a/flask_producer.py +++ b/flask_producer.py @@ -8,7 +8,7 @@ import pika import rabbit_config as rcfg if len(sys.argv) < 3: - sys.stderr.write("Usage: {} TAG USERNAME ".format(sys.argv[0])) + sys.stderr.write(f"Usage: {sys.argv[0]} TAG USERNAME ") exit(1) node = sys.argv[1] @@ -37,7 +37,7 @@ channel.exchange_declare(exchange=rcfg.Exchange, exchange_type="direct") channel.basic_publish( exchange=rcfg.Exchange, routing_key=node, body=json.dumps(message) ) -print(" [x] Sent {}: {}".format(node, json.dumps(message))) +print(f" [x] Sent {node}: {json.dumps(message)}") # creates a named queue result = channel.queue_declare(queue=user_name, exclusive=False, durable=True) @@ -50,7 +50,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)) + print(f"Received message from {method.routing_key}: \n\t{msg}") channel.queue_delete(method.routing_key) @@ -58,7 +58,7 @@ def work(ch, method, properties, body): channel.basic_consume( queue=sys.argv[2], on_message_callback=work, auto_ack=True ) -print("Subscribing to queue: {}".format(sys.argv[2])) +print(f"Subscribing to queue: {sys.argv[2]}") # initiate message ingestion try: diff --git a/prod_rmq_agents/get-next-uid-gid.py b/prod_rmq_agents/get-next-uid-gid.py index fdad2e39dc7cd024db8cd523f79aff95ba5873d3..a6a6d531bfa2f293a5634846064bbfe34381f458 100644 --- a/prod_rmq_agents/get-next-uid-gid.py +++ b/prod_rmq_agents/get-next-uid-gid.py @@ -53,7 +53,7 @@ def resolve_uid_gid(ch, method, properties, body): # Retrieve message msg = json.loads(body) - logger.info("Received {}".format(msg)) + logger.info(f"Received {msg}") username = msg["username"] msg["success"] = False @@ -63,7 +63,7 @@ def resolve_uid_gid(ch, method, properties, body): user_exists = popen(user_exists_cmd).read().rstrip() if user_exists: - logger.info("The user, {} already exists".format(username)) + logger.info(f"The user, {username} already exists") msg["uid"] = user_exists.split(":")[2] msg["gid"] = user_exists.split(":")[3] @@ -106,7 +106,7 @@ def resolve_uid_gid(ch, method, properties, body): logger.info("confirmation sent") -logger.info("Start listening to queue: {}".format(task)) +logger.info(f"Start listening to queue: {task}") rc_rmq.start_consume( {"queue": task, "routing_key": "request.*", "cb": resolve_uid_gid} ) diff --git a/prod_rmq_agents/subscribe_mail_lists.py b/prod_rmq_agents/subscribe_mail_lists.py index 4629b104af9ae73ae2ce6a05319d9b5eb5e7b742..d6b8f8211f6513bb4c9d0bf65d965fed7b011e18 100644 --- a/prod_rmq_agents/subscribe_mail_lists.py +++ b/prod_rmq_agents/subscribe_mail_lists.py @@ -23,7 +23,7 @@ def mail_list_subscription(ch, method, properties, body): # Retrieve message msg = json.loads(body) - logger.info("Received msg {}".format(msg)) + logger.info(f"Received msg {msg}") username = msg["username"] fullname = msg["fullname"] email = msg["email"] @@ -38,7 +38,7 @@ def mail_list_subscription(ch, method, properties, body): f"QUIET ADD hpc-users {email} {fullname}" ) - logger.info("Adding user{} to mail list".format(username)) + logger.info(f"Adding user {username} to mail list") msg["success"] = False try: # Create a text/plain message @@ -76,7 +76,7 @@ def mail_list_subscription(ch, method, properties, body): logger.info("confirmation sent") -logger.info("Start listening to queue: {}".format(task)) +logger.info(f"Start listening to queue: {task}") rc_rmq.start_consume( { "queue": task, # Define your Queue name diff --git a/prod_rmq_agents/user_reg_event_logger.py b/prod_rmq_agents/user_reg_event_logger.py index 606b24ffa3b899b7633a2e1e083911be6174a735..45807430d453762df1734dfc18b33d5c09e31c10 100644 --- a/prod_rmq_agents/user_reg_event_logger.py +++ b/prod_rmq_agents/user_reg_event_logger.py @@ -26,7 +26,7 @@ def log_user_reg_events(ch, method, properties, body): ch.basic_ack(delivery_tag=method.delivery_tag) -print("Start listening to queue: {}".format(task)) +print(f"Start listening to queue: {task}") rc_rmq.start_consume( { "queue": task, # Define your Queue name diff --git a/prod_rmq_agents/user_reg_logger.py b/prod_rmq_agents/user_reg_logger.py index 568bee1f2f67da5f6e867817ef734d22e8f4c633..d95be12922a4d94cb53564bde2a23af2b132417b 100755 --- a/prod_rmq_agents/user_reg_logger.py +++ b/prod_rmq_agents/user_reg_logger.py @@ -36,7 +36,7 @@ def log_registration(ch, method, properties, body): ch.basic_ack(delivery_tag=method.delivery_tag) -logger.info("Start listening to queue: {}".format(task)) +logger.info(f"Start listening to queue: {task}") # Start consuming messages from queue with callback function rc_rmq.start_consume( diff --git a/rc_rmq.py b/rc_rmq.py index 47896f18e23dc58cccd4ea3ad88f1a93b6e090ac..188cd6f3baa8d1b325d2c37f1e1aa9efea09c987 100644 --- a/rc_rmq.py +++ b/rc_rmq.py @@ -35,22 +35,15 @@ class RCRMQ(object): if self.DEBUG: print( - """ + f""" Created RabbitMQ instance with: - Exchange name: {}, - Exchange type: {}, - Host: {}, - User: {}, - VHost: {}, - Port: {} - """.format( - self.EXCHANGE, - self.EXCHANGE_TYPE, - self.HOST, - self.USER, - self.VHOST, - self.PORT, - ) + Exchange name: {self.EXCHANGE}, + Exchange type: {self.EXCHANGE_TYPE}, + Host: {self.HOST}, + User: {self.USER}, + VHost: {self.VHOST}, + Port: {self.PORT} + """ ) self._consumer_tag = None