Exemplo n.º 1
0
    def test_post_scenario_remoteexecution_satellite(self):
        """Run a REX job on pre-upgrade created client registered
        with Satellite.

        :id: postupgrade-ad3b1564-d3e6-4ada-9337-3a6ee6863bae

        :steps:
            1. Run a REX job on content host.

        :expectedresults:
            1. The job should successfully executed on pre-upgrade created client.
        """
        client_name = get_entity_data(self.__class__.__name__)['client_name']
        job = entities.JobInvocation().run(
            data={
                'job_template_id': 89,
                'inputs': {
                    'command': "ls"
                },
                'targeting_type': 'static_query',
                'search_query': f"name = {client_name}",
            })
        self.assertEqual(job['output']['success_count'], 1)
        cleanup_of_provisioned_server(hostname=client_name,
                                      provisioning_server=self.libvirt_vm,
                                      distro=DISTRO_RHEL7)
Exemplo n.º 2
0
    def test_post_scenario_remoteexecution_external_capsule(self):
        """Run a REX job on pre-upgrade created client registered
        with external capsule.

        :id: postupgrade-00ed2a25-b0bd-446f-a3fc-09149c57fe94

        :steps:
            1. Run a REX job on content host.

        :expectedresults:
            1. The job should successfully executed on pre-upgrade created client.
        """
        client_name = get_entity_data(self.__class__.__name__)['client_name']
        job = entities.JobInvocation().run(
            data={
                'job_template_id': 89,
                'inputs': {
                    'command': "ls"
                },
                'targeting_type': 'static_query',
                'search_query': "name = {0}".format(client_name)
            })
        self.assertEqual(job['output']['success_count'], 1)
        cleanup_of_provisioned_server(hostname=client_name,
                                      provisioning_server=self.libvirt_vm,
                                      distro=DISTRO_RHEL7)
Exemplo n.º 3
0
    def test_pre_scenario_remoteexecution_external_capsule(self):
        """Run REX job on client registered with external capsule

        :id: preupgrade-261dd2aa-be01-4c34-b877-54b8ee346561

        :steps:
            1. Create Subnet.
            2. Create Content host.
            3. Install katello-ca package and register to Satellite host.
            4. add rex ssh_key of external capsule on content host.
            5. run the REX job on client vm.

        :expectedresults:
            1. Content host should create with pre-required details.
            2. REX job should run on it.
        """
        try:
            default_loc_id = (entities.Location().search(
                query={'search': f'name="{DEFAULT_LOC}"'})[0].id)
            sn = entities.Subnet(
                domain=self.vm_domain,
                gateway=self.gateway,
                ipam='DHCP',
                location=[default_loc_id],
                mask=self.netmask,
                network=self.subnet,
                organization=[self.org.id],
                remote_execution_proxy=[entities.SmartProxy(id=2)],
            ).create()
            client = VirtualMachine(distro=DISTRO_RHEL7,
                                    provisioning_server=self.libvirt_vm,
                                    bridge=self.bridge)
            client.create()
            client.install_capsule_katello_ca(capsule=self.proxy_name)
            client.register_contenthost(org=self.org.label, lce='Library')
            add_remote_execution_ssh_key(hostname=client.ip_addr,
                                         proxy_hostname=self.proxy_name)
            host = entities.Host().search(
                query={'search': f'name="{client.hostname}"'})
            host[0].subnet = sn
            host[0].update(['subnet'])
            job = entities.JobInvocation().run(
                data={
                    'job_template_id': 89,
                    'inputs': {
                        'command': "ls"
                    },
                    'targeting_type': 'static_query',
                    'search_query': f"name = {client.hostname}",
                })
            self.assertEqual(job['output']['success_count'], 1)
            global_dict = {
                self.__class__.__name__: {
                    'client_name': client.hostname
                }
            }
            create_dict(global_dict)
        except Exception as exp:
            if client._created:
                cleanup_of_provisioned_server(
                    hostname=client.hostname,
                    provisioning_server=self.libvirt_vm,
                    distro=DISTRO_RHEL7,
                )
            raise Exception(exp)
Exemplo n.º 4
0
    def test_pre_scenario_containers_support_removal(self):
        """Pre-upgrade scenario test to verify containers created and run
        before upgrade

        :id: preupgrade-f6de07ae-14c7-4452-9cb1-cafe2aa648ae

        :steps:

            1. Create docker host
            2. Create and run container from dockerhub
            3. Create and run container from external registry

        :expectedresults:

            1. Docker host is created
            2. Container from dockerhub is created and running
            3. Container from external registry is created and running

        """
        repo_name = 'rhel'
        compute_resource_name = gen_string('alpha')
        registry_url = settings.docker.external_registry_1
        org = entities.Organization().create()

        docker_host = VirtualMachine(source_image=settings.docker.docker_image,
                                     tag=u'docker')
        docker_host.create()
        try:
            docker_host.install_katello_ca()

            compute_resource = entities.DockerComputeResource(
                name=compute_resource_name,
                organization=[org],
                url='http://{0}:2375'.format(docker_host.ip_addr),
            ).create()

            # Only one registry with given URL can exist on Satellite,
            # so search for it first and create it only if necessary
            try:
                registry = entities.Registry().search(
                    filters={'url': registry_url})[0]
            except IndexError:
                registry = entities.Registry(
                    url=registry_url,
                    organization=[org],
                ).create()

            # container from dockerhub
            dockerhub_container = entities.DockerHubContainer(
                command='sleep inf',
                compute_resource=compute_resource,
                organization=[org],
            ).create()
            self.assertEqual(dockerhub_container.compute_resource.id,
                             compute_resource.id)

            # container from external registry
            external_container = entities.DockerRegistryContainer(
                command='sleep inf',
                compute_resource=compute_resource,
                organization=[org],
                registry=registry,
                repository_name=repo_name,
            ).create()
            self.assertEqual(external_container.compute_resource.id,
                             compute_resource.id)
            self.assertEqual(external_container.registry.id, registry.id)
            self.assertEqual(external_container.repository_name, repo_name)

            running_containers = docker_host.run('docker ps')
            self.assertEqual(running_containers.return_code, 0)

            self.assertTrue(
                any(dockerhub_container.name in line
                    for line in running_containers.stdout))
            self.assertTrue(
                any(external_container.name in line
                    for line in running_containers.stdout))

            scenario_dict = {
                self.__class__.__name__: {
                    'docker_host': docker_host.hostname,
                    'dockerhub_container': dockerhub_container.name,
                    'external_container': external_container.name,
                }
            }
            create_dict(scenario_dict)
        except Exception as exp:
            cleanup_of_provisioned_server(
                hostname=docker_host.hostname,
                provisioning_server=settings.clients.provisioning_server)
            raise Exception(exp)
Exemplo n.º 5
0
    def test_post_scenario_containers_support_removal(self):
        """Post-upgrade scenario test to verify containers created and run
        before upgrade are still running after upgrade.

        :id: postupgrade-f6de07ae-14c7-4452-9cb1-cafe2aa648ae

        :steps:

            1. Verify that upgrade procedure removed foreman_docker support
            2. Verify container from dockerhub is still running
            3. Verify container from external registry is still running

        :expectedresults:

            1. Upgrade procedure removed support for foreman_docker
            2. Container from dockerhub is still running
            3. Container from external registry is still running

        """
        entity_data = get_entity_data(self.__class__.__name__)
        docker_host_hostname = entity_data.get('docker_host')
        dockerhub_container = entity_data.get('dockerhub_container')
        external_container = entity_data.get('external_container')
        try:
            extract_log_command = "sed -n '/{delimiter}/,/{delimiter}/p' {path}".format(
                delimiter="RemoveForemanDockerSupport",
                path="/var/log/foreman-installer/satellite*log")
            docker_log = ssh.command(extract_log_command,
                                     output_format='plain')
            self.assertEqual(docker_log.return_code, 0)

            docker_log = docker_log.stdout.split("\n")

            self.assertTrue(
                any("RemoveForemanDockerSupport: migrated" in line
                    for line in docker_log))
            self.assertTrue(
                any("remove_column(:containers, :capsule_id)" in line
                    for line in docker_log))

            removed_tables = ('docker_images', 'docker_tags',
                              'docker_container_wizard_states_images',
                              'containers')

            for table in removed_tables:
                self.assertTrue(
                    any("table_exists?(:{})".format(table) in line
                        for line in docker_log))

            running_containers = ssh.command('docker ps',
                                             hostname=docker_host_hostname)
            self.assertEqual(running_containers.return_code, 0)

            self.assertTrue(
                any(dockerhub_container in line
                    for line in running_containers.stdout))
            self.assertTrue(
                any(external_container in line
                    for line in running_containers.stdout))
        except Exception as exp:
            cleanup_of_provisioned_server(
                hostname=docker_host_hostname,
                provisioning_server=settings.clients.provisioning_server)
            raise Exception(exp)

        cleanup_of_provisioned_server(
            hostname=docker_host_hostname,
            provisioning_server=settings.clients.provisioning_server)