incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chirad...@apache.org
Subject [27/39] git commit: Network-refactor: interaction between firewall manager and network manager changed, verify this works as expected
Date Fri, 18 Jan 2013 01:01:22 GMT
Network-refactor: interaction between firewall manager and network manager changed, verify
this works as expected

Signed-off-by: Chiradeep Vittal <chiradeep@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/dbe3fe2d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/dbe3fe2d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/dbe3fe2d

Branch: refs/heads/master
Commit: dbe3fe2d34e7deb0f6b9fceac32416db2c3917d2
Parents: 728db6c
Author: Chiradeep Vittal <chiradeep@apache.org>
Authored: Wed Jan 9 14:14:00 2013 -0800
Committer: Chiradeep Vittal <chiradeep@apache.org>
Committed: Wed Jan 9 15:49:02 2013 -0800

----------------------------------------------------------------------
 .../test/com/cloud/network/NetworkManagerTest.java |    3 -
 .../network/firewall/FirewallManagerTest.java      |   90 +++++++++++++++
 2 files changed, 90 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/dbe3fe2d/server/test/com/cloud/network/NetworkManagerTest.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/network/NetworkManagerTest.java b/server/test/com/cloud/network/NetworkManagerTest.java
index 6fdf35f..c0856d6 100644
--- a/server/test/com/cloud/network/NetworkManagerTest.java
+++ b/server/test/com/cloud/network/NetworkManagerTest.java
@@ -25,9 +25,6 @@ import org.junit.Test;
 
 import com.cloud.network.element.DhcpServiceProvider;
 import com.cloud.network.element.IpDeployer;
-import com.cloud.network.firewall.FirewallManagerImpl;
-import com.cloud.network.firewall.FirewallManagerTest;
-import com.cloud.network.rules.FirewallManager;
 import com.cloud.utils.component.ComponentLocator;
 import com.cloud.utils.testcase.ComponentSetup;
 import com.cloud.utils.testcase.ComponentTestCase;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/dbe3fe2d/server/test/com/cloud/network/firewall/FirewallManagerTest.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/network/firewall/FirewallManagerTest.java b/server/test/com/cloud/network/firewall/FirewallManagerTest.java
index b17741f..c4470d2 100644
--- a/server/test/com/cloud/network/firewall/FirewallManagerTest.java
+++ b/server/test/com/cloud/network/firewall/FirewallManagerTest.java
@@ -18,17 +18,38 @@
 package com.cloud.network.firewall;
 
 
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.List;
+
 import junit.framework.Assert;
 
 import org.apache.log4j.Logger;
 import org.junit.Test;
 
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.Network;
+import com.cloud.network.NetworkManager;
+import com.cloud.network.NetworkRuleApplier;
 import com.cloud.network.element.FirewallServiceProvider;
 import com.cloud.network.element.NetworkACLServiceProvider;
 import com.cloud.network.element.PortForwardingServiceProvider;
 import com.cloud.network.element.StaticNatServiceProvider;
+import com.cloud.network.element.VirtualRouterElement;
+import com.cloud.network.element.VpcVirtualRouterElement;
 import com.cloud.network.rules.FirewallManager;
+import com.cloud.network.rules.FirewallRule;
+import com.cloud.network.rules.FirewallRule.Purpose;
+import com.cloud.network.rules.FirewallRuleVO;
+import com.cloud.utils.component.Adapter;
+import com.cloud.utils.component.Adapters;
 import com.cloud.utils.component.ComponentLocator;
+import com.cloud.utils.component.ComponentLocator.ComponentInfo;
 import com.cloud.utils.testcase.ComponentSetup;
 import com.cloud.utils.testcase.ComponentTestCase;
 
@@ -63,5 +84,74 @@ public class FirewallManagerTest extends ComponentTestCase {
         s_logger.info("Done testing injection of service elements into firewall manager");
 
     }
+    
+    @Test
+    public void testApplyRules() {
+        List<FirewallRuleVO> ruleList = new ArrayList<FirewallRuleVO>();
+        FirewallRuleVO rule = 
+                new FirewallRuleVO("rule1", 1, 80, "TCP", 1, 2, 1, 
+                        FirewallRule.Purpose.Firewall, null, null, null, null);
+        ruleList.add(rule);
+        FirewallManagerImpl firewallMgr = (FirewallManagerImpl)ComponentLocator.getCurrentLocator().getManager(FirewallManager.class);
+        
+        NetworkManager netMgr = mock(NetworkManager.class);
+        firewallMgr._networkMgr = netMgr;
+        
+        try {
+            firewallMgr.applyRules(ruleList, false, false);
+            verify(netMgr)
+                   .applyRules(any(List.class), 
+                         any(FirewallRule.Purpose.class), 
+                         any(NetworkRuleApplier.class), 
+                         anyBoolean());
+            
+        } catch (ResourceUnavailableException e) {
+            Assert.fail("Unreachable code");
+        }
+    }
+    
+    @Test
+    public void testApplyFWRules() {
+        List<FirewallRuleVO> ruleList = new ArrayList<FirewallRuleVO>();
+        FirewallRuleVO rule = 
+                new FirewallRuleVO("rule1", 1, 80, "TCP", 1, 2, 1, 
+                        FirewallRule.Purpose.Firewall, null, null, null, null);
+        ruleList.add(rule);
+        FirewallManagerImpl firewallMgr = (FirewallManagerImpl)ComponentLocator.getCurrentLocator().getManager(FirewallManager.class);
+        VirtualRouterElement virtualRouter =  
+                mock(VirtualRouterElement.class);
+        VpcVirtualRouterElement vpcVirtualRouter =                  
+                mock(VpcVirtualRouterElement.class);
+        ComponentInfo<Adapter> c1 = 
+                new ComponentInfo<Adapter>("VirtualRouter", 
+                        VirtualRouterElement.class, virtualRouter);
+        ComponentInfo<Adapter> c2 = 
+                new ComponentInfo<Adapter>("VpcVirtualRouter", 
+                        VpcVirtualRouterElement.class, vpcVirtualRouter);
+        List<ComponentInfo<Adapter>> adapters = 
+                new ArrayList<ComponentLocator.ComponentInfo<Adapter>>();
+        adapters.add(c1);
+        adapters.add(c2);
+        Adapters<FirewallServiceProvider> fwElements = 
+                new Adapters<FirewallServiceProvider>("firewalElements", adapters);
+        firewallMgr._firewallElements = fwElements;
+        
+        try {
+            when(
+                  virtualRouter.applyFWRules(any(Network.class), any(List.class))
+                ).thenReturn(false);
+            when(
+                    vpcVirtualRouter.applyFWRules(any(Network.class), any(List.class))
+                  ).thenReturn(true);
+            //Network network, Purpose purpose, List<? extends FirewallRule> rules
+            firewallMgr.applyRules(mock(Network.class), Purpose.Firewall, ruleList);
+            verify(vpcVirtualRouter).applyFWRules(any(Network.class), any(List.class));
+            verify(virtualRouter).applyFWRules(any(Network.class), any(List.class));
+
+            
+        } catch (ResourceUnavailableException e) {
+            Assert.fail("Unreachable code");
+        }
+    }
 
 }


Mime
View raw message