cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From likit...@apache.org
Subject [1/2] Dedicate guest vlan range to account
Date Wed, 01 May 2013 10:30:19 GMT
Updated Branches:
  refs/heads/dedicate-guest-vlan-ranges_2 [created] eef8e9c6e


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eef8e9c6/server/test/com/cloud/network/DedicateGuestVlanRangesTest.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/network/DedicateGuestVlanRangesTest.java b/server/test/com/cloud/network/DedicateGuestVlanRangesTest.java
new file mode 100755
index 0000000..45ec791
--- /dev/null
+++ b/server/test/com/cloud/network/DedicateGuestVlanRangesTest.java
@@ -0,0 +1,372 @@
+// 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;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+import java.lang.reflect.Field;
+
+import org.apache.cloudstack.api.command.admin.network.DedicateGuestVlanRangeCmd;
+import org.apache.cloudstack.api.command.admin.network.ListDedicatedGuestVlanRangesCmd;
+import org.apache.cloudstack.api.command.admin.network.ReleaseDedicatedGuestVlanRangeCmd;
+
+import org.apache.log4j.Logger;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import com.cloud.dc.DataCenterVnetVO;
+import com.cloud.dc.dao.DataCenterVnetDao;
+import com.cloud.network.dao.AccountGuestVlanMapDao;
+import com.cloud.network.dao.AccountGuestVlanMapVO;
+import com.cloud.network.dao.PhysicalNetworkDao;
+import com.cloud.network.dao.PhysicalNetworkVO;
+import com.cloud.projects.ProjectManager;
+import com.cloud.user.Account;
+import com.cloud.user.dao.AccountDao;
+import com.cloud.user.AccountManager;
+import com.cloud.user.AccountVO;
+import com.cloud.user.UserContext;
+import com.cloud.utils.db.Transaction;
+
+import junit.framework.Assert;
+
+import static org.mockito.Matchers.*;
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.doNothing;
+
+public class DedicateGuestVlanRangesTest {
+
+    private static final Logger s_logger = Logger.getLogger(DedicateGuestVlanRangesTest.class);
+
+    NetworkServiceImpl networkService = new NetworkServiceImpl();
+
+    DedicateGuestVlanRangeCmd dedicateGuestVlanRangesCmd = new DedicateGuestVlanRangeCmdExtn();
+    Class<?> _dedicateGuestVlanRangeClass = dedicateGuestVlanRangesCmd.getClass().getSuperclass();
+
+    ReleaseDedicatedGuestVlanRangeCmd releaseDedicatedGuestVlanRangesCmd = new ReleaseDedicatedGuestVlanRangeCmdExtn();
+    Class<?> _releaseGuestVlanRangeClass = releaseDedicatedGuestVlanRangesCmd.getClass().getSuperclass();
+
+    ListDedicatedGuestVlanRangesCmd listDedicatedGuestVlanRangesCmd = new ListDedicatedGuestVlanRangesCmdExtn();
+    Class<?> _listDedicatedGuestVlanRangeClass = listDedicatedGuestVlanRangesCmd.getClass().getSuperclass();
+
+
+    @Mock AccountManager _accountMgr;
+    @Mock AccountDao _accountDao;
+    @Mock ProjectManager _projectMgr;
+    @Mock PhysicalNetworkDao _physicalNetworkDao;
+    @Mock DataCenterVnetDao _dataCenterVnetDao;
+    @Mock AccountGuestVlanMapDao _accountGuestVlanMapDao;
+
+    @Before
+    public void setup() throws Exception {
+        MockitoAnnotations.initMocks(this);
+
+        networkService._accountMgr = _accountMgr;
+        networkService._accountDao = _accountDao;
+        networkService._projectMgr = _projectMgr;
+        networkService._physicalNetworkDao = _physicalNetworkDao;
+        networkService._datacneter_vnet = _dataCenterVnetDao;
+        networkService._accountGuestVlanMapDao = _accountGuestVlanMapDao;
+
+        Account account = (Account) new AccountVO("testaccount", 1, "networkdomain", (short)
0, UUID.randomUUID().toString());
+        when(networkService._accountMgr.getAccount(anyLong())).thenReturn(account);
+        when(networkService._accountDao.findActiveAccount(anyString(), anyLong())).thenReturn(account);
+
+        UserContext.registerContext(1, account, null, true);
+
+        Field accountNameField = _dedicateGuestVlanRangeClass.getDeclaredField("accountName");
+        accountNameField.setAccessible(true);
+        accountNameField.set(dedicateGuestVlanRangesCmd, "accountname");
+
+        Field projectIdField = _dedicateGuestVlanRangeClass.getDeclaredField("projectId");
+        projectIdField.setAccessible(true);
+        projectIdField.set(dedicateGuestVlanRangesCmd, null);
+
+        Field domainIdField = _dedicateGuestVlanRangeClass.getDeclaredField("domainId");
+        domainIdField.setAccessible(true);
+        domainIdField.set(dedicateGuestVlanRangesCmd, 1L);
+
+        Field physicalNetworkIdField = _dedicateGuestVlanRangeClass.getDeclaredField("physicalNetworkId");
+        physicalNetworkIdField.setAccessible(true);
+        physicalNetworkIdField.set(dedicateGuestVlanRangesCmd, 1L);
+
+        Field releaseIdField = _releaseGuestVlanRangeClass.getDeclaredField("id");
+        releaseIdField.setAccessible(true);
+        releaseIdField.set(releaseDedicatedGuestVlanRangesCmd, 1L);
+    }
+
+    @Test
+    public void testDedicateGuestVlanRange() throws Exception {
+        s_logger.info("Running tests for DedicateGuestVlanRange API");
+
+        /*
+         * TEST 1: given valid parameters DedicateGuestVlanRange should succeed
+         */
+        runDedicateGuestVlanRangePostiveTest();
+
+        /*
+        * TEST 2: given invalid format for vlan range DedicateGuestVlanRange should fail
+        */
+        runDedicateGuestVlanRangeInvalidFormat();
+
+        /*
+         * TEST 3: given vlan range that doesn't exist in the system request should fail
+         */
+        runDedicateGuestVlanRangeInvalidRangeValue();
+
+        /*
+         * TEST 4: given vlan range has vlans that are allocated to a different account request
should fail
+         */
+        runDedicateGuestVlanRangeAllocatedVlans();
+
+        /*
+         * TEST 5: given vlan range is already dedicated to another account request should
fail
+         */
+        runDedicateGuestVlanRangeDedicatedRange();
+
+        /*
+         * TEST 6: given vlan range is partially dedicated to a different account request
should fail
+         */
+        runDedicateGuestVlanRangePartiallyDedicated();
+    }
+
+    @Test
+    public void testReleaseDedicatedGuestVlanRange() throws Exception {
+
+        s_logger.info("Running tests for ReleaseDedicatedGuestVlanRange API");
+
+        /*
+         * TEST 1: given valid parameters ReleaseDedicatedGuestVlanRange should succeed
+         */
+        runReleaseDedicatedGuestVlanRangePostiveTest();
+
+        /*
+         * TEST 2: given range doesn't exist request should fail
+         */
+        runReleaseDedicatedGuestVlanRangeInvalidRange();
+    }
+
+    void runDedicateGuestVlanRangePostiveTest() throws Exception {
+        Transaction txn = Transaction.open("runDedicateGuestVlanRangePostiveTest");
+        
+        Field dedicateVlanField = _dedicateGuestVlanRangeClass.getDeclaredField("vlan");
+        dedicateVlanField.setAccessible(true);
+        dedicateVlanField.set(dedicateGuestVlanRangesCmd, "2-5");
+
+        PhysicalNetworkVO physicalNetwork = new PhysicalNetworkVO(1L, 1L, "2-5", "200", 1L,
null, "testphysicalnetwork");
+        AccountGuestVlanMapVO accountGuestVlanMapVO = new AccountGuestVlanMapVO(1L,1L);
+
+        when(networkService._physicalNetworkDao.findById(anyLong())).thenReturn(physicalNetwork);
+
+        when(networkService._datacneter_vnet.listAllocatedVnetsInRange(anyLong(), anyLong(),
anyInt(), anyInt())).thenReturn(null);
+
+        when(networkService._accountGuestVlanMapDao.listAccountGuestVlanMapsByPhysicalNetwork(anyLong())).thenReturn(null);
+
+        when(networkService._accountGuestVlanMapDao.persist(any(AccountGuestVlanMapVO.class))).thenReturn(accountGuestVlanMapVO);
+
+        when(networkService._datacneter_vnet.update(anyLong(), any(DataCenterVnetVO.class))).thenReturn(true);
+
+        List<DataCenterVnetVO> dataCenterVnetList = new ArrayList<DataCenterVnetVO>();
+        DataCenterVnetVO dataCenterVnetVO = new DataCenterVnetVO("2-5", 1L, 1L);
+        dataCenterVnetList.add(dataCenterVnetVO);
+        when(networkService._datacneter_vnet.findVnet(anyLong(), anyString())).thenReturn(dataCenterVnetList);
+
+        try {
+            GuestVlan result = networkService.dedicateGuestVlanRange(dedicateGuestVlanRangesCmd);
+            Assert.assertNotNull(result);
+        } catch (Exception e) {
+            s_logger.info("exception in testing runDedicateGuestVlanRangePostiveTest message:
" + e.toString());
+        } finally {
+            txn.close("runDedicateGuestRangePostiveTest");
+        }
+    }
+
+    void runDedicateGuestVlanRangeInvalidFormat() throws Exception {
+        Transaction txn = Transaction.open("runDedicateGuestVlanRangeInvalidFormat");
+
+        Field dedicateVlanField = _dedicateGuestVlanRangeClass.getDeclaredField("vlan");
+        dedicateVlanField.setAccessible(true);
+        dedicateVlanField.set(dedicateGuestVlanRangesCmd, "2");
+
+        PhysicalNetworkVO physicalNetwork = new PhysicalNetworkVO(1L, 1L, "2-5", "200", 1L,
null, "testphysicalnetwork");
+
+        when(networkService._physicalNetworkDao.findById(anyLong())).thenReturn(physicalNetwork);
+
+        try {
+            networkService.dedicateGuestVlanRange(dedicateGuestVlanRangesCmd);
+        } catch (Exception e) {
+            Assert.assertTrue(e.getMessage().contains("Invalid format for parameter value
vlan"));
+        } finally {
+            txn.close("runDedicateGuestVlanRangeInvalidFormat");
+        }
+    }
+
+    void runDedicateGuestVlanRangeInvalidRangeValue() throws Exception {
+        Transaction txn = Transaction.open("runDedicateGuestVlanRangeInvalidRangeValue");
+
+        Field dedicateVlanField = _dedicateGuestVlanRangeClass.getDeclaredField("vlan");
+        dedicateVlanField.setAccessible(true);
+        dedicateVlanField.set(dedicateGuestVlanRangesCmd, "2-5");
+        
+        PhysicalNetworkVO physicalNetwork = new PhysicalNetworkVO(1L, 1L, "6-10", "200",
1L, null, "testphysicalnetwork");
+
+        when(networkService._physicalNetworkDao.findById(anyLong())).thenReturn(physicalNetwork);
+
+        try {
+            networkService.dedicateGuestVlanRange(dedicateGuestVlanRangesCmd);
+        } catch (Exception e) {
+            Assert.assertTrue(e.getMessage().contains("Unable to find guest vlan by range"));
+        } finally {
+            txn.close("runDedicateGuestVlanRangeInvalidRangeValue");
+        }
+    }
+
+    void runDedicateGuestVlanRangeAllocatedVlans() throws Exception {
+        Transaction txn = Transaction.open("runDedicateGuestVlanRangeAllocatedVlans");
+        
+        Field dedicateVlanField = _dedicateGuestVlanRangeClass.getDeclaredField("vlan");
+        dedicateVlanField.setAccessible(true);
+        dedicateVlanField.set(dedicateGuestVlanRangesCmd, "2-5");
+
+        PhysicalNetworkVO physicalNetwork = new PhysicalNetworkVO(1L, 1L, "2-5", "200", 1L,
null, "testphysicalnetwork");
+        when(networkService._physicalNetworkDao.findById(anyLong())).thenReturn(physicalNetwork);
+
+        List<DataCenterVnetVO> dataCenterList = new ArrayList<DataCenterVnetVO>();
+        DataCenterVnetVO dataCenter = new DataCenterVnetVO("2-5", 1L, 1L);
+        dataCenter.setAccountId(1L);
+        dataCenterList.add(dataCenter);
+        when(networkService._datacneter_vnet.listAllocatedVnetsInRange(anyLong(), anyLong(),
anyInt(), anyInt())).thenReturn(dataCenterList);
+
+        try {
+            networkService.dedicateGuestVlanRange(dedicateGuestVlanRangesCmd);
+        } catch (Exception e) {
+            Assert.assertTrue(e.getMessage().contains("is allocated to a different account"));
+        } finally {
+            txn.close("runDedicateGuestVlanRangeAllocatedVlans");
+        }
+    }
+
+    void runDedicateGuestVlanRangeDedicatedRange() throws Exception {
+        Transaction txn = Transaction.open("runDedicateGuestVlanRangeDedicatedRange");
+        
+        Field dedicateVlanField = _dedicateGuestVlanRangeClass.getDeclaredField("vlan");
+        dedicateVlanField.setAccessible(true);
+        dedicateVlanField.set(dedicateGuestVlanRangesCmd, "2-5");
+
+        PhysicalNetworkVO physicalNetwork = new PhysicalNetworkVO(1L, 1L, "2-5", "200", 1L,
null, "testphysicalnetwork");;
+
+        when(networkService._physicalNetworkDao.findById(anyLong())).thenReturn(physicalNetwork);
+
+        when(networkService._datacneter_vnet.listAllocatedVnetsInRange(anyLong(), anyLong(),
anyInt(), anyInt())).thenReturn(null);
+
+        List<AccountGuestVlanMapVO> guestVlanMaps = new ArrayList<AccountGuestVlanMapVO>();
+        AccountGuestVlanMapVO accountGuestVlanMap = new AccountGuestVlanMapVO(1L, 1L);
+        accountGuestVlanMap.setGuestVlanRange("2-5");
+        guestVlanMaps.add(accountGuestVlanMap);
+        when(networkService._accountGuestVlanMapDao.listAccountGuestVlanMapsByPhysicalNetwork(anyLong())).thenReturn(guestVlanMaps);
+
+        try {
+            networkService.dedicateGuestVlanRange(dedicateGuestVlanRangesCmd);
+        } catch (Exception e) {
+            Assert.assertTrue(e.getMessage().contains("Vlan range is already dedicated to
another account"));
+        } finally {
+            txn.close("runDedicateGuestVlanRangeDedicatedRange");
+        }
+    }
+
+    void runDedicateGuestVlanRangePartiallyDedicated() throws Exception {
+        Transaction txn = Transaction.open("runDedicateGuestVlanRangePartiallyDedicated");
+        
+        Field dedicateVlanField = _dedicateGuestVlanRangeClass.getDeclaredField("vlan");
+        dedicateVlanField.setAccessible(true);
+        dedicateVlanField.set(dedicateGuestVlanRangesCmd, "2-5");
+
+        PhysicalNetworkVO physicalNetwork = new PhysicalNetworkVO(1L, 1L, "2-5", "200", 1L,
null, "testphysicalnetwork");
+
+        when(networkService._physicalNetworkDao.findById(anyLong())).thenReturn(physicalNetwork);
+
+        when(networkService._datacneter_vnet.listAllocatedVnetsInRange(anyLong(), anyLong(),
anyInt(), anyInt())).thenReturn(null);
+
+        List<AccountGuestVlanMapVO> guestVlanMaps = new ArrayList<AccountGuestVlanMapVO>();
+        AccountGuestVlanMapVO accountGuestVlanMap = new AccountGuestVlanMapVO(2L, 1L);
+        accountGuestVlanMap.setGuestVlanRange("4-8");
+        guestVlanMaps.add(accountGuestVlanMap);
+        when(networkService._accountGuestVlanMapDao.listAccountGuestVlanMapsByPhysicalNetwork(anyLong())).thenReturn(guestVlanMaps);
+
+        try {
+            networkService.dedicateGuestVlanRange(dedicateGuestVlanRangesCmd);
+        } catch (Exception e) {
+            Assert.assertTrue(e.getMessage().contains("Vlan range is partially dedicated
to another account"));
+        } finally {
+            txn.close("runDedicateGuestVlanRangePartiallyDedicated");
+        }
+    }
+    
+    void runReleaseDedicatedGuestVlanRangePostiveTest() throws Exception {
+        Transaction txn = Transaction.open("runReleaseDedicatedGuestVlanRangePostiveTest");
+
+        AccountGuestVlanMapVO accountGuestVlanMap = new AccountGuestVlanMapVO(1L, 1L);
+        when(networkService._accountGuestVlanMapDao.findById(anyLong())).thenReturn(accountGuestVlanMap);
+        doNothing().when(networkService._datacneter_vnet).releaseDedicatedGuestVlans(anyLong());
+        when(networkService._accountGuestVlanMapDao.remove(anyLong())).thenReturn(true);
+
+        try {
+            Boolean result = networkService.releaseDedicatedGuestVlanRange(releaseDedicatedGuestVlanRangesCmd.getId());
+            Assert.assertTrue(result);
+        } catch (Exception e) {
+            s_logger.info("exception in testing runReleaseGuestVlanRangePostiveTest1 message:
" + e.toString());
+        } finally {
+            txn.close("runReleaseDedicatedGuestVlanRangePostiveTest");
+        }
+    }
+
+    void runReleaseDedicatedGuestVlanRangeInvalidRange() throws Exception {
+        Transaction txn = Transaction.open("runReleaseDedicatedGuestVlanRangeInvalidRange");
+
+        when(networkService._accountGuestVlanMapDao.findById(anyLong())).thenReturn(null);
+
+        try {
+        	networkService.releaseDedicatedGuestVlanRange(releaseDedicatedGuestVlanRangesCmd.getId());
+        } catch (Exception e) {
+            Assert.assertTrue(e.getMessage().contains("Dedicated guest vlan with specified
id doesn't exist in the system"));
+        } finally {
+            txn.close("runReleaseDedicatedGuestVlanRangeInvalidRange");
+        }
+    }
+    
+    public class DedicateGuestVlanRangeCmdExtn extends DedicateGuestVlanRangeCmd {
+        public long getEntityOwnerId() {
+            return 1;
+        }
+    }
+
+    public class ReleaseDedicatedGuestVlanRangeCmdExtn extends ReleaseDedicatedGuestVlanRangeCmd
{
+        public long getEntityOwnerId() {
+            return 1;
+        }
+    }
+
+    public class ListDedicatedGuestVlanRangesCmdExtn extends ListDedicatedGuestVlanRangesCmd
{
+        public long getEntityOwnerId() {
+            return 1;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eef8e9c6/server/test/com/cloud/network/MockNetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/network/MockNetworkManagerImpl.java b/server/test/com/cloud/network/MockNetworkManagerImpl.java
index e9987bd..8c14d30 100755
--- a/server/test/com/cloud/network/MockNetworkManagerImpl.java
+++ b/server/test/com/cloud/network/MockNetworkManagerImpl.java
@@ -29,6 +29,7 @@ import com.cloud.network.Networks.TrafficType;
 import com.cloud.network.addr.PublicIp;
 import com.cloud.network.dao.IPAddressVO;
 import com.cloud.network.dao.NetworkVO;
+import com.cloud.network.GuestVlan;
 import com.cloud.network.element.LoadBalancingServiceProvider;
 import com.cloud.network.element.StaticNatServiceProvider;
 import com.cloud.network.element.UserDataServiceProvider;
@@ -54,6 +55,8 @@ import com.cloud.vm.VirtualMachine.Type;
 import com.cloud.vm.VirtualMachineProfile;
 import com.cloud.vm.VirtualMachineProfileImpl;
 import org.apache.cloudstack.acl.ControlledEntity.ACLType;
+import org.apache.cloudstack.api.command.admin.network.DedicateGuestVlanRangeCmd;
+import org.apache.cloudstack.api.command.admin.network.ListDedicatedGuestVlanRangesCmd;
 import org.apache.cloudstack.api.command.admin.usage.ListTrafficTypeImplementorsCmd;
 import org.apache.cloudstack.api.command.user.network.CreateNetworkCmd;
 import org.apache.cloudstack.api.command.user.network.ListNetworksCmd;
@@ -334,6 +337,24 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage
     }
 
     @Override
+    public GuestVlan dedicateGuestVlanRange(DedicateGuestVlanRangeCmd cmd) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Pair<List<? extends GuestVlan>, Integer> listDedicatedGuestVlanRanges(ListDedicatedGuestVlanRangesCmd
cmd) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public boolean releaseDedicatedGuestVlanRange(Long dedicatedGuestVlanRangeId) {
+        // TODO Auto-generated method stub
+        return true;
+    }
+
+        @Override
     public List<? extends Service> listNetworkServices(String providerName) {
         // TODO Auto-generated method stub
         return null;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eef8e9c6/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
old mode 100644
new mode 100755
index 9b18358..969df1b
--- a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
+++ b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
@@ -28,6 +28,7 @@ import com.cloud.network.Network.Provider;
 import com.cloud.network.Network.Service;
 import com.cloud.network.Networks.TrafficType;
 import com.cloud.network.addr.PublicIp;
+import com.cloud.network.dao.AccountGuestVlanMapVO;
 import com.cloud.network.dao.IPAddressVO;
 import com.cloud.network.dao.NetworkServiceMapDao;
 import com.cloud.network.dao.NetworkVO;
@@ -58,6 +59,8 @@ import com.cloud.vm.VirtualMachine.Type;
 import com.cloud.vm.VirtualMachineProfile;
 import com.cloud.vm.VirtualMachineProfileImpl;
 import org.apache.cloudstack.acl.ControlledEntity.ACLType;
+import org.apache.cloudstack.api.command.admin.network.DedicateGuestVlanRangeCmd;
+import org.apache.cloudstack.api.command.admin.network.ListDedicatedGuestVlanRangesCmd;
 import org.apache.cloudstack.api.command.admin.usage.ListTrafficTypeImplementorsCmd;
 import org.apache.cloudstack.api.command.user.network.CreateNetworkCmd;
 import org.apache.cloudstack.api.command.user.network.ListNetworksCmd;
@@ -346,9 +349,24 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage
         return false;
     }
 
+    @Override
+    public GuestVlan dedicateGuestVlanRange(DedicateGuestVlanRangeCmd cmd) {
+        // TODO Auto-generated method stub
+        return null;
+    }
 
+    @Override
+    public Pair<List<? extends GuestVlan>, Integer> listDedicatedGuestVlanRanges(ListDedicatedGuestVlanRangesCmd
cmd) {
+        // TODO Auto-generated method stub
+        return null;
+    }
 
+    @Override
+    public boolean releaseDedicatedGuestVlanRange(Long dedicatedGuestVlanRangeId) {
+        // TODO Auto-generated method stub
+        return true;
 
+    }
 
     /* (non-Javadoc)
      * @see com.cloud.network.NetworkService#listNetworkServices(java.lang.String)

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eef8e9c6/server/test/org/apache/cloudstack/affinity/AffinityApiTestConfiguration.java
----------------------------------------------------------------------
diff --git a/server/test/org/apache/cloudstack/affinity/AffinityApiTestConfiguration.java
b/server/test/org/apache/cloudstack/affinity/AffinityApiTestConfiguration.java
old mode 100644
new mode 100755
index 4dd6ad7..a1224db
--- a/server/test/org/apache/cloudstack/affinity/AffinityApiTestConfiguration.java
+++ b/server/test/org/apache/cloudstack/affinity/AffinityApiTestConfiguration.java
@@ -72,6 +72,7 @@ import com.cloud.network.NetworkManager;
 import com.cloud.network.NetworkModel;
 import com.cloud.network.NetworkService;
 import com.cloud.network.StorageNetworkManager;
+import com.cloud.network.dao.AccountGuestVlanMapDaoImpl;
 import com.cloud.network.dao.FirewallRulesCidrsDaoImpl;
 import com.cloud.network.dao.FirewallRulesDaoImpl;
 import com.cloud.network.dao.IPAddressDaoImpl;
@@ -136,7 +137,7 @@ import com.cloud.vm.dao.VMInstanceDaoImpl;
         FirewallRulesCidrsDaoImpl.class, PhysicalNetworkDaoImpl.class, PhysicalNetworkTrafficTypeDaoImpl.class,
         PhysicalNetworkServiceProviderDaoImpl.class, LoadBalancerDaoImpl.class, NetworkServiceMapDaoImpl.class,
         PrimaryDataStoreDaoImpl.class, StoragePoolDetailsDaoImpl.class, AffinityGroupServiceImpl.class,
-        ComponentContext.class, AffinityGroupProcessor.class, UserVmVO.class, EventUtils.class,
UserVmVO.class
+        ComponentContext.class, AffinityGroupProcessor.class, UserVmVO.class, EventUtils.class,
UserVmVO.class, AccountGuestVlanMapDaoImpl.class
         }, includeFilters = { @Filter(value = AffinityApiTestConfiguration.Library.class,
type = FilterType.CUSTOM) }, useDefaultFilters = false)
 public class AffinityApiTestConfiguration {
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eef8e9c6/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java
----------------------------------------------------------------------
diff --git a/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java
b/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java
old mode 100644
new mode 100755
index 709dfe2..d47deaa
--- a/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java
+++ b/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java
@@ -53,6 +53,7 @@ import com.cloud.network.NetworkManager;
 import com.cloud.network.NetworkModel;
 import com.cloud.network.NetworkService;
 import com.cloud.network.StorageNetworkManager;
+import com.cloud.network.dao.AccountGuestVlanMapDaoImpl;
 import com.cloud.network.dao.FirewallRulesCidrsDaoImpl;
 import com.cloud.network.dao.FirewallRulesDaoImpl;
 import com.cloud.network.dao.IPAddressDaoImpl;
@@ -146,7 +147,8 @@ import com.cloud.vm.dao.VMInstanceDaoImpl;
         LoadBalancerDaoImpl.class,
         NetworkServiceMapDaoImpl.class,
         PrimaryDataStoreDaoImpl.class,
-        StoragePoolDetailsDaoImpl.class
+        StoragePoolDetailsDaoImpl.class,
+        AccountGuestVlanMapDaoImpl.class
     },
 includeFilters={@Filter(value=ChildTestConfiguration.Library.class, type=FilterType.CUSTOM)},
 useDefaultFilters=false

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eef8e9c6/setup/db/db/schema-410to420.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql
index 2de6fe5..6d30760 100644
--- a/setup/db/db/schema-410to420.sql
+++ b/setup/db/db/schema-410to420.sql
@@ -1115,8 +1115,25 @@ CREATE VIEW `cloud`.`account_view` AS
             and async_job.instance_type = 'Account'
             and async_job.job_status = 0;
 
+
 alter table `cloud_usage`.`usage_network_offering` add column nic_id bigint(20) unsigned
NOT NULL;
 ALTER TABLE `cloud`.`data_center_details` MODIFY value varchar(1024);
 ALTER TABLE `cloud`.`cluster_details` MODIFY value varchar(255);
 ALTER TABLE `cloud`.`storage_pool_details` MODIFY value varchar(255);
 ALTER TABLE `cloud`.`account_details` MODIFY value varchar(255);
+
+CREATE TABLE `cloud`.`account_vnet_map` (
+  `id` bigint unsigned NOT NULL UNIQUE AUTO_INCREMENT,
+  `uuid` varchar(255) UNIQUE,
+  `vnet_range` varchar(255) NOT NULL COMMENT 'dedicated guest vlan range',
+  `account_id` bigint unsigned NOT NULL COMMENT 'account id. foreign key to account table',
+  `physical_network_id` bigint unsigned NOT NULL COMMENT 'physical network id. foreign key
to the the physical network table',
+  PRIMARY KEY (`id`),
+  CONSTRAINT `fk_account_vnet_map__physical_network_id` FOREIGN KEY (`physical_network_id`)
REFERENCES `physical_network` (`id`) ON DELETE CASCADE,
+  INDEX `i_account_vnet_map__physical_network_id`(`physical_network_id`),
+  CONSTRAINT `fk_account_vnet_map__account_id` FOREIGN KEY (`account_id`) REFERENCES `account`
(`id`) ON DELETE CASCADE,
+  INDEX `i_account_vnet_map__account_id`(`account_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+ALTER TABLE `cloud`.`op_dc_vnet_alloc` ADD COLUMN account_vnet_map_id bigint unsigned;
+ALTER TABLE `cloud`.`op_dc_vnet_alloc` ADD CONSTRAINT `fk_op_dc_vnet_alloc__account_vnet_map_id`
FOREIGN KEY `fk_op_dc_vnet_alloc__account_vnet_map_id` (`account_vnet_map_id`) REFERENCES
`account_vnet_map` (`id`);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eef8e9c6/test/integration/smoke/test_guest_vlan_range.py
----------------------------------------------------------------------
diff --git a/test/integration/smoke/test_guest_vlan_range.py b/test/integration/smoke/test_guest_vlan_range.py
new file mode 100644
index 0000000..eca0e61
--- /dev/null
+++ b/test/integration/smoke/test_guest_vlan_range.py
@@ -0,0 +1,157 @@
+# 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.
+""" P1 tests for Dedicating Guest Vlan Ranges
+"""
+#Import Local Modules
+import marvin
+from nose.plugins.attrib import attr
+from marvin.cloudstackTestCase import *
+from marvin.cloudstackAPI import *
+from marvin.integration.lib.utils import *
+from marvin.integration.lib.base import *
+from marvin.integration.lib.common import *
+import datetime
+
+
+class Services:
+    """Test Dedicating Guest Vlan Ranges
+    """
+
+    def __init__(self):
+        self.services = {
+                        "domain": {
+                                   "name": "Domain",
+                                   },
+                        "account": {
+                                    "email": "test@test.com",
+                                    "firstname": "Test",
+                                    "lastname": "User",
+                                    "username": "test",
+                                    "password": "password",
+                         },
+                        "name": "testphysicalnetwork"
+                    }
+
+
+class TesDedicateGuestVlanRange(cloudstackTestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        cls.api_client = super(TesDedicateGuestVlanRange, cls).getClsTestClient().getApiClient()
+        cls.services = Services().services
+        # Get Zone, Domain
+        cls.domain = get_domain(cls.api_client, cls.services)
+        cls.zone = get_zone(cls.api_client, cls.services)
+
+        # Create Account
+        cls.account = Account.create(
+                            cls.api_client,
+                            cls.services["account"],
+                            domainid=cls.domain.id
+                            )
+        cls._cleanup = [
+                        #cls.account,
+                        ]
+        return
+
+    @classmethod
+    def tearDownClass(cls):
+        try:
+            # Cleanup resources used
+            cleanup_resources(cls.api_client, cls._cleanup)
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    def setUp(self):
+        self.apiclient = self.testClient.getApiClient()
+        self.dbclient = self.testClient.getDbConnection()
+        self.cleanup = []
+        return
+
+    def tearDown(self):
+        try:
+            # Clean up
+            cleanup_resources(self.apiclient, self.cleanup)
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    @attr(tags=["simulator", "advanced", "guestvlanrange", "dedicate", "release"])
+    def test_dedicateGuestVlanRange(self):
+        """Test guest vlan range dedication
+        """
+
+        """Assume a physical network is available
+        """
+        # Validate the following:
+        # 1. List the available physical network using ListPhysicalNetwork
+        # 2. Add a Guest Vlan range to the available physical network using UpdatePhysicalNetwork
+        # 3. Dedicate the created guest vlan range to user account using DedicateGuestVlanRange
+        # 4. Verify vlan range is dedicated with listDedicatedGuestVlanRanges
+        # 5. Release the dedicated guest vlan range back to the system
+        # 6. Verify guest vlan range has been released, verify with listDedicatedGuestVlanRanges
+        # 7. Remove the added guest vlan range using UpdatePhysicalNetwork
+
+        self.debug("Listing available physical network")
+        list_physical_network_response = PhysicalNetwork.list(
+                             self.apiclient
+                             )
+        self.assertEqual(
+                         isinstance(list_physical_network_response, list),
+                         True,
+                         "Check for list guest vlan range response"
+                         )
+        physical_network_response = list_physical_network_response[0]
+
+        self.debug("Adding guest vlan range")
+        addGuestVlanRangeResponse = physical_network_response.update(self.apiclient, id=physical_network_response.id,
vlan="387-390")
+
+        self.debug("Dedicating guest vlan range");
+        dedicate_guest_vlan_range_response = PhysicalNetwork.dedicate(
+                                                self.apiclient,
+                                                "387-390",
+                                                physicalnetworkid=physical_network_response.id,
+                                                account=self.account.name,
+                                                domainid=self.account.domainid
+                                            )
+        list_dedicated_guest_vlan_range_response = PhysicalNetwork.listDedicated(
+                                                self.apiclient,
+                                                id=dedicate_guest_vlan_range_response.id
+                                        )
+        dedicated_guest_vlan_response = list_dedicated_guest_vlan_range_response[0]
+        self.assertEqual(
+                            dedicated_guest_vlan_response.account,
+                            self.account.name,
+                            "Check account name is in listDedicatedGuestVlanRanges as the
account the range is dedicated to"
+                        )
+
+        self.debug("Releasing guest vlan range");
+        dedicated_guest_vlan_response.release(self.apiclient)
+        list_dedicated_guest_vlan_range_response = PhysicalNetwork.listDedicated(
+                                                self.apiclient,
+                                                id=dedicate_guest_vlan_range_response.id
+                                        )
+        dedicated_guest_vlan_response = list_dedicated_guest_vlan_range_response[0]
+        self.assertEqual(
+                            dedicated_guest_vlan_response.account,
+                            "system",
+                            "Check account name is system account in listDedicatedGuestVlanRanges"
+                        )
+        
+        self.debug("Removing guest vlan range")
+        removeGuestVlanRangeResponse = physical_network_response.update(self.apiclient, id=physical_network_response.id,
removevlan="387-390")

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eef8e9c6/tools/marvin/marvin/integration/lib/base.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/integration/lib/base.py b/tools/marvin/marvin/integration/lib/base.py
index 1d86c6c..e2df74c 100755
--- a/tools/marvin/marvin/integration/lib/base.py
+++ b/tools/marvin/marvin/integration/lib/base.py
@@ -2179,6 +2179,33 @@ class PhysicalNetwork:
         return apiclient.addTrafficType(cmd)
 
     @classmethod
+    def dedicate(cls, apiclient, vlanrange, physicalnetworkid, account=None, domainid=None,
projectid=None):
+        """Dedicate guest vlan range"""
+
+        cmd = dedicateGuestVlanRange.dedicateGuestVlanRangeCmd()
+        cmd.vlanrange = vlanrange
+        cmd.physicalnetworkid = physicalnetworkid
+        cmd.account = account
+        cmd.domainid = domainid
+        cmd.projectid = projectid
+        return PhysicalNetwork(apiclient.dedicateGuestVlanRange(cmd).__dict__)
+
+    def release(self, apiclient):
+        """Release guest vlan range"""
+
+        cmd = releaseDedicatedGuestVlanRange.releaseDedicatedGuestVlanRangeCmd()
+        cmd.id = self.id
+        return apiclient.releaseDedicatedGuestVlanRange(cmd)
+
+    @classmethod
+    def listDedicated(cls, apiclient, **kwargs):
+        """Lists all dedicated guest vlan ranges"""
+
+        cmd = listDedicatedGuestVlanRanges.listDedicatedGuestVlanRangesCmd()
+        [setattr(cmd, k, v) for k, v in kwargs.items()]
+        return map(lambda pn : PhysicalNetwork(pn.__dict__), apiclient.listDedicatedGuestVlanRanges(cmd))
+
+    @classmethod
     def list(cls, apiclient, **kwargs):
         """Lists all physical networks"""
 


Mime
View raw message