36
36
from nova .objects import instance
37
37
from nova .objects import instance_info_cache
38
38
from nova .objects import pci_device
39
- from nova .objects import security_group
40
39
from nova import test
41
40
from nova .tests .unit import fake_instance
42
41
from nova .tests .unit .objects import test_instance_device_metadata
46
45
from nova .tests .unit .objects import test_instance_pci_requests
47
46
from nova .tests .unit .objects import test_migration_context as test_mig_ctxt
48
47
from nova .tests .unit .objects import test_objects
49
- from nova .tests .unit .objects import test_security_group
50
48
from nova .tests .unit .objects import test_vcpu_model
51
49
from nova import utils
52
50
@@ -66,7 +64,6 @@ def fake_instance(self):
66
64
db_inst ['launched_at' ] = datetime .datetime (1955 , 11 , 12 ,
67
65
22 , 4 , 0 )
68
66
db_inst ['deleted' ] = False
69
- db_inst ['security_groups' ] = []
70
67
db_inst ['pci_devices' ] = []
71
68
db_inst ['user_id' ] = self .context .user_id
72
69
db_inst ['project_id' ] = self .context .project_id
@@ -380,7 +377,7 @@ def test_get_by_id(self, mock_get):
380
377
inst = objects .Instance .get_by_id (self .context , 'instid' )
381
378
self .assertEqual (self .fake_instance ['uuid' ], inst .uuid )
382
379
mock_get .assert_called_once_with (self .context , 'instid' ,
383
- columns_to_join = ['info_cache' , 'security_groups' ])
380
+ columns_to_join = ['info_cache' ])
384
381
385
382
@mock .patch .object (db , 'instance_get_by_uuid' )
386
383
def test_load (self , mock_get ):
@@ -399,8 +396,7 @@ def test_load(self, mock_get):
399
396
self .assertEqual ({'foo' : 'bar' }, meta2 )
400
397
401
398
call_list = [mock .call (self .context , fake_uuid ,
402
- columns_to_join = ['info_cache' ,
403
- 'security_groups' ]),
399
+ columns_to_join = ['info_cache' ]),
404
400
mock .call (self .context , fake_uuid ,
405
401
columns_to_join = ['metadata' ]),
406
402
]
@@ -475,7 +471,7 @@ def test_get_remote(self, mock_get):
475
471
str (inst .access_ip_v6 ))
476
472
477
473
mock_get .assert_called_once_with (self .context , uuids .instance ,
478
- columns_to_join = ['info_cache' , 'security_groups' ])
474
+ columns_to_join = ['info_cache' ])
479
475
480
476
@mock .patch .object (instance_info_cache .InstanceInfoCache , 'refresh' )
481
477
@mock .patch .object (db , 'instance_get_by_uuid' )
@@ -492,11 +488,9 @@ def test_refresh(self, mock_get, mock_refresh):
492
488
self .assertEqual (set ([]), inst .obj_what_changed ())
493
489
494
490
get_call_list = [mock .call (self .context , fake_uuid ,
495
- columns_to_join = ['info_cache' ,
496
- 'security_groups' ]),
491
+ columns_to_join = ['info_cache' ]),
497
492
mock .call (self .context , fake_uuid ,
498
- columns_to_join = ['info_cache' ,
499
- 'security_groups' ]),
493
+ columns_to_join = ['info_cache' ]),
500
494
]
501
495
mock_get .assert_has_calls (get_call_list , any_order = False )
502
496
mock_refresh .assert_called_once_with ()
@@ -566,12 +560,10 @@ def _save_test_helper(self, save_kwargs,
566
560
# NOTE(danms): Ignore flavor migrations for the moment
567
561
self .assertEqual (set ([]), inst .obj_what_changed () - set (['flavor' ]))
568
562
mock_db_instance_get_by_uuid .assert_called_once_with (
569
- self .context , fake_uuid , columns_to_join = ['info_cache' ,
570
- 'security_groups' ])
563
+ self .context , fake_uuid , columns_to_join = ['info_cache' ])
571
564
mock_db_instance_update_and_get_original .assert_called_once_with (
572
565
self .context , fake_uuid , expected_updates ,
573
- columns_to_join = ['info_cache' , 'security_groups' ,
574
- 'system_metadata' ]
566
+ columns_to_join = ['info_cache' , 'system_metadata' ]
575
567
)
576
568
mock_notifications_send_update .assert_called_with (self .context ,
577
569
mock .ANY ,
@@ -609,10 +601,10 @@ def test_save_rename_sends_notification(self, mock_send, mock_get,
609
601
self .assertEqual (set ([]), inst .obj_what_changed () - set (['flavor' ]))
610
602
611
603
mock_get .assert_called_once_with (self .context , fake_uuid ,
612
- columns_to_join = ['info_cache' , 'security_groups' ])
604
+ columns_to_join = ['info_cache' ])
613
605
mock_update_and_get .assert_called_once_with (self .context , fake_uuid ,
614
- expected_updates , columns_to_join = ['info_cache' , 'security_groups' ,
615
- 'system_metadata' ] )
606
+ expected_updates , columns_to_join = ['info_cache' , 'system_metadata' ]
607
+ )
616
608
mock_send .assert_called_once_with (self .context , mock .ANY , mock .ANY )
617
609
618
610
@mock .patch ('nova.db.main.api.instance_extra_update_by_uuid' )
@@ -794,7 +786,7 @@ def test_get_deleted(self, mock_get):
794
786
# NOTE(danms): Make sure it's actually a bool
795
787
self .assertTrue (inst .deleted )
796
788
mock_get .assert_called_once_with (self .context , fake_uuid ,
797
- columns_to_join = ['info_cache' , 'security_groups' ])
789
+ columns_to_join = ['info_cache' ])
798
790
799
791
@mock .patch .object (db , 'instance_get_by_uuid' )
800
792
def test_get_not_cleaned (self , mock_get ):
@@ -806,7 +798,7 @@ def test_get_not_cleaned(self, mock_get):
806
798
# NOTE(mikal): Make sure it's actually a bool
807
799
self .assertFalse (inst .cleaned )
808
800
mock_get .assert_called_once_with (self .context , fake_uuid ,
809
- columns_to_join = ['info_cache' , 'security_groups' ])
801
+ columns_to_join = ['info_cache' ])
810
802
811
803
@mock .patch .object (db , 'instance_get_by_uuid' )
812
804
def test_get_cleaned (self , mock_get ):
@@ -818,7 +810,7 @@ def test_get_cleaned(self, mock_get):
818
810
# NOTE(mikal): Make sure it's actually a bool
819
811
self .assertTrue (inst .cleaned )
820
812
mock_get .assert_called_once_with (self .context , fake_uuid ,
821
- columns_to_join = ['info_cache' , 'security_groups' ])
813
+ columns_to_join = ['info_cache' ])
822
814
823
815
@mock .patch .object (db , 'instance_update_and_get_original' )
824
816
@mock .patch .object (db , 'instance_info_cache_update' )
@@ -846,7 +838,7 @@ def test_with_info_cache(self, mock_get, mock_upd_cache, mock_upd_and_get):
846
838
inst .save ()
847
839
848
840
mock_get .assert_called_once_with (self .context , fake_uuid ,
849
- columns_to_join = ['info_cache' , 'security_groups' ])
841
+ columns_to_join = ['info_cache' ])
850
842
mock_upd_cache .assert_called_once_with (self .context , fake_uuid ,
851
843
{'network_info' : nwinfo2_json })
852
844
self .assertFalse (mock_upd_and_get .called )
@@ -900,22 +892,15 @@ def test_with_security_groups(self, mock_get, mock_upd_and_get,
900
892
mock_upd_secgrp .return_value = fake_inst ['security_groups' ][0 ]
901
893
902
894
inst = objects .Instance .get_by_uuid (self .context , fake_uuid )
903
- self .assertEqual (2 , len (inst .security_groups ))
904
- for index , group in enumerate (fake_inst ['security_groups' ]):
905
- for key in group :
906
- self .assertEqual (group [key ],
907
- getattr (inst .security_groups [index ], key ))
908
- self .assertIsInstance (inst .security_groups [index ],
909
- security_group .SecurityGroup )
895
+ # we no longer actually save these, so this should return 0
896
+ self .assertEqual (0 , len (inst .security_groups ))
910
897
self .assertEqual (set (), inst .security_groups .obj_what_changed ())
911
- inst .security_groups [0 ].description = 'changed'
912
898
inst .save ()
913
899
self .assertEqual (set (), inst .security_groups .obj_what_changed ())
914
900
915
901
mock_get .assert_called_once_with (self .context , fake_uuid ,
916
- columns_to_join = ['info_cache' , 'security_groups' ])
917
- mock_upd_secgrp .assert_called_once_with (self .context , 1 ,
918
- {'description' : 'changed' })
902
+ columns_to_join = ['info_cache' ])
903
+ mock_upd_secgrp .assert_not_called ()
919
904
self .assertFalse (mock_upd_and_get .called )
920
905
921
906
@mock .patch .object (db , 'instance_get_by_uuid' )
@@ -927,7 +912,7 @@ def test_with_empty_security_groups(self, mock_get):
927
912
inst = objects .Instance .get_by_uuid (self .context , fake_uuid )
928
913
self .assertEqual (0 , len (inst .security_groups ))
929
914
mock_get .assert_called_once_with (self .context , fake_uuid ,
930
- columns_to_join = ['info_cache' , 'security_groups' ])
915
+ columns_to_join = ['info_cache' ])
931
916
932
917
@mock .patch .object (db , 'instance_get_by_uuid' )
933
918
def test_with_empty_pci_devices (self , mock_get ):
@@ -1201,23 +1186,16 @@ def test_create_with_special_things(self, mock_create):
1201
1186
fake_inst = fake_instance .fake_db_instance ()
1202
1187
mock_create .return_value = fake_inst
1203
1188
1204
- secgroups = security_group .SecurityGroupList ()
1205
- secgroups .objects = []
1206
- for name in ('foo' , 'bar' ):
1207
- secgroup = security_group .SecurityGroup ()
1208
- secgroup .name = name
1209
- secgroups .objects .append (secgroup )
1210
1189
info_cache = instance_info_cache .InstanceInfoCache ()
1211
1190
info_cache .network_info = network_model .NetworkInfo ()
1212
1191
inst = objects .Instance (context = self .context ,
1213
- host = 'foo-host' , security_groups = secgroups ,
1192
+ host = 'foo-host' ,
1214
1193
info_cache = info_cache )
1215
1194
inst .create ()
1216
1195
1217
1196
mock_create .assert_called_once_with (self .context ,
1218
1197
{'host' : 'foo-host' ,
1219
1198
'deleted' : 0 ,
1220
- 'security_groups' : ['foo' , 'bar' ],
1221
1199
'info_cache' : {'network_info' : '[]' },
1222
1200
'extra' : {
1223
1201
'vcpu_model' : None ,
@@ -1340,6 +1318,7 @@ def test_from_db_object_info_cache_not_set(self):
1340
1318
self .assertIsNone (inst .info_cache )
1341
1319
1342
1320
def test_from_db_object_security_groups_net_set (self ):
1321
+ # this is the default now since we no longer set these things
1343
1322
inst = instance .Instance (context = self .context ,
1344
1323
info_cache = None )
1345
1324
db_inst = fake_instance .fake_db_instance ()
@@ -1601,20 +1580,6 @@ def test_load_ec2_ids(self, mock_get):
1601
1580
mock_get .assert_called_once_with (self .context , inst )
1602
1581
self .assertEqual (fake_ec2_ids , ec2_ids )
1603
1582
1604
- @mock .patch ('nova.objects.SecurityGroupList.get_by_instance' )
1605
- def test_load_security_groups (self , mock_get ):
1606
- secgroups = []
1607
- for name in ('foo' , 'bar' ):
1608
- secgroup = security_group .SecurityGroup ()
1609
- secgroup .name = name
1610
- secgroups .append (secgroup )
1611
- fake_secgroups = security_group .SecurityGroupList (objects = secgroups )
1612
- mock_get .return_value = fake_secgroups
1613
- inst = objects .Instance (context = self .context , uuid = uuids .instance )
1614
- secgroups = inst .security_groups
1615
- mock_get .assert_called_once_with (self .context , inst )
1616
- self .assertEqual (fake_secgroups , secgroups )
1617
-
1618
1583
@mock .patch ('nova.objects.PciDeviceList.get_by_instance_uuid' )
1619
1584
def test_load_pci_devices (self , mock_get ):
1620
1585
fake_pci_devices = pci_device .PciDeviceList ()
@@ -1744,7 +1709,6 @@ def fake_instance(self, id, updates=None):
1744
1709
db_inst ['updated_at' ] = None
1745
1710
db_inst ['launched_at' ] = datetime .datetime (1955 , 11 , 12 ,
1746
1711
22 , 4 , 0 )
1747
- db_inst ['security_groups' ] = []
1748
1712
db_inst ['deleted' ] = 0
1749
1713
1750
1714
db_inst ['info_cache' ] = dict (test_instance_info_cache .fake_info_cache ,
@@ -2010,49 +1974,6 @@ def test_fill_faults(self, mock_fault_get):
2010
1974
[x .uuid for x in insts ],
2011
1975
latest = True )
2012
1976
2013
- @mock .patch ('nova.objects.instance.Instance.obj_make_compatible' )
2014
- def test_get_by_security_group (self , mock_compat ):
2015
- fake_secgroup = dict (test_security_group .fake_secgroup )
2016
- fake_secgroup ['instances' ] = [
2017
- fake_instance .fake_db_instance (id = 1 ,
2018
- system_metadata = {'foo' : 'bar' }),
2019
- fake_instance .fake_db_instance (id = 2 ),
2020
- ]
2021
-
2022
- with mock .patch .object (db , 'security_group_get' ) as sgg :
2023
- sgg .return_value = fake_secgroup
2024
- secgroup = security_group .SecurityGroup ()
2025
- secgroup .id = fake_secgroup ['id' ]
2026
- instances = instance .InstanceList .get_by_security_group (
2027
- self .context , secgroup )
2028
-
2029
- self .assertEqual (2 , len (instances ))
2030
- self .assertEqual ([1 , 2 ], [x .id for x in instances ])
2031
- self .assertTrue (instances [0 ].obj_attr_is_set ('system_metadata' ))
2032
- self .assertEqual ({'foo' : 'bar' }, instances [0 ].system_metadata )
2033
-
2034
- def test_get_by_security_group_after_destroy (self ):
2035
- db_sg = db .security_group_create (
2036
- self .context ,
2037
- {'name' : 'foo' ,
2038
- 'description' : 'test group' ,
2039
- 'user_id' : self .context .user_id ,
2040
- 'project_id' : self .context .project_id })
2041
- self .assertFalse (db .security_group_in_use (self .context , db_sg .id ))
2042
- inst = objects .Instance (
2043
- context = self .context ,
2044
- user_id = self .context .user_id ,
2045
- project_id = self .context .project_id )
2046
- inst .create ()
2047
-
2048
- db .instance_add_security_group (self .context ,
2049
- inst .uuid ,
2050
- db_sg .id )
2051
-
2052
- self .assertTrue (db .security_group_in_use (self .context , db_sg .id ))
2053
- inst .destroy ()
2054
- self .assertFalse (db .security_group_in_use (self .context , db_sg .id ))
2055
-
2056
1977
@mock .patch ('nova.db.main.api.instance_get_all_uuids_by_hosts' )
2057
1978
def test_get_uuids_by_host_no_match (self , mock_get_all ):
2058
1979
mock_get_all .return_value = collections .defaultdict (list )
@@ -2159,14 +2080,14 @@ def test_expected_cols_extra(self):
2159
2080
2160
2081
def test_expected_cols_no_duplicates (self ):
2161
2082
expected_attr = ['metadata' , 'system_metadata' , 'info_cache' ,
2162
- 'security_groups' , ' info_cache' , 'metadata' ,
2083
+ 'info_cache' , 'metadata' ,
2163
2084
'pci_devices' , 'tags' , 'extra' , 'flavor' ]
2164
2085
2165
2086
result_list = instance ._expected_cols (expected_attr )
2166
2087
2167
2088
self .assertEqual (len (result_list ), len (set (expected_attr )))
2168
2089
self .assertEqual (['metadata' , 'system_metadata' , 'info_cache' ,
2169
- 'security_groups' , ' pci_devices' , 'tags' , 'extra' ,
2090
+ 'pci_devices' , 'tags' , 'extra' ,
2170
2091
'extra.flavor' ], result_list )
2171
2092
2172
2093
0 commit comments