Best Python code snippet using autotest_python
topo_latest.py
Source:topo_latest.py
...17 for i in range(num):18 routers.append(self.addSwitch('r000%s' %(i + 1)))19 20 # Add hosts with specific number21 def add_hosts(self, label, router, num = 1):22 for i in range(num):23 host = self.addHost(label %(i + 1))24 self.addLink(host, router)25 # Add nodes with specific number26 def add_nodes(self, nodes, label, num = 1):27 for i in range(num):28 nodes.append(self.addSwitch(label %(i + 1)))29 # Create topos connected to WuTang-->routers[1]30 def create_wt(self, router):31 # link0: Add 1 host to WuTang32 self.add_hosts('wt%s', router, 1)33 34 # link1: Add 8 nodes and corresponding links between them35 num_1 = 836 wt_1 = []37 # 1100: 1-->router order 1-->link order 0-->add nodes(0) or hosts(1) 0--> specific node(0:Switch or Invalid)38 self.add_nodes(wt_1, 'wt_1100%s', num_1)39 self.addLink(wt_1[0], router)40 self.addLink(wt_1[0], wt_1[1]) # node_0 <--> node_141 self.addLink(wt_1[1], wt_1[2]) # node_1 <--> node_242 self.addLink(wt_1[2], wt_1[3]) # node_2 <--> node_343 self.addLink(wt_1[2], wt_1[4])44 self.addLink(wt_1[1], wt_1[5]) # node_1 <--> node_545 self.addLink(wt_1[5], wt_1[6]) # node_5 <--> node_646 self.addLink(wt_1[6], wt_1[7]) # node_6 <--> node_747 # Add hosts connected to each node48 self.add_hosts('wt_1111%s', wt_1[0], 2) # Add 2 hosts to node_049 self.add_hosts('wt_1112%s', wt_1[1], 3) # Add 3 hosts to node_150 self.add_hosts('wt_1113%s', wt_1[2], 3) # Add 3 hosts to node_251 self.add_hosts('wt_1114%s', wt_1[3], 3) # Add 3 hosts to node_352 self.add_hosts('wt_1115%s', wt_1[4], 3) # Add 3 hosts to node_453 self.add_hosts('wt_1116%s', wt_1[5], 7) # Add 7 hosts to node_554 self.add_hosts('wt_1117%s', wt_1[6], 4) # Add 4 hosts to node_655 self.add_hosts('wt_1118%s', wt_1[7], 3) # Add 3 hosts to node_756 57 # link2: Add 8 nodes and corresponding links between them58 num_2 = 859 wt_2 = []60 self.add_nodes(wt_2, 'wt_1200%s', num_2)61 self.addLink(wt_2[0], router)62 self.addLink(wt_2[0], wt_2[1]) # node_47 <--> node_4863 self.addLink(wt_2[0], wt_2[2]) # node_47 <--> node_4964 self.addLink(wt_2[2], wt_2[3]) # node_49 <--> node_5065 self.addLink(wt_2[2], wt_2[5]) # node_49 <--> node_5266 self.addLink(wt_2[3], wt_2[4]) # node_50 <--> node_5167 self.addLink(wt_2[4], wt_2[6]) # node_51 <--> node_5368 self.addLink(wt_2[4], wt_2[7]) # node_51 <--> node_5469 # Add hosts connected to each node70 self.add_hosts('wt_1211%s', wt_2[0], 2) # Add 2 hosts to node_4771 self.add_hosts('wt_1212%s', wt_2[1], 2) # Add 2 hosts to node_4872 self.add_hosts('wt_1213%s', wt_2[2], 4) # Add 4 hosts to node_4973 self.add_hosts('wt_1214%s', wt_2[3], 14) # Add 14 hosts to node_5074 self.add_hosts('wt_1215%s', wt_2[4], 3) # Add 3 hosts to node_5175 self.add_hosts('wt_1216%s', wt_2[5], 2) # Add 2 hosts to node_5276 self.add_hosts('wt_1217%s', wt_2[6], 6) # Add 6 hosts to node_5377 self.add_hosts('wt_1218%s', wt_2[7], 2) # Add 2 hosts to node_5478 # link3: Add 14 nodes and corresponding links between them79 num_3 = 1380 wt_3 = [] 81 self.add_nodes(wt_3, 'wt_1300%s', num_3)82 self.addLink(wt_3[0], router) 83 self.addLink(wt_3[0], wt_3[1]) # node_33 <--> node_3484 self.addLink(wt_3[0], wt_3[2]) # node_33 <--> node_3585 self.addLink(wt_3[0], wt_3[3]) # node_33 <--> node_3686 self.addLink(wt_3[2], wt_3[5]) # node_35 <--> node_3887 self.addLink(wt_3[2], wt_3[6]) # node_35 <--> node_39 88 self.addLink(wt_3[5], wt_3[7]) # node_38 <--> node_40 89 self.addLink(wt_3[6], wt_3[8]) # node_39 <--> node_4190 self.addLink(wt_3[7], wt_3[10]) # node_40 <--> node_4391 self.addLink(wt_3[8], wt_3[11]) # node_41 <--> node_4492 self.addLink(wt_3[10], wt_3[12]) # node_43 <--> node_4593 self.addLink(wt_3[12], wt_3[9]) # node_45 <--> node_4294 self.addLink(wt_3[3], wt_3[4]) # node_36 <--> node_3795 # Add hosts connected to each node96 self.add_hosts('wt_1311%s', wt_3[0], 2) # Add 2 hosts to node_3397 self.add_hosts('wt_1312%s', wt_3[1], 11) # Add 11 hosts to node_3498 self.add_hosts('wt_1313%s', wt_3[2], 5) # Add 5 hosts to node_3599 self.add_hosts('wt_1314%s', wt_3[3], 5) # Add 5 hosts to node_36100 self.add_hosts('wt_1315%s', wt_3[4], 4) # Add 4 hosts to node_37101 self.add_hosts('wt_1316%s', wt_3[5], 6) # Add 6 hosts to node_38102 self.add_hosts('wt_1317%s', wt_3[6], 10) # Add 10 hosts to node_39103 self.add_hosts('wt_1318%s', wt_3[7], 6) # Add 6 hosts to node_40104 self.add_hosts('wt_1319%s', wt_3[8], 12) # Add 12 hosts to node_41105 self.add_hosts('wt_13110%s', wt_3[9], 14) # Add 14 hosts to node_42106 self.add_hosts('wt_13111%s', wt_3[10], 10) # Add 10 hosts to node_43107 self.add_hosts('wt_13112%s', wt_3[11], 10) # Add 10 hosts to node_44108 self.add_hosts('wt_13113%s', wt_3[12], 3) # Add 3 hosts to node_45109 # Create topos connected to HuangShi-->routers[110 def create_lb(self, router):111 # link1: Add 4 nodes and corresponding links between them112 lb_1 = []113 num_1 = 4114 self.add_nodes(lb_1, 'lb_3100%s', num_1)115 self.addLink(lb_1[0], router)116 self.addLink(lb_1[0], lb_1[1]) # node_64<-->node_65117 self.addLink(lb_1[1], lb_1[2]) # node_65<-->node_66118 self.addLink(lb_1[1], lb_1[3]) # node_65<-->node_67119 # Add hosts connected to each node120 self.add_hosts('lb_3111%s', lb_1[0], 6) # Add 6 hosts to node_64121 self.add_hosts('lb_3112%s', lb_1[1], 4) # Add 4 hosts to node_65122 self.add_hosts('lb_3113%s', lb_1[2], 1) # Add 1 host to node_66123 self.add_hosts('lb_3114%s', lb_1[3], 5) # Add 5 hosts to node_67124 # link2: Add 6 nodes and corresponding links between them125 num_2 = 6126 lb_2 = []127 self.add_nodes(lb_2, 'lb_3200%s', num_2)128 self.addLink(lb_2[0], router)129 self.addLink(lb_2[0], lb_2[1]) # node_68<-->node_69130 self.addLink(lb_2[1], lb_2[2]) # node_69<-->node_70131 self.addLink(lb_2[1], lb_2[3]) # node_69<-->node_71132 self.addLink(lb_2[2], lb_2[4]) # node_70<-->node_72133 self.addLink(lb_2[2], lb_2[5]) # node_70<-->node_73134 # Add hosts connected to each node135 self.add_hosts('lb_3211%s', lb_2[0], 2) # Add 2 hosts to node_68136 self.add_hosts('lb_3212%s', lb_2[1], 5) # Add 5 hosts to node_69137 self.add_hosts('lb_3213%s', lb_2[2], 4) # Add 4 hosts to node_70138 self.add_hosts('lb_3214%s', lb_2[3], 6) # Add 6 hosts to node_71139 self.add_hosts('lb_3215%s', lb_2[4], 6) # Add 6 hosts to node_72140 self.add_hosts('lb_3216%s', lb_2[5], 5) # Add 5 hosts to node_73141 # link3: Add 9 nodes and corresponding links between them142 num_3 = 9143 lb_3 = []144 self.add_nodes(lb_3, 'lb_3300%s', num_3)145 self.addLink(lb_3[0], router)146 self.addLink(lb_3[0], lb_3[1]) # node_55<-->node_56147 self.addLink(lb_3[1], lb_3[5]) # node_56<-->node_60148 self.addLink(lb_3[1], lb_3[6]) # node_56<-->node_61149 self.addLink(lb_3[5], lb_3[8]) # node_60<-->node_63150 self.addLink(lb_3[6], lb_3[7]) # node_61<-->node_62151 self.addLink(lb_3[0], lb_3[3]) # node_55<-->node_58152 self.addLink(lb_3[3], lb_3[2]) # node_58<-->node_57153 self.addLink(lb_3[3], lb_3[4]) # node_58<-->node_59154 # Add hosts connected to each node155 self.add_hosts('lb_3311%s', lb_3[0], 8) # Add 8 hosts to node_55156 self.add_hosts('lb_3312%s', lb_3[1], 2) # Add 2 hosts to node_56157 self.add_hosts('lb_3313%s', lb_3[2], 6) # Add 6 hosts to node_57158 self.add_hosts('lb_3314%s', lb_3[3], 16) # Add 16 hosts to node_58159 self.add_hosts('lb_3315%s', lb_3[4], 6) # Add 6 hosts to node_59160 self.add_hosts('lb_3316%s', lb_3[5], 6) # Add 6 hosts to node_60161 self.add_hosts('lb_3317%s', lb_3[6], 12) # Add 12 hosts to node_61162 self.add_hosts('lb_3318%s', lb_3[7], 6) # Add 6 hosts to node_62163 self.add_hosts('lb_3319%s', lb_3[8], 6) # Add 6 hosts to node_63164 # link4: Add 12 nodes and corresponding links between them165 num_4 = 12166 lb_4 = []167 self.add_nodes(lb_4, 'lb_3400%s', num_4)168 self.addLink(lb_4[0], router)169 self.addLink(lb_4[0], lb_4[1]) # node_74<-->node_75170 self.addLink(lb_4[1], lb_4[3]) # node_75<-->node_77171 self.addLink(lb_4[3], lb_4[9]) # node_77<-->node_83172 self.addLink(lb_4[9], lb_4[7]) # node_83<-->node_81173 self.addLink(lb_4[7], lb_4[11]) # node_81<-->node_85174 self.addLink(lb_4[9], lb_4[8]) # node_83<-->node_82175 self.addLink(lb_4[0], lb_4[2]) # node_74<-->node_76176 self.addLink(lb_4[2], lb_4[10]) # node_76<-->node_84177 self.addLink(lb_4[0], lb_4[4]) # node_74<-->node_78178 self.addLink(lb_4[4], lb_4[5]) # node_78<-->node_79179 self.addLink(lb_4[4], lb_4[6]) # node_78<-->node_80180 # Add hosts to each node181 self.add_hosts('lb_3411%s', lb_4[0], 3) # Add 3 hosts to node_74182 self.add_hosts('lb_3412%s', lb_4[1], 1) # Add 1 hosts to node_75183 self.add_hosts('lb_3413%s', lb_4[2], 4) # Add 4 hosts to node_76184 self.add_hosts('lb_3414%s', lb_4[3], 10) # Add 10 hosts to node_77185 self.add_hosts('lb_3415%s', lb_4[4], 4) # Add 4 hosts to node_78186 self.add_hosts('lb_3416%s', lb_4[5], 5) # Add 5 hosts to node_79187 self.add_hosts('lb_3417%s', lb_4[6], 5) # Add 5 hosts to node_80188 self.add_hosts('lb_3418%s', lb_4[7], 7) # Add 7 hosts to node_81189 self.add_hosts('lb_3419%s', lb_4[8], 5) # Add 5 hosts to node_82190 self.add_hosts('lb_34110%s', lb_4[9], 1) # Add 1 hosts to node_83191 self.add_hosts('lb_34111%s', lb_4[10], 1) # Add 1 hosts to node_84192 self.add_hosts('lb_34112%s', lb_4[11], 2) # Add 2 hosts to node_85193 def create_hs(self, router):194 # link1: Add 1 node connected to the switch195 num_1 = 1196 hs_1 = []197 self.add_nodes(hs_1, 'hs_7100%s', num_1) # node_87198 self.addLink(hs_1[0], router)199 # link2: Add 7 nodes and corresponding links between them200 num_2 = 7201 hs_2 = [] 202 self.add_nodes(hs_2, 'hs_7200%s', num_2)203 self.addLink(hs_2[0], router)204 self.addLink(hs_2[0], hs_2[1]) # node_8 <--> node_9205 self.addLink(hs_2[1], hs_2[2]) # node_9 <--> node_10206 self.addLink(hs_2[1], hs_2[3]) # node_9 <--> node_11207 self.addLink(hs_2[1], hs_2[4]) # node_9 <--> node_12208 self.addLink(hs_2[2], hs_2[6]) # node_10 <--> node_14209 self.addLink(hs_2[4], hs_2[5]) # node_12 <--> node_13210 # Add hosts connected to each node211 self.add_hosts('hs_7211%s', hs_2[0], 4) # Add 4 hosts to node_8212 self.add_hosts('hs_7212%s', hs_2[1], 4) # Add 4 hosts to node_9213 self.add_hosts('hs_7213%s', hs_2[2], 3) # Add 3 hosts to node_10214 self.add_hosts('hs_7214%s', hs_2[3], 5) # Add 5 hosts to node_11215 self.add_hosts('hs_7215%s', hs_2[4], 6) # Add 6 hosts to node_12216 self.add_hosts('hs_7216%s', hs_2[5], 1) # Add 1 host to node_13217 self.add_hosts('hs_7217%s', hs_2[6], 5) # Add 5 hosts to node_14218 # link3: Add 9 nodes and corresponding links between them219 num_3 = 9220 hs_3 = []221 self.add_nodes(hs_3, 'hs_7300%s', num_3)222 self.addLink(hs_3[0], router)223 self.addLink(hs_3[0], hs_3[1]) # node_16 <--> node_17224 self.addLink(hs_3[0], hs_3[2]) # node_16 <--> node_18225 self.addLink(hs_3[1], hs_3[3]) # node_17 <--> node_19226 self.addLink(hs_3[3], hs_3[4]) # node_19 <--> node_20227 self.addLink(hs_3[3], hs_3[5]) # node_19 <--> node_21228 self.addLink(hs_3[5], hs_3[6]) # node_21 <--> node_22229 self.addLink(hs_3[5], hs_3[7]) # node_21 <--> node_23230 self.addLink(hs_3[5], hs_3[8]) # node_21 <--> node_24231 # Add hosts connected to each node232 self.add_hosts('hs_7311%s', hs_3[0], 4) # Add 4 hosts to node_16233 self.add_hosts('hs_7312%s', hs_3[1], 4) # Add 4 hosts to node_17234 self.add_hosts('hs_7313%s', hs_3[2], 3) # Add 3 hosts to node_18235 self.add_hosts('hs_7314%s', hs_3[3], 5) # Add 5 hosts to node_19236 self.add_hosts('hs_7315%s', hs_3[4], 3) # Add 3 hosts to node_20237 self.add_hosts('hs_7316%s', hs_3[5], 2) # Add 2 hosts to node_21238 self.add_hosts('hs_7317%s', hs_3[6], 4) # Add 4 hosts to node_22239 self.add_hosts('hs_7318%s', hs_3[7], 5) # Add 5 hosts to node_23240 self.add_hosts('hs_7319%s', hs_3[8], 5) # Add 5 hosts to node_24241 # link4: Add 8 nodes and corresponding links between them242 num_4 = 8243 hs_4 = []244 self.add_nodes(hs_4, 'hs_7400%s', num_4)245 self.addLink(hs_4[0], router)246 self.addLink(hs_4[0], hs_4[1]) # node_25 <--> node_26247 self.addLink(hs_4[0], hs_4[2]) # node_25 <--> node_27248 self.addLink(hs_4[0], hs_4[3]) # node_25 <--> node_28249 self.addLink(hs_4[3], hs_4[4]) # node_28 <--> node_29250 self.addLink(hs_4[3], hs_4[5]) # node_28 <--> node_30251 self.addLink(hs_4[3], hs_4[6]) # node_28 <--> node_31252 self.addLink(hs_4[6], hs_4[7]) # node_31 <--> node_32253 # Add hosts connected to each node254 self.add_hosts('hs_7411%s', hs_4[0], 8) # Add 8 hosts to node_25255 self.add_hosts('hs_7412%s', hs_4[1], 10) # Add 10 hosts to node_26256 self.add_hosts('hs_7413%s', hs_4[2], 14) # Add 14 hosts to node_27257 self.add_hosts('hs_7414%s', hs_4[3], 2) # Add 2 hosts to node_28258 self.add_hosts('hs_7415%s', hs_4[4], 6) # Add 6 hosts to node_29259 self.add_hosts('hs_7416%s', hs_4[5], 3) # Add 3 hosts to node_30260 self.add_hosts('hs_7417%s', hs_4[6], 8) # Add 8 hosts to node_31261 self.add_hosts('hs_7418%s', hs_4[7], 11) # Add 11 hosts to node_32262 263 def __init__(self):264 Topo.__init__(self)265 self.create_routers(self.routers, self.num)266 # Add links connected to each router267 for i in range(self.num - 1):268 self.addLink(self.routers[i], self.routers[i + 1])269 self.addLink(self.routers[0], self.routers[self.num - 1])270 # Add 1 host to BaiSha-->routers[0]271 self.add_hosts('bs%s', self.routers[0], 1)272 # Create the topo connected to WuTang-->routers[1]273 self.create_wt(self.routers[1])274 # Add 1 host to JinJiang-->routers[2]275 self.add_hosts('jj2010%s', self.routers[2], 1)276 # Create the topo connected to LinBing-->routers[3]277 self.create_lb(self.routers[3])278 # Add 1 host to Shangzhuang-->routers[4]279 self.add_hosts('sz4010%s', self.routers[4], 1)280 # Add 1 host to DaiTou-->routers[5]281 self.add_hosts('dt5010%s', self.routers[5], 1)282 # Add 1 host to HuShi-->routers[6]283 self.add_hosts('HS6010%s', self.routers[6], 1)284 # Create the topo connected to HuangShi-->routers[7]285 self.create_hs(self.routers[7])286 # Add 1 host to ChangTai-->routers[8]287 self.add_hosts('ct8010%s', self.routers[8], 1)288 # Add 1 host to ZhuangBian-->routers[9]289 self.add_hosts('zb9010%s', self.routers[9], 1) 290 291def configNet():292 293 mytopo=MyTopo()294 net = Mininet( topo=mytopo,controller=None) 295 296 c0 = RemoteController( 'c0', ip='172.17.0.2', port=6633 )297 net.addController(c0)298 net.start()299 CLI( net )300 net.stop()301if __name__ == '__main__':302 setLogLevel( 'info' )303 configNet()...
test_add_case.py
Source:test_add_case.py
1# 主æºç®¡çæ°å¢æµè¯ç¨ä¾2import allure3from PageObject.Common_Page.index_page import Index_Page4from PageObject.Resource_Page.Hosts_Page.add_page import add_Page5from PageObject.Resource_Page.Hosts_Page.list_page import list_Page6def case_test_hosts_new(self, business_area, clusters, hostIp, room, seat, hddPaths, ssdPaths, remoteStorageId, maxUnitCnt,7 hotSpare, description, assert_type):8 index = Index_Page(self.driver)9 index.in_host()10 hosts = list_Page(self.driver)11 hosts.click_new_button()12 add_hosts = add_Page(self.driver)13 add_hosts.add_in()14 with allure.step("è¾å
¥ä¿¡æ¯ï¼"):15 allure.attach(business_area, 'æå±ä¸å¡åº')16 allure.attach(clusters, 'æå±é群')17 allure.attach(hostIp, '主æºIP')18 allure.attach(room, 'æºæ¿')19 allure.attach(seat, 'æºä½')20 allure.attach(hddPaths, 'æºæ¢°ç设å¤')21 allure.attach(ssdPaths, 'åºæç设å¤')22 allure.attach(remoteStorageId, 'å¤ç½®åå¨')23 allure.attach(maxUnitCnt, '容å¨ä¸é')24 allure.attach(hotSpare, 'å¤é')25 allure.attach(description, 'æè¿°')26 add_hosts.add(business_area, clusters, hostIp, room, seat, hddPaths, ssdPaths, remoteStorageId, maxUnitCnt,27 hotSpare, description)28 if assert_type == '1':29 allure_title = "æ·»å æå"30 allure.dynamic.title(allure_title)31 assert add_hosts.is_add_element(), 'æ ¡éªæå'32 add_hosts.click_operation_confirm()33 assert True, 'æ°å¢æå'34 elif assert_type == "2":35 text = add_hosts.non_empty_error()36 allure_title = text37 allure.dynamic.title(allure_title)38 assert "请" or "è¾" in text, text39 elif assert_type == "3":40 allure_title = "主æºIPéå¤"41 allure.dynamic.title(allure_title)42 assert add_hosts.is_add_element(), 'æ ¡éªæå'43 add_hosts.click_operation_confirm()44 text = add_hosts.get_message_text()45 assert "å·²åå¨" in text, text46 elif assert_type == "4":47 text = add_hosts.non_empty_error()48 allure_title = text49 allure.dynamic.title(allure_title)50 assert "请è¾å
¥" in text, text51 else:52 allure_title = "æªç¥é误"53 allure.dynamic.title(allure_title)54 print(f"æªç¥æè¨ç±»å{assert_type}")...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!