@@ -362,7 +362,8 @@ def test_resources_from_request_spec_no_aggregates(self):
362
362
self .context , reqspec , self .mock_host_manager )
363
363
self .assertEqual ([], req .get_request_group (None ).aggregates )
364
364
365
- @mock .patch ("nova.scheduler.utils.ResourceRequest.from_extra_specs" )
365
+ @mock .patch ("nova.scheduler.utils.ResourceRequest.from_extra_specs" ,
366
+ return_value = utils .ResourceRequest ())
366
367
def test_process_extra_specs_granular_called (self , mock_proc ):
367
368
flavor = objects .Flavor (vcpus = 1 ,
368
369
memory_mb = 1024 ,
@@ -794,20 +795,6 @@ def test_resource_request_from_extra_specs(self):
794
795
)
795
796
self .assertEqual (expected_querystring , rr .to_querystring ())
796
797
797
- def test_more_than_one_resource_request_without_group_policy_warns (self ):
798
- extra_specs = {
799
- 'resources:VCPU' : '2' ,
800
- 'resources1:CUSTOM_FOO' : '1'
801
- }
802
- rr = utils .ResourceRequest .from_extra_specs (extra_specs )
803
- rr .add_request_group (objects .RequestGroup (resources = {'CUSTOM_BAR' : 5 }))
804
-
805
- rr .to_querystring ()
806
- self .assertIn (
807
- "There is more than one numbered request group in the allocation "
808
- "candidate query but the flavor did not specify any group policy." ,
809
- self .stdlog .logger .output )
810
-
811
798
def test_resource_request_from_extra_specs_append_request (self ):
812
799
extra_specs = {
813
800
'resources:VCPU' : '2' ,
@@ -1138,3 +1125,154 @@ def test_get_weight_multiplier(self):
1138
1125
1.8 ,
1139
1126
utils .get_weight_multiplier (host1 , 'cpu_weight_multiplier' , 1.0 )
1140
1127
)
1128
+
1129
+
1130
+ class TestResourcesFromRequestGroupDefaultPolicy (test .NoDBTestCase ):
1131
+ """These test cases assert what happens when the group policy is missing
1132
+ from the flavor but more than one numbered request group is requested from
1133
+ various sources. Note that while image can provide required traits for the
1134
+ resource request those traits are always added to the unnumbered group so
1135
+ image cannot be a source of additional numbered groups.
1136
+ """
1137
+
1138
+ def setUp (self ):
1139
+ super (TestResourcesFromRequestGroupDefaultPolicy , self ).setUp ()
1140
+ self .context = nova_context .get_admin_context ()
1141
+ self .port_group1 = objects .RequestGroup .from_port_request (
1142
+ self .context , uuids .port1 ,
1143
+ port_resource_request = {
1144
+ "resources" : {
1145
+ "NET_BW_IGR_KILOBIT_PER_SEC" : 1000 ,
1146
+ "NET_BW_EGR_KILOBIT_PER_SEC" : 1000 },
1147
+ "required" : ["CUSTOM_PHYSNET_2" ,
1148
+ "CUSTOM_VNIC_TYPE_NORMAL" ]
1149
+ })
1150
+ self .port_group2 = objects .RequestGroup .from_port_request (
1151
+ self .context , uuids .port2 ,
1152
+ port_resource_request = {
1153
+ "resources" : {
1154
+ "NET_BW_IGR_KILOBIT_PER_SEC" : 2000 ,
1155
+ "NET_BW_EGR_KILOBIT_PER_SEC" : 2000 },
1156
+ "required" : ["CUSTOM_PHYSNET_3" ,
1157
+ "CUSTOM_VNIC_TYPE_DIRECT" ]
1158
+ })
1159
+
1160
+ def test_one_group_from_flavor_dont_warn (self ):
1161
+ flavor = objects .Flavor (
1162
+ vcpus = 1 , memory_mb = 1024 , root_gb = 10 , ephemeral_gb = 5 , swap = 0 ,
1163
+ extra_specs = {
1164
+ 'resources1:CUSTOM_BAR' : '2' ,
1165
+ })
1166
+ request_spec = objects .RequestSpec (
1167
+ flavor = flavor , image = objects .ImageMeta (), requested_resources = [])
1168
+
1169
+ rr = utils .resources_from_request_spec (
1170
+ self .context , request_spec , host_manager = mock .Mock ())
1171
+
1172
+ log = self .stdlog .logger .output
1173
+ self .assertNotIn (
1174
+ "There is more than one numbered request group in the allocation "
1175
+ "candidate query but the flavor did not specify any group policy." ,
1176
+ log )
1177
+ self .assertNotIn (
1178
+ "To avoid the placement failure nova defaults the group policy to "
1179
+ "'none'." ,
1180
+ log )
1181
+ self .assertIsNone (rr .group_policy )
1182
+ self .assertNotIn ('group_policy=none' , rr .to_querystring ())
1183
+
1184
+ def test_one_group_from_port_dont_warn (self ):
1185
+ flavor = objects .Flavor (
1186
+ vcpus = 1 , memory_mb = 1024 , root_gb = 10 , ephemeral_gb = 5 , swap = 0 ,
1187
+ extra_specs = {})
1188
+ request_spec = objects .RequestSpec (
1189
+ flavor = flavor , image = objects .ImageMeta (),
1190
+ requested_resources = [self .port_group1 ])
1191
+
1192
+ rr = utils .resources_from_request_spec (
1193
+ self .context , request_spec , host_manager = mock .Mock ())
1194
+
1195
+ log = self .stdlog .logger .output
1196
+ self .assertNotIn (
1197
+ "There is more than one numbered request group in the allocation "
1198
+ "candidate query but the flavor did not specify any group policy." ,
1199
+ log )
1200
+ self .assertNotIn (
1201
+ "To avoid the placement failure nova defaults the group policy to "
1202
+ "'none'." ,
1203
+ log )
1204
+ self .assertIsNone (rr .group_policy )
1205
+ self .assertNotIn ('group_policy=none' , rr .to_querystring ())
1206
+
1207
+ def test_two_groups_from_flavor_only_warns (self ):
1208
+ flavor = objects .Flavor (
1209
+ vcpus = 1 , memory_mb = 1024 , root_gb = 10 , ephemeral_gb = 5 , swap = 0 ,
1210
+ extra_specs = {
1211
+ 'resources1:CUSTOM_BAR' : '2' ,
1212
+ 'resources2:CUSTOM_FOO' : '1'
1213
+ })
1214
+ request_spec = objects .RequestSpec (
1215
+ flavor = flavor , image = objects .ImageMeta (), requested_resources = [])
1216
+
1217
+ rr = utils .resources_from_request_spec (
1218
+ self .context , request_spec , host_manager = mock .Mock ())
1219
+
1220
+ log = self .stdlog .logger .output
1221
+ self .assertIn (
1222
+ "There is more than one numbered request group in the allocation "
1223
+ "candidate query but the flavor did not specify any group policy." ,
1224
+ log )
1225
+ self .assertNotIn (
1226
+ "To avoid the placement failure nova defaults the group policy to "
1227
+ "'none'." ,
1228
+ log )
1229
+ self .assertIsNone (rr .group_policy )
1230
+ self .assertNotIn ('group_policy' , rr .to_querystring ())
1231
+
1232
+ def test_one_group_from_flavor_one_from_port_policy_defaulted (self ):
1233
+ flavor = objects .Flavor (
1234
+ vcpus = 1 , memory_mb = 1024 , root_gb = 10 , ephemeral_gb = 5 , swap = 0 ,
1235
+ extra_specs = {
1236
+ 'resources1:CUSTOM_BAR' : '2' ,
1237
+ })
1238
+ request_spec = objects .RequestSpec (
1239
+ flavor = flavor , image = objects .ImageMeta (),
1240
+ requested_resources = [self .port_group1 ])
1241
+
1242
+ rr = utils .resources_from_request_spec (
1243
+ self .context , request_spec , host_manager = mock .Mock ())
1244
+
1245
+ log = self .stdlog .logger .output
1246
+ self .assertIn (
1247
+ "There is more than one numbered request group in the allocation "
1248
+ "candidate query but the flavor did not specify any group policy." ,
1249
+ log )
1250
+ self .assertIn (
1251
+ "To avoid the placement failure nova defaults the group policy to "
1252
+ "'none'." ,
1253
+ log )
1254
+ self .assertEqual ('none' , rr .group_policy )
1255
+ self .assertIn ('group_policy=none' , rr .to_querystring ())
1256
+
1257
+ def test_two_groups_from_ports_policy_defaulted (self ):
1258
+ flavor = objects .Flavor (
1259
+ vcpus = 1 , memory_mb = 1024 , root_gb = 10 , ephemeral_gb = 5 , swap = 0 ,
1260
+ extra_specs = {})
1261
+ request_spec = objects .RequestSpec (
1262
+ flavor = flavor , image = objects .ImageMeta (),
1263
+ requested_resources = [self .port_group1 , self .port_group2 ])
1264
+
1265
+ rr = utils .resources_from_request_spec (
1266
+ self .context , request_spec , host_manager = mock .Mock ())
1267
+
1268
+ log = self .stdlog .logger .output
1269
+ self .assertIn (
1270
+ "There is more than one numbered request group in the allocation "
1271
+ "candidate query but the flavor did not specify any group policy." ,
1272
+ log )
1273
+ self .assertIn (
1274
+ "To avoid the placement failure nova defaults the group policy to "
1275
+ "'none'." ,
1276
+ log )
1277
+ self .assertEqual ('none' , rr .group_policy )
1278
+ self .assertIn ('group_policy=none' , rr .to_querystring ())
0 commit comments