def teardown_function(function): """ teardown any state that was previously setup with a setup_function call. """ the_waiter = waiter() if (resource('ska_mid/tm_subarray_node/1').get('obsState') == "IDLE"): the_waiter.set_wait_for_tearing_down_subarray() LOGGER.info("tearing down composed subarray (IDLE)") SubArray(1).deallocate() the_waiter.wait() LOGGER.info(the_waiter.logs) if (resource('ska_mid/tm_subarray_node/1').get('obsState') == "READY"): LOGGER.info("tearing down configured subarray (READY)") the_waiter.set_wait_for_ending_SB() SubArray(1).end_sb() the_waiter.wait() LOGGER.info(the_waiter.logs) the_waiter.set_wait_for_tearing_down_subarray() SubArray(1).deallocate() the_waiter.wait() LOGGER.info(the_waiter.logs) if (resource('ska_mid/tm_subarray_node/1').get('obsState') == "CONFIGURING"): LOGGER.info("tearing down configuring subarray") restart_subarray(1) if (resource('ska_mid/tm_subarray_node/1').get('obsState') == "SCANNING"): LOGGER.info("tearing down scanning subarray") restart_subarray(1) the_waiter.set_wait_for_going_to_standby() SKAMid().standby() LOGGER.info("standby command is executed on telescope") the_waiter.wait() LOGGER.info(the_waiter.logs)
def main(subarray_id=1, dish_ids=None): """ Allocate resources to a target sub-array. :param subarray_id: numeric subarray ID :param dish_ids: comma-separated dish IDs :return: """ if dish_ids is None: dish_ids = [] LOG.info(f'Running allocate script in OS process {os.getpid()}') LOG.info( f'Called with main(subarray_id={subarray_id}, dish_ids={dish_ids}') subarray = SubArray(subarray_id) dishes = [Dish(i) for i in dish_ids] allocation = ResourceAllocation(dishes=dishes) LOG.info(f'Allocating resources: {allocation}') allocated = subarray.allocate(allocation) LOG.info(f'Resources Allocated: {allocated}') LOG.info('Allocation script complete')
def main(configuration, scan_duration, subarray_id=1, repeat=1, process_json=True): """ Configure a sub-array and perform the scan. :param configuration: name of configuration file :param scan_duration: scan duration in seconds :param subarray_id: numeric subarray ID :param repeat: number of times to repeat the configure/scan :param process_json: set to False to pass JSON directly to TMC without processing :return: """ LOG.info(f'Running observe script in OS process {os.getpid()}') LOG.info(f'Called with main(configuration={configuration}, scan_duration={scan_duration}, ' f'subarray_id={subarray_id})') if not os.path.isfile(configuration): msg = f'File not found: {configuration}' LOG.error(msg) raise IOError(msg) subarray = SubArray(subarray_id) for i in range(repeat): LOG.info(f'Scan {i+1} of {repeat}') LOG.info(f'Configure subarray from CDM: {configuration}') subarray.configure_from_file(configuration, with_processing=process_json) LOG.info(f'Perform scan for {scan_duration}s') subarray.scan(float(scan_duration)) LOG.info('End scheduling block') subarray.end_sb() LOG.info('Observation script complete')
def test_allocation(): the_telescope = SKAMid() the_subarray = SubArray(1) the_resource_allocation = ResourceAllocation(dishes=[Dish(1), Dish(2)]) print("Starting up telescope ...") the_telescope.start_up() #commented this out as it gives an error when it was already deallocated # print("Releasing any previously allocated resources... ") # result = the_subarray.deallocate() # pause() print("Allocating new resources... ") result = the_subarray.allocate(the_resource_allocation) pause( ) #rather poll for subarray_proxy.State changing OFF/OFLLINE to ON (TMC team to confirm whether this is really neccesary assert_that(result).is_equal_to(the_resource_allocation) # Confirm result via direct inspection of TMC subarray_proxy = DeviceProxy('ska_mid/tm_subarray_node/1') pause() # not neccesary receptor_list = subarray_proxy.receptorIDList pause() # not neccesary #need to check the state as well is in ObsState = IDLE and State = ON #TODO check the resource assignment of the CSP is correct (receptors and corresponding VCC state - also check that it changed to correct state) #mid_csp/elt/master check the status of receptors and VCC reflect assignment #mid_csp/elt/subarray_01 check status and correct composition # check the resource assignment of the SDP is correct (no op - also check that the changed to correct state ObsState= IDLE and State = ON) # check that the dishes have responded assert_that(receptor_list).is_equal_to((1, 2)) print("Now deallocating resources ... ") the_subarray.deallocate() pause( ) #rather poll for subarray_proxy.State changing ON OFFLINE (TMC team to confim) # Confirm result via direct inspection of TMC - expecting None receptor_list = subarray_proxy.receptorIDList pause() # not needed assert_that(receptor_list).is_equal_to(None) print("Subarry has no allocated resources") # put telescope to standby the_telescope.standby() print( "Script Complete: All resources dealoccated, Telescope is in standby")
def main(subarray_id=1): """ Deallocate sub-array resources. :param subarray_id: numeric subarray ID :return: """ LOG.info(f'Running deallocate script in OS process {os.getpid()}') LOG.info(f'Called with main(subarray_id={subarray_id}') subarray = SubArray(subarray_id) LOG.info(f'Deallocating resources...') subarray.deallocate() LOG.info('Deallocation script complete')
def set_to_running(result): SKAMid().start_up() #watch_State = watch(resource('ska_mid/tm_subarray_node/1')).for_a_change_on("State") watch_receptorIDList = watch(resource('ska_mid/tm_subarray_node/1')).for_a_change_on("receptorIDList") result['response'] = SubArray(1).allocate(ResourceAllocation(dishes=[Dish(1), Dish(2), Dish(3), Dish(4)])) logging.info("subarray state: " + resource('ska_mid/tm_subarray_node/1').get("State")) watch_receptorIDList.wait_until_value_changed() return result
def and_release_all_resources(self): the_waiter = waiter() the_waiter.set_wait_for_tearing_down_subarray() SubArray(1).deallocate() the_waiter.wait() if the_waiter.timed_out: pytest.fail("timed out whilst releasing resources on subarray:\n {}".format(the_waiter.logs)) self.logs = the_waiter.logs return self
def and_configure_scan_by_file(self,file='resources/test_data/polaris_b1_no_cam.json'): timeout = 80 # update the ID of the config data so that there is no duplicate configs send during tests update_file(file) signal.signal(signal.SIGALRM, handlde_timeout) signal.alarm(timeout) # wait for 30 seconds and timeout if still stick try: logging.info("Configuring the subarray") SubArray(1).configure_from_file(file, with_processing=False) except Exception as ex_obj: LOGGER.info("Exception in configure command: %s", ex_obj)
def config(): timeout = 60 devices_to_log = [ 'ska_mid/tm_subarray_node/1', 'mid_csp/elt/subarray_01', 'mid_csp_cbf/sub_elt/subarray_01', 'mid_sdp/elt/subarray_1', 'mid_d0001/elt/master', 'mid_d0002/elt/master', 'mid_d0003/elt/master', 'mid_d0004/elt/master' ] non_default_states_to_check = { 'mid_d0001/elt/master': 'pointingState', 'mid_d0002/elt/master': 'pointingState', 'mid_d0003/elt/master': 'pointingState', 'mid_d0004/elt/master': 'pointingState' } # update the ID of the config data so that there is no duplicate configs send during tests file = 'resources/test_data/polaris_b1_no_cam.json' update_file(file) signal.signal(signal.SIGALRM, handlde_timeout) signal.alarm(timeout) # wait for 20 seconds and timeout if still stick #set up logging of components s = StateChecker(devices_to_log, specific_states=non_default_states_to_check) s.run(threaded=True, resolution=0.1) LOGGER.info("Starting Configuration Test") d = DeviceLogging('DeviceLoggingImplWithDBDirect') d.update_traces(devices_to_log) d.start_tracing() #setup a watch for subarray node to change obstate as transaction should only be complete once it has changed w = watch( resource('ska_mid/tm_subarray_node/1')).for_a_change_on("obsState") try: SubArray(1).configure_from_file(file, with_processing=False) except: LOGGER.info( "Configure Command timed out after {} seconds".format(timeout)) LOGGER.info("Gathering logs") # sleep for 0.2 seconds to gather any pending events sleep(0.2) d.stop_tracing() s.stop() print_logs_to_file(s, d, status='error') LOGGER.info( "The following messages was logged from devices:\n{}".format( d.get_printable_messages())) #LOGGER.info("The following states was captured:\n{}".format(s.get_records())) pytest.fail("timed out during confguration") #ensure state is on Ready before proceeding w.wait_until_value_changed_to('READY', timeout=20) LOGGER.info("Configure executed successfully") LOGGER.info("Gathering logs") s.stop() d.stop_tracing() print_logs_to_file(s, d, status='ok')
class pilot(): def __init__(self, id): self.SubArray = SubArray(id) self.logs = "" def to_be_composed_out_of(self, dishes): the_waiter = waiter() the_waiter.set_wait_for_assign_resources() self.result = self.SubArray.allocate(ResourceAllocation(dishes=[Dish(x) for x in range(1, dishes + 1)])) the_waiter.wait() self.logs = the_waiter.logs if the_waiter.timed_out: pytest.fail("timed out whilst composing subarray:\n {}".format(the_waiter.logs)) return self def and_configure_scan_by_file(self,file='resources/test_data/polaris_b1_no_cam.json'): timeout = 80 # update the ID of the config data so that there is no duplicate configs send during tests update_file(file) signal.signal(signal.SIGALRM, handlde_timeout) signal.alarm(timeout) # wait for 30 seconds and timeout if still stick try: logging.info("Configuring the subarray") SubArray(1).configure_from_file(file, with_processing=False) except Exception as ex_obj: LOGGER.info("Exception in configure command: %s", ex_obj) def and_release_all_resources(self): the_waiter = waiter() the_waiter.set_wait_for_tearing_down_subarray() SubArray(1).deallocate() the_waiter.wait() if the_waiter.timed_out: pytest.fail("timed out whilst releasing resources on subarray:\n {}".format(the_waiter.logs)) self.logs = the_waiter.logs return self def and_end_sb_when_ready(self): the_waiter = waiter() the_waiter.set_wait_for_going_to_standby() SKAMid().standby() the_waiter.wait() if the_waiter.timed_out: pytest.fail("timed out taking the subarray to IDLE:\n {}".format(the_waiter.logs)) self.logs = the_waiter.logs return self
def teardown_function(function): """ teardown any state that was previously setup with a setup_function call. """ the_waiter = waiter() if (resource('ska_mid/tm_subarray_node/1').get('obsState') == "IDLE"): #this means there must have been an error the_waiter.set_wait_for_tearing_down_subarray() LOGGER.info("tearing down composed subarray (IDLE)") SubArray(1).deallocate() the_waiter.wait() LOGGER.info(the_waiter.logs) if (resource('ska_mid/tm_subarray_node/1').get('obsState') == "READY"): #this means test must have passed LOGGER.info("tearing down configured subarray (READY)") the_waiter.set_wait_for_ending_SB() SubArray(1).end_sb() the_waiter.wait() LOGGER.debug(the_waiter.logs) the_waiter.set_wait_for_tearing_down_subarray() SubArray(1).deallocate() the_waiter.wait() LOGGER.debug(the_waiter.logs) if (resource('ska_mid/tm_subarray_node/1').get('obsState') == "CONFIGURING" ): LOGGER.warn( "Subarray is still in configuring! Please restart MVP manualy to complete tear down" ) restart_subarray(1) #raise exception since we are unable to continue with tear down raise Exception("Unable to tear down test setup") LOGGER.info("Putting Telescope in standby") the_waiter.set_wait_for_going_to_standby() SKAMid().standby() the_waiter.wait() LOGGER.debug(the_waiter.logs)
def teardown_function(function): """ teardown any state that was previously setup with a setup_function call. """ if (resource('ska_mid/tm_subarray_node/1').get("State") == "ON"): the_waiter = waiter() the_waiter.set_wait_for_tearing_down_subarray() SubArray(1).deallocate() the_waiter.wait() LOGGER.info(the_waiter.logs) if (resource('ska_mid/tm_subarray_node/1').get("State") == "OFF"): the_waiter = waiter() the_waiter.set_wait_for_going_to_standby() SKAMid().standby() the_waiter.wait() LOGGER.info(the_waiter.logs)
def allocate_four_dishes(result): the_waiter = waiter() the_waiter.set_wait_for_assign_resources() result['response'] = SubArray(1).allocate( ResourceAllocation(dishes=[Dish(1), Dish(2), Dish(3), Dish(4)])) #wait for certain values to be changed (refer to helpers for what is currently defined as neccesarry to wait) the_waiter.wait() LOGGER.info(the_waiter.logs) result = wait_for(resource('mid_csp/elt/master'), 20).to_be({ "attr": "receptorMembership", "value": (1, 1, 1, 1) }) if (result == "timed out"): LOGGER.info( "timed out after 2 seconds waiting for mid_csp/elt/master receptorMembership to change to (1,1,1,1)" ) return result
def send_scan(duration): SubArray(1).scan(duration)
def __init__(self, id): self.SubArray = SubArray(id) self.logs = ""
def deallocate_resources(result): result = SubArray(1).deallocate() logging.info("ReleaseResources command is involked on subarray ")