Commit 5482dab1 authored by Elisabetta Giani's avatar Elisabetta Giani
Browse files

AT5-262: Removed some minor bugs.

parent 347dd961
Loading
Loading
Loading
Loading
+19 −25
Original line number Diff line number Diff line
@@ -125,18 +125,18 @@ class CspMaster(with_metaclass(DeviceMeta, SKAMaster)):
            try:
                if dev_name in self._se_fqdn:
                    if evt.attr_value.name.lower() == "state":
                        print("{}: received event on {} value {}".format(dev_name,
                        self.logger.debug("{}: received event on {} value {}".format(dev_name,
                                                                         evt.attr_value.name,
                                                                         evt.attr_value.value))
                        self._se_state[dev_name] = evt.attr_value.value
                        
                    elif evt.attr_value.name.lower() == "healthstate":
                        print("{}: received event on {} value {}".format(dev_name,
                        self.logger.debug("{}: received event on {} value {}".format(dev_name,
                                                                         evt.attr_value.name,
                                                                         evt.attr_value.value))
                        self._se_health_state[dev_name] = evt.attr_value.value
                    elif evt.attr_value.name.lower() == "adminmode":
                        print("device: {} adminMode value {}".format(dev_name,evt.attr_value.value ))
                        self.logger.debug("device: {} adminMode value {}".format(dev_name,evt.attr_value.value ))
                        self._se_admin_mode[dev_name] = evt.attr_value.value
                    else:
                        log_msg = ("Attribute {} not still "
@@ -437,16 +437,13 @@ class CspMaster(with_metaclass(DeviceMeta, SKAMaster)):
        #TODO: order the list alphabetically so that the CBF is always the first element to start
        # the TANGO command to execute
        tango_cmd_name = 0
        # the command progress attribute to check subscription         
        cmd_progress_attr = 0
        # the sub-element device state after successful transition
        dev_successful_state = 0
        try:
            tango_cmd_name = args_dict['cmd_name']
            cmd_progress_attr = args_dict['attr_name']
            dev_successful_state = args_dict['dev_state']
        except KeyError as key_err:
            print("No key: {}".format(str(key_err)))
            self.logger.warn("No key: {}".format(str(key_err)))
            # reset the CSP and sub-element running flags
            self._cmd_execution_state = CmdExecState.IDLE
            for device in device_list:
@@ -456,14 +453,14 @@ class CspMaster(with_metaclass(DeviceMeta, SKAMaster)):
        # tango_cmd_name: is the TANGO command name with the capital letter
        # In the dictionary keys, is generally used the command name in lower letters
        cmd_name = tango_cmd_name.lower()
        print("cmd_name: {} attr_name: {} dev_state: {}".format(cmd_name, 
                                                              cmd_progress_attr,
        self.logger.debug("cmd_name: {} dev_state: {}".format(cmd_name,
                                                  dev_successful_state))
        num_of_failed_device = 0
        self._num_dev_completed_task[cmd_name] = 0
        self._list_dev_completed_task[cmd_name] = []
        self._cmd_progress[cmd_name] = 0
        self._cmd_duration_measured[cmd_name] = 0
        self._alarm_message[cmd_name] = ''
        # sub-element command execution measured time
        se_cmd_duration_measured = defaultdict(lambda:defaultdict(lambda:0))
        # loop on the devices and power-on them sequentially
@@ -472,10 +469,10 @@ class CspMaster(with_metaclass(DeviceMeta, SKAMaster)):
            self._se_cmd_execution_state[device][cmd_name] = CmdExecState.RUNNING
            se_cmd_duration_measured[device][cmd_name] = 0
            self._se_cmd_progress[device][cmd_name] = 0
            self._alarm_message[cmd_name] = ''
            
            try:
                device_proxy = self._se_proxies[device] 
                print("Issue asynch command {} on device {}:".format(cmd_name, device))
                self.logger.debug("Issue asynch command {} on device {}:".format(cmd_name, device))
               
                # Note: when the command ends on the sub-element, the _cmd_ended_cb callback
                # is called. This callback sets the sub-element execution state to FAULT if
@@ -491,7 +488,7 @@ class CspMaster(with_metaclass(DeviceMeta, SKAMaster)):
                # register the starting time for the command
                self._se_cmd_starting_time[device] = time.time() 
                # loop on the device until the State changes to ON or a timeout occurred
                print("Device {} State {} expected value {}".format(device, self._se_state[device], dev_successful_state))
                self.logger.debug("Device {} State {} expected value {}".format(device, self._se_state[device], dev_successful_state))
                command_progress = self._cmd_progress[cmd_name]
                while True:
                    if self._se_state[device] == dev_successful_state:
@@ -504,9 +501,7 @@ class CspMaster(with_metaclass(DeviceMeta, SKAMaster)):
                        # reset the value of the attribute reporting the execution state of
                        # the command
                        self._se_cmd_execution_state[device][cmd_name] = CmdExecState.IDLE
                        se_cmd_duration_measured[device][cmd_name] = (time.time() 
                                                                      - self._se_cmd_starting_time[device])
                        self.logger.info("measured duration:", se_cmd_duration_measured[device][cmd_name])
                        
                        self._se_cmd_progress[device][cmd_name] = 100
                        # command success: exit from the wait loop and issue the command
                        # on the next device in the list
@@ -514,8 +509,8 @@ class CspMaster(with_metaclass(DeviceMeta, SKAMaster)):
                    # check for other sub-element device State values
                    if self._se_state[device] in [tango.DevState.FAULT, tango.DevState.ALARM]:
                        self._se_cmd_execution_state[device][cmd_name] = CmdExecState.FAILED
                        self._alarm_message[device] = ("Device {} is {}".format(device, self.get_status()))
                        self.logger.warn(self._alarm_message[device]) 
                        self._alarm_message[cmd_name] += ("Device {} is {}".format(device, self.get_status()))
                        self.logger.warn(self._alarm_message[cmd_name]) 
                        num_of_failed_device += 1
                        break
                    # check if sub-element command ended throwing an exception: in this case the
@@ -542,13 +537,12 @@ class CspMaster(with_metaclass(DeviceMeta, SKAMaster)):
                    if (elapsed_time > self._se_cmd_duration_expected[device][cmd_name] or
                        self._se_cmd_execution_state[device][cmd_name] == CmdExecState.TIMEOUT):
                        msg = ("Timeout executing {} command  on device {}".format(cmd_name, device))
                        print(msg)
                        self.logger.warn(msg)
                        self._se_cmd_execution_state[device][cmd_name] = CmdExecState.TIMEOUT       
                        num_of_failed_device += 1
                        # if the CBF command timeout expires, the CSP power-on is stopped
                        # TODO: verify if this behavior conflicts with ICD
                        print("elapsed_time:{} device {}".format(elapsed_time, device))
                        self.logger.debug("elapsed_time:{} device {}".format(elapsed_time, device))
                        if device == self.CspCbf:
                            self.logger.error("CBF Timeout during power-on!!! Exit")
                            self._timeout_expired[cmd_name] = True
@@ -564,6 +558,9 @@ class CspMaster(with_metaclass(DeviceMeta, SKAMaster)):
                    self._cmd_progress[cmd_name] = command_progress + self._se_cmd_progress[device][cmd_name]/len(device_list)
                # end of the while loop
                # calculate the real execution time for the command
                se_cmd_duration_measured[device][cmd_name] = (time.time() 
                                                                      - self._se_cmd_starting_time[device])
                self.logger.info("measured duration:{}".format(se_cmd_duration_measured[device][cmd_name]))
                self._cmd_duration_measured[cmd_name] += se_cmd_duration_measured[device][cmd_name]
                # update the progress counter at the end of the loop 
                self._cmd_progress[cmd_name] = command_progress + (self._se_cmd_progress[device][cmd_name]/len(device_list))
@@ -1755,15 +1752,13 @@ class CspMaster(with_metaclass(DeviceMeta, SKAMaster)):
        # are passed as arguments of the function
        # args: the list of sub-element FQDNS
        # args_dict: dictionary with the specific command information
        print("Send command to device", device_list)
        args_dict = {'cmd_name':'On', 'attr_name': 'onCommandProgress', 'dev_state': tango.DevState.ON}
        args_dict = {'cmd_name':'On', 'dev_state': tango.DevState.ON}
        self._command_thread['on'] = threading.Thread(target=self._issue_power_command, name="Thread-On",
                                               args=(device_list,),
                                               kwargs=args_dict)
        # set the  CSP command execution running flag
        self._cmd_execution_state['on'] = CmdExecState.RUNNING
        # start the thread
        print("starting thread")
        self._command_thread['on'].start()
        # sleep for a while to let the thread start
        time.sleep(0.2)
@@ -1831,7 +1826,6 @@ class CspMaster(with_metaclass(DeviceMeta, SKAMaster)):
        # args: the list of sub-element FQDNS
        # args_dict: dictionary with the specific command information
        args_dict = {'cmd_name':'Off',
                     'attr_name': 'offCommandProgress',
                     'dev_state': tango.DevState.ON}
       
        self._command_thread['off'] = threading.Thread(target=self._issue_power_command, name="Thread-Off",
@@ -1902,7 +1896,7 @@ class CspMaster(with_metaclass(DeviceMeta, SKAMaster)):
        # cmd_name : the TANGO command name to execute
        # attr_name: the corresponding command progress attribute to subscribe
        # dev_state: the expected finale state for the device transition
        args_dict = {'cmd_name':"Standby", 'attr_name':'standbyCommandProgress',
        args_dict = {'cmd_name':'Standby',
                     'dev_state':tango.DevState.STANDBY}
        # invoke the constructor for the command thread
        self._command_thread['standby'] = threading.Thread(target=self._issue_power_command,
+1 −1
Original line number Diff line number Diff line
@@ -177,7 +177,7 @@ class CmdInputArgsCheck(object):
            # check for devices that are not ONLINE/MAINTENANCE                    
            device_to_remove = []
            for device in device_list:
                self.logger.debug("CmdInputArgsCheack-processing device:", device)
                dev_instance.logger.debug("CmdInputArgsCheack-processing device:", device)
                # if the sub-element device server is not running or the adminMode
                # attribute is not ONLINE or MAINTENANCE:
                # - schedule the device for removing from the input arg list