Exemplo n.º 1
0
    def test_stop_test_environment_task(self):
        """
        Test that stop task stops a running test environment
        """

        test_id = '34fe32fdsfdsxxx'
        docker = Client(version='auto')
        image = 'adsabs/pythonsimpleserver:v1.0.0'

        try:
            container = docker.create_container(
                image=image,
                name='livetest-pythonserver-{}'.format(test_id),
            )
        except errors.NotFound:
            docker.pull(image)
            container = docker.create_container(
                image='adsabs/pythonsimpleserver:v1.0.0',
                name='livetest-pythonserver-{}'.format(test_id),
            )
        except Exception as error:
            self.fail('Unknown exception: {}'.format(error))

        docker.start(container=container['Id'])

        stop_test_environment(test_id=test_id)

        self.assertFalse([
            i for i in docker.containers()
            if [j for j in i['Names'] if test_id in j]
        ])
    def test_containers_are_stopped(self, mocked):
        """
        Test that we have the opportunity to stop containers based on an id
        """
        instance = mocked.return_value
        instance.containers.return_value = [
            {
                u"Command": u"/entrypoint.sh redis-server",
                u"Created": 1443632967,
                u"Id": u"mocked",
                u"Image": u"redis",
                u"Labels": {},
                u"Names": [u"/livetest-redis-tLJpZ"],
                u"Ports": [{u"PrivatePort": 6379, u"Type": u"tcp"}],
                u"Status": u"Up About a minute",
            }
        ]
        instance.stop.return_value = None
        instance.remove_container.return_value = None

        stop_test_environment(test_id="livetest")

        instance.stop.assert_has_calls([call(container=u"mocked")])

        instance.remove_container.assert_has_calls([call(container=u"mocked")])
Exemplo n.º 3
0
    def test_containers_are_stopped(self, mocked):
        """
        Test that we have the opportunity to stop containers based on an id
        """
        instance = mocked.return_value
        instance.containers.return_value = [{
            u'Command':
            u'/entrypoint.sh redis-server',
            u'Created':
            1443632967,
            u'Id':
            u'mocked',
            u'Image':
            u'redis',
            u'Labels': {},
            u'Names': [u'/livetest-redis-tLJpZ'],
            u'Ports': [{
                u'PrivatePort': 6379,
                u'Type': u'tcp'
            }],
            u'Status':
            u'Up About a minute'
        }]
        instance.stop.return_value = None
        instance.remove_container.return_value = None

        stop_test_environment(test_id='livetest')

        instance.stop.assert_has_calls([call(container=u'mocked')])

        instance.remove_container.assert_has_calls([call(container=u'mocked')])
Exemplo n.º 4
0
    def test_stop_test_environment_task(self):
        """
        Test that stop task stops a running test environment
        """

        test_id = '34fe32fdsfdsxxx'
        docker = Client(version='auto')
        image = 'adsabs/pythonsimpleserver:v1.0.0'

        try:
            container = docker.create_container(
                image=image,
                name='livetest-pythonserver-{}'.format(test_id),
            )
        except errors.NotFound:
            docker.pull(image)
            container = docker.create_container(
                image='adsabs/pythonsimpleserver:v1.0.0',
                name='livetest-pythonserver-{}'.format(test_id),
            )
        except Exception as error:
            self.fail('Unknown exception: {}'.format(error))

        docker.start(container=container['Id'])

        stop_test_environment(test_id=test_id)

        self.assertFalse([i for i in docker.containers() if [j for j in i['Names'] if test_id in j]])