def test_share_host_update_db(self): with mock.patch.object(timeutils, 'utcnow', mock.Mock(return_value='fake-now')): base.share_update_db(self.context, 31337, 'fake_host') db.share_update.assert_called_once_with( self.context, 31337, {'host': 'fake_host', 'scheduled_at': 'fake-now'})
def schedule_create_share(self, context, request_spec, filter_properties): weighed_host = self._schedule_share(context, request_spec, filter_properties) if not weighed_host: raise exception.NoValidHost(reason="") host = weighed_host.obj.host share_id = request_spec['share_id'] snapshot_id = request_spec['snapshot_id'] updated_share = base.share_update_db(context, share_id, host) self._post_select_populate_filter_properties(filter_properties, weighed_host.obj) # context is not serializable filter_properties.pop('context', None) self.share_rpcapi.create_share_instance( context, updated_share.instance, host, request_spec=request_spec, filter_properties=filter_properties, snapshot_id=snapshot_id )
def schedule_create_share(self, context, request_spec, filter_properties): weighed_host = self._schedule_share(context, request_spec, filter_properties) if not weighed_host: raise exception.NoValidHost(reason="") host = weighed_host.obj.host share_id = request_spec['share_id'] snapshot_id = request_spec['snapshot_id'] updated_share = base.share_update_db(context, share_id, host) self._post_select_populate_filter_properties(filter_properties, weighed_host.obj) # context is not serializable filter_properties.pop('context', None) self.share_rpcapi.create_share_instance( context, updated_share.instance, host, request_spec=request_spec, filter_properties=filter_properties, snapshot_id=snapshot_id)
def schedule_create_share(self, context, request_spec, filter_properties): """Picks a host that is up at random.""" topic = CONF.share_topic host = self._schedule(context, topic, request_spec, filter_properties=filter_properties) share_id = request_spec['share_id'] snapshot_id = request_spec['snapshot_id'] updated_share = base.share_update_db(context, share_id, host) self.share_rpcapi.create_share_instance( context, updated_share.instance, host, request_spec, filter_properties, snapshot_id )
def schedule_create_share(self, context, request_spec, filter_properties): """Picks a host that is up and has the fewest shares.""" # TODO(rushiagr) - pick only hosts that run shares elevated = context.elevated() share_id = request_spec.get('share_id') snapshot_id = request_spec.get('snapshot_id') share_properties = request_spec.get('share_properties') share_size = share_properties.get('size') instance_properties = request_spec.get('share_instance_properties', {}) availability_zone_id = instance_properties.get('availability_zone_id') results = db.service_get_all_share_sorted(elevated) if availability_zone_id: results = [ (service_g, gigs) for (service_g, gigs) in results if (service_g['availability_zone_id'] == availability_zone_id) ] for result in results: (service, share_gigabytes) = result if share_gigabytes + share_size > CONF.max_gigabytes: msg = _("Not enough allocatable share gigabytes remaining") raise exception.NoValidHost(reason=msg) if utils.service_is_up(service) and not service['disabled']: updated_share = base.share_update_db(context, share_id, service['host']) self.share_rpcapi.create_share_instance( context, updated_share.instance, service['host'], request_spec, None, snapshot_id=snapshot_id) return None msg = _("Is the appropriate service running?") raise exception.NoValidHost(reason=msg)
def schedule_create_share(self, context, request_spec, filter_properties): """Picks a host that is up and has the fewest shares.""" # TODO(rushiagr) - pick only hosts that run shares elevated = context.elevated() share_id = request_spec.get('share_id') snapshot_id = request_spec.get('snapshot_id') share_properties = request_spec.get('share_properties') share_size = share_properties.get('size') instance_properties = request_spec.get('share_instance_properties', {}) availability_zone_id = instance_properties.get('availability_zone_id') results = db.service_get_all_share_sorted(elevated) if availability_zone_id: results = [(service_g, gigs) for (service_g, gigs) in results if (service_g['availability_zone_id'] == availability_zone_id)] for result in results: (service, share_gigabytes) = result if share_gigabytes + share_size > CONF.max_gigabytes: msg = _("Not enough allocatable share gigabytes remaining") raise exception.NoValidHost(reason=msg) if utils.service_is_up(service) and not service['disabled']: updated_share = base.share_update_db(context, share_id, service['host']) self.share_rpcapi.create_share_instance( context, updated_share.instance, service['host'], request_spec, None, snapshot_id=snapshot_id) return None msg = _("Is the appropriate service running?") raise exception.NoValidHost(reason=msg)