def test_positive_update_template(self):
        """Create an operating system that points at provisioning template and
        then update it to point to another template

        :id: 02125a7a-905a-492a-a49b-768adf4ac00c

        :expectedresults: The operating system is updated and points at the
            expected provisioning template.

        :CaseLevel: Integration
        """
        template_1 = entities.ProvisioningTemplate(
            organization=[self.org]).create()
        template_2 = entities.ProvisioningTemplate(
            organization=[self.org]).create()
        os = entities.OperatingSystem(
            provisioning_template=[template_1]).create()
        self.assertEqual(len(os.provisioning_template), 1)
        self.assertEqual(os.provisioning_template[0].id, template_1.id)
        os = entities.OperatingSystem(id=os.id,
                                      provisioning_template=[
                                          template_2
                                      ]).update(['provisioning_template'])
        self.assertEqual(len(os.provisioning_template), 1)
        self.assertEqual(os.provisioning_template[0].id, template_2.id)
Exemple #2
0
def module_provisioningtemplate_pxe(module_org, module_location):
    pxe_template = entities.ProvisioningTemplate().search(
        query={'search': f'name="{DEFAULT_PXE_TEMPLATE}"'})
    pxe_template = pxe_template[0].read()
    pxe_template.organization.append(module_org)
    pxe_template.location.append(module_location)
    pxe_template.update(['organization', 'location'])
    pxe_template = entities.ProvisioningTemplate(id=pxe_template.id).read()
    return pxe_template
Exemple #3
0
def module_provisioningtemplate_default(module_org, module_location):
    provisioning_template = entities.ProvisioningTemplate().search(
        query={'search': 'name="{0}"'.format(DEFAULT_TEMPLATE)})
    provisioning_template = provisioning_template[0].read()
    provisioning_template.organization.append(module_org)
    provisioning_template.location.append(module_location)
    provisioning_template.update(['organization', 'location'])
    provisioning_template = entities.ProvisioningTemplate(
        id=provisioning_template.id).read()
    return provisioning_template
Exemple #4
0
    def test_positive_update_template(self):
        """Add and Remove config template.

        :id: 67bec745-5f10-494c-92a7-173ee63e8297

        :expectedresults: Config Template is added and then removed.

        :CaseLevel: Integration
        """
        with Session(self.browser) as session:
            org_name = gen_string('alpha')
            make_org(session, org_name=org_name)
            for template_name in generate_strings_list():
                with self.subTest(template_name):
                    # Create config template using nailgun
                    template = entities.ProvisioningTemplate(
                        name=template_name).create()
                    self.assertEqual(template.name, template_name)
                    kwargs = {
                        'org_name': org_name,
                        'entity_type': 'templates',
                        'entity_name': template_name
                    }
                    self.assertIsNotNone(self.org.add_entity(**kwargs))
                    self.assertIsNotNone(self.org.remove_entity(**kwargs))
def test_positive_update_template(session, module_org):
    """Update operating system with new provisioning template value

    :id: 0b90eb24-8fc9-4e42-8709-6eee8ffbbdb5

    :expectedresults: OS is updated with new template

    :CaseLevel: Integration
    """
    name = gen_string('alpha')
    major_version = gen_string('numeric', 2)
    os = entities.OperatingSystem(name=name,
                                  major=major_version,
                                  family='Redhat').create()
    template = entities.ProvisioningTemplate(
        organization=[module_org],
        snippet=False,
        template_kind=entities.TemplateKind().search(
            query={'search': 'name="provision"'})[0],
        operatingsystem=[os],
    ).create()
    with session:
        os_full_name = '{} {}'.format(name, major_version)
        values = session.operatingsystem.read(os_full_name)
        assert values['templates']['resources'][
            'Provisioning template'] == DEFAULT_TEMPLATE
        session.operatingsystem.update(
            os_full_name,
            {'templates.resources': {
                'Provisioning template': template.name
            }})
        values = session.operatingsystem.read(os_full_name)
        assert values['templates']['resources'][
            'Provisioning template'] == template.name
def function_template_combination(module_hostgroup_and_environment):
    """Create ProvisioningTemplate and TemplateConfiguration for each test
    and at the end delete ProvisioningTemplate used on tests
    """
    template = entities.ProvisioningTemplate(
        snippet=False,
        template_combinations=[{
            'hostgroup_id':
            module_hostgroup_and_environment['hostgroup'].id,
            'environment_id':
            module_hostgroup_and_environment['env'].id,
        }],
    )
    template = template.create()
    template_combination_dct = template.template_combinations[0]
    template_combination = entities.TemplateCombination(
        id=template_combination_dct['id'],
        environment=module_hostgroup_and_environment['env'],
        provisioning_template=template,
        hostgroup=module_hostgroup_and_environment['hostgroup'],
    )
    yield {'template': template, 'template_combination': template_combination}
    # Clean combination if it is not already deleted
    try:
        template_combination.delete()
    except HTTPError:
        pass
    template.delete()
Exemple #7
0
def test_positive_update_template(session):
    """Add/Remove template from/to location

    :id: 8faf60d1-f4d6-4a58-a484-606a42957ce7

    :expectedresults: config template is removed and then added to the location

    :CaseLevel: Integration
    """
    template = entities.ProvisioningTemplate().create()
    loc = entities.Location().create()
    with session:
        session.location.update(
            loc.name, {
                'provisioning_templates.all_templates': False,
                'provisioning_templates.resources.unassigned': [template.name]
            })
        loc_values = session.location.read(loc.name)
        assert loc_values['provisioning_templates']['resources']['unassigned'][
            0] == template.name
        session.location.update(
            loc.name,
            {'provisioning_templates.resources.assigned': [template.name]})
        new_loc_values = session.location.read(loc.name)
        assert len(new_loc_values[
                       'provisioning_templates']['resources']['assigned']) == \
            len(loc_values[
                    'provisioning_templates']['resources']['assigned']) + 1
        assert template.name in new_loc_values['provisioning_templates'][
            'resources']['assigned']
Exemple #8
0
def test_positive_update_template(session):
    """Add and remove provisioning template from/to organization.

    :id: 67bec745-5f10-494c-92a7-173ee63e8297

    :expectedresults: Provisioning Template is added and then removed.

    :CaseLevel: Integration
    """
    template = entities.ProvisioningTemplate().create()
    org = entities.Organization().create()
    with session:
        session.organization.update(
            org.name,
            {'provisioning_templates.resources.assigned': [template.name]}
        )
        org_values = session.organization.read(org.name)
        assert template.name in org_values[
            'provisioning_templates']['resources']['assigned']
        session.organization.update(
            org.name,
            {'provisioning_templates.resources.unassigned': [template.name]}
        )
        org_values = session.organization.read(org.name)
        assert template.name in org_values[
            'provisioning_templates']['resources']['unassigned']
Exemple #9
0
    def test_positive_build_pxe_default(self, tftpboot):
        """Call the "build_pxe_default" path.

        :id: ca19d9da-1049-4b39-823b-933fc1a0cebd

        :expectedresults: The response is a JSON payload, all templates are deployed to TFTP/HTTP
                          and are rendered correctly

        :CaseLevel: Integration

        :CaseImportance: Critical

        :BZ: 1202564
        """
        response = client.post(
            entities.ProvisioningTemplate().path('build_pxe_default'),
            auth=settings.server.get_credentials(),
            verify=False,
        )
        response.raise_for_status()
        assert type(response.json()) == dict
        for template in tftpboot.values():
            if template['path'].startswith('http'):
                r = client.get(template['path'], verify=False)
                r.raise_for_status()
                rendered = r.text
            else:
                rendered = ssh.command(f"cat {template['path']}").stdout[0]
            assert (rendered == f"{settings.server.scheme}://"
                    f"{settings.server.hostname} {template['kind']}")
Exemple #10
0
def test_positive_clone(session, clone_setup):
    """Assure ability to clone a provisioning template

    :id: 912f1619-4bb0-4e0f-88ce-88b5726fdbe0

    :Steps:
        1.  Go to Provisioning template UI
        2.  Choose a template and attempt to clone it

    :expectedresults: The template is cloned

    :CaseLevel: Integration
    """
    clone_name = gen_string('alpha')
    with session:
        session.provisioningtemplate.clone(
            clone_setup['pt'].name,
            {
                'template.name': clone_name,
                'association.applicable_os.assigned': clone_setup['os_list'],
            },
        )
        pt = entities.ProvisioningTemplate().search(
            query={'search': 'name=={0}'.format(clone_name)})
        assigned_oses = [os.read() for os in pt[0].read().operatingsystem]
        assert pt, (
            'Template {0} expected to exist but is not included in the search'
            'results'.format(clone_name))
        assert set(clone_setup['os_list']) == set(
            '{0} {1}'.format(os.name, os.major) for os in assigned_oses)
Exemple #11
0
    def test_positive_update_with_manager_role(self):
        """Create template providing the initial name, then update its name
        with manager user role.

        :id: 463790a2-c384-4851-99d2-78777762b6df

        :expectedresults: Provisioning Template is created, and its name can
            be updated.

        :CaseImportance: Critical

        :BZ: 1277308
        """
        new_name = gen_string('alpha')
        user_login = gen_string('alpha')
        user_password = gen_string('alpha')
        template = entities.ProvisioningTemplate(
            organization=[self.organization], location=[self.loc]).create()
        # Create user with Manager role
        role = entities.Role().search(query={'search': 'name="Manager"'})[0]
        entities.User(
            role=[role],
            admin=False,
            login=user_login,
            password=user_password,
            organization=[self.organization],
            default_organization=self.organization,
            location=[self.loc],
        ).create()
        with Session(self, user=user_login, password=user_password):
            self.template.update(name=template.name, new_name=new_name)
            self.assertIsNotNone(self.template.search(new_name))
def provisioning_env(module_org, module_loc):
    # Build PXE default template to get default PXE file
    entities.ProvisioningTemplate().build_pxe_default()
    return configure_provisioning(
        org=module_org,
        loc=module_loc,
        os='Redhat {0}'.format(RHELRepository().repo_data['version']),
    )
Exemple #13
0
def provisioning_env(discovery_org, discovery_location):
    # Build PXE default template to get default PXE file
    entities.ProvisioningTemplate().build_pxe_default()
    return configure_provisioning(
        org=discovery_org,
        loc=discovery_location,
        os='Redhat {}'.format(RHELRepository().repo_data['version']),
    )
Exemple #14
0
    def test_positive_import_force_locked_template(
            self, module_org, create_import_export_local_dir):
        """Assure locked templates are updated from repository when `force` is
        specified.

        :id: b80fbfc4-bcab-4a5d-b6c1-0e22906cd8ab

        :Steps:
            1. Import some of the locked template specifying the `force`
               parameter `false`.
            2. After ensuring the template is not updated, Import same locked template
               specifying the `force` parameter `true`.

        :expectedresults:
            1. Assert result is {'message': 'success'}
            2. With force - false, assert that locked template is not updated.
            3. With force - true, assert that the locked template is updated.

        :CaseImportance: Medium

        :CaseAutomation: NotAutomated
        """
        prefix = gen_string('alpha')
        _, dir_path = create_import_export_local_dir
        TemplateSync.imports({
            'repo': dir_path,
            'prefix': prefix,
            'organization-ids': module_org.id,
            'lock': 'true'
        })
        ptemplate = entities.ProvisioningTemplate().search(
            query={
                'per_page': 10,
                'search': f'name~{prefix}',
                'organization_id': module_org.id
            })
        if ptemplate:
            assert ptemplate[0].read().locked
            update_txt = 'updated a little'
            ssh.command(
                f"echo {update_txt} >> {dir_path}/example_template.erb")
            TemplateSync.imports({
                'repo': dir_path,
                'prefix': prefix,
                'organization-id': module_org.id
            })
            assert update_txt not in Template.dump(
                {'name': f'{prefix}example template'})
            TemplateSync.imports({
                'repo': dir_path,
                'prefix': prefix,
                'organization-id': module_org.id,
                'force': 'true',
            })
            assert update_txt in Template.dump(
                {'name': f'{prefix}example template'})
        else:
            pytest.fail('The template is not imported for force test')
Exemple #15
0
    def test_import_filtered_templates_from_git_with_negate(self, module_org):
        """Assure templates with a given filter regex are NOT pulled from
        git repo.

        :id: a6857454-249b-4a2e-9b53-b5d7b4eb34e3

        :Steps:
            1. Using nailgun or direct API call
               import the templates NOT matching with regex e.g: `^freebsd.*`
               refer to: `/apidoc/v2/template/import.html` using the
               {'negate': true} in POST body to negate the filter regex.

        :expectedresults:
            1. Assert result is {'message': 'success'}
            2. Assert templates mathing the regex were not pulled.

        :CaseImportance: Medium
        """
        prefix = gen_string('alpha')
        filtered_imported_templates = entities.Template().imports(
            data={
                'repo': FOREMAN_TEMPLATE_IMPORT_URL,
                'branch': 'automation',
                'filter': 'robottelo',
                'organization_ids': [module_org.id],
                'prefix': prefix,
                'negate': True,
            })
        not_imported_count = [
            template['imported']
            for template in filtered_imported_templates['message']['templates']
        ].count(False)
        assert not_imported_count == 9
        ptemplates = entities.ProvisioningTemplate().search(
            query={
                'per_page': '100',
                'search': 'name~jenkins',
                'organization_id': module_org.id
            })
        assert len(ptemplates) == 6
        ptables = entities.PartitionTable().search(
            query={
                'per_page': '100',
                'search': 'name~jenkins',
                'organization_id': module_org.id
            })
        assert len(ptables) == 1
        rtemplates = entities.ReportTemplate().search(
            query={
                'per_page': '100',
                'search': 'name~jenkins',
                'organization_id': module_org.id
            })
        assert len(rtemplates) == 1
Exemple #16
0
 def make_entities(self):
     """Set up reusable entities for tests."""
     return dict(
         domain=entities.Domain().create(),
         subnet=entities.Subnet().create(),
         env=entities.Environment().create(),
         host_group=entities.HostGroup().create(),
         template=entities.ProvisioningTemplate().create(),
         test_cr=entities.LibvirtComputeResource().create(),
         new_user=entities.User().create(),
     )
Exemple #17
0
 def setUpClass(cls):
     """Set up reusable entities for tests."""
     super(LocationTestCase, cls).setUpClass()
     cls.org = entities.Organization().create()
     cls.org2 = entities.Organization().create()
     cls.domain = entities.Domain().create()
     cls.subnet = entities.Subnet().create()
     cls.env = entities.Environment().create()
     cls.host_group = entities.HostGroup().create()
     cls.template = entities.ProvisioningTemplate().create()
     cls.test_cr = entities.LibvirtComputeResource().create()
     cls.new_user = entities.User().create()
Exemple #18
0
    def test_positive_delete_by_type(self):
        """Delete some entities of different types and check audit logs for
        these events using entity type and performed action as search criteria

        :id: 69dcd846-5cef-457f-ae75-c1cf76071d00

        :expectedresults: Audit logs contain corresponding entries per each
            delete event
        """
        with Session(self):
            for entity_item in [
                {
                    'entity': entities.Architecture(),
                    'entity_type': 'architecture'
                },
                {
                    'entity': entities.Domain(),
                    'entity_type': 'domain'
                },
                {
                    'entity': entities.HostGroup(),
                    'entity_type': 'hostgroup'
                },
                {
                    'entity': entities.Location(),
                    'entity_type': 'location'
                },
                {
                    'entity': entities.PartitionTable(),
                    'entity_type': 'ptable',
                },
                {
                    'entity': entities.Role(),
                    'entity_type': 'role'
                },
                {
                    'entity': entities.ProvisioningTemplate(),
                    'entity_type': 'template',
                },
                {
                    'entity': entities.UserGroup(),
                    'entity_type': 'usergroup'
                },
            ]:
                entity = entity_item['entity'].create()
                entity.delete()
                self.audit.filter('type={} and action=delete'.format(
                    entity_item['entity_type']))
                result = self.audit.get_last_entry()
                self.assertIn('destroyed', result['full_statement'])
                self.assertEqual(result['entity_name'], entity.name)
    def test_positive_create_with_template(self, module_org):
        """Create an operating system that points at a provisioning template.

        :id: df73ecba-5a1c-4201-9c2f-b2e03e8fec25

        :expectedresults: The operating system is created and points at the
            expected provisioning template.

        :CaseLevel: Integration
        """
        template = entities.ProvisioningTemplate(organization=[module_org]).create()
        operating_sys = entities.OperatingSystem(provisioning_template=[template]).create()
        assert len(operating_sys.provisioning_template) == 1
        assert operating_sys.provisioning_template[0].id == template.id
def clone_setup(module_org, module_loc):
    name = gen_string('alpha')
    content = gen_string('alpha')
    os_list = [entities.OperatingSystem().create().title for _ in range(2)]
    return {
        'pt': entities.ProvisioningTemplate(
            name=name,
            organization=[module_org],
            location=[module_loc],
            template=content,
            snippet=False,
        ).create(),
        'os_list': os_list,
    }
Exemple #21
0
    def test_positive_update_with_manager_role(self):
        """Create template providing the initial name, then update its name
        with manager user role.

        :id: 0aed79f0-7c9a-4789-99ba-56f2db82f097

        :expectedresults: Provisioning Template is created, and its name can
            be updated.

        :CaseImportance: Critical

        :BZ: 1277308
        """
        user_login = gen_string('alpha')
        user_password = gen_string('alpha')
        new_name = gen_string('alpha')
        org = entities.Organization().create()
        loc = entities.Location().create()
        template = entities.ProvisioningTemplate(organization=[org],
                                                 location=[loc]).create()
        # Create user with Manager role
        role = entities.Role().search(query={'search': 'name="Manager"'})[0]
        entities.User(
            role=[role],
            admin=False,
            login=user_login,
            password=user_password,
            organization=[org],
            location=[loc],
        ).create()
        # Update template name with that user
        cfg = get_nailgun_config()
        cfg.auth = (user_login, user_password)
        updated = entities.ProvisioningTemplate(cfg,
                                                id=template.id,
                                                name=new_name).update(['name'])
        self.assertEqual(updated.name, new_name)
Exemple #22
0
    def test_positive_import_locked_template(self, module_org):
        """Assure locked templates are pulled from repository while using force parameter.

        :id: 936c91cc-1947-45b0-8bf0-79ba4be87b97

        :Steps:
            1. Using nailgun try to import a locked template with force parameter

        :expectedresults:
            1. Assert locked template is updated

        :CaseImportance: Medium
        """
        # import template with lock
        output = entities.Template().imports(
            data={
                'repo': FOREMAN_TEMPLATE_IMPORT_URL,
                'branch': 'locked',
                'organization_ids': [module_org.id],
                'dirname': 'locked',
                'force': True,
                'lock': True,
            }
        )
        assert output['message']['templates'][0]['imported']
        # force import same template with changed content
        output = entities.Template().imports(
            data={
                'repo': FOREMAN_TEMPLATE_IMPORT_URL,
                'branch': 'locked',
                'organization_ids': [module_org.id],
                'dirname': 'after_lock',
                'force': True,
            }
        )
        # assert template was changed
        assert output['message']['templates'][0]['imported']
        assert output['message']['templates'][0]['changed']
        res = requests.get(
            url=f"{FOREMAN_TEMPLATE_IMPORT_API_URL}/contents/after_lock/robottelo_locked.erb",
            headers={'Authorization': f'token {settings.git.github_token}'},
            params={'ref': 'locked'},
        )
        res.raise_for_status()
        git_content = base64.b64decode(json.loads(res.text)['content'])
        sat_content = entities.ProvisioningTemplate(
            id=output['message']['templates'][0]['id']
        ).read()
        assert git_content.decode('utf-8') == sat_content.template
Exemple #23
0
    def test_positive_create_with_template_kind(self):
        """Create a provisioning template providing the template_kind.

        :id: d7309be8-b5c9-4f77-8c4e-e9f2b8982076

        :expectedresults: Provisioning Template is created and contains
            provided template kind.

        :CaseImportance: Critical
        """
        template_kind = choice(entities.TemplateKind().search())
        template = entities.ProvisioningTemplate(
            snippet=False, template_kind=template_kind,
        ).create()
        self.assertEqual(template.template_kind.id, template_kind.id)
Exemple #24
0
 def setUpClass(cls):
     """Set up reusable entities for tests."""
     super().setUpClass()
     cls.subnet = entities.Subnet().create()
     cls.env = entities.Environment().create()
     cls.env2 = entities.Environment().create()
     cls.domain = entities.Domain().create()
     cls.domain2 = entities.Domain().create()
     cls.medium = make_medium()
     cls.host_group = entities.HostGroup().create()
     cls.host_group2 = entities.HostGroup().create()
     cls.host_group3 = entities.HostGroup().create()
     cls.comp_resource = entities.LibvirtComputeResource().create()
     cls.template = entities.ProvisioningTemplate().create()
     cls.user = entities.User().create()
Exemple #25
0
    def setUpClass(cls):
        """Steps to Configure foreman discovery

        1. Build PXE default template
        2. Create Organization/Location
        3. Update Global parameters to set default org and location for
           discovered hosts.
        4. Enable auto_provision flag to perform discovery via discovery
           rules.
        """
        super().setUpClass()

        # Build PXE default template to get default PXE file
        entities.ProvisioningTemplate().build_pxe_default()
        # let's just modify the timeouts to speed things up
        ssh.command("sed -ie 's/TIMEOUT [[:digit:]]\\+/TIMEOUT 1/g' "
                    "/var/lib/tftpboot/pxelinux.cfg/default")
        ssh.command(
            "sed -ie '/APPEND initrd/s/$/ fdi.countdown=1 fdi.ssh=1 fdi.rootpw=changeme/' "
            "/var/lib/tftpboot/pxelinux.cfg/default")
        # Create Org and location
        cls.org = entities.Organization().create()
        cls.loc = entities.Location().create()
        # Get default settings values
        cls.default_disco_settings = {
            i.name: i
            for i in entities.Setting().search(
                query={'search': 'name~discovery'})
        }

        # Update discovery taxonomies settings
        cls.discovery_loc = copy(
            cls.default_disco_settings['discovery_location'])
        cls.discovery_loc.value = cls.loc.name
        cls.discovery_loc.update(['value'])
        cls.discovery_org = copy(
            cls.default_disco_settings['discovery_organization'])
        cls.discovery_org.value = cls.org.name
        cls.discovery_org.update(['value'])

        # Enable flag to auto provision discovered hosts via discovery rules
        cls.discovery_auto = copy(cls.default_disco_settings['discovery_auto'])
        cls.discovery_auto.value = 'true'
        cls.discovery_auto.update(['value'])

        # Flag which shows whether environment is fully configured for
        # discovered host provisioning.
        cls.configured_env = False
Exemple #26
0
    def test_negative_import_locked_template(self, module_org):
        """Assure locked templates are not pulled from repository.

        :id: 88e21cad-448e-45e0-add2-94493a1319c5

        :Steps:
            1. Using nailgun try to import a locked template

        :expectedresults:
            1. Assert locked template is not updated

        :CaseImportance: Medium
        """
        # import template with lock
        output = entities.Template().imports(
            data={
                'repo': FOREMAN_TEMPLATE_IMPORT_URL,
                'branch': 'locked',
                'organization_ids': [module_org.id],
                'dirname': 'locked',
                'force': True,
                'lock': True,
            }
        )
        assert output['message']['templates'][0]['imported']
        # try to import same template with changed content
        output = entities.Template().imports(
            data={
                'repo': FOREMAN_TEMPLATE_IMPORT_URL,
                'branch': 'locked',
                'organization_ids': [module_org.id],
                'dirname': 'after_lock',
            }
        )
        # assert content wasn't changed
        assert not output['message']['templates'][0]['imported']
        res = requests.get(
            url=f"{FOREMAN_TEMPLATE_IMPORT_API_URL}/contents/locked/robottelo_locked.erb",
            headers={'Authorization': f'token {settings.git.github_token}'},
            params={'ref': 'locked'},
        )
        res.raise_for_status()
        git_content = base64.b64decode(json.loads(res.text)['content'])
        sat_content = entities.ProvisioningTemplate(
            id=output['message']['templates'][0]['id']
        ).read()
        assert git_content.decode('utf-8') == sat_content.template
Exemple #27
0
def test_positive_add_org_hostgroup_template(session):
    """Add a organization, hostgroup, provisioning template by using
       the location name

    :id: 27d56d64-6866-46b6-962d-1ac2a11ae136

    :expectedresults: organization, hostgroup, provisioning template are
        added to location

    :CaseLevel: Integration
    """
    org = entities.Organization().create()
    loc = entities.Location().create()
    hostgroup = entities.HostGroup().create()
    template = entities.ProvisioningTemplate().create()
    with session:
        session.location.update(
            loc.name,
            {
                'organizations.resources.assigned': [org.name],
                'host_groups.all_hostgroups': False,
                'host_groups.resources.unassigned': [hostgroup.name],
                'provisioning_templates.all_templates': False,
                'provisioning_templates.resources.unassigned': [template.name],
            },
        )
        loc_values = session.location.read(loc.name)
        assert loc_values['organizations']['resources']['assigned'][
            0] == org.name
        assert hostgroup.name in loc_values['host_groups']['resources'][
            'unassigned']
        assert template.name in loc_values['provisioning_templates'][
            'resources']['unassigned']
        session.location.update(
            loc.name,
            {
                'host_groups.resources.assigned': [hostgroup.name],
                'provisioning_templates.resources.assigned': [template.name],
            },
        )
        loc_values = session.location.read(loc.name)
        assert hostgroup.name in loc_values['host_groups']['resources'][
            'assigned']
        assert template.name in loc_values['provisioning_templates'][
            'resources']['assigned']
Exemple #28
0
 def setUp(self):
     """Create ProvisioningTemplate and TemplateConfiguration for each test"""
     super(TemplateCombinationTestCase, self).setUp()
     self.template = entities.ProvisioningTemplate(
         snippet=False,
         template_combinations=[{
             'hostgroup_id': self.hostgroup.id,
             'environment_id': self.env.id
         }],
     )
     self.template = self.template.create()
     template_combination_dct = self.template.template_combinations[0]
     self.template_combination = entities.TemplateCombination(
         id=template_combination_dct['id'],
         environment=self.env,
         provisioning_template=self.template,
         hostgroup=self.hostgroup,
     )
Exemple #29
0
    def test_positive_create_with_template_kind_name(self):
        """Create a provisioning template providing existing
        template_kind name.

        :id: 4a1410e4-aa3c-4d27-b062-089e34722bd9

        :expectedresults: Provisioning Template is created

        :BZ: 1379006

        :CaseImportance: Critical
        """
        template_kind = choice(entities.TemplateKind().search())
        template = entities.ProvisioningTemplate(snippet=False)
        template.create_missing()
        template.template_kind = None
        template.template_kind_name = template_kind.name
        template = template.create(create_missing=False)
        self.assertEqual(template.template_kind.id, template_kind.id)
def discovery_settings(module_org, module_location):
    """Steps to Configure foreman discovery

    1. Build PXE default template
    2. Create Organization/Location
    3. Update Global parameters to set default org and location for
       discovered hosts.
    4. Enable auto_provision flag to perform discovery via discovery
       rules.
    """
    # Build PXE default template to get default PXE file
    entities.ProvisioningTemplate().build_pxe_default()
    # let's just modify the timeouts to speed things up
    ssh.command("sed -ie 's/TIMEOUT [[:digit:]]\\+/TIMEOUT 1/g' "
                "/var/lib/tftpboot/pxelinux.cfg/default")
    ssh.command(
        "sed -ie '/APPEND initrd/s/$/ fdi.countdown=1 fdi.ssh=1 fdi.rootpw=changeme/' "
        "/var/lib/tftpboot/pxelinux.cfg/default")
    # Get default settings values
    default_disco_settings = {
        i.name: i
        for i in entities.Setting().search(query={'search': 'name~discovery'})
    }

    # Update discovery taxonomies settings
    discovery_loc = copy(default_disco_settings['discovery_location'])
    discovery_loc.value = module_location.name
    discovery_loc.update(['value'])
    discovery_org = copy(default_disco_settings['discovery_organization'])
    discovery_org.value = module_org.name
    discovery_org.update(['value'])

    # Enable flag to auto provision discovered hosts via discovery rules
    discovery_auto = copy(default_disco_settings['discovery_auto'])
    discovery_auto.value = 'true'
    discovery_auto.update(['value'])

    yield
    # Restore default global setting's values
    default_disco_settings['discovery_location'].update(['value'])
    default_disco_settings['discovery_organization'].update(['value'])
    default_disco_settings['discovery_auto'].update(['value'])