def test_positive_list_containers(session, module_org, module_loc):
    """Create a Docker-based Compute Resource then list its running containers.

    :id: ebac82ed-5a29-4a06-8aae-bd5b08f60fba

    :expectedresults: Compute Resource can be created, listed and existing
        running instances can be listed.

    :BZ: 1466240, 1478966

    :CaseLevel: Integration
    """
    compute_resource = entities.DockerComputeResource(
        location=[module_loc],
        organization=[module_org],
        url=settings.docker.external_url,
    ).create()
    containers = [
        entities.DockerHubContainer(
            compute_resource=compute_resource,
            location=[module_loc],
            organization=[module_org],
        ).create() for _ in range(3)
    ]
    with session:
        for container in containers:
            assert container.name in session.computeresource.search_container(
                compute_resource.name, container.name)[0]['Name']
Esempio n. 2
0
    def test_positive_power_on_off(self):
        """Create containers for local and external compute resource,
        then power them on and finally power them off

        @Feature: Docker

        @Assert: The docker container is created for each compute resource
        and the power status is showing properly
        """
        for compute_resource in (self.cr_internal, self.cr_external):
            with self.subTest(compute_resource):
                container = entities.DockerHubContainer(
                    command='top',
                    compute_resource=compute_resource,
                    organization=[self.org],
                ).create()
                self.assertEqual(
                    container.compute_resource.read().url,
                    compute_resource.url,
                )
                self.assertTrue(container.power(
                    data={u'power_action': 'status'})['running'])
                container.power(data={u'power_action': 'stop'})
                self.assertFalse(container.power(
                    data={u'power_action': 'status'})['running'])
Esempio n. 3
0
    def test_positive_list_containers_internal(self):
        """Create a Docker-based Compute Resource in the Satellite 6
        instance then list its running containers.

        @Assert: Compute Resource can be created and existing instances can be
        listed.

        @Feature: Docker
        """
        for url in (settings.docker.external_url,
                    settings.docker.get_unix_socket_url()):
            with self.subTest(url):
                compute_resource = entities.DockerComputeResource(
                    organization=[self.org],
                    url=url,
                ).create()
                self.assertEqual(compute_resource.url, url)
                self.assertEqual(len(entities.AbstractDockerContainer(
                    compute_resource=compute_resource).search()), 0)
                container = entities.DockerHubContainer(
                    command='top',
                    compute_resource=compute_resource,
                    organization=[self.org],
                ).create()
                result = entities.AbstractDockerContainer(
                    compute_resource=compute_resource).search()
                self.assertEqual(len(result), 1)
                self.assertEqual(result[0].name, container.name)
Esempio n. 4
0
def test_positive_power_on_off(session, module_container_host):
    """Create containers for a compute resource,
    then power them on and finally power them off

    :id: cc27bb6f-7fa4-4c87-bf7e-339f2f888717

    :expectedresults: The docker container is created and the power status
        is showing properly

    :BZ: 1683348

    :CaseComponent: ContainerManagement-Runtime

    :CaseLevel: Integration
    """
    container = entities.DockerHubContainer(
        compute_resource=module_container_host.compute_resource,
        location=[module_container_host.location],
        name=gen_string('alpha', 4).lower(),
        organization=[module_container_host.organization],
    ).create()
    with session:
        for status in ('Off', 'On'):
            session.container.set_power(container.name, status)
            assert session.container.search(container.name)[0]['Status'] == status
Esempio n. 5
0
    def test_positive_read_container_log(self):
        """Create containers for local and external compute resource and
        read their logs

        @Feature: Docker

        @Assert: The docker container is created for each compute resource and
        its log can be read
        """
        for compute_resource in (self.cr_internal, self.cr_external):
            with self.subTest(compute_resource):
                container = entities.DockerHubContainer(
                    command='date',
                    compute_resource=compute_resource,
                    organization=[self.org],
                ).create()
                self.assertTrue(container.logs()['logs'])
Esempio n. 6
0
    def test_positive_delete(self):
        """Delete containers in local and external compute resources

        @Feature: Docker

        @Assert: The docker containers are deleted in local and external
        compute resources
        """
        for compute_resource in (self.cr_internal, self.cr_external):
            with self.subTest(compute_resource.url):
                container = entities.DockerHubContainer(
                    command='top',
                    compute_resource=compute_resource,
                    organization=[self.org],
                ).create()
                container.delete()
                with self.assertRaises(HTTPError):
                    container.read()
Esempio n. 7
0
    def test_positive_create_with_compresource(self):
        """Create containers for local and external compute resources

        @Feature: Docker

        @Assert: The docker container is created for each compute resource
        """
        for compute_resource in (self.cr_internal, self.cr_external):
            with self.subTest(compute_resource.url):
                container = entities.DockerHubContainer(
                    command='top',
                    compute_resource=compute_resource,
                    organization=[self.org],
                ).create()
                self.assertEqual(
                    container.compute_resource.read().name,
                    compute_resource.name,
                )
Esempio n. 8
0
    def test_positive_create_using_cv(self):
        """Create docker container using custom content view, lifecycle
        environment and docker repository for local and external compute
        resources

        @Feature: Docker

        @Assert: The docker container is created for each compute resource
        """
        lce = entities.LifecycleEnvironment(organization=self.org).create()
        repo = _create_repository(
            entities.Product(organization=self.org).create(),
            upstream_name='centos',
        )
        repo.sync()
        content_view = entities.ContentView(organization=self.org).create()
        content_view.repository = [repo]
        content_view = content_view.update(['repository'])
        content_view.publish()
        content_view = content_view.read()
        self.assertEqual(len(content_view.version), 1)
        cvv = content_view.read().version[0].read()
        promote(cvv, lce.id)
        for compute_resource in (self.cr_internal, self.cr_external):
            with self.subTest(compute_resource):
                container = entities.DockerHubContainer(
                    command='top',
                    compute_resource=compute_resource,
                    organization=[self.org],
                    repository_name=repo.container_repository_name,
                    tag='latest',
                    tty='yes',
                ).create()
                self.assertEqual(
                    container.compute_resource.read().name,
                    compute_resource.name
                )
                self.assertEqual(
                    container.repository_name,
                    repo.container_repository_name
                )
                self.assertEqual(container.tag, 'latest')
Esempio n. 9
0
def test_positive_delete(session, module_container_host):
    """Delete containers in an external compute resource

    :id: e69808e7-6a0c-4310-b57a-2271ac61d11a

    :expectedresults: The docker containers are deleted

    :CaseLevel: Integration
    """
    container = entities.DockerHubContainer(
        compute_resource=module_container_host.compute_resource,
        location=[module_container_host.location],
        name=gen_string('alpha', 4).lower(),
        organization=[module_container_host.organization],
    ).create()
    with session:
        assert session.container.search(container.name)[0]['Name'].lower() == container.name
        session.container.delete(container.name)
        assert container.name not in [
            el['Name'] for el in session.container.search(container.name)]
    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

        """
        rh_registry_available = not bz_bug_is_open(1703397)
        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
            if rh_registry_available:
                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))
            if rh_registry_available:
                self.assertTrue(
                    any(external_container.name in line
                        for line in running_containers.stdout))

            ext_container_name = external_container.name if rh_registry_available else ''

            scenario_dict = {
                self.__class__.__name__: {
                    'rh_registry_available': rh_registry_available,
                    'docker_host': docker_host.hostname,
                    'dockerhub_container': dockerhub_container.name,
                    'external_container': ext_container_name,
                }
            }
            create_dict(scenario_dict)
        except Exception as exp:
            self._vm_cleanup(hostname=docker_host.hostname)
            raise Exception(exp)