64
64
self.assertEqual(len(classes), 1 + len(self.class_map))
66
66
def test_get_filter_classes_raises_on_invalid_classes(self):
67
self.assertRaises(exception.ClassNotFound,
67
self.assertRaises(ImportError,
68
68
filters.get_filter_classes,
69
69
['nova.tests.scheduler.test_host_filters.NoExist'])
70
70
self.assertRaises(exception.ClassNotFound,
306
306
filter_properties = {'instance_type': {'memory_mb': 1024,
308
308
'ephemeral_gb': 0},
309
'query': self.json_query}
309
'scheduler_hints': {'query': self.json_query}}
310
310
capabilities = {'enabled': True}
311
311
host = fakes.FakeHostState('host1', 'compute',
312
312
{'free_ram_mb': 1024,
331
331
filter_properties = {'instance_type': {'memory_mb': 1024,
333
333
'ephemeral_gb': 0},
334
'query': self.json_query}
334
'scheduler_hints': {'query': self.json_query}}
335
335
capabilities = {'enabled': True}
336
336
host = fakes.FakeHostState('host1', 'compute',
337
337
{'free_ram_mb': 1023,
344
344
filter_properties = {'instance_type': {'memory_mb': 1024,
346
346
'ephemeral_gb': 0},
347
'query': self.json_query}
347
'scheduler_hints': {'query': self.json_query}}
348
348
capabilities = {'enabled': True}
349
349
host = fakes.FakeHostState('host1', 'compute',
350
350
{'free_ram_mb': 1024,
361
361
filter_properties = {'instance_type': {'memory_mb': 1024,
363
363
'ephemeral_gb': 0},
364
'scheduler_hints': {'query': json_query}}
365
365
capabilities = {'enabled': False}
366
366
host = fakes.FakeHostState('host1', 'compute',
367
367
{'free_ram_mb': 1024,
377
377
['not', '$service.disabled']])
378
378
filter_properties = {'instance_type': {'memory_mb': 1024,
379
379
'local_gb': 200},
380
'scheduler_hints': {'query': json_query}}
381
381
capabilities = {'enabled': True}
382
382
service = {'disabled': True}
383
383
host = fakes.FakeHostState('host1', 'compute',
400
400
['>', '$free_ram_mb', 30],
401
401
['>', '$free_disk_mb', 300]]]]
402
filter_properties = {'query': json.dumps(raw)}
402
filter_properties = {'scheduler_hints': {'query': json.dumps(raw)}}
405
405
capabilities = {'enabled': True, 'opt1': 'match'}
497
497
for (op, args, expected) in ops_to_test:
498
498
raw = [op] + args
499
filter_properties = {'query': json.dumps(raw)}
499
filter_properties = {'scheduler_hints': {'query': json.dumps(raw)}}
500
500
self.assertEqual(expected,
501
501
filt_cls.host_passes(host, filter_properties))
503
503
# This results in [False, True, False, True] and if any are True
504
504
# then it passes...
505
505
raw = ['not', True, False, True, False]
506
filter_properties = {'query': json.dumps(raw)}
506
filter_properties = {'scheduler_hints': {'query': json.dumps(raw)}}
507
507
self.assertTrue(filt_cls.host_passes(host, filter_properties))
509
509
# This results in [False, False, False] and if any are True
510
510
# then it passes...which this doesn't
511
511
raw = ['not', True, True, True]
512
filter_properties = {'query': json.dumps(raw)}
512
filter_properties = {'scheduler_hints': {'query': json.dumps(raw)}}
513
513
self.assertFalse(filt_cls.host_passes(host, filter_properties))
515
515
def test_json_filter_unknown_operator_raises(self):
516
516
filt_cls = self.class_map['JsonFilter']()
517
517
raw = ['!=', 1, 2]
518
filter_properties = {'query': json.dumps(raw)}
518
filter_properties = {'scheduler_hints': {'query': json.dumps(raw)}}
519
519
host = fakes.FakeHostState('host1', 'compute',
520
520
{'capabilities': {'enabled': True}})
521
521
self.assertRaises(KeyError,
527
527
{'capabilities': {'enabled': True}})
530
filter_properties = {'query': json.dumps(raw)}
530
filter_properties = {'scheduler_hints': {'query': json.dumps(raw)}}
531
531
self.assertTrue(filt_cls.host_passes(host, filter_properties))
533
filter_properties = {'query': json.dumps(raw)}
533
filter_properties = {'scheduler_hints': {'query': json.dumps(raw)}}
534
534
self.assertTrue(filt_cls.host_passes(host, filter_properties))
536
536
def test_json_filter_invalid_num_arguments_fails(self):
539
539
{'capabilities': {'enabled': True}})
541
541
raw = ['>', ['and', ['or', ['not', ['<', ['>=', ['<=', ['in', ]]]]]]]]
542
filter_properties = {'query': json.dumps(raw)}
542
filter_properties = {'scheduler_hints': {'query': json.dumps(raw)}}
543
543
self.assertFalse(filt_cls.host_passes(host, filter_properties))
546
filter_properties = {'query': json.dumps(raw)}
546
filter_properties = {'scheduler_hints': {'query': json.dumps(raw)}}
547
547
self.assertFalse(filt_cls.host_passes(host, filter_properties))
549
549
def test_json_filter_unknown_variable_ignored(self):
552
552
{'capabilities': {'enabled': True}})
554
554
raw = ['=', '$........', 1, 1]
555
filter_properties = {'query': json.dumps(raw)}
555
filter_properties = {'scheduler_hints': {'query': json.dumps(raw)}}
556
556
self.assertTrue(filt_cls.host_passes(host, filter_properties))
558
558
raw = ['=', '$foo', 2, 2]
559
filter_properties = {'query': json.dumps(raw)}
559
filter_properties = {'scheduler_hints': {'query': json.dumps(raw)}}
560
560
self.assertTrue(filt_cls.host_passes(host, filter_properties))
562
562
def test_core_filter_passes(self):