| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
from oslo_utils import imageutils |
| 17 |
from oslo_utils.tests import base as test_base |
| 18 |
|
| 19 |
|
| 20 |
class QemuImgInfoTestCase(test_base.BaseTestCase): |
| 21 |
def test_qemu_img_unsupported(self): |
| 22 |
self.assertRaises( |
| 23 |
ValueError, imageutils.QemuImgInfo, '', format='human' |
| 24 |
) |
| 25 |
|
| 26 |
def test_qemu_img_info(self): |
| 27 |
img_output = '''{ |
| 28 |
"virtual-size": 41126400, |
| 29 |
"filename": "fake_img", |
| 30 |
"cluster-size": 65536, |
| 31 |
"format": "qcow2", |
| 32 |
"actual-size": 13168640, |
| 33 |
"format-specific": {"data": {"foo": "bar"}}, |
| 34 |
"encrypted": true |
| 35 |
}''' |
| 36 |
image_info = imageutils.QemuImgInfo(img_output, format='json') |
| 37 |
self.assertEqual(41126400, image_info.virtual_size) |
| 38 |
self.assertEqual('fake_img', image_info.image) |
| 39 |
self.assertEqual(65536, image_info.cluster_size) |
| 40 |
self.assertEqual('qcow2', image_info.file_format) |
| 41 |
self.assertEqual(13168640, image_info.disk_size) |
| 42 |
self.assertEqual("bar", image_info.format_specific["data"]["foo"]) |
| 43 |
self.assertEqual('yes', image_info.encrypted) |
| 44 |
|
| 45 |
expected_str = "format_specific: {'data': {'foo': 'bar'}}" |
| 46 |
self.assertIn(expected_str, str(image_info)) |
| 47 |
|
| 48 |
def test_qemu_img_info_blank(self): |
| 49 |
img_output = '{}' |
| 50 |
image_info = imageutils.QemuImgInfo(img_output, format='json') |
| 51 |
self.assertIsNone(image_info.virtual_size) |
| 52 |
self.assertIsNone(image_info.image) |
| 53 |
self.assertIsNone(image_info.cluster_size) |
| 54 |
self.assertIsNone(image_info.file_format) |
| 55 |
self.assertIsNone(image_info.disk_size) |
| 56 |
self.assertIsNone(image_info.format_specific) |
| 57 |
self.assertIsNone(image_info.encrypted) |