diff --git a/scripts/python/api/tbed.py b/scripts/python/api/tbed.py index 9a8c8bd59..f52f1c905 100644 --- a/scripts/python/api/tbed.py +++ b/scripts/python/api/tbed.py @@ -207,9 +207,9 @@ def checkConnectionPair(self, fromContainers, toContainers, port, success): return success # Look for any error logs on all nodes - def chekForNetpluginErrors(self): + def checkForNetpluginErrors(self): for node in self.nodes: - ret = node.chekForNetpluginErrors() + ret = node.checkForNetpluginErrors() if ret == False and self.failOnError: tutils.exit("Errors in log file") @@ -217,7 +217,7 @@ def chekForNetpluginErrors(self): def errExit(self, str): # print erros from netplugin log file for node in self.nodes: - node.chekForNetpluginErrors() + node.checkForNetpluginErrors() # exit the script tutils.exit(str) diff --git a/scripts/python/api/tnode.py b/scripts/python/api/tnode.py index 2f13409cd..ee7ecb624 100644 --- a/scripts/python/api/tnode.py +++ b/scripts/python/api/tnode.py @@ -146,7 +146,7 @@ def runContainer(self, imgName="ubuntu:14.04", cmdName="sh", networkName=None, s # Return a container object return container.Container(self, cid, cntName="") - def chekForNetpluginErrors(self): + def checkForNetpluginErrors(self): out, err, exitCode = self.runCmd('grep "error\|fatal" /tmp/net*') if out != [] or err != []: print "\n\n\n\n\n\n" diff --git a/scripts/python/runTestCase.py b/scripts/python/runTestCase.py deleted file mode 100755 index 25b663ef6..000000000 --- a/scripts/python/runTestCase.py +++ /dev/null @@ -1,100 +0,0 @@ -#!/usr/bin/python - -# sanity tests -import api.tbed -import api.tutils -import time -import sys -import api.objmodel -import testcases.tcBasic -import testcases.tcPolicy -import testcases.tcNetwork -import testcases.tcTrigger -import testcases.tcAci -import argparse -import os -import exceptions -import traceback - -# Create the parser and sub parser -parser = argparse.ArgumentParser() -parser.add_argument('--version', action='version', version='1.0.0') -parser.add_argument("-nodes", required=True, help="list of nodes(comma seperated)") -parser.add_argument("-iteration", default="3", help="Number of iterations") -parser.add_argument("-user", default='vagrant', help="User id for ssh") -parser.add_argument("-password", default='vagrant', help="password for ssh") -parser.add_argument("-binpath", default='/opt/gopath/bin', help="netplugin/netmaster binary path") -parser.add_argument("-containers", default='0', help="number of containers") -parser.add_argument("-short", default='false', help="do a quick run of the tests for quick validation") - -# Parse the args -args = parser.parse_args() -addrList = args.nodes.split(",") - -shortRun = args.short.lower() - -numCntr = len(addrList) * 2 -numIteration = int(args.iteration) -numTriggerTests = 6 - -if args.containers != '0': - numCntr = int(args.containers) - -if shortRun == "true": - print "doing a short run" - numCntr = len(addrList) * 2 - numIteration = 1 - numTriggerTests = 1 - -api.tutils.info("Running " + str(numIteration) + " iterations with " + str(numCntr) + " containers on " + str(len(addrList)) + " nodes") - -try: - # Time when test started - startTime = time.time() - - # Setup testbed - testbed = api.tbed.Testbed(addrList, args.user, args.password, args.binpath) - - time.sleep(15) - - testbed.chekForNetpluginErrors() - - # Run single test case - testcases.tcTrigger.netmasterSwitchoverTest(testbed, numCntr, numIteration) - - # Test netplugin disconnect/connect - testcases.tcTrigger.netpluginDisconnectTest(testbed, numCntr, numIteration) - - # Run multiple triggers on the Testbed - testcases.tcTrigger.testMultiTrigger(testbed, (numIteration * numTriggerTests)) - - # Test netplugin disconnect/connect - testcases.tcTrigger.netpluginDisconnectTest(testbed, numCntr, numIteration) - - # Run multiple triggers on the Testbed - testcases.tcTrigger.testMultiTrigger(testbed, (numIteration * numTriggerTests)) - - # Cleanup testbed - testbed.cleanup() - - # Calculate how long it took - doneTime = time.time() - elapsedTime = doneTime - startTime - api.tutils.log("Test started at " + time.asctime(time.localtime(startTime))) - api.tutils.log("Test ended at " + time.asctime(time.localtime(doneTime))) - if elapsedTime > 120.0: - api.tutils.log("Tests took " + str(elapsedTime/60) + " minutes") - else: - api.tutils.log("Tests took " + str(elapsedTime) + " seconds") - - api.tutils.info("testcase passed") - os._exit(0) - -except exceptions.KeyboardInterrupt: - print "\n\n Keyboard interrupt.... Exiting\n" - os._exit(1) - -except: # catch *all* exceptions - print "Exception: " - traceback.print_exc() - os._exit(1) diff --git a/scripts/python/sanity.py b/scripts/python/sanity.py deleted file mode 100755 index 7a114499b..000000000 --- a/scripts/python/sanity.py +++ /dev/null @@ -1,121 +0,0 @@ -#!/usr/bin/python - -# sanity tests -import api.tbed -import api.tutils -import time -import sys -import api.objmodel -import testcases.tcBasic -import testcases.tcPolicy -import testcases.tcNetwork -import testcases.tcTrigger -import testcases.tcAci -import argparse -import os -import exceptions -import traceback - -# Create the parser and sub parser -parser = argparse.ArgumentParser() -parser.add_argument('--version', action='version', version='1.0.0') -parser.add_argument("-nodes", required=True, help="list of nodes(comma seperated)") -parser.add_argument("-iteration", default="3", help="Number of iterations") -parser.add_argument("-user", default='vagrant', help="User id for ssh") -parser.add_argument("-password", default='vagrant', help="password for ssh") -parser.add_argument("-binpath", default='/opt/gopath/bin', help="netplugin/netmaster binary path") -parser.add_argument("-containers", default='0', help="number of containers") -parser.add_argument("-short", default='false', help="do a quick run of the tests for quick validation") - -# Parse the args -args = parser.parse_args() -addrList = args.nodes.split(",") - -shortRun = args.short.lower() - -numCntr = len(addrList) * 2 -numIteration = int(args.iteration) -numTriggerTests = 6 - -if args.containers != '0': - numCntr = int(args.containers) - -if shortRun == "true": - print "doing a short run" - numCntr = len(addrList) * 2 - numIteration = 1 - numTriggerTests = 1 - -api.tutils.info("Running " + str(numIteration) + " iterations with " + str(numCntr) + " containers on " + str(len(addrList)) + " nodes") - -try: - # Time when test started - startTime = time.time() - - # Setup testbed - testbed = api.tbed.Testbed(addrList, args.user, args.password, args.binpath) - - time.sleep(15) - - testbed.chekForNetpluginErrors() - - # Run vlan tests - testcases.tcNetwork.testAddDeleteTenant(testbed, numCntr, numIteration, encap="vlan") - testcases.tcNetwork.testAddDeleteNetwork(testbed, (numCntr * 3), numIteration, encap="vlan") - testcases.tcBasic.startRemoveContainer(testbed, numCntr, numIteration, encap="vlan") - testcases.tcBasic.startStopContainer(testbed, numCntr, numIteration, encap="vlan") - - # Run policy tests. in vlan mode - testcases.tcPolicy.testBasicPolicy(testbed, numCntr, numIteration, encap="vlan") - testcases.tcPolicy.testPolicyAddDeleteRule(testbed, numCntr, numIteration, encap="vlan") - testcases.tcPolicy.testPolicyFromEpg(testbed, numCntr, numIteration, encap="vlan") - testcases.tcPolicy.testPolicyFeatures(testbed, encap="vlan") - - # Run vxlan tests - testcases.tcNetwork.testAddDeleteTenant(testbed, numCntr, numIteration, encap="vxlan") - testcases.tcNetwork.testAddDeleteNetwork(testbed, (numCntr * 3), numIteration, encap="vxlan") - testcases.tcBasic.startRemoveContainer(testbed, numCntr, numIteration, encap="vxlan") - testcases.tcBasic.startStopContainer(testbed, numCntr, numIteration, encap="vxlan") - - # Run policy tests. in vxlan mode - testcases.tcPolicy.testBasicPolicy(testbed, numCntr, numIteration, encap="vxlan") - testcases.tcPolicy.testPolicyAddDeleteRule(testbed, numCntr, numIteration, encap="vxlan") - testcases.tcPolicy.testPolicyFromEpg(testbed, numCntr, numIteration, encap="vxlan") - testcases.tcPolicy.testPolicyFeatures(testbed, encap="vxlan") - - # Run netmaster switchover test - testcases.tcTrigger.netmasterSwitchoverTest(testbed, numCntr, numIteration) - - # Test netplugin disconnect/connect - testcases.tcTrigger.netpluginDisconnectTest(testbed, numCntr, numIteration) - - # Run multiple triggers on the Testbed - testcases.tcTrigger.testMultiTrigger(testbed, (numIteration * numTriggerTests)) - - # Run ACI mode sanity - testcases.tcAci.testACIMode(testbed) - - # Cleanup testbed - testbed.cleanup() - - # Calculate how long it took - doneTime = time.time() - elapsedTime = doneTime - startTime - api.tutils.log("Test started at " + time.asctime(time.localtime(startTime))) - api.tutils.log("Test ended at " + time.asctime(time.localtime(doneTime))) - if elapsedTime > 120.0: - api.tutils.log("Tests took " + str(elapsedTime/60) + " minutes") - else: - api.tutils.log("Tests took " + str(elapsedTime) + " seconds") - - api.tutils.info("Sanity passed") - os._exit(0) - -except exceptions.KeyboardInterrupt: - print "\n\n Keyboard interrupt.... Exiting\n" - os._exit(1) - -except: # catch *all* exceptions - print "Exception: " - traceback.print_exc() - os._exit(1) diff --git a/scripts/python/setupProxy.py b/scripts/python/setupProxy.py deleted file mode 100755 index e22f128eb..000000000 --- a/scripts/python/setupProxy.py +++ /dev/null @@ -1,90 +0,0 @@ -#!/usr/bin/python - -# sanity tests -import time -import sys -import os -import urllib -import urllib2 -import json - -# Wrapper for HTTP get -def httpGet(url): - try: - retData = urllib2.urlopen(url) - return retData.read() - - except urllib2.HTTPError, err: - if err.code == 404: - print "Page not found!" - elif err.code == 403: - print "Access denied!" - else: - print "HTTP Error! Error code", err.code - return "Error" - except urllib2.URLError, err: - print "URL error:", err.reason - return "Error" - -# Function to setup proxy -def setupProxy(): - print "Setting up proxy" - cfg = """{ - "Tenants" : [ { - "Name" : "default", - "Networks" : [ - { - "Name" : "private", - "Endpoints" : [ { - "Container" : "proxyPort", - "Host" : "netplugin-node1" - }] - } ] - } ] - } - - """ - - # Write the config file - print "Writing config file.." - cfgFile = "/tmp/proxy-endpoint.cfg" - f = open(cfgFile,'w') - f.write(cfg) - f.close() - - # Add the config to Netmaster - print 'netdcli -add-cfg ' + cfgFile - print os.popen('netdcli -add-cfg ' + cfgFile).read() - - print "Adding ovs interface" - - # get the endpoints - for iter in range(5): - resp = httpGet('http://netmaster:9999/endpoints') - if resp != "Error": - # Read the json response - epList = json.loads(resp) - - # Look for pro - for ep in epList: - if ep['id'] == "private.default-proxyPort": - # Config ip and bringup interface - print "Found the proxy endpoint, bringing up the ovs interface" - print "sudo ifconfig " + ep['portName'] + " " + ep['ipAddress'] + " up" - print os.popen("sudo ifconfig " + ep['portName'] + " " + ep['ipAddress'] + " up").read() - return - - print "Failed to find proxy endpoint. Retrying.." - else: - print "HTTP error reading endpoints. Retrying.." - - # Retry after 1 sec - time.sleep(1) - - # Failed to create endpoint - print "ERROR: Error finding proxy endpoint. Exiting" - os._exit(1) - -if __name__ == "__main__": - # Call it - setupProxy() diff --git a/scripts/python/testcases/__init__.py b/scripts/python/testcases/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/scripts/python/testcases/tcAci.py b/scripts/python/testcases/tcAci.py deleted file mode 100644 index f0c8d918e..000000000 --- a/scripts/python/testcases/tcAci.py +++ /dev/null @@ -1,48 +0,0 @@ -import api.tutils -import time -import sys -import api.objmodel - -# Test configure ACI mode -def testACIMode(testbed): - api.tutils.info("testACIMode starting") - api.objmodel.setFabricMode("aci") - - # Create a network - testTen = api.objmodel.tenant('default') - testNet = testTen.newNetwork("aciNet", 0, "22.2.2.0/24", "22.2.2.254", "vlan") - - # Create two epgs - epgA = testNet.newGroup("epgA") - epgB = testNet.newGroup("epgB") - - # Start two containers each on epgA and epgB - cA1 = testbed.runContainerOnNode(0, "epgA.aciNet") - cA2 = testbed.runContainerOnNode(0, "epgA.aciNet") - cB1 = testbed.runContainerOnNode(0, "epgB.aciNet") - cB2 = testbed.runContainerOnNode(0, "epgB.aciNet") - - # Verify cA1 can ping cA2 - cA1.checkPing(cA2.getIpAddr()) - - # Verify cB1 can ping cB2 - cB1.checkPing(cB2.getIpAddr()) - - # Verify cA1 cannot ping cB1 - cA1.checkPingFailure(cB1.getIpAddr()) - - # remove containers - testbed.removeContainers([cA1, cA2, cB1, cB2]) - - # delete epgs - testNet.deleteGroup("epgA") - testNet.deleteGroup("epgB") - - # delete network - testTen.deleteNetwork("aciNet") - api.objmodel.setFabricMode("default") - - # Check for errors - testbed.chekForNetpluginErrors() - - api.tutils.info("testACIMode Test passed") diff --git a/scripts/python/testcases/tcBasic.py b/scripts/python/testcases/tcBasic.py deleted file mode 100644 index 0e9311241..000000000 --- a/scripts/python/testcases/tcBasic.py +++ /dev/null @@ -1,82 +0,0 @@ -import api.tutils -import time -import sys -import api.objmodel - -# Start/Remove container test -def startRemoveContainer(testbed, numContainer, numIter, encap="vxlan"): - api.tutils.info("startRemoveContainer starting") - - tenant = api.objmodel.tenant('default') - network = tenant.newNetwork('private', pktTag=1001, subnet="10.1.0.0/16", gateway="10.1.1.254", encap=encap) - - for iter in range(numIter): - # Start the containers - containers = testbed.runContainers(numContainer) - - # Perform ping test on the containers - testbed.pingTest(containers) - - # remove containers - for cnt in containers: - cnt.remove() - - # Check for errors - testbed.chekForNetpluginErrors() - - # Iteration is done - api.tutils.info("startRemoveContainer iteration " + str(iter) + " Passed") - - # Delete the network we created - tenant.deleteNetwork('private') - - # Check for errors - testbed.chekForNetpluginErrors() - - # Test is done - api.tutils.info("startRemoveContainer Test passed") - -# start/stop containers -def startStopContainer(testbed, numContainer, numIter, encap="vxlan"): - api.tutils.info("startStopContainer starting") - - tenant = api.objmodel.tenant('default') - network = tenant.newNetwork('private', pktTag=1001, subnet="10.1.0.0/16", gateway="10.1.1.254", encap=encap) - - # Start the containers - containers = testbed.runContainers(numContainer) - - # Perform ping test on the containers - testbed.pingTest(containers) - - for iter in range(numIter): - - # Stop the containers - for cnt in containers: - cnt.stop() - - # Start the containers - for cnt in containers: - cnt.start() - - # Perform ping test on the containers - testbed.pingTest(containers) - - # Check for errors - testbed.chekForNetpluginErrors() - - # Iteration is done - api.tutils.info("startStopContainer iteration " + str(iter) + " Passed") - - # remove containers - for cnt in containers: - cnt.remove() - - # Delete the network we created - tenant.deleteNetwork('private') - - # Check for errors - testbed.chekForNetpluginErrors() - - # Test is done - api.tutils.info("startStopContainer Test passed") diff --git a/scripts/python/testcases/tcDockExec.py b/scripts/python/testcases/tcDockExec.py deleted file mode 100644 index a583cdb63..000000000 --- a/scripts/python/testcases/tcDockExec.py +++ /dev/null @@ -1,84 +0,0 @@ -import api.tutils -import time -import sys -import api.objmodel - -# Repeatedly execute docker exec. -# This tests docker exec to catch a bug in docker. hence its not included in sanity tests -def testDockExecRepeate(testbed, numContainer, numIteration, numExec): - api.tutils.info("testDockExecRepeate Test starting") - - tenant = api.objmodel.tenant('default') - network = tenant.newNetwork('private', pktTag=1001, subnet="10.1.0.0/16", gateway="10.1.1.254") - - for iter in range(numIteration): - # Create policy - policy = tenant.newPolicy('first') - - # create default deny Rule - policy.addRule('1', direction="in", protocol="tcp", action="deny") - - # Create allow port 8000 Rule - policy.addRule('2', direction="in", priority=100, protocol="tcp", port=8000, action="allow") - - # Add the policy to epg - groups = [] - for cntIdx in range(numContainer): - nodeIdx = cntIdx % testbed.numNodes() - epgName = "srv" + str(cntIdx) - group = network.newGroup(epgName, policies=["first"]) - groups.append(group) - - # start containers - containers = testbed.runContainers(numContainer, withService=True) - - # Run exec multiple times - for eidx in range(numExec): - # start netcast listeners - testbed.startListeners(containers, [8000, 8001]) - - cntrIpList = [] - # Read all IP addresses - for cnt in containers: - cntrIp = cnt.getIpAddr() - cntrIpList.append(cntrIp) - - # Check connection to all containers from one container on each node - for cidx, cnt in enumerate(containers): - for aidx, ipAddr in enumerate(cntrIpList): - if cidx != aidx: - ret = cnt.checkConnection(ipAddr, 8000) - # If connection status is not what we were expecting, we are done. - if ret != True: - api.tutils.exit("Connection failed") - - # stop netcast listeners - testbed.stopListeners(containers) - - # remove containers - testbed.removeContainers(containers) - - # Remove policy from epg - for group in groups: - group.removePolicy("first") - - # delete epg - for cntIdx in range(numContainer): - nodeIdx = cntIdx % testbed.numNodes() - epgName = "srv" + str(cntIdx) - network.deleteGroup(epgName) - - # Remove the policy and rules - policy.deleteRule('1') - policy.deleteRule('2') - tenant.deletePolicy('first') - - # Check for errors - testbed.chekForNetpluginErrors() - - api.tutils.info("dockExec Iteration " + str(iter) + " passed") - - # Delete the network we created - tenant.deleteNetwork('private') - - api.tutils.info("testDockExecRepeate Test passed") diff --git a/scripts/python/testcases/tcNetwork.py b/scripts/python/testcases/tcNetwork.py deleted file mode 100644 index 6e726ff38..000000000 --- a/scripts/python/testcases/tcNetwork.py +++ /dev/null @@ -1,120 +0,0 @@ -import api.tutils -import time -import sys -import api.objmodel - -# Test network add delete -# This test expects atleast 4 containers per node -def testAddDeleteNetwork(testbed, numContainer, numIter, encap="vxlan"): - api.tutils.info("testAddDeleteNetwork starting") - - tenant = api.objmodel.tenant('default') - - for iter in range(numIter): - # create networks - networks = [] - netNames = [] - - # Determine the number of networks so that each node has atleast two containers in each network. - # so that we can test both single host and multi-host scenarios - if numContainer >= (testbed.numNodes() * 2): - numNetworks = numContainer / (testbed.numNodes() * 2) - else: - numNetworks = 1 - - for idx in range(numNetworks): - netName = "net" + str(idx) - subnet = "10.1." + str(idx) + ".0/24" - gateway = "10.1." + str(idx) + ".254" - network = tenant.newNetwork(netName, pktTag=(1001 + idx), subnet=subnet, gateway=gateway, encap=encap) - networks.append(network) - netNames.append(netName) - - # start containers - containers = testbed.runContainersInNetworks(numContainer, netNames) - - cntrIpList = [] - # Read all IP addresses - for cnt in containers: - cntrIp = cnt.getIpAddr() - cntrIpList.append(cntrIp) - - # Test ping from each container to other container in same network - # We expect ping success for each container in same network - # AND ping failure for each container in different network - for cidx, cnt in enumerate(containers): - if (cidx % (testbed.numNodes() * numNetworks)) == 0: - for ipidx, ipAddr in enumerate(cntrIpList): - if (ipidx % len(networks)) == (cidx % len(networks)): - cnt.checkPing(ipAddr) - elif ((cidx + 1) % len(networks)) == (ipidx % len(networks)): - cnt.checkPingFailure(ipAddr) - - # remove containers - testbed.removeContainers(containers) - - # delete networks - for idx in range(numContainer/2): - netName = "net" + str(idx) - tenant.deleteNetwork(netName) - - # Check for errors - testbed.chekForNetpluginErrors() - - api.tutils.info("testAddDeleteNetwork Iteration " + str(iter) + " passed") - - api.tutils.info("testAddDeleteNetwork Test passed") - -# Test tenant add delete -def testAddDeleteTenant(testbed, numContainer, numIter, encap="vxlan"): - api.tutils.info("testAddDeleteTenant starting") - - for iter in range(numIter): - # create tenants and networks - tenants = [] - networks = [] - netNames = [] - for idx in range(numContainer/2): - nodeIdx = idx % testbed.numNodes() - tenantName = "tenant" + str(idx) - tenant = api.objmodel.tenant(tenantName) - tenants.append(tenant) - netName = "net" + str(idx) - subnet = "10.1." + str(idx) + ".0/24" - gateway = "10.1." + str(idx) + ".254" - network = tenant.newNetwork(netName, pktTag=(1001 + idx), subnet=subnet, gateway=gateway, encap=encap) - networks.append(network) - netNames.append(netName + "/" + tenantName) - - - # start containers - containers = testbed.runContainersInNetworks(numContainer, netNames) - - cntrIpList = [] - # Read all IP addresses - for cnt in containers: - cntrIp = cnt.getIpAddr() - cntrIpList.append(cntrIp) - - # Test ping from each container to other container in same network - for cidx, cnt in enumerate(containers): - if (cidx % testbed.numNodes()) == 0: - for ipidx, ipAddr in enumerate(cntrIpList): - if (ipidx % len(networks)) == (cidx % len(networks)): - cnt.checkPing(ipAddr) - - # remove containers - testbed.removeContainers(containers) - - # delete networks and tenants - for idx, tenant in enumerate(tenants): - netName = "net" + str(idx) - tenant.deleteNetwork(netName) - tenant.delete() - - # Check for errors - testbed.chekForNetpluginErrors() - - api.tutils.info("testAddDeleteTenant Iteration " + str(iter) + " passed") - - api.tutils.info("testAddDeleteTenant Test passed") diff --git a/scripts/python/testcases/tcPolicy.py b/scripts/python/testcases/tcPolicy.py deleted file mode 100644 index 4c029d993..000000000 --- a/scripts/python/testcases/tcPolicy.py +++ /dev/null @@ -1,419 +0,0 @@ -import api.tutils -import time -import sys -import api.objmodel - -# Test basic group based policy -def testBasicPolicy(testbed, numContainer, numIter, encap="vxlan"): - api.tutils.info("testBasicPolicy starting") - - tenant = api.objmodel.tenant('default') - network = tenant.newNetwork('private', pktTag=1001, subnet="10.1.0.0/16", gateway="10.1.1.254", encap=encap) - - for iter in range(numIter): - # Create policy - policy = tenant.newPolicy('first') - - # create default deny Rule - policy.addRule('1', direction="in", protocol="tcp", action="deny") - - # Create allow port 8000 Rule - policy.addRule('2', direction="in", priority=100, protocol="tcp", port=8000, action="allow") - - # Add the policy to epg - groups = [] - for cntIdx in range(numContainer): - nodeIdx = cntIdx % testbed.numNodes() - epgName = "srv" + str(cntIdx) - group = network.newGroup(epgName, policies=["first"]) - groups.append(group) - - # start containers - containers = testbed.runContainers(numContainer, withService=True) - - # start netcast listeners - testbed.startListeners(containers, [8000, 8001]) - - # Check connection to all containers - if testbed.checkConnections(containers, 8000, True) != True: - api.tutils.exit("Connection failed") - if testbed.checkConnections(containers, 8001, False) != False: - api.tutils.exit("Connection succeded while expecting it to fail") - - # stop netcast listeners - testbed.stopListeners(containers) - - # remove containers - testbed.removeContainers(containers) - - # Remove policy from epg - for group in groups: - group.removePolicy("first") - - # delete epg - for cntIdx in range(numContainer): - nodeIdx = cntIdx % testbed.numNodes() - epgName = "srv" + str(cntIdx) - network.deleteGroup(epgName) - - # Remove the policy and rules - policy.deleteRule('1') - policy.deleteRule('2') - tenant.deletePolicy('first') - - # Check for errors - testbed.chekForNetpluginErrors() - - api.tutils.info("testBasicPolicy Iteration " + str(iter) + " passed") - - # Delete the network we created - tenant.deleteNetwork('private') - - api.tutils.info("testBasicPolicy Test passed") - - -# Test adding/deleting rules from Policy -def testPolicyAddDeleteRule(testbed, numContainer, numIter, encap="vxlan"): - api.tutils.info("testPolicyAddDeleteRule starting") - - tenant = api.objmodel.tenant('default') - network = tenant.newNetwork('private', pktTag=1001, subnet="10.1.0.0/16", gateway="10.1.1.254", encap=encap) - - # Create policy - policy = tenant.newPolicy('first') - - # create default deny Rule - policy.addRule('1', direction="in", protocol="tcp", action="deny") - - # Create allow port 8000 Rule - policy.addRule('2', direction="in", priority=100, protocol="tcp", port=8000, action="allow") - - # Add the policy to epg - groups = [] - for cntIdx in range(numContainer): - nodeIdx = cntIdx % testbed.numNodes() - epgName = "srv" + str(cntIdx) - group = network.newGroup(epgName, policies=["first"]) - groups.append(group) - - # start containers - containers = testbed.runContainers(numContainer, withService=True) - - # start netcast listeners - testbed.startListeners(containers, [8000, 8001]) - - # Check connection to all containers - if testbed.checkConnections(containers, 8000, True) != True: - api.tutils.exit("Connection failed") - if testbed.checkConnections(containers, 8001, False) != False: - api.tutils.exit("Connection succeded while expecting it to fail") - - for iter in range(numIter): - - # Add a rule for port 8001 - policy.addRule('3', direction="in", priority=100, protocol="tcp", port=8001, action="allow") - - # now check connection passes - if testbed.checkConnections(containers, 8001, True) != True: - api.tutils.exit("Connection failed to port 8001") - - # Now delete the Rule - policy.deleteRule('3') - - # Now verify connection fails - if testbed.checkConnections(containers, 8001, False) != False: - api.tutils.exit("Connection succeded while expecting it to fail") - - # Check for errors - testbed.chekForNetpluginErrors() - - api.tutils.info("testPolicyAddDeleteRule Iteration " + str(iter) + " Passed") - - # stop netcast listeners - testbed.stopListeners(containers) - - # remove containers - testbed.removeContainers(containers) - - # Remove policy from epg - for group in groups: - group.removePolicy("first") - - # delete epg - for cntIdx in range(numContainer): - nodeIdx = cntIdx % testbed.numNodes() - epgName = "srv" + str(cntIdx) - network.deleteGroup(epgName) - - # Remove the policy and rules - policy.deleteRule('1') - policy.deleteRule('2') - tenant.deletePolicy('first') - tenant.deleteNetwork('private') - - # Check for errors - testbed.chekForNetpluginErrors() - - api.tutils.info("testPolicyAddDeleteRule Test passed") - -# Test basic group based policy -def testPolicyFromEpg(testbed, numContainer, numIter, encap="vxlan"): - api.tutils.info("testPolicyFromEpg starting") - - tenant = api.objmodel.tenant('default') - network = tenant.newNetwork('private', pktTag=1001, subnet="10.1.0.0/16", gateway="10.1.1.254", encap=encap) - - for iter in range(numIter): - # Create common epg - network.newGroup('common') - - # Add the policy to epg - groups = [] - for cntIdx in range(numContainer): - nodeIdx = cntIdx % testbed.numNodes() - srvName = "srv" + str(cntIdx) - - # Create policy for each service - policy = tenant.newPolicy(srvName) - - # create default deny Rule - policy.addRule('1', direction="in", protocol="tcp", action="deny") - - # Create allow port 8000 Rule - policy.addRule('2', direction="in", priority=100, protocol="tcp", port=8000, action="allow") - # Create allow from 'common' epg rule - policy.addRule('3', direction="in", priority=100, endpointGroup="common", network='private', protocol="tcp", port=8001, action="allow") - group = network.newGroup(srvName, policies=[srvName]) - groups.append(group) - - # start containers - containers = testbed.runContainers(numContainer, withService=True) - - # Start containers in common Epg - cmnContainers = testbed.runContainersInService(numContainer, serviceName='common') - - # start netcat listeners - testbed.startListeners(containers, [8000, 8001]) - - # Check connection to all containers - if testbed.checkConnections(containers, 8000, True) != True: - api.tutils.exit("Connection failed") - if testbed.checkConnections(containers, 8001, False) != False: - api.tutils.exit("Connection succeded while expecting it to fail") - if testbed.checkConnectionPair(cmnContainers, containers, 8001, True) != True: - api.tutils.exit("Connection failed") - - # stop netcat listeners - testbed.stopListeners(containers) - - # remove containers - testbed.removeContainers(containers) - testbed.removeContainers(cmnContainers) - - # delete epg - for cntIdx in range(numContainer): - nodeIdx = cntIdx % testbed.numNodes() - srvName = "srv" + str(cntIdx) - network.deleteGroup(srvName) - tenant.deletePolicy(srvName) - - network.deleteGroup('common') - - # Check for errors - testbed.chekForNetpluginErrors() - - api.tutils.info("testPolicyFromEpg Iteration " + str(iter) + " passed") - - # delete the network - tenant.deleteNetwork('private') - - api.tutils.info("testPolicyFromEpg Test passed") - -# Test basic group based policy -def testPolicyFeatures(testbed, encap="vxlan"): - api.tutils.info("testPolicyFeatures starting") - - tenant = api.objmodel.tenant('default') - network = tenant.newNetwork('private', pktTag=1, subnet="10.1.0.0/16", gateway="10.1.1.254", encap=encap) - dummyNet = tenant.newNetwork('dummy', pktTag=2, subnet="20.1.0.0/16", gateway="20.1.1.254", encap=encap) - - # Create policy - pol1 = tenant.newPolicy('first') - pol2 = tenant.newPolicy('second') - - # Add the policy to epg - group1 = network.newGroup("srv1", policies=["first"]) - group2 = network.newGroup("srv2", policies=["second"]) - - # start containers - cnt1 = testbed.nodes[0].runContainer("ubuntu:14.04", networkName='private', serviceName='srv1') - cnt2 = testbed.nodes[0].runContainer("ubuntu:14.04", networkName='private', serviceName='srv2') - - # start netcast listeners - cnt1.startListener(8000) - cnt1.startListener(8001) - cnt2.startListener(8000) - cnt2.startListener(8001) - - # Policy features to test - # - from ip address - # - from network - # - direction out - # - to ip address - # - to network - # - icmp protocol - # - udp protocol -- ??? FIXME: netcat doesnt support udp very well. - - # Make sure connection succeds without any rule - if cnt2.checkConnection(cnt1.getIpAddr(), 8000) != True: - api.tutils.exit("Connection failed") - - api.tutils.log("Teasing incoming rules") - - # create incoming deny rule and verify connection fails - pol1.addRule('1', direction="in", protocol="tcp", action="deny") - if cnt2.checkConnection(cnt1.getIpAddr(), 8000) != False: - api.tutils.exit("Connection succeeded while expecting to fail") - - # Add incoming specific rule and connection succeds - pol1.addRule('2', direction="in", priority=100, protocol="tcp", port=8000, action="allow") - if cnt2.checkConnection(cnt1.getIpAddr(), 8000) != True: - api.tutils.exit("Connection failed") - if cnt2.checkConnection(cnt1.getIpAddr(), 8001) != False: - api.tutils.exit("Connection succeeded while expecting to fail") - - # Add incoming from-EPG rule and verify connection succeds - pol1.addRule('3', direction="in", priority=100, endpointGroup="srv2", network='private', protocol="tcp", port=8001, action="allow") - if cnt2.checkConnection(cnt1.getIpAddr(), 8001) != True: - api.tutils.exit("Connection failed") - - # delete from-epg rule and verify connection fails - pol1.deleteRule('3') - if cnt2.checkConnection(cnt1.getIpAddr(), 8001) != False: - api.tutils.exit("Connection succeeded while expecting to fail") - - # Add incoming from-network rule and verify connection succeds - pol1.addRule('3', direction="in", priority=10, network='private', protocol="tcp", action="allow") - pol1.addRule('4', direction="in", priority=100, network='dummy', protocol="tcp", action="deny") - if cnt2.checkConnection(cnt1.getIpAddr(), 8001) != True: - api.tutils.exit("Connection failed") - - # delete rule and verify connection fails - pol1.deleteRule('3') - pol1.deleteRule('4') - if cnt2.checkConnection(cnt1.getIpAddr(), 8001) != False: - api.tutils.exit("Connection succeeded while expecting to fail") - - - # Add incoming from-ipaddress rule and verify connection succeds - pol1.addRule('3', direction="in", priority=10, ipAddress=cnt2.getIpAddr(), protocol="tcp", action="allow") - pol1.addRule('4', direction="in", priority=100, ipAddress="20.1.1.1/24", protocol="tcp", action="deny") - if cnt2.checkConnection(cnt1.getIpAddr(), 8001) != True: - api.tutils.exit("Connection failed") - - # delete rules - pol1.deleteRule('4') - pol1.deleteRule('3') - pol1.deleteRule('2') - pol1.deleteRule('1') - - ############## Outgoing rule tests ###################### - api.tutils.log("Teasing outgoing rules") - - # Make sure connection succeds without any rule - if cnt2.checkConnection(cnt1.getIpAddr(), 8000) != True: - api.tutils.exit("Connection failed") - - # create outgoign deny rule and verify connection fails - pol1.addRule('1', direction="out", protocol="tcp", action="deny") - if cnt1.checkConnection(cnt2.getIpAddr(), 8000) != False: - api.tutils.exit("Connection succeeded while expecting to fail") - - # Add outgoing specific rule and connection succeds - pol1.addRule('2', direction="out", priority=100, protocol="tcp", port=8000, action="allow") - if cnt1.checkConnection(cnt2.getIpAddr(), 8000) != True: - api.tutils.exit("Connection failed") - if cnt1.checkConnection(cnt2.getIpAddr(), 8001) != False: - api.tutils.exit("Connection succeeded while expecting to fail") - - # Add outgoing to-EPG rule and verify connection succeds - pol1.addRule('3', direction="out", priority=100, endpointGroup="srv2", network='private', protocol="tcp", port=8001, action="allow") - if cnt1.checkConnection(cnt2.getIpAddr(), 8001) != True: - api.tutils.exit("Connection failed") - - # delete to-epg rule and verify connection fails - pol1.deleteRule('3') - if cnt1.checkConnection(cnt2.getIpAddr(), 8001) != False: - api.tutils.exit("Connection succeeded while expecting to fail") - - # Add outgoing to-network rule and verify connection succeds - pol1.addRule('3', direction="out", priority=10, network='private', protocol="tcp", action="allow") - pol1.addRule('4', direction="out", priority=100, network='dummy', protocol="tcp", action="deny") - if cnt1.checkConnection(cnt2.getIpAddr(), 8001) != True: - api.tutils.exit("Connection failed") - - # delete rule and verify connection fails - pol1.deleteRule('3') - pol1.deleteRule('4') - if cnt1.checkConnection(cnt2.getIpAddr(), 8001) != False: - api.tutils.exit("Connection succeeded while expecting to fail") - - - # Add outgoing to to-ipaddress rule and verify connection succeds - pol1.addRule('3', direction="out", priority=10, ipAddress=cnt2.getIpAddr(), protocol="tcp", action="allow") - pol1.addRule('4', direction="out", priority=100, ipAddress="20.1.1.1/24", protocol="tcp", action="deny") - if cnt1.checkConnection(cnt2.getIpAddr(), 8001) != True: - api.tutils.exit("Connection failed") - - # delete rules - pol1.deleteRule('4') - pol1.deleteRule('3') - pol1.deleteRule('2') - pol1.deleteRule('1') - - #################### ICMP rule test ################ - api.tutils.log("Teasing ICMP rules") - - # Make sure ping succeds without any rule - cnt1.checkPing(cnt2.getIpAddr()) - - # Deny incoming ICMP and make sure ping fails - pol1.addRule('1', direction="in", protocol="icmp", action="deny") - cnt1.checkPingFailure(cnt2.getIpAddr()) - - # Add more specific rule and verify ping succeds - pol1.addRule('2', direction="in", priority=100, ipAddress=cnt2.getIpAddr(), protocol="icmp", action="allow") - cnt1.checkPing(cnt2.getIpAddr()) - - # Delete specific rule and verify ping fails - pol1.deleteRule('2') - cnt1.checkPingFailure(cnt2.getIpAddr()) - - # delete rule and make sure ping succeds - pol1.deleteRule('1') - cnt1.checkPing(cnt2.getIpAddr()) - - # stop netcast listeners - cnt1.stopListener() - cnt2.stopListener() - - # remove containers - cnt1.remove() - cnt2.remove() - - # delete epg - network.deleteGroup("srv1") - network.deleteGroup("srv2") - - # Remove the policy and rules - tenant.deletePolicy('first') - tenant.deletePolicy('second') - - # Check for errors - testbed.chekForNetpluginErrors() - - # Delete the network we created - tenant.deleteNetwork('private') - tenant.deleteNetwork('dummy') - - api.tutils.info("testPolicyFeatures Test passed") diff --git a/scripts/python/testcases/tcTrigger.py b/scripts/python/testcases/tcTrigger.py deleted file mode 100644 index 3b0060f04..000000000 --- a/scripts/python/testcases/tcTrigger.py +++ /dev/null @@ -1,395 +0,0 @@ -import api.tutils -import time -import sys -import api.objmodel -import api.etcd -import random - -# Check ping between all containers in the same network -def checkPingContainersInNetworks(containers, networks): - cntrIpList = [] - # Read all IP addresses - for cnt in containers: - cntrIp = cnt.getIpAddr() - cntrIpList.append(cntrIp) - - nidx = random.randint(0, (len(networks) - 1)) - - # Test ping from each container to other container in same network - # We expect ping success for each container in same network - for cidx, cnt in enumerate(containers): - for ipidx, ipAddr in enumerate(cntrIpList): - if (ipidx % len(networks)) == (cidx % len(networks)) and (cidx % len(networks) == nidx): - cnt.checkPing(ipAddr) - -# Check full mesh connection to all containers within a group -def checkConnectionsWithinGroup(containers, groups, port, success): - cntrIpList = [] - # Read all IP addresses - for cnt in containers: - cntrIp = cnt.getIpAddr() - cntrIpList.append(cntrIp) - - gidx = random.randint(0, (len(groups) - 1)) - - # Check connection to all containers - for cidx, cnt in enumerate(containers): - for aidx, ipAddr in enumerate(cntrIpList): - if (cidx % len(groups)) == (aidx % len(groups)) and (cidx % len(groups) == gidx): - ret = cnt.checkConnection(ipAddr, port) - # If connection status is not what we were expecting, we are done. - if ret != success: - return ret - - # Return - return success - -# Check connection to all containers between two neighboring groups -def checkConnectionsAcrossGroup(containers, groups, port, success): - cntrIpList = [] - # Read all IP addresses - for cnt in containers: - cntrIp = cnt.getIpAddr() - cntrIpList.append(cntrIp) - - gidx = random.randint(0, (len(groups) - 1)) - - # Check connection to all containers - for cidx, cnt in enumerate(containers): - for aidx, ipAddr in enumerate(cntrIpList): - cgrp = groups[cidx % len(groups)] - agrp = groups[aidx % len(groups)] - if ((cidx + 1) % len(groups)) == (aidx % len(groups)) and cgrp.networkName == agrp.networkName and (cidx % len(groups) == gidx): - ret = cnt.checkConnection(ipAddr, port) - # If connection status is not what we were expecting, we are done. - if ret != success: - return ret - - # Return - return success - -# Checks all datapth connections -def checkAllConnection(testbed, netContainers, networks, grpContainers, groups): - # Check ping between containes in same network - checkPingContainersInNetworks(netContainers, networks) - - # Check port 8000 and 8001 connecting succeedes within group - if checkConnectionsWithinGroup(grpContainers, groups, 8000, True) != True: - api.tutils.exit("Connection failed") - if checkConnectionsWithinGroup(grpContainers, groups, 8001, True) != True: - api.tutils.exit("Connection failed") - if checkConnectionsAcrossGroup(grpContainers, groups, 8000, True) != True: - api.tutils.exit("Connection failed") - if checkConnectionsAcrossGroup(grpContainers, groups, 8001, False) != False: - api.tutils.exit("Connection succeeded while expecting to fail") - - # Check for errors - testbed.chekForNetpluginErrors() - -# remove all containers -def removeAllContainers(netContainers, grpContainers): - for cnt in netContainers: - cnt.remove() - for cnt in grpContainers: - cnt.remove() - -# Start all containers -def startAllContainers(testbed, netNames, groupNames): - # start containers in each network - numCntr = len(netNames) * testbed.numNodes() * 2 - netContainers = testbed.runContainersInNetworks(numCntr, netNames) - - # start containers in each group - numCntr = len(groupNames) * testbed.numNodes() * 2 - grpContainers = testbed.runContainersInGroups(numCntr, groupNames) - - # start netcat listeners on epg containers - testbed.startListeners(grpContainers, [8000, 8001]) - - # Return newly created containers - return netContainers, grpContainers - -# Trigger netplugin restart -def triggerNetpluginRestart(testbed): - for node in testbed.nodes: - api.tutils.info("Restarting netplugin on " + node.hostname) - node.stopNetplugin() - time.sleep(1) - - # Move old log file - currTime = time.strftime("%H:%M:%S", time.localtime()) - node.runCmd("mv /tmp/netplugin.log /tmp/netplugin-" + currTime + ".log") - - node.startNetplugin() - - # Wait a little - time.sleep(30) - -# Trigger netplugin disconnect/connect -def triggerNetpluginDisconectConnect(testbed): - for node in testbed.nodes: - api.tutils.info("Stopping netplugin on " + node.hostname) - node.stopNetplugin() - - # Wait for netplugin service to expire - time.sleep(50) - - # Move old log file - currTime = time.strftime("%H:%M:%S", time.localtime()) - node.runCmd("mv /tmp/netplugin.log /tmp/netplugin-" + currTime + ".log") - - api.tutils.info("Restarting netplugin on " + node.hostname) - node.startNetplugin() - - # Wait a little - time.sleep(30) - - # Check for errors - testbed.chekForNetpluginErrors() - -# Trigger netmaster restart -def triggerNetmasterRestart(testbed): - for node in testbed.nodes: - api.tutils.info("Restarting netmaster on " + node.hostname) - node.stopNetmaster() - time.sleep(1) - - for node in testbed.nodes: - currTime = time.strftime("%H:%M:%S", time.localtime()) - node.runCmd("mv /tmp/netmaster.log /tmp/netmaster-" + currTime + ".log") - - node.startNetmaster() - time.sleep(1) - - # Wait a little - time.sleep(10) - -# Trigger netmaster restart -def triggerNetmasterSwitchover(testbed): - for node in testbed.nodes: - # Read netmaster service info - srvKey = '/contiv.io/service/netmaster/' + node.addr + ':9999' - srvInfo = api.etcd.etcdClient('http://localhost:4001').getKey(srvKey) - - # Check if its the leader - if srvInfo['Role'] == "leader": - api.tutils.info("Switching over netmaster from " + node.hostname) - node.stopNetmaster() - # Wit till leader lock times out - time.sleep(45) - - currTime = time.strftime("%H:%M:%S", time.localtime()) - node.runCmd("mv /tmp/netmaster.log /tmp/netmaster-" + currTime + ".log") - - node.startNetmaster() - - # Wait a little - time.sleep(10) - - # re-read netmaster service list and make sure someone else is leader - foundLeader = False - srvList = api.etcd.etcdClient('http://localhost:4001').listKey('/contiv.io/service/netmaster/') - for srv in srvList: - if srv['Role'] == "leader": - foundLeader = True - api.tutils.log(srv['HostAddr'] + " is the new leader") - # Make sure new leader is not same as old leader - if srv['HostAddr'] == node.addr: - api.tutils.exit("Netmaster switchover failed (old host is still leader)") - - # Make sure we found atleast one leader - if foundLeader == False: - api.tutils.exit("No Leader found after switchover") - - # Switchover trigger is done - return - - # If we reached here, we found no leader - api.tutils.exit("No Leader found to perform switchover") - -# Trigger removal/add of all containers -def triggerRestartContainers(testbed, netContainers, grpContainers, netNames, groupNames): - # Remove all containers - removeAllContainers(netContainers, grpContainers) - - # Start all containers - return startAllContainers(testbed, netNames, groupNames) - -# Tests multiple triggers and verifies datapath after each trigger -def testMultiTrigger(testbed, numIter, numTenants=1, numNetworksPerTenant=1, numGroupsPerNetwork=2): - # create tenants and networks - tenants = [] - networks = [] - netNames = [] - groups = [] - groupNames = [] - policies = [] - - # Setup tenants, networks and policies - for tidx in range(numTenants): - tenantName = "tenant" + str(tidx) - tenant = api.objmodel.tenant(tenantName) - tenants.append(tenant) - - # Create multiple networks per tenant - for nidx in range(numNetworksPerTenant): - netName = "net" + str(nidx) - subnet = "10." + str(tidx) + "." + str(nidx) + ".0/24" - gateway = "10." + str(tidx) + "." + str(nidx) + ".254" - pktTag = 1001 + (tidx * numNetworksPerTenant) + nidx - network = tenant.newNetwork(netName, pktTag=pktTag, subnet=subnet, gateway=gateway, encap="vxlan") - networks.append(network) - netNames.append(netName + "/" + tenantName) - - # Create multiple EPGs and associated policies - for pidx in range(numGroupsPerNetwork): - srvName = "srv" + str(pidx) - policyName = "srv" + str(pidx) + "_" + netName - - # Create policy for each service - policy = tenant.newPolicy(policyName) - policies.append(policy) - - # create default deny Rule - policy.addRule('1', direction="in", protocol="tcp", action="deny") - - # Create allow port 8000 Rule - policy.addRule('2', direction="in", priority=100, protocol="tcp", port=8000, action="allow") - - # create the EPG - group = network.newGroup(srvName, policies=[policyName]) - groups.append(group) - groupNames.append(srvName + "." + netName + "/" + tenantName) - - # Create allow from this epg rule - policy.addRule('3', direction="in", priority=100, endpointGroup=srvName, network=netName, protocol="tcp", port=8001, action="allow") - - - # start containers in each network and each group - netContainers, grpContainers = startAllContainers(testbed, netNames, groupNames) - - # Check all datapaths - checkAllConnection(testbed, netContainers, networks, grpContainers, groups) - - # Run a random trigger and verify all connections - for iter in range(numIter): - triggerIdx = random.randint(1, 3) - - # Run the specific trigger - if triggerIdx == 1: - triggerName = "triggerNetpluginRestart" - api.tutils.log("Performing trigger " + triggerName) - # restart netplugin - triggerNetpluginRestart(testbed) - elif triggerIdx == 2: - triggerName = "triggerNetmasterRestart" - api.tutils.log("Performing trigger " + triggerName) - # restart netmaster - triggerNetmasterRestart(testbed) - elif triggerIdx == 3: - triggerName = "triggerRestartContainers" - api.tutils.log("Performing trigger " + triggerName) - # restart containers - netContainers, grpContainers = triggerRestartContainers(testbed, netContainers, grpContainers, netNames, groupNames) - else: - api.tutils.exit("Unexpected value") - - api.tutils.log("Performed trigger " + triggerName + " verifying datapath") - - # Check all datapaths after each trigger - checkAllConnection(testbed, netContainers, networks, grpContainers, groups) - - api.tutils.info("testMultiTrigger Iteration " + str(iter) + " trigger " + triggerName + " Passed") - - # Cleanup all containers - removeAllContainers(netContainers, grpContainers) - - # Cleanup all state - for group in groups: - group.delete() - for policy in policies: - policy.delete() - for net in networks: - net.delete() - for tenant in tenants: - tenant.delete() - - # Check for cleanup errors - testbed.chekForNetpluginErrors() - - # Done - api.tutils.info("testMultiTrigger PASSED") - -# Test netmaster switchover tests -def netmasterSwitchoverTest(testbed, numContainer, numIter, encap="vxlan"): - api.tutils.info("netmasterSwitchoverTest starting") - - tenant = api.objmodel.tenant('default') - network = tenant.newNetwork('private', pktTag=1001, subnet="10.1.0.0/16", gateway="10.1.1.254", encap=encap) - - # Always run even number of iterations so that mastership comes back to original node - numIter = numIter + (numIter % 2) - for iter in range(numIter): - # Start the containers - containers = testbed.runContainers(numContainer) - - # Perform netmaster switchover - triggerNetmasterSwitchover(testbed) - - # Perform ping test on the containers - testbed.pingTest(containers) - - # remove containers - for cnt in containers: - cnt.remove() - - # Check for errors - testbed.chekForNetpluginErrors() - - # Iteration is done - api.tutils.info("netmasterSwitchoverTest iteration " + str(iter) + " Passed") - - # Delete the network we created - tenant.deleteNetwork('private') - - # Check for errors - testbed.chekForNetpluginErrors() - - # Test is done - api.tutils.info("netmasterSwitchoverTest Test passed") - -# Test netplugin disconnect/connect -def netpluginDisconnectTest(testbed, numContainer, numIter, encap="vxlan"): - api.tutils.info("netpluginDisconnectTest starting") - - tenant = api.objmodel.tenant('default') - network = tenant.newNetwork('private', pktTag=1001, subnet="10.1.0.0/16", gateway="10.1.1.254", encap=encap) - - for iter in range(numIter): - # Start the containers - containers = testbed.runContainers(numContainer) - - # Perform netplugin disconnect/connect - triggerNetpluginDisconectConnect(testbed) - - # Perform ping test on the containers - testbed.pingTest(containers) - - # remove containers - for cnt in containers: - cnt.remove() - - # Check for errors - testbed.chekForNetpluginErrors() - - # Iteration is done - api.tutils.info("netpluginDisconnectTest iteration " + str(iter) + " Passed") - - # Delete the network we created - tenant.deleteNetwork('private') - - # Check for errors - testbed.chekForNetpluginErrors() - - # Test is done - api.tutils.info("netpluginDisconnectTest Test passed")