Merge "Parse unicode cpu_info as json before using it"
This commit is contained in:
@@ -13,6 +13,9 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import six
|
||||
|
||||
from nova.openstack.common import jsonutils
|
||||
from nova.openstack.common import log as logging
|
||||
from nova.scheduler import filters
|
||||
from nova.scheduler.filters import extra_specs_ops
|
||||
@@ -45,6 +48,11 @@ class ComputeCapabilitiesFilter(filters.BaseHostFilter):
|
||||
cap = host_state
|
||||
for index in range(0, len(scope)):
|
||||
try:
|
||||
if isinstance(cap, six.string_types):
|
||||
try:
|
||||
cap = jsonutils.loads(cap)
|
||||
except ValueError:
|
||||
return False
|
||||
if not isinstance(cap, dict):
|
||||
if getattr(cap, scope[index], None) is None:
|
||||
# If can't find, check stats dict
|
||||
|
||||
@@ -18,6 +18,7 @@ Tests For Scheduler Host Filters.
|
||||
import httplib
|
||||
|
||||
from oslo.config import cfg
|
||||
import six
|
||||
import stubout
|
||||
|
||||
from nova import context
|
||||
@@ -822,6 +823,28 @@ class HostFiltersTestCase(test.NoDBTestCase):
|
||||
assertion = self.assertTrue if passes else self.assertFalse
|
||||
assertion(filt_cls.host_passes(host, filter_properties))
|
||||
|
||||
def test_compute_filter_pass_cpu_info_as_text_type(self):
|
||||
cpu_info = """ { "vendor": "Intel", "model": "core2duo",
|
||||
"arch": "i686","features": ["lahf_lm", "rdtscp"], "topology":
|
||||
{"cores": 1, "threads":1, "sockets": 1}} """
|
||||
|
||||
cpu_info = six.text_type(cpu_info)
|
||||
|
||||
self._do_test_compute_filter_extra_specs(
|
||||
ecaps={'cpu_info': cpu_info},
|
||||
especs={'capabilities:cpu_info:vendor': 'Intel'},
|
||||
passes=True)
|
||||
|
||||
def test_compute_filter_fail_cpu_info_as_text_type_not_valid(self):
|
||||
cpu_info = "cpu_info"
|
||||
|
||||
cpu_info = six.text_type(cpu_info)
|
||||
|
||||
self._do_test_compute_filter_extra_specs(
|
||||
ecaps={'cpu_info': cpu_info},
|
||||
especs={'capabilities:cpu_info:vendor': 'Intel'},
|
||||
passes=False)
|
||||
|
||||
def test_compute_filter_passes_extra_specs_simple(self):
|
||||
self._do_test_compute_filter_extra_specs(
|
||||
ecaps={'stats': {'opt1': 1, 'opt2': 2}},
|
||||
|
||||
Reference in New Issue
Block a user