Ejemplo n.º 1
0
 def wait_for_cs_is_started(self):
     for _ in range(10):
         try:
             _ = self._api
         except (OSError, MaxRetryError):
             time.sleep(10)
         else:
             break
     else:
         logger.warning(f"CloudShell {self.conf.host} is not alive")
         raise CSIsNotAliveError
 def _store_extra_files(self):
     err_msg_smb_tmpl = (
         f"There are {{}} for a Shell {self.conf.name} but SMB Handler isn't set up"
     )
     if self._cs_smb_handler and self.conf.dependencies_path:
         self._cs_smb_handler.add_dependencies_to_offline_pypi(
             self.conf.dependencies_path)
     elif not self._cs_smb_handler and self.conf.dependencies_path:
         logger.warning(err_msg_smb_tmpl.format("dependecies file"))
     if self._cs_smb_handler and self.conf.extra_standards_paths:
         self._cs_smb_handler.add_extra_standards(
             self.conf.extra_standards_paths)
     elif not self._cs_smb_handler and self.conf.extra_standards_paths:
         logger.warning(err_msg_smb_tmpl.format("extra cs standards"))
def get_test_suite(stop_flag: Event, handler: ResourceHandler,
                   handler_storage: HandlerStorage) -> TestSuite:
    if handler.device_type == DeviceType.WITHOUT_DEVICE:
        logger.warning(
            f'"{handler.name}" is a fake device so test only installing env and trying '
            f"to execute commands and getting an expected error for connection"
        )
    elif handler.device_type == DeviceType.SIMULATOR:
        logger.warning(
            f'"{handler.name}" is a simulator, testing only an Autoload')

    test_suite = TestSuite()
    test_cases_map = TEST_CASES_MAP[handler.family][handler.device_type]

    if handler.family in AUTOLOAD_TEST_FOR_FAMILIES:
        test_cases = [test_cases_map.get("autoload")]
    else:
        test_cases = []

    for command in handler.get_commands():
        test_case = test_cases_map.get(command.lower())
        if isinstance(test_case, tuple):
            for optional_test_case in test_case:
                assert issubclass(optional_test_case, OptionalTestCase)
                if optional_test_case.is_suitable(handler, handler_storage):
                    tc = optional_test_case.test_case()
                    if tc not in test_cases:
                        test_cases.append(tc)
        elif test_case and test_case not in test_cases:
            if test_case not in test_cases:
                test_cases.append(test_case)

    for test_case in test_cases:
        for test_name in TestLoader().getTestCaseNames(test_case):
            test_inst = test_case(test_name, stop_flag, handler,
                                  handler_storage)
            test_suite.addTest(test_inst)

    return test_suite
    def download_logs(self, path_to_save: Path, start_time: datetime,
                      reservation_ids: set[str]):
        logger.info("Downloading CS logs")
        try:
            with suppress(FileNotFoundError):
                shutil.rmtree(path_to_save)
            path_to_save.mkdir()

            shell_logs_path = path_to_save / "shell_logs"
            installation_logs_path = path_to_save / "installation_logs"
            autoload_logs_path = shell_logs_path / "inventory"
            shell_logs_path.mkdir()
            installation_logs_path.mkdir()
            autoload_logs_path.mkdir()

            self._smb_handler.download_r_dir(
                self._CS_LOGS_INSTALLATION_DIR,
                installation_logs_path,
                FilterByLastWriteTime(start_time),
            )
            self._smb_handler.download_r_dir(
                self._CS_LOGS_SHELL_DIR,
                shell_logs_path,
                FilterByFileNameInIterable(reservation_ids),
            )
            self._smb_handler.download_r_dir(
                self._CS_LOGS_AUTOLOAD_DIR,
                autoload_logs_path,
                FilterByLastWriteTime(start_time),
            )
        except Exception as e:
            if "path not found" in str(e).lower():
                logger.info("Cannot find log dir")
            else:
                logger.warning(f"Cannot download logs, error: {e}")
        logger.debug("CS logs downloaded")
Ejemplo n.º 5
0
 def _delete_file(self, file_path: str):
     # todo find ability to delete file after TFTP
     logger.warning("We cannot delete files from TFTP server.")
 def _add_cs_standard_file_path(self, standard_path: Path):
     r_file_path = f"{self._CS_STANDARDS_PATH}{standard_path.name}"
     logger.warning(
         f"Adding a tosca standard {standard_path.name} to the CS")
     self._smb_handler.put_file_path(r_file_path, standard_path)