예제 #1
0
    def test_copy_volume_to_image(self):
        drv = self._driver

        vol = db_fakes.get_fake_volume_info()

        image_meta = db_fakes.get_fake_image_meta()

        self.stubs.Set(drv, 'local_path', self.fake_local_path)

        self.mox.StubOutWithMock(image_utils, 'upload_volume')

        temp_vhd_path = os.path.join(CONF.image_conversion_dir,
                                     str(image_meta['id']) + ".vhd")

        image_utils.upload_volume(None, None, image_meta, temp_vhd_path, 'vpc')

        self.mox.StubOutWithMock(windows_utils.WindowsUtils,
                                 'copy_vhd_disk')

        windows_utils.WindowsUtils.copy_vhd_disk(self.fake_local_path(vol),
                                                 temp_vhd_path)

        self.mox.ReplayAll()

        drv.copy_volume_to_image(None, vol, None, image_meta)
예제 #2
0
    def test_copy_volume_to_image(self):
        mox = self._mox
        drv = self._driver

        vol = db_fakes.get_fake_volume_info()

        image_meta = db_fakes.get_fake_image_meta()

        self.stubs.Set(drv, 'local_path', self.fake_local_path)

        mox.StubOutWithMock(image_utils, 'upload_volume')

        temp_vhd_path = os.path.join(CONF.image_conversion_dir,
                                     str(image_meta['id']) + ".vhd")

        image_utils.upload_volume(None, None, image_meta, temp_vhd_path, 'vpc')

        self._mox.StubOutWithMock(windows_utils.WindowsUtils,
                                  'copy_vhd_disk')

        windows_utils.WindowsUtils.copy_vhd_disk(self.fake_local_path(vol),
                                                 temp_vhd_path)

        mox.ReplayAll()

        drv.copy_volume_to_image(None, vol, None, image_meta)

        mox.VerifyAll()
예제 #3
0
    def test_create_cloned_volume(self):
        drv = self._driver

        volume = db_fakes.get_fake_volume_info()
        volume_cloned = db_fakes.get_fake_volume_info_cloned()
        new_vhd_path = self.fake_local_path(volume)
        src_vhd_path = self.fake_local_path(volume_cloned)

        self.mox.StubOutWithMock(windows_utils.WindowsUtils,
                                 'copy_vhd_disk')
        self.mox.StubOutWithMock(windows_utils.WindowsUtils,
                                 'import_wt_disk')
        self.mox.StubOutWithMock(vhdutils.VHDUtils,
                                 'resize_vhd')

        self.stubs.Set(drv.utils,
                       'is_resize_needed',
                       lambda vhd_path, new_size, old_size: True)
        self.stubs.Set(drv, 'local_path', self.fake_local_path)

        windows_utils.WindowsUtils.copy_vhd_disk(src_vhd_path,
                                                 new_vhd_path)
        drv.utils.is_resize_needed(new_vhd_path,
                                   volume['size'],
                                   volume_cloned['size'])
        vhdutils.VHDUtils.resize_vhd(new_vhd_path, volume['size'] << 30)
        windows_utils.WindowsUtils.import_wt_disk(new_vhd_path,
                                                  volume['name'])

        self.mox.ReplayAll()

        drv.create_cloned_volume(volume, volume_cloned)
예제 #4
0
    def test_initialize_connection(self):
        mox = self._mox
        drv = self._driver

        volume = db_fakes.get_fake_volume_info()
        initiator_name = "%s%s" % (CONF.iscsi_target_prefix, volume['name'])

        connector = db_fakes.get_fake_connector_info()

        self._mox.StubOutWithMock(windows_utils.WindowsUtils,
                                  'associate_initiator_with_iscsi_target')
        windows_utils.WindowsUtils.associate_initiator_with_iscsi_target(
            volume['provider_location'],
            initiator_name,
        )

        self._mox.StubOutWithMock(windows_utils.WindowsUtils,
                                  'get_host_information')
        windows_utils.WindowsUtils.get_host_information(
            volume, volume['provider_location'])

        mox.ReplayAll()

        drv.initialize_connection(volume, connector)

        mox.VerifyAll()
예제 #5
0
    def test_create_cloned_volume(self):
        drv = self._driver

        volume = db_fakes.get_fake_volume_info()
        volume_cloned = db_fakes.get_fake_volume_info_cloned()
        new_vhd_path = self.fake_local_path(volume)
        src_vhd_path = self.fake_local_path(volume_cloned)

        self.mox.StubOutWithMock(windows_utils.WindowsUtils, 'copy_vhd_disk')
        self.mox.StubOutWithMock(windows_utils.WindowsUtils, 'import_wt_disk')
        self.mox.StubOutWithMock(vhdutils.VHDUtils, 'resize_vhd')

        self.stubs.Set(drv.utils, 'is_resize_needed',
                       lambda vhd_path, new_size, old_size: True)
        self.stubs.Set(drv, 'local_path', self.fake_local_path)

        windows_utils.WindowsUtils.copy_vhd_disk(src_vhd_path, new_vhd_path)
        drv.utils.is_resize_needed(new_vhd_path, volume['size'],
                                   volume_cloned['size'])
        vhdutils.VHDUtils.resize_vhd(new_vhd_path, volume['size'] << 30)
        windows_utils.WindowsUtils.import_wt_disk(new_vhd_path, volume['name'])

        self.mox.ReplayAll()

        drv.create_cloned_volume(volume, volume_cloned)
예제 #6
0
    def test_create_volume_from_snapshot(self):
        #Create a volume
        self._create_volume()
        #Create a snapshot from the previous volume
        self._create_snapshot()

        self._volume_data_2 = db_fakes.get_fake_volume_info(self._volume_id_2)

        self._drv.create_volume_from_snapshot(self._volume_data_2,
                                              self._snapshot_data)

        wt_disks = self._wutils.find_vhd_by_name(self._volume_data_2['name'])
        self.assertEquals(len(wt_disks), 1)
예제 #7
0
    def test_create_volume_from_snapshot(self):
        #Create a volume
        self._create_volume()
        #Create a snapshot from the previous volume
        self._create_snapshot()

        self._volume_data_2 = db_fakes.get_fake_volume_info(self._volume_id_2)

        self._drv.create_volume_from_snapshot(self._volume_data_2,
                                              self._snapshot_data)

        wt_disks = self._wutils.find_vhd_by_name(self._volume_data_2['name'])
        self.assertEquals(len(wt_disks), 1)
예제 #8
0
    def test_remove_export(self):
        drv = self._driver

        volume = db_fakes.get_fake_volume_info()

        target_name = volume['provider_location']

        self.mox.StubOutWithMock(windows_utils.WindowsUtils,
                                 'remove_iscsi_target')
        windows_utils.WindowsUtils.remove_iscsi_target(target_name)

        self.mox.ReplayAll()

        drv.remove_export(None, volume)
예제 #9
0
    def test_create_volume_from_snapshot(self):
        drv = self._driver

        snapshot = db_fakes.get_fake_snapshot_info()
        volume = db_fakes.get_fake_volume_info()

        self.mox.StubOutWithMock(windows_utils.WindowsUtils,
                                 'create_volume_from_snapshot')
        windows_utils.WindowsUtils.\
            create_volume_from_snapshot(volume, snapshot['name'])

        self.mox.ReplayAll()

        drv.create_volume_from_snapshot(volume, snapshot)
예제 #10
0
    def test_create_volume_from_snapshot(self):
        drv = self._driver

        snapshot = db_fakes.get_fake_snapshot_info()
        volume = db_fakes.get_fake_volume_info()

        self.mox.StubOutWithMock(windows_utils.WindowsUtils,
                                 'create_volume_from_snapshot')
        windows_utils.WindowsUtils.\
            create_volume_from_snapshot(volume, snapshot['name'])

        self.mox.ReplayAll()

        drv.create_volume_from_snapshot(volume, snapshot)
예제 #11
0
    def test_remove_export(self):
        drv = self._driver

        volume = db_fakes.get_fake_volume_info()

        target_name = volume['provider_location']

        self.mox.StubOutWithMock(windows_utils.WindowsUtils,
                                 'remove_iscsi_target')
        windows_utils.WindowsUtils.remove_iscsi_target(target_name)

        self.mox.ReplayAll()

        drv.remove_export(None, volume)
예제 #12
0
    def test_create_snapshot(self):
        drv = self._driver
        self.mox.StubOutWithMock(windows_utils.WindowsUtils, 'create_snapshot')
        volume = db_fakes.get_fake_volume_info()
        snapshot = db_fakes.get_fake_snapshot_info()

        self.stubs.Set(drv, 'local_path', self.fake_local_path(snapshot))

        windows_utils.WindowsUtils.create_snapshot(volume['name'],
                                                   snapshot['name'])

        self.mox.ReplayAll()

        drv.create_snapshot(snapshot)
예제 #13
0
    def test_create_volume(self):
        drv = self._driver
        vol = db_fakes.get_fake_volume_info()

        self.stubs.Set(drv, 'local_path', self.fake_local_path)

        self.mox.StubOutWithMock(windows_utils.WindowsUtils, 'create_volume')

        windows_utils.WindowsUtils.create_volume(self.fake_local_path(vol),
                                                 vol['name'], vol['size'])

        self.mox.ReplayAll()

        drv.create_volume(vol)
예제 #14
0
    def test_terminate_connection(self):
        drv = self._driver

        volume = db_fakes.get_fake_volume_info()
        initiator_name = "%s%s" % (CONF.iscsi_target_prefix, volume['name'])
        connector = db_fakes.get_fake_connector_info()

        self.mox.StubOutWithMock(windows_utils.WindowsUtils,
                                 'delete_iscsi_target')
        windows_utils.WindowsUtils.delete_iscsi_target(
            initiator_name, volume['provider_location'])

        self.mox.ReplayAll()

        drv.terminate_connection(volume, connector)
예제 #15
0
    def test_delete_volume(self):
        """delete_volume simple test case."""
        drv = self._driver

        vol = db_fakes.get_fake_volume_info()

        self.mox.StubOutWithMock(drv, 'local_path')
        drv.local_path(vol).AndReturn(self.fake_local_path(vol))

        self.mox.StubOutWithMock(windows_utils.WindowsUtils, 'delete_volume')
        windows_utils.WindowsUtils.delete_volume(vol['name'],
                                                 self.fake_local_path(vol))
        self.mox.ReplayAll()

        drv.delete_volume(vol)
예제 #16
0
    def test_create_volume(self):
        drv = self._driver
        vol = db_fakes.get_fake_volume_info()

        self.stubs.Set(drv, 'local_path', self.fake_local_path)

        self.mox.StubOutWithMock(windows_utils.WindowsUtils,
                                 'create_volume')

        windows_utils.WindowsUtils.create_volume(self.fake_local_path(vol),
                                                 vol['name'], vol['size'])

        self.mox.ReplayAll()

        drv.create_volume(vol)
예제 #17
0
    def test_terminate_connection(self):
        drv = self._driver

        volume = db_fakes.get_fake_volume_info()
        initiator_name = "%s%s" % (CONF.iscsi_target_prefix, volume['name'])
        connector = db_fakes.get_fake_connector_info()

        self.mox.StubOutWithMock(windows_utils.WindowsUtils,
                                 'delete_iscsi_target')
        windows_utils.WindowsUtils.delete_iscsi_target(
            initiator_name, volume['provider_location'])

        self.mox.ReplayAll()

        drv.terminate_connection(volume, connector)
예제 #18
0
    def test_create_snapshot(self):
        drv = self._driver
        self.mox.StubOutWithMock(windows_utils.WindowsUtils,
                                 'create_snapshot')
        volume = db_fakes.get_fake_volume_info()
        snapshot = db_fakes.get_fake_snapshot_info()

        self.stubs.Set(drv, 'local_path', self.fake_local_path(snapshot))

        windows_utils.WindowsUtils.create_snapshot(volume['name'],
                                                   snapshot['name'])

        self.mox.ReplayAll()

        drv.create_snapshot(snapshot)
예제 #19
0
    def test_copy_image_to_volume(self):
        """resize_image common case usage."""
        drv = self._driver

        volume = db_fakes.get_fake_volume_info()

        self.stubs.Set(drv, 'local_path', self.fake_local_path)

        self.mox.StubOutWithMock(image_utils, 'fetch_to_vhd')
        image_utils.fetch_to_vhd(None, None, None,
                                 self.fake_local_path(volume), mox.IgnoreArg())

        self.mox.ReplayAll()

        drv.copy_image_to_volume(None, volume, None, None)
예제 #20
0
    def test_delete_volume(self):
        """delete_volume simple test case."""
        drv = self._driver

        vol = db_fakes.get_fake_volume_info()

        self.mox.StubOutWithMock(drv, 'local_path')
        drv.local_path(vol).AndReturn(self.fake_local_path(vol))

        self.mox.StubOutWithMock(windows_utils.WindowsUtils,
                                 'delete_volume')
        windows_utils.WindowsUtils.delete_volume(vol['name'],
                                                 self.fake_local_path(vol))
        self.mox.ReplayAll()

        drv.delete_volume(vol)
예제 #21
0
    def test_copy_image_to_volume(self):
        """resize_image common case usage."""
        drv = self._driver

        volume = db_fakes.get_fake_volume_info()

        self.stubs.Set(drv, 'local_path', self.fake_local_path)

        self.mox.StubOutWithMock(image_utils, 'fetch_to_vhd')
        image_utils.fetch_to_vhd(None, None, None,
                                 self.fake_local_path(volume),
                                 mox.IgnoreArg())

        self.mox.ReplayAll()

        drv.copy_image_to_volume(None, volume, None, None)
예제 #22
0
    def test_copy_image_to_volume(self):
        """resize_image common case usage."""
        drv = self._driver

        volume = db_fakes.get_fake_volume_info()

        fake_get_supported_type = lambda x: constants.VHD_TYPE_FIXED
        self.stubs.Set(drv, 'local_path', self.fake_local_path)
        self.stubs.Set(windows_utils.WindowsUtils, 'get_supported_vhd_type',
                       fake_get_supported_type)

        self.mox.StubOutWithMock(os, 'makedirs')
        self.mox.StubOutWithMock(os, 'unlink')
        self.mox.StubOutWithMock(image_utils, 'create_temporary_file')
        self.mox.StubOutWithMock(image_utils, 'fetch_to_vhd')
        self.mox.StubOutWithMock(vhdutils.VHDUtils, 'convert_vhd')
        self.mox.StubOutWithMock(vhdutils.VHDUtils, 'resize_vhd')
        self.mox.StubOutWithMock(windows_utils.WindowsUtils,
                                 'change_disk_status')

        fake_temp_path = r'C:\fake\temp\file'
        if (CONF.image_conversion_dir and not
                os.path.exists(CONF.image_conversion_dir)):
            os.makedirs(CONF.image_conversion_dir)
        image_utils.create_temporary_file(suffix='.vhd').AndReturn(
            fake_temp_path)

        fake_volume_path = self.fake_local_path(volume)

        image_utils.fetch_to_vhd(None, None, None,
                                 fake_temp_path,
                                 mox.IgnoreArg())
        windows_utils.WindowsUtils.change_disk_status(volume['name'],
                                                      mox.IsA(bool))
        os.unlink(mox.IsA(str))
        vhdutils.VHDUtils.convert_vhd(fake_temp_path,
                                      fake_volume_path,
                                      constants.VHD_TYPE_FIXED)
        vhdutils.VHDUtils.resize_vhd(fake_volume_path,
                                     volume['size'] << 30)
        windows_utils.WindowsUtils.change_disk_status(volume['name'],
                                                      mox.IsA(bool))
        os.unlink(mox.IsA(str))

        self.mox.ReplayAll()

        drv.copy_image_to_volume(None, volume, None, None)
예제 #23
0
    def test_copy_image_to_volume(self):
        """resize_image common case usage."""
        drv = self._driver

        volume = db_fakes.get_fake_volume_info()

        fake_get_supported_type = lambda x: constants.VHD_TYPE_FIXED
        self.stubs.Set(drv, 'local_path', self.fake_local_path)
        self.stubs.Set(windows_utils.WindowsUtils, 'get_supported_vhd_type',
                       fake_get_supported_type)

        self.mox.StubOutWithMock(os, 'makedirs')
        self.mox.StubOutWithMock(os, 'unlink')
        self.mox.StubOutWithMock(image_utils, 'create_temporary_file')
        self.mox.StubOutWithMock(image_utils, 'fetch_to_vhd')
        self.mox.StubOutWithMock(vhdutils.VHDUtils, 'convert_vhd')
        self.mox.StubOutWithMock(vhdutils.VHDUtils, 'resize_vhd')
        self.mox.StubOutWithMock(windows_utils.WindowsUtils,
                                 'change_disk_status')

        fake_temp_path = r'C:\fake\temp\file'
        if (CONF.image_conversion_dir and not
                os.path.exists(CONF.image_conversion_dir)):
            os.makedirs(CONF.image_conversion_dir)
        image_utils.create_temporary_file(suffix='.vhd').AndReturn(
            fake_temp_path)

        fake_volume_path = self.fake_local_path(volume)

        image_utils.fetch_to_vhd(None, None, None,
                                 fake_temp_path,
                                 mox.IgnoreArg())
        windows_utils.WindowsUtils.change_disk_status(volume['name'],
                                                      mox.IsA(bool))
        os.unlink(mox.IsA(str))
        vhdutils.VHDUtils.convert_vhd(fake_temp_path,
                                      fake_volume_path,
                                      constants.VHD_TYPE_FIXED)
        vhdutils.VHDUtils.resize_vhd(fake_volume_path,
                                     volume['size'] << 30)
        windows_utils.WindowsUtils.change_disk_status(volume['name'],
                                                      mox.IsA(bool))
        os.unlink(mox.IsA(str))

        self.mox.ReplayAll()

        drv.copy_image_to_volume(None, volume, None, None)
예제 #24
0
    def test_remove_export(self):
        mox = self._mox
        drv = self._driver

        volume = db_fakes.get_fake_volume_info()

        target_name = volume['provider_location']

        self._mox.StubOutWithMock(windows_common.WindowsCommon,
                                  'remove_iscsi_target')
        windows_common.WindowsCommon.remove_iscsi_target(target_name)

        mox.ReplayAll()

        drv.remove_export(None, volume)

        mox.VerifyAll()
예제 #25
0
    def test_create_volume_from_snapshot(self):
        mox = self._mox
        drv = self._driver

        snapshot = db_fakes.get_fake_snapshot_info()
        volume = db_fakes.get_fake_volume_info()

        self._mox.StubOutWithMock(windows_common.WindowsCommon,
                                  'create_volume_from_snapshot')
        windows_common.WindowsCommon.\
            create_volume_from_snapshot(volume['name'], snapshot['name'])

        mox.ReplayAll()

        drv.create_volume_from_snapshot(volume, snapshot)

        mox.VerifyAll()
예제 #26
0
    def test_extend_volume(self):
        drv = self._driver

        volume = db_fakes.get_fake_volume_info()

        TEST_VOLUME_ADDITIONAL_SIZE_MB = 1024
        TEST_VOLUME_ADDITIONAL_SIZE_GB = 1

        self.mox.StubOutWithMock(windows_utils.WindowsUtils, 'extend')

        windows_utils.WindowsUtils.extend(volume['name'],
                                          TEST_VOLUME_ADDITIONAL_SIZE_MB)

        new_size = volume['size'] + TEST_VOLUME_ADDITIONAL_SIZE_GB

        self.mox.ReplayAll()

        drv.extend_volume(volume, new_size)
예제 #27
0
    def test_extend_volume(self):
        drv = self._driver

        volume = db_fakes.get_fake_volume_info()

        TEST_VOLUME_ADDITIONAL_SIZE_MB = 1024
        TEST_VOLUME_ADDITIONAL_SIZE_GB = 1

        self.mox.StubOutWithMock(windows_utils.WindowsUtils, 'extend')

        windows_utils.WindowsUtils.extend(volume['name'],
                                          TEST_VOLUME_ADDITIONAL_SIZE_MB)

        new_size = volume['size'] + TEST_VOLUME_ADDITIONAL_SIZE_GB

        self.mox.ReplayAll()

        drv.extend_volume(volume, new_size)
예제 #28
0
    def test_copy_image_to_volume(self):
        """resize_image common case usage."""
        mox = self._mox
        drv = self._driver

        volume = db_fakes.get_fake_volume_info()

        self.stubs.Set(drv, 'local_path', self.fake_local_path)

        self._mox.StubOutWithMock(windows_common.WindowsCommon,
                                  'fetch_to_vhd')
        windows_common.WindowsCommon.fetch_to_vhd(None, None, None,
                                                  self.fake_local_path(volume))
        mox.ReplayAll()

        drv.copy_image_to_volume(None, volume, None, None)

        mox.VerifyAll()
예제 #29
0
    def test_ensure_export(self):
        drv = self._driver

        volume = db_fakes.get_fake_volume_info()

        initiator_name = "%s%s" % (CONF.iscsi_target_prefix, volume['name'])

        self.mox.StubOutWithMock(windows_utils.WindowsUtils,
                                 'create_iscsi_target')
        windows_utils.WindowsUtils.create_iscsi_target(initiator_name, True)
        self.mox.StubOutWithMock(windows_utils.WindowsUtils,
                                 'add_disk_to_target')
        windows_utils.WindowsUtils.add_disk_to_target(volume['name'],
                                                      initiator_name)

        self.mox.ReplayAll()

        drv.ensure_export(None, volume)
예제 #30
0
    def test_ensure_export(self):
        drv = self._driver

        volume = db_fakes.get_fake_volume_info()

        initiator_name = "%s%s" % (CONF.iscsi_target_prefix, volume['name'])

        self.mox.StubOutWithMock(windows_utils.WindowsUtils,
                                 'create_iscsi_target')
        windows_utils.WindowsUtils.create_iscsi_target(initiator_name, True)
        self.mox.StubOutWithMock(windows_utils.WindowsUtils,
                                 'add_disk_to_target')
        windows_utils.WindowsUtils.add_disk_to_target(volume['name'],
                                                      initiator_name)

        self.mox.ReplayAll()

        drv.ensure_export(None, volume)
예제 #31
0
    def test_create_snapshot(self):
        mox = self._mox
        drv = self._driver
        self._mox.StubOutWithMock(windows_common.WindowsCommon,
                                  'create_snapshot')
        volume = db_fakes.get_fake_volume_info()
        snapshot = db_fakes.get_fake_snapshot_info()

        self.stubs.Set(drv, 'local_path', self.fake_local_path(snapshot))

        windows_common.WindowsCommon.create_snapshot(volume['name'],
                                                     snapshot['name'])

        mox.ReplayAll()

        drv.create_snapshot(snapshot)

        mox.VerifyAll()
예제 #32
0
    def test_delete_volume(self):
        """delete_volume simple test case."""
        mox = self._mox
        drv = self._driver

        volume = db_fakes.get_fake_volume_info()

        mox.StubOutWithMock(drv, 'local_path')
        drv.local_path(volume).AndReturn(self.fake_local_path(volume))

        self._mox.StubOutWithMock(windows_common.WindowsCommon,
                                  'delete_volume')
        windows_common.WindowsCommon.delete_volume(volume['name'],
                                                   self.fake_local_path(volume))
        mox.ReplayAll()

        drv.delete_volume(volume)

        mox.VerifyAll()
예제 #33
0
    def test_create_cloned_volume(self):
        drv = self._driver

        volume = db_fakes.get_fake_volume_info()
        volume_cloned = db_fakes.get_fake_volume_info_cloned()

        self.mox.StubOutWithMock(windows_utils.WindowsUtils, 'create_volume')

        windows_utils.WindowsUtils.create_volume(mox.IgnoreArg(),
                                                 mox.IgnoreArg(),
                                                 mox.IgnoreArg())

        self.mox.StubOutWithMock(windows_utils.WindowsUtils, 'copy_vhd_disk')
        windows_utils.WindowsUtils.copy_vhd_disk(
            self.fake_local_path(volume_cloned), self.fake_local_path(volume))

        self.mox.ReplayAll()

        drv.create_cloned_volume(volume, volume_cloned)
예제 #34
0
    def test_create_volume(self):
        mox = self._mox
        drv = self._driver
        volume = db_fakes.get_fake_volume_info()

        self.stubs.Set(drv, 'local_path', self.fake_local_path)

        self._mox.StubOutWithMock(windows_common.WindowsCommon,
                                  'create_volume')

        windows_common.WindowsCommon.create_volume(self.fake_local_path(volume),
                                                   volume['name'],
                                                   volume['size'])

        mox.ReplayAll()

        drv.create_volume(volume)

        mox.VerifyAll()
예제 #35
0
    def test_copy_volume_to_image(self):
        mox = self._mox
        drv = self._driver

        volume = db_fakes.get_fake_volume_info()

        self.stubs.Set(drv, 'local_path', self.fake_local_path)

        self._mox.StubOutWithMock(windows_common.WindowsCommon,
                                  'upload_volume')

        windows_common.WindowsCommon.upload_volume(None, None, None,
                                                   self.fake_local_path(volume))

        mox.ReplayAll()

        drv.copy_volume_to_image(None, volume, None, None)

        mox.VerifyAll()
예제 #36
0
    def _test_copy_volume_to_image(self, supported_format):
        drv = self._driver

        vol = db_fakes.get_fake_volume_info()

        image_meta = db_fakes.get_fake_image_meta()

        fake_get_supported_format = lambda x: supported_format

        self.stubs.Set(os.path, 'exists', lambda x: False)
        self.stubs.Set(drv, 'local_path', self.fake_local_path)
        self.stubs.Set(windows_utils.WindowsUtils, 'get_supported_format',
                       fake_get_supported_format)

        self.mox.StubOutWithMock(fileutils, 'ensure_tree')
        self.mox.StubOutWithMock(fileutils, 'delete_if_exists')
        self.mox.StubOutWithMock(image_utils, 'upload_volume')
        self.mox.StubOutWithMock(windows_utils.WindowsUtils, 'copy_vhd_disk')
        self.mox.StubOutWithMock(vhdutils.VHDUtils, 'convert_vhd')

        fileutils.ensure_tree(CONF.image_conversion_dir)
        temp_vhd_path = os.path.join(CONF.image_conversion_dir,
                                     str(image_meta['id']) + "." +
                                     supported_format)
        upload_image = temp_vhd_path

        windows_utils.WindowsUtils.copy_vhd_disk(self.fake_local_path(vol),
                                                 temp_vhd_path)
        if supported_format == 'vhdx':
            upload_image = upload_image[:-1]
            vhdutils.VHDUtils.convert_vhd(temp_vhd_path, upload_image,
                                          constants.VHD_TYPE_DYNAMIC)

        image_utils.upload_volume(None, None, image_meta, upload_image, 'vhd')

        fileutils.delete_if_exists(temp_vhd_path)
        fileutils.delete_if_exists(upload_image)

        self.mox.ReplayAll()

        drv.copy_volume_to_image(None, vol, None, image_meta)
예제 #37
0
    def _test_copy_volume_to_image(self, supported_format):
        drv = self._driver

        vol = db_fakes.get_fake_volume_info()

        image_meta = db_fakes.get_fake_image_meta()

        fake_get_supported_format = lambda x: supported_format

        self.stubs.Set(os.path, 'exists', lambda x: False)
        self.stubs.Set(drv, 'local_path', self.fake_local_path)
        self.stubs.Set(windows_utils.WindowsUtils, 'get_supported_format',
                       fake_get_supported_format)

        self.mox.StubOutWithMock(fileutils, 'ensure_tree')
        self.mox.StubOutWithMock(fileutils, 'delete_if_exists')
        self.mox.StubOutWithMock(image_utils, 'upload_volume')
        self.mox.StubOutWithMock(windows_utils.WindowsUtils, 'copy_vhd_disk')
        self.mox.StubOutWithMock(vhdutils.VHDUtils, 'convert_vhd')

        fileutils.ensure_tree(CONF.image_conversion_dir)
        temp_vhd_path = os.path.join(
            CONF.image_conversion_dir,
            str(image_meta['id']) + "." + supported_format)
        upload_image = temp_vhd_path

        windows_utils.WindowsUtils.copy_vhd_disk(self.fake_local_path(vol),
                                                 temp_vhd_path)
        if supported_format == 'vhdx':
            upload_image = upload_image[:-1]
            vhdutils.VHDUtils.convert_vhd(temp_vhd_path, upload_image,
                                          constants.VHD_TYPE_DYNAMIC)

        image_utils.upload_volume(None, None, image_meta, upload_image, 'vhd')

        fileutils.delete_if_exists(temp_vhd_path)
        fileutils.delete_if_exists(upload_image)

        self.mox.ReplayAll()

        drv.copy_volume_to_image(None, vol, None, image_meta)
예제 #38
0
    def test_initialize_connection(self):
        drv = self._driver

        volume = db_fakes.get_fake_volume_info()
        initiator_name = "%s%s" % (CONF.iscsi_target_prefix, volume['name'])

        connector = db_fakes.get_fake_connector_info()

        self.mox.StubOutWithMock(windows_utils.WindowsUtils,
                                 'associate_initiator_with_iscsi_target')
        windows_utils.WindowsUtils.associate_initiator_with_iscsi_target(
            volume['provider_location'], initiator_name, )

        self.mox.StubOutWithMock(windows_utils.WindowsUtils,
                                 'get_host_information')
        windows_utils.WindowsUtils.get_host_information(
            volume, volume['provider_location'])

        self.mox.ReplayAll()

        drv.initialize_connection(volume, connector)
예제 #39
0
    def test_create_export(self):
        drv = self._driver

        volume = db_fakes.get_fake_volume_info()

        initiator_name = "%s%s" % (CONF.iscsi_target_prefix, volume['name'])

        self.mox.StubOutWithMock(windows_utils.WindowsUtils,
                                 'create_iscsi_target')
        windows_utils.WindowsUtils.create_iscsi_target(initiator_name,
                                                       mox.IgnoreArg())
        self.mox.StubOutWithMock(windows_utils.WindowsUtils,
                                 'add_disk_to_target')
        windows_utils.WindowsUtils.add_disk_to_target(volume['name'],
                                                      initiator_name)

        self.mox.ReplayAll()

        export_info = drv.create_export(None, volume)

        self.assertEqual(export_info['provider_location'], initiator_name)
예제 #40
0
    def test_create_cloned_volume(self):
        drv = self._driver

        volume = db_fakes.get_fake_volume_info()
        volume_cloned = db_fakes.get_fake_volume_info_cloned()

        self.mox.StubOutWithMock(windows_utils.WindowsUtils,
                                 'create_volume')

        windows_utils.WindowsUtils.create_volume(mox.IgnoreArg(),
                                                 mox.IgnoreArg(),
                                                 mox.IgnoreArg())

        self.mox.StubOutWithMock(windows_utils.WindowsUtils,
                                 'copy_vhd_disk')
        windows_utils.WindowsUtils.copy_vhd_disk(self.fake_local_path(
            volume_cloned), self.fake_local_path(volume))

        self.mox.ReplayAll()

        drv.create_cloned_volume(volume, volume_cloned)
예제 #41
0
    def test_create_export(self):
        drv = self._driver

        volume = db_fakes.get_fake_volume_info()

        initiator_name = "%s%s" % (CONF.iscsi_target_prefix, volume['name'])

        self.mox.StubOutWithMock(windows_utils.WindowsUtils,
                                 'create_iscsi_target')
        windows_utils.WindowsUtils.create_iscsi_target(initiator_name,
                                                       mox.IgnoreArg())
        self.mox.StubOutWithMock(windows_utils.WindowsUtils,
                                 'add_disk_to_target')
        windows_utils.WindowsUtils.add_disk_to_target(volume['name'],
                                                      initiator_name)

        self.mox.ReplayAll()

        export_info = drv.create_export(None, volume)

        self.assertEqual(export_info['provider_location'], initiator_name)
예제 #42
0
    def test_create_cloned_volume(self):
        mox = self._mox
        drv = self._driver

        volume = db_fakes.get_fake_volume_info()
        volume_cloned = db_fakes.get_fake_volume_info_cloned()

        self._mox.StubOutWithMock(windows_common.WindowsCommon, 'create_volume')

        windows_common.WindowsCommon.create_volume(IgnoreArg(), IgnoreArg(),
                                                   IgnoreArg())

        self._mox.StubOutWithMock(windows_common.WindowsCommon,
                                  'copy_vhd_disk')
        windows_common.WindowsCommon.copy_vhd_disk(self.fake_local_path(
            volume_cloned),self.fake_local_path(volume))

        mox.ReplayAll()

        drv.create_cloned_volume(volume, volume_cloned)

        mox.VerifyAll()
예제 #43
0
 def _create_volume(self):
     self._volume_data = db_fakes.get_fake_volume_info(self._volume_id)
     self._drv.create_volume(self._volume_data)
예제 #44
0
 def _create_volume(self):
     self._volume_data = db_fakes.get_fake_volume_info(self._volume_id)
     self._drv.create_volume(self._volume_data)