Пример #1
0
    def setUpClass(cls):
        super().setUpClass()
        bridge = settings.vlan_networking.bridge
        # RHV Settings
        cls.rhev_url = settings.rhev.hostname
        cls.rhev_password = settings.rhev.password
        cls.rhev_username = settings.rhev.username
        cls.rhev_datacenter = settings.rhev.datacenter
        cls.rhev_img_name = settings.rhev.image_name
        cls.rhev_img_arch = settings.rhev.image_arch
        cls.rhev_img_os = settings.rhev.image_os
        cls.rhev_img_user = settings.rhev.image_username
        cls.rhev_img_pass = settings.rhev.image_password
        cls.rhev_vm_name = settings.rhev.vm_name
        cls.rhev_storage_domain = settings.rhev.storage_domain
        cls.rhv_api = RHEVMSystem(
            hostname=cls.rhev_url.split('/')[2],
            username=cls.rhev_username,
            password=cls.rhev_password,
            version='4.0',
            verify=False,
        )
        cls.cluster_id = cls.rhv_api.get_cluster(cls.rhev_datacenter).id
        cls.storage_id = cls.rhv_api.get_storage_domain(cls.rhev_storage_domain).id
        cls.network_id = (
            cls.rhv_api.api.system_service().networks_service().list(search=f'name={bridge}')[0].id
        )
        if is_open('BZ:1685949'):
            dc = cls.rhv_api._data_centers_service.list(search=f'name={cls.rhev_datacenter}')[0]
            dc = cls.rhv_api._data_centers_service.data_center_service(dc.id)
            cls.quota = dc.quotas_service().list()[0].id
        else:
            cls.quota = 'Default'

        # Vmware Settings
        cls.vmware_server = settings.vmware.vcenter
        cls.vmware_password = settings.vmware.password
        cls.vmware_username = settings.vmware.username
        cls.vmware_datacenter = settings.vmware.datacenter
        cls.vmware_img_name = settings.vmware.image_name
        cls.vmware_img_arch = settings.vmware.image_arch
        cls.vmware_img_os = settings.vmware.image_os
        cls.vmware_img_user = settings.vmware.image_username
        cls.vmware_img_pass = settings.vmware.image_password
        cls.vmware_vm_name = settings.vmware.vm_name
        cls.current_interface = VMWARE_CONSTANTS.get('network_interfaces') % bridge
        cls.vmware_api = VMWareSystem(
            hostname=cls.vmware_server, username=cls.vmware_username, password=cls.vmware_password
        )
        cls.vmware_net_id = cls.vmware_api.get_network(cls.current_interface)._moId

        # Provisioning setup
        cls.org = entities.Organization(name=gen_string('alpha')).create()
        cls.org_name = cls.org.name
        cls.loc = entities.Location(name=gen_string('alpha'), organization=[cls.org]).create()
        cls.loc_name = cls.loc.name
        cls.config_env = configure_provisioning(
            compute=True, org=cls.org, loc=cls.loc, os=cls.rhev_img_os
        )
        cls.os_name = cls.config_env['os']
    def setUpClass(cls):
        super(ComputeResourceHostTestCase, cls).setUpClass()
        bridge = settings.vlan_networking.bridge
        # RHV Settings
        cls.rhev_url = settings.rhev.hostname
        cls.rhev_password = settings.rhev.password
        cls.rhev_username = settings.rhev.username
        cls.rhev_datacenter = settings.rhev.datacenter
        cls.rhev_img_name = settings.rhev.image_name
        cls.rhev_img_arch = settings.rhev.image_arch
        cls.rhev_img_os = settings.rhev.image_os
        cls.rhev_img_user = settings.rhev.image_username
        cls.rhev_img_pass = settings.rhev.image_password
        cls.rhev_vm_name = settings.rhev.vm_name
        cls.rhev_storage_domain = settings.rhev.storage_domain
        cls.rhv_api = RHEVMSystem(hostname=cls.rhev_url.split('/')[2],
                                  username=cls.rhev_username,
                                  password=cls.rhev_password,
                                  version='4.0',
                                  verify=False)
        cls.cluster_id = cls.rhv_api.get_cluster(cls.rhev_datacenter).id
        cls.storage_id = cls.rhv_api._get_storage_domain(
            cls.rhev_storage_domain).id
        cls.network_id = (
            cls.rhv_api.api.system_service().networks_service().list(
                search='name={0}'.format(bridge))[0].id)

        # Vmware Settings
        cls.vmware_server = settings.vmware.vcenter
        cls.vmware_password = settings.vmware.password
        cls.vmware_username = settings.vmware.username
        cls.vmware_datacenter = settings.vmware.datacenter
        cls.vmware_img_name = settings.vmware.image_name
        cls.vmware_img_arch = settings.vmware.image_arch
        cls.vmware_img_os = settings.vmware.image_os
        cls.vmware_img_user = settings.vmware.image_username
        cls.vmware_img_pass = settings.vmware.image_password
        cls.vmware_vm_name = settings.vmware.vm_name
        cls.current_interface = (VMWARE_CONSTANTS.get('network_interfaces') %
                                 bridge)
        cls.vmware_api = VMWareSystem(hostname=cls.vmware_server,
                                      username=cls.vmware_username,
                                      password=cls.vmware_password)
        cls.vmware_net_id = cls.vmware_api.get_obj(
            vimtype=vim.Network, name=cls.current_interface)._moId

        # Provisioning setup
        cls.org = entities.Organization(name=gen_string('alpha')).create()
        cls.org_name = cls.org.name
        cls.loc = entities.Location(
            name=gen_string('alpha'),
            organization=[cls.org],
        ).create()
        cls.loc_name = cls.loc.name
        cls.config_env = configure_provisioning(compute=True,
                                                org=cls.org,
                                                loc=cls.loc,
                                                os=cls.rhev_img_os)
        cls.os_name = cls.config_env['os']
Пример #3
0
 def setUpClass(cls):
     super(VmwareComputeResourceTestCase, cls).setUpClass()
     cls.vmware_url = settings.vmware.vcenter
     cls.vmware_password = settings.vmware.password
     cls.vmware_username = settings.vmware.username
     cls.vmware_datacenter = settings.vmware.datacenter
     cls.vmware_img_name = settings.vmware.image_name
     cls.vmware_img_arch = settings.vmware.image_arch
     cls.vmware_img_os = settings.vmware.image_os
     cls.vmware_img_user = settings.vmware.image_username
     cls.vmware_img_pass = settings.vmware.image_password
     cls.vmware_vm_name = settings.vmware.vm_name
     cls.current_interface = (VMWARE_CONSTANTS.get('network_interfaces') %
                              settings.vlan_networking.bridge)
 def setUpClass(cls):
     super(VmwareComputeResourceTestCase, cls).setUpClass()
     cls.vmware_url = settings.vmware.vcenter
     cls.vmware_password = settings.vmware.password
     cls.vmware_username = settings.vmware.username
     cls.vmware_datacenter = settings.vmware.datacenter
     cls.vmware_img_name = settings.vmware.image_name
     cls.vmware_img_arch = settings.vmware.image_arch
     cls.vmware_img_os = settings.vmware.image_os
     cls.vmware_img_user = settings.vmware.image_username
     cls.vmware_img_pass = settings.vmware.image_password
     cls.vmware_vm_name = settings.vmware.vm_name
     cls.current_interface = (
         VMWARE_CONSTANTS.get(
             'network_interfaces') % settings.vlan_networking.bridge
     )
 def setUpClass(cls):
     super().setUpClass()
     cls.org = make_org()
     cls.loc = make_location()
     Org.add_location({'id': cls.org['id'], 'location-id': cls.loc['id']})
     cls.vmware_server = settings.vmware.vcenter
     cls.vmware_password = settings.vmware.password
     cls.vmware_username = settings.vmware.username
     cls.vmware_datacenter = settings.vmware.datacenter
     cls.vmware_img_name = settings.vmware.image_name
     cls.vmware_img_arch = settings.vmware.image_arch
     cls.vmware_img_os = settings.vmware.image_os
     cls.vmware_img_user = settings.vmware.image_username
     cls.vmware_img_pass = settings.vmware.image_password
     cls.vmware_vm_name = settings.vmware.vm_name
     cls.current_interface = (VMWARE_CONSTANTS.get('network_interfaces') %
                              settings.vlan_networking.bridge)
def vmware(module_org, module_location):
    vmware = type('vmware', (object, ), {})()
    vmware.org = module_org
    vmware.loc = module_location
    Org.add_location({'id': vmware.org.id, 'location-id': vmware.loc.id})
    vmware.vmware_server = settings.vmware.vcenter
    vmware.vmware_password = settings.vmware.password
    vmware.vmware_username = settings.vmware.username
    vmware.vmware_datacenter = settings.vmware.datacenter
    vmware.vmware_img_name = settings.vmware.image_name
    vmware.vmware_img_arch = settings.vmware.image_arch
    vmware.vmware_img_os = settings.vmware.image_os
    vmware.vmware_img_user = settings.vmware.image_username
    vmware.vmware_img_pass = settings.vmware.image_password
    vmware.vmware_vm_name = settings.vmware.vm_name
    vmware.current_interface = (VMWARE_CONSTANTS.get('network_interfaces') %
                                settings.vlan_networking.bridge)
    return vmware
 def setUpClass(cls):
     super(VMWareComputeResourceTestCase, cls).setUpClass()
     cls.org = make_org()
     cls.loc = make_location()
     Org.add_location({'id': cls.org['id'], 'location-id': cls.loc['id']})
     cls.vmware_server = settings.vmware.vcenter
     cls.vmware_password = settings.vmware.password
     cls.vmware_username = settings.vmware.username
     cls.vmware_datacenter = settings.vmware.datacenter
     cls.vmware_img_name = settings.vmware.image_name
     cls.vmware_img_arch = settings.vmware.image_arch
     cls.vmware_img_os = settings.vmware.image_os
     cls.vmware_img_user = settings.vmware.image_username
     cls.vmware_img_pass = settings.vmware.image_password
     cls.vmware_vm_name = settings.vmware.vm_name
     cls.current_interface = (
         VMWARE_CONSTANTS.get(
             'network_interfaces') % settings.vlan_networking.bridge
     )
Пример #8
0
def vmware(bridge):
    vmware = {}
    vmware['vmware_server'] = settings.vmware.vcenter
    vmware['vmware_password'] = settings.vmware.password
    vmware['vmware_username'] = settings.vmware.username
    vmware['vmware_datacenter'] = settings.vmware.datacenter
    vmware['vmware_img_name'] = settings.vmware.image_name
    vmware['vmware_img_arch'] = settings.vmware.image_arch
    vmware['vmware_img_os'] = settings.vmware.image_os
    vmware['vmware_img_user'] = settings.vmware.image_username
    vmware['vmware_img_pass'] = settings.vmware.image_password
    vmware['vmware_vm_name'] = settings.vmware.vm_name
    vmware['current_interface'] = VMWARE_CONSTANTS.get('network_interfaces') % bridge
    vmware['vmware_api'] = VMWareSystem(
        hostname=vmware['vmware_server'],
        username=vmware['vmware_username'],
        password=vmware['vmware_password'],
    )
    vmware['vmware_net_id'] = vmware['vmware_api'].get_network(vmware['current_interface'])._moId
    return vmware
def vmware():
    bridge = settings.vlan_networking.bridge
    vmware = type("", (), {})()
    vmware.vmware_server = settings.vmware.vcenter
    vmware.vmware_password = settings.vmware.password
    vmware.vmware_username = settings.vmware.username
    vmware.vmware_datacenter = settings.vmware.datacenter
    vmware.vmware_img_name = settings.vmware.image_name
    vmware.vmware_img_arch = settings.vmware.image_arch
    vmware.vmware_img_os = settings.vmware.image_os
    vmware.vmware_img_user = settings.vmware.image_username
    vmware.vmware_img_pass = settings.vmware.image_password
    vmware.vmware_vm_name = settings.vmware.vm_name
    vmware.current_interface = VMWARE_CONSTANTS.get('network_interfaces') % bridge
    vmware.vmware_api = VMWareSystem(
        hostname=vmware.vmware_server,
        username=vmware.vmware_username,
        password=vmware.vmware_password,
    )
    vmware.vmware_net_id = vmware.vmware_api.get_network(vmware.current_interface)._moId
    return vmware
Пример #10
0
def test_positive_access_vmware_with_custom_profile(session,
                                                    module_vmware_settings):
    """Associate custom default (3-Large) compute profile

    :id: 751ef765-5091-4322-a0d9-0c9c73009cc4

    :setup: vmware hostname and credentials.

    :steps:

        1. Create a compute resource of type vmware.
        2. Provide valid hostname, username and password.
        3. Select the created vmware CR.
        4. Click Compute Profile tab.
        5. Edit (3-Large) with valid configurations and submit.

    :expectedresults: The Compute Resource created and associated to compute profile (3-Large)
        with provided values.

    :CaseLevel: Integration
    """
    cr_name = gen_string('alpha')
    data_store_summary_string = _get_vmware_datastore_summary_string()
    cr_profile_data = dict(
        cpus='2',
        cores_per_socket='2',
        memory='1024',
        firmware='EFI',
        cluster=VMWARE_CONSTANTS.get('cluster'),
        resource_pool=VMWARE_CONSTANTS.get('pool'),
        folder=VMWARE_CONSTANTS.get('folder'),
        guest_os=VMWARE_CONSTANTS.get('guest_os'),
        virtual_hw_version=VMWARE_CONSTANTS.get('virtualhw_version'),
        memory_hot_add=True,
        cpu_hot_add=True,
        cdrom_drive=True,
        annotation_notes=gen_string('alpha'),
        network_interfaces=[
            dict(
                nic_type=VMWARE_CONSTANTS.get('network_interface_name'),
                network=module_vmware_settings['current_interface'],
            ),
            dict(
                nic_type=VMWARE_CONSTANTS.get('network_interface_name'),
                network=module_vmware_settings['current_interface'],
            ),
        ],
        storage=[
            dict(
                controller=VMWARE_CONSTANTS.get('scsicontroller'),
                disks=[
                    dict(
                        data_store=data_store_summary_string,
                        size='10 GB',
                        thin_provision=True,
                        eager_zero=True,
                    ),
                    dict(
                        data_store=data_store_summary_string,
                        size='20 GB',
                        thin_provision=False,
                        eager_zero=False,
                    ),
                ],
            ),
            dict(
                controller=VMWARE_CONSTANTS.get('scsicontroller'),
                disks=[
                    dict(
                        data_store=data_store_summary_string,
                        size='30 GB',
                        thin_provision=False,
                        eager_zero=True,
                    )
                ],
            ),
        ],
    )
    with session:
        session.computeresource.create({
            'name':
            cr_name,
            'provider':
            FOREMAN_PROVIDERS['vmware'],
            'provider_content.vcenter':
            module_vmware_settings['vcenter'],
            'provider_content.user':
            module_vmware_settings['user'],
            'provider_content.password':
            module_vmware_settings['password'],
            'provider_content.datacenter.value':
            module_vmware_settings['datacenter'],
        })
        assert session.computeresource.search(cr_name)[0]['Name'] == cr_name
        session.computeresource.update_computeprofile(
            cr_name,
            COMPUTE_PROFILE_LARGE,
            {
                f'provider_content.{key}': value
                for key, value in cr_profile_data.items()
            },
        )
        values = session.computeresource.read_computeprofile(
            cr_name, COMPUTE_PROFILE_LARGE)
        provider_content = values['provider_content']
        # assert main compute resource profile data updated successfully.
        excluded_keys = ['network_interfaces', 'storage']
        expected_value = {
            key: value
            for key, value in cr_profile_data.items()
            if key not in excluded_keys
        }
        provided_value = {
            key: value
            for key, value in provider_content.items() if key in expected_value
        }
        assert provided_value == expected_value
        # assert compute resource profile network data updated successfully.
        for network_index, expected_network_value in enumerate(
                cr_profile_data['network_interfaces']):
            provided_network_value = {
                key: value
                for key, value in provider_content['network_interfaces']
                [network_index].items() if key in expected_network_value
            }
            assert provided_network_value == expected_network_value
        # assert compute resource profile storage data updated successfully.
        for controller_index, expected_controller_value in enumerate(
                cr_profile_data['storage']):
            provided_controller_value = provider_content['storage'][
                controller_index]
            assert (provided_controller_value['controller'] ==
                    expected_controller_value['controller'])
            for disk_index, expected_disk_value in enumerate(
                    expected_controller_value['disks']):
                provided_disk_value = {
                    key: value
                    for key, value in provided_controller_value['disks']
                    [disk_index].items() if key in expected_disk_value
                }
                assert provided_disk_value == expected_disk_value
Пример #11
0
    def test_positive_access_vmware_with_custom_profile(self):
        """Associate custom default (3-Large) compute profile

        :id: 751ef765-5091-4322-a0d9-0c9c73009cc4

        :setup: vmware hostname and credentials.

        :steps:

            1. Create a compute resource of type vmware.
            2. Provide valid hostname, username and password.
            3. Select the created vmware CR.
            4. Click Compute Profile tab.
            5. Edit (3-Large) with valid configurations and submit.

        :expectedresults: The Compute Resource created and opened successfully

        :Caseautomation: notautomated

        :CaseLevel: Integration
        """
        parameter_list = [
            ['VCenter/Server', self.vmware_url, 'field'],
            ['Username', self.vmware_username, 'field'],
            ['Password', self.vmware_password, 'field'],
            ['Datacenter', self.vmware_datacenter, 'special select'],
        ]
        name = gen_string('alpha')
        with Session(self) as session:
            make_resource(session,
                          name=name,
                          provider_type=FOREMAN_PROVIDERS['vmware'],
                          parameter_list=parameter_list)
            self.compute_resource.set_profile_values(
                name,
                COMPUTE_PROFILE_LARGE,
                cpus=2,
                corespersocket=2,
                memory=1024,
                cluster=VMWARE_CONSTANTS.get('cluster'),
                folder=VMWARE_CONSTANTS.get('folder'),
                guest_os=VMWARE_CONSTANTS.get('guest_os'),
                scsicontroller=VMWARE_CONSTANTS.get('scsicontroller'),
                virtualhw_version=VMWARE_CONSTANTS.get('virtualhw_version'),
                memory_hotadd=True,
                cpu_hotadd=True,
                cdrom_drive=False,
                annotation_notes=gen_string('alpha'),
                pool=VMWARE_CONSTANTS.get('pool'),
                network_interfaces=[
                    dict(name=VMWARE_CONSTANTS.get('network_interface_name'),
                         network=self.current_interface),
                    dict(name=VMWARE_CONSTANTS.get('network_interface_name'),
                         network=self.current_interface),
                ],
                storage=[
                    dict(
                        datastore=VMWARE_CONSTANTS.get('datastore'),
                        size='10',
                        thin_provision=True,
                        eager_zero=True,
                    ),
                    dict(
                        datastore=VMWARE_CONSTANTS.get('datastore'),
                        size='10',
                        thin_provision=False,
                        eager_zero=False,
                    )
                ])
            self.assertIsNotNone(self.compute_resource.search(name))
    def test_positive_apply_vmware_with_custom_profile_to_host(self):
        """Associate custom default (3-Large) compute profile with hostgroup
        and then inherit it to the host

        :id: c16c6d42-3950-46a7-bfe6-5e19bcfa29d0

        :customerscenario: true

        :setup: vmware hostname and credentials.

        :steps:

            1. Create a compute resource of type vmware.
            2. Provide valid hostname, username and password.
            3. Select the created vmware CR.
            4. Click Compute Profile tab.
            5. Edit (3-Large) with valid configurations and submit.
            6. Create new host group with custom profile
            7. Open new host page and put host group name into corresponding
               field
            8. Check that compute profile is inherited and then switch to
               Virtual Machine tab

        :expectedresults: All fields values for Virtual Machine tab are
            inherited from custom profile and have non default values

        :Caseautomation: Automated

        :BZ: 1249744

        :CaseLevel: Integration
        """
        org = entities.Organization().create()
        parameter_list = [
            ['VCenter/Server', self.vmware_url, 'field'],
            ['Username', self.vmware_username, 'field'],
            ['Password', self.vmware_password, 'field'],
            ['Datacenter', self.vmware_datacenter, 'special select'],
        ]
        name = gen_string('alpha')
        hg_name = gen_string('alpha')
        with Session(self) as session:
            make_resource(
                session,
                name=name,
                provider_type=FOREMAN_PROVIDERS['vmware'],
                orgs=[org.name],
                org_select=True,
                parameter_list=parameter_list
            )
            self.compute_resource.set_profile_values(
                name, COMPUTE_PROFILE_LARGE,
                cpus=3,
                corespersocket=4,
                memory=2048,
                cluster=VMWARE_CONSTANTS.get('cluster'),
                folder=VMWARE_CONSTANTS.get('folder'),
            )
            self.assertIsNotNone(self.compute_resource.search(name))
            make_hostgroup(
                session,
                name=hg_name,
                organizations=[org.name],
                parameters_list=[
                    ['Host Group', 'Compute Profile', COMPUTE_PROFILE_LARGE],
                ],
            )
            self.hosts.navigate_to_entity()
            self.hosts.click(locators['host.new'])
            self.hosts.assign_value(locators['host.organization'], org.name)
            # Selecting host group and then compute resource. It is not
            # possible to do it in opposite order as mentioned in initial BZ,
            # because selecting host group will always reset most fields values
            self.hosts.assign_value(locators['host.host_group'], hg_name)
            self.hosts.click(locators['host.deploy_on'])
            self.hosts.assign_value(
                common_locators['select_list_search_box'], name)
            self.hosts.click(
                common_locators['entity_select_list'] %
                '{} (VMware)'.format(name)
            )
            # Check that compute profile is inherited automatically from host
            # group
            self.assertEqual(
                self.hosts.get_element_value(
                    locators['host.fetch_compute_profile']),
                COMPUTE_PROFILE_LARGE
            )
            # Open Virtual Machine tab
            self.hosts.click(tab_locators['host.tab_virtual_machine'])
            # Check that all values are inherited from custom profile
            for locator, value in [
                ['host.cpus', '3'],
                ['host.cores', '4'],
                ['host.memory', '2048'],
                ['host.fetch_cluster', VMWARE_CONSTANTS.get('cluster')],
                ['host.fetch_folder', VMWARE_CONSTANTS.get('folder')],

            ]:
                self.assertEqual(
                    self.hosts.get_element_value(locators[locator]), value)
    def test_positive_access_vmware_with_custom_profile(self):
        """Associate custom default (3-Large) compute profile

        :id: 751ef765-5091-4322-a0d9-0c9c73009cc4

        :setup: vmware hostname and credentials.

        :steps:

            1. Create a compute resource of type vmware.
            2. Provide valid hostname, username and password.
            3. Select the created vmware CR.
            4. Click Compute Profile tab.
            5. Edit (3-Large) with valid configurations and submit.

        :expectedresults: The Compute Resource created and opened successfully

        :Caseautomation: Automated

        :CaseLevel: Integration
        """
        parameter_list = [
            ['VCenter/Server', self.vmware_url, 'field'],
            ['Username', self.vmware_username, 'field'],
            ['Password', self.vmware_password, 'field'],
            ['Datacenter', self.vmware_datacenter, 'special select'],
        ]
        name = gen_string('alpha')
        with Session(self) as session:
            make_resource(
                session,
                name=name,
                provider_type=FOREMAN_PROVIDERS['vmware'],
                parameter_list=parameter_list
            )
            self.compute_resource.set_profile_values(
                name, COMPUTE_PROFILE_LARGE,
                cpus=2,
                corespersocket=2,
                memory=1024,
                cluster=VMWARE_CONSTANTS.get('cluster'),
                folder=VMWARE_CONSTANTS.get('folder'),
                guest_os=VMWARE_CONSTANTS.get('guest_os'),
                scsicontroller=VMWARE_CONSTANTS.get('scsicontroller'),
                virtualhw_version=VMWARE_CONSTANTS.get('virtualhw_version'),
                memory_hotadd=True,
                cpu_hotadd=True,
                cdrom_drive=False,
                annotation_notes=gen_string('alpha'),
                pool=VMWARE_CONSTANTS.get('pool'),
                network_interfaces=[
                    dict(
                        name=VMWARE_CONSTANTS.get('network_interface_name'),
                        network=self.current_interface
                    ),
                    dict(
                        name=VMWARE_CONSTANTS.get('network_interface_name'),
                        network=self.current_interface
                    ),
                ],
                storage=[
                    dict(
                        datastore=VMWARE_CONSTANTS.get('datastore'),
                        size='10',
                        thin_provision=True,
                        eager_zero=True,
                    ),
                    dict(
                        datastore=VMWARE_CONSTANTS.get('datastore'),
                        size='10',
                        thin_provision=False,
                        eager_zero=False,
                    )
                ]
                )
            self.assertIsNotNone(self.compute_resource.search(name))
    def setUpClass(cls):
        super(ComputeResourceHostTestCase, cls).setUpClass()
        bridge = settings.vlan_networking.bridge
        # RHV Settings
        cls.rhev_url = settings.rhev.hostname
        cls.rhev_password = settings.rhev.password
        cls.rhev_username = settings.rhev.username
        cls.rhev_datacenter = settings.rhev.datacenter
        cls.rhev_img_name = settings.rhev.image_name
        cls.rhev_img_arch = settings.rhev.image_arch
        cls.rhev_img_os = settings.rhev.image_os
        cls.rhev_img_user = settings.rhev.image_username
        cls.rhev_img_pass = settings.rhev.image_password
        cls.rhev_vm_name = settings.rhev.vm_name
        cls.rhev_storage_domain = settings.rhev.storage_domain
        cls.rhv_api = RHEVMSystem(hostname=cls.rhev_url.split('/')[2],
                                  username=cls.rhev_username,
                                  password=cls.rhev_password,
                                  version='4.0',
                                  verify=False
                                  )
        cls.cluster_id = cls.rhv_api.get_cluster(cls.rhev_datacenter).id
        cls.storage_id = cls.rhv_api.get_storage_domain(
            cls.rhev_storage_domain).id
        cls.network_id = (
            cls.rhv_api.api.system_service().networks_service(
            ).list(search='name={0}'.format(bridge))[0].id
        )
        if bz_bug_is_open(1685949):
            dc = cls.rhv_api._data_centers_service.list(
                search='name={0}'.format(cls.rhev_datacenter))[0]
            dc = cls.rhv_api._data_centers_service.data_center_service(dc.id)
            cls.quota = dc.quotas_service().list()[0].id
        else:
            cls.quota = 'Default'

        # Vmware Settings
        cls.vmware_server = settings.vmware.vcenter
        cls.vmware_password = settings.vmware.password
        cls.vmware_username = settings.vmware.username
        cls.vmware_datacenter = settings.vmware.datacenter
        cls.vmware_img_name = settings.vmware.image_name
        cls.vmware_img_arch = settings.vmware.image_arch
        cls.vmware_img_os = settings.vmware.image_os
        cls.vmware_img_user = settings.vmware.image_username
        cls.vmware_img_pass = settings.vmware.image_password
        cls.vmware_vm_name = settings.vmware.vm_name
        cls.current_interface = (
                VMWARE_CONSTANTS.get('network_interfaces') % bridge
        )
        cls.vmware_api = VMWareSystem(hostname=cls.vmware_server,
                                      username=cls.vmware_username,
                                      password=cls.vmware_password
                                      )
        cls.vmware_net_id = cls.vmware_api.get_network(
            cls.current_interface)._moId

        # Provisioning setup
        cls.org = entities.Organization(name=gen_string('alpha')).create()
        cls.org_name = cls.org.name
        cls.loc = entities.Location(
            name=gen_string('alpha'),
            organization=[cls.org],
        ).create()
        cls.loc_name = cls.loc.name
        cls.config_env = configure_provisioning(
            compute=True,
            org=cls.org,
            loc=cls.loc,
            os=cls.rhev_img_os
        )
        cls.os_name = cls.config_env['os']
def test_positive_access_vmware_with_custom_profile(session,  module_vmware_settings):
    """Associate custom default (3-Large) compute profile

    :id: 751ef765-5091-4322-a0d9-0c9c73009cc4

    :setup: vmware hostname and credentials.

    :steps:

        1. Create a compute resource of type vmware.
        2. Provide valid hostname, username and password.
        3. Select the created vmware CR.
        4. Click Compute Profile tab.
        5. Edit (3-Large) with valid configurations and submit.

    :expectedresults: The Compute Resource created and associated to compute profile (3-Large)
        with provided values.

    :CaseLevel: Integration
    """
    cr_name = gen_string('alpha')
    data_store_summary_string = _get_vmware_datastore_summary_string()
    cr_profile_data = dict(
        cpus='2',
        cores_per_socket='2',
        memory='1024',
        firmware='EFI',
        cluster=VMWARE_CONSTANTS.get('cluster'),
        resource_pool=VMWARE_CONSTANTS.get('pool'),
        folder=VMWARE_CONSTANTS.get('folder'),
        guest_os=VMWARE_CONSTANTS.get('guest_os'),
        virtual_hw_version=VMWARE_CONSTANTS.get('virtualhw_version'),
        memory_hot_add=True,
        cpu_hot_add=True,
        cdrom_drive=True,
        annotation_notes=gen_string('alpha'),
        network_interfaces=[
            dict(nic_type=VMWARE_CONSTANTS.get('network_interface_name'),
                 network=module_vmware_settings['current_interface']),
            dict(nic_type=VMWARE_CONSTANTS.get('network_interface_name'),
                 network=module_vmware_settings['current_interface']),
        ],
        storage=[
            dict(
                controller=VMWARE_CONSTANTS.get('scsicontroller'),
                disks=[
                    dict(
                        data_store=data_store_summary_string,
                        size='10 GB',
                        thin_provision=True,
                        eager_zero=True,
                    ),
                    dict(
                        data_store=data_store_summary_string,
                        size='20 GB',
                        thin_provision=False,
                        eager_zero=False,
                    ),
                ],
            ),
            dict(
                controller=VMWARE_CONSTANTS.get('scsicontroller'),
                disks=[
                    dict(
                        data_store=data_store_summary_string,
                        size='30 GB',
                        thin_provision=False,
                        eager_zero=True,
                    ),
                ],
            ),
        ],
    )
    with session:
        session.computeresource.create({
            'name': cr_name,
            'provider': FOREMAN_PROVIDERS['vmware'],
            'provider_content.vcenter': module_vmware_settings['vcenter'],
            'provider_content.user': module_vmware_settings['user'],
            'provider_content.password': module_vmware_settings['password'],
            'provider_content.datacenter.value': module_vmware_settings['datacenter'],
        })
        assert session.computeresource.search(cr_name)[0]['Name'] == cr_name
        session.computeresource.update_computeprofile(
            cr_name,
            COMPUTE_PROFILE_LARGE,
            {'provider_content.{0}'.format(key): value for key, value in cr_profile_data.items()}
        )
        values = session.computeresource.read_computeprofile(cr_name, COMPUTE_PROFILE_LARGE)
        provider_content = values['provider_content']
        # assert main compute resource profile data updated successfully.
        excluded_keys = ['network_interfaces', 'storage']
        expected_value = {key: value for key, value in cr_profile_data.items()
                          if key not in excluded_keys}
        provided_value = {key: value for key, value in provider_content.items()
                          if key in expected_value}
        assert provided_value == expected_value
        # assert compute resource profile network data updated successfully.
        for network_index, expected_network_value in enumerate(
                cr_profile_data['network_interfaces']):
            provided_network_value = {
                    key: value
                    for key, value in provider_content['network_interfaces'][network_index].items()
                    if key in expected_network_value
            }
            assert provided_network_value == expected_network_value
        # assert compute resource profile storage data updated successfully.
        for controller_index, expected_controller_value in enumerate(cr_profile_data['storage']):
            provided_controller_value = provider_content['storage'][controller_index]
            assert (provided_controller_value['controller']
                    == expected_controller_value['controller'])
            for disk_index, expected_disk_value in enumerate(expected_controller_value['disks']):
                provided_disk_value = {
                        key: value
                        for key, value in provided_controller_value['disks'][disk_index].items()
                        if key in expected_disk_value
                }
                assert provided_disk_value == expected_disk_value
    def test_positive_apply_vmware_with_custom_profile_to_host(self):
        """Associate custom default (3-Large) compute profile with hostgroup
        and then inherit it to the host

        :id: c16c6d42-3950-46a7-bfe6-5e19bcfa29d0

        :customerscenario: true

        :setup: vmware hostname and credentials.

        :steps:

            1. Create a compute resource of type vmware.
            2. Provide valid hostname, username and password.
            3. Select the created vmware CR.
            4. Click Compute Profile tab.
            5. Edit (3-Large) with valid configurations and submit.
            6. Create new host group with custom profile
            7. Open new host page and put host group name into corresponding
               field
            8. Check that compute profile is inherited and then switch to
               Virtual Machine tab

        :expectedresults: All fields values for Virtual Machine tab are
            inherited from custom profile and have non default values

        :Caseautomation: Automated

        :BZ: 1249744

        :CaseLevel: Integration
        """
        org = entities.Organization().create()
        parameter_list = [
            ['VCenter/Server', self.vmware_url, 'field'],
            ['Username', self.vmware_username, 'field'],
            ['Password', self.vmware_password, 'field'],
            ['Datacenter', self.vmware_datacenter, 'special select'],
        ]
        name = gen_string('alpha')
        hg_name = gen_string('alpha')
        with Session(self) as session:
            make_resource(session,
                          name=name,
                          provider_type=FOREMAN_PROVIDERS['vmware'],
                          orgs=[org.name],
                          org_select=True,
                          parameter_list=parameter_list)
            self.compute_resource.set_profile_values(
                name,
                COMPUTE_PROFILE_LARGE,
                cpus=3,
                corespersocket=4,
                memory=2048,
                cluster=VMWARE_CONSTANTS.get('cluster'),
                folder=VMWARE_CONSTANTS.get('folder'),
            )
            self.assertIsNotNone(self.compute_resource.search(name))
            make_hostgroup(
                session,
                name=hg_name,
                organizations=[org.name],
                parameters_list=[
                    ['Host Group', 'Compute Profile', COMPUTE_PROFILE_LARGE],
                ],
            )
            self.hosts.navigate_to_entity()
            self.hosts.click(locators['host.new'])
            self.hosts.assign_value(locators['host.organization'], org.name)
            # Selecting host group and then compute resource. It is not
            # possible to do it in opposite order as mentioned in initial BZ,
            # because selecting host group will always reset most fields values
            self.hosts.assign_value(locators['host.host_group'], hg_name)
            self.hosts.click(locators['host.deploy_on'])
            self.hosts.assign_value(common_locators['select_list_search_box'],
                                    name)
            self.hosts.click(common_locators['entity_select_list'] %
                             '{} (VMware)'.format(name))
            # Check that compute profile is inherited automatically from host
            # group
            self.assertEqual(
                self.hosts.get_element_value(
                    locators['host.fetch_compute_profile']),
                COMPUTE_PROFILE_LARGE)
            # Open Virtual Machine tab
            self.hosts.click(tab_locators['host.tab_virtual_machine'])
            # Check that all values are inherited from custom profile
            for locator, value in [
                ['host.cpus', '3'],
                ['host.cores', '4'],
                ['host.memory', '2048'],
                ['host.fetch_cluster',
                 VMWARE_CONSTANTS.get('cluster')],
                ['host.fetch_folder',
                 VMWARE_CONSTANTS.get('folder')],
            ]:
                self.assertEqual(
                    self.hosts.get_element_value(locators[locator]), value)