Beispiel #1
0
    def setUp(self):
        super(GlanceImageTestCase, self).setUp()

        self.glance_mock_client = mock.MagicMock()
        self.glance_mock_client().images.data()._resp = 'fake_resp_1'

        self.glance_client_patch = mockpatch.PatchObject(
            glance_client, 'Client', new=self.glance_mock_client)
        self.useFixture(self.glance_client_patch)
        self.identity_mock = mock.Mock()
        self.image_mock = mock.Mock()

        self.fake_cloud = mock.Mock()
        self.fake_cloud.mysql_connector = mock.Mock()

        self.fake_cloud.resources = dict(identity=self.identity_mock,
                                         image=self.image_mock)
        self.glance_image = GlanceImage(FAKE_CONFIG, self.fake_cloud)

        self.fake_image_1 = mock.Mock()
        self.fake_image_1.id = 'fake_image_id_1'
        self.fake_image_1.name = 'fake_image_name_1'
        self.fake_image_1.status = 'fake_status_1'
        self.fake_image_1.checksum = 'fake_shecksum_1'
        self.fake_image_1.container_format = 'bare'
        self.fake_image_1.disk_format = 'qcow2'
        self.fake_image_1.is_public = True
        self.fake_image_1.protected = False
        self.fake_image_1.size = 1024
        self.fake_image_1.properties = 'fake_properties'

        self.fake_image_2 = mock.Mock()
        self.fake_image_2.name = 'fake_image_name_2'

        self.fake_input_info = {'images': {}}

        self.fake_result_info = {
            'images': {
                'fake_image_id_1': {
                    'image': {
                        'checksum': 'fake_shecksum_1',
                        'container_format': 'bare',
                        'disk_format': 'qcow2',
                        'id': 'fake_image_id_1',
                        'is_public': True,
                        'name': 'fake_image_name_1',
                        'protected': False,
                        'size': 1024,
                        'resource': self.image_mock,
                        'properties': 'fake_properties'
                    },
                    'meta': {}
                }
            },
        }
    def setUp(self):
        super(GlanceImageTestCase, self).setUp()

        self.glance_mock_client = mock.MagicMock()
        self.glance_mock_client().images.data()._resp = 'fake_resp_1'

        self.glance_client_patch = mockpatch.PatchObject(
            glance_client,
            'Client',
            new=self.glance_mock_client)
        self.useFixture(self.glance_client_patch)
        self.identity_mock = mock.Mock()
        self.image_mock = mock.Mock()

        self.fake_cloud = mock.Mock()
        self.fake_cloud.mysql_connector = mock.Mock()

        self.fake_cloud.resources = dict(identity=self.identity_mock,
                                         image=self.image_mock)
        self.glance_image = GlanceImage(FAKE_CONFIG, self.fake_cloud)

        self.fake_image_1 = mock.Mock()
        self.fake_image_1.id = 'fake_image_id_1'
        self.fake_image_1.name = 'fake_image_name_1'
        self.fake_image_1.status = 'fake_status_1'
        self.fake_image_1.checksum = 'fake_shecksum_1'
        self.fake_image_1.container_format = 'bare'
        self.fake_image_1.disk_format = 'qcow2'
        self.fake_image_1.is_public = True
        self.fake_image_1.protected = False
        self.fake_image_1.size = 1024
        self.fake_image_1.properties = 'fake_properties'

        self.fake_image_2 = mock.Mock()
        self.fake_image_2.name = 'fake_image_name_2'

        self.fake_input_info = {'images': {}}

        self.fake_result_info = {
            'images': {
                'fake_image_id_1': {'image': {'checksum': 'fake_shecksum_1',
                                              'container_format': 'bare',
                                              'disk_format': 'qcow2',
                                              'id': 'fake_image_id_1',
                                              'is_public': True,
                                              'name': 'fake_image_name_1',
                                              'protected': False,
                                              'size': 1024,
                                              'resource': self.image_mock,
                                              'properties': 'fake_properties'},
                                    'meta': {}}},
        }
    def setUp(self):
        super(GlanceImageTestCase, self).setUp()

        self.glance_mock_client = mock.MagicMock()

        self.glance_client_patch = mockpatch.PatchObject(glance_client, 'Client',
                                                         new=self.glance_mock_client)
        self.useFixture(self.glance_client_patch)
        self.identity_mock = mock.Mock()

        self.glance_image = GlanceImage(FAKE_CONFIG, self.identity_mock)

        self.fake_image_1 = mock.Mock()
        self.fake_image_1.id = 'fake_image_id_1'
        self.fake_image_1.status = 'fake_status_1'
        self.fake_image_1._resp = 'fake_resp_1'
        self.fake_image_1.checksum = 'fake_shecksum_1'

        self.fake_image_2 = mock.Mock()
class GlanceImageTestCase(test.TestCase):
    def setUp(self):
        super(GlanceImageTestCase, self).setUp()

        self.glance_mock_client = mock.MagicMock()

        self.glance_client_patch = mockpatch.PatchObject(glance_client, 'Client',
                                                         new=self.glance_mock_client)
        self.useFixture(self.glance_client_patch)
        self.identity_mock = mock.Mock()

        self.glance_image = GlanceImage(FAKE_CONFIG, self.identity_mock)

        self.fake_image_1 = mock.Mock()
        self.fake_image_1.id = 'fake_image_id_1'
        self.fake_image_1.status = 'fake_status_1'
        self.fake_image_1._resp = 'fake_resp_1'
        self.fake_image_1.checksum = 'fake_shecksum_1'

        self.fake_image_2 = mock.Mock()

    def test_get_client(self):
        fake_endpoint = 'fake_endpoint'
        fake_auth_token = 'fake_auth_token'
        self.identity_mock.get_endpoint_by_name_service.return_value = fake_endpoint
        self.identity_mock.get_auth_token_from_user.return_value = fake_auth_token

        glance_client = self.glance_image.get_glance_client()
        mock_calls = [mock.call(endpoint=fake_endpoint, token=fake_auth_token)]

        self.glance_mock_client.assert_has_calls(mock_calls)
        self.assertEqual(self.glance_mock_client(), glance_client)

    def test_get_images_list(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals(fake_images, self.glance_image.get_image_list())

    def test_create_image(self):
        self.glance_image.create_image(name='fake_image_name', data='fake_data')
        test_args = {'name': 'fake_image_name',
                     'data': 'fake_data'}

        self.glance_mock_client().images.create.assert_called_once_with(**test_args)

    def test_delete_image(self):
        fake_image_id = 'fake_image_id_1'
        self.glance_image.delete_image(fake_image_id)

        self.glance_mock_client().images.delete.assert_called_once_with(fake_image_id)

    def test_get_image(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals(self.fake_image_1,
                          self.glance_image.get_image('fake_image_id_1'))

    def test_get_image_status(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals(self.fake_image_1.status,
                          self.glance_image.get_image_status('fake_image_id_1'))

    def test_get_ref_image(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals(self.fake_image_1._resp,
                          self.glance_image.get_ref_image('fake_image_id_1'))

    def test_get_image_checksum(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals(self.fake_image_1.checksum,
                          self.glance_image.get_image_checksum('fake_image_id_1'))
    def setUp(self):
        test.TestCase.setUp(self)

        self.glance_mock_client = mock.MagicMock()
        self.glance_mock_client().images.data()._resp = 'fake_resp_1'

        self.glance_client_patch = mockpatch.PatchObject(
            glance_client,
            'Client',
            new=self.glance_mock_client)
        self.useFixture(self.glance_client_patch)
        self.identity_mock = mock.Mock()
        self.identity_mock.get_endpoint_by_service_type = mock.Mock(
            return_value="http://192.168.1.2:9696/v2")
        fake_user = FakeUser()
        self.identity_mock.try_get_user_by_id = mock.Mock(
            return_value=fake_user)
        self.identity_mock.try_get_tenant_name_by_id = mock.Mock(
            return_value="fake_tenant_name")
        self.identity_mock.keystone_client.users.list = mock.Mock(
            return_value=[])
        self.image_mock = mock.Mock()

        self.fake_cloud = mock.Mock()
        self.fake_cloud.position = 'dst'

        self.fake_cloud.resources = dict(identity=self.identity_mock,
                                         image=self.image_mock)
        self.fake_cloud.mysql_connector = mock.MagicMock()

        self.glance_image = GlanceImage(FAKE_CONFIG, self.fake_cloud)

        self.fake_image_1 = mock.MagicMock()

        values_dict = {
            'id': 'fake_image_id_1',
            'name': 'fake_image_name_1',
            'status': 'active',
            'checksum': 'fake_shecksum_1',
            'owner': 'fake_tenant_id',
            'container_format': 'bare',
            'disk_format': 'qcow2',
            'is_public': True,
            'protected': False,
            'size': 1024,
            'properties': {},
            'deleted': False,
        }
        for k, w in values_dict.items():
            setattr(self.fake_image_1, k, w)
        self.fake_image_1.to_dict = mock.Mock(return_value=values_dict)
        self.fake_image_1.deleted = False

        self.fake_image_2 = mock.Mock()
        self.fake_image_2.name = 'fake_image_name_2'
        self.fake_image_2.deleted = False

        self.fake_input_info = {'images': {}}

        self.fake_result_info = {
            'images': {
                'fake_image_id_1': {'image': {'checksum': 'fake_shecksum_1',
                                              'container_format': 'bare',
                                              'disk_format': 'qcow2',
                                              'id': 'fake_image_id_1',
                                              'is_public': True,
                                              'location': None,
                                              'owner': 'fake_tenant_id',
                                              'owner_name': 'fake_tenant_name',
                                              'name': 'fake_image_name_1',
                                              'protected': False,
                                              'size': 1024,
                                              'resource': self.image_mock,
                                              'members': {},
                                              'properties': {},
                                              'copy_from': None,
                                              'min_disk': None,
                                              'min_ram': None,
                                              'store': None,
                                              'deleted': False},
                                    'meta': {'img_loc': None}}},
            'tags': {},
            'members': {}
        }
class GlanceImageTestCase(test.TestCase):

    def setUp(self):
        test.TestCase.setUp(self)

        self.glance_mock_client = mock.MagicMock()
        self.glance_mock_client().images.data()._resp = 'fake_resp_1'

        self.glance_client_patch = mockpatch.PatchObject(
            glance_client,
            'Client',
            new=self.glance_mock_client)
        self.useFixture(self.glance_client_patch)
        self.identity_mock = mock.Mock()
        self.identity_mock.get_endpoint_by_service_type = mock.Mock(
            return_value="http://192.168.1.2:9696/v2")
        fake_user = FakeUser()
        self.identity_mock.try_get_user_by_id = mock.Mock(
            return_value=fake_user)
        self.identity_mock.try_get_tenant_name_by_id = mock.Mock(
            return_value="fake_tenant_name")
        self.identity_mock.keystone_client.users.list = mock.Mock(
            return_value=[])
        self.image_mock = mock.Mock()

        self.fake_cloud = mock.Mock()
        self.fake_cloud.position = 'dst'

        self.fake_cloud.resources = dict(identity=self.identity_mock,
                                         image=self.image_mock)
        self.fake_cloud.mysql_connector = mock.MagicMock()

        self.glance_image = GlanceImage(FAKE_CONFIG, self.fake_cloud)

        self.fake_image_1 = mock.MagicMock()

        values_dict = {
            'id': 'fake_image_id_1',
            'name': 'fake_image_name_1',
            'status': 'active',
            'checksum': 'fake_shecksum_1',
            'owner': 'fake_tenant_id',
            'container_format': 'bare',
            'disk_format': 'qcow2',
            'is_public': True,
            'protected': False,
            'size': 1024,
            'properties': {},
            'deleted': False,
        }
        for k, w in values_dict.items():
            setattr(self.fake_image_1, k, w)
        self.fake_image_1.to_dict = mock.Mock(return_value=values_dict)
        self.fake_image_1.deleted = False

        self.fake_image_2 = mock.Mock()
        self.fake_image_2.name = 'fake_image_name_2'
        self.fake_image_2.deleted = False

        self.fake_input_info = {'images': {}}

        self.fake_result_info = {
            'images': {
                'fake_image_id_1': {'image': {'checksum': 'fake_shecksum_1',
                                              'container_format': 'bare',
                                              'disk_format': 'qcow2',
                                              'id': 'fake_image_id_1',
                                              'is_public': True,
                                              'location': None,
                                              'owner': 'fake_tenant_id',
                                              'owner_name': 'fake_tenant_name',
                                              'name': 'fake_image_name_1',
                                              'protected': False,
                                              'size': 1024,
                                              'resource': self.image_mock,
                                              'members': {},
                                              'properties': {},
                                              'copy_from': None,
                                              'min_disk': None,
                                              'min_ram': None,
                                              'store': None,
                                              'deleted': False},
                                    'meta': {'img_loc': None}}},
            'tags': {},
            'members': {}
        }

    def test_get_glance_client(self):
        fake_endpoint = 'fake_endpoint'
        fake_auth_token = 'fake_auth_token'
        self.identity_mock.get_endpoint_by_service_type.return_value = (
            fake_endpoint)
        self.identity_mock.get_auth_token_from_user.return_value = (
            fake_auth_token)

        gl_client = self.glance_image.get_client()
        mock_calls = [mock.call(endpoint=fake_endpoint, token=fake_auth_token,
                                insecure=FAKE_CONFIG.cloud.insecure)]

        self.glance_mock_client.assert_has_calls(mock_calls)
        self.assertEqual(self.glance_mock_client(), gl_client)

    def test_get_image_list(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        images_list = self.glance_image.get_image_list()
        self.glance_mock_client().images.list.assert_called_once_with(
            filters={'is_public': None})
        self.assertEquals(fake_images, images_list)

    def test_create_image(self):
        self.glance_image.create_image(name='fake_image_name',
                                       data='fake_data')
        test_args = {'name': 'fake_image_name',
                     'data': 'fake_data'}

        self.glance_mock_client().images.create.assert_called_once_with(
            **test_args)

    def test_delete_image(self):
        fake_image_id = 'fake_image_id_1'
        self.glance_image.delete_image(fake_image_id)

        self.glance_mock_client().images.update.assert_called_once_with(
            fake_image_id, protected=False)
        self.glance_mock_client().images.delete.assert_called_once_with(
            fake_image_id)

    def test_get_image_by_id(self):
        self.glance_mock_client().images.get.return_value = self.fake_image_1

        self.assertEquals(self.fake_image_1,
                          self.glance_image.get_image_by_id('fake_image_id_1'))

    def test_get_image_by_name(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals(
            self.fake_image_1,
            self.glance_image.get_image_by_name('fake_image_name_1'))

    def test_get_image(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals(self.fake_image_1,
                          self.glance_image.get_image('fake_image_id_1'))

        self.assertEquals(self.fake_image_2,
                          self.glance_image.get_image('fake_image_name_2'))

    def test_get_image_status(self):
        self.glance_mock_client().images.get.return_value = self.fake_image_1

        self.assertEquals(self.fake_image_1.status,
                          self.glance_image.get_image_status(
                              'fake_image_id_1'))

    def test_get_ref_image(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals('fake_resp_1',
                          self.glance_image.get_ref_image('fake_image_id_1'))

    def test_get_image_checksum(self):
        self.glance_mock_client().images.get.return_value = self.fake_image_1

        self.assertEquals(self.fake_image_1.checksum,
                          self.glance_image.get_image_checksum(
                              'fake_image_id_1'))

    def test_make_image_info(self):
        info = self.glance_image.make_image_info(self.fake_image_1,
                                                 self.fake_input_info)

        self.assertEqual({"images": self.fake_result_info["images"]}, info)

    def test_make_image_info_no_image(self):
        info = self.glance_image.make_image_info(self.fake_image_1,
                                                 self.fake_input_info)

        self.assertEqual(self.fake_input_info, info)

    def test_read_info_id(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        info = self.glance_image.read_info(image_id='fake_image_id_1')
        self.assertEqual(self.fake_result_info, info)

    def test_read_info_name(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        info = self.glance_image.read_info(image_name='fake_image_name_1')
        self.assertEqual(self.fake_result_info, info)

    def test_read_info_list(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        info = self.glance_image.read_info(images_list=['fake_image_name_1'])
        self.assertEqual(self.fake_result_info, info)

    def test_read_info_default(self):
        fake_images = [self.fake_image_1]
        self.glance_mock_client().images.list.return_value = fake_images

        info = self.glance_image.read_info()
        self.assertEqual(self.fake_result_info, info)

    def test_get_matching_image_positive_match_uuid(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        img = self.glance_image.get_matching_image(
            uuid=self.fake_image_1.id, checksum='mismatch_checksum',
            size=2048, name='mismatch_name')
        self.assertEqual(self.fake_image_1, img)

    def test_get_matching_image_positive_mismatch_uuid(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        img = self.glance_image.get_matching_image(
            uuid='mismatching', checksum=self.fake_image_1.checksum,
            size=self.fake_image_1.size, name=self.fake_image_1.name)
        self.assertEqual(self.fake_image_1, img)

    def test_get_matching_image_negative(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        img = self.glance_image.get_matching_image(
            uuid='mismatching', checksum='mismatch_checksum',
            size=2048, name='mismatch_name')
        self.assertEqual(None, img)
class GlanceImageTestCase(test.TestCase):
    def setUp(self):
        super(GlanceImageTestCase, self).setUp()

        self.glance_mock_client = mock.MagicMock()
        self.glance_mock_client().images.data()._resp = 'fake_resp_1'

        self.glance_client_patch = mockpatch.PatchObject(
            glance_client,
            'Client',
            new=self.glance_mock_client)
        self.useFixture(self.glance_client_patch)
        self.identity_mock = mock.Mock()
        self.image_mock = mock.Mock()

        self.fake_cloud = mock.Mock()
        self.fake_cloud.mysql_connector = mock.Mock()

        self.fake_cloud.resources = dict(identity=self.identity_mock,
                                         image=self.image_mock)
        self.glance_image = GlanceImage(FAKE_CONFIG, self.fake_cloud)

        self.fake_image_1 = mock.Mock()
        self.fake_image_1.id = 'fake_image_id_1'
        self.fake_image_1.name = 'fake_image_name_1'
        self.fake_image_1.status = 'fake_status_1'
        self.fake_image_1.checksum = 'fake_shecksum_1'
        self.fake_image_1.container_format = 'bare'
        self.fake_image_1.disk_format = 'qcow2'
        self.fake_image_1.is_public = True
        self.fake_image_1.protected = False
        self.fake_image_1.size = 1024
        self.fake_image_1.properties = 'fake_properties'

        self.fake_image_2 = mock.Mock()
        self.fake_image_2.name = 'fake_image_name_2'

        self.fake_input_info = {'images': {}}

        self.fake_result_info = {
            'images': {
                'fake_image_id_1': {'image': {'checksum': 'fake_shecksum_1',
                                              'container_format': 'bare',
                                              'disk_format': 'qcow2',
                                              'id': 'fake_image_id_1',
                                              'is_public': True,
                                              'name': 'fake_image_name_1',
                                              'protected': False,
                                              'size': 1024,
                                              'resource': self.image_mock,
                                              'properties': 'fake_properties'},
                                    'meta': {}}},
        }

    def test_get_glance_client(self):
        fake_endpoint = 'fake_endpoint'
        fake_auth_token = 'fake_auth_token'
        self.identity_mock.get_endpoint_by_service_name.return_value = (
            fake_endpoint)
        self.identity_mock.get_auth_token_from_user.return_value = (
            fake_auth_token)

        gl_client = self.glance_image.get_client()
        mock_calls = [mock.call(endpoint=fake_endpoint, token=fake_auth_token)]

        self.glance_mock_client.assert_has_calls(mock_calls)
        self.assertEqual(self.glance_mock_client(), gl_client)

    def test_get_image_list(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals(fake_images, self.glance_image.get_image_list())

    def test_create_image(self):
        self.glance_image.create_image(name='fake_image_name',
                                       data='fake_data')
        test_args = {'name': 'fake_image_name',
                     'data': 'fake_data'}

        self.glance_mock_client().images.create.assert_called_once_with(
            **test_args)

    def test_delete_image(self):
        fake_image_id = 'fake_image_id_1'
        self.glance_image.delete_image(fake_image_id)

        self.glance_mock_client().images.delete.assert_called_once_with(
            fake_image_id)

    def test_get_image_by_id(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals(self.fake_image_1,
                          self.glance_image.get_image_by_id('fake_image_id_1'))

    def test_get_image_by_name(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals(
            self.fake_image_1,
            self.glance_image.get_image_by_name('fake_image_name_1'))

    def test_get_image(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals(self.fake_image_1,
                          self.glance_image.get_image('fake_image_id_1'))

        self.assertEquals(self.fake_image_2,
                          self.glance_image.get_image('fake_image_name_2'))

    def test_get_image_status(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals(self.fake_image_1.status,
                          self.glance_image.get_image_status(
                              'fake_image_id_1'))

    def test_get_ref_image(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals('fake_resp_1',
                          self.glance_image.get_ref_image('fake_image_id_1'))

    def test_get_image_checksum(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals(self.fake_image_1.checksum,
                          self.glance_image.get_image_checksum(
                              'fake_image_id_1'))

    def test_make_image_info(self):
        info = self.glance_image.make_image_info(self.fake_image_1,
                                                 self.fake_input_info)

        self.assertEqual(self.fake_result_info, info)

    def test_make_image_info_no_image(self):
        info = self.glance_image.make_image_info(self.fake_image_1,
                                                 self.fake_input_info)

        self.assertEqual(self.fake_input_info, info)

    def test_read_info_id(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        info = self.glance_image.read_info(image_id='fake_image_id_1')
        self.assertEqual(self.fake_result_info, info)

    def test_read_info_name(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        info = self.glance_image.read_info(image_name='fake_image_name_1')
        self.assertEqual(self.fake_result_info, info)

    def test_read_info_list(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        info = self.glance_image.read_info(images_list=['fake_image_name_1'])
        self.assertEqual(self.fake_result_info, info)

    def test_read_info_default(self):
        fake_images = [self.fake_image_1]
        self.glance_mock_client().images.list.return_value = fake_images

        info = self.glance_image.read_info()
        self.assertEqual(self.fake_result_info, info)

    @mock.patch('cloudferrylib.os.image.glance_image.copy.deepcopy')
    @mock.patch('cloudferrylib.utils.file_like_proxy.FileLikeProxy')
    def test_deploy(self, mock_proxy, mock_copy):
        mock_copy.return_value = self.fake_result_info
        self.glance_mock_client().images.create.return_value = (
            self.fake_image_1)

        fake_images1 = [self.fake_image_2, mock.Mock()]
        fake_images2 = [self.fake_image_1, self.fake_image_2]
        fake_images3 = [self.fake_image_1]

        self.glance_mock_client().images.list.side_effect = (fake_images1,
                                                             fake_images2,
                                                             fake_images3)

        new_info = self.glance_image.deploy(self.fake_result_info)

        self.assertEqual(self.fake_result_info, new_info)
        mock_proxy.assert_called_once_with(
            self.fake_result_info['images']['fake_image_id_1']['image'],
            None,
            '10MB')
    def setUp(self):
        super(GlanceImageTestCase, self).setUp()

        self.glance_mock_client = mock.MagicMock()
        self.glance_mock_client().images.data()._resp = 'fake_resp_1'

        self.glance_client_patch = mockpatch.PatchObject(
            glance_client,
            'Client',
            new=self.glance_mock_client)
        self.useFixture(self.glance_client_patch)
        self.identity_mock = mock.Mock()
        self.identity_mock.get_endpoint_by_service_type = mock.Mock(
            return_value="http://192.168.1.2:9696/v2")
        fake_user = FakeUser()
        self.identity_mock.try_get_user_by_id = mock.Mock(
            return_value=fake_user)
        self.identity_mock.try_get_tenant_name_by_id = mock.Mock(
            return_value="fake_tenant_name")
        self.identity_mock.keystone_client.users.list = mock.Mock(
            return_value=[])
        self.image_mock = mock.Mock()

        self.fake_cloud = mock.Mock()
        self.fake_cloud.position = 'dst'

        self.fake_cloud.resources = dict(identity=self.identity_mock,
                                         image=self.image_mock)
        self.fake_cloud.mysql_connector = mock.MagicMock()

        self.glance_image = GlanceImage(FAKE_CONFIG, self.fake_cloud)

        self.fake_image_1 = mock.Mock()

        values_dict = {
            'id': 'fake_image_id_1',
            'name': 'fake_image_name_1',
            'status': 'active',
            'checksum': 'fake_shecksum_1',
            'owner': 'fake_tenant_id',
            'container_format': 'bare',
            'disk_format': 'qcow2',
            'is_public': True,
            'protected': False,
            'size': 1024,
            'properties': {},
        }
        for k, w in values_dict.items():
            setattr(self.fake_image_1, k, w)
        self.fake_image_1.to_dict = mock.Mock(return_value=values_dict)

        self.fake_image_2 = mock.Mock()
        self.fake_image_2.name = 'fake_image_name_2'

        self.fake_input_info = {'images': {}}

        self.fake_result_info = {
            'images': {
                'fake_image_id_1': {'image': {'checksum': 'fake_shecksum_1',
                                              'container_format': 'bare',
                                              'disk_format': 'qcow2',
                                              'id': 'fake_image_id_1',
                                              'is_public': True,
                                              'owner': 'fake_tenant_id',
                                              'owner_name': 'fake_tenant_name',
                                              'name': 'fake_image_name_1',
                                              'protected': False,
                                              'size': 1024,
                                              'resource': self.image_mock,
                                              'properties': {
                                                  'user_name': 'fake_user_name'
                                              }},
                                    'meta': {'img_loc': None}}},
            'tags': {},
            'members': {}
        }
class GlanceImageTestCase(test.TestCase):

    def setUp(self):
        super(GlanceImageTestCase, self).setUp()

        self.glance_mock_client = mock.MagicMock()
        self.glance_mock_client().images.data()._resp = 'fake_resp_1'

        self.glance_client_patch = mockpatch.PatchObject(
            glance_client,
            'Client',
            new=self.glance_mock_client)
        self.useFixture(self.glance_client_patch)
        self.identity_mock = mock.Mock()
        self.identity_mock.get_endpoint_by_service_type = mock.Mock(
            return_value="http://192.168.1.2:9696/v2")
        fake_user = FakeUser()
        self.identity_mock.try_get_user_by_id = mock.Mock(
            return_value=fake_user)
        self.identity_mock.try_get_tenant_name_by_id = mock.Mock(
            return_value="fake_tenant_name")
        self.identity_mock.keystone_client.users.list = mock.Mock(
            return_value=[])
        self.image_mock = mock.Mock()

        self.fake_cloud = mock.Mock()
        self.fake_cloud.position = 'dst'

        self.fake_cloud.resources = dict(identity=self.identity_mock,
                                         image=self.image_mock)
        self.fake_cloud.mysql_connector = mock.MagicMock()

        self.glance_image = GlanceImage(FAKE_CONFIG, self.fake_cloud)

        self.fake_image_1 = mock.Mock()

        values_dict = {
            'id': 'fake_image_id_1',
            'name': 'fake_image_name_1',
            'status': 'active',
            'checksum': 'fake_shecksum_1',
            'owner': 'fake_tenant_id',
            'container_format': 'bare',
            'disk_format': 'qcow2',
            'is_public': True,
            'protected': False,
            'size': 1024,
            'properties': {},
        }
        for k, w in values_dict.items():
            setattr(self.fake_image_1, k, w)
        self.fake_image_1.to_dict = mock.Mock(return_value=values_dict)

        self.fake_image_2 = mock.Mock()
        self.fake_image_2.name = 'fake_image_name_2'

        self.fake_input_info = {'images': {}}

        self.fake_result_info = {
            'images': {
                'fake_image_id_1': {'image': {'checksum': 'fake_shecksum_1',
                                              'container_format': 'bare',
                                              'disk_format': 'qcow2',
                                              'id': 'fake_image_id_1',
                                              'is_public': True,
                                              'owner': 'fake_tenant_id',
                                              'owner_name': 'fake_tenant_name',
                                              'name': 'fake_image_name_1',
                                              'protected': False,
                                              'size': 1024,
                                              'resource': self.image_mock,
                                              'properties': {
                                                  'user_name': 'fake_user_name'
                                              }},
                                    'meta': {'img_loc': None}}},
            'tags': {},
            'members': {}
        }

    def test_get_glance_client(self):
        fake_endpoint = 'fake_endpoint'
        fake_auth_token = 'fake_auth_token'
        self.identity_mock.get_endpoint_by_service_type.return_value = (
            fake_endpoint)
        self.identity_mock.get_auth_token_from_user.return_value = (
            fake_auth_token)

        gl_client = self.glance_image.get_client()
        mock_calls = [mock.call(endpoint=fake_endpoint, token=fake_auth_token)]

        self.glance_mock_client.assert_has_calls(mock_calls)
        self.assertEqual(self.glance_mock_client(), gl_client)

    def test_get_image_list(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        images_list = self.glance_image.get_image_list()
        self.glance_mock_client().images.list.assert_called_once_with(
            filters={'is_public': None})
        self.assertEquals(fake_images, images_list)

    def test_create_image(self):
        self.glance_image.create_image(name='fake_image_name',
                                       data='fake_data')
        test_args = {'name': 'fake_image_name',
                     'data': 'fake_data'}

        self.glance_mock_client().images.create.assert_called_once_with(
            **test_args)

    def test_delete_image(self):
        fake_image_id = 'fake_image_id_1'
        self.glance_image.delete_image(fake_image_id)

        self.glance_mock_client().images.delete.assert_called_once_with(
            fake_image_id)

    def test_get_image_by_id(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals(self.fake_image_1,
                          self.glance_image.get_image_by_id('fake_image_id_1'))

    def test_get_image_by_name(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals(
            self.fake_image_1,
            self.glance_image.get_image_by_name('fake_image_name_1'))

    def test_get_image(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals(self.fake_image_1,
                          self.glance_image.get_image('fake_image_id_1'))

        self.assertEquals(self.fake_image_2,
                          self.glance_image.get_image('fake_image_name_2'))

    def test_get_image_status(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals(self.fake_image_1.status,
                          self.glance_image.get_image_status(
                              'fake_image_id_1'))

    def test_get_ref_image(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals('fake_resp_1',
                          self.glance_image.get_ref_image('fake_image_id_1'))

    def test_get_image_checksum(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals(self.fake_image_1.checksum,
                          self.glance_image.get_image_checksum(
                              'fake_image_id_1'))

    def test_make_image_info(self):
        info = self.glance_image.make_image_info(self.fake_image_1,
                                                 self.fake_input_info)

        self.assertEqual({"images": self.fake_result_info["images"]}, info)

    def test_make_image_info_no_image(self):
        info = self.glance_image.make_image_info(self.fake_image_1,
                                                 self.fake_input_info)

        self.assertEqual(self.fake_input_info, info)

    def test_read_info_id(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        info = self.glance_image.read_info(image_id='fake_image_id_1')
        self.assertEqual(self.fake_result_info, info)

    def test_read_info_name(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        info = self.glance_image.read_info(image_name='fake_image_name_1')
        self.assertEqual(self.fake_result_info, info)

    def test_read_info_list(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        info = self.glance_image.read_info(images_list=['fake_image_name_1'])
        self.assertEqual(self.fake_result_info, info)

    def test_read_info_default(self):
        fake_images = [self.fake_image_1]
        self.glance_mock_client().images.list.return_value = fake_images

        info = self.glance_image.read_info()
        self.assertEqual(self.fake_result_info, info)
    def setUp(self):
        super(GlanceImageTestCase, self).setUp()

        self.glance_mock_client = mock.MagicMock()
        self.glance_mock_client().images.data()._resp = "fake_resp_1"

        self.glance_client_patch = mockpatch.PatchObject(glance_client, "Client", new=self.glance_mock_client)
        self.useFixture(self.glance_client_patch)
        self.identity_mock = mock.Mock()
        self.identity_mock.get_endpoint_by_service_type = mock.Mock(return_value="http://192.168.1.2:9696/v2")
        fake_user = FakeUser()
        self.identity_mock.try_get_user_by_id = mock.Mock(return_value=fake_user)
        self.identity_mock.try_get_tenant_name_by_id = mock.Mock(return_value="fake_tenant_name")
        self.identity_mock.keystone_client.users.list = mock.Mock(return_value=[])
        self.image_mock = mock.Mock()

        self.fake_cloud = mock.Mock()
        self.fake_cloud.position = "dst"

        self.fake_cloud.resources = dict(identity=self.identity_mock, image=self.image_mock)
        self.fake_cloud.mysql_connector = mock.MagicMock()

        self.glance_image = GlanceImage(FAKE_CONFIG, self.fake_cloud)

        self.fake_image_1 = mock.MagicMock()

        values_dict = {
            "id": "fake_image_id_1",
            "name": "fake_image_name_1",
            "status": "active",
            "checksum": "fake_shecksum_1",
            "owner": "fake_tenant_id",
            "container_format": "bare",
            "disk_format": "qcow2",
            "is_public": True,
            "protected": False,
            "size": 1024,
            "properties": {},
        }
        for k, w in values_dict.items():
            setattr(self.fake_image_1, k, w)
        self.fake_image_1.to_dict = mock.Mock(return_value=values_dict)

        self.fake_image_2 = mock.Mock()
        self.fake_image_2.name = "fake_image_name_2"

        self.fake_input_info = {"images": {}}

        self.fake_result_info = {
            "images": {
                "fake_image_id_1": {
                    "image": {
                        "checksum": "fake_shecksum_1",
                        "container_format": "bare",
                        "disk_format": "qcow2",
                        "id": "fake_image_id_1",
                        "is_public": True,
                        "owner": "fake_tenant_id",
                        "owner_name": "fake_tenant_name",
                        "name": "fake_image_name_1",
                        "protected": False,
                        "size": 1024,
                        "resource": self.image_mock,
                        "members": {},
                        "properties": {},
                    },
                    "meta": {"img_loc": None},
                }
            },
            "tags": {},
            "members": {},
        }
class GlanceImageTestCase(test.TestCase):
    def setUp(self):
        super(GlanceImageTestCase, self).setUp()

        self.glance_mock_client = mock.MagicMock()
        self.glance_mock_client().images.data()._resp = "fake_resp_1"

        self.glance_client_patch = mockpatch.PatchObject(glance_client, "Client", new=self.glance_mock_client)
        self.useFixture(self.glance_client_patch)
        self.identity_mock = mock.Mock()
        self.identity_mock.get_endpoint_by_service_type = mock.Mock(return_value="http://192.168.1.2:9696/v2")
        fake_user = FakeUser()
        self.identity_mock.try_get_user_by_id = mock.Mock(return_value=fake_user)
        self.identity_mock.try_get_tenant_name_by_id = mock.Mock(return_value="fake_tenant_name")
        self.identity_mock.keystone_client.users.list = mock.Mock(return_value=[])
        self.image_mock = mock.Mock()

        self.fake_cloud = mock.Mock()
        self.fake_cloud.position = "dst"

        self.fake_cloud.resources = dict(identity=self.identity_mock, image=self.image_mock)
        self.fake_cloud.mysql_connector = mock.MagicMock()

        self.glance_image = GlanceImage(FAKE_CONFIG, self.fake_cloud)

        self.fake_image_1 = mock.MagicMock()

        values_dict = {
            "id": "fake_image_id_1",
            "name": "fake_image_name_1",
            "status": "active",
            "checksum": "fake_shecksum_1",
            "owner": "fake_tenant_id",
            "container_format": "bare",
            "disk_format": "qcow2",
            "is_public": True,
            "protected": False,
            "size": 1024,
            "properties": {},
        }
        for k, w in values_dict.items():
            setattr(self.fake_image_1, k, w)
        self.fake_image_1.to_dict = mock.Mock(return_value=values_dict)

        self.fake_image_2 = mock.Mock()
        self.fake_image_2.name = "fake_image_name_2"

        self.fake_input_info = {"images": {}}

        self.fake_result_info = {
            "images": {
                "fake_image_id_1": {
                    "image": {
                        "checksum": "fake_shecksum_1",
                        "container_format": "bare",
                        "disk_format": "qcow2",
                        "id": "fake_image_id_1",
                        "is_public": True,
                        "owner": "fake_tenant_id",
                        "owner_name": "fake_tenant_name",
                        "name": "fake_image_name_1",
                        "protected": False,
                        "size": 1024,
                        "resource": self.image_mock,
                        "members": {},
                        "properties": {},
                    },
                    "meta": {"img_loc": None},
                }
            },
            "tags": {},
            "members": {},
        }

    def test_get_glance_client(self):
        fake_endpoint = "fake_endpoint"
        fake_auth_token = "fake_auth_token"
        self.identity_mock.get_endpoint_by_service_type.return_value = fake_endpoint
        self.identity_mock.get_auth_token_from_user.return_value = fake_auth_token

        gl_client = self.glance_image.get_client()
        mock_calls = [mock.call(endpoint=fake_endpoint, token=fake_auth_token)]

        self.glance_mock_client.assert_has_calls(mock_calls)
        self.assertEqual(self.glance_mock_client(), gl_client)

    def test_get_image_list(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        images_list = self.glance_image.get_image_list()
        self.glance_mock_client().images.list.assert_called_once_with(filters={"is_public": None})
        self.assertEquals(fake_images, images_list)

    def test_create_image(self):
        self.glance_image.create_image(name="fake_image_name", data="fake_data")
        test_args = {"name": "fake_image_name", "data": "fake_data"}

        self.glance_mock_client().images.create.assert_called_once_with(**test_args)

    def test_delete_image(self):
        fake_image_id = "fake_image_id_1"
        self.glance_image.delete_image(fake_image_id)

        self.glance_mock_client().images.update.assert_called_once_with(fake_image_id, protected=False)
        self.glance_mock_client().images.delete.assert_called_once_with(fake_image_id)

    def test_get_image_by_id(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals(self.fake_image_1, self.glance_image.get_image_by_id("fake_image_id_1"))

    def test_get_image_by_name(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals(self.fake_image_1, self.glance_image.get_image_by_name("fake_image_name_1"))

    def test_get_image(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals(self.fake_image_1, self.glance_image.get_image("fake_image_id_1"))

        self.assertEquals(self.fake_image_2, self.glance_image.get_image("fake_image_name_2"))

    def test_get_image_status(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals(self.fake_image_1.status, self.glance_image.get_image_status("fake_image_id_1"))

    def test_get_ref_image(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals("fake_resp_1", self.glance_image.get_ref_image("fake_image_id_1"))

    def test_get_image_checksum(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals(self.fake_image_1.checksum, self.glance_image.get_image_checksum("fake_image_id_1"))

    def test_make_image_info(self):
        info = self.glance_image.make_image_info(self.fake_image_1, self.fake_input_info)

        self.assertEqual({"images": self.fake_result_info["images"]}, info)

    def test_make_image_info_no_image(self):
        info = self.glance_image.make_image_info(self.fake_image_1, self.fake_input_info)

        self.assertEqual(self.fake_input_info, info)

    def test_read_info_id(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        info = self.glance_image.read_info(image_id="fake_image_id_1")
        self.assertEqual(self.fake_result_info, info)

    def test_read_info_name(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        info = self.glance_image.read_info(image_name="fake_image_name_1")
        self.assertEqual(self.fake_result_info, info)

    def test_read_info_list(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        info = self.glance_image.read_info(images_list=["fake_image_name_1"])
        self.assertEqual(self.fake_result_info, info)

    def test_read_info_default(self):
        fake_images = [self.fake_image_1]
        self.glance_mock_client().images.list.return_value = fake_images

        info = self.glance_image.read_info()
        self.assertEqual(self.fake_result_info, info)
Beispiel #12
0
class GlanceImageTestCase(test.TestCase):
    def setUp(self):
        super(GlanceImageTestCase, self).setUp()

        self.glance_mock_client = mock.MagicMock()
        self.glance_mock_client().images.data()._resp = 'fake_resp_1'

        self.glance_client_patch = mockpatch.PatchObject(
            glance_client, 'Client', new=self.glance_mock_client)
        self.useFixture(self.glance_client_patch)
        self.identity_mock = mock.Mock()
        self.image_mock = mock.Mock()

        self.fake_cloud = mock.Mock()
        self.fake_cloud.mysql_connector = mock.Mock()

        self.fake_cloud.resources = dict(identity=self.identity_mock,
                                         image=self.image_mock)
        self.glance_image = GlanceImage(FAKE_CONFIG, self.fake_cloud)

        self.fake_image_1 = mock.Mock()
        self.fake_image_1.id = 'fake_image_id_1'
        self.fake_image_1.name = 'fake_image_name_1'
        self.fake_image_1.status = 'fake_status_1'
        self.fake_image_1.checksum = 'fake_shecksum_1'
        self.fake_image_1.container_format = 'bare'
        self.fake_image_1.disk_format = 'qcow2'
        self.fake_image_1.is_public = True
        self.fake_image_1.protected = False
        self.fake_image_1.size = 1024
        self.fake_image_1.properties = 'fake_properties'

        self.fake_image_2 = mock.Mock()
        self.fake_image_2.name = 'fake_image_name_2'

        self.fake_input_info = {'images': {}}

        self.fake_result_info = {
            'images': {
                'fake_image_id_1': {
                    'image': {
                        'checksum': 'fake_shecksum_1',
                        'container_format': 'bare',
                        'disk_format': 'qcow2',
                        'id': 'fake_image_id_1',
                        'is_public': True,
                        'name': 'fake_image_name_1',
                        'protected': False,
                        'size': 1024,
                        'resource': self.image_mock,
                        'properties': 'fake_properties'
                    },
                    'meta': {}
                }
            },
        }

    def test_get_glance_client(self):
        fake_endpoint = 'fake_endpoint'
        fake_auth_token = 'fake_auth_token'
        self.identity_mock.get_endpoint_by_service_name.return_value = (
            fake_endpoint)
        self.identity_mock.get_auth_token_from_user.return_value = (
            fake_auth_token)

        gl_client = self.glance_image.get_client()
        mock_calls = [mock.call(endpoint=fake_endpoint, token=fake_auth_token)]

        self.glance_mock_client.assert_has_calls(mock_calls)
        self.assertEqual(self.glance_mock_client(), gl_client)

    def test_get_image_list(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals(fake_images, self.glance_image.get_image_list())

    def test_create_image(self):
        self.glance_image.create_image(name='fake_image_name',
                                       data='fake_data')
        test_args = {'name': 'fake_image_name', 'data': 'fake_data'}

        self.glance_mock_client().images.create.assert_called_once_with(
            **test_args)

    def test_delete_image(self):
        fake_image_id = 'fake_image_id_1'
        self.glance_image.delete_image(fake_image_id)

        self.glance_mock_client().images.delete.assert_called_once_with(
            fake_image_id)

    def test_get_image_by_id(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals(self.fake_image_1,
                          self.glance_image.get_image_by_id('fake_image_id_1'))

    def test_get_image_by_name(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals(
            self.fake_image_1,
            self.glance_image.get_image_by_name('fake_image_name_1'))

    def test_get_image(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals(self.fake_image_1,
                          self.glance_image.get_image('fake_image_id_1'))

        self.assertEquals(self.fake_image_2,
                          self.glance_image.get_image('fake_image_name_2'))

    def test_get_image_status(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals(
            self.fake_image_1.status,
            self.glance_image.get_image_status('fake_image_id_1'))

    def test_get_ref_image(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals('fake_resp_1',
                          self.glance_image.get_ref_image('fake_image_id_1'))

    def test_get_image_checksum(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        self.assertEquals(
            self.fake_image_1.checksum,
            self.glance_image.get_image_checksum('fake_image_id_1'))

    def test_make_image_info(self):
        info = self.glance_image.make_image_info(self.fake_image_1,
                                                 self.fake_input_info)

        self.assertEqual(self.fake_result_info, info)

    def test_make_image_info_no_image(self):
        info = self.glance_image.make_image_info(self.fake_image_1,
                                                 self.fake_input_info)

        self.assertEqual(self.fake_input_info, info)

    def test_read_info_id(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        info = self.glance_image.read_info(image_id='fake_image_id_1')
        self.assertEqual(self.fake_result_info, info)

    def test_read_info_name(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        info = self.glance_image.read_info(image_name='fake_image_name_1')
        self.assertEqual(self.fake_result_info, info)

    def test_read_info_list(self):
        fake_images = [self.fake_image_1, self.fake_image_2]
        self.glance_mock_client().images.list.return_value = fake_images

        info = self.glance_image.read_info(images_list=['fake_image_name_1'])
        self.assertEqual(self.fake_result_info, info)

    def test_read_info_default(self):
        fake_images = [self.fake_image_1]
        self.glance_mock_client().images.list.return_value = fake_images

        info = self.glance_image.read_info()
        self.assertEqual(self.fake_result_info, info)

    @mock.patch('cloudferrylib.os.image.glance_image.copy.deepcopy')
    @mock.patch('cloudferrylib.utils.file_like_proxy.FileLikeProxy')
    def test_deploy(self, mock_proxy, mock_copy):
        mock_copy.return_value = self.fake_result_info
        self.glance_mock_client().images.create.return_value = (
            self.fake_image_1)

        fake_images1 = [self.fake_image_2, mock.Mock()]
        fake_images2 = [self.fake_image_1, self.fake_image_2]
        fake_images3 = [self.fake_image_1]

        self.glance_mock_client().images.list.side_effect = (fake_images1,
                                                             fake_images2,
                                                             fake_images3)

        new_info = self.glance_image.deploy(self.fake_result_info)

        self.assertEqual(self.fake_result_info, new_info)
        mock_proxy.assert_called_once_with(
            self.fake_result_info['images']['fake_image_id_1']['image'], None,
            '10MB')