68
class ExtraSpecsOpsTestCase(test.TestCase):
69
def _do_extra_specs_ops_test(self, value, req, matches):
70
assertion = self.assertTrue if matches else self.assertFalse
71
assertion(extra_specs_ops.match(value, req))
73
def test_extra_specs_matches_simple(self):
74
self._do_extra_specs_ops_test(
79
def test_extra_specs_fails_simple(self):
80
self._do_extra_specs_ops_test(
85
def test_extra_specs_fails_simple2(self):
86
self._do_extra_specs_ops_test(
91
def test_extra_specs_fails_simple3(self):
92
self._do_extra_specs_ops_test(
97
def test_extra_specs_fails_with_bogus_ops(self):
98
self._do_extra_specs_ops_test(
103
def test_extra_specs_matches_with_op_eq(self):
104
self._do_extra_specs_ops_test(
109
def test_extra_specs_matches_with_op_eq2(self):
110
self._do_extra_specs_ops_test(
115
def test_extra_specs_fails_with_op_eq(self):
116
self._do_extra_specs_ops_test(
121
def test_extra_specs_fails_with_op_eq3(self):
122
self._do_extra_specs_ops_test(
127
def test_extra_specs_matches_with_op_seq(self):
128
self._do_extra_specs_ops_test(
133
def test_extra_specs_fails_with_op_seq(self):
134
self._do_extra_specs_ops_test(
139
def test_extra_specs_matches_with_op_sneq(self):
140
self._do_extra_specs_ops_test(
145
def test_extra_specs_fails_with_op_sneq(self):
146
self._do_extra_specs_ops_test(
151
def test_extra_specs_fails_with_op_sge(self):
152
self._do_extra_specs_ops_test(
157
def test_extra_specs_fails_with_op_sle(self):
158
self._do_extra_specs_ops_test(
163
def test_extra_specs_fails_with_op_sl(self):
164
self._do_extra_specs_ops_test(
169
def test_extra_specs_fails_with_op_sg(self):
170
self._do_extra_specs_ops_test(
175
def test_extra_specs_matches_with_op_in(self):
176
self._do_extra_specs_ops_test(
181
def test_extra_specs_matches_with_op_in2(self):
182
self._do_extra_specs_ops_test(
187
def test_extra_specs_matches_with_op_in3(self):
188
self._do_extra_specs_ops_test(
190
req='<in> 12311321 <in>',
193
def test_extra_specs_fails_with_op_in(self):
194
self._do_extra_specs_ops_test(
199
def test_extra_specs_fails_with_op_in2(self):
200
self._do_extra_specs_ops_test(
205
def test_extra_specs_matches_with_op_or(self):
206
self._do_extra_specs_ops_test(
208
req='<or> 11 <or> 12',
211
def test_extra_specs_matches_with_op_or2(self):
212
self._do_extra_specs_ops_test(
214
req='<or> 11 <or> 12 <or>',
217
def test_extra_specs_fails_with_op_or(self):
218
self._do_extra_specs_ops_test(
220
req='<or> 11 <or> 12',
223
def test_extra_specs_fails_with_op_or2(self):
224
self._do_extra_specs_ops_test(
226
req='<or> 11 <or> 12 <or>',
229
def test_extra_specs_matches_with_op_le(self):
230
self._do_extra_specs_ops_test(
235
def test_extra_specs_fails_with_op_le(self):
236
self._do_extra_specs_ops_test(
241
def test_extra_specs_matches_with_op_ge(self):
242
self._do_extra_specs_ops_test(
247
def test_extra_specs_fails_with_op_ge(self):
248
self._do_extra_specs_ops_test(
67
254
class HostFiltersTestCase(test.TestCase):
68
255
"""Test case for host filters."""
503
690
assertion = self.assertTrue if passes else self.assertFalse
504
691
assertion(filt_cls.host_passes(host, filter_properties))
506
def test_compute_filter_passes_extra_specs_simple1(self):
507
self._do_test_compute_filter_extra_specs(
508
ecaps={'opt1': '1', 'opt2': '2'},
509
especs={'opt1': '1'},
512
def test_compute_filter_passes_extra_specs_simple2(self):
513
self._do_test_compute_filter_extra_specs(
514
ecaps={'opt1': '1', 'opt2': '2'},
515
especs={'opt1': '1', 'opt2': '2'},
518
def test_compute_filter_fails_extra_specs_simple1(self):
519
self._do_test_compute_filter_extra_specs(
520
ecaps={'opt1': '1', 'opt2': '2'},
521
especs={'opt1': '1111'},
524
def test_compute_filter_fails_extra_specs_simple2(self):
525
self._do_test_compute_filter_extra_specs(
526
ecaps={'opt1': '1', 'opt2': '2'},
530
def test_compute_filter_fails_extra_specs_simple3(self):
531
self._do_test_compute_filter_extra_specs(
532
ecaps={'opt1': '1', 'opt2': '2'},
533
especs={'opt3': '3'},
536
def test_compute_filter_fails_extra_specs_simple4(self):
537
self._do_test_compute_filter_extra_specs(
538
ecaps={'opt1': '1', 'opt2': '2'},
539
especs={'opt1': '1', 'opt2': '222'},
542
def test_compute_filter_fails_extra_specs_simple5(self):
543
self._do_test_compute_filter_extra_specs(
544
ecaps={'opt1': '1', 'opt2': '2'},
545
especs={'opt1': '1111', 'opt2': '222'},
548
def test_compute_filter_fails_extra_specs_with_bogus_ops(self):
549
self._do_test_compute_filter_extra_specs(
550
ecaps={'opt1': '2', 'opt2': '5'},
551
especs={'opt1': '> 4', 'opt2': '< 3'},
554
def test_compute_filter_passes_extra_specs_with_op_eq(self):
555
self._do_test_compute_filter_extra_specs(
556
ecaps={'opt1': '123'},
557
especs={'opt1': '= 123'},
560
def test_compute_filter_passes_extra_specs_with_op_eq2(self):
561
self._do_test_compute_filter_extra_specs(
562
ecaps={'opt1': '124'},
563
especs={'opt1': '= 123'},
566
def test_compute_filter_passes_extra_specs_with_op_eq3(self):
567
self._do_test_compute_filter_extra_specs(
568
ecaps={'opt1': '124', 'opt2': '456'},
569
especs={'opt1': '= 123', 'opt2': '= 456'},
572
def test_compute_filter_fails_extra_specs_with_op_eq(self):
573
self._do_test_compute_filter_extra_specs(
574
ecaps={'opt2': '34'},
575
especs={'opt2': '= 234'},
578
def test_compute_filter_passes_extra_specs_with_op_eq2(self):
579
self._do_test_compute_filter_extra_specs(
580
ecaps={'opt1': '124', 'opt2': '4567'},
581
especs={'opt1': '= 123', 'opt2': '= 456'},
584
def test_compute_filter_fails_extra_specs_with_op_eq3(self):
585
self._do_test_compute_filter_extra_specs(
586
ecaps={'opt1': '124'},
587
especs={'opt1': '='},
590
def test_compute_filter_fails_extra_specs_with_op_eq4(self):
591
self._do_test_compute_filter_extra_specs(
592
ecaps={'opt3': '124', 'opt4': '456'},
593
especs={'opt11': '= 124', 'opt12': '= 456'},
596
def test_compute_filter_passes_extra_specs_with_op_seq(self):
597
self._do_test_compute_filter_extra_specs(
598
ecaps={'opt1': '123'},
599
especs={'opt1': 's== 123'},
602
def test_compute_filter_fails_extra_specs_with_op_seq(self):
603
self._do_test_compute_filter_extra_specs(
604
ecaps={'opt2': '2345'},
605
especs={'opt2': 's== 234'},
608
def test_compute_filter_passes_extra_specs_with_op_sneq(self):
609
self._do_test_compute_filter_extra_specs(
610
ecaps={'opt1': '11'},
611
especs={'opt1': 's!= 123'},
614
def test_compute_filter_fails_extra_specs_with_op_sneq(self):
615
self._do_test_compute_filter_extra_specs(
616
ecaps={'opt2': '234'},
617
especs={'opt2': 's!= 234'},
620
def test_compute_filter_passes_extra_specs_with_op_sgle(self):
621
self._do_test_compute_filter_extra_specs(
622
ecaps={'opt1': '11', 'opt2': '543'},
623
especs={'opt1': 's<= 123', 'opt2': 's>= 43'},
626
def test_compute_filter_fails_extra_specs_with_op_sge(self):
627
self._do_test_compute_filter_extra_specs(
628
ecaps={'opt2': '1000'},
629
especs={'opt2': 's>= 234'},
632
def test_compute_filter_fails_extra_specs_with_op_sle(self):
633
self._do_test_compute_filter_extra_specs(
634
ecaps={'opt2': '234'},
635
especs={'opt2': 's<= 1000'},
638
def test_compute_filter_passes_extra_specs_with_op_sgl(self):
639
self._do_test_compute_filter_extra_specs(
640
ecaps={'opt1': '11', 'opt2': '543'},
641
especs={'opt1': 's< 123', 'opt2': 's> 43'},
644
def test_compute_filter_fails_extra_specs_with_op_sl(self):
645
self._do_test_compute_filter_extra_specs(
647
especs={'opt2': 's< 12'},
650
def test_compute_filter_fails_extra_specs_with_op_sg(self):
651
self._do_test_compute_filter_extra_specs(
652
ecaps={'opt2': '12'},
653
especs={'opt2': 's> 2'},
656
def test_compute_filter_passes_extra_specs_with_op_in(self):
657
self._do_test_compute_filter_extra_specs(
658
ecaps={'opt1': '12311321'},
659
especs={'opt1': '<in> 11'},
662
def test_compute_filter_passes_extra_specs_with_op_in2(self):
663
self._do_test_compute_filter_extra_specs(
664
ecaps={'opt1': '12311321'},
665
especs={'opt1': '<in> 12311321'},
668
def test_compute_filter_passes_extra_specs_with_op_in3(self):
669
self._do_test_compute_filter_extra_specs(
670
ecaps={'opt1': '12311321'},
671
especs={'opt1': '<in> 12311321 <in>'},
674
def test_compute_filter_fails_extra_specs_with_op_in(self):
675
self._do_test_compute_filter_extra_specs(
676
ecaps={'opt1': '12310321'},
677
especs={'opt1': '<in> 11'},
680
def test_compute_filter_fails_extra_specs_with_op_in2(self):
681
self._do_test_compute_filter_extra_specs(
682
ecaps={'opt1': '12310321'},
683
especs={'opt1': '<in> 11 <in>'},
686
def test_compute_filter_passes_extra_specs_with_op_or(self):
687
self._do_test_compute_filter_extra_specs(
688
ecaps={'opt1': '12'},
689
especs={'opt1': '<or> 11 <or> 12'},
692
def test_compute_filter_passes_extra_specs_with_op_or2(self):
693
self._do_test_compute_filter_extra_specs(
694
ecaps={'opt1': '12'},
695
especs={'opt1': '<or> 11 <or> 12 <or>'},
698
def test_compute_filter_fails_extra_specs_with_op_or(self):
699
self._do_test_compute_filter_extra_specs(
700
ecaps={'opt1': '13'},
701
especs={'opt1': '<or> 11 <or> 12'},
704
def test_compute_filter_fails_extra_specs_with_op_or2(self):
705
self._do_test_compute_filter_extra_specs(
706
ecaps={'opt1': '13'},
707
especs={'opt1': '<or> 11 <or> 12 <or>'},
710
def test_compute_filter_passes_extra_specs_with_op_le(self):
711
self._do_test_compute_filter_extra_specs(
712
ecaps={'opt1': 2, 'opt2': 2},
713
especs={'opt1': '<= 10', 'opt2': '<= 20'},
716
def test_compute_filter_fails_extra_specs_with_op_le(self):
717
self._do_test_compute_filter_extra_specs(
718
ecaps={'opt1': 1, 'opt2': 3},
719
especs={'opt1': '<= 2', 'opt2': '<= 2'},
722
def test_compute_filter_passes_extra_specs_with_op_ge(self):
723
self._do_test_compute_filter_extra_specs(
724
ecaps={'opt1': 2, 'opt2': 2},
725
especs={'opt1': '>= 1', 'opt2': '>= 2'},
728
def test_compute_filter_fails_extra_specs_with_op_ge(self):
729
self._do_test_compute_filter_extra_specs(
730
ecaps={'opt1': 1, 'opt2': 2},
731
especs={'opt1': '>= 2', 'opt2': '>= 2'},
693
def test_compute_filter_passes_extra_specs_simple(self):
694
self._do_test_compute_filter_extra_specs(
695
ecaps={'opt1': '1', 'opt2': '2'},
696
especs={'opt1': '1', 'opt2': '2', 'trust:trusted_host': 'true'},
699
def test_compute_filter_fails_extra_specs_simple(self):
700
self._do_test_compute_filter_extra_specs(
701
ecaps={'opt1': '1', 'opt2': '2'},
702
especs={'opt1': '1', 'opt2': '222', 'trust:trusted_host': 'true'},
734
705
def test_aggregate_filter_passes_no_extra_specs(self):
752
723
db.aggregate_host_add(self.context.elevated(), result.id, host)
755
def test_aggregate_filter_passes_extra_specs(self):
756
self._stub_service_is_up(True)
757
filt_cls = self.class_map['AggregateInstanceExtraSpecsFilter']()
758
extra_specs = {'opt1': '1', 'opt2': '2'}
759
self._create_aggregate_with_host(metadata={'opt1': '1'})
760
self._create_aggregate_with_host(name='fake2', metadata={'opt2': '2'})
762
filter_properties = {'context': self.context, 'instance_type':
763
{'memory_mb': 1024, 'extra_specs': extra_specs}}
764
host = fakes.FakeHostState('host1', 'compute', {'free_ram_mb': 1024})
765
self.assertTrue(filt_cls.host_passes(host, filter_properties))
767
def test_aggregate_filter_fails_extra_specs(self):
768
self._stub_service_is_up(True)
769
filt_cls = self.class_map['AggregateInstanceExtraSpecsFilter']()
770
extra_specs = {'opt1': 1, 'opt2': 3}
771
self._create_aggregate_with_host(metadata={'opt1': '1'})
772
self._create_aggregate_with_host(name='fake2', metadata={'opt2': '2'})
773
filter_properties = {'context': self.context, 'instance_type':
774
{'memory_mb': 1024, 'extra_specs': extra_specs}}
775
host = fakes.FakeHostState('host1', 'compute', {'free_ram_mb': 1024})
776
self.assertFalse(filt_cls.host_passes(host, filter_properties))
726
def _do_test_aggregate_filter_extra_specs(self, emeta, especs, passes):
727
self._stub_service_is_up(True)
728
filt_cls = self.class_map['AggregateInstanceExtraSpecsFilter']()
729
self._create_aggregate_with_host(name='fake2', metadata=emeta)
730
filter_properties = {'context': self.context,
731
'instance_type': {'memory_mb': 1024, 'extra_specs': especs}}
732
host = fakes.FakeHostState('host1', 'compute', {'free_ram_mb': 1024})
733
assertion = self.assertTrue if passes else self.assertFalse
734
assertion(filt_cls.host_passes(host, filter_properties))
778
736
def test_aggregate_filter_fails_extra_specs_deleted_host(self):
779
737
self._stub_service_is_up(True)
780
738
filt_cls = self.class_map['AggregateInstanceExtraSpecsFilter']()
781
extra_specs = {'opt1': '1', 'opt2': '2'}
739
extra_specs = {'opt1': 's== 1', 'opt2': 's== 2',
740
'trust:trusted_host': 'true'}
782
741
self._create_aggregate_with_host(metadata={'opt1': '1'})
783
742
agg2 = self._create_aggregate_with_host(name='fake2',
784
743
metadata={'opt2': '2'})