Commit 46b2edaa authored by Gianluca Marotta's avatar Gianluca Marotta
Browse files

CT-214 First implementation of AssignResourceCommand, with tests

parent 9687c216
Loading
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -376,8 +376,9 @@ class CspSubarray(SKASubarray):

        @transaction_id
        def do(self, argin):
            return super().do(argin)
            self.logger.warning("Assign Resource Command not yet implemented in CSP Subarray. This is an instance of the lmcbaseclasses")
            #TODO: Edit the logger
            self.logger.INFO('Assign resource command ... ')


    class ConfigureCommand(SKASubarray.ConfigureCommand):

+12 −3
Original line number Diff line number Diff line
@@ -99,8 +99,15 @@ class MidCspSubarrayBase(CspSubarray):
            return super().do()
            #return (ResultCode.OK, "On command completed OK")

    class AddReceptorsCommand(SKASubarray.AssignResourcesCommand):
    class AssignResourcesCommand(CspSubarray.AssignResourcesCommand):

        def do(self, argin):
            super().do(argin)
            config = json.loads(argin)
            receptor_list = config['receptorIDList']
            self.addReceptors(receptor_list)

        def addReceptors(self, argin):
            device = self.target
            # check if the CbfSubarray TANGO device is already running
            # and the proxy registered
@@ -601,9 +608,10 @@ class MidCspSubarrayBase(CspSubarray):
        """
        super().init_command_objects()
        args = (self, self.state_model, self.logger)
        self._addreceptors_cmd_obj = self.AddReceptorsCommand(*args)

        self._assignresources_cmd_obj = self.AssignResourcesCommand(*args)
        self._removereceptors_cmd_obj = self.RemoveReceptorsCommand(*args)
        self.register_command_object("AddReceptors", self.AddReceptorsCommand(*args))
        self.register_command_object("AssignResources", self.AssignResourcesCommand(*args))
        self.register_command_object("RemoveReceptors", self.RemoveReceptorsCommand(*args))
        self.register_command_object("RemoveAllReceptors", self.RemoveAllReceptorsCommand(*args))

@@ -781,6 +789,7 @@ class MidCspSubarrayBase(CspSubarray):
    # --------
    # Commands
    # --------
    #cancellare????
    @command(
        dtype_in='DevVarUShortArray',
        doc_in="List of the receptor IDs to add to the subarray.",
+25 −5
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ import numpy as np
import logging
import unittest
import pytest
import json

# Tango imports
import tango
@@ -115,7 +116,13 @@ class TestCspSubarray(TestBase):
        obs_state = self.midcsp_subarray01.obsState
        LOGGER.info("CSPSubarray state:{}-{}".format(state, obs_state))
        LOGGER.info("Going to assign receptors")
        self.midcsp_subarray01.AddReceptors(receptor_list.tolist())

        param = {
            'subarrayID': 1,
            'dish': {'receptorIDList': receptor_list.tolist()}}
        json_config = json.dumps(param)
        self.midcsp_subarray01.AssignResources(json_config)

        # wait for the transition to IDLE
        prober_obs_state = Probe(self.midcsp_subarray01, 'obsState', ObsState.IDLE,
                                           f"Wrong CSP Subarray obsState is not IDLE")
@@ -212,7 +219,12 @@ class TestCspSubarray(TestBase):
                invalid_receptor_to_assign.append(id_num)
            if len(invalid_receptor_to_assign) > 3:
                break
        self.midcsp_subarray01.AddReceptors(invalid_receptor_to_assign)
        param = {
            'subarrayID': 1,
            'dish': { 'receptorIDList': invalid_receptor_to_assign}}
        json_config = json.dumps(param)
        self.midcsp_subarray01.AssignResources(json_config)

        prober_obs_state = Probe(self.midcsp_subarray01, "obsState", ObsState.EMPTY, f"CSP Subarray is not EMPTY")
        Poller(4, 0.2).check(prober_obs_state)
        receptors = self.midcsp_subarray01.assignedReceptors
@@ -241,7 +253,11 @@ class TestCspSubarray(TestBase):
        # assert the array is not empty
        assert receptor_list.any()
        # Exercise the system: issue the AddREceptors command
        self.midcsp_subarray01.AddReceptors(receptor_list)
        param = {
            'subarrayID': 1,
            'dish': {'receptorIDList': receptor_list}}
        json_config = json.dumps(param)
        self.midcsp_subarray01.AssignResources(json_config)
        # check the final subarray obstate
        prober_obs_state = Probe(self.midcsp_subarray01, 'obsState', ObsState.IDLE,
                                           f"Wrong CSP Subarray obsState")
@@ -263,7 +279,11 @@ class TestCspSubarray(TestBase):
        LOGGER.info(f"receptors belonging to subarray:{assigned_receptors}")
        # Exercise: try to re-assign one of the subarray receptors
        LOGGER.info(f"Try to assign receptor:{assigned_receptors[0]}")
        self.midcsp_subarray01.AddReceptors([assigned_receptors[0],])
        param = {
            'subarrayID': 1,
            'dish': {'receptorIDList': [assigned_receptors[0],]}}
        json_config = json.dumps(param)
        self.midcsp_subarray01.AssignResources(json_config)
        # check 
        prober_obs_state = Probe(self.midcsp_subarray01, 'obsState', ObsState.IDLE,
                                           f"Wrong CSP Subarray obsState")
@@ -514,7 +534,7 @@ class TestCspSubarray(TestBase):
    def test_send_abort_WHILE_in_configuring(self):
        """
        Configure the CSP Subarray with a JSon string including
        the new ADR4 fields.
        the new ADR22 fields.
        """
        self._setup_subarray()
        self._assign_receptors()