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:
Jack Lu
2016-06-21 14:42:44 +08:00
parent d669449cd2
commit afc9cb9b2d
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.
"""
context = weight_properties['context']
context = context.elevated()
volume_number = db.volume_data_get_for_host(context=context,
host=host_state.host,
count_only=True)