示例#1
0
    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))
示例#2
0
    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))
示例#3
0
    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
示例#4
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()
            # refresh subscription
            capsule_vm.run('subscription-manager refresh')
            # 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.hostname)
            # 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._capsule_hostname})
    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})