[Fuego] [PATCH] Add support to run or reject tests based on the board availability

Pavan Arun Deshpande <[email protected]> Tue, 18 May 2021 17:40:30 +0530
Newsgroups dev.linux.lists.fuego
Message-ID <CAMQEYMdiJn5G6+rq4qX=e=L8Q+pzKyT7a+JMoUvK3q6=kRV_kg@mail.gmail.com>
Hi Tim,
I have copied the ftc patch below.
if  any suggestions let me know.


Subject: [PATCH] 1. Add support to run or reject tests  based on the board
 availability.

2. ftc: Add support ftc get-board <board> [<field1> <field2>...] [-q]

        get-board : retrieve the board information from <board>.json file

Signed-off-by: Pavan Arun Deshpande <[email protected]>
---
 scripts/ftc | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 81 insertions(+), 3 deletions(-)

diff --git a/scripts/ftc b/scripts/ftc
index 6629642..5b2285f 100755
--- a/scripts/ftc
+++ b/scripts/ftc
@@ -36,7 +36,7 @@
 import os
 import sys
 import subprocess
-
+import json
 # delay other imports until we're sure we're running in the container
 re = None
 time = None
@@ -322,6 +322,20 @@ Here are some examples:
  $ ftc update-board status=busy information="processing local jobs"
 """),

+"get-board": ("retrieve the board information from <board>.json file",
+    """Usage: ftc get-board <board> [<field1> <field2>...] [-q]
+       Use '-q' to show the attribute values only.
+Get the one or more(or all) board fields from thre server
+
+Here are some examples:
+    $ ftc get-board docker                                   ----- prints
all the fields.
+    $ ftc get-board docker status                            ----- prints
only status field.
+    $ ftc get-board docker status information                ----- prints
both status and information fields.
+    $ ftc get-board docker status information description    ----- prints
the status,information and  description fields.
+"""),
+
+
+
 "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
@@ -2165,7 +2179,6 @@ def do_list_nodes(conf):
 def do_list_jobs(conf):
     job_list = [job['name'] for job in server.get_jobs()]
     job_list.sort()
-
     indent = show_list_title("Jenkins jobs in this system:")
     for job in job_list:
         print indent + job
@@ -3367,6 +3380,7 @@ def find_best_test_match(test_name, req_version,
test_tuples):

     return candidate

+
 def do_run_request(conf, options):
     put_run_flag = False
     allow_upgrade_flag = False
@@ -3399,12 +3413,25 @@ def do_run_request(conf, options):

     print "Trying to get request '%s' from server" % req_id
     req = get_request(conf, req_id)
+    board_name = req["board"]
+    board_field = {"host": conf.host, "board": board_name}
+
+    url = conf.SERVER_URL_BASE+"get_board"
+    resp = requests.post(url, board_field)
+    result, content = resp.text.split('\n', 1)

+    board_file_dict = json.loads(content)
+    board_status = board_file_dict["status"]
+    board_information = board_file_dict["information"]
+    if result != "OK":
+        error_out("Can't read board data '%s' from server\nServer returned
message: %s" % (run_id, content))
+        sys.exit(0)
+    #if board is ready run the request
+    elif board_status == "ready":
         # In do_run_request, notify server that request is in-progress
         update_request(conf, req_id, "running")

         # now actually execute the request
-    board_name = req["board"]
         test_name = req["test_name"]
         req_version = req["version"]
         try:
@@ -3550,6 +3577,12 @@ def do_run_request(conf, options):
         #    print("Request %s was updated on the server" % req_id)

         sys.exit(rcode)
+    # if board is offline reject the request
+    elif board_status == "offline" or board_status == "disabled":
+        update_request(conf, req_id, "error",
+                    {"reason": "%s board is %s due to %s"
%(board_name,board_status,board_information)})
+        error_out("%s board is %s due to %s" %
(board_name,board_status,board_information))
+        sys.exit(0)

 def do_query_request(conf, options):
     attr = None
@@ -4138,6 +4171,47 @@ def do_update_board(conf, options):

     print "OK"

+def do_get_board(conf,options):
+    global quiet
+    try:
+        board_name = options[0]
+    except:
+        error_out("Must specify a board name get board fields")
+    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+"get_board"
+
+
+    board_dict = {"host": conf.host, "board": board_name }
+
+    resp = requests.post(url, board_dict)
+    result, content = resp.text.split('\n', 1)
+    board_fields = json.loads(content)
+    if result != "OK":
+        error_out("Can't update board attribute.\nServer returned message:
%s" % content)
+    elif options:
+        for option in options:
+            attr = option
+            try:
+                if quiet:
+                    print(board_fields[attr])
+                else:
+                    print("%s=%s" % (attr, board_fields[attr]))
+
+            except:
+                print("board attribute %s not found" % attr)
+        del(options[:])
+    else:
+        print("----------------------------board
fields--------------------------------------")
+        print(json.dumps(board_fields,indent=4,sort_keys=True))
+

 def put_run_fuego(conf, run_filepath):
     url = conf.SERVER_URL_BASE+"put_run"
@@ -6154,6 +6228,10 @@ def main():
         do_update_board(conf, options)
         sys.exit(0)

+    if command == "get-board":
+        do_get_board(conf, options)
+        sys.exit(0)
+
     if command == "put-run":
         do_put_run(conf, options)
         sys.exit(0)
-- 
2.17.1

Thanks and Regards
Pavan Arun Deshpande

-- 






This
message contains confidential information and is intended only 
for the
individual(s) named. If you are not the intended
recipient, you are 
notified that disclosing, copying, distributing or taking any
action in 
reliance on the contents of this mail and attached file/s is strictly
prohibited. Please notify the
sender immediately and delete this e-mail 
from your system. E-mail transmission
cannot be guaranteed to be secured or 
error-free as information could be
intercepted, corrupted, lost, destroyed, 
arrive late or incomplete, or contain
viruses. The sender therefore does 
not accept liability for any errors or
omissions in the contents of this 
message, which arise as a result of e-mail
transmission.