Exemple #1
0
    def _setup_static(self):
        """Configure CloudStack tests for use with static configuration."""
        parser = ConfigParser()
        parser.read(self.config_static_path)

        self.endpoint = parser.get('cloudstack', 'endpoint')

        parts = urlparse(self.endpoint)

        self.host = parts.hostname

        if not self.host:
            raise ApplicationError(
                'Could not determine host from endpoint: %s' % self.endpoint)

        if parts.port:
            self.port = parts.port
        elif parts.scheme == 'http':
            self.port = 80
        elif parts.scheme == 'https':
            self.port = 443
        else:
            raise ApplicationError(
                'Could not determine port from endpoint: %s' % self.endpoint)

        display.info('Read cs host "%s" and port %d from config: %s' %
                     (self.host, self.port, self.config_static_path),
                     verbosity=1)

        self._wait_for_service()
Exemple #2
0
    def parse(path):
        """
        :type path: str
        :rtype: TowerConfig
        """
        parser = ConfigParser()
        parser.read(path)

        keys = (
            'version',
            'host',
            'username',
            'password',
        )

        values = dict((k, parser.get('default', k)) for k in keys)
        config = TowerConfig(values)

        missing = [k for k in keys if not values.get(k)]

        if missing:
            raise ApplicationError(
                'Missing or empty Tower configuration value(s): %s' %
                ', '.join(missing))

        return config
Exemple #3
0
    def get_environment_config(self):
        """
        :rtype: CloudEnvironmentConfig
        """
        parser = ConfigParser()
        parser.read(self.config_path)

        ansible_vars = dict(resource_prefix=self.resource_prefix, )

        ansible_vars.update(dict(parser.items('default')))

        return CloudEnvironmentConfig(ansible_vars=ansible_vars, )
Exemple #4
0
    def configure_environment(self, env, cmd):
        """
        :type env: dict[str, str]
        :type cmd: list[str]
        """
        parser = ConfigParser()
        parser.read(self.config_path)

        changes = dict(VULTR_API_KEY=parser.get('default', 'key'), )
        env.update(changes)

        cmd.append('-e')
        cmd.append('vultr_resource_prefix=%s' % self.resource_prefix)
Exemple #5
0
    def get_environment_config(self):
        """
        :rtype: CloudEnvironmentConfig
        """
        parser = ConfigParser()
        parser.read(self.config_path)

        env_vars = dict(VULTR_API_KEY=parser.get('default', 'key'), )

        ansible_vars = dict(vultr_resource_prefix=self.resource_prefix, )

        return CloudEnvironmentConfig(
            env_vars=env_vars,
            ansible_vars=ansible_vars,
        )
Exemple #6
0
    def configure_environment(self, env, cmd):
        """
        :type env: dict[str, str]
        :type cmd: list[str]
        """
        parser = ConfigParser()
        parser.read(self.config_path)

        changes = dict(CLOUDSCALE_API_TOKEN=parser.get(
            'default', 'cloudscale_api_token'), )

        env.update(changes)

        cmd.append('-e')
        cmd.append('cloudscale_resource_prefix=%s' % self.resource_prefix)
Exemple #7
0
    def get_environment_config(self):
        parser = ConfigParser()
        parser.read(self.config_path)

        env_vars = dict(HCLOUD_TOKEN=parser.get('default',
                                                'hcloud_api_token'), )

        ansible_vars = dict(hcloud_prefix=self.resource_prefix, )

        ansible_vars.update(
            dict((key.lower(), value) for key, value in env_vars.items()))

        return CloudEnvironmentConfig(
            env_vars=env_vars,
            ansible_vars=ansible_vars,
        )
Exemple #8
0
    def get_environment_config(self):
        """
        :rtype: CloudEnvironmentConfig
        """
        parser = ConfigParser()
        parser.read(self.config_path)

        ansible_vars = dict(resource_prefix=self.resource_prefix, )

        ansible_vars.update(dict(parser.items('default')))

        env_vars = {'ANSIBLE_DEBUG_BOTOCORE_LOGS': 'True'}

        return CloudEnvironmentConfig(
            env_vars=env_vars,
            ansible_vars=ansible_vars,
            callback_plugins=['aws_resource_actions'],
        )
Exemple #9
0
    def get_environment_config(self):
        """
        :rtype: CloudEnvironmentConfig
        """
        parser = ConfigParser()
        parser.read(self.config_path)

        ansible_vars = dict(
            resource_prefix=self.resource_prefix,
        )

        ansible_vars.update(dict(parser.items('default')))

        display.sensitive.add(ansible_vars.get('opennebula_password'))

        return CloudEnvironmentConfig(
            ansible_vars=ansible_vars,
        )
Exemple #10
0
def get_config(config_path):
    """
    :type config_path: str
    :rtype: dict[str, str]
    """
    parser = ConfigParser()
    parser.read(config_path)

    config = dict(
        (key.upper(), value) for key, value in parser.items('default'))

    rg_vars = (
        'RESOURCE_GROUP',
        'RESOURCE_GROUP_SECONDARY',
    )

    sp_vars = (
        'AZURE_CLIENT_ID',
        'AZURE_SECRET',
        'AZURE_SUBSCRIPTION_ID',
        'AZURE_TENANT',
    )

    ad_vars = (
        'AZURE_AD_USER',
        'AZURE_PASSWORD',
        'AZURE_SUBSCRIPTION_ID',
    )

    rg_ok = all(var in config for var in rg_vars)
    sp_ok = all(var in config for var in sp_vars)
    ad_ok = all(var in config for var in ad_vars)

    if not rg_ok:
        raise ApplicationError('Resource groups must be defined with: %s' %
                               ', '.join(sorted(rg_vars)))

    if not sp_ok and not ad_ok:
        raise ApplicationError(
            'Credentials must be defined using either:\nService Principal: %s\nActive Directory: %s'
            % (', '.join(sorted(sp_vars)), ', '.join(sorted(ad_vars))))

    return config
Exemple #11
0
    def get_environment_config(self):
        """
        :rtype: CloudEnvironmentConfig
        """
        parser = ConfigParser()
        parser.read(self.config_path)

        env_vars = dict(CLOUDSCALE_API_TOKEN=parser.get(
            'default', 'cloudscale_api_token'), )

        ansible_vars = dict(cloudscale_resource_prefix=self.resource_prefix, )

        ansible_vars.update(
            dict((key.lower(), value) for key, value in env_vars.items()))

        return CloudEnvironmentConfig(
            env_vars=env_vars,
            ansible_vars=ansible_vars,
        )
Exemple #12
0
    def get_environment_config(self):
        """
        :rtype: CloudEnvironmentConfig
        """
        vmware_test_platform = self._get_cloud_config('vmware_test_platform')
        if vmware_test_platform in ('worldstream', 'static'):
            parser = ConfigParser()
            parser.read(self.config_path)

            # Most of the test cases use ansible_vars, but we plan to refactor these
            # to use env_vars, output both for now
            env_vars = dict(
                (key.upper(), value) for key, value in parser.items('DEFAULT'))

            ansible_vars = dict(
                resource_prefix=self.resource_prefix,
            )
            ansible_vars.update(dict(parser.items('DEFAULT')))

        else:
            env_vars = dict(
                VCENTER_HOST=self._get_cloud_config('vcenter_host'),
            )

            ansible_vars = dict(
                vcsim=self._get_cloud_config('vcenter_host'),
            )

        return CloudEnvironmentConfig(
            env_vars=env_vars,
            ansible_vars=ansible_vars,
        )
Exemple #13
0
    def get_environment_config(self):
        """
        :rtype: CloudEnvironmentConfig
        """
        parser = ConfigParser()
        parser.read(self.config_path)

        config = dict(parser.items('default'))

        env_vars = dict(
            CLOUDSTACK_ENDPOINT=config['endpoint'],
            CLOUDSTACK_KEY=config['key'],
            CLOUDSTACK_SECRET=config['secret'],
            CLOUDSTACK_TIMEOUT=config['timeout'],
        )

        ansible_vars = dict(cs_resource_prefix=self.resource_prefix, )

        return CloudEnvironmentConfig(
            env_vars=env_vars,
            ansible_vars=ansible_vars,
        )
Exemple #14
0
    def _setup_static(self):
        parser = ConfigParser()
        parser.read(self.config_static_path)

        self.endpoint = parser.get('DEFAULT', 'vcenter_hostname')
        self.port = parser.get('DEFAULT', 'vcenter_port')

        if parser.get('DEFAULT', 'vmware_validate_certs').lower() in ('no', 'false'):
            self.insecure = True

        self._wait_for_service()
Exemple #15
0
    def pylint(args, context, paths, plugin_dir, plugin_names):  # type: (SanityConfig, str, t.List[str], str, t.List[str]) -> t.List[t.Dict[str, str]]
        """Run pylint using the config specified by the context on the specified paths."""
        rcfile = os.path.join(ANSIBLE_ROOT, 'test/sanity/pylint/config/%s' % context.split('/')[0])

        if not os.path.exists(rcfile):
            rcfile = os.path.join(ANSIBLE_ROOT, 'test/sanity/pylint/config/default')

        parser = ConfigParser()
        parser.read(rcfile)

        if parser.has_section('ansible-test'):
            config = dict(parser.items('ansible-test'))
        else:
            config = dict()

        disable_plugins = set(i.strip() for i in config.get('disable-plugins', '').split(',') if i)
        load_plugins = set(plugin_names) - disable_plugins

        cmd = [
            args.python_executable,
            '-m', 'pylint',
            '--jobs', '0',
            '--reports', 'n',
            '--max-line-length', '160',
            '--rcfile', rcfile,
            '--output-format', 'json',
            '--load-plugins', ','.join(load_plugins),
        ] + paths

        append_python_path = [plugin_dir]

        if data_context().content.collection:
            append_python_path.append(data_context().content.collection.root)

        env = ansible_environment(args)
        env['PYTHONPATH'] += os.path.pathsep + os.path.pathsep.join(append_python_path)

        if paths:
            display.info('Checking %d file(s) in context "%s" with config: %s' % (len(paths), context, rcfile), verbosity=1)

            try:
                stdout, stderr = run_command(args, cmd, env=env, capture=True)
                status = 0
            except SubprocessError as ex:
                stdout = ex.stdout
                stderr = ex.stderr
                status = ex.status

            if stderr or status >= 32:
                raise SubprocessError(cmd=cmd, status=status, stderr=stderr, stdout=stdout)
        else:
            stdout = None

        if not args.explain and stdout:
            messages = json.loads(stdout)
        else:
            messages = []

        return messages
Exemple #16
0
    def _setup_static(self):
        parser = ConfigParser({
            'vcenter_port': '443',
            'vmware_proxy_host': '',
            'vmware_proxy_port': ''
        })
        parser.read(self.config_static_path)

        self.endpoint = parser.get('DEFAULT', 'vcenter_hostname')
        self.port = parser.get('DEFAULT', 'vcenter_port')

        if parser.get('DEFAULT',
                      'vmware_validate_certs').lower() in ('no', 'false'):
            self.insecure = True
        proxy_host = parser.get('DEFAULT', 'vmware_proxy_host')
        proxy_port = int(parser.get('DEFAULT', 'vmware_proxy_port'))
        if proxy_host and proxy_port:
            self.proxy = 'http://%s:%d' % (proxy_host, proxy_port)

        self._wait_for_service()
Exemple #17
0
    def get_environment_config(self):
        """
        :rtype: CloudEnvironmentConfig
        """
        parser = ConfigParser()
        parser.read(self.config_path)

        env_vars = dict(SCW_API_KEY=parser.get('default', 'key'),
                        SCW_ORG=parser.get('default', 'org'))

        ansible_vars = dict(scw_org=parser.get('default', 'org'), )

        return CloudEnvironmentConfig(
            env_vars=env_vars,
            ansible_vars=ansible_vars,
        )
Exemple #18
0
    def pylint(self, args, context, paths):
        """
        :type args: SanityConfig
        :type context: str
        :type paths: list[str]
        :rtype: list[dict[str, str]]
        """
        #rcfile = 'test/sanity/pylint/config/%s' % context.split('/')[0]
        rcfile = os.path.join(
            os.path.dirname(ansible_test.__file__),
            'lib/sanity/pylint/config/%s' % context.split('/')[0])

        if not os.path.exists(rcfile):
            rcfile = os.path.join(os.path.dirname(ansible_test.__file__),
                                  'lib/sanity/pylint/config/default')

        parser = ConfigParser()
        parser.read(rcfile)

        if parser.has_section('ansible-test'):
            config = dict(parser.items('ansible-test'))
        else:
            config = dict()

        disable_plugins = set(
            i.strip() for i in config.get('disable-plugins', '').split(',')
            if i)
        load_plugins = set(self.plugin_names) - disable_plugins

        cmd = [
            args.python_executable,
            '-m',
            'pylint',
            '--jobs',
            '0',
            '--reports',
            'n',
            '--max-line-length',
            '160',
            '--rcfile',
            rcfile,
            '--output-format',
            'json',
            '--load-plugins',
            ','.join(load_plugins),
        ] + paths

        env = ansible_environment(args)
        env['PYTHONPATH'] += '%s%s' % (os.path.pathsep, self.plugin_dir)

        if paths:
            display.info(
                'Checking %d file(s) in context "%s" with config: %s' %
                (len(paths), context, rcfile),
                verbosity=1)

            try:
                stdout, stderr = run_command(args, cmd, env=env, capture=True)
                status = 0
            except SubprocessError as ex:
                stdout = ex.stdout
                stderr = ex.stderr
                status = ex.status

            if stderr or status >= 32:
                raise SubprocessError(cmd=cmd,
                                      status=status,
                                      stderr=stderr,
                                      stdout=stdout)
        else:
            stdout = None

        if not args.explain and stdout:
            messages = json.loads(stdout)
        else:
            messages = []

        return messages