def __init__(self, context):
        from vcttesting.docker import Docker, params_from_env
        from vcttesting.hgmo import HgCluster

        if 'HGMO_STATE_FILE' not in os.environ:
            print('Do not know where to store state.')
            print(
                'Set the HGMO_STATE_FILE environment variable and try again.')
            sys.exit(1)

        if 'DOCKER_STATE_FILE' not in os.environ:
            print('Do not where to store Docker state.')
            print(
                'Set the DOCKER_STATE_FILE environment variable and try again.'
            )
            sys.exit(1)

        docker_url, tls = params_from_env(os.environ)
        docker = Docker(os.environ['DOCKER_STATE_FILE'], docker_url, tls=tls)
        if not docker.is_alive():
            print('Docker not available')
            sys.exit(1)
        self.c = HgCluster(
            docker,
            os.environ['HGMO_STATE_FILE'],
            ldap_image=os.environ.get('DOCKER_LDAP_IMAGE'),
            master_image=os.environ.get('DOCKER_HGMASTER_IMAGE'),
            web_image=os.environ.get('DOCKER_HGWEB_IMAGE'),
            pulse_image=os.environ.get('DOCKER_PULSE_IMAGE'))
Пример #2
0
def has_docker():
    if 'SKIP_DOCKER_TESTS' in os.environ:
        return False

    from vcttesting.docker import Docker, params_from_env

    url, tls = params_from_env(os.environ)

    tf = tempfile.NamedTemporaryFile()
    tf.close()
    d = Docker(tf.name, url, tls=tls)
    return d.is_alive()
Пример #3
0
    def __init__(self, context):
        from vcttesting.docker import Docker, params_from_env
        from vcttesting.hgmo import HgCluster

        if 'DOCKER_STATE_FILE' not in os.environ:
            print('Do not where to store Docker state.')
            print('Set the DOCKER_STATE_FILE environment variable and try again.')
            sys.exit(1)

        docker_url, tls = params_from_env(os.environ)
        docker = Docker(os.environ['DOCKER_STATE_FILE'], docker_url, tls=tls)
        if not docker.is_alive():
            print('Docker not available')
            sys.exit(1)
        self.c = HgCluster(docker)
Пример #4
0
    def __init__(self, context):
        if 'DOCKER_STATE_FILE' in os.environ:
            state_file = os.environ['DOCKER_STATE_FILE']

        # When running from Mercurial tests, use a per-test state file.
        # We can't use HGTMP because it is shared across many tests. We
        # use HGRCPATH as a base, since it is in a test-specific directory.
        elif 'HGRCPATH' in os.environ:
            state_file = os.path.join(os.path.dirname(os.environ['HGRCPATH']),
                                      '.dockerstate')
        else:
            state_file = os.path.join(ROOT, '.dockerstate')

        docker_url, tls = params_from_env(os.environ)
        d = Docker(state_file, docker_url, tls=tls)

        if not d.is_alive():
            print('Docker is not available!')
            sys.exit(1)

        self.d = d
Пример #5
0
    def __init__(self,
                 path,
                 web_image=None,
                 hgrb_image=None,
                 ldap_image=None,
                 pulse_image=None,
                 rbweb_image=None,
                 autolanddb_image=None,
                 autoland_image=None,
                 hgweb_image=None,
                 treestatus_image=None):
        if not path:
            raise Exception('You must specify a path to create an instance')
        path = os.path.abspath(path)
        self._path = path

        self.started = False

        self.web_image = web_image
        self.hgrb_image = hgrb_image
        self.ldap_image = ldap_image
        self.pulse_image = pulse_image
        self.rbweb_image = rbweb_image
        self.autolanddb_image = autolanddb_image
        self.autoland_image = autoland_image
        self.hgweb_image = hgweb_image
        self.treestatus_image = treestatus_image

        self._name = os.path.dirname(path)

        if not os.path.exists(path):
            os.mkdir(path)

        keys_path = os.path.join(path, 'keys')
        try:
            os.mkdir(keys_path)
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise

        credentials_path = os.path.join(path, 'credentials')
        try:
            os.mkdir(credentials_path)
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise

        self._state_path = os.path.join(path, 'state.json')

        docker_state = os.path.join(path, '.dockerstate')

        self._docker_state = docker_state

        self.bugzilla_username = None
        self.bugzilla_password = None
        self.docker_env = {}

        if os.path.exists(self._state_path):
            with open(self._state_path, 'rb') as fh:
                state = json.load(fh)

                for k, v in state.items():
                    setattr(self, k, v)

        # Preserve Docker settings from last time.
        #
        # This was introduced to make watchman happy, as its triggers may not
        # inherit environment variables.
        for k, v in self.docker_env.items():
            os.environ[k] = v

        docker_url, tls = params_from_env(os.environ)
        self._docker = Docker(docker_state, docker_url, tls=tls)

        if not self._docker.is_alive():
            raise DockerNotAvailable('Docker is not available.')