Beispiel #1
0
    def open(self, timeout=None, test=None):
        if timeout is None:
            timeout = self.timeout
        self.child = self.spawn(self.command)
        self.child.timeout(timeout)
        self.child.eol("\r")

        if test is None:
            test = current()

        if self.test is not test:
            self.test = test
            self.child.logger(self.test.message_io(self.name))

        if self.new_prompt and getattr(self.commands, "change_prompt", None):
            self.child.expect(self.prompt)

            change_prompt_command = self.commands.change_prompt.format(
                self.new_prompt)

            self.child.send(change_prompt_command)
            self.child.expect(re.escape(change_prompt_command))
            self.child.expect("\n")

            self.prompt = self.new_prompt
Beispiel #2
0
def getuid():
    if current().subtype == TestSubType.Example:
        testname = (
            f"{basename(parentname(current().name)).replace(' ', '_').replace(',','')}"
        )
    else:
        testname = f"{basename(current().name).replace(' ', '_').replace(',','')}"
    return testname + "_" + str(uuid.uuid1()).replace("-", "_")
Beispiel #3
0
    def expect(self, *args, **kwargs):
        test = kwargs.pop("test", None)

        if test is None:
            test = current()

        if self.child is None:
            self.open()

        if self.test is not test:
            self.test = test
            self.child.logger(self.test.message_io(self.name))

        return self.child.expect(*args, **kwargs)
Beispiel #4
0
    def readlines(self, timeout=None, test=None):
        """Return currently available output.
        """
        if test is None:
            test = current()

        if timeout is None:
            timeout = self.timeout

        if self.app.test is not test:
            self.app.test = test
            self.app.child.logger(self.app.test.message_io(self.name))

        output = ""
        pattern = f"({self.app.prompt})|(\n)"

        while True:
            raised_timeout = False

            try:
                match = self.app.child.expect(pattern, timeout=timeout)
                # prompt
                if match.groups()[0]:
                    output += self.app.child.before
                    self.exitcode = self.get_exitcode()
                    self.app.child.send("\r", eol="")
                    self.app.child.expect("\n")
                    break
                # new line
                elif match.groups()[1]:
                    output += self.app.child.before + self.app.child.after

            except ExpectTimeoutError:
                output = self.app.child.before \
                    if output is None \
                    else (output + (self.app.child.before or ''))
                break

        output = output.rstrip().replace("\r", "")

        if output and self.parser:
            self.values = self.parser.parse(output)

        if self.output is None:
            self.output = ""

        self.output += output
        return output
Beispiel #5
0
    def send(self, *args, **kwargs):
        command = kwargs.pop("command", None)

        if self.child is None:
            self.open()

        if command is not None:
            test = kwargs.pop("test", None)
            if test is None:
                test = current()

            if self.test is not test:
                self.test = test
                self.child.logger(self.test.message_io(self.name))

            return self._send_command(*args, **kwargs)

        return self.child.send(*args, **kwargs)
Beispiel #6
0
    def __call__(self,
                 command,
                 timeout=None,
                 total=None,
                 parser=None,
                 asynchronous=False,
                 asyncronous=False,
                 test=None,
                 name=None):
        """Execute shell command.

        :param command: command to execute
        :param timeout: time to wait for the next line of output
        :param total: time to wait for the command to complete
            and return to the prompt, default: None (no limit)
        :param parser: output parser
        :param asynchronous: asynchronous command, default: None (not async)
        :param test: caller test
        """
        if test is None:
            test = current()

        if timeout is None:
            timeout = self.timeout

        if self.child is None:
            self.open(timeout)

        if self.test is not test:
            self.test = test

        if asyncronous or asynchronous:
            return AsyncCommand(self,
                                command=command,
                                timeout=None,
                                parser=parser,
                                name=name)

        return Command(self,
                       command=command,
                       timeout=timeout,
                       total=total,
                       parser=parser,
                       name=name)
Beispiel #7
0
    return yaml.safe_load(
        open(os.path.join(current_dir, test_file), "r")
    )["spec"]["templates"]["podTemplates"][0]["spec"]["containers"][0]["image"]


def get_docker_compose_path():
    caller_dir = os.path.dirname(
        os.path.abspath(inspect.currentframe().f_back.f_globals["__file__"]))
    docker_compose_project_dir = os.path.join(caller_dir, "../docker-compose")
    docker_compose_file_path = os.path.join(docker_compose_project_dir,
                                            "docker-compose.yml")
    return docker_compose_file_path, docker_compose_project_dir


kubectl_cmd = "kubectl" \
    if current().context.native \
    else f"docker-compose -f {get_docker_compose_path()[0]} exec runner kubectl"
test_namespace = os.getenv('TEST_NAMESPACE') \
    if 'TEST_NAMESPACE' in os.environ \
    else "test"
operator_version = os.getenv('OPERATOR_VERSION') \
    if 'OPERATOR_VERSION' in os.environ \
    else open(os.path.join(pathlib.Path(__file__).parent.absolute(), "../../release")).read(1024).strip(" \r\n\t")
operator_namespace = os.getenv('OPERATOR_NAMESPACE') \
    if 'OPERATOR_NAMESPACE' in os.environ \
    else 'kube-system'
operator_install = os.getenv('OPERATOR_INSTALL') \
    if 'OPERATOR_INSTALL' in os.environ \
    else 'yes'
minio_namespace = os.getenv('MINIO_NAMESPACE') \
    if 'MINIO_NAMESPACE' in os.environ \
Beispiel #8
0
def get_full_path(test_file, lookup_in_host=True):
    # this must be substituted if ran in docker
    if current().context.native or lookup_in_host:
        return os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), test_file))
    else:
        return os.path.abspath(f"/home/master/clickhouse-operator/tests/e2e/{test_file}")