Exemplo n.º 1
0
 def test_cache(self, request, ssh_result):
     """Check get_host_os_version() calls are cached"""
     ssh_result.return_value.stdout = ['Red Hat Enterprise Linux Server release 7.2.1 (Maipo)']
     assert 'RHEL7.2.1' == host_info.get_host_os_version()
     ssh_result.assert_called_once_with('cat /etc/redhat-release')
     ssh_result.return_value.stdout = ['Doesnt matter because because its cached']
     assert 'RHEL7.2.1' == host_info.get_host_os_version()
     # if called more than once cache didn't worked
     ssh_result.assert_called_once_with('cat /etc/redhat-release')
Exemplo n.º 2
0
 def test_cache(self):
     """Check get_host_os_version() calls are cached"""
     self._command.return_value.stdout = [
         u'Red Hat Enterprise Linux Server release 7.2.1 (Maipo)'
     ]
     self.assertEqual(u'RHEL7.2.1', host_info.get_host_os_version())
     self._command.assert_called_once_with('cat /etc/redhat-release')
     self._command.return_value.stdout = [
         u'Doesnt matter because because its cached'
     ]
     self.assertEqual(u'RHEL7.2.1', host_info.get_host_os_version())
     # if called more than once cache didn't worked
     self._command.assert_called_once_with('cat /etc/redhat-release')
Exemplo n.º 3
0
 def test_cache(self):
     """Check get_host_os_version() calls are cached"""
     self._command.return_value.stdout = [
         u'Red Hat Enterprise Linux Server release 7.2.1 (Maipo)'
     ]
     self.assertEqual(u'RHEL7.2.1', host_info.get_host_os_version())
     self._command.assert_called_once_with('cat /etc/redhat-release')
     self._command.return_value.stdout = [
         u'Doesnt matter because because its cached'
     ]
     self.assertEqual(u'RHEL7.2.1', host_info.get_host_os_version())
     # if called more than once cache didn't worked
     self._command.assert_called_once_with('cat /etc/redhat-release')
Exemplo n.º 4
0
        def wrapper(*args, **kwargs):
            """Wrapper that will skip the test if one of defined versions
            match host's version.
            """
            def log_version_info(msg, template):
                LOGGER.debug(template, func.__name__, func.__module__, msg)

            if not settings.configured:
                settings.configure()

            host_version = get_host_os_version()

            if any(host_version.startswith(version) for version in versions):
                skip_msg = f'host {host_version} in ignored versions {versions}'
                skip_template = 'Skipping test %s in module %s due to %s'
                log_version_info(skip_msg, skip_template)
                raise unittest2.SkipTest(skip_msg)

            return func(*args, **kwargs)
Exemplo n.º 5
0
        def wrapper(*args, **kwargs):
            """Wrapper that will skip the test if one of defined versions
            match host's version.
            """
            def log_version_info(msg, template):
                LOGGER.debug(template, func.__name__, func.__module__, msg)

            if not settings.configured:
                settings.configure()

            host_version = get_host_os_version()

            if any(host_version.startswith(version) for version in versions):
                skip_msg = 'host {0} in ignored versions {1}'.format(
                    host_version,
                    versions
                )
                skip_template = 'Skipping test %s in module %s due to %s'
                log_version_info(skip_msg, skip_template)
                raise unittest2.SkipTest(skip_msg)

            return func(*args, **kwargs)
Exemplo n.º 6
0
    def __init__(
        self,
        cpu=1,
        ram=512,
        distro=None,
        provisioning_server=None,
        image_dir=None,
        tag=None,
        hostname=None,
        domain=None,
        source_image=None,
        target_image=None,
        bridge=None,
        network=None,
    ):
        image_map = {
            DISTRO_RHEL6: settings.distro.image_el6,
            DISTRO_RHEL7: settings.distro.image_el7,
            DISTRO_RHEL8: settings.distro.image_el8,
            DISTRO_SLES11: settings.distro.image_sles11,
            DISTRO_SLES12: settings.distro.image_sles12,
            'image_docker': settings.docker.docker_image,
        }
        self.cpu = cpu
        self.mac = None
        self.ram = ram
        self.nw_type = None
        if distro is None:
            # use the same distro as satellite host server os
            from paramiko.ssh_exception import NoValidConnectionsError, SSHException

            try:
                server_host_os_version = get_host_os_version()
            except (NoValidConnectionsError, SSHException):
                import traceback

                trace = sys.exc_info()
                tb_lines = '\n'.join(traceback.format_tb(trace[2]))
                core_exc = trace[1]
                raise VirtualMachineError(
                    'Exception connecting via ssh to get host os version:\n'
                    f'{tb_lines}\n{core_exc}')
            if server_host_os_version.startswith('RHEL6'):
                distro = DISTRO_RHEL6
            elif server_host_os_version.startswith('RHEL7'):
                distro = DISTRO_RHEL7
            else:
                raise VirtualMachineError(
                    'Cannot find a default compatible distro using '
                    f'host OS version: {server_host_os_version}')

        self.distro = distro
        if self.distro not in self.allowed_distros:
            raise VirtualMachineError(
                f'{self.distro} is not a supported distro. Choose one of {self.allowed_distros}'
            )

        self.provisioning_server = provisioning_server or settings.clients.provisioning_server

        if self.provisioning_server in [None, '']:
            raise VirtualMachineError(
                'A provisioning server must be provided. Make sure to fill '
                '"provisioning_server" on clients section of your robottelo '
                'configuration. Or provide a not None provisioning_server '
                'argument.')
        if image_dir is None:
            self.image_dir = settings.clients.image_dir
        else:
            self.image_dir = image_dir

        self._hostname = hostname
        self.ip_addr = None
        self._domain = domain
        self._created = False
        self._subscribed = False
        self._source_image = source_image or '{0}-base'.format(
            image_map.get(self.distro))
        self._target_image = target_image or gen_string('alphanumeric',
                                                        16).lower()
        if tag:
            self._target_image = tag + self._target_image
        self.bridge = bridge
        self.network = network
        if len(self.hostname) > 59:
            raise VirtualMachineError(
                'Max virtual machine name is 59 chars (see BZ1289363). Name '
                '"{}" is {} chars long. Please provide shorter name'.format(
                    self.hostname, len(self.hostname)))
Exemplo n.º 7
0
    def __init__(self,
                 cpu=4,
                 ram=16384,
                 distro=None,
                 provisioning_server=None,
                 image_dir=None,
                 org_id=None,
                 lce_id=None,
                 organization_ids=None,
                 location_ids=None):
        """Manage a virtual machine with satellite capsule product setup for
        client provisioning.

        :param int cpu: The number of CPUs usage.
        :param int ram: the number of RAM usage in mega bytes.
        :param str distro: The OS distro to use to provision the virtual
         machine, it's also used in capsule setup to prepare the satellite
         products content.
        :param str provisioning_server: the provisioning server url
        :param str image_dir: the images location path on the provisioning
         server.
        :param int org_id: The organization id used to subscribe the
         virtual machine and to create the products contents that the virtual
         machine will use to setup the capsule.
        :param int lce_id: the lifecycle environment used for the subscription
         of virtual machine
        :param List[int] organization_ids: the organization ids of
         organizations that will use the capsule.
        :param List[int] location_ids: the location ids for which the content
         will be synchronized.
        """
        # ensure that capsule configuration exist and validate
        if not setting_is_set('capsule'):
            raise CapsuleVirtualMachineError('capsule configuration not set')

        if distro is None:
            # use the same distro as satellite host server os
            server_host_os_version = get_host_os_version()
            if server_host_os_version.startswith('RHEL6'):
                distro = DISTRO_RHEL6
            elif server_host_os_version.startswith('RHEL7'):
                distro = DISTRO_RHEL7
            else:
                raise CapsuleVirtualMachineError(
                    'cannot find a default compatible distro to create'
                    ' the virtual machine')

        self._capsule_distro = distro
        self._capsule_domain = settings.capsule.domain
        self._capsule_instance_name = settings.capsule.instance_name
        self._capsule_hostname_hash = settings.capsule.hash
        self._capsule_hostname = settings.capsule.hostname
        self._ddns_package_url = settings.capsule.ddns_package_url

        super(CapsuleVirtualMachine,
              self).__init__(cpu=cpu,
                             ram=ram,
                             distro=distro,
                             provisioning_server=provisioning_server,
                             image_dir=image_dir,
                             hostname=self._capsule_hostname,
                             domain=self._capsule_domain,
                             target_image=self._capsule_instance_name)

        self._capsule_org_id = org_id
        self._capsule_lce_id = lce_id
        if organization_ids is None:
            organization_ids = []
        self._capsule_organization_ids = organization_ids
        if location_ids is None:
            location_ids = []
        self._capsule_location_ids = location_ids
        self._capsule = None
        self._capsule_org = None
        self._capsule_lce = None
Exemplo n.º 8
0
    def __init__(
            self, cpu=1, ram=512, distro=None, provisioning_server=None,
            image_dir=None, tag=None, hostname=None, domain=None,
            source_image=None, target_image=None, bridge=None):
        distro_docker = settings.docker.docker_image
        distro_el6 = settings.distro.image_el6
        distro_el7 = settings.distro.image_el7
        allowed_distros = [distro_docker, distro_el6, distro_el7]
        self.cpu = cpu
        self.ram = ram
        if distro == DISTRO_RHEL6:
            distro = distro_el6
        if distro == DISTRO_RHEL7:
            distro = distro_el7
        if distro is None:
            # use the same distro as satellite host server os
            server_host_os_version = get_host_os_version()
            if server_host_os_version.startswith('RHEL6'):
                distro = distro_el6
            elif server_host_os_version.startswith('RHEL7'):
                distro = distro_el7
            else:
                raise VirtualMachineError(
                    'cannot find a default compatible distro to create'
                    ' the virtual machine')
        self.distro = distro
        if self.distro not in (allowed_distros):
            raise VirtualMachineError(
                u'{0} is not a supported distro. Choose one of {1}'
                .format(self.distro, allowed_distros)
            )
        if provisioning_server is None:
            self.provisioning_server = settings.clients.provisioning_server
        else:
            self.provisioning_server = provisioning_server
        if self.provisioning_server is None or self.provisioning_server == '':
            raise VirtualMachineError(
                'A provisioning server must be provided. Make sure to fill '
                '"provisioning_server" on clients section of your robottelo '
                'configuration. Or provide a not None provisioning_server '
                'argument.'
            )
        if image_dir is None:
            self.image_dir = settings.clients.image_dir
        else:
            self.image_dir = image_dir

        self._hostname = hostname
        self.ip_addr = None
        self._domain = domain
        self._created = False
        self._subscribed = False
        self._source_image = source_image or u'{0}-base'.format(self.distro)
        self._target_image = (
            target_image or gen_string('alphanumeric', 16).lower()
        )
        if tag:
            self._target_image = tag + self._target_image
        self.bridge = bridge
        if len(self.hostname) > 59:
            raise VirtualMachineError(
                'Max virtual machine name is 59 chars (see BZ1289363). Name '
                '"{}" is {} chars long. Please provide shorter name'
                .format(self.hostname, len(self.hostname))
            )
Exemplo n.º 9
0
    def __init__(
            self, cpu=4, ram=16384, distro=None, provisioning_server=None,
            image_dir=None, org_id=None, lce_id=None,
            organization_ids=None, location_ids=None):
        """Manage a virtual machine with satellite capsule product setup for
        client provisioning.

        :param int cpu: The number of CPUs usage.
        :param int ram: the number of RAM usage in mega bytes.
        :param str distro: The OS distro to use to provision the virtual
         machine, it's also used in capsule setup to prepare the satellite
         products content.
        :param str provisioning_server: the provisioning server url
        :param str image_dir: the images location path on the provisioning
         server.
        :param int org_id: The organization id used to subscribe the
         virtual machine and to create the products contents that the virtual
         machine will use to setup the capsule.
        :param int lce_id: the lifecycle environment used for the subscription
         of virtual machine
        :param List[int] organization_ids: the organization ids of
         organizations that will use the capsule.
        :param List[int] location_ids: the location ids for which the content
         will be synchronized.
        """
        # ensure that capsule configuration exist and validate
        if not setting_is_set('capsule'):
            raise CapsuleVirtualMachineError('capsule configuration not set')

        if distro is None:
            # use the same distro as satellite host server os
            server_host_os_version = get_host_os_version()
            if server_host_os_version.startswith('RHEL6'):
                distro = DISTRO_RHEL6
            elif server_host_os_version.startswith('RHEL7'):
                distro = DISTRO_RHEL7
            else:
                raise CapsuleVirtualMachineError(
                    'cannot find a default compatible distro to create'
                    ' the virtual machine')

        self._capsule_distro = distro
        self._capsule_domain = settings.capsule.domain
        self._capsule_instance_name = settings.capsule.instance_name
        self._capsule_hostname_hash = settings.capsule.hash
        self._capsule_hostname = settings.capsule.hostname
        self._ddns_package_url = settings.capsule.ddns_package_url

        super(CapsuleVirtualMachine, self).__init__(
            cpu=cpu, ram=ram, distro=distro,
            provisioning_server=provisioning_server, image_dir=image_dir,
            hostname=self._capsule_hostname,
            domain=self._capsule_domain,
            target_image=self._capsule_instance_name
        )

        self._capsule_org_id = org_id
        self._capsule_lce_id = lce_id
        if organization_ids is None:
            organization_ids = []
        self._capsule_organization_ids = organization_ids
        if location_ids is None:
            location_ids = []
        self._capsule_location_ids = location_ids
        self._capsule = None
        self._capsule_org = None
        self._capsule_lce = None