コード例 #1
0
    def test_create_image_put_v2_bad_delete(self, mock_image_client,
                                            mock_is_client_version):
        mock_is_client_version.return_value = True
        self.cloud.image_api_use_tasks = False

        mock_image_client.get.return_value = []
        self.assertEqual([], self.cloud.list_images())

        args = {
            'name': '42 name',
            'container_format': 'bare',
            'disk_format': 'qcow2',
            'owner_specified.openstack.md5': mock.ANY,
            'owner_specified.openstack.sha256': mock.ANY,
            'owner_specified.openstack.object': 'images/42 name',
            'visibility': 'private',
            'min_disk': 0,
            'min_ram': 0
        }
        ret = munch.Munch(args.copy())
        ret['id'] = '42'
        ret['status'] = 'success'
        mock_image_client.get.side_effect = [
            [],
            [ret],
            [ret],
        ]
        mock_image_client.post.return_value = ret
        mock_image_client.put.side_effect = exc.OpenStackCloudHTTPError(
            "Some error", {})
        self.assertRaises(exc.OpenStackCloudHTTPError,
                          self._call_create_image,
                          '42 name',
                          min_disk='0',
                          min_ram=0)
        mock_image_client.post.assert_called_with('/images', json=args)
        mock_image_client.put.assert_called_with(
            '/images/42/file',
            headers={'Content-Type': 'application/octet-stream'},
            data=mock.ANY)
        mock_image_client.delete.assert_called_with('/images/42')
コード例 #2
0
    def test_create_image_put_v1_bad_delete(self, mock_image_client,
                                            mock_is_client_version):
        mock_is_client_version.return_value = False
        mock_image_client.get.return_value = []
        self.assertEqual([], self.cloud.list_images())

        args = {
            'name': '42 name',
            'container_format': 'bare',
            'disk_format': 'qcow2',
            'properties': {
                'owner_specified.openstack.md5': mock.ANY,
                'owner_specified.openstack.sha256': mock.ANY,
                'owner_specified.openstack.object': 'images/42 name',
                'is_public': False
            }
        }
        ret = munch.Munch(args.copy())
        ret['id'] = '42'
        ret['status'] = 'success'
        mock_image_client.get.side_effect = [
            [],
            [ret],
        ]
        mock_image_client.post.return_value = ret
        mock_image_client.put.side_effect = exc.OpenStackCloudHTTPError(
            "Some error", {})
        self.assertRaises(exc.OpenStackCloudHTTPError, self._call_create_image,
                          '42 name')
        mock_image_client.post.assert_called_with('/images', json=args)
        mock_image_client.put.assert_called_with(
            '/images/42',
            data=mock.ANY,
            headers={
                'x-image-meta-checksum': mock.ANY,
                'x-glance-registry-purge-props': 'false'
            })
        mock_image_client.delete.assert_called_with('/images/42')