Merge "Use elevated context to query DB in VolumeNumberWeigher"

This commit is contained in:
Jenkins 2016-07-02 04:40:24 +00:00 committed by Gerrit Code Review
commit 2b213e0148
2 changed files with 10 additions and 1 deletions

View File

@ -50,6 +50,7 @@ class VolumeNumberWeigher(weights.BaseHostWeigher):
We want spreading to be the default. We want spreading to be the default.
""" """
context = weight_properties['context'] context = weight_properties['context']
context = context.elevated()
volume_number = db.volume_data_get_for_host(context=context, volume_number = db.volume_data_get_for_host(context=context,
host=host_state.host, host=host_state.host,
count_only=True) count_only=True)

View File

@ -23,6 +23,7 @@ from cinder import context
from cinder.db.sqlalchemy import api from cinder.db.sqlalchemy import api
from cinder.scheduler import weights from cinder.scheduler import weights
from cinder import test from cinder import test
from cinder.tests.unit import fake_constants
from cinder.tests.unit.scheduler import fakes from cinder.tests.unit.scheduler import fakes
from cinder.volume import utils from cinder.volume import utils
@ -46,9 +47,16 @@ def fake_volume_data_get_for_host(context, host, count_only=False):
class VolumeNumberWeigherTestCase(test.TestCase): class VolumeNumberWeigherTestCase(test.TestCase):
def setUp(self): def setUp(self):
super(VolumeNumberWeigherTestCase, self).setUp() super(VolumeNumberWeigherTestCase, self).setUp()
self.context = context.get_admin_context() uid = fake_constants.USER_ID
pid = fake_constants.PROJECT_ID
self.context = context.RequestContext(user_id=uid,
project_id=pid,
is_admin=False,
read_deleted="no",
overwrite=False)
self.host_manager = fakes.FakeHostManager() self.host_manager = fakes.FakeHostManager()
self.weight_handler = weights.HostWeightHandler( self.weight_handler = weights.HostWeightHandler(
'cinder.scheduler.weights') 'cinder.scheduler.weights')