cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alena1...@apache.org
Subject git commit: refs/heads/master - CLOUDSTACK-766 - allow Vlan assignment to Isolated network. The network with Vlan assigned, gets created with Setup state, and will never get picked up by the GC thread meaning its vlan will never get released
Date Thu, 21 Mar 2013 23:05:57 GMT
Updated Branches:
  refs/heads/master c9f4e5130 -> 37cdb5d74


CLOUDSTACK-766 - allow Vlan assignment to Isolated network. The network with Vlan assigned,
gets created with Setup state, and will never get picked up by the GC thread meaning its vlan
will never get released


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

Branch: refs/heads/master
Commit: 37cdb5d74b6b63f3a78dbc2c3b258b429b8f55a6
Parents: c9f4e51
Author: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Authored: Thu Mar 21 15:17:34 2013 -0700
Committer: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Committed: Thu Mar 21 16:05:48 2013 -0700

----------------------------------------------------------------------
 .../configuration/ConfigurationManagerImpl.java    |   23 +-
 .../src/com/cloud/network/NetworkManagerImpl.java  |   24 +-
 .../networkoffering/ChildTestConfiguration.java    |  333 +++++++++++++++
 .../networkoffering/CreateNetworkOfferingTest.java |  179 ++++++++
 server/test/resources/createNetworkOffering.xml    |   44 ++
 5 files changed, 577 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/37cdb5d7/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
index b1ad6b7..8dbf081 100755
--- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
+++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
@@ -87,7 +87,6 @@ import com.cloud.dc.dao.ClusterDao;
 import com.cloud.dc.dao.DataCenterDao;
 import com.cloud.dc.dao.DataCenterIpAddressDao;
 import com.cloud.dc.dao.DataCenterLinkLocalIpAddressDao;
-import com.cloud.dc.dao.DataCenterLinkLocalIpAddressDaoImpl;
 import com.cloud.dc.dao.HostPodDao;
 import com.cloud.dc.dao.PodVlanMapDao;
 import com.cloud.dc.dao.VlanDao;
@@ -3337,20 +3336,24 @@ public class ConfigurationManagerImpl extends ManagerBase implements
Configurati
         String multicastRateStr = _configDao.getValue("multicast.throttling.rate");
         int multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr));
         tags = cleanupTags(tags);
-        
-        if (specifyVlan != specifyIpRanges) {
-            throw new InvalidParameterValueException("SpecifyVlan should be equal to specifyIpRanges
which is " + specifyIpRanges);
-        }
 
         // specifyVlan should always be true for Shared network offerings
         if (!specifyVlan && type == GuestType.Shared) {
             throw new InvalidParameterValueException("SpecifyVlan should be true if network
offering's type is " + type);
         }
         
-        //specifyIpRanges should always be false for Isolated offering with Source nat service
enabled
-        if (specifyVlan && type == GuestType.Isolated && serviceProviderMap.containsKey(Service.SourceNat))
{
-            throw new InvalidParameterValueException("SpecifyVlan should be false if the
network offering type is " 
-                                                        + type + " and service " + Service.SourceNat.getName()
+ " is supported");
+        //specifyIpRanges should always be true for Shared networks
+        //specifyIpRanges can only be true for Isolated networks with no Source Nat service
+        if (specifyIpRanges) {
+            if (type == GuestType.Isolated) {
+                if (serviceProviderMap.containsKey(Service.SourceNat)) {
+                    throw new InvalidParameterValueException("SpecifyIpRanges can only be
true for Shared network offerings and Isolated with no SourceNat service");
+                }
+            }
+        } else {
+            if (type == GuestType.Shared) {
+                throw new InvalidParameterValueException("SpecifyIpRanges should always be
true for Shared network offerings");
+            }
         }
 
         // isPersistent should always be false for Shared network Offerings
@@ -3374,7 +3377,6 @@ public class ConfigurationManagerImpl extends ManagerBase implements
Configurati
                         + " with availability " + Availability.Required);
             }
         }
-
         
         boolean dedicatedLb = false;
         boolean elasticLb = false;
@@ -3481,6 +3483,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements
Configurati
         return offering;
     }
 
+
     @Override
     public List<? extends NetworkOffering> searchForNetworkOfferings(ListNetworkOfferingsCmd
cmd) {
         Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm"));

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/37cdb5d7/server/src/com/cloud/network/NetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java
index 5136572..b1236cc 100755
--- a/server/src/com/cloud/network/NetworkManagerImpl.java
+++ b/server/src/com/cloud/network/NetworkManagerImpl.java
@@ -1995,28 +1995,20 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager,
L
         if (cidr != null && gateway != null) {
             userNetwork.setCidr(cidr);
             userNetwork.setGateway(gateway);
-            if (vlanId != null) {
-                userNetwork.setBroadcastUri(URI.create("vlan://" + vlanId));
-                userNetwork.setBroadcastDomainType(BroadcastDomainType.Vlan);
-                if (!vlanId.equalsIgnoreCase(Vlan.UNTAGGED)) {
-                    userNetwork.setBroadcastDomainType(BroadcastDomainType.Vlan);
-                } else {
-                    userNetwork.setBroadcastDomainType(BroadcastDomainType.Native);
-                }
-            }
         }
         
         if (ip6Cidr != null && ip6Gateway != null) {
             userNetwork.setIp6Cidr(ip6Cidr);
             userNetwork.setIp6Gateway(ip6Gateway);
-            if (vlanId != null) {
-                userNetwork.setBroadcastUri(URI.create("vlan://" + vlanId));
+        }
+        
+        if (vlanId != null) {
+            userNetwork.setBroadcastUri(URI.create("vlan://" + vlanId));
+            userNetwork.setBroadcastDomainType(BroadcastDomainType.Vlan);
+            if (!vlanId.equalsIgnoreCase(Vlan.UNTAGGED)) {
                 userNetwork.setBroadcastDomainType(BroadcastDomainType.Vlan);
-                if (!vlanId.equalsIgnoreCase(Vlan.UNTAGGED)) {
-                    userNetwork.setBroadcastDomainType(BroadcastDomainType.Vlan);
-                } else {
-                    userNetwork.setBroadcastDomainType(BroadcastDomainType.Native);
-                }
+            } else {
+                userNetwork.setBroadcastDomainType(BroadcastDomainType.Native);
             }
         }
         

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/37cdb5d7/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
new file mode 100644
index 0000000..895a5d4
--- /dev/null
+++ b/server/test/org/apache/cloudstack/networkoffering/ChildTestConfiguration.java
@@ -0,0 +1,333 @@
+// 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 org.apache.cloudstack.networkoffering;
+
+import java.io.IOException;
+
+import org.apache.cloudstack.acl.SecurityChecker;
+import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDaoImpl;
+import org.mockito.Mockito;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.ComponentScan.Filter;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.FilterType;
+import org.springframework.core.type.classreading.MetadataReader;
+import org.springframework.core.type.classreading.MetadataReaderFactory;
+import org.springframework.core.type.filter.TypeFilter;
+
+import com.cloud.agent.AgentManager;
+import com.cloud.alert.AlertManager;
+import com.cloud.api.query.dao.UserAccountJoinDaoImpl;
+import com.cloud.capacity.dao.CapacityDaoImpl;
+import com.cloud.cluster.agentlb.dao.HostTransferMapDaoImpl;
+import com.cloud.configuration.dao.ConfigurationDao;
+import com.cloud.dc.dao.AccountVlanMapDaoImpl;
+import com.cloud.dc.dao.ClusterDaoImpl;
+import com.cloud.dc.dao.DataCenterDaoImpl;
+import com.cloud.dc.dao.DataCenterIpAddressDaoImpl;
+import com.cloud.dc.dao.DataCenterLinkLocalIpAddressDaoImpl;
+import com.cloud.dc.dao.DataCenterVnetDaoImpl;
+import com.cloud.dc.dao.DcDetailsDaoImpl;
+import com.cloud.dc.dao.HostPodDaoImpl;
+import com.cloud.dc.dao.PodVlanDaoImpl;
+import com.cloud.dc.dao.PodVlanMapDaoImpl;
+import com.cloud.dc.dao.VlanDaoImpl;
+import com.cloud.domain.dao.DomainDaoImpl;
+import com.cloud.event.dao.UsageEventDaoImpl;
+import com.cloud.host.dao.HostDaoImpl;
+import com.cloud.host.dao.HostDetailsDaoImpl;
+import com.cloud.host.dao.HostTagsDaoImpl;
+import com.cloud.network.Ipv6AddressManager;
+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.FirewallRulesCidrsDaoImpl;
+import com.cloud.network.dao.FirewallRulesDaoImpl;
+import com.cloud.network.dao.IPAddressDaoImpl;
+import com.cloud.network.dao.LoadBalancerDaoImpl;
+import com.cloud.network.dao.NetworkDao;
+import com.cloud.network.dao.NetworkDomainDaoImpl;
+import com.cloud.network.dao.NetworkServiceMapDaoImpl;
+import com.cloud.network.dao.PhysicalNetworkDaoImpl;
+import com.cloud.network.dao.PhysicalNetworkServiceProviderDaoImpl;
+import com.cloud.network.dao.PhysicalNetworkTrafficTypeDaoImpl;
+import com.cloud.network.dao.UserIpv6AddressDaoImpl;
+import com.cloud.network.element.DhcpServiceProvider;
+import com.cloud.network.element.IpDeployer;
+import com.cloud.network.element.NetworkElement;
+import com.cloud.network.guru.NetworkGuru;
+import com.cloud.network.lb.LoadBalancingRulesManager;
+import com.cloud.network.rules.FirewallManager;
+import com.cloud.network.rules.RulesManager;
+import com.cloud.network.rules.dao.PortForwardingRulesDaoImpl;
+import com.cloud.network.vpc.NetworkACLManager;
+import com.cloud.network.vpc.VpcManager;
+import com.cloud.network.vpc.dao.PrivateIpDaoImpl;
+import com.cloud.network.vpn.RemoteAccessVpnService;
+import com.cloud.offerings.dao.NetworkOfferingDao;
+import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
+import com.cloud.offerings.dao.NetworkOfferingServiceMapDaoImpl;
+import com.cloud.projects.ProjectManager;
+import com.cloud.service.dao.ServiceOfferingDaoImpl;
+import com.cloud.storage.dao.DiskOfferingDaoImpl;
+import com.cloud.storage.dao.S3DaoImpl;
+import com.cloud.storage.dao.SnapshotDaoImpl;
+import com.cloud.storage.dao.StoragePoolDetailsDaoImpl;
+import com.cloud.storage.dao.SwiftDaoImpl;
+import com.cloud.storage.dao.VolumeDaoImpl;
+import com.cloud.storage.s3.S3Manager;
+import com.cloud.storage.secondary.SecondaryStorageVmManager;
+import com.cloud.storage.swift.SwiftManager;
+import com.cloud.tags.dao.ResourceTagsDaoImpl;
+import com.cloud.user.AccountManager;
+import com.cloud.user.ResourceLimitService;
+import com.cloud.user.UserContext;
+import com.cloud.user.UserContextInitializer;
+import com.cloud.user.dao.AccountDaoImpl;
+import com.cloud.user.dao.UserDaoImpl;
+import com.cloud.utils.component.SpringComponentScanUtils;
+import com.cloud.vm.dao.InstanceGroupDaoImpl;
+import com.cloud.vm.dao.NicDaoImpl;
+import com.cloud.vm.dao.NicSecondaryIpDaoImpl;
+import com.cloud.vm.dao.UserVmDao;
+import com.cloud.vm.dao.VMInstanceDaoImpl;
+
+@Configuration
+@ComponentScan(basePackageClasses={
+        AccountVlanMapDaoImpl.class,
+        VolumeDaoImpl.class,
+        HostPodDaoImpl.class,
+        DomainDaoImpl.class,
+        SwiftDaoImpl.class,
+        ServiceOfferingDaoImpl.class,
+        VlanDaoImpl.class,
+        IPAddressDaoImpl.class,
+        ResourceTagsDaoImpl.class,
+        AccountDaoImpl.class,
+        InstanceGroupDaoImpl.class,
+        UserAccountJoinDaoImpl.class,
+        CapacityDaoImpl.class,
+        SnapshotDaoImpl.class,
+        HostDaoImpl.class,
+        VMInstanceDaoImpl.class,
+        HostTransferMapDaoImpl.class,
+        PortForwardingRulesDaoImpl.class,
+        PrivateIpDaoImpl.class,
+        UsageEventDaoImpl.class,
+        PodVlanMapDaoImpl.class,
+        DiskOfferingDaoImpl.class,
+        DataCenterDaoImpl.class,
+        DataCenterIpAddressDaoImpl.class,
+        DataCenterLinkLocalIpAddressDaoImpl.class,
+        DataCenterVnetDaoImpl.class,
+        PodVlanDaoImpl.class,
+        DcDetailsDaoImpl.class,
+        NicSecondaryIpDaoImpl.class,
+        UserIpv6AddressDaoImpl.class,
+        S3DaoImpl.class,
+        UserDaoImpl.class,
+        NicDaoImpl.class,
+        NetworkDomainDaoImpl.class,
+        HostDetailsDaoImpl.class,
+        HostTagsDaoImpl.class,
+        ClusterDaoImpl.class,
+        FirewallRulesDaoImpl.class,
+        FirewallRulesCidrsDaoImpl.class,
+        PhysicalNetworkDaoImpl.class,
+        PhysicalNetworkTrafficTypeDaoImpl.class,
+        PhysicalNetworkServiceProviderDaoImpl.class,
+        LoadBalancerDaoImpl.class,
+        NetworkServiceMapDaoImpl.class,
+        PrimaryDataStoreDaoImpl.class,
+        StoragePoolDetailsDaoImpl.class
+    },
+includeFilters={@Filter(value=ChildTestConfiguration.Library.class, type=FilterType.CUSTOM)},
+useDefaultFilters=false
+)
+
+public class ChildTestConfiguration {
+    
+    @Bean
+    public AccountManager acctMgr() {
+        return Mockito.mock(AccountManager.class);
+    }
+    
+    @Bean
+    public NetworkService ntwkSvc() {
+        return Mockito.mock(NetworkService.class);
+    }
+    
+    @Bean
+    public NetworkModel ntwkMdl() {
+        return Mockito.mock(NetworkModel.class);
+    }
+    
+    @Bean
+    public AlertManager alertMgr() {
+        return Mockito.mock(AlertManager.class);
+    }
+    
+    @Bean
+    public SecurityChecker securityChkr() {
+        return Mockito.mock(SecurityChecker.class);
+    }
+    
+    @Bean
+    public ResourceLimitService resourceSvc() {
+        return Mockito.mock(ResourceLimitService.class);
+    }
+    
+    @Bean
+    public ProjectManager projectMgr() {
+        return Mockito.mock(ProjectManager.class);
+    }
+    
+    @Bean
+    public SecondaryStorageVmManager ssvmMgr() {
+        return Mockito.mock(SecondaryStorageVmManager.class);
+    }
+    
+    @Bean
+    public SwiftManager swiftMgr() {
+        return Mockito.mock(SwiftManager.class);
+    }
+    
+    @Bean
+    public S3Manager s3Mgr() {
+        return Mockito.mock(S3Manager.class);
+    }
+    
+    @Bean
+    public VpcManager vpcMgr() {
+        return Mockito.mock(VpcManager.class);
+    }
+    
+    @Bean
+    public UserVmDao userVMDao() {
+        return Mockito.mock(UserVmDao.class);
+    }
+    
+    @Bean
+    public RulesManager rulesMgr() {
+        return Mockito.mock(RulesManager.class);
+    }
+    
+    @Bean
+    public LoadBalancingRulesManager lbRulesMgr() {
+        return Mockito.mock(LoadBalancingRulesManager.class);
+    }
+    
+    @Bean
+    public RemoteAccessVpnService vpnMgr() {
+        return Mockito.mock(RemoteAccessVpnService.class);
+    }
+    
+    @Bean
+    public NetworkGuru ntwkGuru() {
+        return Mockito.mock(NetworkGuru.class);
+    }
+    
+    @Bean
+    public NetworkElement ntwkElement() {
+        return Mockito.mock(NetworkElement.class);
+    }
+    
+    @Bean
+    public IpDeployer ipDeployer() {
+        return Mockito.mock(IpDeployer.class);
+    }
+    
+    @Bean
+    public DhcpServiceProvider dhcpProvider() {
+        return Mockito.mock(DhcpServiceProvider.class);
+    }
+    
+    @Bean
+    public FirewallManager firewallMgr() {
+        return Mockito.mock(FirewallManager.class);
+    }
+    
+    @Bean
+    public AgentManager agentMgr() {
+        return Mockito.mock(AgentManager.class);
+    }
+    
+    @Bean
+    public StorageNetworkManager storageNtwkMgr() {
+        return Mockito.mock(StorageNetworkManager.class);
+    }
+    
+    @Bean
+    public NetworkACLManager ntwkAclMgr() {
+        return Mockito.mock(NetworkACLManager.class);
+    }
+    
+    @Bean
+    public Ipv6AddressManager ipv6Mgr() {
+        return Mockito.mock(Ipv6AddressManager.class);
+    }
+    
+    @Bean
+    public ConfigurationDao configDao() {
+        return Mockito.mock(ConfigurationDao.class);
+    }
+    
+    @Bean
+    public UserContext userContext() {
+        return Mockito.mock(UserContext.class);
+    }
+    
+    @Bean
+    public UserContextInitializer userContextInitializer() {
+        return Mockito.mock(UserContextInitializer.class);
+    }
+    
+    @Bean
+    public NetworkManager networkManager() {
+        return Mockito.mock(NetworkManager.class);
+    }
+    
+    @Bean
+    public NetworkOfferingDao networkOfferingDao() {
+        return Mockito.mock(NetworkOfferingDao.class);
+    }
+    
+    @Bean
+    public NetworkDao networkDao() {
+        return Mockito.mock(NetworkDao.class);
+    }
+    
+    @Bean
+    public NetworkOfferingServiceMapDao networkOfferingServiceMapDao() {
+        return Mockito.mock(NetworkOfferingServiceMapDao.class);
+    }
+    
+    public static class Library implements TypeFilter {
+
+        @Override
+        public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException
{
+            mdr.getClassMetadata().getClassName();
+            ComponentScan cs = ChildTestConfiguration.class.getAnnotation(ComponentScan.class);
+            return SpringComponentScanUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(),
cs);
+        }
+
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/37cdb5d7/server/test/org/apache/cloudstack/networkoffering/CreateNetworkOfferingTest.java
----------------------------------------------------------------------
diff --git a/server/test/org/apache/cloudstack/networkoffering/CreateNetworkOfferingTest.java
b/server/test/org/apache/cloudstack/networkoffering/CreateNetworkOfferingTest.java
new file mode 100644
index 0000000..bb82991
--- /dev/null
+++ b/server/test/org/apache/cloudstack/networkoffering/CreateNetworkOfferingTest.java
@@ -0,0 +1,179 @@
+// 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 org.apache.cloudstack.networkoffering;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.inject.Inject;
+
+import junit.framework.TestCase;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import com.cloud.configuration.ConfigurationManager;
+import com.cloud.configuration.ConfigurationVO;
+import com.cloud.configuration.dao.ConfigurationDao;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.network.Network;
+import com.cloud.network.Network.Provider;
+import com.cloud.network.Network.Service;
+import com.cloud.network.Networks.TrafficType;
+import com.cloud.offering.NetworkOffering.Availability;
+import com.cloud.offerings.NetworkOfferingServiceMapVO;
+import com.cloud.offerings.NetworkOfferingVO;
+import com.cloud.offerings.dao.NetworkOfferingDao;
+import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
+import com.cloud.user.UserContext;
+import com.cloud.user.UserContextInitializer;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations="classpath:/createNetworkOffering.xml")
+
+public class CreateNetworkOfferingTest extends TestCase{
+    
+    @Inject
+    ConfigurationManager configMgr;
+    
+    @Inject
+    ConfigurationDao configDao;
+    
+    @Inject
+    NetworkOfferingDao offDao;
+    
+    @Inject
+    UserContext usrCtx;
+    
+    @Inject
+    UserContextInitializer usrCtxInit;
+    
+    @Inject
+    NetworkOfferingServiceMapDao mapDao;
+    
+    @Before
+    public void setUp() {
+        ConfigurationVO configVO = new ConfigurationVO("200", "200","200","200","200","200");
+        Mockito.when(configDao.findByName(Mockito.anyString())).thenReturn(configVO);
+        
+        Mockito.when(offDao.persist(Mockito.any(NetworkOfferingVO.class))).thenReturn(new
NetworkOfferingVO());
+        Mockito.when(mapDao.persist(Mockito.any(NetworkOfferingServiceMapVO.class))).thenReturn(new
NetworkOfferingServiceMapVO());
+        Mockito.when(usrCtx.current()).thenReturn(new UserContext());
+    }
+
+    //Test Shared network offerings
+    @Test
+    public void createSharedNtwkOffWithVlan() {
+        NetworkOfferingVO off = configMgr.createNetworkOffering("shared", "shared", TrafficType.Guest,
null, true,
+                Availability.Optional, 200, null, false, Network.GuestType.Shared, false,
+                null, false, null, true, false);
+        
+        assertNotNull("Shared network offering with specifyVlan=true failed to create ",
off);
+    }
+    
+    @Test
+    public void createSharedNtwkOffWithNoVlan() {
+        try {
+            NetworkOfferingVO off = configMgr.createNetworkOffering("shared", "shared", TrafficType.Guest,
null, false,
+                    Availability.Optional, 200, null, false, Network.GuestType.Shared, false,
+                    null, false, null, true, false);
+            assertNull("Shared network offering with specifyVlan=false was created", off);
+        } catch (InvalidParameterValueException ex) {
+        }
+    }
+    
+    @Test
+    public void createSharedNtwkOffWithSpecifyIpRanges() {
+        NetworkOfferingVO off = configMgr.createNetworkOffering("shared", "shared", TrafficType.Guest,
null, true,
+                Availability.Optional, 200, null, false, Network.GuestType.Shared, false,
+                null, false, null, true, false);
+        
+        assertNotNull("Shared network offering with specifyIpRanges=true failed to create
", off);
+    }
+    
+    @Test
+    public void createSharedNtwkOffWithoutSpecifyIpRanges() {
+        try {
+            NetworkOfferingVO off = configMgr.createNetworkOffering("shared", "shared", TrafficType.Guest,
null, true,
+                    Availability.Optional, 200, null, false, Network.GuestType.Shared, false,
+                    null, false, null, false, false);
+            assertNull("Shared network offering with specifyIpRanges=false was created",
off);
+        } catch (InvalidParameterValueException ex) {
+        }
+    }
+
+    //Test Isolated network offerings
+    @Test
+    public void createIsolatedNtwkOffWithNoVlan() {
+        Map<Service, Set<Provider>> serviceProviderMap = new HashMap<Network.Service,
Set<Network.Provider>>();
+        Set<Network.Provider> vrProvider = new HashSet<Network.Provider>();
+        vrProvider.add(Provider.VirtualRouter);
+        serviceProviderMap.put(Network.Service.SourceNat, vrProvider);
+        NetworkOfferingVO off = configMgr.createNetworkOffering("isolated", "isolated", TrafficType.Guest,
null, false,
+                Availability.Optional, 200, serviceProviderMap, false, Network.GuestType.Isolated,
false,
+                null, false, null, false, false);
+        
+        assertNotNull("Isolated network offering with specifyIpRanges=false failed to create
", off);
+    }
+    
+    @Test
+    public void createIsolatedNtwkOffWithVlan() {
+        Map<Service, Set<Provider>> serviceProviderMap = new HashMap<Network.Service,
Set<Network.Provider>>();
+        Set<Network.Provider> vrProvider = new HashSet<Network.Provider>();
+        vrProvider.add(Provider.VirtualRouter);
+        serviceProviderMap.put(Network.Service.SourceNat, vrProvider);
+        NetworkOfferingVO off = configMgr.createNetworkOffering("isolated", "isolated", TrafficType.Guest,
null, true,
+                Availability.Optional, 200, serviceProviderMap, false, Network.GuestType.Isolated,
false,
+                null, false, null, false, false);
+        assertNotNull("Isolated network offering with specifyVlan=true wasn't created", off);
+       
+    }
+    
+    @Test
+    public void createIsolatedNtwkOffWithSpecifyIpRangesAndSourceNat() {
+        try {
+            Map<Service, Set<Provider>> serviceProviderMap = new HashMap<Network.Service,
Set<Network.Provider>>();
+            Set<Network.Provider> vrProvider = new HashSet<Network.Provider>();
+            vrProvider.add(Provider.VirtualRouter);
+            serviceProviderMap.put(Network.Service.SourceNat, vrProvider);
+            NetworkOfferingVO off = configMgr.createNetworkOffering("isolated", "isolated",
TrafficType.Guest, null, false,
+                    Availability.Optional, 200, serviceProviderMap, false, Network.GuestType.Isolated,
false,
+                    null, false, null, true, false);
+            assertNull("Isolated network offering with specifyIpRanges=true and source nat
service enabled, was created", off);
+        } catch (InvalidParameterValueException ex) {
+        }
+    }
+    
+    @Test
+    public void createIsolatedNtwkOffWithSpecifyIpRangesAndNoSourceNat() {
+        
+        Map<Service, Set<Provider>> serviceProviderMap = new HashMap<Network.Service,
Set<Network.Provider>>();
+        Set<Network.Provider> vrProvider = new HashSet<Network.Provider>();
+        NetworkOfferingVO off = configMgr.createNetworkOffering("isolated", "isolated", TrafficType.Guest,
null, false,
+                Availability.Optional, 200, serviceProviderMap, false, Network.GuestType.Isolated,
false,
+                null, false, null, true, false);
+        assertNotNull("Isolated network offering with specifyIpRanges=true and with no sourceNatService,
failed to create", off);
+        
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/37cdb5d7/server/test/resources/createNetworkOffering.xml
----------------------------------------------------------------------
diff --git a/server/test/resources/createNetworkOffering.xml b/server/test/resources/createNetworkOffering.xml
new file mode 100644
index 0000000..f3faaa8
--- /dev/null
+++ b/server/test/resources/createNetworkOffering.xml
@@ -0,0 +1,44 @@
+<!-- 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. -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
+  xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
+  xsi:schemaLocation="http://www.springframework.org/schema/beans
+                      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+                      http://www.springframework.org/schema/tx 
+                      http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
+                      http://www.springframework.org/schema/aop
+                      http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
+                      http://www.springframework.org/schema/context
+                      http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+
+     <context:annotation-config />
+
+    <!-- @DB support -->
+    <aop:config proxy-target-class="true">
+    <aop:aspect id="dbContextBuilder" ref="transactionContextBuilder">
+    <aop:pointcut id="captureAnyMethod" expression="execution(* *(..))" />
+
+    <aop:around pointcut-ref="captureAnyMethod" method="AroundAnyMethod" />
+    </aop:aspect>
+    </aop:config>
+    
+
+    <bean id="ConfigurationManager" class="com.cloud.configuration.ConfigurationManagerImpl">
+        <property name="name" value="ConfigurationManager"/>
+    </bean>
+  
+    <bean class="org.apache.cloudstack.networkoffering.ChildTestConfiguration" />
+    
+    <bean id="transactionContextBuilder" class="com.cloud.utils.db.TransactionContextBuilder"
/>
+    
+
+</beans>


Mime
View raw message