def __init__(self, server_config=None, **kwargs):
     self._fields = {
         'set_console_password': entity_fields.BooleanField(),
         'user': entity_fields.StringField(),
         'password': entity_fields.StringField()
     }
     super(OVirtComputeResource, self).__init__(server_config, **kwargs)
     self._fields['provider'].default = 'Ovirt'
     self._fields['provider'].required = True
     self._fields['provider_friendly_name'].default = 'OVirt'
Esempio n. 2
0
    def test_length_arg(self):
        """Ensure that the ``length`` argument is respected."""
        # What happens when we pass in an exact length?
        string = entity_fields.StringField(length=5).gen_value()
        self.assertEqual(len(string), 5)

        # What happens when we pass in a range of lengths?
        string = entity_fields.StringField(length=(1, 20)).gen_value()
        self.assertGreaterEqual(len(string), 1)
        self.assertLessEqual(len(string), 20)
Esempio n. 3
0
    def test_str_type_arg(self):
        """Ensure that the ``str_type`` argument is respected."""
        # This method uses single-use variables. But the code just looks
        # ridiculous if they are eliminated.
        for str_type in ('alpha', ('alpha', )):
            string = entity_fields.StringField(str_type=str_type).gen_value()
            self.assertTrue(string.isalpha())
        for str_type in ('numeric', ('numeric', )):
            string = entity_fields.StringField(str_type=str_type).gen_value()
            self.assertTrue(string.isnumeric())

        str_type = ('alpha', 'numeric')
        string = entity_fields.StringField(str_type=str_type).gen_value()
        self.assertTrue(string.isalpha() or string.isnumeric())
Esempio n. 4
0
 def __init__(self, server_config=None, **kwargs):
     _check_for_value('template', kwargs)
     self._fields = {
         'advanced': entity_fields.BooleanField(),
         'description': entity_fields.StringField(),
         'fact_name': entity_fields.StringField(),
         'input_type': entity_fields.StringField(),
         'name': entity_fields.StringField(),
         'options': entity_fields.StringField(),
         'puppet_class_name': entity_fields.StringField(),
         'puppet_parameter_name': entity_fields.StringField(),
         'required': entity_fields.BooleanField(),
         # There is no Template base class yet
         'template': entity_fields.OneToOneField(JobTemplate, required=True),
         'variable_name': entity_fields.StringField(),
     }
     super(TemplateInput, self).__init__(server_config, **kwargs)
     self._meta = {
         'api_path': '/api/v2/templates/{0}/template_inputs'.format(self.template.id),
         'server_modes': ('sat')
     }
Esempio n. 5
0
 def __init__(self, server_config=None, **kwargs):
     self._fields = {
         'audit_comment': entity_fields.StringField(),
         'description_format': entity_fields.StringField(),
         'effective_user': entity_fields.DictField(),
         'job_category': entity_fields.StringField(),
         'location': entity_fields.OneToManyField(Location),
         'locked': entity_fields.BooleanField(),
         'name': entity_fields.StringField(),
         'organization': entity_fields.OneToManyField(Organization),
         'provider_type': entity_fields.StringField(),
         'snippet': entity_fields.BooleanField(),
         'template': entity_fields.StringField(),
         'template_inputs': entity_fields.OneToManyField(TemplateInput),
     }
     self._meta = {
         'api_path': 'api/v2/job_templates',
         'server_modes': ('sat')}
     super(JobTemplate, self).__init__(server_config, **kwargs)
Esempio n. 6
0
    def test_inherit_puppetclass(self):
        """Host that created from HostGroup entity with PuppetClass
        assigned to it should inherit such puppet class information under
        'all_puppetclasses' field

        :id: 7b840f3d-413c-40bb-9a7d-cd9dad3c0737

        :expectedresults: Host inherited 'all_puppetclasses' details from
            HostGroup that was used for such Host create procedure

        :BZ: 1107708, 1222118, 1487586

        :CaseLevel: System
        """
        # Creating entities like organization, content view and lifecycle_env
        # with not utf-8 names for easier interaction with puppet environment
        # further in test
        org = entities.Organization(name=gen_string('alpha')).create()
        location = entities.Location(organization=[org]).create()
        # Creating puppet repository with puppet module assigned to it
        product = entities.Product(organization=org).create()
        puppet_repo = entities.Repository(content_type='puppet',
                                          product=product).create()
        # Working with 'ntp' module as we know for sure that it contains at
        # least few puppet classes
        with open(get_data_file(PUPPET_MODULE_NTP_PUPPETLABS), 'rb') as handle:
            puppet_repo.upload_content(files={'content': handle})

        content_view = entities.ContentView(name=gen_string('alpha'),
                                            organization=org).create()

        result = content_view.available_puppet_modules()['results']
        assert len(result) == 1
        entities.ContentViewPuppetModule(author=result[0]['author'],
                                         name=result[0]['name'],
                                         content_view=content_view).create()
        content_view.publish()
        content_view = content_view.read()
        lc_env = entities.LifecycleEnvironment(name=gen_string('alpha'),
                                               organization=org).create()
        promote(content_view.version[0], lc_env.id)
        content_view = content_view.read()
        assert len(content_view.version) == 1
        assert len(content_view.puppet_module) == 1

        # Form environment name variable for our test
        env_name = f'KT_{org.name}_{lc_env.name}_{content_view.name}_{content_view.id}'

        # Get all environments for current organization.
        # We have two environments (one created after publishing and one more
        # was created after promotion), so we need to select promoted one
        environments = entities.Environment().search(
            query={'organization_id': org.id})
        assert len(environments) == 2
        environments = [
            environment for environment in environments
            if environment.name == env_name
        ]
        assert len(environments) == 1
        environment = environments[0].read()
        environment.location = [location]
        environment.update()

        # Create a host group and it dependencies.
        mac = entity_fields.MACAddressField().gen_value()
        root_pass = entity_fields.StringField(length=(8, 30)).gen_value()
        domain = entities.Domain().create()
        architecture = entities.Architecture().create()
        ptable = entities.PartitionTable().create()
        operatingsystem = entities.OperatingSystem(architecture=[architecture],
                                                   ptable=[ptable]).create()
        medium = entities.Media(operatingsystem=[operatingsystem]).create()
        hostgroup = entities.HostGroup(
            architecture=architecture,
            domain=domain,
            environment=environment,
            location=[location.id],
            medium=medium,
            name=gen_string('alpha'),
            operatingsystem=operatingsystem,
            organization=[org.id],
            ptable=ptable,
        ).create()
        assert len(hostgroup.read_json()['all_puppetclasses']) == 0

        # Get puppet class id for ntp module
        response = client.get(
            environment.path('self') + '/puppetclasses',
            auth=get_credentials(),
            verify=False,
        )
        response.raise_for_status()
        results = response.json()['results']
        puppet_class_id = results['ntp'][0]['id']

        # Assign puppet class
        client.post(
            hostgroup.path('self') + '/puppetclass_ids',
            data={
                'puppetclass_id': puppet_class_id
            },
            auth=get_credentials(),
            verify=False,
        ).raise_for_status()
        hostgroup_attrs = hostgroup.read_json()
        assert len(hostgroup_attrs['all_puppetclasses']) == 1
        assert hostgroup_attrs['all_puppetclasses'][0]['name'] == 'ntp'

        # Create Host entity using HostGroup
        host = entities.Host(
            hostgroup=hostgroup,
            mac=mac,
            root_pass=root_pass,
            environment=environment,
            location=location,
            organization=org,
            content_facet_attributes={
                'content_view_id': content_view.id,
                'lifecycle_environment_id': lc_env.id,
            },
            name=gen_string('alpha'),
        ).create(False)
        host_attrs = host.read_json()
        assert len(host_attrs['all_puppetclasses']) == 1
        assert host_attrs['all_puppetclasses'][0]['name'] == 'ntp'
Esempio n. 7
0
    def test_inherit_puppetclass(self, session_puppet_enabled_sat):
        """Host that created from HostGroup entity with PuppetClass
        assigned to it should inherit such puppet class information under
        'all_puppetclasses' field

        :id: 7b840f3d-413c-40bb-9a7d-cd9dad3c0737

        :expectedresults: Host inherited 'all_puppetclasses' details from
            HostGroup that was used for such Host create procedure

        :BZ: 1107708, 1222118, 1487586

        :CaseLevel: System
        """
        # Creating entities like organization, content view and lifecycle_env
        # with not utf-8 names for easier interaction with puppet environment
        # further in test
        org = session_puppet_enabled_sat.api.Organization(
            name=gen_string('alpha')).create()
        location = session_puppet_enabled_sat.api.Location(
            organization=[org]).create()

        # Working with 'api_test_classparameters' module as we know for sure that it contains
        # at least few puppet classes, the name of the repo is the same as the name of puppet_class
        repo = puppet_class = 'api_test_classparameters'
        env_name = session_puppet_enabled_sat.create_custom_environment(
            repo=repo)
        content_view = session_puppet_enabled_sat.api.ContentView(
            name=gen_string('alpha'), organization=org).create()
        content_view.publish()
        content_view = content_view.read()
        lc_env = session_puppet_enabled_sat.api.LifecycleEnvironment(
            name=gen_string('alpha'), organization=org).create()
        promote(content_view.version[0], lc_env.id)
        content_view = content_view.read()
        assert len(content_view.version) == 1

        # Get environments that contains chosen puppet module
        environment = session_puppet_enabled_sat.api.Environment().search(
            query={'search': f'name={env_name}'})
        assert len(environment) == 1
        environment = environment[0]
        environment.location = [location]
        environment.organization = [org]
        environment.update()

        # Create a host group and it dependencies.
        mac = entity_fields.MACAddressField().gen_value()
        root_pass = entity_fields.StringField(length=(8, 30)).gen_value()
        domain = session_puppet_enabled_sat.api.Domain().create()
        architecture = session_puppet_enabled_sat.api.Architecture().create()
        ptable = session_puppet_enabled_sat.api.PartitionTable().create()
        operatingsystem = session_puppet_enabled_sat.api.OperatingSystem(
            architecture=[architecture], ptable=[ptable]).create()
        medium = session_puppet_enabled_sat.api.Media(
            operatingsystem=[operatingsystem]).create()
        hostgroup = session_puppet_enabled_sat.api.HostGroup(
            architecture=architecture,
            domain=domain,
            environment=environment,
            location=[location.id],
            medium=medium,
            name=gen_string('alpha'),
            operatingsystem=operatingsystem,
            organization=[org.id],
            ptable=ptable,
        ).create()
        assert len(hostgroup.read_json()['all_puppetclasses']) == 0

        # Get puppet class id for ntp module
        response = client.get(
            environment.path('self') + '/puppetclasses',
            auth=get_credentials(),
            verify=False,
        )
        response.raise_for_status()
        results = response.json()['results']
        puppet_class_id = results[puppet_class][0]['id']

        # Assign puppet class
        client.post(
            hostgroup.path('self') + '/puppetclass_ids',
            data={
                'puppetclass_id': puppet_class_id
            },
            auth=get_credentials(),
            verify=False,
        ).raise_for_status()
        hostgroup_attrs = hostgroup.read_json()
        assert len(hostgroup_attrs['all_puppetclasses']) == 1
        assert hostgroup_attrs['all_puppetclasses'][0]['name'] == puppet_class

        # Create Host entity using HostGroup
        host = session_puppet_enabled_sat.api.Host(
            hostgroup=hostgroup,
            mac=mac,
            root_pass=root_pass,
            environment=environment,
            location=location,
            organization=org,
            content_facet_attributes={
                'content_view_id': content_view.id,
                'lifecycle_environment_id': lc_env.id,
            },
            name=gen_string('alpha'),
        ).create(False)
        host_attrs = host.read_json()
        assert len(host_attrs['all_puppetclasses']) == 1
        assert host_attrs['all_puppetclasses'][0]['name'] == puppet_class
Esempio n. 8
0
 def test_str_is_returned(self):
     """Ensure a unicode string at least 1 char long is returned."""
     string = entity_fields.StringField().gen_value()
     self.assertIsInstance(string, type(u''))
     self.assertGreater(len(string), 0)