Exemplo n.º 1
0
    def __init__(self, builddir, serveddir, logtofile):
        """
        Start a local git server.

        In order to support test cases in parallel, select the port the
        server will listen to in runtime. Since there is no reliable way
        to allocate the port prior to starting the server (another
        process in the host machine can use the port between it is
        selected from a list and it is really allocated to the server)
        try to start the server in a port and in the case it is already
        in use, try the next one in the allowed range.
        """
        self.daemon = None
        self.port = None
        self.logfile = infra.open_log_file(builddir, "gitremote", logtofile)

        daemon_cmd = ["git", "daemon", "--reuseaddr", "--verbose",
                      "--listen=localhost", "--export-all",
                      "--base-path={}".format(serveddir)]
        for port in range(GIT_REMOTE_PORT_INITIAL, GIT_REMOTE_PORT_LAST + 1):
            cmd = daemon_cmd + ["--port={port}".format(port=port)]
            self.logfile.write("> starting git remote with '{}'\n".format(" ".join(cmd)))
            self.daemon = pexpect.spawn(cmd[0], cmd[1:], logfile=self.logfile)
            ret = self.daemon.expect(["Ready to rumble",
                                      "Address already in use"])
            if ret == 0:
                self.port = port
                return
        raise SystemError("Could not find a free port to run git remote")
Exemplo n.º 2
0
    def __init__(self, builddir, serveddir, logtofile):
        """
        Start a local git server.

        In order to support test cases in parallel, select the port the
        server will listen to in runtime. Since there is no reliable way
        to allocate the port prior to starting the server (another
        process in the host machine can use the port between it is
        selected from a list and it is really allocated to the server)
        try to start the server in a port and in the case it is already
        in use, try the next one in the allowed range.
        """
        self.daemon = None
        self.port = None
        self.logfile = infra.open_log_file(builddir, "gitremote", logtofile)

        daemon_cmd = [
            "git", "daemon", "--reuseaddr", "--verbose", "--listen=localhost",
            "--export-all", "--base-path={}".format(serveddir)
        ]
        for port in range(GIT_REMOTE_PORT_INITIAL, GIT_REMOTE_PORT_LAST + 1):
            cmd = daemon_cmd + ["--port={port}".format(port=port)]
            self.logfile.write("> starting git remote with '{}'\n".format(
                " ".join(cmd)))
            self.daemon = pexpect.spawn(cmd[0],
                                        cmd[1:],
                                        logfile=self.logfile,
                                        encoding='utf-8')
            ret = self.daemon.expect(
                ["Ready to rumble", "Address already in use"])
            if ret == 0:
                self.port = port
                return
        raise SystemError("Could not find a free port to run git remote")
Exemplo n.º 3
0
 def __init__(self, builddir, downloaddir, logtofile, timeout_multiplier):
     self.qemu = None
     self.downloaddir = downloaddir
     self.logfile = infra.open_log_file(builddir, "run", logtofile)
     # We use elastic runners on the cloud to runs our tests. Those runners
     # can take a long time to run the emulator. Use a timeout multiplier
     # when running the tests to avoid sporadic failures.
     self.timeout_multiplier = timeout_multiplier
Exemplo n.º 4
0
 def __init__(self, builddir, downloaddir, logtofile, timeout_multiplier):
     self.qemu = None
     self.downloaddir = downloaddir
     self.logfile = infra.open_log_file(builddir, "run", logtofile)
     # We use elastic runners on the cloud to runs our tests. Those runners
     # can take a long time to run the emulator. Use a timeout multiplier
     # when running the tests to avoid sporadic failures.
     self.timeout_multiplier = timeout_multiplier
Exemplo n.º 5
0
    def __init__(self, builddir, logtofile):
        """
        Start an OpenSSH SSH Daemon

        In order to support test cases in parallel, select the port the
        server will listen to in runtime. Since there is no reliable way
        to allocate the port prior to starting the server (another
        process in the host machine can use the port between it is
        selected from a list and it is really allocated to the server)
        try to start the server in a port and in the case it is already
        in use, try the next one in the allowed range.
        """
        self.daemon = None
        self.port = None

        self.logfile = infra.open_log_file(builddir, "sshd", logtofile)

        server_keyfile = os.path.join(builddir, SSHD_KEY)
        auth_keys_file = os.path.join(builddir, SSH_AUTH_KEYS_FILE)
        daemon_cmd = [SSHD_PATH,
                      "-D",  # or use -ddd to debug
                      "-e",
                      "-h", server_keyfile,
                      "-f", "/dev/null",
                      "-o", "ListenAddress=localhost",
                      "-o", "PidFile=none",
                      "-o", "AuthenticationMethods=publickey",
                      "-o", "StrictModes=no",
                      "-o", "Subsystem=sftp internal-sftp",
                      "-o", "AuthorizedKeysFile={}".format(auth_keys_file)]
        for port in range(SSHD_PORT_INITIAL, SSHD_PORT_LAST + 1):
            cmd = daemon_cmd + ["-p", "{}".format(port)]
            self.logfile.write(
                "> starting sshd with '{}'\n".format(" ".join(cmd)))
            try:
                self.daemon = pexpect.spawn(cmd[0], cmd[1:], logfile=self.logfile,
                                            encoding='utf-8')
            except pexpect.exceptions.ExceptionPexpect as e:
                self.logfile.write("> {} - skipping\n".format(e))
                raise SkipTest(str(e))

            ret = self.daemon.expect([
                # Success
                "Server listening on .* port {}.".format(port),
                # Failure
                "Cannot bind any address."])
            if ret == 0:
                self.port = port
                return
        raise SystemError("Could not find a free port to run sshd")
Exemplo n.º 6
0
 def __init__(self, config, builddir, logtofile):
     self.config = '\n'.join(
         [line.lstrip() for line in config.splitlines()]) + '\n'
     self.builddir = builddir
     self.logfile = infra.open_log_file(builddir, "build", logtofile)
Exemplo n.º 7
0
 def __init__(self, config, builddir, logtofile):
     self.config = '\n'.join([line.lstrip() for line in
                              config.splitlines()]) + '\n'
     self.builddir = builddir
     self.logfile = infra.open_log_file(builddir, "build", logtofile)
Exemplo n.º 8
0
 def __init__(self, config, builddir, logtofile):
     self.config = config
     self.builddir = builddir
     self.logfile = infra.open_log_file(builddir, "build", logtofile)
Exemplo n.º 9
0
 def __init__(self, builddir, downloaddir, logtofile):
     self.qemu = None
     self.downloaddir = downloaddir
     self.logfile = infra.open_log_file(builddir, "run", logtofile)
Exemplo n.º 10
0
 def __init__(self, builddir, downloaddir, logtofile):
     self.qemu = None
     self.downloaddir = downloaddir
     self.logfile = infra.open_log_file(builddir, "run", logtofile)
Exemplo n.º 11
0
def generate_keys(builddir, logtofile):
    logfile = infra.open_log_file(builddir, "ssh-keygen", logtofile)
    generate_keys_server(builddir, logfile)
    generate_keys_client(builddir, logfile)
Exemplo n.º 12
0
 def __init__(self, config, builddir, logtofile):
     self.config = config
     self.builddir = builddir
     self.logfile = infra.open_log_file(builddir, "build", logtofile)