13
13
from enum import Enum
14
14
15
15
__metaclass__ = type
16
+ BUILDIMAGE_REPO_FLAG = "buildimage"
17
+ MGMT_REPO_FLAG = "sonic-mgmt"
18
+ INTERNAL_REPO_LIST = ["Networking-acs-buildimage" , "sonic-mgmt-int" ]
19
+ GITHUB_SONIC_MGMT_REPO = "https://github.com/sonic-net/sonic-mgmt"
20
+ INTERNAL_SONIC_MGMT_REPO = "https://dev.azure.com/mssonic/internal/_git/sonic-mgmt-int"
16
21
PR_TEST_SCRIPTS_FILE = "pr_test_scripts.yaml"
22
+ SPECIFIC_PARAM_KEYWORD = "specific_param"
17
23
TOLERATE_HTTP_EXCEPTION_TIMES = 20
18
24
TOKEN_EXPIRE_HOURS = 6
19
25
@@ -34,7 +40,10 @@ def get_test_scripts(test_set):
34
40
pr_test_scripts_file = os .path .join (os .path .dirname (_self_path ), PR_TEST_SCRIPTS_FILE )
35
41
with open (pr_test_scripts_file ) as f :
36
42
pr_test_scripts = yaml .safe_load (f )
37
- return pr_test_scripts .get (test_set , [])
43
+
44
+ test_script_list = pr_test_scripts .get (test_set , [])
45
+ specific_param_list = pr_test_scripts .get (SPECIFIC_PARAM_KEYWORD , {}).get (test_set , [])
46
+ return test_script_list , specific_param_list
38
47
39
48
40
49
def test_plan_status_factory (status ):
@@ -69,7 +78,7 @@ def print_logs(self, test_plan_id, resp_data, start_time):
69
78
status = resp_data .get ("status" , None )
70
79
current_status = test_plan_status_factory (status ).get_status ()
71
80
72
- if ( current_status == self .get_status () ):
81
+ if current_status == self .get_status ():
73
82
print ("Test plan id: {}, status: {}, elapsed: {:.0f} seconds"
74
83
.format (test_plan_id , resp_data .get ("status" , None ), time .time () - start_time ))
75
84
@@ -203,20 +212,34 @@ def create(self, topology, test_plan_name="my_test_plan", deploy_mg_extra_params
203
212
print ("Test scripts to be covered in this test plan:" )
204
213
print (json .dumps (scripts , indent = 4 ))
205
214
206
- common_params = ["--completeness_level=confident" , "--allow_recover" ]
207
- for param in common_extra_params :
208
- common_params .append (param )
215
+ common_extra_params = common_extra_params + " --completeness_level=confident --allow_recover"
216
+
217
+ # If triggered by the internal repos, use internal sonic-mgmt repo as the code base
218
+ sonic_mgmt_repo_url = GITHUB_SONIC_MGMT_REPO
219
+ if kwargs .get ("source_repo" ) in INTERNAL_REPO_LIST :
220
+ sonic_mgmt_repo_url = INTERNAL_SONIC_MGMT_REPO
221
+
222
+ # If triggered by mgmt repo, use pull request id as the code base
223
+ sonic_mgmt_pull_request_id = ""
224
+ if MGMT_REPO_FLAG in kwargs .get ("source_repo" ):
225
+ sonic_mgmt_pull_request_id = pr_id
226
+
227
+ # If triggered by buildimage repo, use image built from the buildId
228
+ kvm_image_build_id = kvm_build_id
229
+ if BUILDIMAGE_REPO_FLAG in kwargs .get ("source_repo" ):
230
+ kvm_image_build_id = build_id
209
231
210
232
payload = json .dumps ({
211
233
"name" : test_plan_name ,
212
234
"testbed" : {
213
235
"platform" : platform ,
214
236
"name" : testbed_name ,
215
237
"topology" : topology ,
216
- "image_url" : image_url ,
217
238
"hwsku" : hwsku ,
218
239
"min" : min_worker ,
219
- "max" : max_worker
240
+ "max" : max_worker ,
241
+ "nbr_type" : kwargs ["vm_type" ],
242
+ "asic_num" : kwargs ["num_asic" ]
220
243
},
221
244
"test_option" : {
222
245
"stop_on_failure" : kwargs .get ("stop_on_failure" , True ),
@@ -227,30 +250,36 @@ def create(self, topology, test_plan_name="my_test_plan", deploy_mg_extra_params
227
250
"features_exclude" : features_exclude ,
228
251
"scripts_exclude" : scripts_exclude
229
252
},
230
- "common_params" : common_params ,
231
- "specified_params" : json .loads (kwargs ['specified_params' ]),
232
- "deploy_mg_params" : deploy_mg_extra_params
253
+ "image" : {
254
+ "url" : image_url ,
255
+ "release" : "" ,
256
+ "kvm_image_build_id" : kvm_image_build_id
257
+ },
258
+ "sonic_mgmt" : {
259
+ "repo_url" : sonic_mgmt_repo_url ,
260
+ "branch" : kwargs ["mgmt_branch" ],
261
+ "pull_request_id" : sonic_mgmt_pull_request_id
262
+ },
263
+ "common_param" : common_extra_params ,
264
+ "specific_param" : kwargs .get ("specific_param" , []),
265
+ "deploy_mg_param" : deploy_mg_extra_params ,
266
+ "max_execute_seconds" : kwargs .get ("max_execute_seconds" , None ),
267
+ "dump_kvm_if_fail" : kwargs .get ("dump_kvm_if_fail" , False ),
233
268
},
234
269
"type" : test_plan_type ,
235
- "extra_params" : {
236
- "pull_request_id" : pr_id ,
237
- "build_id" : build_id ,
270
+ "trigger" : {
271
+ "requester" : kwargs .get ("requester" , "Pull Request" ),
238
272
"source_repo" : kwargs .get ("source_repo" ),
239
- "kvm_build_id" : kvm_build_id ,
240
- "max_execute_seconds" : kwargs .get ("max_execute_seconds" , None ),
241
- "dump_kvm_if_fail" : kwargs .get ("dump_kvm_if_fail" , 2 ),
242
- "mgmt_branch" : kwargs ["mgmt_branch" ],
243
- "testbed" : {
244
- "num_asic" : kwargs ["num_asic" ],
245
- "vm_type" : kwargs ["vm_type" ]
246
- },
273
+ "pull_request_id" : pr_id ,
274
+ "build_id" : build_id
275
+ },
276
+ "extra_params" : {
247
277
"secrets" : {
248
278
"azp_access_token" : kwargs ["azp_access_token" ],
249
279
"azp_repo_access_token" : kwargs ["azp_repo_access_token" ],
250
280
}
251
281
},
252
- "priority" : 10 ,
253
- "requester" : kwargs .get ("requester" , "Pull Request" )
282
+ "priority" : 10
254
283
})
255
284
print ('Creating test plan with payload: {}' .format (payload ))
256
285
headers = {
@@ -351,11 +380,8 @@ def poll(self, test_plan_id, interval=60, timeout=-1, expected_state=""):
351
380
elif expected_status .get_status () < current_status .get_status ():
352
381
steps = None
353
382
step_status = None
354
- extra_params = resp_data .get ("extra_params" , None )
355
383
runtime = resp_data .get ("runtime" , None )
356
- if extra_params and "steps" in extra_params :
357
- steps = extra_params .get ("steps" , None )
358
- else :
384
+ if runtime :
359
385
steps = runtime .get ("steps" , None )
360
386
if steps :
361
387
for step in steps :
@@ -485,8 +511,9 @@ def poll(self, test_plan_id, interval=60, timeout=-1, expected_state=""):
485
511
"--common-extra-params" ,
486
512
type = str ,
487
513
dest = "common_extra_params" ,
514
+ nargs = '?' ,
515
+ const = "" ,
488
516
default = "" ,
489
- nargs = '*' ,
490
517
required = False ,
491
518
help = "Run test common extra params"
492
519
)
@@ -769,10 +796,12 @@ def poll(self, test_plan_id, interval=60, timeout=-1, expected_state=""):
769
796
).replace (' ' , '_' )
770
797
771
798
scripts = args .scripts
799
+ specific_param = []
772
800
# For KVM PR test, get test modules from pr_test_scripts.yaml, otherwise use args.scripts
773
801
if args .platform == "kvm" :
774
802
args .test_set = args .test_set if args .test_set else args .topology
775
- scripts = "," .join (get_test_scripts (args .test_set ))
803
+ scripts , specific_param = get_test_scripts (args .test_set )
804
+ scripts = "," .join (scripts )
776
805
777
806
tp .create (
778
807
args .topology ,
@@ -792,6 +821,7 @@ def poll(self, test_plan_id, interval=60, timeout=-1, expected_state=""):
792
821
common_extra_params = args .common_extra_params ,
793
822
num_asic = args .num_asic ,
794
823
specified_params = args .specified_params ,
824
+ specific_param = specific_param ,
795
825
vm_type = args .vm_type ,
796
826
azp_access_token = args .azp_access_token ,
797
827
azp_repo_access_token = args .azp_repo_access_token ,
0 commit comments