~ubuntu-branches/ubuntu/vivid/ironic/vivid-updates

« back to all changes in this revision

Viewing changes to ironic/tests/drivers/test_deploy_utils.py

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2015-01-05 12:21:37 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20150105122137-171bqrdpcxqipunk
Tags: 2015.1~b1-0ubuntu1
* New upstream beta release:
  - d/control: Align version requirements with upstream release.
* d/watch: Update uversionmangle to deal with kilo beta versioning
  changes.
* d/control: Bumped Standards-Version to 3.9.6, no changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
#    License for the specific language governing permissions and limitations
15
15
#    under the License.
16
16
 
 
17
import os
 
18
import tempfile
 
19
 
17
20
import fixtures
18
21
import mock
19
 
import os
20
 
import tempfile
21
 
 
22
22
from oslo.config import cfg
 
23
from oslo_concurrency import processutils
23
24
 
24
25
from ironic.common import disk_partitioner
25
26
from ironic.common import exception
 
27
from ironic.common import images
26
28
from ironic.common import utils as common_utils
27
29
from ironic.drivers.modules import deploy_utils as utils
28
30
from ironic.drivers.modules import image_cache
29
 
from ironic.openstack.common import processutils
30
31
from ironic.tests import base as tests_base
31
32
 
32
33
_PXECONF_DEPLOY = """
160
161
 
161
162
        name_list = ['get_dev', 'get_image_mb', 'discovery', 'login_iscsi',
162
163
                     'logout_iscsi', 'delete_iscsi', 'make_partitions',
163
 
                     'is_block_device', 'dd', 'mkswap', 'block_uuid',
164
 
                     'notify', 'destroy_disk_metadata']
 
164
                     'is_block_device', 'populate_image', 'mkswap',
 
165
                     'block_uuid', 'notify', 'destroy_disk_metadata']
165
166
        parent_mock = self._mock_calls(name_list)
166
167
        parent_mock.get_dev.return_value = dev
167
168
        parent_mock.get_image_mb.return_value = 1
180
181
                                                    commit=True),
181
182
                          mock.call.is_block_device(root_part),
182
183
                          mock.call.is_block_device(swap_part),
183
 
                          mock.call.dd(image_path, root_part),
 
184
                          mock.call.populate_image(image_path, root_part),
184
185
                          mock.call.mkswap(swap_part),
185
186
                          mock.call.block_uuid(root_part),
186
187
                          mock.call.logout_iscsi(address, port, iqn),
213
214
 
214
215
        name_list = ['get_dev', 'get_image_mb', 'discovery', 'login_iscsi',
215
216
                     'logout_iscsi', 'delete_iscsi', 'make_partitions',
216
 
                     'is_block_device', 'dd', 'block_uuid',
 
217
                     'is_block_device', 'populate_image', 'block_uuid',
217
218
                     'notify', 'destroy_disk_metadata']
218
219
        parent_mock = self._mock_calls(name_list)
219
220
        parent_mock.get_dev.return_value = dev
231
232
                                                    ephemeral_mb,
232
233
                                                    commit=True),
233
234
                          mock.call.is_block_device(root_part),
234
 
                          mock.call.dd(image_path, root_part),
 
235
                          mock.call.populate_image(image_path, root_part),
235
236
                          mock.call.block_uuid(root_part),
236
237
                          mock.call.logout_iscsi(address, port, iqn),
237
238
                          mock.call.delete_iscsi(address, port, iqn)]
265
266
 
266
267
        name_list = ['get_dev', 'get_image_mb', 'discovery', 'login_iscsi',
267
268
                     'logout_iscsi', 'delete_iscsi', 'make_partitions',
268
 
                     'is_block_device', 'dd', 'mkswap', 'block_uuid',
269
 
                     'notify', 'mkfs_ephemeral',
 
269
                     'is_block_device', 'populate_image', 'mkswap',
 
270
                     'block_uuid', 'notify', 'mkfs_ephemeral',
270
271
                     'destroy_disk_metadata']
271
272
        parent_mock = self._mock_calls(name_list)
272
273
        parent_mock.get_dev.return_value = dev
288
289
                          mock.call.is_block_device(root_part),
289
290
                          mock.call.is_block_device(swap_part),
290
291
                          mock.call.is_block_device(ephemeral_part),
291
 
                          mock.call.dd(image_path, root_part),
 
292
                          mock.call.populate_image(image_path, root_part),
292
293
                          mock.call.mkswap(swap_part),
293
294
                          mock.call.mkfs_ephemeral(ephemeral_part,
294
295
                                                   ephemeral_format),
325
326
 
326
327
        name_list = ['get_dev', 'get_image_mb', 'discovery', 'login_iscsi',
327
328
                     'logout_iscsi', 'delete_iscsi', 'make_partitions',
328
 
                     'is_block_device', 'dd', 'mkswap', 'block_uuid',
329
 
                     'notify', 'mkfs_ephemeral', 'get_dev_block_size']
 
329
                     'is_block_device', 'populate_image', 'mkswap',
 
330
                     'block_uuid', 'notify', 'mkfs_ephemeral',
 
331
                     'get_dev_block_size']
330
332
        parent_mock = self._mock_calls(name_list)
331
333
        parent_mock.get_dev.return_value = dev
332
334
        parent_mock.get_image_mb.return_value = 1
347
349
                          mock.call.is_block_device(root_part),
348
350
                          mock.call.is_block_device(swap_part),
349
351
                          mock.call.is_block_device(ephemeral_part),
350
 
                          mock.call.dd(image_path, root_part),
 
352
                          mock.call.populate_image(image_path, root_part),
351
353
                          mock.call.mkswap(swap_part),
352
354
                          mock.call.block_uuid(root_part),
353
355
                          mock.call.logout_iscsi(address, port, iqn),
469
471
        actual = utils.get_dev('1.2.3.4', 5678, 'iqn.fake', 9)
470
472
        self.assertEqual(expected, actual)
471
473
 
472
 
    def test_get_image_mb(self):
 
474
    @mock.patch.object(os.path, 'getsize')
 
475
    @mock.patch.object(images, 'converted_size')
 
476
    def test_get_image_mb(self, mock_csize, mock_getsize):
473
477
        mb = 1024 * 1024
474
 
        size = None
475
 
 
476
 
        def fake_getsize(path):
477
 
            return size
478
 
 
479
 
        self.useFixture(fixtures.MonkeyPatch('os.path.getsize', fake_getsize))
480
 
        size = 0
481
 
        self.assertEqual(0, utils.get_image_mb('x'))
482
 
        size = 1
483
 
        self.assertEqual(1, utils.get_image_mb('x'))
484
 
        size = mb
485
 
        self.assertEqual(1, utils.get_image_mb('x'))
486
 
        size = mb + 1
487
 
        self.assertEqual(2, utils.get_image_mb('x'))
 
478
 
 
479
        mock_getsize.return_value = 0
 
480
        mock_csize.return_value = 0
 
481
        self.assertEqual(0, utils.get_image_mb('x', False))
 
482
        self.assertEqual(0, utils.get_image_mb('x', True))
 
483
        mock_getsize.return_value = 1
 
484
        mock_csize.return_value = 1
 
485
        self.assertEqual(1, utils.get_image_mb('x', False))
 
486
        self.assertEqual(1, utils.get_image_mb('x', True))
 
487
        mock_getsize.return_value = mb
 
488
        mock_csize.return_value = mb
 
489
        self.assertEqual(1, utils.get_image_mb('x', False))
 
490
        self.assertEqual(1, utils.get_image_mb('x', True))
 
491
        mock_getsize.return_value = mb + 1
 
492
        mock_csize.return_value = mb + 1
 
493
        self.assertEqual(2, utils.get_image_mb('x', False))
 
494
        self.assertEqual(2, utils.get_image_mb('x', True))
488
495
 
489
496
 
490
497
@mock.patch.object(disk_partitioner.DiskPartitioner, 'commit', lambda _: None)
678
685
        mock_exec.assert_has_calls(expected_call)
679
686
 
680
687
 
 
688
@mock.patch.object(utils, 'dd')
 
689
@mock.patch.object(images, 'qemu_img_info')
 
690
@mock.patch.object(images, 'convert_image')
 
691
class PopulateImageTestCase(tests_base.TestCase):
 
692
 
 
693
    def setUp(self):
 
694
        super(PopulateImageTestCase, self).setUp()
 
695
 
 
696
    def test_populate_raw_image(self, mock_cg, mock_qinfo, mock_dd):
 
697
        type(mock_qinfo.return_value).file_format = mock.PropertyMock(
 
698
            return_value='raw')
 
699
        utils.populate_image('src', 'dst')
 
700
        mock_dd.assert_called_once_with('src', 'dst')
 
701
        self.assertFalse(mock_cg.called)
 
702
 
 
703
    def test_populate_qcow2_image(self, mock_cg, mock_qinfo, mock_dd):
 
704
        type(mock_qinfo.return_value).file_format = mock.PropertyMock(
 
705
            return_value='qcow2')
 
706
        utils.populate_image('src', 'dst')
 
707
        mock_cg.assert_called_once_with('src', 'dst', 'raw', True)
 
708
        self.assertFalse(mock_dd.called)
 
709
 
 
710
 
681
711
@mock.patch.object(utils, 'is_block_device', lambda d: True)
682
712
@mock.patch.object(utils, 'block_uuid', lambda p: 'uuid')
683
713
@mock.patch.object(utils, 'dd', lambda *_: None)
 
714
@mock.patch.object(images, 'convert_image', lambda *_: None)
684
715
@mock.patch.object(common_utils, 'mkfs', lambda *_: None)
685
716
# NOTE(dtantsur): destroy_disk_metadata resets file size, disabling it
686
717
@mock.patch.object(utils, 'destroy_disk_metadata', lambda *_: None)
760
791
        mock_clean_up_caches.assert_called_once_with(None, 'master_dir',
761
792
                                                     [('uuid', 'path')])
762
793
        mock_cache.fetch_image.assert_called_once_with('uuid', 'path',
763
 
                                                       ctx=None)
 
794
                                                       ctx=None,
 
795
                                                       force_raw=True)
764
796
 
765
797
    @mock.patch.object(image_cache, 'clean_up_caches')
766
798
    def test_fetch_images_fail(self, mock_clean_up_caches):