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")
Beispiel #2
0
def check_subarry_state():
    # check that the obsState of SDP-Subarray is IDEL
    assert_that(
        resource('mid_sdp/elt/subarray_1').get('obsState')).is_equal_to('IDLE')
    # check that the obsState of CSP-Subarray is IDEL
    assert_that(resource('ska_mid/tm_subarray_node/1').get(
        'obsState')).is_equal_to('IDLE')
    # check that the obsState of TMC-Subarray is IDEL
    assert_that(resource('mid_csp/elt/subarray_01').get(
        'obsState')).is_equal_to('IDLE')
    LOGGER.info(
        "Then the subarray is in the condition that allows scan configurations to take place: PASSED"
    )
Beispiel #3
0
def pre_condition(dev_proxy, device_name, expected):
    """verify the device dish mode before executing mode transition requests"""
    try:
        assert_that(
            resource(device_name).get('dishMode')).is_equal_to(expected)
    except AssertionError:
        # standbyfp mode is used as initial condition since it can be reached from other dish modes
        _change_dish_mode(dev_proxy, 'SetStandbyFPMode', device_name)
        _change_dish_mode(dev_proxy, mode_cmd_map[expected], device_name)
        assert_that(
            resource(device_name).get('dishMode')).is_equal_to(expected)
    logging.info(device_name + ' initial dishMode: ' +
                 resource(device_name).get('dishMode'))
Beispiel #4
0
def check_subarray_composition(result):
    #check that there was no error in response
    assert_that(result['response']).is_equal_to(
        ResourceAllocation(dishes=[Dish(1), Dish(2),
                                   Dish(3), Dish(4)]))
    #check that this is reflected correctly on TMC side
    assert_that(resource('ska_mid/tm_subarray_node/1').get(
        "receptorIDList")).is_equal_to((1, 2, 3, 4))
    #check that this is reflected correctly on CSP side
    assert_that(resource('mid_csp/elt/subarray_01').get(
        'assignedReceptors')).is_equal_to((1, 2, 3, 4))
    assert_that(
        resource('mid_csp/elt/master').get('receptorMembership')).is_equal_to(
            (1, 1, 1, 1))
 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")
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"
    sdp_block = update_resource_config_file(assign_resources_file)
    LOGGER.info("_______sdp_block________" + str(sdp_block))
    config = load_config_from_file(assign_resources_file)
    CentralNode = DeviceProxy("ska_mid/tm_central/central_node")
    CentralNode.AssignResources(config)
    the_waiter = waiter()
    the_waiter.wait()
    LOGGER.info("Invoked AssignResources on CentralNode")
    return sdp_block
Beispiel #7
0
def pre_condition(dev_proxy, device_name, expected):
    """verify the device dish mode before executing mode transition requests"""
    actual = resource(device_name).get("dishMode")
    LOGGER.info(
        f"Resource actual dishMode: {actual}. Expected dishMode: {expected}")
    if actual != expected:
        # standbyfp is used as initial condition because it can be reached from other
        # dish modes but dont request standbyfp if this is the current dish mode
        if actual != "STANDBY_FP":
            _change_dish_mode(dev_proxy, "SetStandbyFPMode", device_name)
        _change_dish_mode(dev_proxy, mode_cmd_map[expected], device_name)
    assert_that(resource(device_name).get("dishMode")).is_equal_to(expected)
    LOGGER.info(
        f"{device_name} initial dishMode: {resource(device_name).get('dishMode')}"
    )
Beispiel #8
0
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)
Beispiel #9
0
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'))
Beispiel #10
0
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")
Beispiel #11
0
 def _loop(self,resources,state_name,resolution,max_nr_of_records,specific_states):
     n = 0
     list = []
     while self._get_running():
         n +=1
         record = {}
         start_time = time()
         record['seq'] = n
         record['time_window'] = datetime.now().strftime('%H:%M:%S.%f')[:-3] 
         for resource_name in resources:
             if specific_states == {}:
                 specific_state_name = state_name
             else:
                 specific_state_name = self._get_specific_state(specific_states,resource_name,state_name)
             record['{} state'.format(resource_name)] = resource(resource_name).get(specific_state_name)
             record['{} delta'.format(resource_name)] = '{:f}'.format(time() - start_time)
         if self._is_unique(list,record):
             record['unique'] = True
         else:
             record['unique'] = False
         list.append(record)
         if max_nr_of_records != None:
             if n >= max_nr_of_records:
                 logging.debug('nr of records ({}) is above max {}, stopping'.format(n,max_nr_of_records))
                 self._clear_running()
                 break
         time_left_to_sleep = abs(resolution - (time() - start_time))
         sleep(time_left_to_sleep)  
     self._update_records(list)
Beispiel #12
0
 def test_init(self):
     """
     Test the __init__ method.
     """
     device_name = 'name'
     item_under_test = resource(device_name)
     assert item_under_test.device_name == device_name
Beispiel #13
0
def check_subarray_composition(result):
    #check that there was no error in response
    # TODO: To uncomment once latest tmc-mid chart is published
    assert_that(result['response']).is_equal_to(
        ResourceAllocation(dishes=[Dish(1), Dish(2),
                                   Dish(3), Dish(4)]))
    #check that this is reflected correctly on TMC side
    assert_that(resource('ska_mid/tm_subarray_node/1').get(
        "receptorIDList")).is_equal_to((1, 2, 3, 4))
    #check that this is reflected correctly on CSP side
    assert_that(resource('mid_csp/elt/subarray_01').get(
        'assignedReceptors')).is_equal_to((1, 2, 3, 4))
    #assert_that(resource('mid_csp/elt/master').get('receptorMembership')).is_equal_to((1, 1,))
    #TODO need to find a better way of testing sets with sets
    #assert_that(set(resource('mid_csp/elt/master').get('availableReceptorIDs'))).is_subset_of(set((4,3)))
    #check that this is reflected correctly on SDP side - no code at the current implementation
    LOGGER.info("Then I have a subarray composed of 4 dishes: PASSED")
Beispiel #14
0
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":
        if resource("ska_mid/tm_subarray_node/1").get("obsState") == "IDLE":
            LOGGER.info("tearing down composed subarray (IDLE)")
            take_subarray(1).and_release_all_resources()
            LOGGER.info(
                "Resources are deallocated successfully from Subarray.")
    if resource("ska_mid/tm_subarray_node/1").get("obsState") == "CONFIGURING":
        LOGGER.warn(
            "Subarray is still in CONFIFURING! Please restart MVP manually to complete tear down"
        )
        restart_subarray(1)
        raise Exception("Unable to tear down test setup")
    if resource("ska_mid/tm_subarray_node/1").get("obsState") == "READY":
        LOGGER.info("tearing down configured subarray (READY)")
        take_subarray(1).and_end_sb_when_ready().and_release_all_resources()
    if resource("ska_mid/tm_subarray_node/1").get("obsState") == "SCANNING":
        LOGGER.warn(
            "Subarray is still in SCANNING! Please restart MVP manually to complete tear down"
        )
        restart_subarray(1)
        raise Exception("Unable to tear down test setup")
    if resource("ska_mid/tm_subarray_node/1").get("obsState") == "ABORTING":
        LOGGER.warn(
            "Subarray is still in ABORTING! Please restart MVP manually to complete tear down"
        )
        restart_subarray(1)
    if resource("ska_mid/tm_subarray_node/1").get("obsState") == "ABORTED":
        take_subarray(1).restart_when_aborted()
    LOGGER.info("Put Telescope back to standby")
    set_telescope_to_standby()
    LOGGER.info("Telescope is in StandBy.")
Beispiel #15
0
def receptorID_list_empty():
    watch_receptorIDList = watch(resource('ska_mid/tm_subarray_node/1')).for_a_change_on("receptorIDList")
    # gather info
    receptorIDList_val = watch_receptorIDList.get_value_when_changed()
    # confirm
    assert_that(receptorIDList_val == [])
    logging.info("ReceptorIDList is empty")
    # put telescope to standby
    SKAMid().standby()
Beispiel #16
0
def set_stow_mode(az):
    az['initial_az'] = resource(DISH).get("achievedPointing")[1]
    dish_proxy = tango.DeviceProxy(DISH)
    LOGGER.info(f"{DISH} initial azimuth: {az['initial_az']}")
    LOGGER.info(
        f"{DISH} initial elevation: {resource(DISH).get('achievedPointing')[2]}"
    )
    dish_proxy.setstowmode()
    LOGGER.info(f"{DISH} requested dishMode: STOW")
Beispiel #17
0
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 = download_test_data(
        "mid_assign_resources_v1.json",
        "skampi-test-data/tmc-integration/assign-resources")
    sdp_block = update_resource_config_file(assign_resources_file)
    LOGGER.info("_______sdp_block________" + str(sdp_block))
    config = load_config_from_file(assign_resources_file)
    os.remove(assign_resources_file)
    CentralNode = DeviceProxy('ska_mid/tm_central/central_node')
    CentralNode.AssignResources(config)
    the_waiter = waiter()
    the_waiter.wait()
    LOGGER.info('Invoked AssignResources on CentralNode')
    return sdp_block
def end(result):
    """ teardown any state that was previously setup with a setup_function
    call.
    """
    obsstate = resource(result[SUBARRAY_USED]).get('obsState')
    if obsstate == "IDLE":
        LOGGER.info("CLEANUP: tearing down composed subarray (IDLE)")
        take_subarray(1).and_release_all_resources()
    set_telescope_to_standby()
Beispiel #19
0
def restart_subarray(id):
    devices = device_to_subarrays.keys()
    filtered_devices = [
        device for device in devices if device_to_subarrays[device] == id
    ]
    the_waiter = waiter()
    the_waiter.set_wait_for_going_to_standby()
    exceptions_raised = ""
    LOGGER.info("Inside restart subarray method.")
    for device in filtered_devices:
        try:
            resource(device).restart()
            LOGGER.info("Restart subarray API invoked on device :" +
                        str(device))
        except Exception as e:
            exceptions_raised += f"\nException raised on reseting {device}:{e}"
    if exceptions_raised != "":
        raise Exception(f"Error in initialising devices:{exceptions_raised}")
    the_waiter.wait()
Beispiel #20
0
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")
Beispiel #21
0
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("obsState") == "IDLE"):
        LOGGER.info("Release all resources assigned to subarray")
        take_subarray(1).and_release_all_resources()
        LOGGER.info("ResourceIdList is empty for Subarray 1 ")
    LOGGER.info("Put Telescope back to standby")
    set_telescope_to_standby()
    LOGGER.info("Telescope is in standby")
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")
Beispiel #23
0
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()
Beispiel #24
0
def check_ready_state(fixture):
    # check that the TMC report subarray as being in the obsState = READY
    assert_that(resource('ska_mid/tm_subarray_node/1').get('obsState')).is_equal_to('SCANNING')
    #current functionality implies TMC may be in scanning even though CSP is not yet
    #logging.info("TMC-subarray obsState: " + resource('ska_mid/tm_subarray_node/1').get("obsState"))
    #assert_that(resource('mid_csp/elt/subarray_01').get('obsState')).is_equal_to('SCANNING')
    #logging.info("CSP-subarray obsState: " + resource('mid_csp/elt/subarray_01').get("obsState"))
    #check that the SDP report subarray as being in the obsState = READY
    #assert_that(resource('mid_sdp/elt/subarray_1').get('obsState')).is_equal_to('SCANNING')
    #logging.info("SDP-subarray obsState: " + resource('mid_sdp/elt/subarray_1').get("obsState"))
    return fixture
def check_final_state(result):
    """
    Check that the central node device is in the expected state.

    Args:
        result (dict): fixture used to track test progress
    """
    final_state = resource(result[CENTRAL_NODE_USED]).get('telescopeState')
    assert final_state == 'ON', \
        f"Expected telescope to be ON but instead was {final_state}"
    LOGGER.info("Telescope is on")
Beispiel #26
0
def check_final_subarray_state(obsstate, result):
    """

    Args:
        obsstate (str): Sub-array Tango device ObsState
        result (dict): Sub-array Tango device ObsState
    """
    subarray_state = resource(result[SUBARRAY_USED]).get('obsState')
    assert subarray_state == obsstate, \
        f"Expected sub-array to be in {obsstate} but instead was in {subarray_state}"

    LOGGER.info("Sub-array is in ObsState %s", obsstate)
Beispiel #27
0
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')
Beispiel #28
0
def check_final_subarray_state(obsstate, result):
    """
    Check that the final state of the sub-array is as expected.

    Args:
        obsstate (str): Sub-array Tango device ObsState
        result (dict): fixture used to track progress
    """
    subarray_state = resource(result[SUBARRAY_USED]).get('obsState')
    assert subarray_state == obsstate, \
        f"Expected sub-array to be in {obsstate} but instead was in {subarray_state}"
    LOGGER.info("Sub-array is in ObsState %s", obsstate)
Beispiel #29
0
def check_going_out_of_empty():
    ##verify once for obstate = EMPTY
    resource("mid_csp/elt/subarray_01").assert_attribute("obsState").equals(
        "EMPTY")
    resource("mid_sdp/elt/subarray_1").assert_attribute("obsState").equals(
        "EMPTY")
    resource("ska_mid/tm_subarray_node/1").assert_attribute("obsState").equals(
        "EMPTY")
Beispiel #30
0
def check_going_out_of_configured():
    ##Can only return to ON/IDLE if in READY
    resource("mid_csp/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")