Exemplo n.º 1
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,
        )
Exemplo n.º 2
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
Exemplo n.º 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, )
Exemplo n.º 4
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'],
        )
Exemplo n.º 5
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,
        )
Exemplo n.º 6
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
Exemplo n.º 7
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,
        )
Exemplo n.º 8
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