All of lore.kernel.org
 help / color / mirror / Atom feed
From: <Tim.Bird@sony.com>
To: Tim.Bird@sony.com, pavan.ad@pathpartnertech.com, tbird20d@yahoo.com
Cc: fuego@lists.linuxfoundation.org
Subject: [Fuego] [PATCH] ftc: add support for update-board operation
Date: Thu, 15 Apr 2021 01:11:54 +0000	[thread overview]
Message-ID: <BN7PR13MB2499464B63217FC8EBDE0F11FD4D9@BN7PR13MB2499.namprd13.prod.outlook.com> (raw)

Support: 'ftc update-board bbb status=ready'

Supported attributes are: status, information, description
Support status values are: ready, offline, disabled, busy

This is used to set field attributes on the server.

The server is supposed to handle json data opaquely.  Updating
individual fields is a bit too cute, IMHO, but this gets the job
done.  The basic purpose of this is to allow a lab to set the
availability status of a board, on the server, so that users can
tell what's going on if the test requests are rejected or deferred.

Signed-off-by: Tim Bird <tim.bird@sony.com>
---

Pavan,

Based on my musings in my last e-mail, I decided to go ahead and implement a new
operation on the server -- a new "update_board"  API.  This updates one or more individual fields
in the json board file on the server.  The server does not check the fields being updated, but ftc does.
I introduced a new operation with ftc, the 'update-board' sub-command.  It checks for a few specific
attributes that can be updated.  With the 'status' attribute, it checks for a few specific supported
values.

Please see the code below.  Note that this text (after the '---' above, and before the start of the
actual diff below) is ignored by 'git am'.

I have committed this and checked it into the master branch in fuego-core.  Please try it
out.  You can verify that the fields for a board have been changed, by looking at the json
files on the server. (eg look at a file modified at: http://fuegotest.org/cgi-bin/fserver.py/boards)

I have not implemented the behavior described in the command help to reject or defer 
test requests based on the status.  This is code that would be added to ftc's do_run_request()
function.  Would you like to write some code to handle this?

Let me know if you are amenable to this, and I can discuss some details about what
I think this code should do, to get you started.

Part of the reason I am posting this patch is to provide an example of email
patch contribution to the Fuego project.
 -- Tim

 scripts/ftc | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 89 insertions(+), 1 deletion(-)

diff --git a/scripts/ftc b/scripts/ftc
index bb592b0..6629642 100755
--- a/scripts/ftc
+++ b/scripts/ftc
@@ -294,6 +294,34 @@ host with the server, so that it is elible to receive job requests from
 remote hosts.  Before doing this, make sure you have a unique host_name
 configured in your fuego.conf file."""),
 
+"update-board": ("Update board information on the server.",
+   """Usage: ftc update-board <board> <field>=<value> [<field2>=<v2>...]
+
+Update one or more fields for a board on the server.  This allows
+you to set informational data for a board on the server, or set
+the status, indicating whether a board is available.
+
+Allowed fields are: status, description, information
+Values for the status field can be:
+ ready, disabled, offline, busy
+
+If a board is disabled or offline, then test requests for that board
+will be rejected.  If a board is busy, then test requests for that board will
+not be processed (by 'ftc run-requests'), but will be left on the server
+for future processing.
+
+Values for the description and information are free-form text. If they
+include spaces (which is likely), they should be quoted on the command
+line so they are a single shell argument.  The information field should
+be used to hold human-readable information reflecting the status of the
+board.
+
+Here are some examples:
+ $ ftc update-board status=offline information="out of service until April 12"
+ $ ftc update-board status=ready information=
+ $ ftc update-board status=busy information="processing local jobs"
+"""),
+
 "put-binary-package": ("Put a test binary-package on the server.",
    """Usage: ftc put-binary-package <test_binary_package_file>
 Put a test binary package on the server.  The test must be an existing test
@@ -3498,6 +3526,9 @@ def do_run_request(conf, options):
     # the specific version of the test requested.  All of the above code just downloads a
     # specific test version, but it doesn't cause do_run_test to run that version
     # For that, we would have to support a '--version' flag for do_run_test.
+
+    # The selection of a specific version for a test should work, as long as the version
+    # is greater than the version of the test in /fuego-core/tests.
     print("Executing test %s on board %s (using spec %s)" % (test_name, board_name, spec_name))
     rcode, run_id = do_run_test(conf, ['-b', board_name, '-t', test_name, '-s', spec_name])
 
@@ -4054,6 +4085,59 @@ def do_put_board(conf, options):
 
     print "Board %s:%s was accepted by the server." % (conf.host, board_name)
 
+def do_update_board(conf, options):
+    try:
+        board_name = options[0]
+    except:
+        error_out("Must specify a board to update")
+    del(options[0])
+
+    # check whether argument is a legal board name
+    bmap = get_fuego_boards(conf)
+    try:
+        board = bmap[board_name]
+    except:
+        error_out("Unrecognized board %s" % (board_name))
+
+    url = conf.SERVER_URL_BASE+"update_board"
+
+    # Note: you can only change the status of a board in your own lab
+    board_dict = {"host": conf.host, "board": board_name }
+
+    # each option is a field in the board dictionary
+    if not options:
+        error_out("No attributes specified.")
+
+    while options:
+        if '=' not in options[0]:
+            error_out("Illegal attribute specification: '%s' (needs an '=')")
+
+        attr, value = options[0].split("=", 1)
+        del(options[0])
+        if not value:
+            value = "None"
+
+        # should validate legal attributes and options here
+        if attr not in ["status", "description", "information"]:
+            error_out("Illegal attribute '%s' - please use 'status', 'description' or 'information'" % attr)
+
+        #if attr in ["host", "board"]:
+        #    error_out("Illegal attribute - can't change '%s' for existing board"% attr)
+
+        allowed_statuses = ["ready", "busy", "offline", "disabled"]
+        if attr == "status":
+            if value not in allowed_statuses:
+                error_out("Invalid status '%s' specified, please use one of %s" % (value, str(allowed_statuses)))
+
+        board_dict[attr] = value
+
+    resp = requests.post(url, board_dict)
+    result, content = resp.text.split('\n', 1)
+    if result != "OK":
+        error_out("Can't update board attribute.\nServer returned message: %s" % content)
+
+    print "OK"
+
 
 def put_run_fuego(conf, run_filepath):
     url = conf.SERVER_URL_BASE+"put_run"
@@ -5484,7 +5568,7 @@ def do_install_test(conf, options, internal=False):
     if not os.path.isfile(test_pkg):
         error_out("Test package '%s' is not found" % test_pkg)
 
-    # this assumes no test name has a dash - probably a bad assumption
+    # FIXTHIS - this assumes no test name has a dash - probably a bad assumption
     test_name, rest = test_pkg.split("-", 1)
 
     testdir = test_home + os.sep + test_name
@@ -6066,6 +6150,10 @@ def main():
         do_put_board(conf, options)
         sys.exit(0)
 
+    if command == "update-board":
+        do_update_board(conf, options)
+        sys.exit(0)
+
     if command == "put-run":
         do_put_run(conf, options)
         sys.exit(0)
-- 
2.1.4


                 reply	other threads:[~2021-04-15  1:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BN7PR13MB2499464B63217FC8EBDE0F11FD4D9@BN7PR13MB2499.namprd13.prod.outlook.com \
    --to=tim.bird@sony.com \
    --cc=fuego@lists.linuxfoundation.org \
    --cc=pavan.ad@pathpartnertech.com \
    --cc=tbird20d@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.