def setup_telescope_and_scan(result): """ confirm the telescope is ready, and then to be sure we are testing a multiscan scenario perform one scan """ LOGGER.info( "Before starting the telescope checking if the TMC is in ON state") assert (tmc_is_on()) LOGGER.info( "Before starting the telescope checking if the telescope is in StandBy" ) assert telescope_is_in_standby() LOGGER.info("Telescope is in StandBy.") LOGGER.info("Starting up telescope") set_telescope_to_running() LOGGER.info("Telescope is in running state.") LOGGER.info("Ensuring resources are assigned") result[SUBARRAY_USED], result['sdp_block'] = take_subarray( 1).to_be_composed_out_of(2) LOGGER.info("Result of Subarray command is :" + str(result[SUBARRAY_USED]) + str(result['sdp_block'])) LOGGER.info("Resources are assigned successfully on Subarray Node.") LOGGER.info("Invoking configure command on the Subarray for first Scan.") result[SUBARRAY_USED].and_configure_scan_by_file( result['sdp_block'], file='resources/test_data/OET_integration/example_configure.json', ) LOGGER.info("Configure is successful on Subarray.") LOGGER.info("Invoking first scan on Subarray.") result[SUBARRAY_USED].and_run_a_scan() LOGGER.info("first scan completed on Subarray.") time.sleep(5) return result
def end(result): """ teardown any state that was previously setup for the tests. Args: result (dict): fixture to track test state """ subarray = resource(result[SUBARRAY_USED]) obsstate = subarray.get('obsState') LOGGER.info("CLEANUP: Sub-array in obsState %s ", obsstate) if obsstate == "IDLE": LOGGER.info("CLEANUP: tearing down composed subarray (IDLE)") take_subarray(1).and_release_all_resources() if obsstate == "READY": LOGGER.info("CLEANUP: tearing down configured subarray (READY)") take_subarray(1).and_end_sb_when_ready( ).and_release_all_resources() if subarray.get('obsState') != "EMPTY": LOGGER.warning( "Subarray is still in %s Please restart MVP manually to complete tear down", obsstate) restart_subarray(1) # raise exception since we are unable to continue with tear down raise Exception("Unable to tear down test setup") if not telescope_is_in_standby(): set_telescope_to_standby() LOGGER.info("CLEANUP: Sub-array is in %s ", subarray.get('obsState'))
def check_standby_state(): """ Check that the telescope is in stand-by. """ assert telescope_is_in_standby(), \ f"Telescope not in STANDBY" LOGGER.info("Telescope is in stand-by")
def set_subarray_to_fault(result): """ Set sub-array to FAULT state by sending incomplete JSON in the Configure command. """ LOGGER.info("Before starting the telescope checking if the TMC is in ON state") assert(tmc_is_on()) if telescope_is_in_standby(): set_telescope_to_running() take_subarray(1).to_be_composed_out_of(2) subarray = SubArray(1) conf_req = ConfigureRequest() conf_req.dish = DishConfiguration(receiver_band=ReceiverBand.BAND_1) # To set sub-array to FAULT, catch and ignore # the DevFailed of a bad Configure command try: subarray.configure_from_cdm(conf_req) except DevFailed: pass subarray_state = resource(result[SUBARRAY_USED]).get('obsState') assert subarray_state == 'FAULT', \ f"Expected sub-array to be in FAULT but instead was in {subarray_state}" LOGGER.info("Sub-array has been set to FAULT")
def start_up(): LOGGER.info("Before starting the telescope checking if the TMC is in ON state") assert(tmc_is_on()) LOGGER.info("Before starting the telescope checking if the telescope is in StandBy") assert(telescope_is_in_standby()) LOGGER.info("Telescope is in StandBy.") LOGGER.info("Starting up the telescope") set_telescope_to_running() LOGGER.info("Telescope started.")
def set_telescope_in_off_state(result): """ Set telescope to OFF state (stand-by) if it is not yet OFF. """ LOGGER.info("Set telescope to stand-by") if resource(result[CENTRAL_NODE_USED]).get('telescopeState') != 'STANDBY': set_telescope_to_standby() assert telescope_is_in_standby(), \ f"Telescope is not in STANDBY" LOGGER.info("Telescope is in STANDBY")
def start_up_telescope(result): LOGGER.info("Before starting the telescope checking if the TMC is in ON state") assert(tmc_is_on()) if telescope_is_in_standby(): LOGGER.info("PROCESS: Starting up telescope") set_telescope_to_running() subarray_state = resource(result[SUBARRAY_USED]).get('obsState') assert subarray_state == 'EMPTY', \ f"Expected sub-array to be in EMPTY but instead was in {subarray_state}" LOGGER.info("Sub-array is in ObsState EMPTY")
def test_tm_subarray_inconsistent_at_start_up(): try: LOGGER.info( "Before starting the telescope checking if the TMC is in ON state") assert (tmc_is_on()) LOGGER.info( "Before starting the telescope checking if the telescope is in StandBy." ) assert telescope_is_in_standby() LOGGER.info("Telescope is in StandBy.") LOGGER.info("Invoking Startup Telescope command on the telescope.") set_telescope_to_running() LOGGER.info("Telescope is started successfully.") resource('ska_mid/tm_central/central_node').assert_attribute( 'telescopeState').equals('ON') #teardown finally: if not telescope_is_in_standby(): set_telescope_to_standby()
def set_to_running(): LOGGER.info( "Before starting the telescope checking if the TMC is in ON state") assert (tmc_is_on()) LOGGER.info( "Before starting the telescope checking if the telescope is in StandBy." ) assert telescope_is_in_standby() LOGGER.info("Telescope is in StandBy.") LOGGER.info("Invoking Startup Telescope command on the telescope.") set_telescope_to_running() LOGGER.info("Telescope is started successfully.")
def set_telescope_in_on_state(result): """ Set telescope to ON state (startup) if it's not yet ON. """ LOGGER.info( "Before starting the telescope checking if the TMC is in ON state") assert (tmc_is_on()) LOGGER.info("Starting up telescope") if telescope_is_in_standby(): set_telescope_to_running() telescope_state = resource(result[CENTRAL_NODE_USED]).get('telescopeState') assert telescope_state == 'ON', \ f"Expected telescope to be ON but instead was {telescope_state}" LOGGER.info("Telescope is in ON state")
def assign(): LOGGER.info( "Before starting the telescope checking if the TMC is in ON state") assert (tmc_is_on()) LOGGER.info( "Before starting the telescope checking if the telescope is in StandBy." ) assert telescope_is_in_standby() LOGGER.info("Telescope is in StandBy.") LOGGER.info("Invoking Startup Telescope command on the telescope.") set_telescope_to_running() LOGGER.info("Telescope is started successfully.") pilot, sdp_block = take_subarray(1).to_be_composed_out_of(2) LOGGER.info("Resources are assigned successfully on Subarray.") return sdp_block
def test_assign_resources(): try: # given an interface to TMC to interact with a subarray node and a central node fixture = {} fixture["state"] = "Unknown" # given a started up telescope assert telescope_is_in_standby() LOGGER.info("Staring up the Telescope") tmc.start_up() fixture["state"] = "Telescope On" # then when I assign a subarray composed of two resources configured as perTMC_integration/assign_resources.json @log_it("TMC_int_comp", devices_to_log, non_default_states_to_check) @sync_assign_resources(2, 500) def compose_sub(): resource("ska_mid/tm_subarray_node/1").assert_attribute( "State").equals("ON") resource("ska_mid/tm_subarray_node/1").assert_attribute( "obsState").equals("EMPTY") assign_resources_file = ( "resources/test_data/TMC_integration/assign_resources1.json") update_resource_config_file(assign_resources_file) config = load_config_from_file(assign_resources_file) CentralNode = DeviceProxy("ska_mid/tm_central/central_node") CentralNode.AssignResources(config) LOGGER.info("Invoked AssignResources on CentralNode") compose_sub() # tear down LOGGER.info("Tests complete: tearing down...") tmc.release_resources() fixture["state"] = "Complete" tmc.set_to_standby() except: LOGGER.info("Tearing down failed test, state = {}".format( fixture["state"])) if fixture["state"] == "Telescope On": tmc.set_to_standby() elif fixture["state"] == "Subarray Assigned": tmc.release_resources() tmc.set_to_standby() else: LOGGER.info("Tearing down completed...") raise
def start_script_execution(script, sb_json, result): """ """ LOGGER.info("Before starting the telescope checking if the TMC is in ON state") assert(tmc_is_on()) if telescope_is_in_standby(): set_telescope_to_running() take_subarray(1).to_be_composed_out_of(2) _ = EXECUTOR.create_script(script) task = EXECUTOR.start_script(sb_json) result[SCRIPT_ID] = task.task_id assert task.state == 'RUNNING', \ f"Expected script to be RUNNING, instead was {task.state}"
def set_subarray_to_idle(result): """ Set sub-array to idle state after resources are allocated. """ LOGGER.info( "Before starting the telescope checking if the TMC is in ON state") assert (tmc_is_on()) if telescope_is_in_standby(): LOGGER.info("Starting up telescope") set_telescope_to_running() LOGGER.info("Assigning 2 dishes") take_subarray(1).to_be_composed_out_of(2) subarray_state = resource(result[SUBARRAY_USED]).get('obsState') assert subarray_state == 'IDLE', \ f"Expected sub-array to be in IDLE but instead was in {subarray_state}" LOGGER.info("Sub-array is in ObsState IDLE")
def allocate_resources(): """ setting up running telescope with 2 dishes are allocated """ LOGGER.info( "Before starting the telescope checking if the TMC is in ON state") assert (tmc_is_on()) LOGGER.info( "Before starting the telescope checking if the telescope is in StandBy" ) if telescope_is_in_standby(): LOGGER.info("Starting up telescope") set_telescope_to_running() LOGGER.info("Telescope started") LOGGER.info("Assigning 2 dishes to subarray 1") take_subarray(1).to_be_composed_out_of(2) LOGGER.info("Resources are successfully assigned to subarray 1.")
def set_subarray_to_aborted(result): """ Set sub-array to ABORTED state by sending Abort command after resources are allocated. """ LOGGER.info("Before starting the telescope checking if the TMC is in ON state") assert(tmc_is_on()) if telescope_is_in_standby(): set_telescope_to_running() take_subarray(1).to_be_composed_out_of(2) subarray = SubArray(1) subarray.abort() subarray_state = resource(result[SUBARRAY_USED]).get('obsState') assert subarray_state == 'ABORTED', \ f"Expected sub-array to be in ABORTED but instead was in {subarray_state}" LOGGER.info("Sub-array has been set to ABORTED")
def allocate_resources_from_sbi(script, sb_json): """ Use the OET Rest API to run resource allocation script with SB JSON Args: script (str): file path to an observing script sb_json (str): file path to a scheduling block """ LOGGER.info("Before starting the telescope checking if the TMC is in ON state") assert(tmc_is_on()) if telescope_is_in_standby(): set_telescope_to_running() script_completion_state = EXECUTOR.execute_script( script, sb_json, timeout=300 ) assert script_completion_state == 'COMPLETED', \ f"Expected resource allocation script to be COMPLETED, instead was {script_completion_state}"
def test_start_up_telescope(run_context): LOGGER.info( "Before starting the telescope checking if the TMC is in ON state") assert (tmc_is_on()) LOGGER.info( "Before starting the telescope checking if the telescope is in StandBy." ) assert (telescope_is_in_standby) jsonLogin = {"username": "******", "password": "******"} url = 'http://taranta-taranta-{}:8080/login'.format( run_context.HELM_RELEASE) r = requests.post(url=url, json=jsonLogin) taranta_jwt = r.cookies.get_dict()['taranta_jwt'] cookies = {'taranta_jwt': taranta_jwt} url = 'http://taranta-taranta-{}:5004/db'.format(run_context.HELM_RELEASE) # with open('test-harness/files/mutation.json', 'r') as file: # mutation = file.read().replace('\n', '') mutation = '{"query":"mutation {\\n executeCommand(device: \\"ska_mid/tm_central/central_node\\", command: \\"TelescopeOn\\") {\\n ok\\n output\\n message\\n }\\n}\\n","variables":"null"}' LOGGER.info("Mutation " + str(mutation)) jsonMutation = json.loads(mutation) LOGGER.info("jsonMutation " + str(jsonMutation)) the_waiter = waiter() the_waiter.set_wait_for_starting_up() r = requests.post(url=url, json=jsonMutation, cookies=cookies) the_waiter.wait() LOGGER.info("r.text " + str(r.text)) parsed = json.loads(r.text) LOGGER.info("parsed r.text is " + str(parsed)) print(json.dumps(parsed, indent=4, sort_keys=True)) LOGGER.info("sorted pasrsed r.text " + str(json.dumps(parsed, indent=4, sort_keys=True))) try: assert parsed['data']['executeCommand']['ok'] == True finally: # tear down command is ignored if it is already in standby if not telescope_is_in_standby(): # wait first for telescope to completely go to standby before switchig it off again set_telescope_to_standby() LOGGER.info("Telescope is in STANDBY")
def test_multi_scan(): #### try: the_waiter = waiter() fixture = {} fixture["state"] = "Unknown" # given a started up telescope LOGGER.info("Checking if Telescope is in StandBy") assert telescope_is_in_standby() LOGGER.info("Telescope is in StandBy") tmc.start_up() LOGGER.info("Staring up the Telescope") fixture["state"] = "Telescope On" # and a subarray composed of two resources configured as perTMC_integration/assign_resources1.json sdp_block = tmc.compose_sub() LOGGER.info("Composing the Subarray") fixture["state"] = "Subarray Assigned" # and for which the subarray is configured to perform a scan as per 'TMC_integration/configure1.json' fixture["state"] = "Subarray CONFIGURING" configure_file = "resources/test_data/TMC_integration/configure2.json" tmc.configure_sub(sdp_block, configure_file) LOGGER.info("Configuring the Subarray") fixture["state"] = "Subarray Configured for SCAN" # and for which the subarray has successfully completed a scan durating 6 seconds based on previos configuration resource("ska_mid/tm_subarray_node/1").assert_attribute("obsState").equals( "READY" ) LOGGER.info("Starting a scan of 6 seconds") with log_states("TMC_ss-41-scan1", devices_to_log, non_default_states_to_check): with sync_scanning(200): SubarrayNode = DeviceProxy("ska_mid/tm_subarray_node/1") SubarrayNode.Scan('{"id":1}') fixture["state"] = "Subarray SCANNING" LOGGER.info("Subarray obsState is: " + str(SubarrayNode.obsState)) LOGGER.info("Scan 1 is executing on Subarray") LOGGER.info("Scan1 complete") fixture["state"] = "Subarray Configured for SCAN" # then when I load a new configuration to perform a can as per TMC_integration/configure2.json LOGGER.info("Configuring the Subarray") fixture["state"] = "Subarray CONFIGURING" configure_file = "resources/test_data/TMC_integration/configure1.json" tmc.configure_sub(sdp_block, configure_file) LOGGER.info("Configuring the Subarray") fixture["state"] = "Subarray Configured for SCAN" # and run a new scan bsed on that configuration resource("mid_csp/elt/subarray_01").assert_attribute("obsState").equals("READY") resource("mid_csp_cbf/sub_elt/subarray_01").assert_attribute("obsState").equals( "READY" ) resource("mid_sdp/elt/subarray_1").assert_attribute("obsState").equals("READY") resource("ska_mid/tm_subarray_node/1").assert_attribute("obsState").equals( "READY" ) LOGGER.info("Starting a scan of 6 seconds") with log_states("TMC_ss-41-scan2", devices_to_log, non_default_states_to_check): with sync_scanning(200): LOGGER.info("Check obsstate again before starting 2nd scan") resource("ska_mid/tm_subarray_node/1").assert_attribute( "obsState" ).equals("READY") resource("mid_csp/elt/subarray_01").assert_attribute("obsState").equals( "READY" ) resource("mid_csp_cbf/sub_elt/subarray_01").assert_attribute( "obsState" ).equals("READY") resource("mid_sdp/elt/subarray_1").assert_attribute("obsState").equals( "READY" ) SubarrayNode = DeviceProxy("ska_mid/tm_subarray_node/1") SubarrayNode.Scan('{"id":1}') fixture["state"] = "Subarray SCANNING" LOGGER.info("Subarray obsState is: " + str(SubarrayNode.obsState)) LOGGER.info("Scan2 complete") fixture["state"] = "Subarray Configured for SCAN" # the scanning should complete without any exceptions # TODO possibly add some other asserts in here # tear down LOGGER.info("TMC-multiscan tests complete: tearing down...") tmc.end_sb() the_waiter.wait() LOGGER.info("Invoked EndSB on Subarray") tmc.release_resources() the_waiter.wait() LOGGER.info("Invoked ReleaseResources on Subarray") tmc.set_to_standby() LOGGER.info("Invoked StandBy on Subarray") the_waiter.wait() LOGGER.info("Invoked StandBy on Subarray") LOGGER.info("Tests complete: tearing down...") except Exception as e: logging.info(f"Exception raised: {e.args}") LOGGER.info("Gathering logs") LOGGER.info("Tearing down failed test, state = {}".format(fixture["state"])) if fixture["state"] == "Telescope On": tmc.set_to_standby() the_waiter.wait() elif fixture["state"] == "Subarray Assigned": tmc.release_resources() the_waiter.wait() tmc.set_to_standby() the_waiter.wait() elif fixture["state"] == "Subarray Configured for SCAN": tmc.end_sb() the_waiter.wait() tmc.release_resources() the_waiter.wait() tmc.set_to_standby() the_waiter.wait() elif fixture["state"] == "Subarray SCANNING": if resource("ska_mid/tm_subarray_node/1").get("obsState") == "SCANNING": raise Exception("unable to teardown subarray from being in SCANNING") else: # sleep arbitrary number here to handle possible failures in un-idempotentcy sleep(3) tmc.end_sb() the_waiter.wait() tmc.release_resources() the_waiter.wait() tmc.set_to_standby() the_waiter.wait() raise e elif fixture["state"] == "Subarray CONFIGURING": raise Exception("unable to teardown subarray from being in CONFIGURING") elif fixture["state"] == "Unknown": LOGGER.info("Put telescope back to standby") tmc.set_to_standby() the_waiter.wait() pytest.fail("unable to complete test without exceptions")
def test_configure_scan(): try: # given an interface to TMC to interact with a subarray node and a central node fixture = {} fixture["state"] = "Unknown" # given a started up telescope assert telescope_is_in_standby() LOGGER.info("Staring up the Telescope") tmc.start_up() fixture["state"] = "Telescope On" # and a subarray composed of two resources configured as perTMC_integration/assign_resources.json LOGGER.info("Composing the Subarray") sdp_block = tmc.compose_sub() fixture["state"] = "Subarray Assigned" # then when I configure a subarray to perform a scan as per 'TMC_integration/configure1.json' @log_it("TMC_int_configure", devices_to_log, non_default_states_to_check) @sync_configure @time_it(90) def configure_sub(sdp_block): # commented because below asserts are already checked in @sync_configure # resource('ska_mid/tm_subarray_node/1').assert_attribute('State').equals('ON') # resource('ska_mid/tm_subarray_node/1').assert_attribute('obsState').equals('IDLE') configure1_file = "resources/test_data/TMC_integration/configure1.json" update_scan_config_file(configure1_file, sdp_block) config = load_config_from_file(configure1_file) LOGGER.info("Configuring a scan for subarray 1") fixture["state"] = "Subarray CONFIGURING" SubarrayNode = DeviceProxy("ska_mid/tm_subarray_node/1") SubarrayNode.Configure(config) LOGGER.info("Invoked Configure on Subarray") configure_sub(sdp_block) fixture["state"] = "Subarray Configured for SCAN" # tear down LOGGER.info("TMC-configure tests complete: tearing down...") tmc.end_sb() fixture["state"] = "Subarray is in IDLE after EndCommand" LOGGER.info("Invoked EndSB on Subarray") DishMaster1 = DeviceProxy("mid_d0001/elt/master") DishMaster2 = DeviceProxy("mid_d0002/elt/master") LOGGER.info( "After EndSB pointingState of Dish1:" + str(DishMaster1.pointingState) ) LOGGER.info( "After EndSB pointingState of Dish2:" + str(DishMaster2.pointingState) ) tmc.release_resources() LOGGER.info("Invoked ReleaseResources on Subarray") fixture["state"] = "Released Resources" tmc.set_to_standby() LOGGER.info("Invoked StandBy on Subarray") except: LOGGER.info("Tearing down failed test, state = {}".format(fixture["state"])) if fixture["state"] == "Telescope On": tmc.set_to_standby() elif fixture["state"] == "Subarray Assigned": tmc.release_resources() tmc.set_to_standby() elif fixture["state"] == "Subarray Configured for SCAN": LOGGER.info("Tearing down in , state = {}".format(fixture["state"])) tmc.end_sb() tmc.release_resources() tmc.set_to_standby() elif fixture["state"] == "Subarray is in IDLE after EndCommand": LOGGER.info("Tearing down in , state = {}".format(fixture["state"])) tmc.release_resources() tmc.set_to_standby() elif fixture["state"] == "Released Resources": LOGGER.info("Tearing down in , state = {}".format(fixture["state"])) tmc.set_to_standby() elif fixture["state"] == "Subarray CONFIGURING": raise Exception("unable to teardown subarray from being in CONFIGURING") pytest.fail("unable to complete test without exceptions")
def test_abort_restart(): try: # given an interface to TMC to interact with a subarray node and a central node fixture = {} fixture["state"] = "Unknown" the_waiter = waiter() # given a started up telescope assert telescope_is_in_standby() LOGGER.info("Staring up the Telescope") tmc.start_up() fixture["state"] = "Telescope On" # and a subarray composed of two resources configured as perTMC_integration/assign_resources.json LOGGER.info("Composing the Subarray") tmc.compose_sub() fixture["state"] = "Subarray Assigned" resource("ska_mid/tm_subarray_node/1").assert_attribute( "obsState").equals("IDLE") LOGGER.info("Aborting the subarray") fixture["state"] = "Subarray ABORTING" @log_it("TMC_int_abort", devices_to_log, non_default_states_to_check) @sync_abort() def abort(): resource("ska_mid/tm_subarray_node/1").assert_attribute( "State").equals("ON") resource("ska_mid/tm_subarray_node/1").assert_attribute( "obsState").equals("IDLE") SubarrayNode = DeviceProxy("ska_mid/tm_subarray_node/1") SubarrayNode.Abort() LOGGER.info("Invoked Abort on Subarray") abort() the_waiter.wait() LOGGER.info("Abort is complete on Subarray") fixture["state"] = "Subarray Aborted" fixture["state"] = "Subarray Restarting" @sync_restart() def restart(): resource("ska_mid/tm_subarray_node/1").assert_attribute( "State").equals("ON") # resource('mid_csp/elt/subarray_01').assert_attribute('obsState').equals('ABORTED') # resource('mid_sdp/elt/subarray_1').assert_attribute('obsState').equals('ABORTED') SubarrayNode = DeviceProxy("ska_mid/tm_subarray_node/1") # the_waiter.wait() LOGGER.info( "Subarray obsState before Aborted assertion check is: " + str(SubarrayNode.obsState)) resource("ska_mid/tm_subarray_node/1").assert_attribute( "obsState").equals("ABORTED") SubarrayNode.restart() LOGGER.info("Subarray obsState is: " + str(SubarrayNode.obsState)) LOGGER.info("Invoked restart on Subarray") restart() LOGGER.info("Restart is complete on Subarray") fixture["state"] = "Subarray empty" tmc.set_to_standby() LOGGER.info("Invoked StandBy on Subarray") fixture["state"] = "Subarray off" # tear down LOGGER.info("TMC-Abort-Restart tests complete: tearing down...") except: LOGGER.info("Tearing down failed test, state = {}".format( fixture["state"])) if fixture["state"] == "Telescope On": tmc.set_to_standby() elif fixture["state"] == "Subarray Assigned": tmc.release_resources() tmc.set_to_standby() elif fixture["state"] == "Subarray ABORTING": # restart_subarray(1) raise Exception( "unable to teardown subarray from being in ABORTING") elif fixture["state"] == "Subarray Aborted": # restart_subarray(1) raise Exception( "unable to teardown subarray from being in Aborted") elif fixture["state"] == "Subarray Restarting": # restart_subarray(1) raise Exception( "unable to teardown subarray from being in Restarting") elif fixture["state"] == "Subarray off": LOGGER.info("Subarray has completed StandBy execution") pytest.fail("unable to complete test without exceptions")
def test_obsreset(): try: # given an interface to TMC to interact with a subarray node and a central node fixture = {} fixture["state"] = "Unknown" the_waiter = waiter() # given a started up telescope assert telescope_is_in_standby() LOGGER.info("Staring up the Telescope") tmc.start_up() fixture["state"] = "Telescope On" # and a subarray composed of two resources configured as perTMC_integration/assign_resources.json LOGGER.info("Composing the Subarray") sdp_block = tmc.compose_sub() fixture["state"] = "Subarray Assigned" @log_it("TMC_int_configure", devices_to_log, non_default_states_to_check) def configure_sub(sdp_block): # commented because below asserts are already checked in @sync_configure # resource('ska_mid/tm_subarray_node/1').assert_attribute('State').equals('ON') # resource('ska_mid/tm_subarray_node/1').assert_attribute('obsState').equals('IDLE') configure1_file = "resources/test_data/TMC_integration/configure2.json" update_scan_config_file(configure1_file, sdp_block) config = load_config_from_file(configure1_file) LOGGER.info("Configuring a scan for subarray 1") fixture["state"] = "Subarray CONFIGURING" SubarrayNode = DeviceProxy("ska_mid/tm_subarray_node/1") SubarrayNode.Configure(config) LOGGER.info("Invoked Configure on Subarray") configure_sub(sdp_block) fixture["state"] = "Subarray Configured for SCAN" resource("ska_mid/tm_subarray_node/1").assert_attribute( "obsState").equals("CONFIGURING") LOGGER.info("Aborting the subarray") fixture["state"] = "Subarray ABORTING" @log_it("TMC_int_abort", devices_to_log, non_default_states_to_check) @sync_abort() def abort(): resource("ska_mid/tm_subarray_node/1").assert_attribute( "State").equals("ON") resource("ska_mid/tm_subarray_node/1").assert_attribute( "obsState").equals("CONFIGURING") SubarrayNode = DeviceProxy("ska_mid/tm_subarray_node/1") SubarrayNode.Abort() LOGGER.info("Invoked Abort on Subarray") abort() the_waiter.wait() LOGGER.info("Abort is complete on Subarray") fixture["state"] = "Subarray Aborted" fixture["state"] = "Subarray Resetting" @sync_obsreset() def obsreset(): resource("ska_mid/tm_subarray_node/1").assert_attribute( "State").equals("ON") # resource('mid_csp/elt/subarray_01').assert_attribute('obsState').equals('ABORTED') # resource('mid_sdp/elt/subarray_1').assert_attribute('obsState').equals('ABORTED') SubarrayNode = DeviceProxy("ska_mid/tm_subarray_node/1") # the_waiter.wait() LOGGER.info( "Subarray obsState before Aborted assertion check is: " + str(SubarrayNode.obsState)) resource("ska_mid/tm_subarray_node/1").assert_attribute( "obsState").equals("ABORTED") SubarrayNode.ObsReset() LOGGER.info("Subarray obsState is: " + str(SubarrayNode.obsState)) LOGGER.info("Invoked obsreset on Subarray") obsreset() LOGGER.info("Obsreset is complete on Subarray") fixture["state"] = "Subarray IDLE" tmc.release_resources() LOGGER.info("Invoked ReleaseResources on Subarray") tmc.set_to_standby() LOGGER.info("Invoked StandBy on Subarray") # tear down LOGGER.info("TMC-ObsReset tests complete: tearing down...") except: LOGGER.info("Tearing down failed test, state = {}".format( fixture["state"])) if fixture["state"] == "Telescope On": tmc.set_to_standby() elif fixture["state"] == "Subarray Assigned": tmc.release_resources() tmc.set_to_standby() elif fixture["state"] == "Subarray ABORTING": raise Exception( "unable to teardown subarray from being in ABORTING") elif fixture["state"] == "Subarray Aborted": raise Exception( "unable to teardown subarray from being in Aborted") elif fixture["state"] == "Subarray Resetting": raise Exception( "unable to teardown subarray from being in Restarting") elif fixture["state"] == "Subarray IDLE": tmc.release_resources() tmc.set_to_standby() pytest.fail("unable to complete test without exceptions")
def test_scan(): try: # given an interface to TMC to interact with a subarray node and a central node fixture = {} fixture["state"] = "Unknown" # given a started up telescope assert telescope_is_in_standby() LOGGER.info("Starting up the Telescope") tmc.start_up() fixture["state"] = "Telescope On" # and a subarray composed of two resources configured as perTMC_integration/assign_resources.json LOGGER.info("Composing the Subarray") sdp_block = tmc.compose_sub() fixture["state"] = "Subarray Assigned" # and a subarray configured to perform a scan as per 'TMC_integration/configure1.json' LOGGER.info("Configuring the Subarray") fixture["state"] = "Subarray CONFIGURING" configure_file = "resources/test_data/TMC_integration/configure1.json" tmc.configure_sub(sdp_block, configure_file) fixture["state"] = "Subarray Configured for SCAN" # When I run a scan of 4 seconds based on previos configuration resource("ska_mid/tm_subarray_node/1").assert_attribute("obsState").equals( "READY" ) LOGGER.info("Starting a scan of 4 seconds") fixture["state"] = "Subarray SCANNING" @log_it("TMC_int_scan", devices_to_log, non_default_states_to_check) @sync_scan(200) def scan(): SubarrayNode = DeviceProxy("ska_mid/tm_subarray_node/1") SubarrayNode.Scan('{"id":1}') scan() LOGGER.info("Scan complete") fixture["state"] = "Subarray Configured for SCAN" # tear down LOGGER.info("TMC-Scan tests complete: tearing down...") tmc.end_sb() LOGGER.info("Invoked EndSB on Subarray") tmc.release_resources() LOGGER.info("Invoked ReleaseResources on Subarray") tmc.set_to_standby() LOGGER.info("Invoked StandBy on Subarray") except: LOGGER.info("Tearing down failed test, state = {}".format(fixture["state"])) if fixture["state"] == "Telescope On": tmc.set_to_standby() elif fixture["state"] == "Subarray Assigned": tmc.release_resources() tmc.set_to_standby() elif fixture["state"] == "Subarray Configured for SCAN": tmc.end_sb() tmc.release_resources() tmc.set_to_standby() elif fixture["state"] == "Subarray SCANNING": raise Exception("unable to teardown subarray from being in SCANNING") elif fixture["state"] == "Subarray CONFIGURING": raise Exception("unable to teardown subarray from being in CONFIGURING") pytest.fail("unable to complete test without exceptions")