Debian Codegraph @

oslo_utils/tests/imageutils/test_qemu.py

raw symbols SCIP
1 # Copyright (C) 2012 Yahoo! Inc.
2 # All Rights Reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
14 # under the License.
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 # test for Bug #1996426
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)