Loading csp-lmc-common/.gitlab-ci.yml +8 −3 Original line number Diff line number Diff line Loading @@ -59,7 +59,7 @@ build:csp-lmc-common_image: # .test_common: image: nexus.engageska-portugal.pt/ska-docker/tango-builder:latest image: nexus.engageska-portugal.pt/ska-docker/ska-python-buildenv:latest before_script: - docker login -u $DOCKER_REGISTRY_USERNAME -p $DOCKER_REGISTRY_PASSWORD $DOCKER_REGISTRY_HOST tags: Loading @@ -68,14 +68,19 @@ build:csp-lmc-common_image: paths: - ./$COMMON_BUILD_PATH/build/ variables: COMMON_BUILD_PATH: csp-lmc-common/docker COMMON_BUILD_PATH: csp-lmc-common test:csp-lmc-common: extends: .test_common stage: test_common script: - cd $COMMON_BUILD_PATH - make test - python3 -m pip install -r requirements.txt -r requirements-tst.txt - python3 setup.py test |tee setup_py_test.stdout - mkdir -p /build/reports - mv /app/setup_py_test.stdout /build/csp-lmc-common-setup-test.stdout - mv /app/htmlcov /build/csp-lmc-common_htmlcov - mv /app/coverage.xml /build # # linting stage .linting_common: Loading csp-lmc-common/conftest.pydeleted 100644 → 0 +0 −87 Original line number Diff line number Diff line """ A module defining a list of fixture functions. """ import importlib import pytest import tango from unittest import mock from tango import DeviceProxy from tango.test_context import DeviceTestContext @pytest.fixture(scope="class") def tango_context(request): """Creates and returns a TANGO DeviceTestContext object. Parameters ---------- request: _pytest.fixtures.SubRequest A request object gives access to the requesting test context. """ test_properties = { 'CspMaster': {'SkaLevel': '2', 'CspCbf': 'mid_csp_cbf/sub_elt/master', 'CspPss': 'mid_csp_pss/sub_elt/master', 'CspPst': 'mid_csp_pst/sub_elt/master', }, 'CspSubarray': {'CspMaster': 'common/elt/master', 'CbfSubarray': 'mid_csp_cbf/sub_elt/subarray_01', 'PssSubarray': 'mid_csp_pss/sub_elt/subarray_01', 'SubID' : 1, }, } # TODO: package_name and class_name can be used in future # fq_test_class_name = request.cls.__module__ # fq_test_class_name_details = fq_test_class_name.split(".") # package_name = fq_test_class_name_details[1] # class_name = module_name = fq_test_class_name_details[1] test_class_name = request.cls.__name__ class_name = test_class_name.split('Test', 1)[-1] module = importlib.import_module("{}.{}".format("csp_lmc_common", class_name)) klass = getattr(module, class_name) tango_context = DeviceTestContext(klass, properties=test_properties.get(class_name)) tango_context.start() yield tango_context tango_context.stop() # # NOTE: if initialize_device is called, the tests crash with error because during the # CspMaster and CspMaster access to the TANGO DB to get the memorized attributes. # Need to mock the call to the TANGO DB get_device_attribute @pytest.fixture(scope="function") def initialize_device(tango_context): """Re-initializes the device. Parameters ---------- tango_context: tango.test_context.DeviceTestContext Context to run a device without a database. """ yield tango_context.device.Init() @pytest.fixture(scope="class") def cbf_master(): """Create DeviceProxy for the CbfMaster device to test the device with the TANGO DB """ database = tango.Database() instance_list = database.get_device_exported_for_class('CbfMaster') for instance in instance_list.value_string: try: return tango.DeviceProxy(instance) except tango.DevFailed: continue @pytest.fixture(scope="class") def csp_master(): """Create DeviceProxy for the CspMaster device to test the device with the TANGO DB """ database = tango.Database() instance_list = database.get_device_exported_for_class('CspMaster') for instance in instance_list.value_string: try: return tango.DeviceProxy(instance) except tango.DevFailed: continue csp-lmc-common/csp_lmc_common/CspMaster.py +28 −18 Original line number Diff line number Diff line Loading @@ -37,9 +37,12 @@ from ska.base import SKAMaster from ska.base import utils from ska.base.commands import ResultCode from ska.base.control_model import HealthState, AdminMode, ObsState, LoggingLevel from .utils.decorators import AdminModeCheck, CmdInputArgsCheck from .utils.cspcommons import CmdExecState from . import release #from .utils.decorators import AdminModeCheck, CmdInputArgsCheck #from .utils.cspcommons import CmdExecState #from . import release from csp_lmc_common.utils.decorators import AdminModeCheck, CmdInputArgsCheck from csp_lmc_common.utils.cspcommons import CmdExecState from csp_lmc_common import release # PROTECTED REGION END# //CspMaster.additional_import __all__ = ["CspMaster", "main"] Loading Loading @@ -322,6 +325,11 @@ class CspMaster(SKAMaster): self._health_state = self._se_health_state[self.CspCbf] return def _open_connection(self, fqdn): device_proxy = DeviceProxy(fqdn) self.logger.info("device_proxy: {}".format(device_proxy)) return device_proxy def _connect_to_subelements (self): """ Class method. Loading @@ -335,7 +343,8 @@ class CspMaster(SKAMaster): # DeviceProxy to sub-elements log_msg = "Trying connection to" + str(fqdn) + " device" self.logger.info(log_msg) device_proxy = DeviceProxy(fqdn) device_proxy = self._open_connection(fqdn) #device_proxy = tango.DeviceProxy(fqdn) #device_proxy.ping() # Note: ping() method is not called. The DeviceProxy is initialized even if the # sub-element is not running (but defined into the TANGO DB!). Loading Loading @@ -1212,12 +1221,12 @@ class CspMaster(SKAMaster): self._build_state = '{}, {}, {}'.format(release.name, release.version, release.description) self._version_id = release.version # connect to TANGO DB csp_tango_db = tango.Database() #csp_tango_db = tango.Database() # read the CSP memorized attributes from the TANGO DB. # Note: a memorized attribute has defined the attribute # property '__value' attribute_properties = csp_tango_db.get_device_attribute_property(self.get_name(), {'adminMode': ['__value']}) #attribute_properties = csp_tango_db.get_device_attribute_property(self.get_name(), # {'adminMode': ['__value']}) # set init values for the CSP Element and Sub-element SCM states self.set_state(tango.DevState.INIT) self._health_state = HealthState.OK Loading @@ -1233,16 +1242,16 @@ class CspMaster(SKAMaster): # build a dictionary with the (attr_name, value) of the memorized attributes # use memorized atrtibute if present, otherwise the default one memorized_attr_dict = {attr_name : int(value[0]) for attr_name, db_key in attribute_properties.items() for key, value in db_key.items() if key == '__value'} try: self._admin_mode = memorized_attr_dict['adminMode'] if self._admin_mode not in [AdminMode.ONLINE, AdminMode.MAINTENANCE]: self._health_state = HealthState.UNKNOWN self.set_state(tango.DevState.DISABLE) except KeyError as key_err: self.logger.info("Key {} not found".format(key_err)) #memorized_attr_dict = {attr_name : int(value[0]) for attr_name, db_key in attribute_properties.items() # for key, value in db_key.items() # if key == '__value'} #try: # self._admin_mode = memorized_attr_dict['adminMode'] # if self._admin_mode not in [AdminMode.ONLINE, AdminMode.MAINTENANCE]: # self._health_state = HealthState.UNKNOWN # self.set_state(tango.DevState.DISABLE) #except KeyError as key_err: # self.logger.info("Key {} not found".format(key_err)) # initialize list with CSP sub-element FQDNs self._se_fqdn = [] Loading @@ -1260,6 +1269,7 @@ class CspMaster(SKAMaster): # read the sub-elements adminMode (memorized) attributes from # the TANGO DB. # Note: a memorized attribute has defined the attribute property '__value' ''' for fqdn in self._se_fqdn: attribute_properties = csp_tango_db.get_device_attribute_property(fqdn, {'adminMode': ['__value']}) Loading @@ -1271,7 +1281,7 @@ class CspMaster(SKAMaster): msg = ("No key {} found for sub-element {}" " adminMode attribute".format(key_err, fqdn)) self.logger.info(msg) ''' # _se_proxies: the sub-element proxies # implemented as dictionary: # keys: sub-element FQDN Loading csp-lmc-common/csp_lmc_common/CspSubarray.py +22 −22 Original line number Diff line number Diff line Loading @@ -156,25 +156,25 @@ class CspSubarray(SKASubarray): device._sc_subarray_obs_state = defaultdict(lambda: ObsState.IDLE) device._sc_subarray_obs_mode = defaultdict(lambda: ObsMode.IDLE) device._mutex_obs_state = threading.Lock() device._csp_tango_db = tango.Database() #device._csp_tango_db = tango.Database() # read the CSP memorized attributes from the TANGO DB. # Note: a memorized attribute has defined the attribute # property '__value' attribute_properties = device._csp_tango_db.get_device_attribute_property(device.get_name(), {'adminMode': ['__value']}) #attribute_properties = device._csp_tango_db.get_device_attribute_property(device.get_name(), # {'adminMode': ['__value']}) # build a dictionary with the (attr_name, value) of the memorized attributes # use memorized atrtibute if present, otherwise the default one memorized_attr_dict = {attr_name : int(value[0]) for attr_name, db_key in attribute_properties.items() for key, value in db_key.items() if key == '__value'} try: device._admin_mode = memorized_attr_dict['adminMode'] if device._admin_mode not in [AdminMode.ONLINE, AdminMode.MAINTENANCE]: device._health_state = HealthState.UNKNOWN device.set_state(tango.DevState.DISABLE) except KeyError as key_err: device.logger.info("Key {} not found".format(key_err)) #memorized_attr_dict = {attr_name : int(value[0]) for attr_name, db_key in attribute_properties.items() # for key, value in db_key.items() # if key == '__value'} #try: # device._admin_mode = memorized_attr_dict['adminMode'] # if device._admin_mode not in [AdminMode.ONLINE, AdminMode.MAINTENANCE]: # device._health_state = HealthState.UNKNOWN # device.set_state(tango.DevState.DISABLE) # # except KeyError as key_err: # device.logger.info("Key {} not found".format(key_err)) # list of sub-array sub-component FQDNs device._sc_subarray_fqdn = [] Loading Loading @@ -1653,14 +1653,14 @@ class CspSubarray(SKASubarray): return # read the sub-componet adminMode (memorized) attribute from # the CSP.LMC TANGO DB. attribute_properties = self._csp_tango_db.get_device_attribute_property(fqdn, {'adminMode': ['__value']}) self.logger.debug("fqdn: {} attribute_properties: {}".format(fqdn, attribute_properties)) try: admin_mode_memorized = attribute_properties['adminMode']['__value'] self._sc_subarray_admin_mode[fqdn] = int(admin_mode_memorized[0]) except KeyError as key_error: self.logger.warning("No key {} found".format(str(key_error))) #attribute_properties = self._csp_tango_db.get_device_attribute_property(fqdn, # {'adminMode': ['__value']}) #self.logger.debug("fqdn: {} attribute_properties: {}".format(fqdn, attribute_properties)) #try: # admin_mode_memorized = attribute_properties['adminMode']['__value'] # self._sc_subarray_admin_mode[fqdn] = int(admin_mode_memorized[0]) #except KeyError as key_error: # self.logger.warning("No key {} found".format(str(key_error))) try: log_msg = "Trying connection to " + str(fqdn) + " device" self.logger.info(log_msg) Loading csp-lmc-common/csp_lmc_common/__init__.py +8 −0 Original line number Diff line number Diff line __all__ = [ "CspMaster", "CspSubarray", ] from .CspMaster import CspMaster from .CspSubarray import CspSubarray Loading
csp-lmc-common/.gitlab-ci.yml +8 −3 Original line number Diff line number Diff line Loading @@ -59,7 +59,7 @@ build:csp-lmc-common_image: # .test_common: image: nexus.engageska-portugal.pt/ska-docker/tango-builder:latest image: nexus.engageska-portugal.pt/ska-docker/ska-python-buildenv:latest before_script: - docker login -u $DOCKER_REGISTRY_USERNAME -p $DOCKER_REGISTRY_PASSWORD $DOCKER_REGISTRY_HOST tags: Loading @@ -68,14 +68,19 @@ build:csp-lmc-common_image: paths: - ./$COMMON_BUILD_PATH/build/ variables: COMMON_BUILD_PATH: csp-lmc-common/docker COMMON_BUILD_PATH: csp-lmc-common test:csp-lmc-common: extends: .test_common stage: test_common script: - cd $COMMON_BUILD_PATH - make test - python3 -m pip install -r requirements.txt -r requirements-tst.txt - python3 setup.py test |tee setup_py_test.stdout - mkdir -p /build/reports - mv /app/setup_py_test.stdout /build/csp-lmc-common-setup-test.stdout - mv /app/htmlcov /build/csp-lmc-common_htmlcov - mv /app/coverage.xml /build # # linting stage .linting_common: Loading
csp-lmc-common/conftest.pydeleted 100644 → 0 +0 −87 Original line number Diff line number Diff line """ A module defining a list of fixture functions. """ import importlib import pytest import tango from unittest import mock from tango import DeviceProxy from tango.test_context import DeviceTestContext @pytest.fixture(scope="class") def tango_context(request): """Creates and returns a TANGO DeviceTestContext object. Parameters ---------- request: _pytest.fixtures.SubRequest A request object gives access to the requesting test context. """ test_properties = { 'CspMaster': {'SkaLevel': '2', 'CspCbf': 'mid_csp_cbf/sub_elt/master', 'CspPss': 'mid_csp_pss/sub_elt/master', 'CspPst': 'mid_csp_pst/sub_elt/master', }, 'CspSubarray': {'CspMaster': 'common/elt/master', 'CbfSubarray': 'mid_csp_cbf/sub_elt/subarray_01', 'PssSubarray': 'mid_csp_pss/sub_elt/subarray_01', 'SubID' : 1, }, } # TODO: package_name and class_name can be used in future # fq_test_class_name = request.cls.__module__ # fq_test_class_name_details = fq_test_class_name.split(".") # package_name = fq_test_class_name_details[1] # class_name = module_name = fq_test_class_name_details[1] test_class_name = request.cls.__name__ class_name = test_class_name.split('Test', 1)[-1] module = importlib.import_module("{}.{}".format("csp_lmc_common", class_name)) klass = getattr(module, class_name) tango_context = DeviceTestContext(klass, properties=test_properties.get(class_name)) tango_context.start() yield tango_context tango_context.stop() # # NOTE: if initialize_device is called, the tests crash with error because during the # CspMaster and CspMaster access to the TANGO DB to get the memorized attributes. # Need to mock the call to the TANGO DB get_device_attribute @pytest.fixture(scope="function") def initialize_device(tango_context): """Re-initializes the device. Parameters ---------- tango_context: tango.test_context.DeviceTestContext Context to run a device without a database. """ yield tango_context.device.Init() @pytest.fixture(scope="class") def cbf_master(): """Create DeviceProxy for the CbfMaster device to test the device with the TANGO DB """ database = tango.Database() instance_list = database.get_device_exported_for_class('CbfMaster') for instance in instance_list.value_string: try: return tango.DeviceProxy(instance) except tango.DevFailed: continue @pytest.fixture(scope="class") def csp_master(): """Create DeviceProxy for the CspMaster device to test the device with the TANGO DB """ database = tango.Database() instance_list = database.get_device_exported_for_class('CspMaster') for instance in instance_list.value_string: try: return tango.DeviceProxy(instance) except tango.DevFailed: continue
csp-lmc-common/csp_lmc_common/CspMaster.py +28 −18 Original line number Diff line number Diff line Loading @@ -37,9 +37,12 @@ from ska.base import SKAMaster from ska.base import utils from ska.base.commands import ResultCode from ska.base.control_model import HealthState, AdminMode, ObsState, LoggingLevel from .utils.decorators import AdminModeCheck, CmdInputArgsCheck from .utils.cspcommons import CmdExecState from . import release #from .utils.decorators import AdminModeCheck, CmdInputArgsCheck #from .utils.cspcommons import CmdExecState #from . import release from csp_lmc_common.utils.decorators import AdminModeCheck, CmdInputArgsCheck from csp_lmc_common.utils.cspcommons import CmdExecState from csp_lmc_common import release # PROTECTED REGION END# //CspMaster.additional_import __all__ = ["CspMaster", "main"] Loading Loading @@ -322,6 +325,11 @@ class CspMaster(SKAMaster): self._health_state = self._se_health_state[self.CspCbf] return def _open_connection(self, fqdn): device_proxy = DeviceProxy(fqdn) self.logger.info("device_proxy: {}".format(device_proxy)) return device_proxy def _connect_to_subelements (self): """ Class method. Loading @@ -335,7 +343,8 @@ class CspMaster(SKAMaster): # DeviceProxy to sub-elements log_msg = "Trying connection to" + str(fqdn) + " device" self.logger.info(log_msg) device_proxy = DeviceProxy(fqdn) device_proxy = self._open_connection(fqdn) #device_proxy = tango.DeviceProxy(fqdn) #device_proxy.ping() # Note: ping() method is not called. The DeviceProxy is initialized even if the # sub-element is not running (but defined into the TANGO DB!). Loading Loading @@ -1212,12 +1221,12 @@ class CspMaster(SKAMaster): self._build_state = '{}, {}, {}'.format(release.name, release.version, release.description) self._version_id = release.version # connect to TANGO DB csp_tango_db = tango.Database() #csp_tango_db = tango.Database() # read the CSP memorized attributes from the TANGO DB. # Note: a memorized attribute has defined the attribute # property '__value' attribute_properties = csp_tango_db.get_device_attribute_property(self.get_name(), {'adminMode': ['__value']}) #attribute_properties = csp_tango_db.get_device_attribute_property(self.get_name(), # {'adminMode': ['__value']}) # set init values for the CSP Element and Sub-element SCM states self.set_state(tango.DevState.INIT) self._health_state = HealthState.OK Loading @@ -1233,16 +1242,16 @@ class CspMaster(SKAMaster): # build a dictionary with the (attr_name, value) of the memorized attributes # use memorized atrtibute if present, otherwise the default one memorized_attr_dict = {attr_name : int(value[0]) for attr_name, db_key in attribute_properties.items() for key, value in db_key.items() if key == '__value'} try: self._admin_mode = memorized_attr_dict['adminMode'] if self._admin_mode not in [AdminMode.ONLINE, AdminMode.MAINTENANCE]: self._health_state = HealthState.UNKNOWN self.set_state(tango.DevState.DISABLE) except KeyError as key_err: self.logger.info("Key {} not found".format(key_err)) #memorized_attr_dict = {attr_name : int(value[0]) for attr_name, db_key in attribute_properties.items() # for key, value in db_key.items() # if key == '__value'} #try: # self._admin_mode = memorized_attr_dict['adminMode'] # if self._admin_mode not in [AdminMode.ONLINE, AdminMode.MAINTENANCE]: # self._health_state = HealthState.UNKNOWN # self.set_state(tango.DevState.DISABLE) #except KeyError as key_err: # self.logger.info("Key {} not found".format(key_err)) # initialize list with CSP sub-element FQDNs self._se_fqdn = [] Loading @@ -1260,6 +1269,7 @@ class CspMaster(SKAMaster): # read the sub-elements adminMode (memorized) attributes from # the TANGO DB. # Note: a memorized attribute has defined the attribute property '__value' ''' for fqdn in self._se_fqdn: attribute_properties = csp_tango_db.get_device_attribute_property(fqdn, {'adminMode': ['__value']}) Loading @@ -1271,7 +1281,7 @@ class CspMaster(SKAMaster): msg = ("No key {} found for sub-element {}" " adminMode attribute".format(key_err, fqdn)) self.logger.info(msg) ''' # _se_proxies: the sub-element proxies # implemented as dictionary: # keys: sub-element FQDN Loading
csp-lmc-common/csp_lmc_common/CspSubarray.py +22 −22 Original line number Diff line number Diff line Loading @@ -156,25 +156,25 @@ class CspSubarray(SKASubarray): device._sc_subarray_obs_state = defaultdict(lambda: ObsState.IDLE) device._sc_subarray_obs_mode = defaultdict(lambda: ObsMode.IDLE) device._mutex_obs_state = threading.Lock() device._csp_tango_db = tango.Database() #device._csp_tango_db = tango.Database() # read the CSP memorized attributes from the TANGO DB. # Note: a memorized attribute has defined the attribute # property '__value' attribute_properties = device._csp_tango_db.get_device_attribute_property(device.get_name(), {'adminMode': ['__value']}) #attribute_properties = device._csp_tango_db.get_device_attribute_property(device.get_name(), # {'adminMode': ['__value']}) # build a dictionary with the (attr_name, value) of the memorized attributes # use memorized atrtibute if present, otherwise the default one memorized_attr_dict = {attr_name : int(value[0]) for attr_name, db_key in attribute_properties.items() for key, value in db_key.items() if key == '__value'} try: device._admin_mode = memorized_attr_dict['adminMode'] if device._admin_mode not in [AdminMode.ONLINE, AdminMode.MAINTENANCE]: device._health_state = HealthState.UNKNOWN device.set_state(tango.DevState.DISABLE) except KeyError as key_err: device.logger.info("Key {} not found".format(key_err)) #memorized_attr_dict = {attr_name : int(value[0]) for attr_name, db_key in attribute_properties.items() # for key, value in db_key.items() # if key == '__value'} #try: # device._admin_mode = memorized_attr_dict['adminMode'] # if device._admin_mode not in [AdminMode.ONLINE, AdminMode.MAINTENANCE]: # device._health_state = HealthState.UNKNOWN # device.set_state(tango.DevState.DISABLE) # # except KeyError as key_err: # device.logger.info("Key {} not found".format(key_err)) # list of sub-array sub-component FQDNs device._sc_subarray_fqdn = [] Loading Loading @@ -1653,14 +1653,14 @@ class CspSubarray(SKASubarray): return # read the sub-componet adminMode (memorized) attribute from # the CSP.LMC TANGO DB. attribute_properties = self._csp_tango_db.get_device_attribute_property(fqdn, {'adminMode': ['__value']}) self.logger.debug("fqdn: {} attribute_properties: {}".format(fqdn, attribute_properties)) try: admin_mode_memorized = attribute_properties['adminMode']['__value'] self._sc_subarray_admin_mode[fqdn] = int(admin_mode_memorized[0]) except KeyError as key_error: self.logger.warning("No key {} found".format(str(key_error))) #attribute_properties = self._csp_tango_db.get_device_attribute_property(fqdn, # {'adminMode': ['__value']}) #self.logger.debug("fqdn: {} attribute_properties: {}".format(fqdn, attribute_properties)) #try: # admin_mode_memorized = attribute_properties['adminMode']['__value'] # self._sc_subarray_admin_mode[fqdn] = int(admin_mode_memorized[0]) #except KeyError as key_error: # self.logger.warning("No key {} found".format(str(key_error))) try: log_msg = "Trying connection to " + str(fqdn) + " device" self.logger.info(log_msg) Loading
csp-lmc-common/csp_lmc_common/__init__.py +8 −0 Original line number Diff line number Diff line __all__ = [ "CspMaster", "CspSubarray", ] from .CspMaster import CspMaster from .CspSubarray import CspSubarray