def test_positive_pxe_less_multi_nic_with_dhcp_unattended(self): """Discover a host with multiple NIC on a network with dhcp using ISO image in unattended mode. :id: cdfebc3d-d8c1-4f82-a384-cc5cd9926c65 :expectedresults: Host should be discovered successfully :CaseLevel: System """ with Session(self) as session: session.nav.go_to_select_org(self.org_name) # To show new fact column 'Interfaces' on Discovered Hosts page self._edit_discovery_fact_column_param(session, "interfaces") with LibvirtGuest(boot_iso=True, extra_nic=True) as pxe_less_host: hostname = pxe_less_host.guest_name self.assertTrue( self.discoveredhosts.waitfordiscoveredhost(hostname) ) self.assertIsNotNone(self.discoveredhosts.search(hostname)) element = locators['discoveredhosts.fetch_interfaces'] host_interfaces = self.discoveredhosts.fetch_fact_value( hostname, element) self.assertEqual(u'eth0,eth1,lo', host_interfaces)
def test_custom_facts_discovery(self): """Check if defined custom facts are displayed under host's facts @Feature: Foreman Discovery - PXELess @Setup: Provisioning should be configured @Steps: Validate specified custom facts @Assert: All defined custom facts should be displayed correctly """ param_value = 'myfact' with Session(self.browser) as session: session.nav.go_to_select_org(self.org_name) # To show new fact column 'Interfaces' on Discovered Hosts page self._edit_discovery_fact_column_param(session, param_value) with LibvirtGuest(boot_iso=True) as pxe_less_host: hostname = pxe_less_host.guest_name self._assertdiscoveredhost(hostname) element = locators['discoveredhosts.fetch_custom_fact'] custom_fact = self.discoveredhosts.fetch_fact_value( hostname, element) self.assertEqual(u'somevalue', custom_fact)
def test_positive_provision_pxe_host_with_bios_syslinux(self): """Provision the pxe-based BIOS discovered host from cli using SYSLINUX loader :id: b5385fe3-d532-4373-af64-5492275ff8d4 :Setup: 1. Create a BIOS VM and set it to boot from a network 2. for getting more detailed info from FDI, remaster the image to have ssh enabled :steps: 1. Build a default PXE template 2. Run assertion step #1 3. Boot the VM (from NW) 4. Run assertion steps #2-4 5. Provision the discovered host 6. Run assertion steps #5-9 :expectedresults: Host should be provisioned successfully 1. [TBD] Ensure the tftpboot files are updated 1.1 Ensure fdi-image files have been placed under tftpboot/boot/ 1.2 Ensure the 'default' pxelinux config has been placed under tftpboot/pxelinux.cfg/ 1.3 Ensure the discovery section exists inside pxelinux config, it leads to the FDI kernel and the ONTIMEOUT is set to discovery 2. [TBD] Ensure PXE handoff goes as expected (tcpdump -p tftp) 3. [TBD] Ensure FDI loaded and successfully sent out facts 3.1 ping vm 3.2 ssh to the VM and read the logs (if ssh enabled) 3.3 optionally sniff the HTTP traffic coming from the host 4. Ensure host appeared in Discovered Hosts on satellite 5. [TBD] Ensure the tftpboot files are updated for the hosts mac 6. [TBD] Ensure PXE handoff goes as expected (tcpdump -p tftp) 7. [TBD] Optionally ensure anaconda loaded and the installation finished 8. [TBD] Ensure the host is provisioned with correct attributes 9. Ensure the entry from discovered host list disappeared :CaseLevel: System """ # fixme: assertion #1 if not self.configured_env: self.__class__.configured_env = configure_env_for_provision( org=self.org, loc=self.loc) with LibvirtGuest() as pxe_host: hostname = pxe_host.guest_name # fixme: assertion #2-3 # assertion #4 discovered_host = self._assertdiscoveredhost(hostname) self.assertIsNotNone(discovered_host) # Provision just discovered host DiscoveredHost.provision({ 'name': discovered_host['name'], 'hostgroup': self.configured_env['hostgroup']['name'], 'root-password': gen_string('alphanumeric'), }) # fixme: assertion #5-8 provisioned_host = Host.info({ 'name': '{0}.{1}'.format(discovered_host['name'], self.configured_env['domain']['name']) }) # assertion #8 self.assertEqual(provisioned_host['network']['subnet-ipv4'], self.configured_env['subnet']['name']) self.assertEqual( provisioned_host['operating-system']['partition-table'], self.configured_env['ptable']['name']) self.assertEqual( provisioned_host['operating-system']['operating-system'], self.configured_env['os']['title']) # assertion #9 with self.assertRaises(CLIReturnCodeError): DiscoveredHost.info({'id': discovered_host['id']})
def test_positive_provision_pxeless_bios_syslinux(self): """Provision and discover the pxe-less BIOS host from cli using SYSLINUX loader :id: ae7f3ce2-e66e-44dc-85cb-0c3c4782cbb1 :Setup: 1. Craft the FDI with remaster the image to have ssh enabled :Steps: 1. Create a BIOS VM and set it to boot from the FDI 2. Run assertion steps #1-2 3. Provision the discovered host using PXELinux loader 4. Run assertion steps #3-7 :expectedresults: Host should be provisioned successfully 1. [TBD] Ensure FDI loaded and successfully sent out facts 1.1 ping vm 1.2 ssh to the VM and read the logs (if ssh enabled) 1.3 optionally sniff the HTTP traffic coming from the host 2. Ensure host appeared in Discovered Hosts on satellite 3. [TBD] Ensure the kexec was successful (e.g. the kexec request result in production.log) 4. [TBD] Ensure anaconda loaded and the installation finished 5. [TBD] Ensure the host is provisioned with correct attributes 6. Ensure the host is created in Hosts 7. Ensure the entry from discovered host list disappeared :CaseLevel: System """ if not self.configured_env: self.__class__.configured_env = configure_env_for_provision( org=self.org, loc=self.loc) with LibvirtGuest(boot_iso=True) as pxe_host: hostname = pxe_host.guest_name # fixme: assertion #1 discovered_host = self._assertdiscoveredhost(hostname) self.assertIsNotNone(discovered_host) # Provision just discovered host DiscoveredHost.provision({ 'name': discovered_host['name'], 'hostgroup': self.configured_env['hostgroup']['name'], 'root-password': gen_string('alphanumeric'), }) # fixme: assertion #2-5 provisioned_host = Host.info({ 'name': '{0}.{1}'.format(discovered_host['name'], self.configured_env['domain']['name']) }) self.assertEqual(provisioned_host['network']['subnet-ipv4'], self.configured_env['subnet']['name']) self.assertEqual( provisioned_host['operating-system']['partition-table'], self.configured_env['ptable']['name']) self.assertEqual( provisioned_host['operating-system']['operating-system'], self.configured_env['os']['title']) # Check that provisioned host is not in the list of discovered # hosts anymore with self.assertRaises(CLIReturnCodeError): DiscoveredHost.info({'id': discovered_host['id']})
def test_positive_auto_provision_pxe_host(_module_user, module_org, module_location, discovery_settings, provisioning_env): """Auto provision a pxe-based host by executing discovery rules :id: c93fd7c9-41ef-4eb5-8042-f72e87e67e10 :parametrized: yes :Setup: Provisioning should be configured and a host should be discovered :Steps: POST /api/v2/discovered_hosts/:id/auto_provision :expectedresults: Selected Host should be auto-provisioned successfully :CaseAutomation: Automated :CaseImportance: Critical """ cfg = get_nailgun_config() if _module_user: cfg.auth = (_module_user[0].login, _module_user[1]) # open a ssh channel and attach it to foreman-tail output ssh_client = ssh.get_client() with ssh_client.invoke_shell() as channel: channel.send('foreman-tail\r') with LibvirtGuest() as pxe_host: discovered_host = _assert_discovered_host(pxe_host, channel, user_config=cfg) # Provision just discovered host discovered_host.hostgroup = entities.HostGroup( cfg, id=provisioning_env['hostgroup']['id']).read() # create a discovery rule that will match hosts MAC address entities.DiscoveryRule( name=gen_string('alphanumeric'), search_=f"mac = {discovered_host.mac}", organization=[module_org], location=[module_location], hostgroup=entities.HostGroup( cfg, id=provisioning_env['hostgroup']['id']).read(), ).create() # Auto-provision the host discovered_host.auto_provision() # Assertions provisioned_host = entities.Host(cfg).search( query={ 'search': 'name={}.{}'.format(discovered_host.name, provisioning_env['domain']['name']) })[0] assert provisioned_host.subnet.read( ).name == provisioning_env['subnet']['name'] assert (provisioned_host.operatingsystem.read().ptable[0].read(). name == provisioning_env['ptable']['name']) assert provisioned_host.operatingsystem.read( ).title == provisioning_env['os']['title'] assert not entities.DiscoveredHost(cfg).search( query={'search': f'name={discovered_host.name}'})
def test_positive_provision_pxe_host_dhcp_change(self, discovery_settings, provisioning_env, target_sat): """Discovered host is provisioned in dhcp range defined in subnet entity :id: 7ab654de-16dd-4a8b-946d-f6adde310340 :bz: 1367549 :customerscenario: true :Setup: Provisioning should be configured and a host should be discovered :Steps: 1. Set some dhcp range in dhcpd.conf in satellite. 2. Create subnet entity in satellite with a range different from whats defined in `dhcpd.conf`. 3. Create Hostgroup with the step 2 subnet. 4. Discover a new host in satellite. 5. Provision a host with the hostgroup created in step 3. :expectedresults: 1. The discovered host should be discovered with range defined in dhcpd.conf 2. But provisoning the discovered host should acquire an IP from dhcp range defined in subnet entity. :CaseImportance: Critical """ subnet = target_sat.api.Subnet( id=provisioning_env['subnet']['id']).read() # Updating satellite subnet component and dhcp conf ranges # Storing now for restoring later old_sub_from = subnet.from_ old_sub_to = subnet.to old_sub_to_4o = old_sub_to.split('.')[-1] # Calculating Subnet's new `from` range in Satellite Subnet Component new_subnet_from = subnet.from_[:subnet.from_.rfind('.') + 1] + str(int(old_sub_to_4o) - 9) # Same time, calculating dhcp confs new `to` range new_dhcp_conf_to = subnet.to[:subnet.to.rfind('.') + 1] + str(int(old_sub_to_4o) - 10) cfg = get_nailgun_config() with target_sat.session.shell() as shell: shell.send('foreman-tail') try: # updating the ranges in component and in dhcp.conf subnet.from_ = new_subnet_from subnet.update(['from_']) target_sat.execute( f'cp /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd_backup.conf && ' f'sed -ie \'s/{subnet.to}/{new_dhcp_conf_to}/\' /etc/dhcp/dhcpd.conf && ' f'systemctl restart dhcpd') with LibvirtGuest() as pxe_host: discovered_host = _assert_discovered_host( pxe_host, shell, cfg) # Assert Discovered host discovered within dhcp.conf range before provisioning assert int(discovered_host.ip.split('.')[-1]) <= int( new_dhcp_conf_to.split('.')[-1]) # Provision just discovered host discovered_host.hostgroup = target_sat.api.HostGroup( id=provisioning_env['hostgroup']['id']).read() discovered_host.root_pass = gen_string('alphanumeric') discovered_host.update(['hostgroup', 'root_pass']) # Assertions provisioned_host = target_sat.api.Host().search( query={ 'search': 'name={}.{}'.format( discovered_host.name, provisioning_env['domain']['name']) })[0] assert int(provisioned_host.ip.split('.')[-1]) >= int( new_subnet_from.split('.')[-1]) assert int(provisioned_host.ip.split('.')[-1]) <= int( old_sub_to_4o) assert not target_sat.api.DiscoveredHost().search( query={'search': f'name={discovered_host.name}'}) finally: subnet.from_ = old_sub_from subnet.update(['from_']) target_sat.execute( 'mv /etc/dhcp/dhcpd_backup.conf /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf' )
def test_positive_reboot_all_pxe_hosts( self, _module_user, discovered_host_cleanup, discovery_settings, provisioning_env, target_sat, ): """Rebooting all pxe-based discovered hosts :id: 69c807f8-5646-4aa6-8b3c-5ecdb69560ed :parametrized: yes :Setup: Provisioning should be configured and a hosts should be discovered via PXE boot. :Steps: PUT /api/v2/discovered_hosts/reboot_all :expectedresults: All disdcovered host should be rebooted successfully :CaseAutomation: Automated :CaseImportance: Medium """ cfg = get_nailgun_config() if _module_user: cfg.auth = (_module_user[0].login, _module_user[1]) # open ssh channels and attach them to foreman-tail output shell_1, shell_2 = target_sat.session.shell( ), target_sat.session.shell() shell_1.send('foreman-tail') shell_2.send('foreman-tail') with LibvirtGuest() as pxe_host_1: _assert_discovered_host(pxe_host_1, shell_1, user_config=cfg) with LibvirtGuest() as pxe_host_2: _assert_discovered_host(pxe_host_2, shell_2, user_config=cfg) # reboot_all method leads to general /discovered_hosts/ path, so it doesn't matter # what DiscoveredHost object we execute this on try: entities.DiscoveredHost().reboot_all() except simplejson.errors.JSONDecodeError as e: if is_open('BZ:1893349'): pass else: raise e # assert that server receives DHCP discover from hosts PXELinux # this means that the hosts got rebooted for pxe_host in [(pxe_host_1, shell_1), (pxe_host_2, shell_2)]: for pattern in [ ( f"DHCPDISCOVER from {pxe_host[0].mac}", "DHCPDISCOVER", ), (f"DHCPACK on [0-9.]+ to {pxe_host[0].mac}", "DHCPACK"), ]: try: _wait_for_log(pxe_host[1], pattern[0], timeout=30) except TimedOutError: # raise assertion error raise AssertionError( f'Timed out waiting for {pattern[1]} from ' f'{pxe_host[0].mac}')
def test_positive_provision_pxe_host_with_parameters(self): """Provision the pxe-based BIOS discovered host with host parameters from cli using SYSLINUX loader :id: 4b315fe1-2eba-4e59-bd0a-9d16ce319ce2 :Setup: 1. Create a BIOS VM and set it to boot from a network :steps: 1. Build a default PXE template 2. Configure HostGroup to be used for provisioning the discovered host after discovery 3. PXE Boot the VM (from Network) 4. Wait for Host to be discovered by Satellite 5. Provision the discovered host with host parameters :expectedresults: 1. Ensure host appeared in Discovered Hosts on satellite 2. Ensure the host is provisioned with correct and all the host parameters given during provisioning 3. Ensure the discovered host is no more available to provision :CaseImportance: High :BZ: 1572947 """ param1_key, param1_value = gen_string('alpha'), gen_string( 'alphanumeric') param2_key, param2_value = gen_string('alpha'), gen_string( 'alphanumeric') host_params = [ '{}={}, {}={}'.format(param1_key, param1_value, param2_key, param2_value) ] if not self.configured_env: self.__class__.configured_env = configure_env_for_provision( org=self.org, loc=self.loc) with LibvirtGuest() as pxe_host: hostname = pxe_host.guest_name discovered_host = self._assertdiscoveredhost(hostname) self.assertIsNotNone(discovered_host) DiscoveredHost.provision({ 'name': discovered_host['name'], 'hostgroup': self.configured_env['hostgroup']['name'], 'root-password': gen_string('alphanumeric'), 'parameters': host_params, }) provisioned_host = Host.info({ 'name': '{}.{}'.format(discovered_host['name'], self.configured_env['domain']['name']) }) self.assertEqual( provisioned_host['parameters'][str(param1_key).lower()], param1_value) self.assertEqual( provisioned_host['parameters'][str(param2_key).lower()], param2_value) with self.assertRaises(CLIReturnCodeError): DiscoveredHost.info({'id': discovered_host['id']})