Пример #1
0
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
Пример #2
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)
Пример #3
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)
Пример #4
0
    def test_positive_create_update_delete(self):
        """Create new location with attributes, update and delete it

        :id: e1844d9d-ec4a-44b3-9743-e932cc70020d

        :BZ: 1233612, 1234287

        :expectedresults: Location created successfully and has expected and
            correct attributes. Attributes can be updated and the location
            can be deleted.

        :CaseImportance: Critical
        """
        # Create
        description = gen_string('utf8')
        loc = make_location({
            'description':
            description,
            'subnet-ids':
            self.subnet.id,
            'puppet-environment-ids':
            self.env.id,
            'domain-ids': [self.domain.id, self.domain2.id],
            'hostgroup-ids': [self.host_group.id, self.host_group2.id],
            'medium-ids':
            self.medium["id"],
            'compute-resource-ids':
            self.comp_resource.id,
            'provisioning-templates':
            self.template.name,
            'user-ids':
            self.user.id,
        })

        self.assertEqual(loc['description'][0], description)
        self.assertIn(self.subnet.name, loc['subnets'][0])
        self.assertIn(self.subnet.network, loc['subnets'][0])
        self.assertEqual(loc['environments'][0], self.env.name)
        self.assertIn(self.domain.name, loc['domains'])
        self.assertIn(self.domain2.name, loc['domains'])
        self.assertIn(self.host_group.name, loc['hostgroups'])
        self.assertIn(self.host_group2.name, loc['hostgroups'])
        self.assertGreater(len(loc['installation-media']), 0)
        self.assertEqual(loc['installation-media'][0], self.medium['name'])
        self.assertEqual(loc['compute-resources'][0], self.comp_resource.name)
        self.assertGreaterEqual(len(loc['templates']), 1)
        # templates are returned as `name (type)` or just `name` if type is unset
        if self.template.template_kind is None:
            template_search = self.template.name
        else:
            template_search = '{} ({})'.format(
                self.template.name,
                entities.TemplateKind().search()[0].name)
        self.assertIn(template_search, loc['templates'])
        self.assertEqual(loc['users'][0], self.user.login)

        # Update
        Location.update({
            'id':
            loc['id'],
            'puppet-environment-ids': [self.env.id, self.env2.id],
            'domain-ids':
            self.domain2.id,
            'hostgroup-ids': [self.host_group2.id, self.host_group3.id],
        })
        loc = Location.info({'id': loc['id']})
        self.assertIn(self.host_group2.name, loc['hostgroups'])
        self.assertIn(self.host_group3.name, loc['hostgroups'])
        self.assertEqual(loc['domains'][0], self.domain2.name)
        self.assertIn(self.env.name, loc['environments'])
        self.assertIn(self.env2.name, loc['environments'])

        # Delete
        Location.delete({'id': loc['id']})
        with self.assertRaises(CLIReturnCodeError):
            Location.info({'id': loc['id']})
Пример #5
0
def tftpboot(module_org):
    """This fixture removes the current deployed templates from TFTP, and sets up new ones.
    It manipulates the global defaults, so it shouldn't be used in concurrent environment

    :param module_org:
    :return: A dictionary containing nailgun entities, names, values and paths of the custom
    Templates
    """
    tftpboot_path = '/var/lib/tftpboot'
    default_templates = {
        'pxegrub': {
            'setting': 'global_PXEGrub',
            'path': f'{tftpboot_path}/grub/menu.lst',
            'kind': 'PXEGrub',
        },
        'pxegrub2': {
            'setting': 'global_PXEGrub2',
            'path': f'{tftpboot_path}/grub2/grub.cfg',
            'kind': 'PXEGrub2',
        },
        'pxelinux': {
            'setting': 'global_PXELinux',
            'path': f'{tftpboot_path}/pxelinux.cfg/default',
            'kind': 'PXELinux',
        },
        'ipxe': {
            'setting': 'global_iPXE',
            'path':
            f'https://{settings.server.hostname}/unattended/iPXE?bootsrap=1',
            'kind': 'iPXE',
        },
    }
    # we keep the value of these for the teardown
    default_settings = entities.Setting().search(
        query={"search": "name ~ Global default"})
    kinds = entities.TemplateKind().search(query={"search": "name ~ PXE"})

    # clean the already-deployed default pxe configs
    ssh.command('rm {0}'.format(' '.join(
        [i['path'] for i in default_templates.values()])))

    # create custom Templates per kind
    for template in default_templates.values():
        template['entity'] = entities.ProvisioningTemplate(
            name=gen_string('alpha'),
            organization=[module_org],
            snippet=False,
            template_kind=[i.id for i in kinds
                           if i.name == template['kind']][0],
            template=f"<%= foreman_server_url %> {template['kind']}",
        ).create(create_missing=False)

        # Update the global settings to use newly created template
        template['setting_id'] = entities.Setting(
            id=[
                i.id for i in default_settings if i.name == template['setting']
            ][0],
            value=template['entity'].name,
        ).update(fields=['value'])

    yield default_templates

    # delete the deployed tftp files
    ssh.command('rm {0}'.format(' '.join(
        [i['path'] for i in default_templates.values()])))
    # set the settings back to defaults
    for setting in default_settings:
        if setting.value is None:
            setting.value = ''
        setting.update(fields=['value'] or '')
Пример #6
0
    def test_positive_end_to_end_crud(self, module_org, module_location,
                                      module_user):
        """Create a new provisioning template with several attributes, update them,
        clone the provisioning template and then delete it

        :id: 8dfbb234-7a52-4873-be72-4de086472670

        :expectedresults: Template is created, with all the given attributes, updated, cloned and
                          deleted

        :CaseImportance: Critical
        """
        cfg = get_nailgun_config()
        cfg.auth = (module_user[1], module_user[2])
        name = gen_string('alpha')
        new_name = gen_string('alpha')
        template_kind = choice(entities.TemplateKind().search())

        template = entities.ProvisioningTemplate(
            name=name,
            organization=[module_org],
            location=[module_location],
            snippet=False,
            template_kind=template_kind,
        ).create()
        assert template.name == name
        assert len(template.organization
                   ) == 1, "Template should be assigned to a single org here"
        assert template.organization[0].id == module_org.id
        assert len(
            template.location
        ) == 1, "Template should be assigned to a single location here"
        assert template.location[0].id == module_location.id
        assert template.snippet is False, "Template snippet attribute is True instead of False"
        assert template.template_kind.id == template_kind.id

        # negative create
        with pytest.raises(HTTPError) as e1:
            entities.ProvisioningTemplate(
                name=gen_choice(invalid_names_list())).create()
        assert e1.value.response.status_code == 422

        invalid = entities.ProvisioningTemplate(snippet=False)
        invalid.create_missing()
        invalid.template_kind = None
        invalid.template_kind_name = gen_string('alpha')
        with pytest.raises(HTTPError) as e2:
            invalid.create(create_missing=False)
        assert e2.value.response.status_code == 422

        # update
        assert template.template_kind.id == template_kind.id, "Template kind id doesn't match"
        updated = entities.ProvisioningTemplate(cfg,
                                                id=template.id,
                                                name=new_name).update(['name'])
        assert updated.name == new_name, "The Provisioning template wasn't properly renamed"
        # clone

        template_origin = template.read_json()
        # remove unique keys
        unique_keys = ('updated_at', 'created_at', 'id', 'name')
        template_origin = {
            key: value
            for key, value in template_origin.items() if key not in unique_keys
        }

        dupe_name = gen_choice(list(valid_data_list().values()))
        dupe_json = entities.ProvisioningTemplate(id=template.clone(
            data={'name': dupe_name})['id']).read_json()
        dupe_template = entities.ProvisioningTemplate(id=dupe_json['id'])
        dupe_json = {
            key: value
            for key, value in dupe_json.items() if key not in unique_keys
        }
        assert template_origin == dupe_json

        # delete
        dupe_template.delete()
        template.delete()
        with pytest.raises(HTTPError) as e3:
            updated.read()
        assert e3.value.response.status_code == 404