def test_120_natOneToOneWanDown(self):
        # create a 1:1 NAT and then down the wan which the NAT is set to
        # if there are more than one WAN
        if remote_control.quickTestsOnly:
            raise unittest2.SkipTest('Skipping a time consuming test')
        if (len(indexOfWans) < 2):
            raise unittest2.SkipTest("Need at least two WANS for combination of wan-balancer and wan failover tests")

        pre_count = global_functions.get_app_metric_value(appWanFailover,"changed")
        
        # raise unittest2.SkipTest('Skipping test_120_natOneToOneWanDown as not possible with current network layout ')
        netsettings = uvmContext.networkManager().getNetworkSettings()
        nukeWanBalancerRules();
        nukeFailoverRules()
        # create valid failover tests
        for wanIndexTup in indexOfWans:
            wanIndex = wanIndexTup[0]
            buildWanTestRule(wanIndex)

        for wanIndexTup in indexOfWans:
            # get the WAN IP address which was source routed
            wanIndex = wanIndexTup[0]
            wanIP = wanIndexTup[1]
            wanExternalIP = wanIndexTup[2]

            # Add networking route which does not handle re-routing if WAN is down
            netsettings['natRules']['list']=[]
            netsettings['natRules']['list'].append(buildNatRule("DST_ADDR",ip_address_testdestination,wanIP))
            uvmContext.networkManager().setNetworkSettings(netsettings)

            # Test that only the routed interface is used 5 times
            subprocess.check_output("ip route flush cache", shell=True)
            for x in range(0, 5):
                result = global_functions.get_public_ip_address()
                print("NAT 1:1 IP %s External IP %s and retrieved IP %s" % (wanIP, wanExternalIP, result))
                assert (result == wanExternalIP)
            # now down the selected wan and see if traffic flows out the other wan
            buildWanTestRule(wanIndex, "ping", "192.168.244.1")
            # Wait for targeted the WAN to be off line before testing that the WAN is off line.
            timeout = 50000
            online = True
            offlineWanIndex = wanIndex
            while online and timeout > 0:
                timeout -= 1
                wanStatus = appWanFailover.getWanStatus()
                for statusInterface in wanStatus['list']:
                    if statusInterface['interfaceId'] == offlineWanIndex:
                        online =  statusInterface['online']
            time.sleep(10) # Let WAN balancer see that the interface is down
            subprocess.check_output("ip route flush cache", shell=True)
            for x in range(0, 5):
                result = global_functions.get_public_ip_address()
                print("WAN Down NAT 1:1 IP %s  External IP %s and retrieved IP %s" % (wanIP, wanExternalIP, result))
                assert (result == wanExternalIP)
            uvmContext.networkManager().setNetworkSettings(orig_netsettings)

        nukeFailoverRules()
        # Check to see if the faceplate counters have incremented. 
        post_count = global_functions.get_app_metric_value(appWanFailover,"changed")
        assert(pre_count < post_count)
    def test_060_routedByPortWan(self):
        # Test that route rules override weighted rules on 2 WANs
        if (len(indexOfWans) < 2):
            raise unittest2.SkipTest(
                "Need at least two WANS for test_060_routedByPortWan")
        nukeWanBalancerRouteRules()

        setWeightOfWan("all", 50)
        # Set all port 80 traffic out the first WAN and 443 on the other
        port80Index = indexOfWans[0][0]
        port80IP = indexOfWans[0][2]
        port443Index = indexOfWans[1][0]
        port443IP = indexOfWans[1][2]
        print "index443 %s" % port443Index
        buildSingleWanRouteRule("DST_PORT", 80, (port80Index))
        buildSingleWanRouteRule("DST_PORT", 443, (port443Index))

        for x in range(0, 9):
            result80 = global_functions.get_public_ip_address()
            result443 = global_functions.get_public_ip_address(
                base_URL="https://test.untangle.com",
                extra_options="--no-check-certificate --secure-protocol=auto")
            print "80 IP %s and 443 IP %s" % (result80, result443)
            assert (result80 == port80IP)
            assert (result443 == port443IP)
    def test_080_routedWanVsNetworkRoute(self):    
        # Test that Networking routes override routed rules in WAN Balancer
        if (len(indexOfWans) < 2):
            raise unittest2.SkipTest("Need at least two WANS for test_080_routedWanVsNetworkRoute")
        netsettings = netsettings = uvmContext.networkManager().getNetworkSettings()
        nukeWanBalancerRouteRules()

        setWeightOfWan("all", 0)
        weightedIndexTup = indexOfWans[0]
        routedIndexTup = indexOfWans[1]
        setWeightOfWan(weightedIndexTup[0], 100)  # set primary to 100%
        # configure route in network which uses the second WAN for test.untangle.com
        routedIP = routedIndexTup[2]
        routedIPGateway = routedIndexTup[3]
        appendRouteRule(createRouteRule(ip_address_testdestination,32,routedIPGateway))
        result1 = global_functions.get_public_ip_address()
        print("Routed IP %s and retrieved IP %s" % (routedIP, result1))
        # Add WAN route IP to Balancer
        buildSingleWanRouteRule("DST_ADDR",ip_address_testdestination,weightedIndexTup[0])
        result2 = global_functions.get_public_ip_address(extra_options="--no-check-certificate --secure-protocol=auto")
        print("Routed IP %s and retrieved IP %s" % (routedIP, result2))
        uvmContext.networkManager().setNetworkSettings(orig_netsettings)

        assert (result1 == routedIP)
        assert (result2 == routedIP)
 def test_020_stickySession(self):
     result = global_functions.get_public_ip_address()
     print("Initial IP address %s" % result)
     for x in range(0, 8):
         result2 = global_functions.get_public_ip_address()
         print("Test IP address %s" % result2)
         assert (result == result2)
    def test_070_weightVsRoutedWan(self):        
        # Test that route rules override weighted rules
        if (len(indexOfWans) < 2):
            raise unittest2.SkipTest("Need at least two WANS for test_070_weightVsRoutedWan")
            
        for x in range(0, 2):
            nukeWanBalancerRouteRules()
            setWeightOfWan("all", 0)
            wanIndexTup = indexOfWans[x]
            wanIndex = wanIndexTup[0]
            setWeightOfWan(wanIndex, 100)
            if (x==0):
                y=1
            else:
                y=0
            weightedIndexTup = indexOfWans[x]
            weightedIP = weightedIndexTup[2]
            routedIndexTup = indexOfWans[y]
            routedIP = routedIndexTup[2]
            # WAN index for route rules is +1 from networking list.  Balance is zero            
            buildSingleWanRouteRule("DST_ADDR",ip_address_testdestination,routedIndexTup[0])

            for x in range(0, 9):
                result = global_functions.get_public_ip_address()
                print("Routed IP %s and retrieved IP %s" % (routedIP, result))
                assert (result == routedIP)
                subprocess.check_output("ip route flush cache", shell=True)
Exemple #6
0
    def test_060_one_wan_offline(self):
        if remote_control.quickTestsOnly:
            raise unittest2.SkipTest('Skipping a time consuming test')
        invalidWanIP = None
        offlineWanIndex = None
        for upWanIndexTup in indexOfWans:
            upWanIndex = upWanIndexTup[0]
            nuke_rules()
            for wanIndexTup in indexOfWans:
                wanIndex = wanIndexTup[0]
                if upWanIndex == wanIndex:
                    # make this interface test disconnected
                    offlineWanIndex = wanIndex
                    build_wan_test(offlineWanIndex,
                                   "ping",
                                   pingHost="192.168.244.1")
                    invalidWanIP = wanIndexTup[2]
                    print "InvalidIP is %s" % invalidWanIP
                else:
                    build_wan_test(wanIndex, "ping")

            wait_for_wan_offline()

            offline_count = offline_wan_count()
            assert (offline_count > 0)

            if (len(indexOfWans) > 1):
                # Skip the WAN IP address check part of the test if test box only has one WAN
                for x in range(0, 8):
                    result = global_functions.get_public_ip_address()
                    print "IP address %s and invalidWanIP %s" % (result,
                                                                 invalidWanIP)
                    assert (result != invalidWanIP)
    def test_110_networkRouteWanDown(self):
        # create a network route and then down the wan which the route is set to
        # if there are more than one WAN
        if remote_control.quickTestsOnly:
            raise unittest2.SkipTest('Skipping a time consuming test')
        if (len(indexOfWans) < 2):
            raise unittest2.SkipTest(
                "Need at least two WANS for combination of wan-balancer and wan failover tests"
            )
        netsettings = netsettings = uvmContext.networkManager(
        ).getNetworkSettings()
        nukeWanBalancerRules()

        for wanIndexTup in indexOfWans:
            # Add networking route which does not handle re-routing if WAN is down
            # get the WAN IP address which was source routed
            wanIndex = wanIndexTup[0]
            # Get the external IP of the interface selected.
            routedIP = wanIndexTup[2]
            wanGatewayIP = wanIndexTup[3]
            netsettings['staticRoutes']['list'] = []
            netsettings['staticRoutes']['list'].append(
                createRouteRule(ip_address_testdestination, 32, wanGatewayIP))
            uvmContext.networkManager().setNetworkSettings(netsettings)
            # Test that only the routed interface is used 5 times
            subprocess.check_output("ip route flush cache", shell=True)
            for x in range(0, 5):
                result = remote_control.run_command(
                    "wget --timeout=4 -q -O - \"$@\" test.untangle.com/cgi-bin/myipaddress.py",
                    stdout=True)
                print "Network Routed IP %s and retrieved IP %s" % (routedIP,
                                                                    result)
                assert (result == routedIP)
            # now down the selected wan and see if traffic flows out the other wan
            buildWanTestRule(wanIndex, "ping", "192.168.244.1")
            # Wait for targeted the WAN to be off line before testing that the WAN is off line.
            timeout = 50000
            online = True
            offlineWanIndex = wanIndex
            while online and timeout > 0:
                timeout -= 1
                wanStatus = appWanFailover.getWanStatus()
                for statusInterface in wanStatus['list']:
                    if statusInterface['interfaceId'] == offlineWanIndex:
                        online = statusInterface['online']
            time.sleep(10)  # Let WAN balancer see that the interface is down
            subprocess.check_output("ip route flush cache", shell=True)
            for x in range(0, 5):
                result = global_functions.get_public_ip_address()
                print "WAN Down Network Routed IP %s and retrieved IP %s" % (
                    routedIP, result)
                assert (result == routedIP)

        nukeFailoverRules()
        uvmContext.networkManager().setNetworkSettings(orig_netsettings)
Exemple #8
0
    def test_100_wanBalancerRouteWanDown(self):
        # create a source route and then down the wan which the route is set to
        # if there are more than one WAN
        if remote_control.quickTestsOnly:
            raise unittest2.SkipTest('Skipping a time consuming test')
        if (len(index_of_wans) < 2):
            raise unittest2.SkipTest(
                "Need at least two WANS for combination of wan-balancer and wan failover tests"
            )
        if same_wan_network(index_of_wans):
            raise unittest2.SkipTest("WANS on same network")

        netsettings = uvmContext.networkManager().getNetworkSettings()
        for wanIndexTup in index_of_wans:
            wanIndex = wanIndexTup[0]
            nuke_wan_balancer_rules()
            # Get the external IP of the interface selected.
            routedIP = wanIndexTup[2]
            # WAN index for route rules is from networking list.  Balance is zero
            build_single_wan_route_rule("DST_ADDR", ip_address_testdestination,
                                        wanIndex)
            # Test that only the routed interface is used 5 times2
            subprocess.check_output("ip route flush cache", shell=True)
            for x in range(0, 5):
                result = remote_control.run_command(
                    "wget --timeout=4 -q -O - \"$@\" test.untangle.com/cgi-bin/myipaddress.py",
                    stdout=True)
                print("WAN Balancer Routed IP %s and retrieved IP %s" %
                      (routedIP, result))
                assert (result == routedIP)
            # now down the selected wan and see if traffic flows out the other wan
            build_wan_test_rule(wanIndex, "ping", "192.168.244.1")
            # Wait for targeted the WAN to be off line before testing that the WAN is off line.
            timeout = 50000
            online = True
            offlineWanIndex = wanIndex
            while online and timeout > 0:
                timeout -= 1
                wanStatus = app_wan_failover.getWanStatus()
                for statusInterface in wanStatus['list']:
                    if statusInterface['interfaceId'] == offlineWanIndex:
                        online = statusInterface['online']
            time.sleep(10)  # Let WAN balancer see that the interface is down
            subprocess.check_output("ip route flush cache", shell=True)
            for x in range(0, 5):
                result = global_functions.get_public_ip_address()
                print(
                    "WAN Down WAN Balancer Routed IP %s and retrieved IP %s" %
                    (routedIP, result))
                assert (result != routedIP)

        nuke_wan_balancer_rules()
        nuke_wan_failover_rules()
    def test_090_heavyWeightWanDown(self):
        # Set the one WAN as 100 weight and the other as zero and down the 100 weight wan
        # if there are more than one WAN
        if (len(indexOfWans) < 2):
            raise unittest2.SkipTest(
                "Need at least two WANS for combination of wan-balancer and wan failover tests"
            )
        # initialize all the weights to 50
        nukeWanBalancerRules()
        # create valid failover tests
        for wanIndexTup in indexOfWans:
            buildWanTestRule(wanIndexTup[0])
        result = remote_control.is_online()
        assert (result == 0)
        for wanIndexTup in indexOfWans:
            wanIndex = wanIndexTup[0]
            # set the selected wan to 100 and others to zero
            setWeightOfWan("all", 0)
            setWeightOfWan(wanIndex, 100)
            # Set the weighted interface with invalid rule
            buildWanTestRule(wanIndex, "ping", "192.168.244.1")
            # get the WAN IP address which was weighted to 100
            weightedIP = wanIndexTup[1]
            # Wait for targeted the WAN to be off line before testing that the WAN is off line.
            timeout = 50000
            online = True
            offlineWanIndex = wanIndex
            while online and timeout > 0:
                timeout -= 1
                wanStatus = appWanFailover.getWanStatus()
                for statusInterface in wanStatus['list']:
                    if statusInterface['interfaceId'] == offlineWanIndex:
                        online = statusInterface['online']
            time.sleep(
                10)  # Let WAN balancer see that the heavy interface is down
            # Test that other interfaces are used 10 times
            for x in range(0, 9):
                result = global_functions.get_public_ip_address()
                print "Weighted IP %s and retrieved IP %s" % (weightedIP,
                                                              result)
                assert (result != weightedIP)
            # reset weight to zero and interface to valid rule
            setWeightOfWan(wanIndex, 0)
            buildWanTestRule(wanIndex)

        # return settings to default
        nukeWanBalancerRules()
        nukeFailoverRules()
    def test_050_routedByIPWan(self):
        if (len(indexOfWans) < 2):
            raise unittest2.SkipTest("Need at least two WANS for test_050_routedByIPWan")
        # Set weighting to default 
        setWeightOfWan("all", 50)

        for wanIndexTup in indexOfWans:
            wanIndex = wanIndexTup[0]
            nukeWanBalancerRouteRules()
            # Get the external IP of the interface selected.
            routedIP = wanIndexTup[2]
            buildSingleWanRouteRule("DST_ADDR",ip_address_testdestination,wanIndex)
            # Test that only the routed interface is used 10 times
            for x in range(0, 9):
                result = global_functions.get_public_ip_address()
                print("Routed IP %s and retrieved IP %s" % (routedIP, result))
                assert (result == routedIP)
        nukeWanBalancerRouteRules()
 def test_030_heavyWeightWan(self):
     # Set the one WAN as 100 weight and the other as zero and vice versa.
     if (len(indexOfWans) < 2):
         raise unittest2.SkipTest("Need at least two WANS for test_030_heavyWeightWan")
     setWeightOfWan("all", 0)
     for wanIndexTup in indexOfWans:
         wanIndex = wanIndexTup[0]
         setWeightOfWan(wanIndex, 100)
         # get the WAN IP address which was weighted to 100
         weightedIP = wanIndexTup[2]
         # Test that only the weighted interface is used 10 times
         for x in range(0, 9):
             result = global_functions.get_public_ip_address()
             print("Weighted IP %s and retrieved IP %s" % (weightedIP, result))
             assert (result == weightedIP)
         # reset weight to zero
         setWeightOfWan(wanIndex, 0)
     # return weight settings to default
     setWeightOfWan("all", 50)
Exemple #12
0
    def test_065_all_wan_offline_but_one(self):
        if remote_control.quickTestsOnly:
            raise unittest2.SkipTest('Skipping a time consuming test')
        if (len(indexOfWans) < 2):
            raise unittest2.SkipTest(
                "Need at least two WANS for test_065_downAllButOneWan")
        pre_count = global_functions.get_app_metric_value(app, "changed")

        validWanIP = None
        # loop through the WANs keeping one up and the rest down.
        for upWanIndexTup in indexOfWans:
            upWanIndex = upWanIndexTup[0]
            nuke_rules()
            for wanIndexTup in indexOfWans:
                wanIndex = wanIndexTup[0]
                if upWanIndex != wanIndex:
                    # make this interface test disconnected
                    build_wan_test(wanIndex, "ping", pingHost="192.168.244.1")
                else:
                    validWanIP = wanIndexTup[2]
                    build_wan_test(upWanIndex, "ping", pingHost="8.8.8.8")
                    print "validIP is %s" % validWanIP

            wait_for_wan_offline()

            online_count = online_wan_count()
            offline_count = offline_wan_count()

            assert (online_count == 1)
            assert (offline_count > 0)

            for x in range(0, 8):
                result = global_functions.get_public_ip_address()
                print "IP address %s and validWanIP %s" % (result, validWanIP)
                assert (result == validWanIP)

        # Check to see if the faceplate counters have incremented.
        post_count = global_functions.get_app_metric_value(app, "changed")
        assert (pre_count < post_count)