def test_positive_create_using_libvirt_without_mac(self): """Create a libvirt host and not specify a MAC address. @id: b003faa9-2810-4176-94d2-ea84bed248eb @Assert: Host is created """ compute_resource = entities.LibvirtComputeResource( url='qemu+ssh://root@{0}/system'.format( settings.compute_resources.libvirt_hostname)).create() host = entities.Host() host.create_missing() result = Host.create({ u'architecture-id': host.architecture.id, u'compute-resource-id': compute_resource.id, u'domain-id': host.domain.id, u'environment-id': host.environment.id, u'location-id': host.location.id, # pylint:disable=no-member u'medium-id': host.medium.id, u'name': host.name, u'operatingsystem-id': host.operatingsystem.id, # pylint:disable=no-member u'organization-id': host.organization.id, u'partition-table-id': host.ptable.id, u'puppet-proxy-id': self.puppet_proxy['id'], u'root-pass': host.root_pass, }) self.assertEqual(result['name'], host.name + '.' + host.domain.name) Host.delete({'id': result['id']})
def class_host_ud( self, azurermclient, session_puppet_enabled_sat, module_azurerm_cloudimg_puppet, module_puppet_loc, module_puppet_org, session_puppet_default_os, azurerm_hostgroup, ): """ Provisions the host on AzureRM using UserData template Later in tests this host will be used to perform assertions """ with session_puppet_enabled_sat.hammer_api_timeout(): with session_puppet_enabled_sat.skip_yum_update_during_provisioning( template='Kickstart default user data' ): host = session_puppet_enabled_sat.cli.Host.create( { 'name': self.hostname, 'compute-attributes': self.compute_attrs, 'interface': self.interfaces_attributes, 'image': module_azurerm_cloudimg_puppet.name, 'hostgroup': azurerm_hostgroup.name, 'location': module_puppet_loc.name, 'organization': module_puppet_org.name, 'operatingsystem-id': session_puppet_default_os.id, }, timeout=1800000, ) yield host with satellite_setting('destroy_vm_on_host_delete=True'): Host.delete({'name': self.fullhostname}, timeout=1800000)
def test_positive_create_using_libvirt_without_mac(self): """Create a libvirt host and not specify a MAC address. @Feature: Hosts @Assert: Host is created """ compute_resource = entities.LibvirtComputeResource( url='qemu+ssh://root@{0}/system'.format( settings.compute_resources.libvirt_hostname ) ).create() host = entities.Host() host.create_missing() result = Host.create({ u'architecture-id': host.architecture.id, u'compute-resource-id': compute_resource.id, u'domain-id': host.domain.id, u'environment-id': host.environment.id, u'interface': 'type=network', u'location-id': host.location.id, # pylint:disable=no-member u'medium-id': host.medium.id, u'name': host.name, u'operatingsystem-id': host.operatingsystem.id, # pylint:disable=no-member u'organization-id': host.organization.id, u'partition-table-id': host.ptable.id, u'puppet-proxy-id': self.puppet_proxy['id'], u'root-pass': host.root_pass, }) self.assertEqual(result['name'], host.name + '.' + host.domain.name) Host.delete({'id': result['id']})
def _capsule_cleanup(self): """make the necessary cleanup in case of a crash""" if self._subscribed: # use try except to unregister the host, in case of host not # reachable (or any other failure), the capsule is not deleted and # this failure will hide any prior failure. try: self.unregister() except Exception as exp: logger.error('Failed to unregister the host: {0}\n{1}'.format( self.hostname, exp.message)) if self._capsule_hostname: # do cleanup as using a static hostname that can be reused by # other tests and organizations try: # try to delete the hostname first Host.delete({'name': self._capsule_hostname}) # try delete the capsule # note: if the host was not registered the capsule does not # exist yet Capsule.delete({'name': self._capsule_hostname}) except Exception as exp: # do nothing, only log the exception # as maybe that the host was not registered or setup does not # reach that stage # or maybe that the capsule was not registered or setup does # not reach that stage logger.error('Failed to cleanup the host: {0}\n{1}'.format( self.hostname, exp.message))
def test_positive_delete_by_name(self): """Create a host and then delete it by name. @id: 93f7504d-9a63-491f-8fdb-ed8017aefab9 @Assert: Host is deleted """ Host.delete({'name': self.host['name']}) with self.assertRaises(CLIReturnCodeError): Host.info({'name': self.host['name']})
def test_positive_delete_by_id(self): """Create a host and then delete it by id. @id: e687a685-ab8b-4c5f-97f9-e14d3ab52f29 @Assert: Host is deleted """ Host.delete({'id': self.host['id']}) with self.assertRaises(CLIReturnCodeError): Host.info({'id': self.host['id']})
def test_positive_delete_by_name(self): """Create a host and then delete it by name. @Feature: Hosts @Assert: Host is deleted """ Host.delete({'name': self.host['name']}) with self.assertRaises(CLIReturnCodeError): Host.info({'name': self.host['name']})
def test_positive_delete_by_id(self): """@Test: Create a host and then delete it by id. @Feature: Hosts @Assert: Host is deleted """ Host.delete({'id': self.host['id']}) with self.assertRaises(CLIReturnCodeError): Host.info({'id': self.host['id']})
def deploy_validation(hypervisor_type): """Checkout the deploy result :param str hypervisor_type: esx, libvirt, rhevm, xen, libvirt, kubevirt, ahv :raises: VirtWhoError: If failed to start virt-who servcie. :ruturn: hypervisor_name and guest_name """ status = get_virtwho_status() if status != 'running': raise VirtWhoError("Failed to start virt-who service") hypervisor_name, guest_name = _get_hypervisor_mapping(hypervisor_type) for host in Host.list({'search': hypervisor_name}): Host.delete({'id': host['id']}) restart_virtwho_service() return hypervisor_name, guest_name
def deploy_validation(): """Checkout the deploy result :raises: VirtWhoError: If failed to start virt-who servcie. :ruturn: hypervisor_name and guest_name """ status = get_virtwho_status() if status != 'running': raise VirtWhoError("Failed to start virt-who service") _, logs = runcmd('cat /var/log/rhsm/rhsm.log') hypervisor_name, guest_name = _get_hypervisor_mapping(logs) for host in Host.list({'search': hypervisor_name}): Host.delete({'id': host['id']}) restart_virtwho_service() return hypervisor_name, guest_name
def _capsule_cleanup(self): """make the necessary cleanup in case of a crash""" if self._subscribed: # use try except to unregister the host, in case of host not # reachable (or any other failure), the capsule is not deleted and # this failure will hide any prior failure. try: self.unregister() except Exception as exp: logger.error('Failed to unregister the host: {0}\n{1}'.format( self.hostname, exp)) if self._capsule_hostname: # do cleanup as using a static hostname that can be reused by # other tests and organizations try: # try to delete the hostname first Host.delete({'name': self._capsule_hostname}) # try delete the capsule except Exception as exp: # log the exception # as maybe that the host was not registered or setup does not # reach that stage # or maybe that the capsule was not registered or setup does # not reach that stage # Destroys the Capsule VM on the provisioning server if # exception has 'return_code=70(Error: host not found)' if exp.return_code == 70: super(CapsuleVirtualMachine, self).destroy() if is_open('BZ:1622064'): logger.warn('Failed to cleanup the host: {0}\n{1}'.format( self.hostname, exp)) else: logger.error('Failed to cleanup the host: {0}\n{1}'.format( self.hostname, exp)) raise try: # try to delete the capsule if it was added already Capsule.delete({'name': self._capsule_hostname}) except Exception as exp: logger.error('Failed to cleanup the capsule: {0}\n{1}'.format( self.hostname, exp)) raise
def class_byos_ft_host( self, azurermclient, module_azurerm_byos_finishimg, module_azurerm_cr, default_architecture, module_domain, module_location, module_org, default_os, default_smart_proxy, module_puppet_environment, ): """ Provisions the host on AzureRM with BYOS Image Later in tests this host will be used to perform assertions """ set_hammer_api_timeout() skip_yum_update_during_provisioning( template='Kickstart default finish') host = Host.create( { 'name': self.hostname, 'compute-resource': module_azurerm_cr.name, 'compute-attributes': self.compute_attrs, 'interface': self.interfaces_attributes, 'location-id': module_location.id, 'organization-id': module_org.id, 'domain-id': module_domain.id, 'architecture-id': default_architecture.id, 'operatingsystem-id': default_os.id, 'root-password': gen_string('alpha'), 'image': module_azurerm_byos_finishimg.name, 'volume': "disk_size_gb=5", }, timeout=1800, ) yield host skip_yum_update_during_provisioning( template='Kickstart default finish', reverse=True) Host.delete({'name': self.fullhostname}, timeout=1800) set_hammer_api_timeout(reverse=True)
def class_byos_ft_host( self, azurermclient, session_puppet_enabled_sat, module_azurerm_byos_finishimg_puppet, module_azurerm_cr_puppet, session_puppet_default_architecture, module_puppet_domain, module_puppet_loc, module_puppet_org, session_puppet_default_os, ): """ Provisions the host on AzureRM with BYOS Image Later in tests this host will be used to perform assertions """ with session_puppet_enabled_sat.hammer_api_timeout(): with session_puppet_enabled_sat.skip_yum_update_during_provisioning( template='Kickstart default finish' ): host = session_puppet_enabled_sat.cli.Host.create( { 'name': self.hostname, 'compute-resource': module_azurerm_cr_puppet.name, 'compute-attributes': self.compute_attrs, 'interface': self.interfaces_attributes, 'location-id': module_puppet_loc.id, 'organization-id': module_puppet_org.id, 'domain-id': module_puppet_domain.id, 'architecture-id': session_puppet_default_architecture.id, 'operatingsystem-id': session_puppet_default_os.id, 'root-password': gen_string('alpha'), 'image': module_azurerm_byos_finishimg_puppet.name, 'volume': "disk_size_gb=5", }, timeout=1800000, ) yield host with satellite_setting('destroy_vm_on_host_delete=True'): Host.delete({'name': self.fullhostname}, timeout=1800000)
def class_host_ft( self, default_sat, azurermclient, module_azurerm_finishimg, module_azurerm_cr, default_architecture, module_domain, module_location, module_org, default_os, default_smart_proxy, module_puppet_environment, ): """ Provisions the host on AzureRM using Finish template Later in tests this host will be used to perform assertions """ with default_sat.hammer_api_timeout(): with default_sat.skip_yum_update_during_provisioning( template='Kickstart default finish'): host = Host.create( { 'name': self.hostname, 'compute-resource': module_azurerm_cr.name, 'compute-attributes': self.compute_attrs, 'interface': self.interfaces_attributes, 'location-id': module_location.id, 'organization-id': module_org.id, 'domain-id': module_domain.id, 'architecture-id': default_architecture.id, 'operatingsystem-id': default_os.id, 'root-password': gen_string('alpha'), 'image': module_azurerm_finishimg.name, }, timeout=1800000, ) yield host with satellite_setting('destroy_vm_on_host_delete=True'): Host.delete({'name': self.fullhostname}, timeout=1800)
def class_host_ud( self, azurermclient, module_azurerm_cloudimg, module_azurerm_cr, default_architecture, module_domain, module_location, module_org, default_os, default_smart_proxy, module_puppet_environment, azurerm_hostgroup, ): """ Provisions the host on AzureRM using UserData template Later in tests this host will be used to perform assertions """ set_hammer_api_timeout() skip_yum_update_during_provisioning( template='Kickstart default user data') host = Host.create( { 'name': self.hostname, 'compute-attributes': self.compute_attrs, 'interface': self.interfaces_attributes, 'image': module_azurerm_cloudimg.name, 'hostgroup': azurerm_hostgroup.name, 'location': module_location.name, 'organization': module_org.name, 'operatingsystem-id': default_os.id, }, timeout=1800, ) yield host skip_yum_update_during_provisioning( template='Kickstart default user data', reverse=True) Host.delete({'name': self.fullhostname}, timeout=1800) set_hammer_api_timeout(reverse=True)
def deploy_configure_by_command(command, hypervisor_type, debug=False, org='Default_Organization'): """Deploy and run virt-who servcie by the hammer command. :param str command: get the command by UI/CLI/API, it should be like: `hammer virt-who-config deploy --id 1 --organization-id 1` :param str hypervisor_type: esx, libvirt, rhevm, xen, libvirt, kubevirt, ahv :param bool debug: if VIRTWHO_DEBUG=1, this option should be True. :param str org: Organization Label """ virtwho_cleanup() guest_name, guest_uuid = get_guest_info(hypervisor_type) if Host.list({'search': guest_name}): Host.delete({'name': guest_name}) register_system(get_system(hypervisor_type), org=org) ret, stdout = runcmd(command) if ret != 0 or 'Finished successfully' not in stdout: raise VirtWhoError(f"Failed to deploy configure by {command}") if debug: return deploy_validation(hypervisor_type)
def tearDown(self, provisioning): """Delete the hosts to free the resources""" hosts = Host.list({'organization': provisioning.org_name}) for host in hosts: Host.delete({'id': host['id']})
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()
def tearDown(self): """Delete the host to free the resources""" super(ComputeResourceHostTestCase, self).tearDown() hosts = Host.list({'organization': self.org_name}) for host in hosts: Host.delete({'id': host['id']})
def tearDown(self): """Delete the host to free the resources""" super().tearDown() hosts = Host.list({'organization': self.org_name}) for host in hosts: Host.delete({'id': host['id']})