Esempio n. 1
0
def foreman_discovery(self):
    """Steps to Configure foreman discovery

    1. Build PXE default template
    2. Create Organization/Location
    3. Update Global parameters to set default org and location for
        discovered hosts.
    4. Enable auto_provision flag to perform discovery via discovery
        rules.
    """
    # Build PXE default template to get default PXE file
    Template.build_pxe_default()
    # let's just modify the timeouts to speed things up
    ssh.command("sed -ie 's/TIMEOUT [[:digit:]]\\+/TIMEOUT 1/g' "
                "/var/lib/tftpboot/pxelinux.cfg/default")
    ssh.command("sed -ie '/APPEND initrd/s/$/ fdi.countdown=1/' "
                "/var/lib/tftpboot/pxelinux.cfg/default")

    # Create Org and location
    org = make_org()
    loc = make_location()

    # Get default settings values
    default_discovery_loc = Settings.list(
        {'search': 'name=discovery_location'})[0]
    default_discovery_org = Settings.list(
        {'search': 'name=discovery_organization'})[0]
    default_discovery_auto = Settings.list({'search':
                                            'name=discovery_auto'})[0]

    # Update default org and location params to place discovered host
    Settings.set({'name': 'discovery_location', 'value': loc['name']})
    Settings.set({'name': 'discovery_organization', 'value': org['name']})

    # Enable flag to auto provision discovered hosts via discovery rules
    Settings.set({'name': 'discovery_auto', 'value': 'true'})

    # Flag which shows whether environment is fully configured for
    # discovered host provisioning.
    configured_env = configure_env_for_provision(org=org, loc=loc)
    yield {
        'default_discovery_auto': default_discovery_auto,
        'default_discovery_loc': default_discovery_loc,
        'default_discovery_org': default_discovery_org,
        'configured_env': configured_env,
    }
    # Restore default global setting's values
    Settings.set({
        'name': 'discovery_location',
        'value': default_discovery_loc['value']
    })
    Settings.set({
        'name': 'discovery_organization',
        'value': default_discovery_org['value']
    })
    Settings.set({
        'name': 'discovery_auto',
        'value': default_discovery_auto['value']
    })
Esempio n. 2
0
    def test_positive_provision_pxe_host_non_admin(self):
        """Provision a pxe-based discovered hosts by non-admin user

        :id: 02144040-6cf6-4251-abaf-b0fad2c83109

        :Setup: Provisioning should be configured and a host should be
            discovered

        :Steps: PUT /api/v2/discovered_hosts/:id

        :expectedresults: Host should be provisioned successfully by non admin user

        :CaseImportance: Critical

        :bz: 1638403
        """
        non_admin = create_org_admin_user(orgs=[self.org.id],
                                          locs=[self.loc.id])
        nonadmin_config = get_nailgun_config(non_admin)
        if not self.configured_env:
            self.__class__.configured_env = configure_env_for_provision(
                org={
                    'id': self.org.id,
                    'name': self.org.name
                },
                loc={
                    'id': self.loc.id,
                    'name': self.loc.name
                },
            )
        with LibvirtGuest() as pxe_host:
            hostname = pxe_host.guest_name
            discovered_host = self._assertdiscoveredhost(
                hostname, nonadmin_config)
            # Provision just discovered host
            discovered_host.hostgroup = entities.HostGroup(
                nonadmin_config,
                id=self.configured_env['hostgroup']['id']).read()
            discovered_host.root_pass = gen_string('alphanumeric')
            discovered_host.update(['hostgroup', 'root_pass'])
            # Assertions
            provisioned_host = entities.Host(nonadmin_config).search(
                query={
                    'search':
                    'name={}.{}'.format(discovered_host.name,
                                        self.configured_env['domain']['name'])
                })[0]
            assert provisioned_host.subnet.read(
            ).name == self.configured_env['subnet']['name']
            assert (provisioned_host.operatingsystem.read().ptable[0].read().
                    name == self.configured_env['ptable']['name'])
            assert (provisioned_host.operatingsystem.read().title ==
                    self.configured_env['os']['title'])
            assert not entities.DiscoveredHost(nonadmin_config).search(
                query={'search': f'name={discovered_host.name}'})
    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 = [f'{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']})
Esempio n. 4
0
def provisioning_env(module_org, module_location):
    env = configure_env_for_provision(
        org={
            'id': module_org.id,
            'name': module_org.name
        },
        loc={
            'id': module_location.id,
            'name': module_location.name
        },
    )
    yield env
Esempio n. 5
0
    def test_positive_provision_pxe_host(self):
        """Provision a pxe-based discovered hosts

        :id: e805b9c5-e8f6-4129-a0e6-ab54e5671ddb

        :Setup: Provisioning should be configured and a host should be
            discovered

        :Steps: PUT /api/v2/discovered_hosts/:id

        :expectedresults: Host should be provisioned successfully

        :CaseImportance: Critical
        """
        if not self.configured_env:
            self.__class__.configured_env = configure_env_for_provision(
                org={
                    'id': self.org.id,
                    'name': self.org.name
                },
                loc={
                    'id': self.loc.id,
                    'name': self.loc.name
                },
            )
        with LibvirtGuest() as pxe_host:
            hostname = pxe_host.guest_name
            discovered_host = self._assertdiscoveredhost(hostname)
            # Provision just discovered host
            discovered_host.hostgroup = entities.HostGroup(
                id=self.configured_env['hostgroup']['id']).read()
            discovered_host.root_pass = gen_string('alphanumeric')
            discovered_host.update(['hostgroup', 'root_pass'])
            # Assertions
            provisioned_host = entities.Host().search(
                query={
                    'search':
                    'name={}.{}'.format(discovered_host.name,
                                        self.configured_env['domain']['name'])
                })[0]
            assert provisioned_host.subnet.read(
            ).name == self.configured_env['subnet']['name']
            assert (provisioned_host.operatingsystem.read().ptable[0].read().
                    name == self.configured_env['ptable']['name'])
            assert (provisioned_host.operatingsystem.read().title ==
                    self.configured_env['os']['title'])
            assert not entities.DiscoveredHost().search(
                query={'search': f'name={discovered_host.name}'})
    def test_positive_provision_pxe_host(self):
        """Provision the pxe based discovered host from cli

        @id: b5385fe3-d532-4373-af64-5492275ff8d4

        @Setup: Host should already be discovered

        @Assert: Host should be provisioned successfully and entry from
        discovered host list should be automatically removed.

        @CaseLevel: System
        """
        if not self.configured_env:
            self.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)
            # Provision just discovered host
            DiscoveredHost.provision({
                'name': discovered_host['name'],
                'hostgroup': self.configured_env['hostgroup']['name'],
                'root-password': gen_string('alphanumeric'),
            })
            provisioned_host = Host.info({
                'name': '{0}.{1}'.format(
                    discovered_host['name'],
                    self.configured_env['domain']['name']
                )
            })
            self.assertEqual(
                provisioned_host['network']['subnet'],
                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']})
Esempio n. 7
0
    def test_positive_provision_pxeless_host(self):
        """Provision the pxe-less discovered host from cli

        :id: ae7f3ce2-e66e-44dc-85cb-0c3c4782cbb1

        :Setup: Host should already be discovered

        :expectedresults: Host should be provisioned successfully and entry
            from discovered host list should be auto removed

        :CaseLevel: System
        """
        if not self.configured_env:
            self.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
            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'),
            })
            provisioned_host = Host.info({
                'name': '{0}.{1}'.format(
                    discovered_host['name'],
                    self.configured_env['domain']['name']
                )
            })
            self.assertEqual(
                provisioned_host['network']['subnet'],
                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']})
Esempio n. 8
0
    def test_positive_provision_pxe_host(self):
        """Provision the pxe based discovered host from cli

        :id: b5385fe3-d532-4373-af64-5492275ff8d4

        :Setup: Host should already be discovered

        :expectedresults: Host should be provisioned successfully and entry
            from discovered host list should be automatically removed.

        :CaseLevel: System
        """
        if not self.configured_env:
            self.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)
            # Provision just discovered host
            DiscoveredHost.provision({
                'name':
                discovered_host['name'],
                'hostgroup':
                self.configured_env['hostgroup']['name'],
                'root-password':
                gen_string('alphanumeric'),
            })
            provisioned_host = Host.info({
                'name':
                '{0}.{1}'.format(discovered_host['name'],
                                 self.configured_env['domain']['name'])
            })
            self.assertEqual(provisioned_host['network']['subnet'],
                             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_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']})
Esempio n. 10
0
    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']})
Esempio n. 11
0
    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']})
Esempio n. 12
0
    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']})