Exemplo n.º 1
0
    def test_update_location_with_multiple_host_group_to_multiple(self):
        """@Test: Create location with multiple (three) host groups assigned to
        it. Try to update location and overwrite all host groups by new
        multiple (two) host groups. Use host groups name as a parameter

        @Feature: Location

        @Assert: Location updated successfully and has correct and expected
        host groups assigned to it

        """
        host_groups = [make_hostgroup() for _ in range(3)]
        loc = make_location({
            'hostgroups': [hg['name'] for hg in host_groups],
        })
        self.assertEqual(len(loc['hostgroups']), 3)
        for host_group in host_groups:
            self.assertIn(host_group['name'], loc['hostgroups'])
        new_host_groups = [make_hostgroup() for _ in range(2)]
        Location.update({
            'hostgroups': [hg['name'] for hg in new_host_groups],
            'id': loc['id'],
        })
        loc = Location.info({'id': loc['id']})
        self.assertEqual(len(loc['hostgroups']), 2)
        for host_group in new_host_groups:
            self.assertIn(host_group['name'], loc['hostgroups'])
Exemplo n.º 2
0
    def test_positive_update_from_hostgroups_to_hostgroups(self):
        """Create location with multiple (three) host groups assigned to
        it. Try to update location and overwrite all host groups by new
        multiple (two) host groups. Use host groups name as a parameter

        :id: e53504d0-8328-485c-bc8c-36ea9a2ad3e1

        :expectedresults: Location updated successfully and has correct and
            expected host groups assigned to it

        :CaseImportance: Critical
        """
        host_groups = [make_hostgroup() for _ in range(3)]
        loc = make_location({
            'hostgroups': [hg['name'] for hg in host_groups],
        })
        self.assertEqual(len(loc['hostgroups']), 3)
        for host_group in host_groups:
            self.assertIn(host_group['name'], loc['hostgroups'])
        new_host_groups = [make_hostgroup() for _ in range(2)]
        Location.update({
            'hostgroups': [hg['name'] for hg in new_host_groups],
            'id': loc['id'],
        })
        loc = Location.info({'id': loc['id']})
        self.assertEqual(len(loc['hostgroups']), 2)
        for host_group in new_host_groups:
            self.assertIn(host_group['name'], loc['hostgroups'])
Exemplo n.º 3
0
    def test_positive_impact_delete_attribute(self):
        """Impact on variable after deleting associated attribute.

        @id: ac6f3a65-ed39-4e97-bdee-349f08bd878e

        @steps:

        1.  Create a variable with matcher for some attribute.
        2.  Delete the attribute.
        3.  Recreate the attribute with same name as earlier.

        @assert:

        1.  The matcher for deleted attribute removed from variable.
        2.  On recreating attribute, the matcher should not reappear in
        variable.

        @CaseLevel: Integration
        """
        hostgroup_name = gen_string('alpha')
        matcher_value = gen_string('alpha')
        smart_variable = make_smart_variable(
            {'puppet-class': self.puppet_class['name']})
        hostgroup = make_hostgroup({
            'name': hostgroup_name,
            'environment-id': self.env['id'],
            'puppet-class-ids': self.puppet_class['id']
        })
        SmartVariable.add_override_value({
            'smart-variable-id': smart_variable['id'],
            'match': 'hostgroup={0}'.format(hostgroup_name),
            'value': matcher_value,
        })
        smart_variable = SmartVariable.info({'id': smart_variable['id']})
        self.assertEqual(
            smart_variable['override-values']['values']['1']['match'],
            'hostgroup={0}'.format(hostgroup_name)
        )
        self.assertEqual(
            smart_variable['override-values']['values']['1']['value'],
            matcher_value,
        )
        HostGroup.delete({'id': hostgroup['id']})
        smart_variable = SmartVariable.info({'id': smart_variable['id']})
        self.assertEqual(len(smart_variable['override-values']['values']), 0)
        make_hostgroup({
            'name': hostgroup_name,
            'environment-id': self.env['id'],
            'puppet-class-ids': self.puppet_class['id']
        })
        smart_variable = SmartVariable.info({'id': smart_variable['id']})
        self.assertEqual(len(smart_variable['override-values']['values']), 0)
Exemplo n.º 4
0
    def test_positive_list_parameters_by_hostgroup_id(self):
        """List all the parameters included in specific HostGroup by id.

        @id: 80c1058d-b87d-4c09-957f-7d3daacdedf4

        @assert: Parameters listed for specific HostGroup.

        @CaseLevel: Integration
        """
        sc_param_id = self.sc_params_ids_list.pop()
        SmartClassParameter.update({
            'id': sc_param_id,
            'override': 1,
        })
        sc_param = SmartClassParameter.info({
            'puppet-class': 'ntp',
            'id': sc_param_id,
        })
        self.assertEqual(sc_param['override'], True)
        hostgroup = make_hostgroup({
            'environment-id': self.env['id'],
            'puppet-class-ids': self.puppet_class['id']
        })
        hostgroup_sc_params = HostGroup.sc_params({
            u'hostgroup-id': hostgroup['id']})
        self.assertGreater(len(hostgroup_sc_params), 0)
Exemplo n.º 5
0
    def test_positive_list_parameters_by_hostgroup_name(self):
        """List all the parameters included in specific HostGroup by its name.

        @id: a2a01ca7-4dd2-4db6-a654-a632864998d9

        @assert: Parameters listed for specific HostGroup.

        @CaseLevel: Integration
        """
        sc_param_id = self.sc_params_ids_list.pop()
        SmartClassParameter.update({
            'id': sc_param_id,
            'override': 1,
        })
        sc_param = SmartClassParameter.info({
            'puppet-class': 'ntp',
            'id': sc_param_id,
        })
        self.assertEqual(sc_param['override'], True)
        hostgroup = make_hostgroup({
            'environment-id': self.env['id'],
            'puppet-class-ids': self.puppet_class['id']
        })
        hostgroup_sc_params = HostGroup.sc_params({
            u'hostgroup': hostgroup['name']})
        self.assertGreater(len(hostgroup_sc_params), 0)
Exemplo n.º 6
0
 def setUpClass(cls):
     """Tests for discovery rules via Hammer CLI"""
     super(DiscoveryRuleRoleTestCase, cls).setUpClass()
     cls.org = make_org()
     cls.loc = make_location()
     cls.hostgroup = make_hostgroup({
         u'organization-ids': cls.org['id'],
         u'location-ids': cls.loc['id'],
     })
     cls.password = gen_alphanumeric()
     cls.user = make_user({
         'organization-ids': cls.org['id'],
         'location-ids': cls.loc['id'],
         'password': cls.password,
     })
     cls.user['password'] = cls.password
     User.add_role({
         'login': cls.user['login'],
         'role': 'Discovery Manager',
     })
     cls.user_reader = make_user({
         'organization-ids': cls.org['id'],
         'location-ids': cls.loc['id'],
         'password': cls.password,
     })
     cls.user_reader['password'] = cls.password
     User.add_role({
         'login': cls.user_reader['login'],
         'role': 'Discovery Reader',
     })
Exemplo n.º 7
0
    def test_negative_create_with_content_source(self):
        """Attempt to create a hostgroup with invalid content source specified

        :id: 9fc1b777-36a3-4940-a9c8-aed7ff725371

        :BZ: 1260697

        :expectedresults: Hostgroup was not created

        :CaseImportance: Medium
        """
        with self.assertRaises(CLIBaseError):
            make_hostgroup({
                'content-source-id': gen_integer(10000, 99999),
                'organization-ids': self.org['id'],
            })
Exemplo n.º 8
0
    def test_positive_update_content_source(self):
        """Update hostgroup's content source

        :id: c22218a1-4d86-4ac1-ad4b-79b10c9adcde

        :customerscenario: true

        :BZ: 1260697, 1313056

        :expectedresults: Hostgroup was successfully updated with new content
            source

        :CaseImportance: High
        """
        content_source = Proxy.list({
            'search': 'url = https://{0}:9090'.format(settings.server.hostname)
        })[0]
        hostgroup = make_hostgroup({
            'content-source-id': content_source['id'],
            'organization-ids': self.org['id'],
        })
        new_content_source = make_proxy()
        self.addCleanup(capsule_cleanup, new_content_source['id'])
        self.addCleanup(HostGroup.delete, {'id': hostgroup['id']})
        HostGroup.update({
            'id': hostgroup['id'],
            'content-source-id': new_content_source['id'],
        })
        hostgroup = HostGroup.info({'id': hostgroup['id']})
        self.assertEqual(
            hostgroup['content-source']['name'], new_content_source['name'])
Exemplo n.º 9
0
    def test_negative_update_content_source(self):
        """Attempt to update hostgroup's content source with invalid value

        :id: 4ffe6d18-3899-4bf1-acb2-d55ea09b7a26

        :BZ: 1260697, 1313056

        :expectedresults: Host group was not updated. Content source remains
            the same as it was before update

        :CaseImportance: Medium
        """
        content_source = Proxy.list({
            'search': 'url = https://{0}:9090'.format(settings.server.hostname)
        })[0]
        hostgroup = make_hostgroup({
            'content-source-id': content_source['id'],
            'organization-ids': self.org['id'],
        })
        with self.assertRaises(CLIBaseError):
            HostGroup.update({
                'id': hostgroup['id'],
                'content-source-id': gen_integer(10000, 99999),
            })
        hostgroup = HostGroup.info({'id': hostgroup['id']})
        self.assertEqual(
            hostgroup['content-source']['name'], content_source['name'])
Exemplo n.º 10
0
    def test_positive_list_scparams_by_id(self):
        """List all overridden smart class parameters using hostgroup id

        :id: 42a24060-2ed7-427e-8396-86d73bbe5f69

        :expectedresults: Overridden sc-param from puppet class is listed

        :Caselevel: Integration
        """
        # Create hostgroup with associated puppet class
        hostgroup = make_hostgroup({
            'puppet-classes': self.puppet_classes[0]['name'],
            'environment': self.env['name'],
            'content-view': self.cv['name'],
            'query-organization': self.org['name'],
        })
        # Override one of the sc-params from puppet class
        sc_params_list = SmartClassParameter.list({
            'environment': self.env['name'],
            'search': u'puppetclass="{0}"'.format(
                self.puppet_classes[0]['name'])
        })
        scp_id = choice(sc_params_list)['id']
        SmartClassParameter.update({'id': scp_id, 'override': 1})
        # Verify that affected sc-param is listed
        hg_scparams = HostGroup.sc_params({'hostgroup-id': hostgroup['id']})
        self.assertIn(scp_id, [scp['id'] for scp in hg_scparams])
Exemplo n.º 11
0
    def test_positive_update_org_loc(self):
        """Update org and location of selected discovery rule

        :id: 26da79aa-30e5-4052-98ae-141de071a68a

        :expectedresults: Rule was updated and with given org & location.

        :BZ: 1377990

        :CaseLevel: Integration
        """
        new_org = make_org()
        new_loc = make_location()
        new_hostgroup = make_hostgroup({
            'organization-ids': new_org['id'],
            'location-ids': new_loc['id'],
        })
        rule = self._make_discoveryrule()
        DiscoveryRule.update({
            'id': rule['id'],
            'organization-ids': new_org['id'],
            'location-ids': new_loc['id'],
            'hostgroup-id': new_hostgroup['id'],
        })
        rule = DiscoveryRule.info({'id': rule['id']})
        self.assertIn(new_org['name'], rule['organizations'])
        self.assertIn(new_loc['name'], rule['locations'])
Exemplo n.º 12
0
    def test_positive_associate_scap_policy_with_hostgroups(self):
        """Associate hostgroups to scap policy

        :id: 916403a0-572d-4cf3-9155-3e3d0373577f

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.
            3. More than 1 hostgroups

        :steps:

            1. Login to hammer shell.
            2. Execute "policy" command with "create" as sub-command.
            3. Pass valid parameters.
            4. Associate multiple hostgroups with policy

        :expectedresults: The policy is created and associated successfully.
        """
        hostgroup = make_hostgroup()
        name = gen_string('alphanumeric')
        scap_policy = make_scap_policy({
            'name': name,
            'scap-content-id': self.scap_id_rhel6,
            'scap-content-profile-id': self.scap_profile_id_rhel6,
            'period': OSCAP_PERIOD['weekly'].lower(),
            'weekday': OSCAP_WEEKDAY['friday'].lower(),
            'hostgroups': hostgroup['name']
        })
        self.assertEqual(scap_policy['hostgroups'][0], hostgroup['name'])
Exemplo n.º 13
0
 def test_add_hostgroup(self):
     "Adds a hostgroup in an org"
     org_result = make_org()
     hostgroup_result = make_hostgroup()
     return_value = Org().add_hostgroup({
             'name': org_result['name'],
             'hostgroup': hostgroup_result['name']})
     self.assertTrue(return_value.return_code, 0)
     self.assertFalse(return_value.stderr)
Exemplo n.º 14
0
 def setUpClass(cls):
     """Tests for discovery rules via Hammer CLI"""
     super(DiscoveryRuleTestCase, cls).setUpClass()
     cls.org = make_org()
     cls.loc = make_location()
     cls.hostgroup = make_hostgroup({
         u'organization-ids': cls.org['id'],
         u'location-ids': cls.loc['id'],
     })
Exemplo n.º 15
0
    def test_positive_add_and_remove_hostgroups(self):
        """add and remove a hostgroup from an organization

        :id: 34e2c7c8-dc20-4709-a5a9-83c0dee9d84d

        :expectedresults: Hostgroups are handled as expected

        :bz: 1395229

        :steps:
            1. add and remove hostgroup by name
            2. add and remove hostgroup by id

        :CaseLevel: Integration
        """
        org = make_org()
        hostgroup_a = make_hostgroup()
        hostgroup_b = make_hostgroup()
        Org.add_hostgroup({
            'hostgroup-id': hostgroup_a['id'],
            'id': org['id'],
        })
        Org.add_hostgroup({
            'hostgroup': hostgroup_b['name'],
            'name': org['name'],
        })
        org_info = Org.info({'name': org['name']})
        self.assertIn(hostgroup_a['name'], org_info['hostgroups'],
                      "Failed to add hostgroup by id")
        self.assertIn(hostgroup_b['name'], org_info['hostgroups'],
                      "Failed to add hostgroup by name")
        Org.remove_hostgroup({
            'hostgroup-id': hostgroup_b['id'],
            'id': org['id'],
        })
        Org.remove_hostgroup({
            'hostgroup': hostgroup_a['name'],
            'name': org['name'],
        })
        org_info = Org.info({'id': org['id']})
        self.assertNotIn(hostgroup_a['name'], org_info['hostgroups'],
                         "Failed to remove hostgroup by name")
        self.assertNotIn(hostgroup_b['name'], org_info['hostgroups'],
                         "Failed to remove hostgroup by id")
Exemplo n.º 16
0
    def test_positive_create_with_domain(self):
        """Check if hostgroup with domain can be created

        @id: c468fcac-9e42-4ee6-a431-abe29b6848ce

        @Assert: Hostgroup should be created and has domain assigned
        """
        domain = make_domain()
        hostgroup = make_hostgroup({'domain-id': domain['id']})
        self.assertEqual(domain['name'], hostgroup['domain'])
Exemplo n.º 17
0
    def test_create_hostgroup_with_environment(self):
        """@Test: Check if hostgroup with environment can be created

        @Feature: Hostgroup - Positive create

        @Assert: Hostgroup is created and has new environment assigned

        """
        environment = make_environment()
        hostgroup = make_hostgroup({'environment-id': environment['id']})
        self.assertEqual(environment['name'], hostgroup['environment'])
Exemplo n.º 18
0
    def test_create_hostgroup_with_operating_system(self):
        """@Test: Check if hostgroup with operating system can be created

        @Feature: Hostgroup - Create

        @Assert: Hostgroup is created and has operating system assigned

        """
        os = make_os()
        hostgroup = make_hostgroup({'operatingsystem-id': os['id']})
        self.assertEqual(hostgroup['operating-system'], os['title'])
Exemplo n.º 19
0
    def test_positive_create_with_loc(self):
        """Check if hostgroup with location can be created

        @id: 84ae02a4-ea7e-43ce-87bd-7bbde3766b14

        @Assert: Hostgroup is created and has new location assigned

        """
        location = make_location()
        hostgroup = make_hostgroup({'location-ids': location['id']})
        self.assertIn(location['name'], hostgroup['locations'])
Exemplo n.º 20
0
    def test_positive_create_with_env(self):
        """Check if hostgroup with environment can be created

        @id: f1bfb333-90cf-4a9f-b183-cf77c1773247

        @Assert: Hostgroup is created and has new environment assigned

        """
        environment = make_environment()
        hostgroup = make_hostgroup({'environment-id': environment['id']})
        self.assertEqual(environment['name'], hostgroup['environment'])
Exemplo n.º 21
0
    def test_positive_create_with_name(self):
        """Successfully creates an HostGroup.

        @id: f5f2056f-d090-4e0d-8fb9-d29255a47908

        @Assert: HostGroup is created.
        """
        for name in valid_hostgroups_list():
            with self.subTest(name):
                hostgroup = make_hostgroup({'name': name})
                self.assertEqual(hostgroup['name'], name)
Exemplo n.º 22
0
    def test_positive_create_with_puppet_ca_proxy(self):
        """Check if hostgroup with puppet CA proxy server can be created

        @id: f7ea1c94-8a0e-4500-98b3-0ecd63b3ce3c

        @Assert: Hostgroup is created and has puppet CA proxy server assigned

        """
        puppet_proxy = Proxy.list()[0]
        hostgroup = make_hostgroup({'puppet-ca-proxy': puppet_proxy['name']})
        self.assertEqual(puppet_proxy['id'], hostgroup['puppet-ca-proxy-id'])
Exemplo n.º 23
0
    def test_positive_create_with_org(self):
        """Check if hostgroup with organization can be created

        @id: 780d4b93-f35a-4c5b-a645-4053aed4c37b

        @Assert: Hostgroup is created and has new organization assigned

        """
        org = make_org()
        hostgroup = make_hostgroup({'organization-ids': org['id']})
        self.assertIn(org['name'], hostgroup['organizations'])
Exemplo n.º 24
0
    def test_create_hostgroup_with_puppet_ca_proxy(self):
        """@Test: Check if hostgroup with puppet CA proxy server can be created

        @Feature: Hostgroup - Positive create

        @Assert: Hostgroup is created and has puppet CA proxy server assigned

        """
        puppet_proxy = Proxy.list()[0]
        hostgroup = make_hostgroup({'puppet-ca-proxy': puppet_proxy['name']})
        self.assertEqual(puppet_proxy['id'], hostgroup['puppet-ca-proxy-id'])
Exemplo n.º 25
0
    def test_positive_create_with_name(self):
        """Successfully creates an HostGroup.

        @Feature: HostGroup

        @Assert: HostGroup is created.
        """
        for name in valid_hostgroups_list():
            with self.subTest(name):
                hostgroup = make_hostgroup({'name': name})
                self.assertEqual(hostgroup['name'], name)
Exemplo n.º 26
0
    def test_positive_create_with_os(self):
        """Check if hostgroup with operating system can be created

        @id: d12c5939-1aac-44f5-8aa3-a04a824f4e83

        @Assert: Hostgroup is created and has operating system assigned

        """
        os = make_os()
        hostgroup = make_hostgroup({'operatingsystem-id': os['id']})
        self.assertEqual(hostgroup['operating-system'], os['title'])
Exemplo n.º 27
0
    def test_create_hostgroup_with_organization(self):
        """@Test: Check if hostgroup with organization can be created

        @Feature: Hostgroup - Positive create

        @Assert: Hostgroup is created and has new organization assigned

        """
        org = make_org()
        hostgroup = make_hostgroup({'organization-ids': org['id']})
        self.assertIn(org['name'], hostgroup['organizations'])
Exemplo n.º 28
0
    def test_create_hostgroup_with_location(self):
        """@Test: Check if hostgroup with location can be created

        @Feature: Hostgroup - Positive create

        @Assert: Hostgroup is created and has new location assigned

        """
        location = make_location()
        hostgroup = make_hostgroup({"location-ids": location["id"]})
        self.assertIn(location["name"], hostgroup["locations"])
Exemplo n.º 29
0
    def test_create_hostgroup_with_location(self):
        """@Test: Check if hostgroup with location can be created

        @Feature: Hostgroup - Positive create

        @Assert: Hostgroup is created and has new location assigned

        """
        location = make_location()
        hostgroup = make_hostgroup({'location-ids': location['id']})
        self.assertIn(location['name'], hostgroup['locations'])
Exemplo n.º 30
0
    def test_create_hostgroup_with_organization(self):
        """@Test: Check if hostgroup with organization can be created

        @Feature: Hostgroup - Positive create

        @Assert: Hostgroup is created and has new organization assigned

        """
        org = make_org()
        hostgroup = make_hostgroup({"organization-ids": org["id"]})
        self.assertIn(org["name"], hostgroup["organizations"])
Exemplo n.º 31
0
    def test_positive_create_with_multiple_entities_ids(self):
        """Check if hostgroup with multiple options ids can be created

        :id: 6277613b-0ece-4dee-b9d8-504f8299ac38

        :expectedresults: Hostgroup should be created and has all defined
            entities assigned

        :BZ: 1395254, 1313056

        :CaseLevel: Integration
        """
        # Common entities
        loc = make_location()
        org = make_org()
        env = make_environment({
            'location-ids': loc['id'],
            'organization-ids': org['id'],
        })
        lce = make_lifecycle_environment({'organization-id': org['id']})
        proxy = Proxy.list({
            'search': 'url = https://{0}:9090'.format(settings.server.hostname)
        })[0]
        # Content View should be promoted to be used with LC Env
        cv = make_content_view({'organization-id': org['id']})
        ContentView.publish({'id': cv['id']})
        cv = ContentView.info({'id': cv['id']})
        ContentView.version_promote({
            'id': cv['versions'][0]['id'],
            'to-lifecycle-environment-id': lce['id'],
        })
        # Network
        domain = make_domain({
            'location-ids': loc['id'],
            'organization-ids': org['id'],
        })
        subnet = make_subnet({
            'domain-ids': domain['id'],
            'organization-ids': org['id'],
        })
        # Operating System
        arch = make_architecture()
        ptable = make_partition_table({
            'location-ids': loc['id'],
            'organization-ids': org['id'],
        })
        os = make_os({
            'architecture-ids': arch['id'],
            'partition-table-ids': ptable['id'],
        })
        media = make_medium({
            'operatingsystem-ids': os['id'],
            'location-ids': loc['id'],
            'organization-ids': org['id'],
        })
        make_hostgroup_params = {
            'location-ids': loc['id'],
            'environment-id': env['id'],
            'lifecycle-environment-id': lce['id'],
            'puppet-proxy-id': proxy['id'],
            'puppet-ca-proxy-id': proxy['id'],
            'content-source-id': proxy['id'],
            'content-view-id': cv['id'],
            'domain-id': domain['id'],
            'subnet-id': subnet['id'],
            'organization-ids': org['id'],
            'architecture-id': arch['id'],
            'partition-table-id': ptable['id'],
            'medium-id': media['id'],
            'operatingsystem-id': os['id'],
        }
        hostgroup = make_hostgroup(make_hostgroup_params)
        self.assertEqual(cv['id'], hostgroup['content-view']['id'])
        self.assertEqual(lce['id'], hostgroup['lifecycle-environment']['id'])
        self.assertEqual(proxy['id'], hostgroup['content-source']['id'])
        # get the json output format
        hostgroup = HostGroup.info(
            {'id': hostgroup['id']}, output_format='json')
        self.assertIn(org['id'], hostgroup['organizations'][0]['id'])
        self.assertIn(loc['id'], hostgroup['locations'][0]['id'])
        self.assertEqual(
            env['id'], hostgroup['puppet-environment']['id'])
        self.assertEqual(
            proxy['id'],
            hostgroup['puppet-master-proxy']['id']
        )
        self.assertEqual(
            proxy['id'],
            hostgroup['puppet-ca-proxy']['id']
        )
        self.assertEqual(
            domain['id'],
            hostgroup['network']['domain']['id']
        )
        self.assertEqual(
            subnet['id'],
            hostgroup['network']['subnet-ipv4']['id'])
        self.assertEqual(
            arch['id'], hostgroup['operating-system']['architecture']['id'])
        self.assertEqual(
            ptable['id'], hostgroup['operating-system']['partition-table']['id'])
        self.assertEqual(
            media['id'],
            hostgroup['operating-system']['medium']['id']
        )
        self.assertEqual(
            os['id'], hostgroup['operating-system']['operating-system']['id'])
Exemplo n.º 32
0
    def test_positive_create_with_synced_content(self):
        """Check if hostgroup with synced kickstart repository can be created

        :id: 7c51ac72-359c-488a-8658-88b5a94d7e7a

        :customerscenario: true

        :expectedresults: Hostgroup should be created and has proper
            installation content id present

        :BZ: 1415707

        :CaseLevel: Integration
        """
        # Check whether path to kickstart media is set
        if settings.rhel6_os is None:
            raise ValueError(
                'Installation media path is not set in properties file')
        # Common entities
        org = make_org()
        lce = make_lifecycle_environment({'organization-id': org['id']})
        product = make_product({'organization-id': org['id']})
        repo = make_repository({
            u'url': settings.rhel6_os,
            u'product-id': product['id'],
            u'content-type': u'yum',
        })
        Repository.synchronize({'id': repo['id']})

        cv = make_content_view({
            'organization-id': org['id'],
            'repository-ids': [repo['id']],
        })
        ContentView.publish({'id': cv['id']})
        cv = ContentView.info({'id': cv['id']})
        cvv = cv['versions'][0]
        ContentView.version_promote({
            'id': cvv['id'],
            'to-lifecycle-environment-id': lce['id'],
        })

        # Get the Partition table ID
        ptable = PartitionTable.info({'name': DEFAULT_PTABLE})

        # Get the arch ID
        arch = Architecture.list({
            'search': 'name={0}'.format(DEFAULT_ARCHITECTURE)})[0]

        # Get the OS ID
        os = OperatingSys.list({
            'search': 'name="RedHat" AND major="{0}" OR major="{1}"'.format(
                RHEL_6_MAJOR_VERSION, RHEL_7_MAJOR_VERSION)
        })[0]

        # Update the OS with found arch and ptable
        OperatingSys.update({
            'id': os['id'],
            'architectures': arch['name'],
            'partition-tables': ptable['name'],
        })
        proxy = Proxy.list({
            'search': 'url = https://{0}:9090'.format(settings.server.hostname)
        })[0]

        # Search for proper installation repository id
        synced_repo = Repository.list({
            'content-view-version-id': cvv['id'],
            'organization-id': org['id'],
            'environment-id': lce['id'],
        })[0]
        hostgroup = make_hostgroup({
            'lifecycle-environment-id': lce['id'],
            'puppet-proxy-id': proxy['id'],
            'puppet-ca-proxy-id': proxy['id'],
            'content-source-id': proxy['id'],
            'content-view-id': cv['id'],
            'organization-ids': org['id'],
            'architecture-id': arch['id'],
            'partition-table-id': ptable['id'],
            'operatingsystem-id': os['id'],
            'kickstart-repository-id': synced_repo['id'],
        })
        hg = HostGroup.info({'id': hostgroup['id']}, output_format='json')
        self.assertEqual(
            hg['kickstart-repository']['id'],
            synced_repo['id']
        )
Exemplo n.º 33
0
def test_positive_oscap_run_via_ansible(module_org, default_proxy,
                                        content_view, lifecycle_env, distro,
                                        default_sat):
    """End-to-End Oscap run via ansible

    :id: c7ea56eb-6cf1-4e79-8d6a-fb872d1bb804

    :parametrized: yes

    :setup: scap content, scap policy, host group

    :steps:

        1. Create a valid scap content
        2. Import Ansible role theforeman.foreman_scap_client
        3. Import Ansible Variables needed for the role
        4. Create a scap policy with anisble as deploy option
        5. Associate the policy with a hostgroup
        6. Provision a host using the hostgroup
        7. Configure REX and associate the Ansible role to created host
        8. Play roles for the host

    :expectedresults: REX job should be success and ARF report should be sent to satellite

    :BZ: 1716307

    :CaseImportance: Critical
    """
    if distro == 'rhel6':
        rhel_repo = settings.repos.rhel6_os
        profile = OSCAP_PROFILE['dsrhel6']
    elif distro == 'rhel7':
        rhel_repo = settings.repos.rhel7_os
        profile = OSCAP_PROFILE['security7']
    else:
        rhel_repo = settings.repos.rhel8_os
        profile = OSCAP_PROFILE['ospp8']
    content = OSCAP_DEFAULT_CONTENT[f'{distro}_content']
    hgrp_name = gen_string('alpha')
    policy_name = gen_string('alpha')
    # Creates host_group for rhel7
    make_hostgroup({
        'content-source-id': default_proxy,
        'name': hgrp_name,
        'organizations': module_org.name,
    })
    # Creates oscap_policy.
    scap_id, scap_profile_id = fetch_scap_and_profile_id(content, profile)
    Ansible.roles_import({'proxy-id': default_proxy})
    Ansible.variables_import({'proxy-id': default_proxy})
    role_id = Ansible.roles_list({'search':
                                  'foreman_scap_client'})[0].get('id')
    make_scap_policy({
        'scap-content-id': scap_id,
        'hostgroups': hgrp_name,
        'deploy-by': 'ansible',
        'name': policy_name,
        'period': OSCAP_PERIOD['weekly'].lower(),
        'scap-content-profile-id': scap_profile_id,
        'weekday': OSCAP_WEEKDAY['friday'].lower(),
        'organizations': module_org.name,
    })
    with VMBroker(
            nick=distro,
            host_classes={'host': ContentHost},
            target_cores=OSCAP_TARGET_CORES,
            target_memory=OSCAP_TARGET_MEMORY,
    ) as vm:
        host_name, _, host_domain = vm.hostname.partition('.')
        vm.install_katello_ca(default_sat)
        vm.register_contenthost(module_org.name, ak_name[distro])
        assert vm.subscribed
        Host.set_parameter({
            'host': vm.hostname.lower(),
            'name': 'remote_execution_connect_by_ip',
            'value': 'True',
            'parameter-type': 'boolean',
        })
        if distro not in (DISTRO_RHEL6, DISTRO_RHEL7):
            vm.create_custom_repos(**rhel_repo)
        else:
            vm.create_custom_repos(**{distro: rhel_repo})
        vm.add_rex_key(satellite=default_sat)
        Host.update({
            'name': vm.hostname.lower(),
            'lifecycle-environment': lifecycle_env.name,
            'content-view': content_view.name,
            'hostgroup': hgrp_name,
            'openscap-proxy-id': default_proxy,
            'organization': module_org.name,
            'ansible-role-ids': role_id,
        })
        job_id = Host.ansible_roles_play({'name':
                                          vm.hostname.lower()})[0].get('id')
        wait_for_tasks(
            f'resource_type = JobInvocation and resource_id = {job_id} and action ~ "hosts job"'
        )
        try:
            result = JobInvocation.info({'id': job_id})['success']
            assert result == '1'
        except AssertionError:
            output = ' '.join(
                JobInvocation.get_output({
                    'id': job_id,
                    'host': vm.hostname
                }))
            result = f'host output: {output}'
            raise AssertionError(result)
        result = vm.run(
            'cat /etc/foreman_scap_client/config.yaml | grep profile')
        assert result.status == 0
        # Runs the actual oscap scan on the vm/clients and
        # uploads report to Internal Capsule.
        vm.execute_foreman_scap_client()
        # Assert whether oscap reports are uploaded to
        # Satellite6.
        result = Arfreport.list({'search': f'host={vm.hostname.lower()}'})
        assert result is not None
Exemplo n.º 34
0
    def test_positive_create_with_multiple_entities_name(self):
        """Check if hostgroup with multiple options name can be created

        :id: a3ef4f0e-971d-4307-8d0a-35103dff6586

        :expectedresults: Hostgroup should be created and has all defined
            entities assigned

        :BZ: 1395254, 1313056

        :CaseLevel: Integration
        """
        # Common entities
        loc = make_location()
        org = make_org()
        env = make_environment({
            'location-ids': loc['id'],
            'organization-ids': org['id'],
        })
        lce = make_lifecycle_environment({'organization-id': org['id']})
        proxy = Proxy.list({
            'search': 'url = https://{0}:9090'.format(settings.server.hostname)
        })[0]
        # Content View should be promoted to be used with LC Env
        cv = make_content_view({'organization-id': org['id']})
        ContentView.publish({'id': cv['id']})
        cv = ContentView.info({'id': cv['id']})
        ContentView.version_promote({
            'id': cv['versions'][0]['id'],
            'to-lifecycle-environment-id': lce['id'],
        })
        # Network
        domain = make_domain({
            'location-ids': loc['id'],
            'organization-ids': org['id'],
        })
        subnet = make_subnet({
            'domain-ids': domain['id'],
            'organization-ids': org['id'],
        })
        # Operating System
        arch = make_architecture()
        ptable = make_partition_table({
            'location-ids': loc['id'],
            'organization-ids': org['id'],
        })
        os = make_os({
            'architecture-ids': arch['id'],
            'partition-table-ids': ptable['id'],
        })
        os_full_name = "{0} {1}.{2}".format(
            os['name'],
            os['major-version'],
            os['minor-version']
        )
        media = make_medium({
            'operatingsystem-ids': os['id'],
            'location-ids': loc['id'],
            'organization-ids': org['id'],
        })
        # Note: in the current hammer version there is no content source name
        # option
        make_hostgroup_params = {
            'organizations': org['name'],
            'locations': loc['name'],
            'environment': env['name'],
            'lifecycle-environment': lce['name'],
            'puppet-proxy': proxy['name'],
            'puppet-ca-proxy': proxy['name'],
            'content-source-id': proxy['id'],
            'content-view': cv['name'],
            'domain': domain['name'],
            'subnet': subnet['name'],
            'architecture': arch['name'],
            'partition-table': ptable['name'],
            'medium': media['name'],
            'operatingsystem':  os_full_name,
            'query-organization': org['name']
        }
        hostgroup = make_hostgroup(make_hostgroup_params)
        self.assertIn(org['name'], hostgroup['organizations'])
        self.assertIn(loc['name'], hostgroup['locations'])
        self.assertEqual(env['name'], hostgroup['puppet-environment'])
        self.assertEqual(proxy['name'], hostgroup['puppet-master-proxy'])
        self.assertEqual(proxy['name'], hostgroup['puppet-ca-proxy'])
        self.assertEqual(domain['name'], hostgroup['network']['domain'])
        self.assertEqual(subnet['name'], hostgroup['network']['subnet-ipv4'])
        self.assertEqual(
            arch['name'],
            hostgroup['operating-system']['architecture']
        )
        self.assertEqual(
            ptable['name'],
            hostgroup['operating-system']['partition-table']
        )
        self.assertEqual(
            media['name'],
            hostgroup['operating-system']['medium']
        )
        self.assertEqual(
            os_full_name,
            hostgroup['operating-system']['operating-system']
        )
        self.assertEqual(
            cv['name'],
            hostgroup['content-view']['name'])
        self.assertEqual(
            lce['name'], hostgroup['lifecycle-environment']['name'])
        self.assertEqual(proxy['name'], hostgroup['content-source']['name'])