Beispiel #1
0
    def test_do_setup(self):
        mock = mox.Mox()
        mock.StubOutWithMock(driver, 'xenapi_lib')
        mock.StubOutWithMock(driver, 'xenapi_opts')

        configuration = mox.MockObject(conf.Configuration)
        configuration.xenapi_connection_url = 'url'
        configuration.xenapi_connection_username = '******'
        configuration.xenapi_connection_password = '******'
        configuration.append_config_values(mox.IgnoreArg())

        session_factory = object()
        nfsops = object()

        driver.xenapi_lib.SessionFactory('url', 'user',
                                         'pass').AndReturn(session_factory)

        driver.xenapi_lib.NFSBasedVolumeOperations(session_factory).AndReturn(
            nfsops)

        drv = driver.XenAPINFSDriver(configuration=configuration)

        mock.ReplayAll()
        drv.do_setup('context')
        mock.VerifyAll()

        self.assertEquals(nfsops, drv.nfs_ops)
    def test_use_image_utils_to_pipe_bytes_to_volume(self):
        mock, drv = self._setup_mock_driver('server', 'serverpath',
                                            '/var/run/sr-mount')

        volume = dict(provider_location='sr-uuid/vdi-uuid', size=1)
        context = MockContext('token')

        mock.StubOutWithMock(driver.image_utils, 'fetch_to_raw')

        drv.nfs_ops.volume_attached_here('server', 'serverpath', 'sr-uuid',
                                         'vdi-uuid', False).AndReturn(
                                             simple_context('device'))

        driver.image_utils.fetch_to_raw(context,
                                        'image_service',
                                        'image_id',
                                        'device',
                                        mox.IgnoreArg(),
                                        size=1)

        mock.ReplayAll()
        drv._use_image_utils_to_pipe_bytes_to_volume(context, volume,
                                                     "image_service",
                                                     "image_id")
        mock.VerifyAll()
Beispiel #3
0
    def test_initialize_connection_null_values(self):
        mock = mox.Mox()

        drv = get_configured_driver('server', 'path')

        mock.ReplayAll()
        result = drv.initialize_connection(
            dict(
                display_name=None,
                display_description=None,
                provider_location='sr_uuid/vdi_uuid'),
            'connector'
        )
        mock.VerifyAll()

        self.assertEquals(
            dict(
                driver_volume_type='xensm',
                data=dict(
                    name_label='',
                    name_description='',
                    sr_uuid='sr_uuid',
                    vdi_uuid='vdi_uuid',
                    sr_type='nfs',
                    server='server',
                    serverpath='path',
                    introduce_sr_keys=['sr_type', 'server', 'serverpath']
                )
            ),
            result
        )
Beispiel #4
0
    def test_delete_snapshot(self):
        mock, drv = self._setup_mock_driver('server', 'serverpath')

        snapshot = dict(provider_location='src-sr-uuid/src-vdi-uuid')

        drv.nfs_ops.delete_volume("server", "serverpath", "src-sr-uuid",
                                  "src-vdi-uuid")

        mock.ReplayAll()
        drv.delete_snapshot(snapshot)
        mock.VerifyAll()
Beispiel #5
0
    def test_delete_volume(self):
        mock = mox.Mox()

        ops = mock.CreateMock(lib.NFSBasedVolumeOperations)
        drv = get_configured_driver('server', 'path')
        drv.nfs_ops = ops

        ops.delete_volume('server', 'path', 'sr_uuid', 'vdi_uuid')

        mock.ReplayAll()
        result = drv.delete_volume(dict(provider_location='sr_uuid/vdi_uuid'))
        mock.VerifyAll()
Beispiel #6
0
    def test_copy_image_to_volume_non_xenserver_case(self):
        mock, drv = self._setup_mock_driver('server', 'serverpath',
                                            '/var/run/sr-mount')

        mock.StubOutWithMock(drv, '_use_image_utils_to_pipe_bytes_to_volume')
        mock.StubOutWithMock(driver, 'is_xenserver_image')
        context = MockContext('token')

        driver.is_xenserver_image(context, 'image_service',
                                  'image_id').AndReturn(False)
        drv._use_image_utils_to_pipe_bytes_to_volume(
            context, 'volume', 'image_service', 'image_id').AndReturn(True)
        mock.ReplayAll()
        drv.copy_image_to_volume(context, "volume", "image_service",
                                 "image_id")
        mock.VerifyAll()
Beispiel #7
0
    def test_create_volume(self):
        mock = mox.Mox()

        ops = mock.CreateMock(lib.NFSBasedVolumeOperations)
        drv = get_configured_driver('server', 'path')
        drv.nfs_ops = ops

        volume_details = dict(sr_uuid='sr_uuid', vdi_uuid='vdi_uuid')
        ops.create_volume('server', 'path', 1, 'name',
                          'desc').AndReturn(volume_details)

        mock.ReplayAll()
        result = drv.create_volume(
            dict(size=1, display_name='name', display_description='desc'))
        mock.VerifyAll()

        self.assertEquals(dict(provider_location='sr_uuid/vdi_uuid'), result)
Beispiel #8
0
    def test_copy_image_to_volume_xenserver_case(self):
        mock, drv = self._setup_mock_driver('server', 'serverpath',
                                            '/var/run/sr-mount')

        mock.StubOutWithMock(drv, '_use_glance_plugin_to_copy_image_to_volume')
        mock.StubOutWithMock(driver, 'is_xenserver_image')
        context = MockContext('token')

        driver.is_xenserver_image(context, 'image_service',
                                  'image_id').AndReturn(True)
        drv._use_glance_plugin_to_copy_image_to_volume(
            context, 'volume', 'image_service', 'image_id').AndReturn('result')
        mock.ReplayAll()
        result = drv.copy_image_to_volume(context, "volume", "image_service",
                                          "image_id")
        self.assertEquals('result', result)
        mock.VerifyAll()
Beispiel #9
0
    def test_create_volume_from_snapshot(self):
        mock, drv = self._setup_mock_driver('server', 'serverpath')

        snapshot = dict(provider_location='src-sr-uuid/src-vdi-uuid')
        volume = dict(display_name='tgt-name', name_description='tgt-desc')

        drv.nfs_ops.copy_volume("server", "serverpath", "src-sr-uuid",
                                "src-vdi-uuid", "tgt-name",
                                "tgt-desc").AndReturn(
                                    dict(sr_uuid="copied-sr",
                                         vdi_uuid="copied-vdi"))

        mock.ReplayAll()
        result = drv.create_volume_from_snapshot(volume, snapshot)
        mock.VerifyAll()

        self.assertEquals(dict(provider_location='copied-sr/copied-vdi'),
                          result)
Beispiel #10
0
    def test_create_snapshot(self):
        mock, drv = self._setup_mock_driver('server', 'serverpath')

        snapshot = dict(volume_id="volume-id",
                        display_name="snapshot-name",
                        display_description="snapshot-desc",
                        volume=dict(provider_location="sr-uuid/vdi-uuid"))

        drv.nfs_ops.copy_volume("server", "serverpath", "sr-uuid", "vdi-uuid",
                                "snapshot-name", "snapshot-desc").AndReturn(
                                    dict(sr_uuid="copied-sr",
                                         vdi_uuid="copied-vdi"))

        mock.ReplayAll()
        result = drv.create_snapshot(snapshot)
        mock.VerifyAll()
        self.assertEquals(dict(provider_location="copied-sr/copied-vdi"),
                          result)
Beispiel #11
0
    def test_use_glance_plugin_to_upload_volume(self):
        mock, drv = self._setup_mock_driver(
            'server', 'serverpath', '/var/run/sr-mount')

        volume = dict(provider_location='sr-uuid/vdi-uuid')
        context = MockContext('token')

        mock.StubOutWithMock(driver.glance, 'get_api_servers')

        driver.glance.get_api_servers().AndReturn((x for x in ['glancesrv']))

        drv.nfs_ops.use_glance_plugin_to_upload_volume(
            'server', 'serverpath', 'sr-uuid', 'vdi-uuid', 'glancesrv',
            'image-id', 'token', '/var/run/sr-mount')

        mock.ReplayAll()
        drv._use_glance_plugin_to_upload_volume(
            context, volume, "image_service", {"id": "image-id"})
        mock.VerifyAll()
Beispiel #12
0
    def test_use_image_utils_to_upload_volume(self):
        mock, drv = self._setup_mock_driver('server', 'serverpath',
                                            '/var/run/sr-mount')

        volume = dict(provider_location='sr-uuid/vdi-uuid')
        context = MockContext('token')

        mock.StubOutWithMock(driver.image_utils, 'upload_volume')

        drv.nfs_ops.volume_attached_here('server', 'serverpath', 'sr-uuid',
                                         'vdi-uuid', True).AndReturn(
                                             simple_context('device'))

        driver.image_utils.upload_volume(context, 'image_service',
                                         'image_meta', 'device')

        mock.ReplayAll()
        drv._use_image_utils_to_upload_volume(context, volume, "image_service",
                                              "image_meta")
        mock.VerifyAll()
Beispiel #13
0
    def test_copy_volume_to_image_non_xenserver_case(self):
        mock, drv = self._setup_mock_driver('server', 'serverpath',
                                            '/var/run/sr-mount')

        mock.StubOutWithMock(drv, '_use_image_utils_to_upload_volume')
        mock.StubOutWithMock(driver, 'is_xenserver_format')
        context = MockContext('token')

        driver.is_xenserver_format('image_meta').AndReturn(False)

        drv._use_image_utils_to_upload_volume(context, 'volume',
                                              'image_service',
                                              'image_meta').AndReturn('result')
        mock.ReplayAll()

        result = drv.copy_volume_to_image(context, "volume", "image_service",
                                          "image_meta")
        self.assertEquals('result', result)

        mock.VerifyAll()
Beispiel #14
0
    def test_use_glance_plugin_to_copy_image_to_volume_fail(self):
        mock, drv = self._setup_mock_driver('server', 'serverpath',
                                            '/var/run/sr-mount')

        volume = dict(provider_location='sr-uuid/vdi-uuid', size=2)

        mock.StubOutWithMock(driver.glance, 'get_api_servers')

        driver.glance.get_api_servers().AndReturn((x for x in ['glancesrv']))

        drv.nfs_ops.use_glance_plugin_to_overwrite_volume(
            'server', 'serverpath', 'sr-uuid', 'vdi-uuid', 'glancesrv',
            'image_id', 'token', '/var/run/sr-mount').AndReturn(False)

        mock.ReplayAll()

        self.assertRaises(
            exception.ImageCopyFailure,
            lambda: drv._use_glance_plugin_to_copy_image_to_volume(
                MockContext('token'), volume, "ignore", "image_id"))

        mock.VerifyAll()
Beispiel #15
0
    def test_use_glance_plugin_to_copy_image_to_volume_success(self):
        mock, drv = self._setup_mock_driver('server', 'serverpath',
                                            '/var/run/sr-mount')

        volume = dict(provider_location='sr-uuid/vdi-uuid', size=2)

        mock.StubOutWithMock(driver.glance, 'get_api_servers')

        driver.glance.get_api_servers().AndReturn((x for x in ['glancesrv']))

        drv.nfs_ops.use_glance_plugin_to_overwrite_volume(
            'server', 'serverpath', 'sr-uuid', 'vdi-uuid', 'glancesrv',
            'image_id', 'token', '/var/run/sr-mount').AndReturn(True)

        drv.nfs_ops.resize_volume('server', 'serverpath', 'sr-uuid',
                                  'vdi-uuid', 2)

        mock.ReplayAll()
        drv._use_glance_plugin_to_copy_image_to_volume(MockContext('token'),
                                                       volume, "ignore",
                                                       "image_id")
        mock.VerifyAll()