Ejemplo n.º 1
0
class TestDockerImageUploader(base.TestCase):

    def setUp(self):
        super(TestDockerImageUploader, self).setUp()
        self.uploader = DockerImageUploader()
        self.patcher = mock.patch('tripleo_common.image.image_uploader.Client')
        self.dockermock = self.patcher.start()

    def tearDown(self):
        super(TestDockerImageUploader, self).tearDown()
        self.patcher.stop()

    def test_upload_image(self):
        image = 'tripleoupstream/heat-docker-agents-centos'
        tag = 'latest'
        pull_source = 'docker.io'
        push_destination = 'localhost:8787'

        self.uploader.upload_image(image + ':' + tag,
                                   pull_source,
                                   push_destination)

        self.dockermock.assert_called_once_with(
            base_url='unix://var/run/docker.sock')

        self.dockermock.return_value.pull.assert_called_once_with(
            pull_source + '/' + image,
            tag=tag, stream=True, insecure_registry=True)
        self.dockermock.return_value.tag.assert_called_once_with(
            image=pull_source + '/' + image + ':' + tag,
            repository=push_destination + '/' + image,
            tag=tag, force=True)
        self.dockermock.return_value.push(
            push_destination + '/' + image,
            tag=tag, stream=True, insecure_registry=True)
Ejemplo n.º 2
0
class TestDockerImageUploader(base.TestCase):

    def setUp(self):
        super(TestDockerImageUploader, self).setUp()
        self.uploader = DockerImageUploader()
        self.patcher = mock.patch('tripleo_common.image.image_uploader.Client')
        self.dockermock = self.patcher.start()

    def tearDown(self):
        super(TestDockerImageUploader, self).tearDown()
        self.patcher.stop()

    def test_upload_image(self):
        image = 'tripleoupstream/heat-docker-agents-centos'
        tag = 'latest'
        pull_source = 'docker.io'
        push_destination = 'localhost:8787'

        self.uploader.upload_image(image + ':' + tag,
                                   pull_source,
                                   push_destination)

        self.dockermock.assert_called_once_with(
            base_url='unix://var/run/docker.sock', version='auto')

        self.dockermock.return_value.pull.assert_called_once_with(
            pull_source + '/' + image,
            tag=tag, stream=True)
        self.dockermock.return_value.tag.assert_called_once_with(
            image=pull_source + '/' + image + ':' + tag,
            repository=push_destination + '/' + image,
            tag=tag, force=True)
        self.dockermock.return_value.push(
            push_destination + '/' + image,
            tag=tag, stream=True)

    def test_upload_image_missing_tag(self):
        image = 'tripleoupstream/heat-docker-agents-centos'
        expected_tag = 'latest'
        pull_source = 'docker.io'
        push_destination = 'localhost:8787'

        self.uploader.upload_image(image,
                                   pull_source,
                                   push_destination)

        self.dockermock.assert_called_once_with(
            base_url='unix://var/run/docker.sock', version='auto')

        self.dockermock.return_value.pull.assert_called_once_with(
            pull_source + '/' + image,
            tag=expected_tag, stream=True)
        self.dockermock.return_value.tag.assert_called_once_with(
            image=pull_source + '/' + image + ':' + expected_tag,
            repository=push_destination + '/' + image,
            tag=expected_tag, force=True)
        self.dockermock.return_value.push(
            push_destination + '/' + image,
            tag=expected_tag, stream=True)
Ejemplo n.º 3
0
 def setUp(self):
     super(TestDockerImageUploader, self).setUp()
     self.uploader = DockerImageUploader()
     self.patcher = mock.patch('tripleo_common.image.image_uploader.Client')
     self.dockermock = self.patcher.start()
Ejemplo n.º 4
0
class TestDockerImageUploader(base.TestCase):
    def setUp(self):
        super(TestDockerImageUploader, self).setUp()
        self.uploader = DockerImageUploader()
        self.patcher = mock.patch('tripleo_common.image.image_uploader.Client')
        self.dockermock = self.patcher.start()

    def tearDown(self):
        super(TestDockerImageUploader, self).tearDown()
        self.patcher.stop()

    def test_upload_image(self):
        image = 'tripleoupstream/heat-docker-agents-centos'
        tag = 'latest'
        pull_source = 'docker.io'
        push_destination = 'localhost:8787'

        self.uploader.upload_image(image + ':' + tag, pull_source,
                                   push_destination)

        self.dockermock.assert_called_once_with(
            base_url='unix://var/run/docker.sock', version='auto')

        self.dockermock.return_value.pull.assert_called_once_with(pull_source +
                                                                  '/' + image,
                                                                  tag=tag,
                                                                  stream=True)
        self.dockermock.return_value.tag.assert_called_once_with(
            image=pull_source + '/' + image + ':' + tag,
            repository=push_destination + '/' + image,
            tag=tag,
            force=True)
        self.dockermock.return_value.push(push_destination + '/' + image,
                                          tag=tag,
                                          stream=True)

    def test_upload_image_missing_tag(self):
        image = 'tripleoupstream/heat-docker-agents-centos'
        expected_tag = 'latest'
        pull_source = 'docker.io'
        push_destination = 'localhost:8787'

        self.uploader.upload_image(image, pull_source, push_destination)

        self.dockermock.assert_called_once_with(
            base_url='unix://var/run/docker.sock', version='auto')

        self.dockermock.return_value.pull.assert_called_once_with(
            pull_source + '/' + image, tag=expected_tag, stream=True)
        self.dockermock.return_value.tag.assert_called_once_with(
            image=pull_source + '/' + image + ':' + expected_tag,
            repository=push_destination + '/' + image,
            tag=expected_tag,
            force=True)
        self.dockermock.return_value.push(push_destination + '/' + image,
                                          tag=expected_tag,
                                          stream=True)

    def test_discover_image_tag(self):
        image = 'docker.io/tripleoupstream/heat-docker-agents-centos:latest'
        vimage = 'docker.io/tripleoupstream/heat-docker-agents-centos:1.2.3'

        dockerc = self.dockermock.return_value
        dockerc.pull.return_value = ['{"status": "done"}']
        dockerc.inspect_image.return_value = {
            'Config': {
                'Labels': {
                    'image-version': '1.2.3'
                }
            }
        }
        result = self.uploader.discover_image_tag(image, 'image-version')
        self.assertEqual('1.2.3', result)

        self.dockermock.assert_called_once_with(
            base_url='unix://var/run/docker.sock', version='auto')

        dockerc.pull.assert_has_calls([
            mock.call(image, tag=None, stream=True),
            mock.call(vimage, tag=None, stream=True),
        ])

    def test_discover_image_tag_no_latest(self):
        image = 'docker.io/tripleoupstream/heat-docker-agents-centos'
        limage = image + ':latest'
        vimage = image + ':1.2.3'

        dockerc = self.dockermock.return_value
        dockerc.pull.return_value = ['{"status": "done"}']
        dockerc.inspect_image.return_value = {
            'Config': {
                'Labels': {
                    'image-version': '1.2.3'
                }
            }
        }
        result = self.uploader.discover_image_tag(image, 'image-version')
        self.assertEqual('1.2.3', result)

        dockerc.pull.assert_has_calls([
            mock.call(limage, tag=None, stream=True),
            mock.call(vimage, tag=None, stream=True),
        ])

    def test_discover_image_tag_no_tag_from_image(self):
        image = 'docker.io/tripleoupstream/heat-docker-agents-centos:latest'

        dockerc = self.dockermock.return_value
        dockerc.pull.return_value = ['{"status": "done"}']
        dockerc.inspect_image.return_value = {
            'Config': {
                'Labels': {
                    'image-version': '1.2.3'
                }
            }
        }
        self.assertRaises(ImageUploaderException,
                          self.uploader.discover_image_tag, image)

    def test_discover_image_tag_missing_label(self):
        image = 'docker.io/tripleoupstream/heat-docker-agents-centos:latest'

        dockerc = self.dockermock.return_value
        dockerc.pull.return_value = ['{"status": "done"}']
        dockerc.inspect_image.return_value = {
            'Config': {
                'Labels': {
                    'image-version': '1.2.3'
                }
            }
        }
        self.assertRaises(ImageUploaderException,
                          self.uploader.discover_image_tag, image, 'foo')

    @mock.patch('time.sleep')
    def test_pull_retry(self, sleep_mock):
        image = 'docker.io/tripleoupstream/heat-docker-agents-centos'

        dockerc = self.dockermock.return_value
        dockerc.pull.side_effect = [['{"error": "ouch"}'
                                     ], ['{"error": "ouch"}'],
                                    ['{"error": "ouch"}'],
                                    ['{"error": "ouch"}'],
                                    ['{"status": "done"}']]
        self.uploader._pull_retry(dockerc, image)

        self.assertEqual(sleep_mock.call_count, 4)
        dockerc.pull.assert_has_calls(
            [mock.call(image, tag=None, stream=True)])

    @mock.patch('time.sleep')
    def test_pull_retry_failure(self, sleep_mock):
        image = 'docker.io/tripleoupstream/heat-docker-agents-centos'

        dockerc = self.dockermock.return_value
        dockerc.pull.side_effect = [
            ['{"error": "ouch"}'],
            ['{"error": "ouch"}'],
            ['{"error": "ouch"}'],
            ['{"error": "ouch"}'],
            ['{"error": "ouch"}'],
        ]
        self.assertRaises(ImageUploaderException, self.uploader._pull_retry,
                          dockerc, image)

        self.assertEqual(sleep_mock.call_count, 5)
        dockerc.pull.assert_has_calls(
            [mock.call(image, tag=None, stream=True)])
 def setUp(self):
     super(TestDockerImageUploader, self).setUp()
     self.uploader = DockerImageUploader()
     self.patcher = mock.patch('tripleo_common.image.image_uploader.Client')
     self.dockermock = self.patcher.start()