def test_volume_host_update_db(self, _mock_utcnow, _mock_vol_update): _mock_utcnow.return_value = 'fake-now' driver.volume_update_db(self.context, 31337, 'fake_host') _mock_vol_update.assert_called_once_with(self.context, 31337, { 'host': 'fake_host', 'scheduled_at': 'fake-now' })
def test_create_volume_update_fault(self, _mock_service_get_all, _mock_volume_get, _mock_vol_fault_update, _mock_vol_update): sched = fakes.FakeFilterScheduler() sched.host_manager = fakes.FakeHostManager() fake_context = context.RequestContext('user', 'project', is_admin=True) fakes.mock_host_manager_db_calls(_mock_service_get_all) volume = fake_volume.fake_volume_obj(self.context) _mock_volume_get.return_value = volume driver.volume_update_db(self.context, volume.id, 'fake_host', 'fake_cluster') request_spec = { 'volume_type': { 'name': 'LVM_iSCSI' }, 'volume_properties': { 'project_id': 1, 'size': 1 }, 'volume_id': volume.id, 'snapshot_id': None, 'image_id': None } request_spec = objects.RequestSpec.from_primitives(request_spec) sched.schedule_create_volume(fake_context, request_spec, {}) _mock_vol_fault_update.assert_called_once_with( fake_context, volume.id, dict(message='', details=''))
def test_volume_host_update_db(self, _mock_volume_get, _mock_vol_update): volume = fake_volume.fake_volume_obj(self.context) _mock_volume_get.return_value = volume driver.volume_update_db(self.context, volume.id, 'fake_host') scheduled_at = volume.scheduled_at.replace(tzinfo=None) _mock_vol_update.assert_called_once_with( self.context, volume.id, {'host': 'fake_host', 'scheduled_at': scheduled_at})
def test_volume_host_update_db(self): self.mox.StubOutWithMock(timeutils, 'utcnow') self.mox.StubOutWithMock(db, 'volume_update') timeutils.utcnow().AndReturn('fake-now') db.volume_update(self.context, 31337, {'host': 'fake_host', 'scheduled_at': 'fake-now'}) self.mox.ReplayAll() driver.volume_update_db(self.context, 31337, 'fake_host')
def test_volume_host_update_db(self): self.mox.StubOutWithMock(timeutils, 'utcnow') self.mox.StubOutWithMock(db, 'volume_update') timeutils.utcnow().AndReturn('fake-now') db.volume_update(self.context, 31337, { 'host': 'fake_host', 'scheduled_at': 'fake-now' }) self.mox.ReplayAll() driver.volume_update_db(self.context, 31337, 'fake_host')
def schedule_create_volume(self, context, request_spec, filter_properties): """Picks a host that is up and has the fewest volumes.""" elevated = context.elevated() volume_id = request_spec.get('volume_id') snapshot_id = request_spec.get('snapshot_id') image_id = request_spec.get('image_id') volume_properties = request_spec.get('volume_properties') volume_size = volume_properties.get('size') availability_zone = volume_properties.get('availability_zone') zone, host = None, None if availability_zone: zone, _x, host = availability_zone.partition(':') if host and context.is_admin: topic = CONF.volume_topic service = db.service_get_by_args(elevated, host, topic) if not utils.service_is_up(service): raise exception.WillNotSchedule(host=host) updated_volume = driver.volume_update_db(context, volume_id, host) self.volume_rpcapi.create_volume(context, updated_volume, host, request_spec, filter_properties, snapshot_id=snapshot_id, image_id=image_id) return None results = db.service_get_all_volume_sorted(elevated) if zone: results = [(s, gigs) for (s, gigs) in results if s['availability_zone'] == zone] for result in results: (service, volume_gigabytes) = result if volume_gigabytes + volume_size > CONF.max_gigabytes: msg = _("Not enough allocatable volume gigabytes remaining") raise exception.NoValidHost(reason=msg) if utils.service_is_up(service) and not service['disabled']: updated_volume = driver.volume_update_db( context, volume_id, service['host']) self.volume_rpcapi.create_volume(context, updated_volume, service['host'], request_spec, filter_properties, snapshot_id=snapshot_id, image_id=image_id) return None msg = _("Is the appropriate service running?") raise exception.NoValidHost(reason=msg)
def test_volume_host_update_db(self, _mock_volume_get, _mock_vol_update): volume = fake_volume.fake_volume_obj(self.context, use_quota=True) _mock_volume_get.return_value = volume driver.volume_update_db(self.context, volume.id, 'fake_host', 'fake_cluster') scheduled_at = volume.scheduled_at.replace(tzinfo=None) _mock_vol_update.assert_called_once_with( self.context, volume.id, { 'host': 'fake_host', 'cluster_name': 'fake_cluster', 'scheduled_at': scheduled_at, 'availability_zone': None })
def schedule_create_volume(self, context, request_spec, filter_properties): weighed_host = self._schedule(context, request_spec, filter_properties) if not weighed_host: raise exception.NoValidHost(reason="") host = weighed_host.obj.host volume_id = request_spec['volume_id'] snapshot_id = request_spec['snapshot_id'] image_id = request_spec['image_id'] updated_volume = driver.volume_update_db(context, volume_id, host) self._post_select_populate_filter_properties(filter_properties, weighed_host.obj) # context is not serializable filter_properties.pop('context', None) self.volume_rpcapi.create_volume(context, updated_volume, host, request_spec=request_spec, filter_properties=filter_properties, allow_reschedule=True, snapshot_id=snapshot_id, image_id=image_id)
def schedule_create_volume(self, context, request_spec, filter_properties): backend = self._schedule(context, request_spec, filter_properties) if not backend: raise exception.NoValidBackend(reason=_("No weighed backends " "available")) backend = backend.obj volume_id = request_spec['volume_id'] updated_volume = driver.volume_update_db( context, volume_id, backend.host, backend.cluster_name, availability_zone=backend.service['availability_zone']) self._post_select_populate_filter_properties(filter_properties, backend) # context is not serializable filter_properties.pop('context', None) self.volume_rpcapi.create_volume(context, updated_volume, request_spec, filter_properties, allow_reschedule=True)
def schedule_create_volume(self, context, request_spec, filter_properties): """Picks a host that is up and has the fewest volumes.""" elevated = context.elevated() volume_id = request_spec.get('volume_id') snapshot_id = request_spec.get('snapshot_id') image_id = request_spec.get('image_id') volume_properties = request_spec.get('volume_properties') volume_size = volume_properties.get('size') availability_zone = volume_properties.get('availability_zone') zone, host = None, None if availability_zone: zone, _x, host = availability_zone.partition(':') if host and context.is_admin: topic = FLAGS.volume_topic service = db.service_get_by_args(elevated, host, topic) if not utils.service_is_up(service): raise exception.WillNotSchedule(host=host) updated_volume = driver.volume_update_db(context, volume_id, host) self.volume_rpcapi.create_volume(context, updated_volume, host, snapshot_id, image_id) return None results = db.service_get_all_volume_sorted(elevated) if zone: results = [(service, gigs) for (service, gigs) in results if service['availability_zone'] == zone] for result in results: (service, volume_gigabytes) = result if volume_gigabytes + volume_size > FLAGS.max_gigabytes: msg = _("Not enough allocatable volume gigabytes remaining") raise exception.NoValidHost(reason=msg) if utils.service_is_up(service) and not service['disabled']: updated_volume = driver.volume_update_db(context, volume_id, service['host']) self.volume_rpcapi.create_volume(context, updated_volume, service['host'], snapshot_id, image_id) return None msg = _("Is the appropriate service running?") raise exception.NoValidHost(reason=msg)
def schedule_create_volume(self, context, request_spec, filter_properties): """Picks a host that is up at random.""" topic = CONF.volume_topic host = self._schedule(context, topic, request_spec, filter_properties=filter_properties) volume_id = request_spec['volume_id'] snapshot_id = request_spec['snapshot_id'] image_id = request_spec['image_id'] updated_volume = driver.volume_update_db(context, volume_id, host) self.volume_rpcapi.create_volume(context, updated_volume, host, snapshot_id, image_id)
def schedule_create_volume(self, context, request_spec, filter_properties): """Use volume type extra_specs to store tenant info for tenant isolation""" volume_id = request_spec.get('volume_id') snapshot_id = request_spec.get('snapshot_id') image_id = request_spec.get('image_id') volume_properties = request_spec.get('volume_properties') availability_zone = volume_properties.get('availability_zone') context_dict = context.to_dict() tenant_name = context_dict['project_name'] # check if request has volume type and volume type matching tenant # if no volume type in request, search db for tenant's bind volume type # if no bind volume type, add default volume type to create volume volume_type = request_spec.get('volume_type') if volume_type: specs = volume_type.get('extra_specs') if 'tenant_name' in specs: if specs['tenant_name'] != tenant_name: msg = _("Tenant cannot use volume type %s." % volume_type['name']) raise exception.InvalidVolumeType(reason=msg) else: #check db if user's tenant has been bond to a volume type bindType = False volume_types = db.volume_type_get_all(context) for key in volume_types: specs = volume_types[key].get('extra_specs') if 'tenant_name' in specs: if specs['tenant_name'] == tenant_name: bindType = True request_spec['volume_type'] = volume_types[key] break if not bindType: request_spec['volume_type'] = db.volume_type_get_by_name( context, 'DEFAULT') LOG.debug(str(request_spec)) host = 'MyHost' updated_volume = driver.volume_update_db(context, volume_id, host) self.volume_rpcapi.create_volume(context, updated_volume, host, request_spec, filter_properties, snapshot_id=snapshot_id, image_id=image_id) return None
def schedule_create_volume(self, context, request_spec, filter_properties): weighed_host = self._schedule(context, request_spec, filter_properties) if not weighed_host: raise exception.NoValidHost(reason="") host = weighed_host.obj.host volume_id = request_spec['volume_id'] snapshot_id = request_spec['snapshot_id'] image_id = request_spec['image_id'] updated_volume = driver.volume_update_db(context, volume_id, host) self.volume_rpcapi.create_volume(context, updated_volume, host, snapshot_id, image_id)
def schedule_create_volume(self, context, request_spec, filter_properties): weighed_host = self._schedule(context, request_spec, filter_properties) if not weighed_host: raise exception.NoValidHost(reason=_("No weighed hosts available")) host = weighed_host.obj.host volume_id = request_spec["volume_id"] updated_volume = driver.volume_update_db(context, volume_id, host) self._post_select_populate_filter_properties(filter_properties, weighed_host.obj) # context is not serializable filter_properties.pop("context", None) self.volume_rpcapi.create_volume( context, updated_volume, host, request_spec, filter_properties, allow_reschedule=True )
def schedule_create_volume(self, context, request_spec, filter_properties): resource_type = request_spec.get('volume_type', None) extra_specs = {} if resource_type: extra_specs = resource_type.get('extra_specs', {}) volume_id = request_spec.get('volume_id') snapshot_id = request_spec.get('snapshot_id') image_id = request_spec.get('image_id') replica_vol = None if 'True' in extra_specs.get('replication_enabled', ''): weighed_host, weighed_host2 = self._get_replication_hosts( context, request_spec, filter_properties) else: weighed_host = self._schedule(context, request_spec, filter_properties) weighed_host2 = None if not weighed_host: raise exception.NoValidHost(reason="") if weighed_host2: az = weighed_host2.obj.service['availability_zone'] replica_vol = {'status': 'secondary_replica', 'attach_status': 'detached', 'host': weighed_host2.obj.host, 'availability_zone': az} host = weighed_host.obj.host updated_volume = driver.volume_update_db(context, volume_id, host, replica=replica_vol) self._post_select_populate_filter_properties(filter_properties, weighed_host.obj) # context is not serializable filter_properties.pop('context', None) self.volume_rpcapi.create_volume(context, updated_volume, host, request_spec, filter_properties, allow_reschedule=True, snapshot_id=snapshot_id, image_id=image_id)
def schedule_create_volume(self, context, request_spec, filter_properties): backend = self._schedule(context, request_spec, filter_properties) if not backend: raise exception.NoValidBackend(reason=_("No weighed backends " "available")) backend = backend.obj volume_id = request_spec['volume_id'] updated_volume = driver.volume_update_db(context, volume_id, backend.host, backend.cluster_name) self._post_select_populate_filter_properties(filter_properties, backend) # context is not serializable filter_properties.pop('context', None) # In case of multiple cinder backends, it is possible for # one backend to fail to schedule, while another succeeds. # If the volume is scheduled successfully, clear any fault # generated. utils.update_volume_fault(context, volume_id, "") LOG.info( ("Volume %(volume_id)s is scheduled to create. " "\n--request_spec: %(request_spec)s, " "\n--filter_properties: %(filter_properties)s, " "\n--snapshot_id: %(snapshot_id)s, " "\n--image_id: %(image_id)s"), { 'volume_id': volume_id, 'request_spec': request_spec, 'filter_properties': filter_properties, 'snapshot_id': request_spec['snapshot_id'], 'image_id': request_spec['image_id'] }) self.volume_rpcapi.create_volume(context, updated_volume, request_spec, filter_properties, allow_reschedule=True)
def schedule_create_volume(self, context, request_spec, filter_properties): backend = self._schedule(context, request_spec, filter_properties) if not backend: raise exception.NoValidBackend(reason=_("No weighed backends " "available")) backend = backend.obj volume_id = request_spec['volume_id'] updated_volume = driver.volume_update_db(context, volume_id, backend.host, backend.cluster_name) self._post_select_populate_filter_properties(filter_properties, backend) # context is not serializable filter_properties.pop('context', None) self.volume_rpcapi.create_volume(context, updated_volume, request_spec, filter_properties, allow_reschedule=True)
def test_volume_host_update_db(self, _mock_utcnow, _mock_vol_update): _mock_utcnow.return_value = 'fake-now' driver.volume_update_db(self.context, 31337, 'fake_host') _mock_vol_update.assert_called_once_with(self.context, 31337, {'host': 'fake_host', 'scheduled_at': 'fake-now'})
def test_volume_host_update_db(self, _mock_utcnow, _mock_vol_update): _mock_utcnow.return_value = "fake-now" driver.volume_update_db(self.context, 31337, "fake_host") _mock_vol_update.assert_called_once_with(self.context, 31337, {"host": "fake_host", "scheduled_at": "fake-now"})