@@ -33,6 +33,8 @@ def setUp(self):
33
33
self .ip_list = "ip_list_token"
34
34
self .ip_str = "ip_str_token"
35
35
self .ip_strs = "ip1_str_token, ip2_str_token"
36
+ self .host_id_str = "225"
37
+ self .host_id_strs = "225,286"
36
38
self .list_biz_hosts_topo_return = [
37
39
{
38
40
"host" : {
@@ -111,7 +113,8 @@ def setUp(self):
111
113
},
112
114
],
113
115
},
114
- ]
116
+ ],
117
+ "count" : 2 ,
115
118
},
116
119
}
117
120
self .get_business_host_topo_expect_return = [
@@ -142,12 +145,42 @@ def setUp(self):
142
145
],
143
146
},
144
147
]
148
+ self .get_filter_business_host_topo_expect_return = (
149
+ [
150
+ {
151
+ "host" : {
152
+ "bk_cloud_id" : 0 ,
153
+ "bk_host_id" : 1 ,
154
+ "bk_host_innerip" : "127.0.0.1" ,
155
+ "bk_mac" : "" ,
156
+ "bk_os_type" : None ,
157
+ },
158
+ "set" : [{"bk_set_id" : 11 , "bk_set_name" : "set1" }],
159
+ "module" : [{"bk_module_id" : 56 , "bk_module_name" : "m1" }],
160
+ },
161
+ {
162
+ "host" : {
163
+ "bk_cloud_id" : 0 ,
164
+ "bk_host_id" : 3 ,
165
+ "bk_host_innerip" : "127.0.0.3" ,
166
+ "bk_mac" : "" ,
167
+ "bk_os_type" : None ,
168
+ },
169
+ "set" : [{"bk_set_id" : 10 , "bk_set_name" : "空闲机池" }, {"bk_set_id" : 11 , "bk_set_name" : "set1" }],
170
+ "module" : [
171
+ {"bk_module_id" : 54 , "bk_module_name" : "空闲机" },
172
+ {"bk_module_id" : 55 , "bk_module_name" : "空闲机1" },
173
+ {"bk_module_id" : 56 , "bk_module_name" : "m1" },
174
+ ],
175
+ },
176
+ ],
177
+ 2 ,
178
+ )
145
179
146
180
def tearDown (self ):
147
181
self .get_client_by_user_patcher .stop ()
148
182
149
183
def test__list_biz_hosts_topo_return_empty (self ):
150
-
151
184
mock_batch_request = MagicMock (return_value = [])
152
185
with patch ("gcloud.utils.cmdb.batch_request" , mock_batch_request ):
153
186
hosts_topo = get_business_host_topo (self .username , self .bk_biz_id , self .supplier_account , self .host_fields )
@@ -202,15 +235,16 @@ def test__get_contains_with_ip_list(self):
202
235
ip_str = self .ip_str ,
203
236
)
204
237
205
- self .assertEqual (hosts_topo , self .get_business_host_topo_expect_return )
238
+ self .assertEqual (hosts_topo , self .get_filter_business_host_topo_expect_return )
206
239
self .mock_client .cc .list_biz_hosts_topo .assert_called_once_with (
207
240
{
208
241
"bk_biz_id" : self .bk_biz_id ,
209
242
"bk_supplier_account" : self .supplier_account ,
210
243
"fields" : self .host_fields ,
211
244
"host_property_filter" : {
212
245
"condition" : "OR" ,
213
- "rules" : [{"field" : "bk_host_innerip" , "operator" : "contains" , "value" : self .ip_str }],
246
+ "rules" : [{"field" : "bk_host_innerip_v6" , "operator" : "contains" , "value" : self .ip_str }]
247
+ + [{"field" : "bk_host_innerip" , "operator" : "contains" , "value" : self .ip_str }],
214
248
},
215
249
"page" : {"start" : 0 , "limit" : 10 },
216
250
},
@@ -228,7 +262,7 @@ def test__get_many_contains_with_ip_list(self):
228
262
ip_str = self .ip_strs ,
229
263
)
230
264
231
- self .assertEqual (hosts_topo , self .get_business_host_topo_expect_return )
265
+ self .assertEqual (hosts_topo , self .get_filter_business_host_topo_expect_return )
232
266
self .mock_client .cc .list_biz_hosts_topo .assert_called_once_with (
233
267
{
234
268
"bk_biz_id" : self .bk_biz_id ,
@@ -237,8 +271,12 @@ def test__get_many_contains_with_ip_list(self):
237
271
"host_property_filter" : {
238
272
"condition" : "OR" ,
239
273
"rules" : [
240
- {"field" : "bk_host_innerip" , "operator" : "contains" , "value" : self .ip_str }
241
- for self .ip_str in self .ip_strs .split ("," )
274
+ {"field" : "bk_host_innerip_v6" , "operator" : "contains" , "value" : ip_str }
275
+ for ip_str in self .ip_strs .split ("," )
276
+ ]
277
+ + [
278
+ {"field" : "bk_host_innerip" , "operator" : "contains" , "value" : ip_str }
279
+ for ip_str in self .ip_strs .split ("," )
242
280
],
243
281
},
244
282
"page" : {"start" : 0 , "limit" : 10 },
@@ -251,12 +289,70 @@ def test__get_with_page_list(self):
251
289
self .username , self .bk_biz_id , self .supplier_account , self .host_fields , start = 0 , limit = 10
252
290
)
253
291
254
- self .assertEqual (hosts_topo , self .get_business_host_topo_expect_return )
292
+ self .assertEqual (hosts_topo , self .get_filter_business_host_topo_expect_return )
255
293
self .mock_client .cc .list_biz_hosts_topo .assert_called_once_with (
256
294
{
257
295
"bk_biz_id" : self .bk_biz_id ,
258
296
"bk_supplier_account" : self .supplier_account ,
259
297
"fields" : self .host_fields ,
260
298
"page" : {"start" : 0 , "limit" : 10 },
261
- },
299
+ }
300
+ )
301
+
302
+ def test_get_equal_host_list (self ):
303
+ self .mock_client .cc .list_biz_hosts_topo = MagicMock (return_value = self .list_biz_hosts_page_topo_return )
304
+ hosts_topo = get_filter_business_host_topo (
305
+ self .username ,
306
+ self .bk_biz_id ,
307
+ self .supplier_account ,
308
+ self .host_fields ,
309
+ start = 0 ,
310
+ limit = 10 ,
311
+ host_id_str = self .host_id_str ,
312
+ )
313
+
314
+ self .assertEqual (hosts_topo , self .get_filter_business_host_topo_expect_return )
315
+ self .mock_client .cc .list_biz_hosts_topo .assert_called_once_with (
316
+ {
317
+ "bk_biz_id" : self .bk_biz_id ,
318
+ "bk_supplier_account" : self .supplier_account ,
319
+ "fields" : self .host_fields ,
320
+ "host_property_filter" : {
321
+ "condition" : "OR" ,
322
+ "rules" : [{"field" : "bk_host_id" , "operator" : "in" , "value" : [int (self .host_id_str )]}],
323
+ },
324
+ "page" : {"start" : 0 , "limit" : 10 },
325
+ }
326
+ )
327
+
328
+ def test_get_many_equal_host_list (self ):
329
+ self .mock_client .cc .list_biz_hosts_topo = MagicMock (return_value = self .list_biz_hosts_page_topo_return )
330
+ hosts_topo = get_filter_business_host_topo (
331
+ self .username ,
332
+ self .bk_biz_id ,
333
+ self .supplier_account ,
334
+ self .host_fields ,
335
+ start = 0 ,
336
+ limit = 10 ,
337
+ host_id_str = self .host_id_strs ,
338
+ )
339
+
340
+ self .assertEqual (hosts_topo , self .get_filter_business_host_topo_expect_return )
341
+ self .mock_client .cc .list_biz_hosts_topo .assert_called_once_with (
342
+ {
343
+ "bk_biz_id" : self .bk_biz_id ,
344
+ "bk_supplier_account" : self .supplier_account ,
345
+ "fields" : self .host_fields ,
346
+ "host_property_filter" : {
347
+ "condition" : "OR" ,
348
+ "rules" : [
349
+ {
350
+ "field" : "bk_host_id" ,
351
+ "operator" : "in" ,
352
+ "value" : [int (host_id ) for host_id in self .host_id_strs .split ("," )],
353
+ }
354
+ ],
355
+ },
356
+ "page" : {"start" : 0 , "limit" : 10 },
357
+ }
262
358
)
0 commit comments