From bbba8dcb9a6f61b59e96823f04c428b8a6649e1b Mon Sep 17 00:00:00 2001
From: Leon Hiemstra <hiemstra@astron.nl>
Date: Wed, 17 Oct 2018 11:37:27 +0000
Subject: [PATCH] Task #2404: first test version supporting UBDriver commands

---
 .../apertif/commissioning/executor.py         | 87 +++++++++++++++----
 1 file changed, 72 insertions(+), 15 deletions(-)

diff --git a/applications/apertif/commissioning/executor.py b/applications/apertif/commissioning/executor.py
index ee2f5026a9..bdce05df94 100644
--- a/applications/apertif/commissioning/executor.py
+++ b/applications/apertif/commissioning/executor.py
@@ -45,7 +45,7 @@ from apertif.messaging.send_file import send_and_wait_files
 from pprint import pprint
 
 
-def writeParset(command, lcu_list=None, exec_time='utcnow()', args=[], parset_template='low_level_parset.template', parset_path='/tmp/parset.parset'):
+def writeParset(command, lcu_list=None, exec_time='utcnow()', args=[], parset_template='low_level_parset.template', parset_path='/tmp/parset_executor.parset'):
     ''' Replace the parset template keys
     
     Input Arguments:
@@ -146,9 +146,7 @@ def verify_reply(reply, test_result=False):
 # Test case contains logging/printing functionality
 ###############################################################################
 tc = test_case.Testcase('MAIN - ', '')
-
-
-
+use_mac_str = 'True'
 
 supportedApps = ['apertif-ag', 'apertif-dev', 'arts_sc1', 'arts_sc4']
 if tc.appStr in supportedApps:
@@ -217,7 +215,7 @@ except Exception as err:
 if tc.unbStr == '':
     print 'Omitting call to central_status, since no XC boards are addressed.'
 else:
-    cmd = '. $RADIOHDL/applications/apertif/commissioning/central_status.sh ' + tc.appStr + ' ' + tc.telStr + ' ' + tc.unbStr + ' ' + 'precheck' + ' ' + tc.polStr
+    cmd = '. $RADIOHDL/applications/apertif/commissioning/central_status.sh ' + tc.appStr + ' ' + tc.telStr + ' ' + tc.unbStr + ' ' + 'precheck' + ' ' + tc.polStr + ' ' + use_mac_str
     print hostname_correlator +':$ '+cmd
     output = shell.ssh_cmd(hostname_correlator, cmd, tc)
     if "Error" in output or not "Passed" in output:
@@ -227,7 +225,7 @@ else:
 ###############################################################################
 # Check if dish UniBoard systems are ready for action. If not, exit immediately.
 ###############################################################################
-command = '. $RADIOHDL/applications/apertif/commissioning/dish_status.sh ' + tc.appStr + ' ' + 'precheck' + ' ' + tc.polStr
+command = '. $RADIOHDL/applications/apertif/commissioning/dish_status.sh ' + tc.appStr + ' ' + 'precheck' + ' ' + tc.polStr + ' ' + use_mac_str
 for lcu in LCUS:
     print lcu+':$ '+command
     output = (shell.ssh_cmd(lcu, command, tc))
@@ -240,13 +238,72 @@ for lcu in LCUS:
 # Run remote dish commands in background
 ###############################################################################
 print 'POL, RUN', tc.polStr, tc.runStr
-#subcommand = '. $RADIOHDL/applications/apertif/commissioning/dish_commands.sh ' + tc.appStr + ' ' + tc.optStr + ' ' + tc.polStr + ' ' + tc.runStr + ' ' + ','.join(map(str,tc.unbNrs))
-subcommand = '. $RADIOHDL/applications/apertif/commissioning/dish_commands.sh ' + tc.appStr + ' ' + tc.optStr + ' ' + tc.polStr + ' ' + "False" + ' ' + ','.join(map(str,tc.unbNrs))
+subcommand = '. $RADIOHDL/applications/apertif/commissioning/dish_commands.sh ' + tc.appStr + ' ' + tc.optStr + ' ' + tc.polStr + ' ' + "False" + ' ' + ','.join(map(str,tc.unbNrs)) + ' ' + use_mac_str
 shell.shell_source(subcommand)
-#for lcu in LCUS:
-#    command = subcommand + ' > ~/'+lcu+'_dish_commands.log '
-#    print lcu+':$ '+command
-#    shell.ssh_cmd_bkgnd(lcu, command)
+
+if tc.optStr == 'noflash':
+    print 'Continuing without BN reflash due to noflash option'
+else:
+    try:
+        #hiemstra@lcu-rtx:~/svn/apertif/commissioning/trunk/test_scripts/python$ python util_send_command.py -c uniboard_writeflash --tel=x filename=/home/hiemstra/images/apertif_unb1_bn_filterbank-r18604.rbf nodelist=[6] --send
+
+        print "Rebooting all nodes to factory"
+        arg_str = 'image=factory'
+        parset_path = writeParset('uniboard_reboot', lcu_list=LCUS, args=[arg_str])
+        reply = send_and_wait_files(parset_path, timeout=20.0)
+        reply = reply[parset_path]
+        pprint(reply)
+        verify_reply(reply,test_result=True)
+
+        print "Flashing BN's with firmware image: ",os.getenv('IMAGE_FB')
+        arg_str = 'filename=' + os.getenv('IMAGE_FB') + ' nodelist=[5]'
+        parset_path = writeParset('uniboard_writeflash', lcu_list=LCUS, args=[arg_str])
+        reply = send_and_wait_files(parset_path, timeout=180.0)
+        reply = reply[parset_path]
+        pprint(reply)
+        verify_reply(reply,test_result=True)
+
+        print "Verifying BN's with firmware image: ",os.getenv('IMAGE_FB')
+        arg_str = 'filename=' + os.getenv('IMAGE_FB') + ' nodelist=[5]'
+        parset_path = writeParset('uniboard_verifyflash', lcu_list=LCUS, args=[arg_str])
+        reply = send_and_wait_files(parset_path, timeout=60.0)
+        reply = reply[parset_path]
+        pprint(reply)
+        verify_reply(reply,test_result=True)
+
+        print "Flashing FN's with firmware image: ",os.getenv('IMAGE_BF')
+        arg_str = 'filename=' + os.getenv('IMAGE_BF') + ' nodelist=[1]'
+        parset_path = writeParset('uniboard_writeflash', lcu_list=LCUS, args=[arg_str])
+        reply = send_and_wait_files(parset_path, timeout=180.0)
+        reply = reply[parset_path]
+        pprint(reply)
+        verify_reply(reply,test_result=True)
+
+        print "Verifying FN's with firmware image: ",os.getenv('IMAGE_BF')
+        arg_str = 'filename=' + os.getenv('IMAGE_BF') + ' nodelist=[1]'
+        parset_path = writeParset('uniboard_verifyflash', lcu_list=LCUS, args=[arg_str])
+        reply = send_and_wait_files(parset_path, timeout=60.0)
+        reply = reply[parset_path]
+        pprint(reply)
+        verify_reply(reply,test_result=True)
+    except Exception as err:
+        print 'Error Signal_Control, UBDriver: ',err
+        sys.exit();
+
+
+try:
+    print "Booting: "
+    parset_path = writeParset('uniboard_reboot', lcu_list=LCUS)
+    reply = send_and_wait_files(parset_path, timeout=60.0)
+    reply = reply[parset_path]
+    pprint(reply)
+    verify_reply(reply,test_result=True)
+except Exception as err:
+    print 'Error Signal_Control, UBDriver: ',err
+    sys.exit();
+
+sys.exit()
+
 
 
 ###############################################################################
@@ -255,7 +312,7 @@ shell.shell_source(subcommand)
 if tc.unbStr == '':
     pass
 else:
-    subcommand = '. $RADIOHDL/applications/apertif/commissioning/central_commands.sh ' + tc.appStr + ' ' + tc.telStr + ' ' + tc.unbStr + ' ' + tc.optStr + ' ' + tc.polStr
+    subcommand = '. $RADIOHDL/applications/apertif/commissioning/central_commands.sh ' + tc.appStr + ' ' + tc.telStr + ' ' + tc.unbStr + ' ' + tc.optStr + ' ' + tc.polStr + ' ' + use_mac_str
     command = subcommand + ' | tee ~/central_commands.log '
     print 'ccu-corr'+':$ '+command
     shell.ssh_cmd('ccu-corr', command, tc)
@@ -332,7 +389,7 @@ if tc.run == True:
 ###############################################################################
 # Everything should be up and running - check dish UniBoard system
 ###############################################################################
-command = '. $RADIOHDL/applications/apertif/commissioning/dish_status.sh ' + tc.appStr + ' ' + 'postcheck' + ' ' + tc.polStr
+command = '. $RADIOHDL/applications/apertif/commissioning/dish_status.sh ' + tc.appStr + ' ' + 'postcheck' + ' ' + tc.polStr + ' ' + use_mac_str
 for lcu in LCUS:
     print lcu+':$ '+command
     output = (shell.ssh_cmd(lcu, command, tc))
@@ -345,7 +402,7 @@ for lcu in LCUS:
 if tc.unbStr == '':
     print 'Omitting call to central_status, since no XC boards are addressed.'
 else:
-    cmd = '. $RADIOHDL/applications/apertif/commissioning/central_status.sh ' + tc.appStr + ' ' + tc.telStr + ' ' + tc.unbStr + ' ' + 'postcheck' + ' ' + tc.polStr
+    cmd = '. $RADIOHDL/applications/apertif/commissioning/central_status.sh ' + tc.appStr + ' ' + tc.telStr + ' ' + tc.unbStr + ' ' + 'postcheck' + ' ' + tc.polStr + ' ' + use_mac_str
     print 'ccu-corr'+':$ '+cmd
     output = shell.ssh_cmd('ccu-corr', cmd, tc)
     if "Error" in output or not "Passed" in output:
-- 
GitLab