From e4ed380415382cbb1245365cae73c437e714afd4 Mon Sep 17 00:00:00 2001 From: Valentin Reis Date: Tue, 8 Jan 2019 09:05:32 -0600 Subject: [PATCH] [feature] Adds a --filter option to `cmd` for pretty-printing. The option accepts a message type and prints the values in the csv format: msgtype, time, payload if the --filter option is recognized msgtype, time otherwise The print is force-flushed on stdout. This switches CI to the "refactored" CI identifier at argotests/tests --- .nix/default.nix | 2 +- bin/cmd | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/.nix/default.nix b/.nix/default.nix index 82dfa53..9f82a46 100644 --- a/.nix/default.nix +++ b/.nix/default.nix @@ -3,5 +3,5 @@ let argotest = "https://xgitlab.cels.anl.gov/argo/argotest/-/archive/master/argotest-master.tar.gz"; in import "${argotest}/test.nix" { nrm-override = ./..; - testName = "base"; + testName = "refactored"; } diff --git a/bin/cmd b/bin/cmd index 3295c35..a0083a6 100755 --- a/bin/cmd +++ b/bin/cmd @@ -8,6 +8,7 @@ import os import nrm.messaging import uuid import sys +import time import collections RPC_MSG = nrm.messaging.MSGTYPES['up_rpc_req'] @@ -59,12 +60,24 @@ class CommandLineInterface(object): while(True): msg = self.pub_client.recvmsg() + logger.debug("pub message: %s", msg) + + def print_if_filter(): + if argv.filter: + if argv.filter == msg.type: + print("%s, %s, %s" % (msg.type, time.time(), + msg.payload)) + sys.stdout.flush() + else: + print("%s, %s" % (msg.type, time.time())) + sys.stdout.flush() + if argv.uuid: uuid = getattr(msg, 'container_uuid', None) if argv.uuid == uuid: - logger.info("pub message: %s", msg) + print_if_filter() else: - logger.info("pub message: %s", msg) + print_if_filter() def do_run(self, argv): """ Connect to the NRM and ask to spawn a container and run a command @@ -227,6 +240,10 @@ class CommandLineInterface(object): parser_listen.add_argument("-u", "--uuid", help="container uuid to listen for", default=None) + parser_listen.add_argument("-f", "--filter", + help="type of message to filter and \ + \ prettyprint, in {power,performance}", + default=None) parser_listen.set_defaults(func=self.do_listen) # setpowerlimit -- GitLab