Esempio n. 1
0
    def unarchive_trex(self):
        """  """

        CommandTemplateExecutor(
            self._cli_service,
            trex_common.CHANGE_PATH).execute_command(path=TREX_ROOT_PATH)

        output = CommandTemplateExecutor(
            self._cli_service,
            trex_common.FILE_INFO).execute_command(file_path=TREX_PACK_NAME)

        if "gzip" in output.lower():
            command = trex_common.UNTAR_GZ_PACKAGE._command.format(
                trex_package=TREX_PACK_NAME)
        elif "tar" in output.lower():
            command = trex_common.UNTAR_PACKAGE._command.format(
                trex_package=TREX_PACK_NAME)
        # elif "Zip" in output:
        #     pass
        else:
            raise Exception(self.__class__.__name__,
                            "Can't determine TRex Package format")

        output = self._cli_service.send_command(
            command=command,
            action_map=trex_common.UNTAR_PACKAGE._action_map,
            error_map=trex_common.UNTAR_PACKAGE._error_map,
            remove_command_from_output=False)

        if re.search(r"error|fail", output, re.IGNORECASE | re.DOTALL):
            raise Exception(self.__class__.__name__,
                            "Un-tar TRex package failed : {}".format(output))

        trex_folder = ""
        for line in output.split("\n"):
            line = line.strip()
            if line and line != command:
                trex_folder = line
                break

        if not trex_folder:
            raise Exception(self.__class__.__name__,
                            "Can't determine root TRex package folder")

        CommandTemplateExecutor(self._cli_service,
                                trex_common.CREATE_SIM_LINK).execute_command(
                                    source_path=trex_folder,
                                    link_name=TREX_FOLDER)
    def download_file(self, test_config_url):
        """ Download file from FTP/TFTP Server """

        try:
            test_files_location = self._trex_client.get_trex_files_path()
        except Exception as e:
            self._logger.exception(e)
            raise Exception(
                "Error happened during determination TRex files location")

        output = CommandTemplateExecutor(
            self._cli_service,
            FILE_INFO).execute_command(file_path=test_files_location)

        if "no such file or directory" in output.lower():
            CommandTemplateExecutor(
                self._cli_service,
                MAKE_DIRECTORY).execute_command(path=test_files_location)

        file_name = os.path.basename(test_config_url)
        output = CommandTemplateExecutor(
            self._cli_service, DOWNLOAD_FILE_TO_TREX).execute_command(
                file_path=os.path.join(test_files_location, file_name),
                url=test_config_url)

        if not re.search(r"saved\s*\[\d+\]", output, re.IGNORECASE):
            self._logger.error(
                "Downloading TRex test configuration file failed: {}".format(
                    output))
            raise Exception("Downloading TRex test configuration file failed.")
Esempio n. 3
0
 def _validate_port(self, logical_port_id):
     output = CommandTemplateExecutor(
         self._cli_service,
         command_template.IS_ENABLED).execute_command(port=logical_port_id)
     if '{}:on'.format(logical_port_id) in output.lower():
         return
     raise Exception('Port {} is disabled'.format(logical_port_id))
Esempio n. 4
0
    def get_sub_interfaces_config(self,
                                  port_name,
                                  action_map=None,
                                  error_map=None):
        """Retrieve current interface configuration.

        :param port_name:
        :param action_map: actions will be taken during executing commands,
            i.e. handles yes/no prompts
        :param error_map: errors will be raised during executing commands,
            i.e. handles Invalid Commands errors
        :return: str
        """
        result = CommandTemplateExecutor(
            self._cli_service,
            iface.SHOW_RUNNING_SUB_INTERFACES,
            action_map=action_map,
            error_map=error_map,
            remove_prompt=True,
        ).execute_command(port_name=port_name)

        return [
            x.replace(" ", "").replace("interface", "")
            for x in result.lower().split("\n")
            if x.strip(" ").startswith("interface")
        ]
    def does_interface_support_qnq(self,
                                   port_name,
                                   action_map=None,
                                   error_map=None):
        """ Validate whether qnq is supported for certain port """

        CommandTemplateExecutor(
            cli_service=self._cli_service,
            command_template=iface_command_template.CONFIGURE_IFACE,
            action_map=action_map,
            error_map=error_map).execute_command(port_name=port_name)

        output = CommandTemplateExecutor(
            cli_service=self._cli_service,
            command_template=iface_command_template.GET_TAG_PROFILE,
            action_map=action_map,
            error_map=error_map).execute_command()

        self._cli_service.send_line("end", self._logger)

        if 'enable' in output.lower():
            return True

        return False