cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhais...@apache.org
Subject [3/4] git commit: updated refs/heads/4.3 to 1f21c29
Date Tue, 25 Nov 2014 11:43:47 GMT
CLOUDSTACK-7917: Validating Load Balancer Rule when updating LB + unit test

Signed-off-by: Rajani Karuturi <rajanikaruturi@gmail.com>
(cherry picked from commit c919ff83d81528b89017b5f5731b2e46350e3dfa)
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>

Conflicts:
	server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java


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

Branch: refs/heads/4.3
Commit: c2f367982ec75977c3d67f726cdc028c71b63bc3
Parents: a62fa62
Author: Daniel Vega <daniel.simoes@corp.globo.com>
Authored: Wed Nov 19 19:01:35 2014 -0200
Committer: Rohit Yadav <rohit.yadav@shapeblue.com>
Committed: Tue Nov 25 14:19:16 2014 +0530

----------------------------------------------------------------------
 .../lb/LoadBalancingRulesManagerImpl.java       |   6 +
 .../network/lb/UpdateLoadBalancerTest.java      | 127 +++++++++++++++++++
 2 files changed, 133 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c2f36798/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
index b830910..cdb38f0 100755
--- a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
+++ b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
@@ -1989,6 +1989,12 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase
implements
             lb.setAlgorithm(algorithm);
         }
 
+        // Validate rule in LB provider
+        LoadBalancingRule rule = getLoadBalancerRuleToApply(lb);
+        if (!validateLbRule(rule)) {
+            throw new InvalidParameterValueException("Modifications in lb rule " + lbRuleId
+ " are not supported.");
+        }
+
         boolean success = _lbDao.update(lbRuleId, lb);
 
         // If algorithm is changed, have to reapply the lb config

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c2f36798/server/test/com/cloud/network/lb/UpdateLoadBalancerTest.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/network/lb/UpdateLoadBalancerTest.java b/server/test/com/cloud/network/lb/UpdateLoadBalancerTest.java
new file mode 100644
index 0000000..f3a938c
--- /dev/null
+++ b/server/test/com/cloud/network/lb/UpdateLoadBalancerTest.java
@@ -0,0 +1,127 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.network.lb;
+
+import static org.mockito.Matchers.anyLong;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.UUID;
+
+import org.apache.cloudstack.api.command.user.loadbalancer.UpdateLoadBalancerRuleCmd;
+import org.apache.cloudstack.context.CallContext;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InOrder;
+import org.mockito.Mockito;
+
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.Network;
+import com.cloud.network.NetworkModel;
+import com.cloud.network.PublicIpAddress;
+import com.cloud.network.as.dao.AutoScaleVmGroupDao;
+import com.cloud.network.dao.LBHealthCheckPolicyDao;
+import com.cloud.network.dao.LBStickinessPolicyDao;
+import com.cloud.network.dao.LoadBalancerCertMapDao;
+import com.cloud.network.dao.LoadBalancerDao;
+import com.cloud.network.dao.LoadBalancerVMMapDao;
+import com.cloud.network.dao.LoadBalancerVO;
+import com.cloud.network.dao.NetworkDao;
+import com.cloud.network.dao.NetworkVO;
+import com.cloud.network.element.LoadBalancingServiceProvider;
+import com.cloud.user.Account;
+import com.cloud.user.AccountVO;
+import com.cloud.user.MockAccountManagerImpl;
+import com.cloud.user.UserVO;
+
+public class UpdateLoadBalancerTest {
+
+    LoadBalancingRulesManagerImpl _lbMgr = new LoadBalancingRulesManagerImpl();
+
+    private UpdateLoadBalancerRuleCmd updateLbRuleCmd;
+    private LoadBalancerDao lbDao = Mockito.mock(LoadBalancerDao.class);
+    private NetworkDao netDao = Mockito.mock(NetworkDao.class);
+    private NetworkModel netModel = Mockito.mock(NetworkModel.class);
+    private LoadBalancingServiceProvider lbServiceProvider= Mockito.mock(LoadBalancingServiceProvider.class);
+
+    private static long domainId = 5L;
+    private static String accountName = "admin";
+
+    @Before
+    public void setUp() {
+        _lbMgr._accountMgr = new MockAccountManagerImpl();
+        _lbMgr._autoScaleVmGroupDao = Mockito.mock(AutoScaleVmGroupDao.class);
+        _lbMgr._networkDao = netDao;
+        _lbMgr._networkModel = netModel;
+        _lbMgr._lb2healthcheckDao = Mockito.mock(LBHealthCheckPolicyDao.class);
+        _lbMgr._lb2stickinesspoliciesDao = Mockito.mock(LBStickinessPolicyDao.class);
+        _lbMgr._lb2VmMapDao = Mockito.mock(LoadBalancerVMMapDao.class);
+        _lbMgr._lbCertMapDao = Mockito.mock(LoadBalancerCertMapDao.class);
+        _lbMgr._lbDao = lbDao;
+        _lbMgr._lbProviders = new ArrayList<LoadBalancingServiceProvider>();
+        _lbMgr._lbProviders.add(lbServiceProvider);
+
+        updateLbRuleCmd = new UpdateLoadBalancerRuleCmd();
+
+        AccountVO account = new AccountVO(accountName, domainId, "networkDomain", Account.ACCOUNT_TYPE_NORMAL,
"uuid");
+        UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email",
"timezone", UUID.randomUUID().toString());
+        CallContext.register(user, account);
+    }
+
+    @Test
+    public void testValidateRuleBeforeUpdateLB() throws ResourceAllocationException, ResourceUnavailableException,
InsufficientCapacityException {
+
+        LoadBalancerVO lb = new LoadBalancerVO(null, null, null, 0L, 0, 0, null, 0L, 0L,
domainId, null);
+
+        when(lbDao.findById(anyLong())).thenReturn(lb);
+        when(netModel.getPublicIpAddress(anyLong())).thenReturn(Mockito.mock(PublicIpAddress.class));
+        when(netDao.findById(anyLong())).thenReturn(Mockito.mock(NetworkVO.class));
+        when(lbServiceProvider.validateLBRule(any(Network.class), any(LoadBalancingRule.class))).thenReturn(true);
+        when(lbDao.update(anyLong(), eq(lb))).thenReturn(true);
+
+        _lbMgr.updateLoadBalancerRule(updateLbRuleCmd);
+
+        InOrder inOrder = Mockito.inOrder(lbServiceProvider, lbDao);
+        inOrder.verify(lbServiceProvider).validateLBRule(any(Network.class), any(LoadBalancingRule.class));
+        inOrder.verify(lbDao).update(anyLong(), eq(lb));
+    }
+
+    @Test(expected = InvalidParameterValueException.class)
+    public void testRuleNotValidated() throws ResourceAllocationException, ResourceUnavailableException,
InsufficientCapacityException {
+
+        LoadBalancerVO lb = new LoadBalancerVO(null, null, null, 0L, 0, 0, null, 0L, 0L,
domainId, null);
+
+        when(lbDao.findById(anyLong())).thenReturn(lb);
+        when(netModel.getPublicIpAddress(anyLong())).thenReturn(Mockito.mock(PublicIpAddress.class));
+        when(netDao.findById(anyLong())).thenReturn(Mockito.mock(NetworkVO.class));
+        when(lbServiceProvider.validateLBRule(any(Network.class), any(LoadBalancingRule.class))).thenReturn(false);
+
+        _lbMgr.updateLoadBalancerRule(updateLbRuleCmd);
+    }
+
+    @After
+    public void tearDown() {
+        CallContext.unregister();
+    }
+
+}
\ No newline at end of file


Mime
View raw message