def schedule_create_volume(self, context, volume_id, snapshot_id, image_id): """Picks a host that is up at random.""" host = self._schedule(context, FLAGS.volume_topic, None, {}) driver.cast_to_host(context, FLAGS.volume_topic, host, 'create_volume', volume_id=volume_id, snapshot_id=snapshot_id, image_id=image_id)
def schedule_prep_resize(self, context, request_spec, *args, **kwargs): """Select a target for resize. Selects a target host for the instance, post-resize, and casts the prep_resize operation to it. """ # We need the new instance type ID... instance_type_id = kwargs['instance_type_id'] elevated = context.elevated() LOG.debug(_("Attempting to determine target host for resize to " "instance type %(instance_type_id)s") % locals()) # Convert it to an actual instance type instance_type = db.instance_type_get(elevated, instance_type_id) # Now let's grab a possibility hosts = self._schedule(elevated, 'compute', request_spec, *args, **kwargs) if not hosts: raise exception.NoValidHost(reason=_("")) host = hosts.pop(0) # Forward off to the host driver.cast_to_host(context, 'compute', host.host, 'prep_resize', **kwargs)
def schedule_prep_resize(self, context, request_spec, *args, **kwargs): """Select a target for resize. Selects a target host for the instance, post-resize, and casts the prep_resize operation to it. """ # We need the new instance type ID... instance_type_id = kwargs["instance_type_id"] elevated = context.elevated() LOG.debug( _("Attempting to determine target host for resize to " "instance type %(instance_type_id)s") % locals() ) # Convert it to an actual instance type instance_type = db.instance_type_get(elevated, instance_type_id) # Now let's grab a possibility hosts = self._schedule(elevated, "compute", request_spec, *args, **kwargs) if not hosts: raise exception.NoValidHost(reason=_("")) host = hosts.pop(0) # Forward off to the host driver.cast_to_host(context, "compute", host.host, "prep_resize", **kwargs)
def test_cast_to_host_network_topic(self): host = "fake_host1" method = "fake_method" fake_kwargs = {"extra_arg": "meow"} self.mox.StubOutWithMock(driver, "cast_to_network_host") driver.cast_to_network_host(self.context, host, method, **fake_kwargs) self.mox.ReplayAll() driver.cast_to_host(self.context, "network", host, method, **fake_kwargs)
def test_cast_to_host_network_topic(self): host = 'fake_host1' method = 'fake_method' fake_kwargs = {'extra_arg': 'meow'} self.mox.StubOutWithMock(driver, 'cast_to_network_host') driver.cast_to_network_host(self.context, host, method, **fake_kwargs) self.mox.ReplayAll() driver.cast_to_host(self.context, 'network', host, method, **fake_kwargs)
def test_cast_to_host_network_topic(self): host = 'fake_host1' method = 'fake_method' fake_kwargs = {'extra_arg': 'meow'} self.mox.StubOutWithMock(driver, 'cast_to_network_host') driver.cast_to_network_host(self.context, host, method, update_db=False, **fake_kwargs) self.mox.ReplayAll() driver.cast_to_host(self.context, 'network', host, method, update_db=False, **fake_kwargs)
def test_cast_to_host_volume_topic(self): host = 'fake_host1' method = 'fake_method' fake_kwargs = {'extra_arg': 'meow'} self.mox.StubOutWithMock(driver, 'cast_to_volume_host') driver.cast_to_volume_host(self.context, host, method, update_db=False, **fake_kwargs) self.mox.ReplayAll() driver.cast_to_host(self.context, 'volume', host, method, update_db=False, **fake_kwargs)
def test_cast_to_host_volume_topic(self): host = 'fake_host1' method = 'fake_method' fake_kwargs = {'extra_arg': 'meow'} self.mox.StubOutWithMock(driver, 'cast_to_volume_host') driver.cast_to_volume_host(self.context, host, method, **fake_kwargs) self.mox.ReplayAll() driver.cast_to_host(self.context, 'volume', host, method, **fake_kwargs)
def test_cast_to_host_unknown_topic(self): host = "fake_host1" method = "fake_method" fake_kwargs = {"extra_arg": "meow"} topic = "unknown" queue = "fake_queue" self.mox.StubOutWithMock(rpc, "queue_get_for") self.mox.StubOutWithMock(rpc, "cast") rpc.queue_get_for(self.context, topic, host).AndReturn(queue) rpc.cast(self.context, queue, {"method": method, "args": fake_kwargs}) self.mox.ReplayAll() driver.cast_to_host(self.context, topic, host, method, **fake_kwargs)
def test_cast_to_host_unknown_topic(self): host = 'fake_host1' method = 'fake_method' fake_kwargs = {'extra_arg': 'meow'} topic = 'unknown' queue = 'fake_queue' self.mox.StubOutWithMock(rpc, 'queue_get_for') self.mox.StubOutWithMock(rpc, 'cast') rpc.queue_get_for(self.context, topic, host).AndReturn(queue) rpc.cast(self.context, queue, {'method': method, 'args': fake_kwargs}) self.mox.ReplayAll() driver.cast_to_host(self.context, topic, host, method, **fake_kwargs)
def test_cast_to_host_unknown_topic(self): host = 'fake_host1' method = 'fake_method' fake_kwargs = {'extra_arg': 'meow'} topic = 'unknown' queue = 'fake_queue' self.mox.StubOutWithMock(db, 'queue_get_for') self.mox.StubOutWithMock(rpc, 'cast') db.queue_get_for(self.context, topic, host).AndReturn(queue) rpc.cast(self.context, queue, {'method': method, 'args': fake_kwargs}) self.mox.ReplayAll() driver.cast_to_host(self.context, topic, host, method, update_db=False, **fake_kwargs)
def test_basic_schedule_fallback(self): ctxt = context.RequestContext('fake', 'fake', False) ctxt_elevated = 'fake-context-elevated' topic = 'fake_topic' method = 'fake_method' fake_args = (1, 2, 3) fake_kwargs = {'fake_kwarg1': 'fake_value1', 'fake_kwarg2': 'fake_value2'} self.mox.StubOutWithMock(ctxt, 'elevated') self.mox.StubOutWithMock(self.driver, 'hosts_up') self.mox.StubOutWithMock(random, 'random') self.mox.StubOutWithMock(driver, 'cast_to_host') ctxt.elevated().AndReturn(ctxt_elevated) self.driver.hosts_up(ctxt_elevated, topic).AndReturn( ['host1', 'host2', 'host3', 'host4']) random.random().AndReturn(.5) driver.cast_to_host(ctxt, topic, 'host3', method, **fake_kwargs) self.mox.ReplayAll() self.driver.schedule(ctxt, topic, method, *fake_args, **fake_kwargs)
def schedule_prep_resize(self, context, request_spec, *args, **kwargs): """Select a target for resize.""" host = self._schedule(context, 'compute', request_spec, **kwargs) driver.cast_to_host(context, 'compute', host, 'prep_resize', **kwargs)
def schedule(self, context, topic, method, *_args, **kwargs): """Picks a host that is up at random.""" host = self._schedule(context, topic, None, **kwargs) driver.cast_to_host(context, topic, host, method, **kwargs)
def schedule(self, context, topic, method, *_args, **kwargs): """Picks a host that is up at random.""" filter_properties = kwargs.get('filter_properties', {}) host = self._schedule(context, topic, None, filter_properties) driver.cast_to_host(context, topic, host, method, **kwargs)
def schedule(self, context, topic, method, *_args, **kwargs): host = self._schedule(context, topic, None, **kwargs) driver.cast_to_host(context, topic, host, method, **kwargs)