Esempio n. 1
0
    def test_positive_debug_option(self):
        """ Verify debug option by "PUT

        /foreman_virt_who_configure/api/v2/configs/:id"

        :id: 75a20b8c-bed8-4c55-b291-14bca6cac364

        :expectedresults: debug option can be updated.

        :CaseLevel: Integration

        :CaseImportance: Medium
        """
        name = gen_string('alpha')
        args = self._make_virtwho_configure()
        args.update({'name': name})
        vhd = entities.VirtWhoConfig(**args).create()
        options = {'true': '1', 'false': '0', '1': '1', '0': '0'}
        for key, value in sorted(options.items(), key=lambda item: item[0]):
            vhd.debug = key
            vhd.update(['debug'])
            command = get_configure_command(vhd.id)
            deploy_configure_by_command(command)
            self.assertEqual(
                get_configure_option('VIRTWHO_DEBUG', VIRTWHO_SYSCONFIG),
                value)
        vhd.delete()
        self.assertFalse(entities.VirtWhoConfig().search(
            query={'search': 'name={}'.format(name)}))
Esempio n. 2
0
    def test_positive_proxy_option(self):
        """ Verify http_proxy option by "PUT

        /foreman_virt_who_configure/api/v2/configs/:id""

        :id: 11352fee-5e00-4b24-9515-30a790685ede

        :expectedresults: http_proxy and no_proxy option can be updated.

        :CaseLevel: Integration

        :CaseImportance: Medium
        """
        name = gen_string('alpha')
        args = self._make_virtwho_configure()
        args.update({'name': name})
        vhd = entities.VirtWhoConfig(**args).create()
        command = get_configure_command(vhd.id)
        deploy_configure_by_command(command)
        self.assertEqual(get_configure_option('NO_PROXY', VIRTWHO_SYSCONFIG),
                         '*')
        proxy = 'test.example.com:3128'
        no_proxy = 'test.satellite.com'
        vhd.proxy = proxy
        vhd.no_proxy = no_proxy
        vhd.update(['proxy', 'no_proxy'])
        command = get_configure_command(vhd.id)
        deploy_configure_by_command(command)
        self.assertEqual(get_configure_option('http_proxy', VIRTWHO_SYSCONFIG),
                         proxy)
        self.assertEqual(get_configure_option('NO_PROXY', VIRTWHO_SYSCONFIG),
                         no_proxy)
        vhd.delete()
        self.assertFalse(entities.VirtWhoConfig().search(
            query={'search': 'name={}'.format(name)}))
Esempio n. 3
0
    def test_positive_configure_organization_list(self):
        """ Verify "GET /foreman_virt_who_configure/

        api/v2/organizations/:organization_id/configs"

        :id: 7434a875-e96a-40bd-9652-83d0805997a5

        :expectedresults: Config can be searched in org list

        :CaseLevel: Integration

        :CaseImportance: Medium
        """
        name = gen_string('alpha')
        args = self._make_virtwho_configure()
        args.update({'name': name})
        vhd = entities.VirtWhoConfig(**args).create()
        command = get_configure_command(vhd.id)
        deploy_configure_by_command(command)
        search_result = vhd.get_organization_configs(data={'per_page': 1000})
        self.assertTrue([
            item for item in search_result['results'] if item['name'] == name
        ])
        vhd.delete()
        self.assertFalse(entities.VirtWhoConfig().search(
            query={'search': 'name={}'.format(name)}))
Esempio n. 4
0
    def test_positive_deploy_configure_by_script(self, form_data,
                                                 virtwho_config):
        """ Verify "GET /foreman_virt_who_configure/api/

        v2/configs/:id/deploy_script"

        :id: 166ec4f8-e3fa-4555-9acb-1a5d693a42bb

        :expectedresults: Config can be created and deployed

        :CaseLevel: Integration

        :CaseImportance: High
        """
        assert virtwho_config.status == 'unknown'
        script = virtwho_config.deploy_script()
        hypervisor_name, guest_name = deploy_configure_by_script(
            script['virt_who_config_script'],
            form_data['hypervisor_type'],
            debug=True)
        virt_who_instance = (entities.VirtWhoConfig().search(
            query={'search': f'name={virtwho_config.name}'})[0].status)
        assert virt_who_instance == 'ok'
        hosts = [
            (
                hypervisor_name,
                f'product_id={virtwho.sku.vdc_physical} and type=NORMAL',
            ),
            (
                guest_name,
                f'product_id={virtwho.sku.vdc_physical} and type=STACK_DERIVED',
            ),
        ]
        for hostname, sku in hosts:
            if 'type=NORMAL' in sku:
                subscriptions = entities.Subscription().search(
                    query={'search': sku})
                vdc_id = subscriptions[0].id
            if 'type=STACK_DERIVED' in sku:
                vdc_id = self._get_guest_bonus(hypervisor_name, sku)
            host, time = wait_for(
                entities.Host().search,
                func_args=(None, {
                    'search': hostname
                }),
                fail_condition=[],
                timeout=5,
                delay=1,
            )
            entities.HostSubscription(host=host[0].id).add_subscriptions(
                data={'subscriptions': [{
                    'id': vdc_id,
                    'quantity': 1
                }]})
            result = entities.Host().search(
                query={'search': hostname})[0].read_json()
            assert result['subscription_status_label'] == 'Fully entitled'
        virtwho_config.delete()
        assert not entities.VirtWhoConfig().search(
            query={'search': f"name={form_data['name']}"})
Esempio n. 5
0
    def test_positive_hypervisor_id_option(self):
        """ Verify hypervisor_id option by "PUT

        /foreman_virt_who_configure/api/v2/configs/:id"

        :id: 9aa17bbc-e417-473a-831c-4d87781f41d8

        :expectedresults: hypervisor_id option can be updated.

        :CaseLevel: Integration

        :CaseImportance: Medium
        """
        name = gen_string('alpha')
        args = self._make_virtwho_configure()
        args.update({'name': name})
        vhd = entities.VirtWhoConfig(**args).create()
        values = ['uuid', 'hostname']
        if self.hypervisor_type in ('esx', 'rhevm'):
            values.append('hwuuid')
        for value in values:
            vhd.hypervisor_id = value
            vhd.update(['hypervisor_id'])
            config_file = get_configure_file(vhd.id)
            command = get_configure_command(vhd.id)
            deploy_configure_by_command(command)
            self.assertEqual(
                get_configure_option('hypervisor_id', config_file), value)
        vhd.delete()
        self.assertFalse(entities.VirtWhoConfig().search(
            query={'search': 'name={}'.format(name)}))
Esempio n. 6
0
    def test_post_crud_virt_who_configuration(self):
        """Virt-who config is intact post upgrade and verify the config can be updated and deleted.

        :id: postupgrade-d7ae7b2b-3291-48c8-b412-cb54e444c7a4

        :steps:
            1. Post upgrade, Verify virt-who exists and has same status.
            2. Verify the connection of the guest on Content host.
            3. Verify the virt-who config-file exists.
            4. Update virt-who config with new name.
            5. Delete virt-who config.

        :expectedresults:
            1. virt-who config is intact post upgrade.
            2. the config and guest connection have the same status.
            3. virt-who config should update and delete successfully.
        """
        org = entities.Organization().search(query={'search': 'name={0}'.format(self.org_name)})[0]

        # Post upgrade, Verify virt-who exists and has same status.
        vhd = entities.VirtWhoConfig(organization_id=org.id).search(
            query={'search': 'name={}'.format(self.name)}
        )[0]
        if not is_open('BZ:1802395'):
            self.assertEqual(vhd.status, 'ok')
        # Verify virt-who status via CLI as we cannot check it via API now
        vhd_cli = VirtWhoConfig.exists(search=('name', self.name))
        self.assertEqual(
            VirtWhoConfig.info({'id': vhd_cli['id']})['general-information']['status'], 'OK'
        )

        # Vefify the connection of the guest on Content host
        entity_data = get_entity_data(self.__class__.__name__)
        hypervisor_name = entity_data.get('hypervisor_name')
        guest_name = entity_data.get('guest_name')
        hosts = [hypervisor_name, guest_name]
        for hostname in hosts:
            result = (
                entities.Host(organization=org.id)
                .search(query={'search': hostname})[0]
                .read_json()
            )
            self.assertEqual(result['subscription_status_label'], 'Fully entitled')

        # Verify the virt-who config-file exists.
        config_file = get_configure_file(vhd.id)
        get_configure_option('hypervisor_id', config_file),

        # Update virt-who config
        modify_name = gen_string('alpha')
        vhd.name = modify_name
        vhd.update(['name'])

        # Delete virt-who config
        vhd.delete()
        self.assertFalse(
            entities.VirtWhoConfig(organization_id=org.id).search(
                query={'search': 'name={}'.format(modify_name)}
            )
        )
Esempio n. 7
0
    def test_positive_deploy_configure_by_script(self, default_org, form_data,
                                                 virtwho_config):
        """Verify "GET /foreman_virt_who_configure/api/

        v2/configs/:id/deploy_script"

        :id: 9668b900-0d2f-42ae-b2f8-523ca292b2bd

        :expectedresults: Config can be created and deployed

        :CaseLevel: Integration

        :CaseImportance: High
        """
        assert virtwho_config.status == 'unknown'
        script = virtwho_config.deploy_script()
        hypervisor_name, guest_name = deploy_configure_by_script(
            script['virt_who_config_script'],
            form_data['hypervisor_type'],
            debug=True,
            org=default_org.label,
        )
        virt_who_instance = (entities.VirtWhoConfig().search(
            query={'search': f'name={virtwho_config.name}'})[0].status)
        assert virt_who_instance == 'ok'
        hosts = [
            (
                hypervisor_name,
                f'product_id={settings.virtwho.sku.vdc_physical} and type=NORMAL',
            ),
            (
                guest_name,
                f'product_id={settings.virtwho.sku.vdc_physical} and type=STACK_DERIVED',
            ),
        ]
        for hostname, sku in hosts:
            host = Host.list({'search': hostname})[0]
            subscriptions = Subscription.list({
                'organization': default_org.name,
                'search': sku
            })
            vdc_id = subscriptions[0]['id']
            if 'type=STACK_DERIVED' in sku:
                for item in subscriptions:
                    if hypervisor_name.lower() in item['type']:
                        vdc_id = item['id']
                        break
            entities.HostSubscription(host=host['id']).add_subscriptions(
                data={'subscriptions': [{
                    'id': vdc_id,
                    'quantity': 1
                }]})
            result = entities.Host().search(
                query={'search': hostname})[0].read_json()
            assert result['subscription_status_label'] == 'Fully entitled'
        virtwho_config.delete()
        assert not entities.VirtWhoConfig().search(
            query={'search': f"name={form_data['name']}"})
Esempio n. 8
0
    def test_positive_deploy_configure_by_script(self):
        """ Verify "GET /foreman_virt_who_configure/api/

        v2/configs/:id/deploy_script"

        :id: bb673b27-c258-4517-8fb9-436a4b51ba9d

        :expectedresults: Config can be created and deployed

        :CaseLevel: Integration

        :CaseImportance: High
        """
        name = gen_string('alpha')
        args = self._make_virtwho_configure()
        args.update({'name': name})
        vhd = entities.VirtWhoConfig(**args).create()
        self.assertEqual(vhd.status, 'unknown')
        script = vhd.deploy_script()
        hypervisor_name, guest_name = deploy_configure_by_script(
            script['virt_who_config_script'], debug=True)
        self.assertEqual(
            entities.VirtWhoConfig().search(
                query={'search': 'name={}'.format(name)})[0].status, 'ok')
        hosts = [
            (hypervisor_name,
             'product_id={} and type=NORMAL'.format(self.vdc_physical)),
            (guest_name,
             'product_id={} and type=STACK_DERIVED'.format(self.vdc_physical))
        ]
        for hostname, sku in hosts:
            if 'type=NORMAL' in sku:
                subscriptions = entities.Subscription().search(
                    query={'search': '{0}'.format(sku)})
                vdc_id = subscriptions[0].id
            if 'type=STACK_DERIVED' in sku:
                vdc_id = self._get_guest_bonus(hypervisor_name, sku)
            host, time = wait_for(entities.Host().search,
                                  func_args=(None, {
                                      'search': "{0}".format(hostname)
                                  }),
                                  fail_condition=[],
                                  timeout=5,
                                  delay=1)
            entities.HostSubscription(host=host[0].id).add_subscriptions(
                data={'subscriptions': [{
                    'id': vdc_id,
                    'quantity': 1
                }]})
            result = entities.Host().search(
                query={'search': '{0}'.format(hostname)})[0].read_json()
            self.assertEqual(result['subscription_status_label'],
                             'Fully entitled')
        vhd.delete()
        self.assertFalse(entities.VirtWhoConfig().search(
            query={'search': 'name={}'.format(name)}))
Esempio n. 9
0
    def test_positive_deploy_configure_by_id(self, form_data, virtwho_config):
        """Verify "POST /foreman_virt_who_configure/api/v2/configs"

        :id: 72d74c05-2580-4f38-b6c0-999ff470d4d6

        :expectedresults: Config can be created and deployed

        :CaseLevel: Integration

        :CaseImportance: High
        """
        assert virtwho_config.status == 'unknown'
        command = get_configure_command(virtwho_config.id)
        hypervisor_name, guest_name = deploy_configure_by_command(
            command, form_data['hypervisor_type'], debug=True)
        virt_who_instance = (entities.VirtWhoConfig().search(
            query={'search': f'name={virtwho_config.name}'})[0].status)
        assert virt_who_instance == 'ok'
        hosts = [
            (
                hypervisor_name,
                f'product_id={settings.virtwho.sku.vdc_physical} and type=NORMAL',
            ),
            (
                guest_name,
                f'product_id={settings.virtwho.sku.vdc_physical} and type=STACK_DERIVED',
            ),
        ]
        for hostname, sku in hosts:
            host = Host.list({'search': hostname})[0]
            subscriptions = Subscription.list({
                'organization': DEFAULT_ORG,
                'search': sku
            })
            vdc_id = subscriptions[0]['id']
            if 'type=STACK_DERIVED' in sku:
                for item in subscriptions:
                    if hypervisor_name.lower() in item['type']:
                        vdc_id = item['id']
                        break
            entities.HostSubscription(host=host['id']).add_subscriptions(
                data={'subscriptions': [{
                    'id': vdc_id,
                    'quantity': 1
                }]})
            result = entities.Host().search(
                query={'search': hostname})[0].read_json()
            assert result['subscription_status_label'] == 'Fully entitled'
        virtwho_config.delete()
        assert not entities.VirtWhoConfig().search(
            query={'search': f"name={form_data['name']}"})
Esempio n. 10
0
    def test_positive_hypervisor_id_option(self, default_org, form_data, virtwho_config):
        """Verify hypervisor_id option by "PUT

        /foreman_virt_who_configure/api/v2/configs/:id"

        :id: 37a08451-2add-4c5c-bab6-ebe002a746f1

        :expectedresults: hypervisor_id option can be updated.

        :CaseLevel: Integration

        :CaseImportance: Medium
        """
        values = ['uuid', 'hostname']
        for value in values:
            virtwho_config.hypervisor_id = value
            virtwho_config.update(['hypervisor_id'])
            config_file = get_configure_file(virtwho_config.id)
            command = get_configure_command(virtwho_config.id, default_org.name)
            deploy_configure_by_command(
                command, form_data['hypervisor_type'], org=default_org.label
            )
            assert get_configure_option('hypervisor_id', config_file) == value
        virtwho_config.delete()
        assert not entities.VirtWhoConfig().search(query={'search': f"name={form_data['name']}"})
Esempio n. 11
0
    def test_positive_configure_organization_list(self, form_data,
                                                  virtwho_config):
        """ Verify "GET /foreman_virt_who_configure/

        api/v2/organizations/:organization_id/configs"

        :id: 7434a875-e96a-40bd-9652-83d0805997a5

        :expectedresults: Config can be searched in org list

        :CaseLevel: Integration

        :CaseImportance: Medium
        """
        command = get_configure_command(virtwho_config.id)
        deploy_configure_by_command(command)
        search_result = virtwho_config.get_organization_configs(
            data={'per_page': 1000})
        assert [
            item for item in search_result['results']
            if item['name'] == form_data['name']
        ]
        virtwho_config.delete()
        assert not entities.VirtWhoConfig().search(
            query={'search': f"name={form_data['name']}"})
Esempio n. 12
0
    def test_positive_interval_option(self, form_data, virtwho_config):
        """ Verify interval option by "PUT

        /foreman_virt_who_configure/api/v2/configs/:id"

        :id: 65f4138b-ca8f-4f1e-805c-1a331b951be5

        :expectedresults: interval option can be updated.

        :CaseLevel: Integration

        :CaseImportance: Medium
        """
        options = {
            '60': '3600',
            '120': '7200',
            '240': '14400',
            '480': '28800',
            '720': '43200',
            '1440': '86400',
            '2880': '172800',
            '4320': '259200',
        }
        for key, value in sorted(options.items(),
                                 key=lambda item: int(item[0])):
            virtwho_config.interval = key
            virtwho_config.update(['interval'])
            command = get_configure_command(virtwho_config.id)
            deploy_configure_by_command(command, form_data['hypervisor_type'])
            assert get_configure_option('VIRTWHO_INTERVAL',
                                        VIRTWHO_SYSCONFIG) == value
        virtwho_config.delete()
        assert not entities.VirtWhoConfig().search(
            query={'search': f"name={form_data['name']}"})
Esempio n. 13
0
    def test_positive_hypervisor_id_option(self, form_data, virtwho_config):
        """ Verify hypervisor_id option by "PUT

        /foreman_virt_who_configure/api/v2/configs/:id"

        :id: f232547f-c4b2-41bc-ab8d-e7579a49ab69

        :expectedresults: hypervisor_id option can be updated.

        :CaseLevel: Integration

        :CaseImportance: Medium
        """
        # esx and rhevm support hwuuid option
        values = ['uuid', 'hostname', 'hwuuid']
        for value in values:
            virtwho_config.hypervisor_id = value
            virtwho_config.update(['hypervisor_id'])
            config_file = get_configure_file(virtwho_config.id)
            command = get_configure_command(virtwho_config.id)
            deploy_configure_by_command(command, form_data['hypervisor_type'])
            assert get_configure_option('hypervisor_id', config_file) == value
        virtwho_config.delete()
        assert not entities.VirtWhoConfig().search(
            query={'search': f"name={form_data['name']}"})
Esempio n. 14
0
    def test_positive_config_delete(self):
        """ Create multiple configs, deploy them, then try to delete them

        :id: b46cf8c1-b122-4011-a029-42dbc587e74c

        :steps:
            1. Create a virt-who config objects
            2. Deploy config on Satellite Server
            3. Delete the config

        :expectedresults:
            The configs are deleted
        """
        vhc_name = "example_config{}".format(gen_integer())
        vhc = entities.VirtWhoConfig(
            name=vhc_name,
            organization=self.org,
            hypervisor_server=settings.clients.provisioning_server,
            satellite_url=settings.server.hostname,
            hypervisor_type='libvirt',
            hypervisor_username='******',
            hypervisor_id='hostname',
            hypervisor_password='').create()
        deploy_virt_who_config(vhc.id, self.org.id)
        sc = VirtWhoHypervisorConfig(vhc.id)
        expected = make_expected_configfile_section_from_api(vhc)
        errors = sc.verify(expected)
        self.assertEqual(len(errors), 0, errors)

        # Delete the config
        vhc.delete()
        with self.assertRaises(HTTPError):
            vhc.read()
Esempio n. 15
0
    def test_positive_proxy_option(self, form_data, virtwho_config):
        """ Verify http_proxy option by "PUT

        /foreman_virt_who_configure/api/v2/configs/:id""

        :id: e1b00b46-d5e6-40d5-a955-a45a75a5cfad

        :expectedresults: http_proxy and no_proxy option can be updated.

        :CaseLevel: Integration

        :CaseImportance: Medium
        """
        command = get_configure_command(virtwho_config.id)
        deploy_configure_by_command(command, form_data['hypervisor_type'])
        assert get_configure_option('NO_PROXY', VIRTWHO_SYSCONFIG) == '*'
        proxy = 'test.example.com:3128'
        no_proxy = 'test.satellite.com'
        virtwho_config.proxy = proxy
        virtwho_config.no_proxy = no_proxy
        virtwho_config.update(['proxy', 'no_proxy'])
        command = get_configure_command(virtwho_config.id)
        deploy_configure_by_command(command, form_data['hypervisor_type'])
        assert get_configure_option('http_proxy', VIRTWHO_SYSCONFIG) == proxy
        assert get_configure_option('NO_PROXY', VIRTWHO_SYSCONFIG) == no_proxy
        virtwho_config.delete()
        assert not entities.VirtWhoConfig().search(
            query={'search': f"name={form_data['name']}"})
Esempio n. 16
0
    def test_positive_config_create(self):
        """ Create a config, deploy it, verify the resulting config files

        :id: 558ebdaa-8e29-47c3-b859-a56f2d28a335

        :steps:
            1. Create a virt-who config object
            2. Deploy config on Satellite Server
            3. Verify the config files

        :expectedresults:
            The config files have the expected config
        """
        vhc_name = "example_config{}".format(gen_integer())
        vhc = entities.VirtWhoConfig(
            name=vhc_name,
            organization=self.org,
            hypervisor_server=settings.clients.provisioning_server,
            satellite_url=settings.server.hostname,
            hypervisor_type='libvirt',
            hypervisor_username='******',
            hypervisor_id='hostname',
            hypervisor_password='').create()

        deploy_virt_who_config(vhc.id, self.org.id)
        sc = VirtWhoHypervisorConfig(vhc.id)
        expected = make_expected_configfile_section_from_api(vhc)
        errors = sc.verify(expected)
        self.assertEqual(len(errors), 0, errors)
Esempio n. 17
0
    def test_positive_configure_organization_list(self, form_data,
                                                  virtwho_config):
        """ Verify "GET /foreman_virt_who_configure/

        api/v2/organizations/:organization_id/configs"

        :id: 5bf34bef-bf68-4557-978d-419bd4df0ba1

        :expectedresults: Config can be searched in org list

        :CaseLevel: Integration

        :CaseImportance: Medium
        """
        command = get_configure_command(virtwho_config.id)
        deploy_configure_by_command(command, form_data['hypervisor_type'])
        search_result = virtwho_config.get_organization_configs(
            data={'per_page': 1000})
        assert [
            item for item in search_result['results']
            if item['name'] == form_data['name']
        ]
        virtwho_config.delete()
        assert not entities.VirtWhoConfig().search(
            query={'search': f"name={form_data['name']}"})
Esempio n. 18
0
    def test_positive_hypervisor_id_option(self, form_data, virtwho_config):
        """ Verify hypervisor_id option by "PUT

        /foreman_virt_who_configure/api/v2/configs/:id"

        :id: 9aa17bbc-e417-473a-831c-4d87781f41d8

        :expectedresults: hypervisor_id option can be updated.

        :CaseLevel: Integration

        :CaseImportance: Medium
        """
        values = ['uuid', 'hostname']
        if settings.virtwho.hypervisor_type in ('esx', 'rhevm'):
            values.append('hwuuid')
        for value in values:
            virtwho_config.hypervisor_id = value
            virtwho_config.update(['hypervisor_id'])
            config_file = get_configure_file(virtwho_config.id)
            command = get_configure_command(virtwho_config.id)
            deploy_configure_by_command(command)
            assert get_configure_option('hypervisor_id', config_file) == value
        virtwho_config.delete()
        assert not entities.VirtWhoConfig().search(query={'search': f"name={form_data['name']}"})
Esempio n. 19
0
    def test_positive_debug_option(self, default_org, form_data,
                                   virtwho_config):
        """Verify debug option by "PUT

        /foreman_virt_who_configure/api/v2/configs/:id"

        :id: be395108-3944-4a04-bee4-6bac3fa03a19

        :expectedresults: debug option can be updated.

        :CaseLevel: Integration

        :CaseImportance: Medium
        """
        options = {'true': '1', 'false': '0', '1': '1', '0': '0'}
        for key, value in sorted(options.items(), key=lambda item: item[0]):
            virtwho_config.debug = key
            virtwho_config.update(['debug'])
            command = get_configure_command(virtwho_config.id,
                                            default_org.name)
            deploy_configure_by_command(command,
                                        form_data['hypervisor_type'],
                                        org=default_org.label)
            assert get_configure_option('debug', ETC_VIRTWHO_CONFIG) == value
        virtwho_config.delete()
        assert not entities.VirtWhoConfig().search(
            query={'search': f"name={form_data['name']}"})
Esempio n. 20
0
    def test_positive_filter_option(self, form_data, virtwho_config):
        """ Verify filter option by "PUT

        /foreman_virt_who_configure/api/v2/configs/:id"

        :id: 89cc1134-69d9-4da8-9ba9-a296c17f4f16

        :expectedresults: filter and filter_hosts can be updated.

        :CaseLevel: Integration

        :CaseImportance: Medium
        """
        whitelist = {'filtering_mode': '1', 'whitelist': '.*redhat.com'}
        blacklist = {'filtering_mode': '2', 'blacklist': '.*redhat.com'}
        if settings.virtwho.hypervisor_type == 'esx':
            whitelist['filter_host_parents'] = '.*redhat.com'
            blacklist['exclude_host_parents'] = '.*redhat.com'
        # Update Whitelist and check the result
        virtwho_config.filtering_mode = whitelist['filtering_mode']
        virtwho_config.whitelist = whitelist['whitelist']
        if settings.virtwho.hypervisor_type == 'esx':
            virtwho_config.filter_host_parents = whitelist[
                'filter_host_parents']
        virtwho_config.update(whitelist.keys())
        config_file = get_configure_file(virtwho_config.id)
        command = get_configure_command(virtwho_config.id)
        deploy_configure_by_command(command)
        assert get_configure_option('filter_hosts',
                                    config_file) == whitelist['whitelist']
        if settings.virtwho.hypervisor_type == 'esx':
            assert (get_configure_option(
                'filter_host_parents',
                config_file) == whitelist['filter_host_parents'])
        # Update Blacklist and check the result
        virtwho_config.filtering_mode = blacklist['filtering_mode']
        virtwho_config.blacklist = blacklist['blacklist']
        if settings.virtwho.hypervisor_type == 'esx':
            virtwho_config.exclude_host_parents = blacklist[
                'exclude_host_parents']
        virtwho_config.update(blacklist.keys())
        config_file = get_configure_file(virtwho_config.id)
        command = get_configure_command(virtwho_config.id)
        deploy_configure_by_command(command)
        assert get_configure_option('exclude_hosts',
                                    config_file) == blacklist['blacklist']
        if settings.virtwho.hypervisor_type == 'esx':
            assert (get_configure_option(
                'exclude_host_parents',
                config_file) == blacklist['exclude_host_parents'])
        virtwho_config.delete()
        assert not entities.VirtWhoConfig().search(
            query={'search': f"name={form_data['name']}"})
Esempio n. 21
0
    def test_positive_filter_option(self, default_org, form_data,
                                    virtwho_config):
        """Verify filter option by "PUT

        /foreman_virt_who_configure/api/v2/configs/:id"

        :id: 1f251d89-5e22-4470-be4c-0aeba84c0273

        :expectedresults: filter and filter_hosts can be updated.

        :CaseLevel: Integration

        :CaseImportance: Medium
        """
        whitelist = {'filtering_mode': '1', 'whitelist': '.*redhat.com'}
        blacklist = {'filtering_mode': '2', 'blacklist': '.*redhat.com'}
        # esx support filter-host-parents and exclude-host-parents options
        whitelist['filter_host_parents'] = '.*redhat.com'
        blacklist['exclude_host_parents'] = '.*redhat.com'
        # Update Whitelist and check the result
        virtwho_config.filtering_mode = whitelist['filtering_mode']
        virtwho_config.whitelist = whitelist['whitelist']
        virtwho_config.filter_host_parents = whitelist['filter_host_parents']
        virtwho_config.update(whitelist.keys())
        config_file = get_configure_file(virtwho_config.id)
        command = get_configure_command(virtwho_config.id, default_org.name)
        deploy_configure_by_command(command,
                                    form_data['hypervisor_type'],
                                    org=default_org.label)
        assert get_configure_option('filter_hosts',
                                    config_file) == whitelist['whitelist']
        assert (get_configure_option(
            'filter_host_parents',
            config_file) == whitelist['filter_host_parents'])
        # Update Blacklist and check the result
        virtwho_config.filtering_mode = blacklist['filtering_mode']
        virtwho_config.blacklist = blacklist['blacklist']
        virtwho_config.exclude_host_parents = blacklist['exclude_host_parents']
        virtwho_config.update(blacklist.keys())
        config_file = get_configure_file(virtwho_config.id)
        command = get_configure_command(virtwho_config.id, default_org.name)
        deploy_configure_by_command(command,
                                    form_data['hypervisor_type'],
                                    org=default_org.label)
        assert get_configure_option('exclude_hosts',
                                    config_file) == blacklist['blacklist']
        assert (get_configure_option(
            'exclude_host_parents',
            config_file) == blacklist['exclude_host_parents'])
        virtwho_config.delete()
        assert not entities.VirtWhoConfig().search(
            query={'search': f"name={form_data['name']}"})
Esempio n. 22
0
    def test_positive_interval_option(self):
        """ Verify interval option by "PUT

        /foreman_virt_who_configure/api/v2/configs/:id"

        :id: 9a96c25b-fddd-47c3-aa9f-3b6dc298d068

        :expectedresults: interval option can be updated.

        :CaseLevel: Integration

        :CaseImportance: Medium
        """
        name = gen_string('alpha')
        args = self._make_virtwho_configure()
        args.update({'name': name})
        vhd = entities.VirtWhoConfig(**args).create()
        options = {
            '60': '3600',
            '120': '7200',
            '240': '14400',
            '480': '28800',
            '720': '43200',
            '1440': '86400',
            '2880': '172800',
            '4320': '259200',
        }
        for key, value in sorted(options.items(),
                                 key=lambda item: int(item[0])):
            vhd.interval = key
            vhd.update(['interval'])
            command = get_configure_command(vhd.id)
            deploy_configure_by_command(command)
            self.assertEqual(
                get_configure_option('VIRTWHO_INTERVAL', VIRTWHO_SYSCONFIG),
                value)
        vhd.delete()
        self.assertFalse(entities.VirtWhoConfig().search(
            query={'search': 'name={}'.format(name)}))
Esempio n. 23
0
    def test_positive_proxy_option(self, default_org, form_data,
                                   virtwho_config):
        """Verify http_proxy option by "PUT

        /foreman_virt_who_configure/api/v2/configs/:id""

        :id: e1b00b46-d5e6-40d5-a955-a45a75a5cfad

        :expectedresults: http_proxy/https_proxy and no_proxy option can be updated.

        :CaseLevel: Integration

        :CaseImportance: Medium

        :BZ: 1902199
        """
        command = get_configure_command(virtwho_config.id, default_org.name)
        deploy_configure_by_command(command,
                                    form_data['hypervisor_type'],
                                    org=default_org.label)
        # Check default NO_PROXY option
        assert get_configure_option('no_proxy', ETC_VIRTWHO_CONFIG) == '*'
        # Check HTTTP Proxy and No_PROXY option
        http_proxy_url, http_proxy_name, http_proxy_id = create_http_proxy(
            http_type='http', org=default_org)
        no_proxy = 'test.satellite.com'
        virtwho_config.http_proxy_id = http_proxy_id
        virtwho_config.no_proxy = no_proxy
        virtwho_config.update(['http_proxy_id', 'no_proxy'])
        command = get_configure_command(virtwho_config.id, default_org.name)
        deploy_configure_by_command(command,
                                    form_data['hypervisor_type'],
                                    org=default_org.label)
        assert get_configure_option('http_proxy',
                                    ETC_VIRTWHO_CONFIG) == http_proxy_url
        assert get_configure_option('no_proxy', ETC_VIRTWHO_CONFIG) == no_proxy
        # Check HTTTPs Proxy option
        https_proxy_url, https_proxy_name, https_proxy_id = create_http_proxy(
            org=default_org)
        virtwho_config.http_proxy_id = https_proxy_id
        virtwho_config.update(['http_proxy_id'])
        deploy_configure_by_command(command,
                                    form_data['hypervisor_type'],
                                    org=default_org.label)
        assert get_configure_option('https_proxy',
                                    ETC_VIRTWHO_CONFIG) == https_proxy_url
        virtwho_config.delete()
        assert not entities.VirtWhoConfig().search(
            query={'search': f"name={form_data['name']}"})
Esempio n. 24
0
    def test_positive_debug_option(self, form_data, virtwho_config):
        """ Verify debug option by "PUT

        /foreman_virt_who_configure/api/v2/configs/:id"

        :id: 75a20b8c-bed8-4c55-b291-14bca6cac364

        :expectedresults: debug option can be updated.

        :CaseLevel: Integration

        :CaseImportance: Medium
        """
        options = {'true': '1', 'false': '0', '1': '1', '0': '0'}
        for key, value in sorted(options.items(), key=lambda item: item[0]):
            virtwho_config.debug = key
            virtwho_config.update(['debug'])
            command = get_configure_command(virtwho_config.id)
            deploy_configure_by_command(command)
            assert get_configure_option('VIRTWHO_DEBUG', VIRTWHO_SYSCONFIG) == value
        virtwho_config.delete()
        assert not entities.VirtWhoConfig().search(query={'search': f"name={form_data['name']}"})
Esempio n. 25
0
def test_positive_virtwho_configs_widget(session):
    """Check if Virt-who Configurations Status Widget is working in the Dashboard UI

    :id: 6bed6d55-2bd5-4438-9f72-d48e78566789

    :Steps:

        1. Create a Virt-who Configuration
        2. Navigate Monitor -> Dashboard
        3. Review the Virt-who Configurations Status widget

    :expectedresults: The widget is updated with all details.

    :CaseLevel: Integration
    """
    org = entities.Organization().create()
    entities.VirtWhoConfig(
        name="example_config{}".format(gen_integer()),
        organization=org,
        hypervisor_server=settings.clients.provisioning_server,
        satellite_url=settings.server.hostname,
        hypervisor_type='libvirt',
        hypervisor_username='******',
        hypervisor_id='hostname',
        hypervisor_password='',
    ).create()

    with session:
        session.organization.select(org_name=org.name)
        expected_values = [
            {'Configuration Status': 'No Reports', 'Count': '1'},
            {'Configuration Status': 'No Change', 'Count': '0'},
            {'Configuration Status': 'OK', 'Count': '0'},
            {'Configuration Status': 'Total Configurations', 'Count': '1'}
        ]
        values = session.dashboard.read('VirtWhoConfigStatus')
        assert values['config_status'] == expected_values
        assert values['latest_config'] == 'No configuration found'
Esempio n. 26
0
    def test_positive_hypervisor_id_option(self, form_data, virtwho_config):
        """Verify hypervisor_id option by "PUT

        /foreman_virt_who_configure/api/v2/configs/:id"

        :id: 16344235-1607-4f60-950b-5a91546cf8f4

        :expectedresults: hypervisor_id option can be updated.

        :CaseLevel: Integration

        :CaseImportance: Medium
        """
        values = ['uuid', 'hostname']
        for value in values:
            virtwho_config.hypervisor_id = value
            virtwho_config.update(['hypervisor_id'])
            config_file = get_configure_file(virtwho_config.id)
            command = get_configure_command(virtwho_config.id)
            deploy_configure_by_command(command, form_data['hypervisor_type'])
            assert get_configure_option('hypervisor_id', config_file) == value
        virtwho_config.delete()
        assert not entities.VirtWhoConfig().search(query={'search': f"name={form_data['name']}"})
Esempio n. 27
0
def virtwho_config(form_data):
    return entities.VirtWhoConfig(**form_data).create()
Esempio n. 28
0
    def test_pre_create_virt_who_configuration(self):
        """Create and deploy virt-who configuration.

        :id: preupgrade-a36cbe89-47a2-422f-9881-0f86bea0e24e

        :steps: In Preupgrade Satellite, Create and deploy virt-who configuration.

        :expectedresults:
            1. Config can be created and deployed by command.
            2. No error msg in /var/log/rhsm/rhsm.log.
            3. Report is sent to satellite.
            4. Virtual sku can be generated and attached.
        """
        default_loc_id = (
            entities.Location().search(query={'search': 'name="{}"'.format(DEFAULT_LOC)})[0].id
        )
        default_loc = entities.Location(id=default_loc_id).read()
        org = entities.Organization(name=self.org_name).create()
        default_loc.organization.append(entities.Organization(id=org.id))
        default_loc.update(['organization'])
        with manifests.clone() as manifest:
            upload_manifest(org.id, manifest.content)
        args = self._make_virtwho_configure()
        args.update({'name': self.name, 'organization_id': org.id})
        vhd = entities.VirtWhoConfig(**args).create()
        self.assertEqual(vhd.status, 'unknown')
        command = get_configure_command(vhd.id, org=org.name)
        hypervisor_name, guest_name = deploy_configure_by_command(
            command, args['hypervisor_type'], debug=True, org=org.name
        )
        self.assertEqual(
            entities.VirtWhoConfig(organization_id=org.id)
            .search(query={'search': 'name={}'.format(self.name)})[0]
            .status,
            'ok',
        )
        hosts = [
            (hypervisor_name, 'product_id={} and type=NORMAL'.format(self.vdc_physical)),
            (guest_name, 'product_id={} and type=STACK_DERIVED'.format(self.vdc_physical)),
        ]
        for hostname, sku in hosts:
            if 'type=NORMAL' in sku:
                subscriptions = entities.Subscription(organization=org.id).search(
                    query={'search': sku}
                )
                vdc_id = subscriptions[0].id
            if 'type=STACK_DERIVED' in sku:
                subscriptions = entities.Subscription(organization=org.id).search(
                    query={'search': sku}
                )
                vdc_id = subscriptions[0].id
            host, time = wait_for(
                entities.Host(organization=org.id).search,
                func_args=(None, {'search': hostname}),
                fail_condition=[],
                timeout=5,
                delay=1,
            )
            entities.HostSubscription(host=host[0].id).add_subscriptions(
                data={'subscriptions': [{'id': vdc_id, 'quantity': 1}]}
            )
            result = (
                entities.Host(organization=org.id)
                .search(query={'search': hostname})[0]
                .read_json()
            )
            self.assertEqual(result['subscription_status_label'], 'Fully entitled')

        scenario_dict = {
            self.__class__.__name__: {
                'hypervisor_name': hypervisor_name,
                'guest_name': guest_name,
            }
        }
        create_dict(scenario_dict)
Esempio n. 29
0
    def test_positive_filter_option(self):
        """ Verify filter option by "PUT

        /foreman_virt_who_configure/api/v2/configs/:id"

        :id: 89cc1134-69d9-4da8-9ba9-a296c17f4f16

        :expectedresults: filter and filter_hosts can be updated.

        :CaseLevel: Integration

        :CaseImportance: Medium
        """
        name = gen_string('alpha')
        args = self._make_virtwho_configure()
        args.update({'name': name})
        vhd = entities.VirtWhoConfig(**args).create()
        whitelist = {
            'filtering_mode': '1',
            'whitelist': '.*redhat.com',
        }
        blacklist = {
            'filtering_mode': '2',
            'blacklist': '.*redhat.com',
        }
        if self.hypervisor_type == 'esx':
            whitelist['filter_host_parents'] = '.*redhat.com'
            blacklist['exclude_host_parents'] = '.*redhat.com'
        # Update Whitelist and check the result
        vhd.filtering_mode = whitelist['filtering_mode']
        vhd.whitelist = whitelist['whitelist']
        if self.hypervisor_type == 'esx':
            vhd.filter_host_parents = whitelist['filter_host_parents']
        vhd.update(whitelist.keys())
        config_file = get_configure_file(vhd.id)
        command = get_configure_command(vhd.id)
        deploy_configure_by_command(command)
        self.assertEqual(get_configure_option('filter_hosts', config_file),
                         whitelist['whitelist'])
        if self.hypervisor_type == 'esx':
            self.assertEqual(
                get_configure_option('filter_host_parents', config_file),
                whitelist['filter_host_parents'])
        # Update Blacklist and check the result
        vhd.filtering_mode = blacklist['filtering_mode']
        vhd.blacklist = blacklist['blacklist']
        if self.hypervisor_type == 'esx':
            vhd.exclude_host_parents = blacklist['exclude_host_parents']
        vhd.update(blacklist.keys())
        config_file = get_configure_file(vhd.id)
        command = get_configure_command(vhd.id)
        deploy_configure_by_command(command)
        self.assertEqual(get_configure_option('exclude_hosts', config_file),
                         blacklist['blacklist'])
        if self.hypervisor_type == 'esx':
            self.assertEqual(
                get_configure_option('exclude_host_parents', config_file),
                blacklist['exclude_host_parents'])
        vhd.delete()
        self.assertFalse(entities.VirtWhoConfig().search(
            query={'search': 'name={}'.format(name)}))
Esempio n. 30
0
    def test_pre_create_virt_who_configuration(self, form_data):
        """Create and deploy virt-who configuration.

        :id: preupgrade-a36cbe89-47a2-422f-9881-0f86bea0e24e

        :steps: In Preupgrade Satellite, Create and deploy virt-who configuration.

        :expectedresults:
            1. Config can be created and deployed by command.
            2. No error msg in /var/log/rhsm/rhsm.log.
            3. Report is sent to satellite.
            4. Virtual sku can be generated and attached.
        """
        default_loc_id = entities.Location().search(
            query={'search': f'name="{DEFAULT_LOC}"'})[0].id
        default_loc = entities.Location(id=default_loc_id).read()
        org = entities.Organization(name=ORG_DATA['name']).create()
        default_loc.organization.append(entities.Organization(id=org.id))
        default_loc.update(['organization'])
        with manifests.clone() as manifest:
            upload_manifest(org.id, manifest.content)
        form_data.update({'organization_id': org.id})
        vhd = entities.VirtWhoConfig(**form_data).create()
        assert vhd.status == 'unknown'
        command = get_configure_command(vhd.id, org=org.name)
        hypervisor_name, guest_name = deploy_configure_by_command(
            command, form_data['hypervisor_type'], debug=True, org=org.label)
        virt_who_instance = (entities.VirtWhoConfig(
            organization_id=org.id).search(
                query={'search': f'name={form_data["name"]}'})[0].status)
        assert virt_who_instance == 'ok'
        hosts = [
            (hypervisor_name,
             f'product_id={settings.virtwho.sku.vdc_physical} and type=NORMAL'
             ),
            (guest_name,
             f'product_id={settings.virtwho.sku.vdc_physical} and type=STACK_DERIVED'
             ),
        ]
        for hostname, sku in hosts:
            host = Host.list({'search': hostname})[0]
            subscriptions = Subscription.list({
                'organization-id': org.id,
                'search': sku
            })
            vdc_id = subscriptions[0]['id']
            if 'type=STACK_DERIVED' in sku:
                for item in subscriptions:
                    if hypervisor_name.lower() in item['type']:
                        vdc_id = item['id']
                        break
            entities.HostSubscription(host=host['id']).add_subscriptions(
                data={'subscriptions': [{
                    'id': vdc_id,
                    'quantity': 1
                }]})
            result = (entities.Host(organization=org.id).search(
                query={'search': hostname})[0].read_json())
            assert result['subscription_status_label'] == 'Fully entitled'

        scenario_dict = {
            self.__class__.__name__: {
                'hypervisor_name': hypervisor_name,
                'guest_name': guest_name,
            }
        }
        create_dict(scenario_dict)