Beispiel #1
0
    def setUp(self):
        super(FetchVhdImageTestCase, self).setUp()
        self.context = context.get_admin_context()
        self.context.auth_token = 'auth_token'

        self.session = FakeSession()
        self.instance = {"uuid": "uuid"}
        self.image_id = "image_id"
        self.uuid_stack = ["uuid_stack"]
        self.sr_path = "sr_path"
        self.params = {
            'image_id': self.image_id,
            'uuid_stack': self.uuid_stack,
            'sr_path': self.sr_path
        }
        self.vdis = {'root': {'uuid': 'vdi'}}

        self.mox.StubOutWithMock(vm_utils, '_make_uuid_stack')
        self.mox.StubOutWithMock(vm_utils, 'get_sr_path')
        self.mox.StubOutWithMock(vm_utils, '_image_uses_bittorrent')
        self.mox.StubOutWithMock(vm_utils, '_add_bittorrent_params')
        self.mox.StubOutWithMock(vm_utils, 'safe_find_sr')
        self.mox.StubOutWithMock(vm_utils, '_scan_sr')
        self.mox.StubOutWithMock(vm_utils, '_check_vdi_size')
        self.mox.StubOutWithMock(vm_utils, 'destroy_vdi')
        self.mox.StubOutWithMock(self.session,
                                 'call_plugin_serialized_with_retry')
        self.mox.StubOutWithMock(vm_utils, '_add_torrent_url')

        vm_utils._make_uuid_stack().AndReturn(self.uuid_stack)
        vm_utils.get_sr_path(self.session).AndReturn(self.sr_path)
Beispiel #2
0
    def test_fallback_to_default_handler(self):
        cfg.CONF.import_opt('xenapi_torrent_base_url',
                            'nova.virt.xenapi.image.bittorrent')
        self.flags(xenapi_torrent_base_url='http://foo')

        self.mox.StubOutWithMock(vm_utils, '_image_uses_bittorrent')
        vm_utils._image_uses_bittorrent(
            self.context, self.instance).AndReturn(True)

        self._stub_bittorrent_download_vhd(raise_exc=RuntimeError)

        vm_utils._make_uuid_stack().AndReturn(["uuid_stack"])
        vm_utils.get_sr_path(self.session).AndReturn('sr_path')

        self._stub_glance_download_vhd()

        self.mox.StubOutWithMock(vm_utils, 'safe_find_sr')
        vm_utils.safe_find_sr(self.session).AndReturn("sr")

        self.mox.StubOutWithMock(vm_utils, '_scan_sr')
        vm_utils._scan_sr(self.session, "sr")

        self.mox.StubOutWithMock(vm_utils, '_check_vdi_size')
        vm_utils._check_vdi_size(self.context, self.session, self.instance,
                                 "vdi")

        self.mox.ReplayAll()

        self.assertEqual("vdi", vm_utils._fetch_vhd_image(self.context,
            self.session, self.instance, 'image_id')['root']['uuid'])

        self.mox.VerifyAll()
Beispiel #3
0
    def setUp(self):
        super(FetchVhdImageTestCase, self).setUp()
        self.context = context.get_admin_context()
        self.context.auth_token = "auth_token"

        self.session = FakeSession()
        self.instance = {"uuid": "uuid"}
        self.image_id = "image_id"
        self.uuid_stack = ["uuid_stack"]
        self.sr_path = "sr_path"
        self.params = {"image_id": self.image_id, "uuid_stack": self.uuid_stack, "sr_path": self.sr_path}
        self.vdis = {"root": {"uuid": "vdi"}}

        self.mox.StubOutWithMock(vm_utils, "_make_uuid_stack")
        self.mox.StubOutWithMock(vm_utils, "get_sr_path")
        self.mox.StubOutWithMock(vm_utils, "_image_uses_bittorrent")
        self.mox.StubOutWithMock(vm_utils, "_add_bittorrent_params")
        self.mox.StubOutWithMock(vm_utils, "safe_find_sr")
        self.mox.StubOutWithMock(vm_utils, "_scan_sr")
        self.mox.StubOutWithMock(vm_utils, "_check_vdi_size")
        self.mox.StubOutWithMock(vm_utils, "destroy_vdi")
        self.mox.StubOutWithMock(self.session, "call_plugin_serialized_with_retry")
        self.mox.StubOutWithMock(vm_utils, "_add_torrent_url")

        vm_utils._make_uuid_stack().AndReturn(self.uuid_stack)
        vm_utils.get_sr_path(self.session).AndReturn(self.sr_path)
Beispiel #4
0
    def _common_params_setup(self, uses_bittorrent):
        self.context = "context"
        self.session = FakeSession()
        self.instance = {"uuid": "uuid"}
        self.image_id = "image_id"
        self.uuid_stack = ["uuid_stack"]
        self.sr_path = "sr_path"
        self.params = {
            'image_id': self.image_id,
            'uuid_stack': self.uuid_stack,
            'sr_path': self.sr_path
        }
        self.bt_params = copy.copy(self.params)
        self.bt_params['torrent_url'] = "%s.torrent" % self.image_id
        self.vdis = {'root': {'uuid': 'vdi'}}

        vm_utils._make_uuid_stack().AndReturn(self.uuid_stack)
        vm_utils.get_sr_path(self.session).AndReturn(self.sr_path)
        vm_utils._image_uses_bittorrent(
            self.context, self.instance).AndReturn(uses_bittorrent)
        if uses_bittorrent:

            def set_url(instance, image_id, params):
                params['torrent_url'] = "%s.torrent" % image_id

            vm_utils._add_torrent_url(
                self.instance, self.image_id,
                self.params).WithSideEffects(set_url).AndReturn(True)
Beispiel #5
0
    def setUp(self):
        super(FetchVhdImageTestCase, self).setUp()
        self.context = context.get_admin_context()
        self.context.auth_token = 'auth_token'
        self.session = FakeSession()
        self.instance = {"uuid": "uuid"}

        self.mox.StubOutWithMock(vm_utils, '_make_uuid_stack')
        vm_utils._make_uuid_stack().AndReturn(["uuid_stack"])

        self.mox.StubOutWithMock(vm_utils, 'get_sr_path')
        vm_utils.get_sr_path(self.session).AndReturn('sr_path')
Beispiel #6
0
    def setUp(self):
        super(FetchVhdImageTestCase, self).setUp()
        self.context = context.get_admin_context()
        self.context.auth_token = 'auth_token'
        self.session = FakeSession()
        self.instance = {"uuid": "uuid"}

        self.mox.StubOutWithMock(vm_utils, '_make_uuid_stack')
        vm_utils._make_uuid_stack().AndReturn(["uuid_stack"])

        self.mox.StubOutWithMock(vm_utils, 'get_sr_path')
        vm_utils.get_sr_path(self.session).AndReturn('sr_path')
Beispiel #7
0
    def _common_params_setup(self, uses_bittorrent):
        self.context = "context"
        self.session = FakeSession()
        self.instance = {"uuid": "uuid"}
        self.image_id = "image_id"
        self.uuid_stack = ["uuid_stack"]
        self.sr_path = "sr_path"
        self.params = {'image_id': self.image_id,
            'uuid_stack': self.uuid_stack, 'sr_path': self.sr_path}
        self.vdis = {'root': {'uuid': 'vdi'}}

        vm_utils._make_uuid_stack().AndReturn(self.uuid_stack)
        vm_utils.get_sr_path(self.session).AndReturn(self.sr_path)
        vm_utils._image_uses_bittorrent(self.context,
            self.instance).AndReturn(uses_bittorrent)
Beispiel #8
0
    def _common_params_setup(self, uses_bittorrent):
        self.context = "context"
        self.session = FakeSession()
        self.instance = {"uuid": "uuid"}
        self.image_id = "image_id"
        self.uuid_stack = ["uuid_stack"]
        self.sr_path = "sr_path"
        self.params = {'image_id': self.image_id,
            'uuid_stack': self.uuid_stack, 'sr_path': self.sr_path}
        self.vdis = {'root': {'uuid': 'vdi'}}

        vm_utils._make_uuid_stack().AndReturn(self.uuid_stack)
        vm_utils.get_sr_path(self.session).AndReturn(self.sr_path)
        vm_utils._image_uses_bittorrent(self.context,
            self.instance).AndReturn(uses_bittorrent)
Beispiel #9
0
    def download_image(self, context, session, instance, image_id):
        params = {}
        params['image_id'] = image_id
        params['uuid_stack'] = vm_utils._make_uuid_stack()
        params['sr_path'] = vm_utils.get_sr_path(session)
        params['torrent_seed_duration'] = CONF.xenserver.torrent_seed_duration
        params['torrent_seed_chance'] = CONF.xenserver.torrent_seed_chance
        params['torrent_max_last_accessed'] = \
                CONF.xenserver.torrent_max_last_accessed
        params['torrent_listen_port_start'] = \
                CONF.xenserver.torrent_listen_port_start
        params['torrent_listen_port_end'] = \
                CONF.xenserver.torrent_listen_port_end
        params['torrent_download_stall_cutoff'] = \
                CONF.xenserver.torrent_download_stall_cutoff
        params['torrent_max_seeder_processes_per_host'] = \
                CONF.xenserver.torrent_max_seeder_processes_per_host

        lookup_fn = self._lookup_torrent_url_fn()
        params['torrent_url'] = lookup_fn(instance, image_id)

        vdis = session.call_plugin_serialized(
                'bittorrent', 'download_vhd', **params)

        return vdis
Beispiel #10
0
    def download_image(self, context, session, instance, image_id):
        params = self._make_params(context, session, image_id)
        params['uuid_stack'] = vm_utils._make_uuid_stack()

        try:
            vdis = self._call_glance_plugin(session, 'download_vhd', params)
        except exception.PluginRetriesExceeded:
            raise exception.CouldNotFetchImage(image_id=image_id)

        return vdis
Beispiel #11
0
    def download_image(self, context, session, instance, image_id):
        params = self._make_params(context, session, image_id)
        params['uuid_stack'] = vm_utils._make_uuid_stack()

        try:
            vdis = self._call_glance_plugin(session, 'download_vhd', params)
        except exception.PluginRetriesExceeded:
            raise exception.CouldNotFetchImage(image_id=image_id)

        return vdis
Beispiel #12
0
    def download_image(self, context, session, instance, image_id):
        params = {'uuid_stack': vm_utils._make_uuid_stack()}
        try:
            vdis = self._call_glance_plugin(context, instance, session,
                                            host_glance.download_vhd, image_id,
                                            params)
        except xenapi_exception.PluginRetriesExceeded:
            raise exception.CouldNotFetchImage(image_id=image_id)

        return vdis
Beispiel #13
0
    def download_image(self, context, session, instance, image_id):
        params = {'uuid_stack': vm_utils._make_uuid_stack()}
        try:
            vdis = self._call_glance_plugin(context, instance, session,
                                            host_glance.download_vhd, image_id,
                                            params)
        except xenapi_exception.PluginRetriesExceeded:
            raise exception.CouldNotFetchImage(image_id=image_id)

        return vdis
    def _common_params_setup(self, uses_bittorrent):
        self.context = "context"
        self.session = FakeSession()
        self.instance = {"uuid": "uuid"}
        self.image_id = "image_id"
        self.uuid_stack = ["uuid_stack"]
        self.sr_path = "sr_path"
        self.params = {'image_id': self.image_id,
            'uuid_stack': self.uuid_stack, 'sr_path': self.sr_path}
        self.bt_params = copy.copy(self.params)
        self.bt_params['torrent_url'] = "%s.torrent" % self.image_id
        self.vdis = {'root': {'uuid': 'vdi'}}

        vm_utils._make_uuid_stack().AndReturn(self.uuid_stack)
        vm_utils.get_sr_path(self.session).AndReturn(self.sr_path)
        vm_utils._image_uses_bittorrent(self.context,
            self.instance).AndReturn(uses_bittorrent)
        if uses_bittorrent:
            def set_url(instance, image_id, params):
                params['torrent_url'] = "%s.torrent" % image_id

            vm_utils._add_torrent_url(self.instance, self.image_id,
                    self.params).WithSideEffects(set_url).AndReturn(True)