Best Python code snippet using tempest_python
tests.py
Source:tests.py
...12class Slice_subnet_test(TestCase):13 def setUp(self):14 print "------set up slice subnet test--------"15 for i in xrange(1, 11):16 self.create_subnet(owner=i)17 @timefunc18 def create_subnet(self, owner, ipcount=64):19 subnet = IPUsage.objects.create_subnet(owner=owner, timeout=5, ipcount=ipcount)20 self.assertTrue(subnet)21 return subnet22 @timefunc23 def allocate_ip(self, owner):24 ip = IPUsage.objects.allocate_ip(owner=owner)25 self.assertTrue('255.255.255.192' == str(ip.supernet.get_network().netmask))26 self.assertTrue(26 == ip.supernet.get_network().prefixlen)27 return ip28 @timefunc29 def release_ip(self, ip):30 result = IPUsage.objects.release_ip(ip=ip)31 self.assertTrue(result)32 @timefunc33 def delete_subnet(self, owner):34 result = IPUsage.objects.delete_subnet(owner=owner)35 self.assertTrue(result)36 def test_networkflow(self):37 for i in xrange(11, 21):38 self.create_subnet(owner=11)39 self.delete_subnet(owner=11)40 self.create_subnet(owner=11)41 IPUsage.objects.subnet_create_success(owner=11)42 ips = []43 for i in xrange(2):44 ip = self.allocate_ip(owner=11)45 print ip46 self.assertTrue(ip.ipaddr == '10.0.2.%s' % (129 + i))47 ips.append(ip)48 ip1 = self.allocate_ip(owner=11)49 self.assertTrue(ip1.ipaddr == '10.0.2.131')50 ip2 = self.allocate_ip(owner=11)51 self.assertTrue(ip2.ipaddr == '10.0.2.132')52 self.release_ip(ip1)53 ip1 = self.allocate_ip(owner=11)54 self.assertTrue(ip1.ipaddr == '10.0.2.131')55 for ip in ips:56 self.release_ip(ip)57 ip1 = self.allocate_ip(owner=11)58 self.assertTrue(ip1.ipaddr == '10.0.2.129')59 self.create_subnet(owner=12)60 self.delete_subnet(owner=11)61 sub13 = self.create_subnet(owner=13)62 self.assertTrue(sub13 == '10.0.2.128/26')63 time.sleep(5)64 sub14 = self.create_subnet(owner=14)65 self.assertTrue(sub14 == '10.0.0.0/26')66 def tearDown(self):67 print "------tear down slice subnet test--------"68 for i in xrange(2, 11):69 self.delete_subnet(owner=i)70class Subnet_test(TestCase):71 def setUp(self):72 print "------set up subnet test--------"73 def test_8(self):74 for i in xrange(32):75 sub = IPUsage.objects.create_subnet(owner=i + 1, timeout=120, ipcount=8)76 self.assertTrue(sub == '10.0.0.%s/29' % (i * 8))77 IPUsage.objects.delete_subnet(owner=31)78 sub = IPUsage.objects.create_subnet(owner=31, timeout=120, ipcount=16)79 self.assertTrue(sub)80 def test_16(self):81 for i in xrange(16):82 sub = IPUsage.objects.create_subnet(owner=i + 1, timeout=120, ipcount=16)83 self.assertTrue(sub == '10.0.0.%s/28' % (i * 16))84 for i in xrange(16):85 sub = IPUsage.objects.create_subnet(owner=i + 33, timeout=120, ipcount=16)86 self.assertTrue(sub == '10.0.1.%s/28' % (i * 16))87 def test_32(self):88 for i in xrange(8):89 sub = IPUsage.objects.create_subnet(owner=i + 1, timeout=120, ipcount=32)90 self.assertTrue(sub == '10.0.0.%s/27' % (i * 32))91 for i in xrange(8):92 sub = IPUsage.objects.create_subnet(owner=i + 33, timeout=120, ipcount=32)93 self.assertTrue(sub == '10.0.1.%s/27' % (i * 32))94 def test_64(self):95 for i in xrange(4):96 sub = IPUsage.objects.create_subnet(owner=i + 1, timeout=120, ipcount=64)97 self.assertTrue(sub == '10.0.0.%s/26' % (i * 64))98 for i in xrange(4):99 sub = IPUsage.objects.create_subnet(owner=i + 33, timeout=120, ipcount=64)100 self.assertTrue(sub == '10.0.1.%s/26' % (i * 64))101 @timefunc102 def create_subnet(self, owner, ipcount=64):103 subnet = IPUsage.objects.create_subnet(owner=owner, timeout=120, ipcount=ipcount)104 return subnet105 def test_networkflow(self):106 for i in xrange(100):107 sub = self.create_subnet(owner=str(uuid.uuid4()), ipcount=8)108 self.assertTrue(sub == '10.0.%s.%s/29' % (i, 0 * 64))109 sub = self.create_subnet(owner=str(uuid.uuid4()), ipcount=16)110 self.assertTrue(sub == '10.0.%s.%s/28' % (i, 1 * 64))111 sub = self.create_subnet(owner=str(uuid.uuid4()), ipcount=32)112 self.assertTrue(sub == '10.0.%s.%s/27' % (i, 2 * 64))113 sub = self.create_subnet(owner=str(uuid.uuid4()), ipcount=64)114 self.assertTrue(sub == '10.0.%s.%s/26' % (i, 3 * 64))115 for j in xrange(7):116 sub = self.create_subnet(owner=str(uuid.uuid4()), ipcount=8)117 self.assertTrue(sub == '10.0.%s.%s/29' % (i, (j + 1) * 8))118 for j in xrange(3):119 sub = self.create_subnet(owner=str(uuid.uuid4()), ipcount=16)120 self.assertTrue(sub == '10.0.%s.%s/28' % (i, 64 + (j + 1) * 16))121 sub = self.create_subnet(owner=str(uuid.uuid4()), ipcount=32)122 self.assertTrue(sub == '10.0.%s.160/27' % (i))123 def tearDown(self):124 print "------tear down subnet test--------"125class Phy_subnet_test(TestCase):126 def setUp(self):127 print "------set up physic subnet test--------"128 def test_test(self):129 ip1 = IPUsage.objects.allocate_ip_for_controller()130 self.assertTrue(ip1.ipaddr == '172.16.0.101')131 ip = IPUsage.objects.allocate_ip_for_controller()132 self.assertTrue(ip.ipaddr == '172.16.0.102')133 IPUsage.objects.release_ip_for_controller(ip1)134 ip1 = IPUsage.objects.allocate_ip_for_controller()135 self.assertTrue(ip1.ipaddr == '172.16.0.101')...
kademlia_large_lan.py
Source:kademlia_large_lan.py
...14 gateway = main_net.create_node('gateway')15 main_net.make_mesh(core) # WAS IT DEPRECATED?16 # make subnets connecting each pair of nodes17 main_net.make_mesh((core[0], *routers)) # WAS IT DEPRECATED?18 main_net.create_subnet('ospf_1', (ospf_routers[0], core[2]))19 main_net.create_subnet('ospf_2', (ospf_routers[1], core[2]))20 main_net.create_subnet('lc1', (*nodes[:2], routers[0]))21 main_net.create_subnet('lc2', (*nodes[2:4], routers[1], gateway))22 main_net.create_subnet('lc3', (*nodes[4:7], core[1]))23 main_net.create_subnet('lc4', (*nodes[7:9], ospf_routers[0]))24 main_net.create_subnet('lc5', (*nodes[9:], ospf_routers[1]))25 main_net.create_overlay(Overlay.RIP, 'RIP_1', (core[0], *routers))26 main_net.create_overlay(Overlay.OSPF, 'OSPF_1', (core[2], *ospf_routers))27 main_net.create_overlay(Overlay.BGP, 'big_boi', [28 [*nodes[:4], *routers, gateway, core[0]], [*nodes[4:7], core[1]], [*nodes[7:], *ospf_routers, core[2]]29 ])30 local_net = main_net.create_local_network(gateway)31 local_routers = local_net.generate_nodes('lan_router', 2)32 local_net.create_subnet('LAN0', (*local_routers, gateway))33 for idx, r in enumerate(local_routers):34 node = local_net.create_node('lan_node' + str(idx + 1), image='kademlia')35 local_net.create_subnet('LAN' + str(idx + 1), (node, r))36 nodes.append(node)37 local_net.create_overlay(Overlay.RIP, 'RIP_1', local_routers)38 main_net.configure(verbose=True)39 for node in nodes[1:]:40 node.add_options(environment={'KADEMLIA_ARGS': nodes[0].get_ip()})41 main_net.render(args.lab_path, verbose=True)42if __name__ == "__main__":...
kademlia_rip_ospf_bgp.py
Source:kademlia_rip_ospf_bgp.py
...13 nodes = net.generate_nodes('n', 11, image='kademlia')14 net.make_mesh(core) # WAS IT DEPRECATED?15 # make subnets connecting each pair of nodes16 net.make_mesh((core[0], *routers)) # WAS IT DEPRECATED?17 net.create_subnet('ospf_1', (ospf_routers[0], core[2]))18 net.create_subnet('ospf_2', (ospf_routers[1], core[2]))19 net.create_subnet('lc1', (*nodes[:2], routers[0]))20 net.create_subnet('lc2', (*nodes[2:4], routers[1]))21 net.create_subnet('lc3', (*nodes[4:7], core[1]))22 net.create_subnet('lc4', (*nodes[7:9], ospf_routers[0]))23 net.create_subnet('lc5', (*nodes[9:], ospf_routers[1]))24 net.create_overlay(Overlay.RIP, 'RIP_1', (core[0], *routers))25 net.create_overlay(Overlay.OSPF, 'OSPF_1', (core[2], *ospf_routers))26 net.create_overlay(Overlay.BGP, 'big_boi', [27 [*nodes[:4], *routers, core[0]], [*nodes[4:7], core[1]], [*nodes[7:], *ospf_routers, core[2]]28 ])29 net.configure(verbose=True)30 for node in nodes[1:]:31 node.add_options(environment={'KADEMLIA_ARGS': nodes[0].get_ip()})32 net.render(args.lab_path, verbose=True)33if __name__ == "__main__":...
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!!