Exemplo n.º 1
0
    def test_positive_reinstall_on_same_node_after_remove(self):
        """Reinstall capsule on the same node after remove

        :id: fac35a44-0bc9-44e9-a2c3-398e1aa9900c

        :customerscenario: true

        :expectedresults: The capsule successfully reinstalled

        :BZ: 1327442

        :CaseLevel: System

        """
        # Note: capsule-remove has been replaced by katello-remove
        with CapsuleVirtualMachine() as capsule_vm:
            # ensure that capsule refresh-features succeed
            with self.assertNotRaises(CLIReturnCodeError):
                Capsule.refresh_features(
                    {'name': capsule_vm._capsule_hostname})
            # katello-remove command request to confirm by typing Y and then by
            # typing remove
            result = capsule_vm.run("printf 'Y\nremove\n' | katello-remove")
            self.assertEqual(result.return_code, 0)
            # ensure that capsule refresh-features fail
            with self.assertRaises(CLIReturnCodeError):
                Capsule.refresh_features(
                    {'name': capsule_vm._capsule_hostname})
            # reinstall katello certs as they have been removed
            capsule_vm.install_katello_ca()
            # install satellite-capsule package
            result = capsule_vm.run('yum install -y satellite-capsule')
            self.assertEqual(result.return_code, 0)
            # generate capsule certs and installer command
            cert_file_path = '/tmp/{0}-certs.tar'.format(capsule_vm.hostname)
            result = ssh.command('capsule-certs-generate '
                                 '--foreman-proxy-fqdn {0} '
                                 '--certs-tar {1}'.format(
                                     capsule_vm.hostname, cert_file_path))
            self.assertEqual(result.return_code, 0)
            # retrieve the installer command from the result output
            installer_cmd = extract_capsule_satellite_installer_command(
                result.stdout)
            # copy the generated certs to capsule vm
            _, temporary_local_cert_file_path = mkstemp(suffix='-certs.tar')
            ssh.download_file(remote_file=cert_file_path,
                              local_file=temporary_local_cert_file_path,
                              hostname=settings.server.hostname)
            ssh.upload_file(local_file=temporary_local_cert_file_path,
                            remote_file=cert_file_path,
                            hostname=capsule_vm.ip_addr)
            # delete the temporary file
            os.remove(temporary_local_cert_file_path)
            result = capsule_vm.run(installer_cmd, timeout=1500)
            self.assertEqual(result.return_code, 0)
            # ensure that capsule refresh-features succeed
            with self.assertNotRaises(CLIReturnCodeError):
                Capsule.refresh_features({'name': capsule_vm.hostname})
Exemplo n.º 2
0
    def _setup_capsule(self):
        """Prepare the virtual machine to host a capsule node"""
        # setup the name resolution
        self._capsule_setup_name_resolution()
        logger.info('adding repofiles required for capsule installation')
        self.create_custom_repos(capsule=settings.capsule_repo,
                                 rhscl=settings.rhscl_repo,
                                 ansible=settings.ansible_repo,
                                 maint=settings.satmaintenance_repo)
        self.configure_rhel_repo(settings.__dict__[self.distro[:-1] + '_repo'])
        self.run('yum repolist')
        self.run('yum -y install satellite-capsule', timeout=1200)
        result = self.run('rpm -q satellite-capsule')
        if result.return_code != 0:
            raise CapsuleVirtualMachineError(
                u'Failed to install satellite-capsule package\n{}'.format(
                    result.stderr))
        cert_file_path = '/root/{0}-certs.tar'.format(self.hostname)
        certs_gen = ssh.command('capsule-certs-generate '
                                '--foreman-proxy-fqdn {0} '
                                '--certs-tar {1}'.format(
                                    self.hostname, cert_file_path))
        if certs_gen.return_code != 0:
            raise CapsuleVirtualMachineError(
                u'Unable to generate certificate\n{}'.format(certs_gen.stderr))
        # copy the certificate to capsule vm
        _, temporary_local_cert_file_path = mkstemp(suffix='-certs.tar')
        logger.info('downloading the certs file: {0}'.format(cert_file_path))
        download_file(remote_file=cert_file_path,
                      local_file=temporary_local_cert_file_path,
                      hostname=settings.server.hostname)
        logger.info('uploading the certs file: {0}'.format(cert_file_path))
        upload_file(key_filename=settings.server.ssh_key,
                    local_file=temporary_local_cert_file_path,
                    remote_file=cert_file_path,
                    hostname=self.ip_addr)
        # delete the temporary file
        os.remove(temporary_local_cert_file_path)

        installer_cmd = extract_capsule_satellite_installer_command(
            certs_gen.stdout)
        result = self.run(installer_cmd, timeout=1800)
        if result.return_code != 0:
            # before exit download the capsule log file
            _, log_path = mkstemp(prefix='capsule_external-', suffix='.log')
            download_file('/var/log/foreman-installer/capsule.log', log_path,
                          self.ip_addr)
            raise CapsuleVirtualMachineError(
                result.return_code, result.stderr,
                u'foreman installer failed at capsule host')

        # manually start pulp_celerybeat service if BZ1446930 is open
        result = self.run('systemctl status pulp_celerybeat.service')
        if 'inactive (dead)' in '\n'.join(result.stdout):
            if is_open('BZ:1446930'):
                result = self.run('systemctl start pulp_celerybeat.service')
                if result.return_code != 0:
                    raise CapsuleVirtualMachineError(
                        'Failed to start pulp_celerybeat service\n{}'.format(
                            result.stderr))
            else:
                raise CapsuleVirtualMachineError(
                    'pulp_celerybeat service not running')
Exemplo n.º 3
0
    def test_positive_reinstall_on_same_node_after_remove(self):
        """Reinstall capsule on the same node after remove

        :id: fac35a44-0bc9-44e9-a2c3-398e1aa9900c

        :customerscenario: true

        :expectedresults: The capsule successfully reinstalled

        :BZ: 1327442

        :CaseLevel: System
        """
        # Note: capsule-remove has been replaced by katello-remove
        with CapsuleVirtualMachine() as capsule_vm:
            # ensure that capsule refresh-features succeed
            with self.assertNotRaises(CLIReturnCodeError):
                Capsule.refresh_features(
                    {'name': capsule_vm._capsule_hostname})
            # katello-remove command request to confirm by typing Y and then by
            # typing remove
            result = capsule_vm.run("printf 'Y\nremove\n' | katello-remove")
            self.assertEqual(result.return_code, 0)
            # ensure that capsule refresh-features fail
            with self.assertRaises(CLIReturnCodeError):
                Capsule.refresh_features(
                    {'name': capsule_vm._capsule_hostname})
            # reinstall katello certs as they have been removed
            capsule_vm.install_katello_ca()
            # install satellite-capsule package
            result = capsule_vm.run('yum install -y satellite-capsule')
            self.assertEqual(result.return_code, 0)
            # generate capsule certs and installer command
            cert_file_path = '/tmp/{0}-certs.tar'.format(capsule_vm.hostname)
            result = ssh.command(
                'capsule-certs-generate '
                '--foreman-proxy-fqdn {0} '
                '--certs-tar {1}'
                .format(capsule_vm.hostname, cert_file_path)
            )
            self.assertEqual(result.return_code, 0)
            # retrieve the installer command from the result output
            installer_cmd = extract_capsule_satellite_installer_command(
                result.stdout
            )
            # copy the generated certs to capsule vm
            _, temporary_local_cert_file_path = mkstemp(suffix='-certs.tar')
            ssh.download_file(
                remote_file=cert_file_path,
                local_file=temporary_local_cert_file_path,
                hostname=settings.server.hostname
            )
            ssh.upload_file(
                local_file=temporary_local_cert_file_path,
                remote_file=cert_file_path,
                hostname=capsule_vm.ip_addr
            )
            # delete the temporary file
            os.remove(temporary_local_cert_file_path)
            result = capsule_vm.run(installer_cmd, timeout=1500)
            self.assertEqual(result.return_code, 0)
            # ensure that capsule refresh-features succeed
            with self.assertNotRaises(CLIReturnCodeError):
                Capsule.refresh_features(
                    {'name': capsule_vm.hostname})
Exemplo n.º 4
0
    def _setup_capsule(self):
        """Prepare the virtual machine to host a capsule node"""
        # setup the name resolution
        self._capsule_setup_name_resolution()
        logger.info('adding repofiles required for capsule installation')
        self.create_custom_repos(
            capsule=settings.capsule_repo,
            rhscl=settings.rhscl_repo,
            ansible=settings.ansible_repo,
            maint=settings.satmaintenance_repo,
        )
        self.configure_rhel_repo(getattr(settings, f"{self.distro}_repo"))
        self.run('yum repolist')
        self.run('yum -y update')
        self.run('yum -y install satellite-capsule', timeout=1200)
        result = self.run('rpm -q satellite-capsule')
        if result.return_code != 0:
            raise CapsuleVirtualMachineError(
                f'Failed to install satellite-capsule package\n{result.stderr}'
            )
        # update http proxy except list
        result = Settings.list({'search': 'http_proxy_except_list'})[0]
        if result["value"] == "[]":
            except_list = f'[{self.hostname}]'
        else:
            except_list = result["value"][:-1] + f', {self.hostname}]'
        Settings.set({'name': 'http_proxy_except_list', 'value': except_list})
        # generate certificate
        cert_file_path = f'/root/{self.hostname}-certs.tar'
        certs_gen = ssh.command('capsule-certs-generate '
                                '--foreman-proxy-fqdn {} '
                                '--certs-tar {}'.format(
                                    self.hostname, cert_file_path))
        if certs_gen.return_code != 0:
            raise CapsuleVirtualMachineError(
                f'Unable to generate certificate\n{certs_gen.stderr}')
        # copy the certificate to capsule vm
        _, temporary_local_cert_file_path = mkstemp(suffix='-certs.tar')
        logger.info(f'downloading the certs file: {cert_file_path}')
        download_file(
            remote_file=cert_file_path,
            local_file=temporary_local_cert_file_path,
            hostname=settings.server.hostname,
        )
        logger.info(f'uploading the certs file: {cert_file_path}')
        upload_file(
            key_filename=settings.server.ssh_key,
            local_file=temporary_local_cert_file_path,
            remote_file=cert_file_path,
            hostname=self.ip_addr,
        )
        # delete the temporary file
        os.remove(temporary_local_cert_file_path)

        installer_cmd = extract_capsule_satellite_installer_command(
            certs_gen.stdout)
        installer_cmd += " --verbose"
        result = self.run(installer_cmd, timeout=1800)
        if result.return_code != 0:
            # before exit download the capsule log file
            _, log_path = mkstemp(prefix='capsule_external-', suffix='.log')
            download_file('/var/log/foreman-installer/capsule.log', log_path,
                          self.ip_addr)
            raise CapsuleVirtualMachineError(
                result.return_code, result.stderr,
                'foreman installer failed at capsule host')

        # manually start pulp_celerybeat service if BZ1446930 is open
        result = self.run('systemctl status pulp_celerybeat.service')
        if 'inactive (dead)' in '\n'.join(result.stdout):
            if is_open('BZ:1446930'):
                result = self.run('systemctl start pulp_celerybeat.service')
                if result.return_code != 0:
                    raise CapsuleVirtualMachineError(
                        f'Failed to start pulp_celerybeat service\n{result.stderr}'
                    )
            else:
                raise CapsuleVirtualMachineError(
                    'pulp_celerybeat service not running')
Exemplo n.º 5
0
    def _setup_capsule(self):
        """Prepare the virtual machine to host a capsule node"""
        # setup the name resolution
        self._capsule_setup_name_resolution()
        logger.info('adding repofiles required for capsule installation')
        self.create_custom_repos(
            capsule=settings.capsule_repo,
            rhscl=settings.rhscl_repo,
            ansible=settings.ansible_repo,
            maint=settings.satmaintenance_repo
        )
        self.configure_rhel_repo(settings.__dict__[self.distro[:-1] + '_repo'])
        self.run('yum repolist')
        self.run('yum -y install satellite-capsule', timeout=900)
        result = self.run('rpm -q satellite-capsule')
        if result.return_code != 0:
            raise CapsuleVirtualMachineError(
                u'Failed to install satellite-capsule package\n{}'.format(
                    result.stderr)
            )
        cert_file_path = '/tmp/{0}-certs.tar'.format(self.hostname)
        certs_gen = ssh.command(
            'capsule-certs-generate '
            '--foreman-proxy-fqdn {0} '
            '--certs-tar {1}'
            .format(self.hostname, cert_file_path)
        )
        if certs_gen.return_code != 0:
            raise CapsuleVirtualMachineError(
                u'Unable to generate certificate\n{}'
                .format(certs_gen.stderr)
            )
        # copy the certificate to capsule vm
        _, temporary_local_cert_file_path = mkstemp(suffix='-certs.tar')
        logger.info(
            'downloading the certs file: {0}'.format(cert_file_path)
        )
        download_file(
            remote_file=cert_file_path,
            local_file=temporary_local_cert_file_path,
            hostname=settings.server.hostname
        )
        logger.info(
            'uploading the certs file: {0}'.format(cert_file_path)
        )
        upload_file(
            key_filename=settings.server.ssh_key,
            local_file=temporary_local_cert_file_path,
            remote_file=cert_file_path,
            hostname=self.ip_addr
        )
        # delete the temporary file
        os.remove(temporary_local_cert_file_path)

        installer_cmd = extract_capsule_satellite_installer_command(
                            certs_gen.stdout
                        )
        if bz_bug_is_open(1458749):
            if '--scenario foreman-proxy-content' in installer_cmd:
                installer_cmd = installer_cmd.replace(
                     '--scenario foreman-proxy-content', '--scenario capsule')
        result = self.run(installer_cmd, timeout=1500)
        if result.return_code != 0:
            # before exit download the capsule log file
            _, log_path = mkstemp(prefix='capsule_external-', suffix='.log')
            download_file(
                '/var/log/foreman-installer/capsule.log',
                log_path,
                self.ip_addr
            )
            raise CapsuleVirtualMachineError(
                result.return_code, result.stderr,
                u'foreman installer failed at capsule host')

        # manually start pulp_celerybeat service if BZ1446930 is open
        result = self.run('systemctl status pulp_celerybeat.service')
        if 'inactive (dead)' in '\n'.join(result.stdout):
            if bz_bug_is_open(1446930):
                result = self.run('systemctl start pulp_celerybeat.service')
                if result.return_code != 0:
                    raise CapsuleVirtualMachineError(
                        'Failed to start pulp_celerybeat service\n{}'.format(
                            result.stderr)
                    )
            else:
                raise CapsuleVirtualMachineError(
                    'pulp_celerybeat service not running')