Example #1
0
def default_proxy():
    """ Returns default capsule/proxy id"""
    proxy = Proxy.list({'search': settings.server.hostname})[0]
    p_features = set(proxy.get('features').split(', '))
    if {'Puppet', 'Ansible', 'Openscap'}.issubset(p_features):
        proxy_id = proxy.get('id')
    else:
        raise ProxyError('Some features like Puppet, DHCP, Openscap, Ansible are not present')
    return proxy_id
Example #2
0
def default_proxy(module_target_sat):
    """Returns default capsule/proxy id"""
    proxy = Proxy.list({'search': module_target_sat.hostname})[0]
    p_features = set(proxy.get('features').split(', '))
    if {'Ansible', 'Openscap'}.issubset(p_features):
        proxy_id = proxy.get('id')
    else:
        raise ProxyError(
            'Some features like DHCP, Openscap, Ansible are not present')
    return proxy_id
Example #3
0
    def configure_puppet_test(cls):
        """Sets up the whole provisioning environment needed for Puppet based
        end-to-end tests like OSCAP etc

        :returns: A dict of entities to help with provisioning
        """
        cls.rhel6_content = OSCAP_DEFAULT_CONTENT['rhel6_content']
        cls.rhel7_content = OSCAP_DEFAULT_CONTENT['rhel7_content']
        cls.rhel8_content = OSCAP_DEFAULT_CONTENT['rhel8_content']
        sat6_hostname = settings.server.hostname
        proxy = Proxy.list({'search': sat6_hostname})[0]
        p_features = set(proxy.get('features').split(', '))
        if {'Puppet', 'Ansible', 'Openscap'}.issubset(p_features):
            cls.proxy_id = proxy.get('id')
        else:
            raise ProxyError(
                'Some features like Puppet, DHCP, Openscap, Ansible are not present'
            )
        ak_name_8 = gen_string('alpha')
        ak_name_7 = gen_string('alpha')
        ak_name_6 = gen_string('alpha')
        repo_values = [
            {
                'repo': settings.sattools_repo['rhel8'],
                'akname': ak_name_8
            },
            {
                'repo': settings.sattools_repo['rhel7'],
                'akname': ak_name_7
            },
            {
                'repo': settings.sattools_repo['rhel6'],
                'akname': ak_name_6
            },
        ]
        # Create new organization and environment.
        org = entities.Organization(name=gen_string('alpha')).create()
        cls.puppet_env = (entities.Environment().search(
            query={'search': 'name=production'})[0].read())
        cls.puppet_env.organization.append(org)
        cls.puppet_env = cls.puppet_env.update(['organization'])
        smart_proxy = (entities.SmartProxy().search(
            query={'search': f'name={sat6_hostname}'})[0].read())
        smart_proxy.import_puppetclasses(environment=cls.puppet_env.name)
        env = entities.LifecycleEnvironment(organization=org,
                                            name=gen_string('alpha')).create()
        # Create content view
        content_view = entities.ContentView(organization=org,
                                            name=gen_string('alpha')).create()
        # Create activation keys for rhel6, rhel7 and rhel8.
        for repo in repo_values:
            activation_key = entities.ActivationKey(name=repo.get('akname'),
                                                    environment=env,
                                                    organization=org).create()
            # Setup org for a custom repo for RHEL6, RHEL7 and RHEL8.
            setup_org_for_a_custom_repo({
                'url': repo.get('repo'),
                'organization-id': org.id,
                'content-view-id': content_view.id,
                'lifecycle-environment-id': env.id,
                'activationkey-id': activation_key.id,
            })

        for content in cls.rhel8_content, cls.rhel7_content, cls.rhel6_content:
            content = Scapcontent.info({'title': content},
                                       output_format='json')
            organization_ids = [
                content_org['id']
                for content_org in content.get('organizations', [])
            ]
            organization_ids.append(org.id)
            Scapcontent.update({
                'title': content['title'],
                'organization-ids': organization_ids
            })

        return {
            'org_name': org.name,
            'cv_name': content_view.name,
            'sat6_hostname': settings.server.hostname,
            'ak_name': {
                'rhel8': ak_name_8,
                'rhel7': ak_name_7,
                'rhel6': ak_name_6
            },
            'env_name': env.name,
        }
Example #4
0
    def configure_puppet_test(cls):
        """Sets up the whole provisioning environment needed for Puppet based
         end-to-end tests like OSCAP etc

         :returns: A dict of entities to help with provisioning
        """
        cls.rhel6_content = OSCAP_DEFAULT_CONTENT['rhel6_content']
        cls.rhel7_content = OSCAP_DEFAULT_CONTENT['rhel7_content']
        sat6_hostname = settings.server.hostname
        proxy = Proxy.list({'search': sat6_hostname})[0]
        p_features = set(proxy.get('features').split(', '))
        if {'Puppet', 'Ansible', 'Openscap'}.issubset(p_features):
            cls.proxy_id = proxy.get('id')
        else:
            raise ProxyError(
                'Some features like Puppet, DHCP, Openscap, Ansible are not present'
            )
        ak_name_7 = gen_string('alpha')
        ak_name_6 = gen_string('alpha')
        repo_values = [
            {
                'repo': settings.sattools_repo['rhel6'],
                'akname': ak_name_6
            },
            {
                'repo': settings.sattools_repo['rhel7'],
                'akname': ak_name_7
            },
        ]
        # Create new organization and environment.
        org = entities.Organization(name=gen_string('alpha')).create()
        loc = entities.Location().search(
            query={'search': "{0}".format(DEFAULT_LOC)})[0].read()
        cls.puppet_env = entities.Environment().search(
            query={u'search': u'name=production'})[0].read()
        cls.puppet_env.location.append(loc)
        cls.puppet_env.organization.append(org)
        cls.puppet_env = cls.puppet_env.update(['location', 'organization'])
        Proxy.import_classes({
            u'environment': cls.puppet_env.name,
            u'name': sat6_hostname,
        })
        Proxy.update({
            'id': cls.proxy_id,
            'organizations': org.name,
            'locations': DEFAULT_LOC
        })
        env = entities.LifecycleEnvironment(organization=org,
                                            name=gen_string('alpha')).create()
        # Create content view
        content_view = entities.ContentView(organization=org,
                                            name=gen_string('alpha')).create()
        # Create two activation keys for rhel7 and rhel6
        for repo in repo_values:
            activation_key = entities.ActivationKey(
                name=repo.get('akname'),
                environment=env,
                organization=org,
            ).create()
            # Setup org for a custom repo for RHEL6 and RHEL7
            setup_org_for_a_custom_repo({
                'url': repo.get('repo'),
                'organization-id': org.id,
                'content-view-id': content_view.id,
                'lifecycle-environment-id': env.id,
                'activationkey-id': activation_key.id
            })

        for content in cls.rhel6_content, cls.rhel7_content:
            Scapcontent.update({
                'title': content,
                'organizations': org.name,
                'locations': DEFAULT_LOC
            })
        return {
            'org_name': org.name,
            'cv_name': content_view.name,
            'sat6_hostname': settings.server.hostname,
            'ak_name': {
                'rhel7': ak_name_7,
                'rhel6': ak_name_6
            },
            'env_name': env.name,
        }