Commit e61b5520 authored by Elisabetta Giani's avatar Elisabetta Giani
Browse files

Merge branch 'master' into CT-60

parents 54923a20 3f01bac0
Loading
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
0.6.0
- start implementing lmcbaseclasses 0.6.0
0.5.12

- push event on obsState
- set subarray to CONFIGURING at Configure command reception
- modified __configure_scan thread to catch the CbfSubarray CONFIGURING
  obsState 

0.5.11
- call to DeviceProxy instead of tango.DeviceProxy to have the deviceemocking works
+145 −36
Original line number Diff line number Diff line
@@ -990,6 +990,10 @@ class CspSubarray(SKASubarray):
            return True
        return False
    
    def _push_event_on_obs_state(self,value):
        self._obs_state = value
        self.push_change_event("obsState", self._obs_state)
    
    # ----------------
    # Class private methods
    # ----------------
@@ -1102,7 +1106,6 @@ class CspSubarray(SKASubarray):
        device_done = defaultdict(lambda:False)
        # inside the end-less lop check the obsState of each sub-component
        device_list = input_arg[0]
        self.logger.info("device_list:{}".format(device_list))
        while True:
            command_progress = 0
            for device in device_list:
@@ -1113,22 +1116,8 @@ class CspSubarray(SKASubarray):
                # if the sub-component execution flag is no more RUNNING, the command has
                # ended with or without success. Go to check next device state.
                if self._sc_subarray_obs_state[device] == dev_successful_state:
                    # !!! bad hack:
                    # if the sub-element subarray state is already READY, sleep for a while to wait
                    # sub-element moves  to CONFIGURING.
                    # TODO:
                    # - wait for all sub-elements subarrays move to CONFIGURING, handling possible
                    #   error/timeout conditions
                    # - when in CONFIGURING, wait for sub-elements subarrays to move to READY
                    #   handling error conditions

                    # check the time elapsed from the command start, if less then 0.1 sleep for a while
                    elapsed_time = time.time() - self._sc_subarray_cmd_starting_time[device]
                    if elapsed_time < 0.1:
                        self.logger.info("Device {} already in READY state after {} sec".format(device,
                                         elapsed_time))
                        time.sleep(0.3)
                        continue
                    self.logger.info("Reconfiguring is:{}".format(self._reconfiguring))
                    if not self._reconfiguring:
                        self.logger.info("Command {} ended with success on device {}.".format(cmd_name,
                                                                                                  device))
                        # update the list and number of device that completed the task
@@ -1170,8 +1159,10 @@ class CspSubarray(SKASubarray):
                self.logger.debug("Command {} on device {} exec_state {}:".format(cmd_name,device,
                                                                   self._sc_subarray_cmd_exec_state[device][cmd_name]))
            self._cmd_progress[cmd_name] = command_progress
            if all(self._sc_subarray_obs_state[device] == ObsState.CONFIGURING for device in device_list):
                self._obs_state = ObsState.CONFIGURING
            if any(self._sc_subarray_obs_state[device] == ObsState.CONFIGURING for device in device_list):
                #self._obs_state = ObsState.CONFIGURING
                self._reconfiguring = False
                self.logger.info("Reconfiguring is:{}".format(self._reconfiguring))
                self.logger.info("Current CspSubarray ObsState:{}".format(self._obs_state))
            if all(value == True for value in device_done.values()):
                self.logger.info("All devices have been handled!")
@@ -1188,7 +1179,7 @@ class CspSubarray(SKASubarray):
                break
            # TODO:
            # check for abort request.
            time.sleep(0.2)
            time.sleep(0.1)
        # end of the while loop
        # check for timeout/failure conditions on each sub-component
        for device in device_list:
@@ -1202,18 +1193,18 @@ class CspSubarray(SKASubarray):
        if self._timeout_expired or self._failure_raised:
            # if failure/timeout found check if the CBF subarray is configured. In
            # this case the CSP.LMC Subarray obsState is set to READY.
            if self._sc_subarray_obs_state[self.CbfSubarray] == ObsState.READY:
                self._obs_state = ObsState.READY
            self._push_event_on_obs_state(self._sc_subarray_obs_state[self.CbfSubarray])
            #TODO:
            # else:...
            # self.set_state(tango.DevState.FAULT)
            # 

        if all(self._sc_subarray_obs_state[fqdn] == dev_successful_state for fqdn in device_list):
            self._obs_state = dev_successful_state
            self._push_event_on_obs_state(ObsState.READY)
            self._valid_scan_configuration = input_arg[1]
            self._cmd_duration_measured[cmd_name] = time.time() - command_start_time
            self._cmd_progress[cmd_name] = 100
        else:
            self._push_event_on_obs_state(ObsState.IDLE)
        self._last_executed_command = cmd_name
        self.logger.info("CspSubarray failure flag:{}".format(self._failure_raised))
        self.logger.info("CspSubarray timeout flag:{}".format(self._timeout_expired))
@@ -2368,7 +2359,125 @@ class CspSubarray(SKASubarray):
            is caught during command execution.
        """
        # PROTECTED REGION ID(CspSubarray.Configure) ENABLED START #
        # checks on State, adminMode and obsState values are performed inside the 
        # python decorators
       
        # the dictionary with the scan configuration
        try:
            # if the stored configuration attribute is not empty, check
            # for the received configuration content
            if self._valid_scan_configuration:
                try:
                    stored_configuration = json.dumps(self._valid_scan_configuration, sort_keys=True)
                    received_configuration = json.dumps(argin, sort_keys=True)
                    # if the received configuration is equal to the last valid configuration and the
                    # state of the subarray is READY than subarray is not re-configured.
                    if (stored_configuration == received_configuration) and (self._obs_state == ObsState.READY):
                        self.logger.info("Subarray is going to use the same configuration")
                        return
                except Exception as e:
                    self.logger.warning(str(e))
            # go ahead and parse the received configuration
            self.validate_scan_configuration(argin)
        except tango.DevFailed as tango_err:
            # validation failure
            msg = "Failure during validation of configuration:{}".format(tango_err.args[0].desc)
            self.logger.error(msg)
            tango.Except.throw_exception("Command failed",
                                         msg,
                                         "Configure",
                                         tango.ErrSeverity.ERR)
        self._reconfiguring = False
        if self._obs_state == ObsState.READY:
            self._reconfiguring = True
        # Forward the Configure command to the sub-elements
        # components (subarrays, pst beams)
        for device in self._sc_subarray_assigned_fqdn:
            # reset the command progress counter for each
            # sub-array component
            self._sc_subarray_cmd_progress[device]['configurescan'] = 0
            self._failure_message['configurescan'] = ''
            # NOTE: what happens if a sub-element subarray/PSt beam TANGO
            # device is not running? The next calls to proxy should fail
            # with a tango.DevFailed exception.
            if not self._is_sc_subarray_running(device):
                msg = "Device {} not running".format(device)
                if device == self.CbfSubarray:
                    # throw the exception, configuration can't proceed
                    tango.Except.throw_exception("Command failed",
                                                 msg,
                                                 "Configure",
                                                 tango.ErrSeverity.ERR)
                self._failure_message['configurescan'] += msg
                self._sc_subarray_cmd_exec_state[device]['configurescan'] = CmdExecState.FAILED
                #skip to next device
                continue
            proxy = self._sc_subarray_proxies[device]
            # subscribe sub-elements attributes to track command execution and
            # timeout on subarray sub-components
            attributes = ['configureScanCmdProgress', 'timeoutExpiredFlag']
            for attr in attributes:
                try:
                    if self._sc_subarray_event_id[attr.lower()] == 0:
                        event_id = proxy.subscribe_event(attr,
                                                         tango.EventType.CHANGE_EVENT,
                                                         self._attributes_change_evt_cb,
                                                         stateless=False)
                        self._sc_subarray_event_id[device][attr] = event_id
                except tango.DevFailed as df:
                    self.logger.info(df.args[0].desc)              
            # NOTE: CBF/PSS sub-array checks for the validity of its
            # configuration. Failure in configuration throws an exception that is
            # caught via the _cmd_ended_cb callback

            try:
                # read the timeout configured for the operation on the device
                self._sc_subarray_duration_expected[device]['configurescan'] = proxy.configureDelayExpected
            except AttributeError as attr_err:
                self.logger.info("No attribute {} on device {}".format(str(attr_err), device))
            try:
                proxy.command_inout_asynch("ConfigureScan",
                                           self._sc_subarray_scan_configuration[device],
                                           self._cmd_ended_cb)
                self.logger.info("Exec state command flag is {}".format(self._sc_subarray_cmd_exec_state[device]['configurescan']))
                # Note: check if callaback executed...
                if self._sc_subarray_cmd_exec_state[device]['configurescan'] != CmdExecState.FAILED:
                    self._sc_subarray_cmd_exec_state[device]['configurescan'] = CmdExecState.RUNNING
                    self._push_event_on_obs_state(ObsState.CONFIGURING)
            except tango.DevFailed as tango_err:
                if device == self.CbfSubarray:
                    msg = "Failure in configuring CBF: {}".format(tango_err.args[0].desc)
                    # throw the exception, configuration can't proceed
                    self._obs_state = ObsState.IDLE
                    self.push_change_event("obsState", self._obs_state)
                    tango.Except.throw_exception("Command failed",
                                                 msg,
                                                 "Configure",
                                                 tango.ErrSeverity.ERR)

                self._failure_message['configurescan'] += tango_err.args[0].desc
                self._sc_subarray_cmd_exec_state[device]['configurescan'] = CmdExecState.FAILED

            # register the starting time for the command
            self._sc_subarray_cmd_starting_time[device] = time.time()
            self.logger.debug("configure starting time: {}".format(self._sc_subarray_cmd_starting_time[device]))
        # end for loop on devices

        # TODO: evaluate the global timeout as the max of the single sub-element
        # timeouts
        # configure the timeout for the operation
        if self._config_delay_expected > 0:
            self._cmd_duration_expected['configurescan'] = self._config_delay_expected
        self.logger.debug("_config_delay_expected :{}".format(self._config_delay_expected))
        # invoke the constructor for the command thread
        thread_args = [self._sc_subarray_assigned_fqdn, argin]
        self._command_thread['configurescan'] = threading.Thread(target=self.__configure_scan,
                                                           name="Thread-Configure",
                                                           args=(thread_args,))
        self._abort_command_event.clear()
        self._cmd_execution_state['configurescan'] = CmdExecState.RUNNING
        self._cmd_duration_measured['configurescan'] = 0
        self._command_thread['configurescan'].start()
        # PROTECTED REGION END #    //  CspSubarray.Configure
    
    @AdminModeCheck('AddNumOfSearchBeams')
+1 −1
Original line number Diff line number Diff line
@@ -18,5 +18,5 @@ license = """BSD-3-Clause"""
url = """www.tango-controls.org"""
copyright = """"""

release=0.5.11
release=0.6.0
tag=csp-lmc-common-0.6.0
+9 −9
Original line number Diff line number Diff line
@@ -288,7 +288,7 @@
                                "mid_csp_cbf/pssconfig/02"
                            ],
                            "CorrConfigAddress": [
                                "mid_csp_cbf/corrconfig/01"
                                "mid_csp_cbf/corrconfig/02"
                            ],
                            "SubID": [
                                "2"
@@ -435,7 +435,7 @@
                                "state",
                                "1000",
                                "subarraymembership",
                                "1000"
                                "200"
                            ]
                        }
                    }
@@ -600,7 +600,7 @@
                                "state",
                                "1000",
                                "subarraymembership",
                                "1000"
                                "200"
                            ]
                        }
                    }
@@ -765,7 +765,7 @@
                                "state",
                                "1000",
                                "subarraymembership",
                                "1000"
                                "200"
                            ]
                        }
                    }
@@ -930,7 +930,7 @@
                                "state",
                                "1000",
                                "subarraymembership",
                                "1000"
                                "200"
                            ]
                        }
                    }
@@ -1109,7 +1109,7 @@
                                "adminmode",
                                "1000",
                                "subarraymembership",
                                "1000"
                                "200"
                            ]
                        }
                    }
@@ -1184,7 +1184,7 @@
                                "adminmode",
                                "1000",
                                "subarraymembership",
                                "1000"
                                "200"
                            ]
                        }
                    }
@@ -1259,7 +1259,7 @@
                                "adminmode",
                                "1000",
                                "subarraymembership",
                                "1000"
                                "200"
                            ]
                        }
                    }
@@ -1334,7 +1334,7 @@
                                "adminmode",
                                "1000",
                                "subarraymembership",
                                "1000"
                                "200"
                            ]
                        }
                    }
+13 −13
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ services:
      - .:/csplmc

  cbfmaster:
    image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/mid-cbf-mcs:0.4.1-7ec0bbf
    image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/mid-cbf-mcs:0.4.2-43db051
    network_mode: ${NETWORK_MODE}
    container_name: ${CONTAINER_NAME_PREFIX}cbfmaster
    depends_on:
@@ -53,7 +53,7 @@ services:


  cbfsubarray01:
    image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/mid-cbf-mcs:0.4.1-7ec0bbf
    image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/mid-cbf-mcs:0.4.2-43db051
    network_mode: ${NETWORK_MODE}
    container_name: ${CONTAINER_NAME_PREFIX}cbfsubarray01
    depends_on:
@@ -75,7 +75,7 @@ services:


  cbfsubarray02:
    image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/mid-cbf-mcs:0.4.1-7ec0bbf
    image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/mid-cbf-mcs:0.4.2-43db051
    network_mode: ${NETWORK_MODE}
    container_name: ${CONTAINER_NAME_PREFIX}cbfsubarray02
    depends_on:
@@ -97,7 +97,7 @@ services:


  vcc001:
    image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/mid-cbf-mcs:0.4.1-7ec0bbf
    image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/mid-cbf-mcs:0.4.2-43db051
    network_mode: ${NETWORK_MODE}
    container_name: ${CONTAINER_NAME_PREFIX}vcc001
    depends_on:
@@ -118,7 +118,7 @@ services:


  vcc002:
    image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/mid-cbf-mcs:0.4.1-7ec0bbf
    image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/mid-cbf-mcs:0.4.2-43db051
    network_mode: ${NETWORK_MODE}
    container_name: ${CONTAINER_NAME_PREFIX}vcc002
    depends_on:
@@ -139,7 +139,7 @@ services:


  vcc003:
    image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/mid-cbf-mcs:0.4.1-7ec0bbf
    image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/mid-cbf-mcs:0.4.2-43db051
    network_mode: ${NETWORK_MODE}
    container_name: ${CONTAINER_NAME_PREFIX}vcc003
    depends_on:
@@ -160,7 +160,7 @@ services:


  vcc004:
    image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/mid-cbf-mcs:0.4.1-7ec0bbf
    image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/mid-cbf-mcs:0.4.2-43db051
    network_mode: ${NETWORK_MODE}
    container_name: ${CONTAINER_NAME_PREFIX}vcc004
    depends_on:
@@ -181,7 +181,7 @@ services:


  fsp01:
    image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/mid-cbf-mcs:0.4.1-7ec0bbf
    image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/mid-cbf-mcs:0.4.2-43db051
    network_mode: ${NETWORK_MODE}
    container_name: ${CONTAINER_NAME_PREFIX}fsp01
    depends_on:
@@ -197,7 +197,7 @@ services:
      - rsyslog-cbf:rw

  fsp02:
    image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/mid-cbf-mcs:0.4.1-7ec0bbf
    image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/mid-cbf-mcs:0.4.2-43db051
    network_mode: ${NETWORK_MODE}
    container_name: ${CONTAINER_NAME_PREFIX}fsp02
    depends_on:
@@ -213,7 +213,7 @@ services:
      - rsyslog-cbf:rw

  fsp03:
    image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/mid-cbf-mcs:0.4.1-7ec0bbf
    image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/mid-cbf-mcs:0.4.2-43db051
    network_mode: ${NETWORK_MODE}
    container_name: ${CONTAINER_NAME_PREFIX}fsp03
    depends_on:
@@ -230,7 +230,7 @@ services:


  fsp04:
    image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/mid-cbf-mcs:0.4.1-7ec0bbf
    image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/mid-cbf-mcs:0.4.2-43db051
    network_mode: ${NETWORK_MODE}
    container_name: ${CONTAINER_NAME_PREFIX}fsp04
    depends_on:
@@ -247,7 +247,7 @@ services:


  tmcspsubarrayleafnodetest:
    image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/mid-cbf-mcs:0.4.1-7ec0bbf
    image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/mid-cbf-mcs:0.4.2-43db051
    network_mode: ${NETWORK_MODE}
    container_name: ${CONTAINER_NAME_PREFIX}tmcspsubarrayleafnodetest
    depends_on:
@@ -264,7 +264,7 @@ services:
      - rsyslog-cbf:rw

  tmcspsubarrayleafnodetest2:
    image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/mid-cbf-mcs:0.4.1-7ec0bbf
    image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/mid-cbf-mcs:0.4.2-43db051
    network_mode: ${NETWORK_MODE}
    container_name: ${CONTAINER_NAME_PREFIX}tmcspsubarrayleafnodetest2
    depends_on:
Loading