Ejemplo n.º 1
0
    def test_positive_proxy_option(self):
        """ Verify http_proxy option by hammer virt-who-config update"

        :id: becd00f7-e140-481a-9249-8a3082297a4b

        :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 = VirtWhoConfig.create(args)['general-information']
        http_proxy = 'test.example.com:3128'
        no_proxy = 'test.satellite.com'
        VirtWhoConfig.update({
            'id': vhd['id'],
            'proxy': http_proxy,
            'no-proxy': no_proxy,
        })
        result = VirtWhoConfig.info({'id': vhd['id']})
        self.assertEqual(result['connection']['http-proxy'], http_proxy)
        self.assertEqual(result['connection']['ignore-proxy'], no_proxy)
        command = get_configure_command(vhd['id'])
        deploy_configure_by_command(command)
        self.assertEqual(get_configure_option('http_proxy', VIRTWHO_SYSCONFIG),
                         http_proxy)
        self.assertEqual(get_configure_option('NO_PROXY', VIRTWHO_SYSCONFIG),
                         no_proxy)
        VirtWhoConfig.delete({'name': name})
        self.assertFalse(VirtWhoConfig.exists(search=('name', name)))
Ejemplo n.º 2
0
    def test_positive_deploy_configure_by_id(self, form_data, virtwho_config):
        """Verify " hammer virt-who-config deploy"

        :id: e66bf88a-bd4e-409a-91a8-bc5e005d95dd

        :expectedresults: Config can be created and deployed

        :CaseLevel: Integration

        :CaseImportance: High
        """
        assert virtwho_config['status'] == 'No Report Yet'
        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 = VirtWhoConfig.info(
            {'id': virtwho_config['id']})['general-information']['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
            result = Host.subscription_attach({
                'host-id': host['id'],
                'subscription-id': vdc_id
            })
            assert 'attached to the host successfully' in '\n'.join(result)
        VirtWhoConfig.delete({'name': virtwho_config['name']})
        assert not VirtWhoConfig.exists(search=('name', form_data['name']))
Ejemplo n.º 3
0
    def test_positive_hypervisor_id_option(self):
        """ Verify hypervisor_id option by hammer virt-who-config update"

        :id: eae7e767-8a71-424c-87da-475c91ac2ea1

        :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 = VirtWhoConfig.create(args)['general-information']
        values = ['uuid', 'hostname']
        if self.hypervisor_type in ('esx', 'rhevm'):
            values.append('hwuuid')
        for value in values:
            VirtWhoConfig.update({'id': vhd['id'], 'hypervisor-id': value})
            result = VirtWhoConfig.info({'id': vhd['id']})
            self.assertEqual(result['connection']['hypervisor-id'], value)
            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)
        VirtWhoConfig.delete({'name': name})
        self.assertFalse(VirtWhoConfig.exists(search=('name', name)))
Ejemplo n.º 4
0
    def test_positive_filter_option(self, form_data, virtwho_config):
        """ Verify filter option by hammer virt-who-config update"

        :id: aaf45c5e-9504-47ce-8f25-b8073c2de036

        :expectedresults: filter and filter_hosts can be updated.

        :CaseLevel: Integration

        :CaseImportance: Medium
        """
        regex = '.*redhat.com'
        whitelist = {
            'id': virtwho_config['id'],
            'filtering-mode': 'whitelist',
            'whitelist': regex
        }
        blacklist = {
            'id': virtwho_config['id'],
            'filtering-mode': 'blacklist',
            'blacklist': regex
        }
        # esx support filter-host-parents and exclude-host-parents options
        whitelist['filter-host-parents'] = regex
        blacklist['exclude-host-parents'] = regex
        config_file = get_configure_file(virtwho_config['id'])
        command = get_configure_command(virtwho_config['id'])
        # Update Whitelist and check the result
        VirtWhoConfig.update(whitelist)
        result = VirtWhoConfig.info({'id': virtwho_config['id']})
        assert result['connection']['filtering'] == 'Whitelist'
        assert result['connection']['filtered-hosts'] == regex
        assert result['connection']['filter-host-parents'] == regex
        deploy_configure_by_command(command, form_data['hypervisor-type'])
        assert get_configure_option('filter_hosts', config_file) == regex
        assert get_configure_option('filter_host_parents',
                                    config_file) == regex
        # Update Blacklist and check the result
        VirtWhoConfig.update(blacklist)
        result = VirtWhoConfig.info({'id': virtwho_config['id']})
        assert result['connection']['filtering'] == 'Blacklist'
        assert result['connection']['excluded-hosts'] == regex
        assert result['connection']['exclude-host-parents'] == regex
        deploy_configure_by_command(command, form_data['hypervisor-type'])
        assert get_configure_option('exclude_hosts', config_file) == regex
        assert get_configure_option('exclude_host_parents',
                                    config_file) == regex
        VirtWhoConfig.delete({'name': virtwho_config['name']})
        assert not VirtWhoConfig.exists(search=('name', form_data['name']))
Ejemplo n.º 5
0
def get_configure_id(name):
    """Return the configure id by hammer.
    :param str name: the configure name you have created.
    :raises: VirtWhoError: If failed to get the configure info by hammer.
    """
    config = VirtWhoConfig.info({'name': name})
    if 'id' in config['general-information']:
        return config['general-information']['id']
    else:
        raise VirtWhoError("No configure id found for {}".format(name))
Ejemplo n.º 6
0
    def test_positive_deploy_configure_by_script(self, form_data, virtwho_config):
        """Verify " hammer virt-who-config fetch"

        :id: 6aaffaeb-aaf2-42cf-b0dc-ca41a53d42a6

        :expectedresults: Config can be created, fetch and deploy

        :CaseLevel: Integration

        :CaseImportance: High
        """
        assert virtwho_config['status'] == 'No Report Yet'
        script = VirtWhoConfig.fetch({'id': virtwho_config['id']}, output_format='base')
        hypervisor_name, guest_name = deploy_configure_by_script(
            script, form_data['hypervisor-type'], debug=True
        )
        virt_who_instance = VirtWhoConfig.info({'id': virtwho_config['id']})[
            'general-information'
        ]['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:
            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
            result = Host.subscription_attach({'host-id': host['id'], 'subscription-id': vdc_id})
            assert 'attached to the host successfully' in '\n'.join(result)
        VirtWhoConfig.delete({'name': virtwho_config['name']})
        assert not VirtWhoConfig.exists(search=('name', form_data['name']))
Ejemplo n.º 7
0
    def test_positive_hypervisor_id_option(self, form_data, virtwho_config):
        """Verify hypervisor_id option by hammer virt-who-config update"

        :id: 551cfc6c-71cd-40e7-9997-a7c85db02c1f

        :expectedresults: hypervisor_id option can be updated.

        :CaseLevel: Integration

        :CaseImportance: Medium
        """
        values = ['uuid', 'hostname']
        for value in values:
            VirtWhoConfig.update({
                'id': virtwho_config['id'],
                'hypervisor-id': value
            })
            result = VirtWhoConfig.info({'id': virtwho_config['id']})
            assert result['connection']['hypervisor-id'] == value
            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
        VirtWhoConfig.delete({'name': virtwho_config['name']})
        assert not VirtWhoConfig.exists(search=('name', form_data['name']))
Ejemplo n.º 8
0
    def test_positive_proxy_option(self, form_data, virtwho_config):
        """ Verify http_proxy option by hammer virt-who-config update"

        :id: 409d108e-e814-482b-93ed-09db89d21dda

        :expectedresults: http_proxy and no_proxy option can be updated.

        :CaseLevel: Integration

        :CaseImportance: Medium
        """
        http_proxy = 'test.example.com:3128'
        no_proxy = 'test.satellite.com'
        VirtWhoConfig.update({
            'id': virtwho_config['id'],
            'proxy': http_proxy,
            'no-proxy': no_proxy
        })
        result = VirtWhoConfig.info({'id': virtwho_config['id']})
        assert result['connection']['http-proxy'] == http_proxy
        assert result['connection']['ignore-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) == http_proxy
        assert get_configure_option('NO_PROXY', VIRTWHO_SYSCONFIG) == no_proxy
        VirtWhoConfig.delete({'name': virtwho_config['name']})
        assert not VirtWhoConfig.exists(search=('name', form_data['name']))
Ejemplo n.º 9
0
    def test_positive_hypervisor_id_option(self, form_data, virtwho_config):
        """Verify hypervisor_id option by hammer virt-who-config update"

        :id: d8428508-3149-4558-8173-4386db5e3760

        :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:
            VirtWhoConfig.update({
                'id': virtwho_config['id'],
                'hypervisor-id': value
            })
            result = VirtWhoConfig.info({'id': virtwho_config['id']})
            assert result['connection']['hypervisor-id'] == value
            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
        VirtWhoConfig.delete({'name': virtwho_config['name']})
        assert not VirtWhoConfig.exists(search=('name', form_data['name']))
Ejemplo n.º 10
0
    def test_positive_hypervisor_id_option(self, default_org, form_data,
                                           virtwho_config):
        """Verify hypervisor_id option by hammer virt-who-config update"

        :id: 082a0eec-f024-4605-b876-a8959cf68e0c

        :expectedresults: hypervisor_id option can be updated.

        :CaseLevel: Integration

        :CaseImportance: Medium
        """
        values = ['uuid', 'hostname']
        for value in values:
            VirtWhoConfig.update({
                'id': virtwho_config['id'],
                'hypervisor-id': value
            })
            result = VirtWhoConfig.info({'id': virtwho_config['id']})
            assert result['connection']['hypervisor-id'] == value
            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
        VirtWhoConfig.delete({'name': virtwho_config['name']})
        assert not VirtWhoConfig.exists(search=('name', form_data['name']))
Ejemplo n.º 11
0
    def test_positive_interval_option(self):
        """ Verify interval option by hammer virt-who-config update"

        :id: cf754c07-99d2-4758-b9dc-ab47443855b3

        :expectedresults: interval option can be updated.

        :CaseLevel: Integration

        :CaseImportance: Medium
        """
        name = gen_string('alpha')
        args = self._make_virtwho_configure()
        args.update({'name': name})
        vhd = VirtWhoConfig.create(args)['general-information']
        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])):
            VirtWhoConfig.update({'id': vhd['id'], 'interval': key})
            command = get_configure_command(vhd['id'])
            deploy_configure_by_command(command)
            self.assertEqual(
                get_configure_option('VIRTWHO_INTERVAL', VIRTWHO_SYSCONFIG),
                value)
        VirtWhoConfig.delete({'name': name})
        self.assertFalse(VirtWhoConfig.exists(search=('name', name)))
Ejemplo n.º 12
0
    def test_positive_rhsm_option(self, form_data, virtwho_config):
        """ Verify rhsm options in the configure file"

        :id: 5155d145-0a8d-4443-81d3-6fb7cef0533b

        :expectedresults:
            rhsm_hostname, rhsm_prefix are ecpected
            rhsm_username is not a login account

        :CaseLevel: Integration

        :CaseImportance: Medium
        """
        config_file = get_configure_file(virtwho_config['id'])
        command = get_configure_command(virtwho_config['id'])
        deploy_configure_by_command(command)
        rhsm_username = get_configure_option('rhsm_username', config_file)
        assert not User.exists(search=('login', rhsm_username))
        assert get_configure_option('rhsm_hostname', config_file) == settings.server.hostname
        assert get_configure_option('rhsm_prefix', config_file) == '/rhsm'
        VirtWhoConfig.delete({'name': virtwho_config['name']})
        assert not VirtWhoConfig.exists(search=('name', form_data['name']))
Ejemplo n.º 13
0
    def test_positive_rhsm_option(self, form_data, virtwho_config):
        """Verify rhsm options in the configure file"

        :id: b5b93d4d-e780-41c0-9eaa-2407cc1dcc9b

        :expectedresults:
            rhsm_hostname, rhsm_prefix are ecpected
            rhsm_username is not a login account

        :CaseLevel: Integration

        :CaseImportance: Medium
        """
        config_file = get_configure_file(virtwho_config['id'])
        command = get_configure_command(virtwho_config['id'])
        deploy_configure_by_command(command, form_data['hypervisor-type'])
        rhsm_username = get_configure_option('rhsm_username', config_file)
        assert not User.exists(search=('login', rhsm_username))
        assert get_configure_option('rhsm_hostname', config_file) == settings.server.hostname
        assert get_configure_option('rhsm_prefix', config_file) == '/rhsm'
        VirtWhoConfig.delete({'name': virtwho_config['name']})
        assert not VirtWhoConfig.exists(search=('name', form_data['name']))
Ejemplo n.º 14
0
    def test_positive_proxy_option(self, default_org, form_data,
                                   virtwho_config):
        """Verify http_proxy option by hammer virt-who-config update"

        :id: 409d108e-e814-482b-93ed-09db89d21dda

        :expectedresults: http_proxy and no_proxy option can be updated.

        :CaseLevel: Integration

        :CaseImportance: Medium

        :BZ: 1902199
        """
        # Check the https proxy option, update it via http proxy name
        https_proxy_url, https_proxy_name, https_proxy_id = create_http_proxy(
            org=default_org)
        no_proxy = 'test.satellite.com'
        VirtWhoConfig.update({
            'id': virtwho_config['id'],
            'http-proxy': https_proxy_name,
            'no-proxy': no_proxy
        })
        result = VirtWhoConfig.info({'id': virtwho_config['id']})
        assert result['http-proxy']['http-proxy-name'] == https_proxy_name
        assert result['connection']['ignore-proxy'] == 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('https_proxy',
                                    ETC_VIRTWHO_CONFIG) == https_proxy_url
        assert get_configure_option('no_proxy', ETC_VIRTWHO_CONFIG) == no_proxy

        # Check the http proxy option, update it via http proxy id
        http_proxy_url, http_proxy_name, http_proxy_id = create_http_proxy(
            http_type='http', org=default_org)
        VirtWhoConfig.update({
            'id': virtwho_config['id'],
            'http-proxy-id': http_proxy_id
        })
        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

        VirtWhoConfig.delete({'name': virtwho_config['name']})
        assert not VirtWhoConfig.exists(search=('name', form_data['name']))
Ejemplo n.º 15
0
    def test_positive_filter_option(self, form_data, virtwho_config):
        """ Verify filter option by hammer virt-who-config update"

        :id: f46e4aa8-c325-4281-8744-f85e819e68c1

        :expectedresults: filter and filter_hosts can be updated.

        :CaseLevel: Integration

        :CaseImportance: Medium
        """
        regex = '.*redhat.com'
        whitelist = {'id': virtwho_config['id'], 'filtering-mode': 'whitelist', 'whitelist': regex}
        blacklist = {'id': virtwho_config['id'], 'filtering-mode': 'blacklist', 'blacklist': regex}
        if settings.virtwho.hypervisor_type == 'esx':
            whitelist['filter-host-parents'] = regex
            blacklist['exclude-host-parents'] = regex
        config_file = get_configure_file(virtwho_config['id'])
        command = get_configure_command(virtwho_config['id'])
        # Update Whitelist and check the result
        VirtWhoConfig.update(whitelist)
        result = VirtWhoConfig.info({'id': virtwho_config['id']})
        assert result['connection']['filtering'] == 'Whitelist'
        assert result['connection']['filtered-hosts'] == regex
        if settings.virtwho.hypervisor_type == 'esx':
            assert result['connection']['filter-host-parents'] == regex
        deploy_configure_by_command(command)
        assert get_configure_option('filter_hosts', config_file) == regex
        if settings.virtwho.hypervisor_type == 'esx':
            assert get_configure_option('filter_host_parents', config_file) == regex
        # Update Blacklist and check the result
        VirtWhoConfig.update(blacklist)
        result = VirtWhoConfig.info({'id': virtwho_config['id']})
        assert result['connection']['filtering'] == 'Blacklist'
        assert result['connection']['excluded-hosts'] == regex
        if settings.virtwho.hypervisor_type == 'esx':
            assert result['connection']['exclude-host-parents'] == regex
        deploy_configure_by_command(command)
        assert get_configure_option('exclude_hosts', config_file) == regex
        if settings.virtwho.hypervisor_type == 'esx':
            assert get_configure_option('exclude_host_parents', config_file) == regex
        VirtWhoConfig.delete({'name': virtwho_config['name']})
        assert not VirtWhoConfig.exists(search=('name', form_data['name']))
Ejemplo n.º 16
0
    def test_positive_deploy_configure_by_script(self, default_org, form_data, virtwho_config):
        """Verify " hammer virt-who-config fetch"

        :id: 22dc8068-c843-4ca0-acbe-0b2aef8ece31

        :expectedresults: Config can be created, fetch and deploy

        :CaseLevel: Integration

        :CaseImportance: High
        """
        assert virtwho_config['status'] == 'No Report Yet'
        script = VirtWhoConfig.fetch({'id': virtwho_config['id']}, output_format='base')
        hypervisor_name, guest_name = deploy_configure_by_script(
            script, form_data['hypervisor-type'], debug=True, org=default_org.label
        )
        virt_who_instance = VirtWhoConfig.info({'id': virtwho_config['id']})['general-information'][
            '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
            result = Host.subscription_attach({'host-id': host['id'], 'subscription-id': vdc_id})
            assert result.strip() == 'Subscription attached to the host successfully.'
        VirtWhoConfig.delete({'name': virtwho_config['name']})
        assert not VirtWhoConfig.exists(search=('name', form_data['name']))
Ejemplo n.º 17
0
    def test_positive_foreman_packages_protection(self, form_data, virtwho_config):
        """foreman-protector should allow virt-who to be installed

        :id: 73dc895f-50b8-4de5-91de-ea55da935fe5

        :expectedresults:
            virt-who packages can be installed
            the virt-who plugin can be deployed successfully

        :CaseLevel: Integration

        :CaseImportance: Medium

        :BZ: 1783987
        """
        virtwho_package_locked()
        command = get_configure_command(virtwho_config['id'])
        deploy_configure_by_command(command)
        virt_who_instance = VirtWhoConfig.info({'id': virtwho_config['id']})[
            'general-information'
        ]['status']
        assert virt_who_instance == 'OK'
        VirtWhoConfig.delete({'name': virtwho_config['name']})
        assert not VirtWhoConfig.exists(search=('name', form_data['name']))
Ejemplo n.º 18
0
    def test_positive_foreman_packages_protection(self, form_data,
                                                  virtwho_config):
        """foreman-protector should allow virt-who to be installed

        :id: 635ef99b-c5a3-4ac4-a0f1-09f7036d116e

        :expectedresults:
            virt-who packages can be installed
            the virt-who plugin can be deployed successfully

        :CaseLevel: Integration

        :CaseImportance: Medium

        :BZ: 1783987
        """
        virtwho_package_locked()
        command = get_configure_command(virtwho_config['id'])
        deploy_configure_by_command(command, form_data['hypervisor-type'])
        virt_who_instance = VirtWhoConfig.info(
            {'id': virtwho_config['id']})['general-information']['status']
        assert virt_who_instance == 'OK'
        VirtWhoConfig.delete({'name': virtwho_config['name']})
        assert not VirtWhoConfig.exists(search=('name', form_data['name']))
Ejemplo n.º 19
0
    def test_positive_deploy_configure_by_script(self):
        """ Verify " hammer virt-who-config fetch"

        :id: ef0f1e33-7084-4d0e-95f1-d3080dfbb4cc

        :expectedresults: Config can be created, fetch and deploy

        :CaseLevel: Integration

        :CaseImportance: High
        """
        name = gen_string('alpha')
        args = self._make_virtwho_configure()
        args.update({'name': name})
        vhd = VirtWhoConfig.create(args)['general-information']
        self.assertEqual(vhd['status'], 'No Report Yet')
        script = VirtWhoConfig.fetch({'id': vhd['id']}, output_format='plain')
        hypervisor_name, guest_name = deploy_configure_by_script(script,
                                                                 debug=True)
        self.assertEqual(
            VirtWhoConfig.info({'id':
                                vhd['id']})['general-information']['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:
            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
            result = Host.subscription_attach({
                'host-id': host['id'],
                'subscription-id': vdc_id
            })
            self.assertTrue(
                'attached to the host successfully' in '\n'.join(result))
        VirtWhoConfig.delete({'name': name})
        self.assertFalse(VirtWhoConfig.exists(search=('name', name)))
Ejemplo n.º 20
0
    def test_positive_hypervisor_id_option(self, form_data, virtwho_config):
        """ Verify hypervisor_id option by hammer virt-who-config update"

        :id: eae7e767-8a71-424c-87da-475c91ac2ea1

        :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:
            VirtWhoConfig.update({'id': virtwho_config['id'], 'hypervisor-id': value})
            result = VirtWhoConfig.info({'id': virtwho_config['id']})
            assert result['connection']['hypervisor-id'] == value
            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
        VirtWhoConfig.delete({'name': virtwho_config['name']})
        assert not VirtWhoConfig.exists(search=('name', form_data['name']))
Ejemplo n.º 21
0
def virtwho_config(form_data):
    return VirtWhoConfig.create(form_data)['general-information']
Ejemplo n.º 22
0
    def test_positive_filter_option(self):
        """ Verify filter option by hammer virt-who-config update"

        :id: f46e4aa8-c325-4281-8744-f85e819e68c1

        :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 = VirtWhoConfig.create(args)['general-information']
        regex = '.*redhat.com'
        whitelist = {
            'id': vhd['id'],
            'filtering-mode': 'whitelist',
            'whitelist': regex,
        }
        blacklist = {
            'id': vhd['id'],
            'filtering-mode': 'blacklist',
            'blacklist': regex,
        }
        if self.hypervisor_type == 'esx':
            whitelist['filter-host-parents'] = regex
            blacklist['exclude-host-parents'] = regex
        config_file = get_configure_file(vhd['id'])
        command = get_configure_command(vhd['id'])
        # Update Whitelist and check the result
        VirtWhoConfig.update(whitelist)
        result = VirtWhoConfig.info({'id': vhd['id']})
        self.assertEqual(result['connection']['filtering'], 'Whitelist')
        self.assertEqual(result['connection']['filtered-hosts'], regex)
        if self.hypervisor_type == 'esx':
            self.assertEqual(result['connection']['filter-host-parents'],
                             regex)
        deploy_configure_by_command(command)
        self.assertEqual(get_configure_option('filter_hosts', config_file),
                         regex)
        if self.hypervisor_type == 'esx':
            self.assertEqual(
                get_configure_option('filter_host_parents', config_file),
                regex)
        # Update Blacklist and check the result
        VirtWhoConfig.update(blacklist)
        result = VirtWhoConfig.info({'id': vhd['id']})
        self.assertEqual(result['connection']['filtering'], 'Blacklist')
        self.assertEqual(result['connection']['excluded-hosts'], regex)
        if self.hypervisor_type == 'esx':
            self.assertEqual(result['connection']['exclude-host-parents'],
                             regex)
        deploy_configure_by_command(command)
        self.assertEqual(get_configure_option('exclude_hosts', config_file),
                         regex)
        if self.hypervisor_type == 'esx':
            self.assertEqual(
                get_configure_option('exclude_host_parents', config_file),
                regex)
        VirtWhoConfig.delete({'name': name})
        self.assertFalse(VirtWhoConfig.exists(search=('name', name)))
Ejemplo n.º 23
0
    def virt_who_hypervisor_config(
        self,
        config_id,
        org_id=None,
        lce_id=None,
        hypervisor_hostname=None,
        configure_ssh=False,
        hypervisor_user=None,
        subscription_name=None,
        exec_one_shot=False,
        upload_manifest=True,
        extra_repos=None,
    ):
        """
        Configure virtual machine as hypervisor virt-who service

        :param int config_id: virt-who config id
        :param int org_id: the organization id
        :param int lce_id: the lifecycle environment id to use
        :param str hypervisor_hostname: the hypervisor hostname
        :param str hypervisor_user: hypervisor user that connect with the ssh key
        :param bool configure_ssh: configure the ssh key to allow host to connect to hypervisor
        :param str subscription_name: the subscription name to assign to virt-who hypervisor guests
        :param bool exec_one_shot: whether to run the virt-who one-shot command after startup
        :param bool upload_manifest: whether to upload the organization manifest
        :param list extra_repos: (Optional) repositories dict options to setup additionally.
        """
        from robottelo.cli.org import Org
        from robottelo.cli import factory as cli_factory
        from robottelo.cli.lifecycleenvironment import LifecycleEnvironment
        from robottelo.cli.subscription import Subscription
        from robottelo.cli.virt_who_config import VirtWhoConfig

        org = cli_factory.make_org() if org_id is None else Org.info(
            {'id': org_id})

        if lce_id is None:
            lce = cli_factory.make_lifecycle_environment(
                {'organization-id': org['id']})
        else:
            lce = LifecycleEnvironment.info({
                'id': lce_id,
                'organization-id': org['id']
            })
        extra_repos = extra_repos or []
        repos = [
            # Red Hat Satellite Tools
            {
                'product': constants.PRDS['rhel'],
                'repository-set': constants.REPOSET['rhst7'],
                'repository': constants.REPOS['rhst7']['name'],
                'repository-id': constants.REPOS['rhst7']['id'],
                'url': settings.sattools_repo['rhel7'],
                'cdn': bool(settings.cdn
                            or not settings.sattools_repo['rhel7']),
            }
        ]
        repos.extend(extra_repos)
        content_setup_data = cli_factory.setup_cdn_and_custom_repos_content(
            org['id'],
            lce['id'],
            repos,
            upload_manifest=upload_manifest,
            rh_subscriptions=[constants.DEFAULT_SUBSCRIPTION_NAME],
        )
        activation_key = content_setup_data['activation_key']
        content_view = content_setup_data['content_view']
        self.contenthost_setup(
            org_label=org['label'],
            activation_key=activation_key['name'],
            patch_os_release_distro=constants.DISTRO_RHEL7,
            rh_repo_ids=[
                repo['repository-id'] for repo in repos if repo['cdn']
            ],
            install_katello_agent=False,
        )
        # configure manually RHEL custom repo url as sync time is very big
        # (more than 2 hours for RHEL 7Server) and not critical in this context.
        rhel_repo_option_name = (
            f'rhel{constants.DISTROS_MAJOR_VERSION[constants.DISTRO_RHEL7]}_repo'
        )
        rhel_repo_url = getattr(settings.repos, rhel_repo_option_name, None)
        if not rhel_repo_url:
            raise ValueError(
                f'Settings option "{rhel_repo_option_name}" is whether not set or does not exist'
            )
        self.configure_rhel_repo(rhel_repo_url)
        if hypervisor_hostname and configure_ssh:
            # configure ssh access of hypervisor from self
            hypervisor_ssh_key_name = f'hypervisor-{gen_alpha().lower()}.key'
            # upload the ssh key
            self.put_ssh_key(settings.server.ssh_key, hypervisor_ssh_key_name)
            # setup the ssh config and known_hosts files
            self.update_known_hosts(self,
                                    hypervisor_ssh_key_name,
                                    hypervisor_hostname,
                                    user=hypervisor_user)

        # upload the virt-who config deployment script
        virt_who_deploy_directory = '/root/virt_who_deploy_output'
        virt_who_deploy_filename = f'{gen_alpha(length=5)}-virt-who-deploy-{config_id}'
        virt_who_deploy_file = f'{virt_who_deploy_directory}/{virt_who_deploy_filename}'
        VirtWhoConfig.fetch({'id': config_id, 'output': virt_who_deploy_file})
        # remote_copy from satellite to self
        satellite = Satellite(settings.server.hostname)
        satellite.session.remote_copy(virt_who_deploy_file, self)

        # ensure the virt-who config deploy script is executable
        result = self.run(f'chmod +x {virt_who_deploy_file}')
        if result.status != 0:
            raise CLIFactoryError(
                f'Failed to set deployment script as executable:\n{result.stderr}'
            )
        # execute the deployment script
        result = self.run(f'{virt_who_deploy_file}')
        if result.status != 0:
            raise CLIFactoryError(
                f'Deployment script failure:\n{result.stderr}')
        # after this step, we should have virt-who service installed and started
        if exec_one_shot:
            # usually to be sure that the virt-who generated the report we need
            # to force a one shot report, for this we have to stop the virt-who
            # service
            result = self.run('service virt-who stop')
            if result.status != 0:
                raise CLIFactoryError(
                    f'Failed to stop the virt-who service:\n{result.stderr}')
            result = self.run('virt-who --one-shot', timeout=900)
            if result.status != 0:
                raise CLIFactoryError(
                    f'Failed when executing virt-who --one-shot:\n{result.stderr}'
                )
            result = self.run('service virt-who start')
            if result.status != 0:
                raise CLIFactoryError(
                    f'Failed to start the virt-who service:\n{result.stderr}')
        # after this step the hypervisor as a content host should be created
        # do not confuse virt-who host with hypervisor host as they can be
        # diffrent hosts and as per this setup we have only registered the virt-who
        # host, the hypervisor host should registered after virt-who send the
        # first report when started or with one shot command
        # the virt-who hypervisor will be registered to satellite with host name
        # like "virt-who-{hypervisor_hostname}-{organization_id}"
        virt_who_hypervisor_hostname = f'virt-who-{hypervisor_hostname}-{org["id"]}'
        # find the registered virt-who hypervisor host
        org_hosts = Host.list({
            'organization-id': org['id'],
            'search': f'name={virt_who_hypervisor_hostname}'
        })
        # Note: if one shot command was executed the report is immediately
        # generated, and the server must have already registered the virt-who
        # hypervisor host
        if not org_hosts and not exec_one_shot:
            # we have to wait until the first report was sent.
            # the report is generated after the virt-who service startup, but some
            # small delay can occur.
            max_time = time.time() + 60
            while time.time() <= max_time:
                time.sleep(5)
                org_hosts = Host.list({
                    'organization-id':
                    org['id'],
                    'search':
                    f'name={virt_who_hypervisor_hostname}',
                })
                if org_hosts:
                    break

        if len(org_hosts) == 0:
            raise CLIFactoryError(
                f'Failed to find hypervisor host:\n{result.stderr}')
        virt_who_hypervisor_host = org_hosts[0]
        subscription_id = None
        if hypervisor_hostname and subscription_name:
            subscriptions = Subscription.list({'organization-id': org_id},
                                              per_page=False)
            for subscription in subscriptions:
                if subscription['name'] == subscription_name:
                    subscription_id = subscription['id']
                    Host.subscription_attach({
                        'host': virt_who_hypervisor_hostname,
                        'subscription-id': subscription_id
                    })
                    break
        return {
            'subscription_id': subscription_id,
            'subscription_name': subscription_name,
            'activation_key_id': activation_key['id'],
            'organization_id': org['id'],
            'content_view_id': content_view['id'],
            'lifecycle_environment_id': lce['id'],
            'virt_who_hypervisor_host': virt_who_hypervisor_host,
        }