def test_positive_provision_rhev_image_based_and_disassociate( provisioning, rhev, tear_down, setting_update): """Provision a host on RHEV compute resource using image-based provisioning :Requirement: Computeresource RHV :CaseComponent: ComputeResources-RHEV :Assignee: lhellebr :id: ba78858f-5cff-462e-a35d-f5aa4d11db52 :parametrized: yes :customerscenario: true :BZ: 1356126 :setup: RHEV with a template on it :steps: 1. Create a RHEV CR 1. Create an image on that CR 2. Create a new host using that CR and image 3. Disassociate the host from the CR :expectedresults: Host should be provisioned with image, associated to CR, then disassociated :CaseAutomation: Automated """ try: name = gen_string('alpha') rhv_cr = ComputeResource.create({ 'name': name, 'provider': 'Ovirt', 'user': rhev.username, 'password': rhev.password, 'datacenter': rhev.datacenter, 'url': rhev.hostname, 'ovirt-quota': rhev.quota, 'organizations': provisioning.org_name, 'locations': provisioning.loc_name, }) assert rhv_cr['name'] == name host_name = gen_string('alpha').lower() # use some RHEL (usually latest) os = (entities.OperatingSystem().search( query={ 'search': f'name="RedHat" AND (major="{RHEL_6_MAJOR_VERSION}" OR ' f'major="{RHEL_7_MAJOR_VERSION}")' })[0].read()) image = ComputeResource.image_create({ 'compute-resource': rhv_cr['name'], 'name': f'img {gen_string(str_type="alpha")}', 'uuid': rhev.image_uuid, 'operatingsystem-id': os.id, 'architecture': rhev.image_arch, 'username': '******', 'password': rhev.image_password, 'user-data': 'yes', # so finish template won't be used }) host = make_host({ 'name': f'{host_name}', 'organization': provisioning.org_name, 'domain': provisioning.config_env['domain'], 'subnet': provisioning.config_env['subnet'], 'location': provisioning.loc_name, 'compute-resource-id': rhv_cr.get('id'), 'compute-attributes': f"cluster={rhev.cluster_id}," "cores=1," "memory=1073741824," "start=0", 'ip': None, 'mac': None, 'interface': f"compute_name=nic1, compute_network={rhev.network_id}", 'provision-method': 'image', 'operatingsystem-id': os.id, 'architecture': rhev.image_arch, 'image-id': f'{image[0]["id"]}', }) hostname = f'{host_name}.{provisioning.config_env["domain"]}' assert hostname == host['name'] host_info = Host.info({'name': hostname}) # Check on RHV, if VM exists assert rhev.rhv_api.does_vm_exist(hostname) # Get the information of created VM rhv_vm = rhev.rhv_api.get_vm(hostname) # Assert of Satellite mac address for VM and Mac of VM created is same assert host_info.get('network').get( 'mac') == rhv_vm.get_nics()[0].mac.address # Check the host is associated to the CR assert 'compute-resource' in host_info assert host_info['compute-resource'] == name # Done. Do not try to SSH, this image-based test should work even without # being in the same network as RHEV. We checked the VM exists and # that's enough. # Disassociate the host from the CR, check it's disassociated Host.disassociate({'name': hostname}) host_info = Host.info({'name': hostname}) assert 'compute-resource' not in host_info finally: # Now, let's just remove the host Host.delete({'id': host['id']}) # Delete the VM since the disassociated VM won't get deleted rhv_vm.delete()