Use elevated context to query DB in VolumeNumberWeigher
Currently tenant would fail to create volume, if cinder uses VolumeNumberWeigher. This will elevate tenant to admin privilege, then VolumeNumberWeigher has the privilege to get volume count of each hosts. Change-Id: I1aa0e8ad74d37389ad1feecef113ab8e260dfd0f Closes-Bug: #1594294
This commit is contained in:
parent
d669449cd2
commit
afc9cb9b2d
@ -50,6 +50,7 @@ class VolumeNumberWeigher(weights.BaseHostWeigher):
|
||||
We want spreading to be the default.
|
||||
"""
|
||||
context = weight_properties['context']
|
||||
context = context.elevated()
|
||||
volume_number = db.volume_data_get_for_host(context=context,
|
||||
host=host_state.host,
|
||||
count_only=True)
|
||||
|
@ -23,6 +23,7 @@ from cinder import context
|
||||
from cinder.db.sqlalchemy import api
|
||||
from cinder.scheduler import weights
|
||||
from cinder import test
|
||||
from cinder.tests.unit import fake_constants
|
||||
from cinder.tests.unit.scheduler import fakes
|
||||
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):
|
||||
|
||||
def setUp(self):
|
||||
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.weight_handler = weights.HostWeightHandler(
|
||||
'cinder.scheduler.weights')
|
||||
|
Loading…
Reference in New Issue
Block a user