~ubuntu-branches/ubuntu/saucy/nova/saucy-proposed

« back to all changes in this revision

Viewing changes to nova/tests/scheduler/test_host_filters.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-05-24 13:12:53 UTC
  • mfrom: (1.1.55)
  • Revision ID: package-import@ubuntu.com-20120524131253-ommql08fg1en06ut
Tags: 2012.2~f1-0ubuntu1
* New upstream release.
* Prepare for quantal:
  - Dropped debian/patches/upstream/0006-Use-project_id-in-ec2.cloud._format_image.patch
  - Dropped debian/patches/upstream/0005-Populate-image-properties-with-project_id-again.patch
  - Dropped debian/patches/upstream/0004-Fixed-bug-962840-added-a-test-case.patch
  - Dropped debian/patches/upstream/0003-Allow-unprivileged-RADOS-users-to-access-rbd-volumes.patch
  - Dropped debian/patches/upstream/0002-Stop-libvirt-test-from-deleting-instances-dir.patch
  - Dropped debian/patches/upstream/0001-fix-bug-where-nova-ignores-glance-host-in-imageref.patch 
  - Dropped debian/patches/0001-fix-useexisting-deprecation-warnings.patch
* debian/control: Add python-keystone as a dependency. (LP: #907197)
* debian/patches/kombu_tests_timeout.patch: Refreshed.
* debian/nova.conf, debian/nova-common.postinst: Convert to new ini
  file configuration
* debian/patches/nova-manage_flagfile_location.patch: Refreshed

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
        self.assertEqual(len(classes), 1 + len(self.class_map))
65
65
 
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,
307
307
                                               'root_gb': 200,
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,
332
332
                                               'root_gb': 200,
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,
345
345
                                               'root_gb': 200,
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,
362
362
                                               'root_gb': 200,
363
363
                                               'ephemeral_gb': 0},
364
 
                             'query': json_query}
 
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
 
                             'query': json_query}
 
380
                           'scheduler_hints': {'query': json_query}}
381
381
        capabilities = {'enabled': True}
382
382
        service = {'disabled': True}
383
383
        host = fakes.FakeHostState('host1', 'compute',
399
399
                      ['and',
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)}}
403
403
 
404
404
        # Passes
405
405
        capabilities = {'enabled': True, 'opt1': 'match'}
496
496
 
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))
502
502
 
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))
508
508
 
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))
514
514
 
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}})
528
528
 
529
529
        raw = []
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))
532
532
        raw = {}
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))
535
535
 
536
536
    def test_json_filter_invalid_num_arguments_fails(self):
539
539
                {'capabilities': {'enabled': True}})
540
540
 
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))
544
544
 
545
545
        raw = ['>', 1]
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))
548
548
 
549
549
    def test_json_filter_unknown_variable_ignored(self):
552
552
                {'capabilities': {'enabled': True}})
553
553
 
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))
557
557
 
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))
561
561
 
562
562
    def test_core_filter_passes(self):