Re: [Fuego] Test request rejection or execution based on board availability
Pavan Arun Deshpande <[email protected]> Fri, 30 Apr 2021 13:23:00 +0530
| Newsgroups | dev.linux.lists.fuego |
|---|---|
| Message-ID | <CAMQEYMcRHZ=Fr7zcWRWSA68kmMangcRg2wfiOV48LT67oqRa4Q@mail.gmail.com> |
Hi Tim, Sorry i have not attached fserver output snapshot and flowchart in the previous mail I have attached the fserver output snapshot and flowchart below. Thanks and regards Pavan Arun Deshpande On Fri, Apr 30, 2021 at 1:19 PM Pavan Arun Deshpande < [email protected]> wrote: > Hi Tim, > > I have implemented "test request rejection or execution based on board > availability" functionality. > I have tested and verified this functionality in my local fserver and > attached fserver output snapshot and flowchart of logic implemented below. > > To retrieve board availability status field which is located in the > board.json file on fserver requires one api to access the board.json file. > For that I have implemented "get_board_file" api on fserver > which helps to retrieve and send the board status field back to the ftc > request. > > I have implemented this on my local fserver code > Here is the patch of fserver > Signed-off-by: Pavan Arun Deshpande <[email protected]> > --- > fserver.py | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++--- > 1 file changed, 51 insertions(+), 3 deletions(-) > > diff --git a/fserver.py b/fserver.py > index a4bca89..3207e22 100755 > --- a/fserver.py > +++ b/fserver.py > @@ -64,11 +64,13 @@ VERSION=(0,6,0) > # 2. local fserver in Fuego container > # 3. test fserver on Tim's private server machine (birdcloud.org) > # 4. test fserver on Tim's home desktop machine (timdesk) > -base_dir = "/home/ubuntu/work/fserver/fserver-data" > +#base_dir = "/home/ubuntu/work/fserver/fserver-data" > +base_dir = "/home/pavan.ad/fserver/fserver/fserver-data" > if not os.path.exists(base_dir): > base_dir = "/usr/local/lib/fserver/fserver-data" > if not os.path.exists(base_dir): > - base_dir = "/home/tbird/work/fserver/fserver-data" > + #base_dir = "/home/tbird/work/fserver/fserver-data" > + base_dir = "/home/pavan.ad/fserver/fserver/fserver-data" > > # this is used for debugging only > def log_this(msg): > @@ -527,6 +529,52 @@ def do_update_board(req): > > send_response(result, msg) > > +def do_get_board_file(req): > + req_data_dir = req.config.data_dir + os.sep + "boards" > + result = "OK" > + msg = "" > + print(req) > + #convert form (cgi.fieldStorage) to dictionary > + new_dict = {} > + for k in req.form.keys(): > + new_dict[k] = req.form[k].value > + > + # remove action > + del(new_dict["action"]) > + > + # sanity check the submitted data > + # check for host and board > + try: > + host = new_dict["host"] > + board = new_dict["board"] > + # FIXTHIS - check that host is registered > + except: > + msg += "Error: missing host or board in form data" > + send_response("FAIL", msg) > + return > + > + filename = "board-%s:%s" % (host, board) > + jfilepath = req_data_dir + os.sep + filename + ".json" > + > + # check that board is already registered > + if not os.path.exists(jfilepath): > + msg += "Error: board '%s:%s' is not registered" % (host, board) > + send_response("FAIL", msg) > + return > + > + #storing <board>.json fields into board dictionary > + import json > + board_fd = open(jfilepath, "r") > + board_dict = json.load(board_fd) > + board_fd.close() > + > + #fetching status field from <board>.json file > + board_status = board_dict["status"] > + msg +=board_status > + > + send_response(result,msg) > + > + > def do_put_request(req): > req_data_dir = req.config.data_dir + os.sep + "requests" > result = "OK" > @@ -1445,7 +1493,7 @@ def main(req): > log_this("DEBUG: in main(), after call to cgi.FieldStorage") > > action_list = ["show", "put_test", "put_run", "put_request", > - "put_binary_package", "put_board", "update_board", > + "put_binary_package", "put_board", "update_board", > "get_board_file", > "query_boards", "query_requests", "query_runs", "query_tests", > "get_request", "get_run_url", "get_test", > "remove_request", "remove_test", "remove_run", > -- > 2.17.1 > > > > The logic to reject or accept the request based on board availability is > implemented in my local ftc script. > here is the patch > > Signed-off-by: Pavan Arun Deshpande <[email protected]> > --- > scripts/ftc | 33 +++++++++++++++++++++++++-------- > 1 file changed, 25 insertions(+), 8 deletions(-) > > diff --git a/scripts/ftc b/scripts/ftc > index 6629642..c951ed8 100755 > --- a/scripts/ftc > +++ b/scripts/ftc > def do_run_request(conf, options): > put_run_flag = False > allow_upgrade_flag = False > @@ -3399,12 +3399,23 @@ 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_file" > + resp = requests.post(url, board_field) > + result, content = resp.text.split('\n', 1) > + print(content) > + 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 content == "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"] > + #board_name = req["board"] > test_name = req["test_name"] > req_version = req["version"] > try: > @@ -3550,6 +3561,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 content == "offline" or content == "disable": > + update_request(conf, req_id, "error", > + {"reason": "board is offline"}) > + error_out("%s board is offline" % (board_name)) > + sys.exit(0) > > def do_query_request(conf, options): > attr = None > 2.17.1 > > Please let me know your opinion on this and if you agree to this we can > implement the same in the main fserver and ftc. > > 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.
board_status_flowchart.png
(image/png, 60.3 KB) - not displayed
fserver.png
(image/png, 97.3 KB) - not displayed