Esempio n. 1
0
def test_ccsds_packet_interface_import_ccsds_header_types_class_attributes():
    """
    Test import_ccsds_header_types function:
    check whether class methods (is_command/get_function_code/get_msg_id) are implemented
    Dynamically imports the appropriate CCSDS primary header, command, and telemetry types from the location given
    in the config value 'CCSDS_header_path' and if found, returns them in a tuple.
    """
    headers_path = "./plugins/ccsds_plugin/cfe/ccsds_v2/ccsds_v2.py"
    sys.path.append(os.path.dirname(headers_path))
    headers_module = importlib.import_module(
        os.path.basename(headers_path).replace(".py", ""))

    ccsds_telemetry = getattr(sys.modules['ccsds_v2'], "CcsdsTelemetry")
    setattr(ccsds_telemetry, 'get_msg_id', None)
    assert import_ccsds_header_types() is None

    ccsds_command = getattr(sys.modules['ccsds_v2'], "CcsdsCommand")
    setattr(ccsds_command, 'get_function_code', None)
    assert import_ccsds_header_types() is None

    ccsds_primary_header = getattr(sys.modules['ccsds_v2'],
                                   "CcsdsPrimaryHeader")
    print("in test ccsds_primary_header=", ccsds_primary_header)
    setattr(ccsds_primary_header, 'is_command', None)
    assert import_ccsds_header_types() is None

    # restore class attributes
    importlib.reload(headers_module)
    assert import_ccsds_header_types() is not None
Esempio n. 2
0
def test_ccsds_packet_interface_import_ccsds_header_types_exception():
    """
    Test import_ccsds_header_types function: raise exception
    Dynamically imports the appropriate CCSDS primary header, command, and telemetry types from the location given
    in the config value 'CCSDS_header_path' and if found, returns them in a tuple.
    """
    with patch("os.path.exists", return_value=False):
        assert import_ccsds_header_types() is None

    with pytest.raises(CtfTestError):
        with patch("importlib.import_module") as mock_import_module:
            mock_import_module.side_effect = CtfTestError(
                "Raise import_module exception for unit test")
            assert import_ccsds_header_types() is None
Esempio n. 3
0
    def initialize(self):
        log.debug("Initializing CfsController")
        self.process_ccsds_files()

        ccsds = import_ccsds_header_types()
        if not (ccsds and ccsds.CcsdsPrimaryHeader and ccsds.CcsdsCommand
                and ccsds.CcsdsTelemetry):
            log.error("Unable to import required CCSDS header types")
            return False

        log.info("Starting Local CFS Interface")
        command = CommandInterface(ccsds, self.config.cmd_udp_port,
                                   self.config.cfs_target_ip,
                                   self.config.endianess_of_target)
        telemetry = TlmListener(self.config.ctf_ip, self.config.tlm_udp_port)
        self.cfs = LocalCfsInterface(self.config, telemetry, command,
                                     self.mid_map, ccsds)
        result = self.cfs.init_passed
        if not result:
            log.error("Failed to initialize LocalCfsInterface")
        else:
            if self.config.start_cfs_on_init and not self.cfs_running:
                result = self.start_cfs("")
            else:
                log.warn(
                    "Not starting CFS executable... Expecting \"StartCfs\" in test script..."
                )

        if result:
            log.info("CfsController Initialized")
        return result
Esempio n. 4
0
    def process_ccsds_files(self):
        """
        Create mid map for CFS plugin, if map does not exist, create ccsds_reader from INIT config file.
        """
        result = True
        if self.mid_map is None:
            log.info("Creating MID Map from CCDD Data at {}".format(
                self.config.ccsds_data_dir))
            self.ccsds_reader = CCDDExportReader(self.config)
            self.mid_map, self.macro_map = self.ccsds_reader.get_ccsds_messages_from_dir(
                self.config.ccsds_data_dir)
        else:
            log.debug("MID Map is already populated; skipping CCDD Data...")

        try:
            self.ccsds = import_ccsds_header_types()
        except CtfTestError:
            self.ccsds = None
            log.warning("Error importing CCSDS header types")

        if not (self.ccsds and self.ccsds.CcsdsPrimaryHeader
                and self.ccsds.CcsdsCommand and self.ccsds.CcsdsTelemetry):
            log.error("Unable to load required CCSDS data types")
            result = False

        return result
Esempio n. 5
0
def test_ccsds_packet_interface_import_ccsds_header_types():
    """
    Test import_ccsds_header_types function
    Dynamically imports the appropriate CCSDS primary header, command, and telemetry types from the location given
    in the config value 'CCSDS_header_path' and if found, returns them in a tuple.
    """
    header_types = import_ccsds_header_types()
    assert len(header_types) == 3
    assert header_types[0].__name__ == 'CcsdsV2PrimaryHeader'
    assert header_types[1].__name__ == 'CcsdsV2CmdPacket'
    assert header_types[2].__name__ == 'CcsdsV2TlmPacket'
Esempio n. 6
0
def test_ccsds_packet_interface_import_ccsds_header_types_module_attributes():
    """
    Test import_ccsds_header_types function: check missing module attributes
    Dynamically imports the appropriate CCSDS primary header, command, and telemetry types from the location given
    in the config value 'CCSDS_header_path' and if found, returns them in a tuple.
    """
    headers_path = "./plugins/ccsds_plugin/cfe/ccsds_v2/ccsds_v2.py"
    sys.path.append(os.path.dirname(headers_path))
    headers_module = importlib.import_module(
        os.path.basename(headers_path).replace(".py", ""))
    # test case: if headers_module does not have required attributes, return None
    del headers_module.CcsdsTelemetry
    assert import_ccsds_header_types() is None
    del headers_module.CcsdsCommand
    assert import_ccsds_header_types() is None
    del headers_module.CcsdsPrimaryHeader
    assert import_ccsds_header_types() is None

    # restore class attributes
    importlib.reload(headers_module)
    assert len(import_ccsds_header_types()) == 3
Esempio n. 7
0
        def initialize(self):
            log.debug("Initializing SP0CfsController")
            self.process_ccsds_files()

            ccsds = import_ccsds_header_types()
            if not (ccsds and ccsds.CcsdsPrimaryHeader and ccsds.CcsdsCommand
                    and ccsds.CcsdsTelemetry):
                log.error("Unable to import required CCSDS header types")
                return False

            log.info("Starting SP0 CFS Interface")
            result = self.sp0_plugin = Global.plugin_manager.find_plugin_for_command(
                "SP0_Register")
            if not result:
                log.error("Failed to connect to SP0 plugin.")
            else:
                result = self.sp0_plugin.sp0_register_from_config(
                    self.config.name, self.config)
                if not result:
                    log.error("Failed SP0 Configuration.")
                else:
                    command = CommandInterface(ccsds, self.config.cmd_udp_port,
                                               self.config.cfs_target_ip)
                    telemetry = TlmListener(self.config.ctf_ip,
                                            self.config.tlm_udp_port)
                    self.cfs = SP0CfsInterface(self.config, telemetry, command,
                                               self.mid_map, ccsds,
                                               self.sp0_plugin)
                    result = self.cfs.init_passed
                    if not result:
                        log.error("Failed to initialize SP0CfsInterface")
                    elif self.config.start_cfs_on_init and not self.cfs_running:
                        result = self.start_cfs("")
                    else:
                        log.warn(
                            "Not starting CFS executable... Expecting \"StartCfs\" in test script..."
                        )

            if result:
                log.info("SP0CfsController Initialized")
            return result