cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h...@apache.org
Subject [2/6] OpenContrail network plugin
Date Fri, 01 Nov 2013 16:55:57 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6b5fab2f/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/IntegrationTestConfiguration.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/IntegrationTestConfiguration.java b/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/IntegrationTestConfiguration.java
new file mode 100644
index 0000000..7c8d516
--- /dev/null
+++ b/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/IntegrationTestConfiguration.java
@@ -0,0 +1,835 @@
+// 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.network.contrail.management;
+
+import java.io.IOException;
+
+import javax.inject.Inject;
+
+import com.cloud.network.dao.IPAddressDao;
+import com.cloud.network.IpAddress;
+
+import org.apache.cloudstack.acl.APIChecker;
+import org.apache.cloudstack.acl.ControlledEntity;
+import org.apache.cloudstack.affinity.AffinityGroupService;
+import org.apache.cloudstack.affinity.AffinityGroupVO;
+import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
+import org.apache.cloudstack.affinity.dao.AffinityGroupDaoImpl;
+import org.apache.cloudstack.affinity.dao.AffinityGroupDomainMapDaoImpl;
+import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDaoImpl;
+import org.apache.cloudstack.api.IdentityService;
+import org.apache.cloudstack.engine.service.api.OrchestrationService;
+import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
+import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
+import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
+import org.apache.cloudstack.engine.subsystem.api.storage.TemplateDataFactory;
+import org.apache.cloudstack.engine.subsystem.api.storage.TemplateService;
+import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
+import org.apache.cloudstack.lb.dao.ApplicationLoadBalancerRuleDaoImpl;
+import org.apache.cloudstack.query.QueryService;
+import org.apache.cloudstack.region.PortableIpDaoImpl;
+import org.apache.cloudstack.region.PortableIpRangeDaoImpl;
+import org.apache.cloudstack.region.RegionManager;
+import org.apache.cloudstack.region.dao.RegionDaoImpl;
+import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDaoImpl;
+import org.apache.cloudstack.storage.image.db.ImageStoreDaoImpl;
+import org.apache.cloudstack.storage.image.db.TemplateDataStoreDaoImpl;
+import org.apache.cloudstack.usage.UsageService;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+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.acl.DomainChecker;
+import com.cloud.agent.AgentManager;
+import com.cloud.agent.manager.allocator.HostAllocator;
+import com.cloud.agent.manager.allocator.PodAllocator;
+import com.cloud.alert.AlertManager;
+import com.cloud.api.ApiDBUtils;
+import com.cloud.api.query.dao.AccountJoinDaoImpl;
+import com.cloud.api.query.dao.AffinityGroupJoinDaoImpl;
+import com.cloud.api.query.dao.AsyncJobJoinDaoImpl;
+import com.cloud.api.query.dao.DataCenterJoinDaoImpl;
+import com.cloud.api.query.dao.DiskOfferingJoinDaoImpl;
+import com.cloud.api.query.dao.DomainRouterJoinDaoImpl;
+import com.cloud.api.query.dao.HostJoinDaoImpl;
+import com.cloud.api.query.dao.ImageStoreJoinDaoImpl;
+import com.cloud.api.query.dao.InstanceGroupJoinDaoImpl;
+import com.cloud.api.query.dao.ProjectAccountJoinDaoImpl;
+import com.cloud.api.query.dao.ProjectInvitationJoinDaoImpl;
+import com.cloud.api.query.dao.ProjectJoinDaoImpl;
+import com.cloud.api.query.dao.ResourceTagJoinDaoImpl;
+import com.cloud.api.query.dao.SecurityGroupJoinDaoImpl;
+import com.cloud.api.query.dao.ServiceOfferingJoinDaoImpl;
+import com.cloud.api.query.dao.StoragePoolJoinDaoImpl;
+import com.cloud.api.query.dao.TemplateJoinDaoImpl;
+import com.cloud.api.query.dao.UserAccountJoinDaoImpl;
+import com.cloud.api.query.dao.UserVmJoinDaoImpl;
+import com.cloud.api.query.dao.VolumeJoinDaoImpl;
+import com.cloud.capacity.CapacityManager;
+import com.cloud.capacity.dao.CapacityDaoImpl;
+import com.cloud.cluster.ClusterManager;
+import com.cloud.cluster.agentlb.dao.HostTransferMapDaoImpl;
+import com.cloud.cluster.dao.ManagementServerHostDaoImpl;
+import com.cloud.configuration.ConfigurationManagerImpl;
+
+import org.apache.cloudstack.framework.config.dao.ConfigurationDaoImpl;
+
+import com.cloud.configuration.dao.ResourceCountDaoImpl;
+import com.cloud.configuration.dao.ResourceLimitDaoImpl;
+import com.cloud.consoleproxy.ConsoleProxyManager;
+import com.cloud.consoleproxy.ConsoleProxyService;
+import com.cloud.dc.ClusterDetailsDaoImpl;
+import com.cloud.dc.DataCenter;
+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 org.apache.cloudstack.engine.datacenter.entity.api.db.dao.DcDetailsDaoImpl;
+import com.cloud.dc.dao.DedicatedResourceDaoImpl;
+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.deploy.DeploymentPlanner;
+import com.cloud.deploy.DeploymentPlanningManager;
+import com.cloud.deploy.dao.PlannerHostReservationDaoImpl;
+import com.cloud.domain.dao.DomainDaoImpl;
+import com.cloud.event.dao.EventDaoImpl;
+import com.cloud.event.dao.EventJoinDaoImpl;
+import com.cloud.event.dao.UsageEventDaoImpl;
+import com.cloud.ha.HighAvailabilityManager;
+import com.cloud.host.dao.HostDaoImpl;
+import com.cloud.host.dao.HostDetailsDaoImpl;
+import com.cloud.host.dao.HostTagsDaoImpl;
+import com.cloud.hypervisor.HypervisorGuruManagerImpl;
+import com.cloud.hypervisor.dao.HypervisorCapabilitiesDaoImpl;
+import com.cloud.network.ExternalDeviceUsageManager;
+import com.cloud.network.Ipv6AddressManagerImpl;
+import com.cloud.network.NetworkModelImpl;
+import com.cloud.network.NetworkServiceImpl;
+import com.cloud.network.NetworkUsageService;
+import com.cloud.network.StorageNetworkManager;
+import com.cloud.network.StorageNetworkService;
+import com.cloud.network.as.AutoScaleService;
+import com.cloud.network.as.dao.AutoScalePolicyConditionMapDaoImpl;
+import com.cloud.network.as.dao.AutoScalePolicyDaoImpl;
+import com.cloud.network.as.dao.AutoScaleVmGroupDaoImpl;
+import com.cloud.network.as.dao.AutoScaleVmGroupPolicyMapDaoImpl;
+import com.cloud.network.as.dao.AutoScaleVmProfileDaoImpl;
+import com.cloud.network.as.dao.ConditionDaoImpl;
+import com.cloud.network.as.dao.CounterDaoImpl;
+import com.cloud.network.dao.AccountGuestVlanMapDaoImpl;
+import com.cloud.network.dao.FirewallRulesCidrsDaoImpl;
+import com.cloud.network.dao.FirewallRulesDaoImpl;
+import com.cloud.network.dao.LBHealthCheckPolicyDaoImpl;
+import com.cloud.network.dao.LBStickinessPolicyDaoImpl;
+import com.cloud.network.dao.LoadBalancerDaoImpl;
+import com.cloud.network.dao.LoadBalancerVMMapDaoImpl;
+import com.cloud.network.dao.NetworkAccountDaoImpl;
+import com.cloud.network.dao.NetworkDaoImpl;
+import com.cloud.network.dao.NetworkDomainDaoImpl;
+import com.cloud.network.dao.NetworkOpDaoImpl;
+import com.cloud.network.dao.NetworkRuleConfigDaoImpl;
+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.RemoteAccessVpnDaoImpl;
+import com.cloud.network.dao.RouterNetworkDaoImpl;
+import com.cloud.network.dao.Site2SiteCustomerGatewayDaoImpl;
+import com.cloud.network.dao.Site2SiteVpnConnectionDaoImpl;
+import com.cloud.network.dao.Site2SiteVpnGatewayDaoImpl;
+import com.cloud.network.dao.UserIpv6AddressDaoImpl;
+import com.cloud.network.dao.VirtualRouterProviderDaoImpl;
+import com.cloud.network.dao.VpnUserDaoImpl;
+import com.cloud.network.element.Site2SiteVpnServiceProvider;
+import com.cloud.network.firewall.FirewallManagerImpl;
+import com.cloud.network.lb.LoadBalancingRulesManagerImpl;
+import com.cloud.network.router.VpcVirtualNetworkApplianceManagerImpl;
+import com.cloud.network.rules.RulesManagerImpl;
+import com.cloud.network.rules.dao.PortForwardingRulesDaoImpl;
+import com.cloud.network.security.dao.SecurityGroupDaoImpl;
+import com.cloud.network.security.dao.SecurityGroupRuleDaoImpl;
+import com.cloud.network.security.dao.SecurityGroupRulesDaoImpl;
+import com.cloud.network.security.dao.SecurityGroupVMMapDaoImpl;
+import com.cloud.network.security.dao.SecurityGroupWorkDaoImpl;
+import com.cloud.network.security.dao.VmRulesetLogDaoImpl;
+import com.cloud.network.vpc.NetworkACLManagerImpl;
+import com.cloud.network.vpc.NetworkACLService;
+import com.cloud.network.vpc.VpcManagerImpl;
+import com.cloud.network.vpc.dao.NetworkACLDaoImpl;
+import com.cloud.network.vpc.dao.NetworkACLItemDaoImpl;
+import com.cloud.network.vpc.dao.PrivateIpDaoImpl;
+import com.cloud.network.vpc.dao.StaticRouteDaoImpl;
+import com.cloud.network.vpc.dao.VpcDaoImpl;
+import com.cloud.network.vpc.dao.VpcGatewayDaoImpl;
+import com.cloud.network.vpc.dao.VpcOfferingDaoImpl;
+import com.cloud.network.vpc.dao.VpcOfferingServiceMapDaoImpl;
+import com.cloud.network.vpc.dao.VpcServiceMapDaoImpl;
+import com.cloud.network.vpn.RemoteAccessVpnService;
+import com.cloud.network.vpn.Site2SiteVpnManager;
+import com.cloud.projects.dao.ProjectInvitationDaoImpl;
+import com.cloud.dc.DataCenter;
+import com.cloud.dc.dao.DataCenterDao;
+import com.cloud.offerings.dao.NetworkOfferingDaoImpl;
+import com.cloud.offerings.dao.NetworkOfferingDao;
+import com.cloud.offering.NetworkOffering;
+import com.cloud.offerings.dao.NetworkOfferingDetailsDaoImpl;
+import com.cloud.offerings.dao.NetworkOfferingServiceMapDaoImpl;
+import com.cloud.projects.ProjectManager;
+import com.cloud.projects.dao.ProjectAccountDaoImpl;
+import com.cloud.projects.ProjectManagerImpl;
+import com.cloud.projects.dao.ProjectDaoImpl;
+import com.cloud.region.ha.GlobalLoadBalancingRulesService;
+import com.cloud.resource.ResourceManager;
+import com.cloud.server.ConfigurationServerImpl;
+import com.cloud.server.ManagementServer;
+import com.cloud.server.ResourceMetaDataService;
+import com.cloud.server.StatsCollector;
+import com.cloud.server.TaggedResourceService;
+import com.cloud.server.auth.UserAuthenticator;
+import com.cloud.service.dao.ServiceOfferingDaoImpl;
+import com.cloud.service.dao.ServiceOfferingDetailsDaoImpl;
+import com.cloud.storage.DataStoreProviderApiService;
+import com.cloud.storage.StorageManager;
+import com.cloud.storage.dao.DiskOfferingDaoImpl;
+import com.cloud.storage.dao.GuestOSCategoryDaoImpl;
+import com.cloud.storage.dao.GuestOSDaoImpl;
+import com.cloud.storage.dao.LaunchPermissionDao;
+import com.cloud.storage.dao.SnapshotDaoImpl;
+import com.cloud.storage.dao.SnapshotPolicyDaoImpl;
+import com.cloud.storage.dao.StoragePoolDetailsDaoImpl;
+import com.cloud.storage.dao.StoragePoolHostDaoImpl;
+import com.cloud.storage.dao.UploadDaoImpl;
+import com.cloud.storage.dao.VMTemplateDaoImpl;
+import com.cloud.storage.dao.VMTemplateDetailsDaoImpl;
+import com.cloud.storage.dao.VMTemplateHostDaoImpl;
+import com.cloud.storage.dao.VMTemplateZoneDaoImpl;
+import com.cloud.storage.dao.VolumeDaoImpl;
+import com.cloud.storage.dao.VolumeHostDaoImpl;
+import com.cloud.storage.secondary.SecondaryStorageVmManager;
+import com.cloud.storage.snapshot.SnapshotApiService;
+import com.cloud.storage.snapshot.SnapshotManager;
+import com.cloud.storage.VolumeApiService;
+import com.cloud.tags.dao.ResourceTagDao;
+import com.cloud.tags.dao.ResourceTagsDaoImpl;
+import com.cloud.template.TemplateApiService;
+import com.cloud.template.TemplateManager;
+import com.cloud.user.Account;
+import com.cloud.user.dao.AccountDao;
+import com.cloud.user.AccountManager;
+import com.cloud.user.User;
+import com.cloud.user.UserVO;
+import com.cloud.user.dao.UserDao;
+import com.cloud.user.AccountDetailsDaoImpl;
+import com.cloud.user.AccountVO;
+import com.cloud.user.DomainManagerImpl;
+import com.cloud.user.ResourceLimitService;
+import com.cloud.user.dao.AccountDaoImpl;
+import com.cloud.user.dao.SSHKeyPairDaoImpl;
+import com.cloud.user.dao.UserDaoImpl;
+import com.cloud.user.dao.UserStatisticsDaoImpl;
+import com.cloud.user.dao.UserStatsLogDaoImpl;
+import com.cloud.user.dao.VmDiskStatisticsDaoImpl;
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.Transaction;
+import com.cloud.utils.db.TransactionCallbackNoReturn;
+import com.cloud.utils.db.TransactionStatus;
+import com.cloud.uuididentity.dao.IdentityDaoImpl;
+import com.cloud.vm.ItWorkDaoImpl;
+import com.cloud.vm.dao.ConsoleProxyDaoImpl;
+import com.cloud.vm.dao.DomainRouterDaoImpl;
+import com.cloud.vm.dao.InstanceGroupDaoImpl;
+import com.cloud.vm.dao.InstanceGroupVMMapDaoImpl;
+import com.cloud.vm.dao.NicIpAliasDaoImpl;
+import com.cloud.vm.dao.NicSecondaryIpDaoImpl;
+import com.cloud.vm.dao.SecondaryStorageVmDaoImpl;
+import com.cloud.vm.dao.UserVmCloneSettingDaoImpl;
+import com.cloud.vm.dao.UserVmDaoImpl;
+import com.cloud.vm.dao.UserVmDetailsDaoImpl;
+import com.cloud.vm.dao.VMInstanceDaoImpl;
+import com.cloud.vm.snapshot.VMSnapshotManager;
+import com.cloud.vm.snapshot.dao.VMSnapshotDaoImpl;
+
+import org.apache.cloudstack.framework.jobs.impl.AsyncJobManagerImpl;
+import org.apache.cloudstack.framework.jobs.dao.AsyncJobDaoImpl;
+import org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationService;
+
+import com.cloud.network.IpAddressManagerImpl;
+
+import org.apache.cloudstack.framework.config.ConfigDepot;
+import org.apache.cloudstack.framework.jobs.dao.SyncQueueItemDaoImpl;
+import org.apache.cloudstack.framework.jobs.impl.SyncQueueManager;
+import org.apache.cloudstack.framework.jobs.dao.AsyncJobJournalDaoImpl;
+import org.apache.cloudstack.framework.jobs.dao.AsyncJobJoinMapDaoImpl;
+import org.apache.cloudstack.framework.jobs.AsyncJobDispatcher;
+import org.apache.cloudstack.framework.jobs.impl.AsyncJobMonitor;
+import org.apache.cloudstack.framework.config.ConfigDepotAdmin;
+import org.apache.cloudstack.network.lb.InternalLoadBalancerVMManager;
+import org.apache.cloudstack.network.lb.InternalLoadBalancerVMService;
+import org.apache.cloudstack.network.lb.ApplicationLoadBalancerService;
+
+import com.cloud.utils.db.EntityManager;
+
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.network.contrail.management.ContrailElementImpl;
+import org.apache.cloudstack.network.contrail.management.ContrailGuru;
+import org.apache.cloudstack.network.contrail.management.ContrailManagerImpl;
+import org.apache.cloudstack.network.contrail.management.EventUtils;
+import org.apache.cloudstack.network.contrail.management.ServerEventHandlerImpl;
+
+
+@ComponentScan(basePackageClasses={
+        AccountDaoImpl.class,
+        AccountDetailsDaoImpl.class,
+        AccountGuestVlanMapDaoImpl.class,
+        AccountJoinDaoImpl.class,
+        AccountVlanMapDaoImpl.class,
+        AffinityGroupDaoImpl.class,
+        AffinityGroupDomainMapDaoImpl.class,
+        AffinityGroupJoinDaoImpl.class,
+        AffinityGroupVMMapDaoImpl.class,
+        ApiDBUtils.class,
+        ApplicationLoadBalancerRuleDaoImpl.class,
+        AsyncJobDaoImpl.class,
+        AsyncJobJoinDaoImpl.class,
+        AsyncJobJoinMapDaoImpl.class,
+        AsyncJobJournalDaoImpl.class,
+        AsyncJobManagerImpl.class,
+        AutoScalePolicyConditionMapDaoImpl.class,
+        AutoScalePolicyDaoImpl.class,
+        AutoScaleVmGroupDaoImpl.class,
+        AutoScaleVmGroupPolicyMapDaoImpl.class,
+        AutoScaleVmProfileDaoImpl.class,
+        CapacityDaoImpl.class,
+        ClusterDaoImpl.class,
+        ClusterDetailsDaoImpl.class,
+        ConditionDaoImpl.class,
+        ConfigurationDaoImpl.class,
+        ConfigurationManagerImpl.class,
+        ConfigurationServerImpl.class,
+        ConsoleProxyDaoImpl.class,
+        ContrailElementImpl.class,
+        ContrailGuru.class,
+        ContrailManagerImpl.class,
+        CounterDaoImpl.class,
+        DataCenterDaoImpl.class,
+        DataCenterIpAddressDaoImpl.class,
+        DataCenterJoinDaoImpl.class,
+        DataCenterLinkLocalIpAddressDaoImpl.class,
+        DataCenterVnetDaoImpl.class,
+        DcDetailsDaoImpl.class,
+        DedicatedResourceDaoImpl.class,
+        DiskOfferingDaoImpl.class,
+        DiskOfferingJoinDaoImpl.class,
+        DomainDaoImpl.class,
+        DomainManagerImpl.class,
+        DomainRouterDaoImpl.class,
+        DomainRouterJoinDaoImpl.class,
+        EventDaoImpl.class,
+        EventJoinDaoImpl.class,
+        EventUtils.class,
+        EventUtils.class,
+        FirewallManagerImpl.class,
+        FirewallRulesCidrsDaoImpl.class,
+        FirewallRulesDaoImpl.class,
+        GuestOSCategoryDaoImpl.class,
+        GuestOSDaoImpl.class,
+        HostDaoImpl.class,
+        HostDetailsDaoImpl.class,
+        HostJoinDaoImpl.class,
+        HostPodDaoImpl.class,
+        HostTagsDaoImpl.class,
+        HostTransferMapDaoImpl.class,
+        HypervisorCapabilitiesDaoImpl.class,
+        HypervisorGuruManagerImpl.class,
+        IdentityDaoImpl.class,
+        ImageStoreDaoImpl.class,
+        ImageStoreJoinDaoImpl.class,
+        InstanceGroupDaoImpl.class,
+        InstanceGroupJoinDaoImpl.class,
+        InstanceGroupVMMapDaoImpl.class,
+        IpAddressManagerImpl.class,
+        Ipv6AddressManagerImpl.class,
+        ItWorkDaoImpl.class,
+        LBHealthCheckPolicyDaoImpl.class,
+        LBStickinessPolicyDaoImpl.class,
+        LaunchPermissionDao.class,
+        LoadBalancerDaoImpl.class,
+        LoadBalancerVMMapDaoImpl.class,
+        LoadBalancingRulesManagerImpl.class,
+        ManagementServerHostDaoImpl.class,
+        MockAccountManager.class,
+        NetworkACLDaoImpl.class,
+        NetworkACLItemDaoImpl.class,
+        NetworkACLManagerImpl.class,
+        NetworkAccountDaoImpl.class,
+        NetworkDaoImpl.class,
+        NetworkDomainDaoImpl.class,
+        NetworkModelImpl.class,
+        NetworkOfferingDaoImpl.class,
+        NetworkOfferingDetailsDaoImpl.class,
+        NetworkOfferingServiceMapDaoImpl.class,
+        NetworkOpDaoImpl.class,
+        NetworkRuleConfigDaoImpl.class,
+        NetworkServiceImpl.class,
+        NetworkServiceMapDaoImpl.class,
+        NicIpAliasDaoImpl.class,
+        NicSecondaryIpDaoImpl.class,
+        PhysicalNetworkDaoImpl.class,
+        PhysicalNetworkServiceProviderDaoImpl.class,
+        PhysicalNetworkTrafficTypeDaoImpl.class,
+        PlannerHostReservationDaoImpl.class,
+        PodVlanDaoImpl.class,
+        PodVlanMapDaoImpl.class,
+        PortForwardingRulesDaoImpl.class,
+        PortableIpDaoImpl.class,
+        PortableIpRangeDaoImpl.class,
+        PrimaryDataStoreDaoImpl.class,
+        PrivateIpDaoImpl.class,
+        ProjectAccountDaoImpl.class,
+        ProjectAccountJoinDaoImpl.class,
+        ProjectInvitationDaoImpl.class,
+        ProjectDaoImpl.class,
+        ProjectInvitationJoinDaoImpl.class,
+        ProjectJoinDaoImpl.class,
+        ProjectManagerImpl.class,
+        RegionDaoImpl.class,
+        RemoteAccessVpnDaoImpl.class,
+        ResourceCountDaoImpl.class,
+        ResourceLimitDaoImpl.class,
+        ResourceTagDao.class,
+        ResourceTagJoinDaoImpl.class,
+        ResourceTagsDaoImpl.class,
+        RouterNetworkDaoImpl.class,
+        RulesManagerImpl.class,
+        SSHKeyPairDaoImpl.class,
+        SecondaryStorageVmDaoImpl.class,
+        SecurityGroupDaoImpl.class,
+        SecurityGroupJoinDaoImpl.class,
+        SecurityGroupRuleDaoImpl.class,
+        SecurityGroupRulesDaoImpl.class,
+        SecurityGroupVMMapDaoImpl.class,
+        SecurityGroupWorkDaoImpl.class,
+        ServerEventHandlerImpl.class,
+        ServiceOfferingDaoImpl.class,
+        ServiceOfferingDetailsDaoImpl.class,
+        ServiceOfferingJoinDaoImpl.class,
+        Site2SiteCustomerGatewayDaoImpl.class,
+        Site2SiteVpnConnectionDaoImpl.class,
+        Site2SiteVpnGatewayDaoImpl.class,
+        SnapshotDaoImpl.class,
+        SnapshotPolicyDaoImpl.class,
+        StaticRouteDaoImpl.class,
+        StatsCollector.class,
+        StoragePoolDetailsDaoImpl.class,
+        StoragePoolHostDaoImpl.class,
+        StoragePoolJoinDaoImpl.class,
+        SyncQueueItemDaoImpl.class,
+        TemplateDataStoreDaoImpl.class,
+        TemplateJoinDaoImpl.class,
+        UploadDaoImpl.class,
+        UsageEventDaoImpl.class,
+        UserAccountJoinDaoImpl.class,
+        UserDaoImpl.class,
+        UserIpv6AddressDaoImpl.class,
+        UserStatisticsDaoImpl.class,
+        UserStatsLogDaoImpl.class,
+        UserVmCloneSettingDaoImpl.class,
+        UserVmDaoImpl.class,
+        UserVmDetailsDaoImpl.class,
+        UserVmJoinDaoImpl.class,
+        VMInstanceDaoImpl.class,
+        VMSnapshotDaoImpl.class,
+        VMTemplateDaoImpl.class,
+        VMTemplateDetailsDaoImpl.class,
+        VMTemplateHostDaoImpl.class,
+        VMTemplateZoneDaoImpl.class,
+        VirtualRouterProviderDaoImpl.class,
+        VlanDaoImpl.class,
+        VmDiskStatisticsDaoImpl.class,
+        VmRulesetLogDaoImpl.class,
+        VolumeDaoImpl.class,
+        VolumeHostDaoImpl.class,
+        VolumeJoinDaoImpl.class,
+        VpcDaoImpl.class,
+        VpcGatewayDaoImpl.class,
+        VpcManagerImpl.class,
+        VpcOfferingDaoImpl.class,
+        VpcOfferingServiceMapDaoImpl.class,
+        VpcServiceMapDaoImpl.class,
+        VpcVirtualNetworkApplianceManagerImpl.class,
+        VpnUserDaoImpl.class,
+},
+includeFilters={@Filter(value=IntegrationTestConfiguration.ComponentFilter.class, type=FilterType.CUSTOM)},
+useDefaultFilters=false)
+
+@Configuration
+public class IntegrationTestConfiguration {
+    public static class ComponentFilter implements TypeFilter {
+        @Override
+        public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
+            String clsname = mdr.getClassMetadata().getClassName();
+            ComponentScan cs = IntegrationTestConfiguration.class.getAnnotation(ComponentScan.class);
+            return includedInBasePackageClasses(clsname, cs);
+        }
+    }
+    
+    public static boolean includedInBasePackageClasses(String clazzName, ComponentScan cs) {
+        Class<?> clazzToCheck;
+        try {
+            clazzToCheck = Class.forName(clazzName);
+        } catch (ClassNotFoundException e) {
+            System.out.println("Unable to find " + clazzName);
+            return false;
+        }
+        Class<?>[] clazzes = cs.basePackageClasses();
+        for (Class<?> clazz : clazzes) {
+            if (clazzToCheck.isAssignableFrom(clazz)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Inject
+    AffinityGroupDao _affinityGroupDao;
+    @Inject AccountDao _accountDao;
+    @Inject UserDao _userDao;
+    @Inject NetworkOfferingDao _networkOfferingDao;
+    @Inject DataCenterDao _zoneDao;
+    @Inject IPAddressDao _ipAddressDao;
+
+
+    @Bean
+    public AffinityGroupService affinityGroupService() {
+        AffinityGroupService mock = Mockito.mock(AffinityGroupService.class);
+        try {
+            final AffinityGroupVO gmock = new AffinityGroupVO("grp1", "grp-type", "affinity group", 1, AccountVO.ACCOUNT_ID_SYSTEM, ControlledEntity.ACLType.Account); 
+	    Transaction.execute(new TransactionCallbackNoReturn() {
+		    @Override
+		    public void doInTransactionWithoutResult(TransactionStatus status) {
+			_affinityGroupDao.persist(gmock);		
+		    }
+	    });
+            Mockito.when(mock.createAffinityGroupInternal(Mockito.any(String.class), Mockito.any(Long.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class))).thenReturn(gmock);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return mock;
+    }
+
+    @Bean
+    public AgentManager agentManager() {
+        return Mockito.mock(AgentManager.class);
+    }
+
+    @Bean
+    public AlertManager alertManager() {
+        return Mockito.mock(AlertManager.class);
+    }
+
+    @Bean
+    public APIChecker apiChecker() {
+        return Mockito.mock(APIChecker.class);
+    }
+
+    @Bean
+    public AsyncJobDispatcher asyncJobDispatcher() {
+        return Mockito.mock(AsyncJobDispatcher.class);
+    }
+    @Bean
+    public AsyncJobMonitor asyncJobMonitor() {
+        return Mockito.mock(AsyncJobMonitor.class);
+    }
+
+    @Bean
+    public AutoScaleService autoScaleService() {
+        return Mockito.mock(AutoScaleService.class);
+    }
+    @Bean
+    public CapacityManager capacityManager() {
+        return Mockito.mock(CapacityManager.class);
+    }
+    @Bean
+    public ClusterManager clusterManager() {
+        return Mockito.mock(ClusterManager.class);
+    }
+    @Bean
+    public ConfigDepot configDepot() {
+        return Mockito.mock(ConfigDepot.class);
+    }
+    @Bean
+    public ConfigDepotAdmin configDepotAdmin() {
+        return Mockito.mock(ConfigDepotAdmin.class);
+    }
+    @Bean
+    public ConsoleProxyManager consoleProxyManager() {
+        return Mockito.mock(ConsoleProxyManager.class);
+    }
+    @Bean
+    public ConsoleProxyService consoleProxyService() {
+        return Mockito.mock(ConsoleProxyService.class);
+    }
+    @Bean
+    public DataStoreManager dataStoreManager() {
+        return Mockito.mock(DataStoreManager.class);
+    }
+    @Bean
+    public DataStoreProviderApiService dataStoreProviderApiService() {
+        return Mockito.mock(DataStoreProviderApiService.class);
+    }
+    @Bean
+    public DeploymentPlanner deploymentPlanner() {
+        return Mockito.mock(DeploymentPlanner.class);
+    }
+    @Bean
+    public DeploymentPlanningManager deploymentPlanningManager() {
+        return Mockito.mock(DeploymentPlanningManager.class);
+    }
+    @Bean
+    public DomainChecker domainChecker() {
+        DomainChecker mock = Mockito.mock(DomainChecker.class);
+        try {
+            Mockito.when(mock.checkAccess(Mockito.any(Account.class), Mockito.any(DataCenter.class))).thenReturn(true);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return mock;
+    }
+    @Bean
+    public EndPointSelector endPointSelector() {
+        return Mockito.mock(EndPointSelector.class);
+    }
+    @Bean
+    public EntityManager entityManager() {
+        EntityManager mock = Mockito.mock(EntityManager.class);
+        try {
+            Mockito.when(mock.findById(Mockito.same(Account.class), Mockito.anyLong())).thenReturn(_accountDao.findById(AccountVO.ACCOUNT_ID_SYSTEM));
+            Mockito.when(mock.findById(Mockito.same(User.class), Mockito.anyLong())).thenReturn(_userDao.findById(UserVO.UID_SYSTEM));
+            Mockito.when(mock.findById(Mockito.same(NetworkOffering.class), Mockito.any(Long.class))).thenAnswer(
+                new Answer<NetworkOffering>()
+                {
+                     @Override
+                     public NetworkOffering answer(final InvocationOnMock invocation) throws Throwable
+                     {
+                          Long id = (Long) invocation.getArguments()[1];
+                          return _networkOfferingDao.findById(id);
+                     }
+                }
+             );
+            Mockito.when(mock.findById(Mockito.same(IpAddress.class), Mockito.any(Long.class))).thenAnswer(
+                new Answer<IpAddress>()
+                {
+                     @Override
+                     public IpAddress answer(final InvocationOnMock invocation) throws Throwable
+                     {
+                          Long id = (Long) invocation.getArguments()[1];
+                          return _ipAddressDao.findById(id);
+                     }
+                }
+             );
+            Mockito.when(mock.findById(Mockito.same(DataCenter.class), Mockito.any(Long.class))).thenAnswer(
+                new Answer<DataCenter>()
+                {
+                     @Override
+                     public DataCenter answer(final InvocationOnMock invocation) throws Throwable
+                     {
+                          Long id = (Long) invocation.getArguments()[1];
+                          return _zoneDao.findById(id);
+                     }
+                }
+             );
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        CallContext.init(mock);
+        return mock;
+    }
+    @Bean
+    public ExternalDeviceUsageManager externalDeviceUsageManager() {
+        return Mockito.mock(ExternalDeviceUsageManager.class);
+    }
+    @Bean
+    public GlobalLoadBalancingRulesService globalLoadBalancingRulesService() {
+        return Mockito.mock(GlobalLoadBalancingRulesService.class);
+    }
+    @Bean
+    public HighAvailabilityManager highAvailabilityManager()  {
+        return Mockito.mock(HighAvailabilityManager.class);
+    }
+    @Bean
+    public HostAllocator hostAllocator() {
+        return Mockito.mock(HostAllocator.class);
+    }
+    @Bean
+    public IdentityService identityService() {
+        return Mockito.mock(IdentityService.class);
+    }
+    @Bean
+    public InternalLoadBalancerVMManager internalLoadBalancerVMManager() {
+        return Mockito.mock(InternalLoadBalancerVMManager.class);
+    }
+    @Bean
+    public InternalLoadBalancerVMService internalLoadBalancerVMService() {
+        return Mockito.mock(InternalLoadBalancerVMService.class);
+    }
+    @Bean
+    public ApplicationLoadBalancerService applicationLoadBalancerService() {
+        return Mockito.mock(ApplicationLoadBalancerService.class);
+    }
+    @Bean
+    public ManagementServer managementServer() {
+        return Mockito.mock(ManagementServer.class);
+    }
+    @Bean
+    public NetworkACLService networkACLService() {
+        return Mockito.mock(NetworkACLService.class);
+    }
+    @Bean
+    public NetworkUsageService networkUsageService() {
+        return Mockito.mock(NetworkUsageService.class);
+    }
+    @Bean
+    public OrchestrationService orchSrvc() {
+        return Mockito.mock(OrchestrationService.class);
+    }
+    @Bean
+    public PodAllocator podAllocator() {
+        return Mockito.mock(PodAllocator.class);
+    }
+    @Bean
+    public QueryService queryService() {
+        return Mockito.mock(QueryService.class);
+    }
+    @Bean
+    public RegionManager regionManager() {
+        return Mockito.mock(RegionManager.class);
+    }
+    @Bean
+    public RemoteAccessVpnService remoteAccessVpnService() {
+        return Mockito.mock(RemoteAccessVpnService.class);
+    }
+    @Bean
+    public ResourceLimitService resourceLimitService() {
+        return Mockito.mock(ResourceLimitService.class);
+    }
+    @Bean
+    public ResourceManager resourceManager() {
+        return Mockito.mock(ResourceManager.class);
+    }
+    @Bean
+    public ResourceMetaDataService resourceMetaDataService() {
+        return Mockito.mock(ResourceMetaDataService.class);
+    }
+    @Bean
+    public SecondaryStorageVmManager secondaryStorageVmManager() {
+        return Mockito.mock(SecondaryStorageVmManager.class);
+    }
+    @Bean
+    public Site2SiteVpnManager  site2SiteVpnManager() {
+        return Mockito.mock(Site2SiteVpnManager.class);
+    }
+    @Bean
+    public Site2SiteVpnServiceProvider site2SiteVpnServiceProvider() {
+        return Mockito.mock(Site2SiteVpnServiceProvider.class);
+    }
+    @Bean
+    public SnapshotApiService snapshotApiService() {
+        return Mockito.mock(SnapshotApiService.class);
+    }
+    @Bean
+    public SnapshotManager snapshotManager() {
+        return Mockito.mock(SnapshotManager.class);
+    }
+    @Bean
+    public StorageManager storageManager() {
+        return Mockito.mock(StorageManager.class);
+    }
+    @Bean
+    public StorageNetworkManager storageNetworkManager() {
+        return Mockito.mock(StorageNetworkManager.class);
+    }
+    @Bean
+    public StorageNetworkService storageNetworkService() {
+        return Mockito.mock(StorageNetworkService.class);
+    }
+    @Bean
+    public StoragePoolAllocator storagePoolAllocator() {
+        return Mockito.mock(StoragePoolAllocator.class);
+    }
+    @Bean
+    public SyncQueueManager syncQueueManager() {
+        return Mockito.mock(SyncQueueManager.class);
+    }
+    @Bean
+    public TaggedResourceService taggedResourceService() {
+        return Mockito.mock(TaggedResourceService.class);
+    }
+    @Bean
+    public TemplateDataFactory templateDataFactory() {
+        return Mockito.mock(TemplateDataFactory.class);
+    }
+    @Bean
+    public TemplateApiService templateApiService() {
+        return Mockito.mock(TemplateApiService.class);
+    }
+    @Bean
+    public TemplateManager templateManager() {
+        return Mockito.mock(TemplateManager.class);
+    }
+    @Bean
+    public TemplateService templateService() {
+        return Mockito.mock(TemplateService.class);
+    }
+    @Bean
+    public UsageService usageService() {
+        return Mockito.mock(UsageService.class);
+    }
+    @Bean
+    public UserAuthenticator userAuthenticator() {
+        return Mockito.mock(UserAuthenticator.class);
+    }
+    @Bean
+    public VMSnapshotManager vMSnapshotManager() {
+        return Mockito.mock(VMSnapshotManager.class);
+    }
+    @Bean
+    public VolumeApiService volumeApiService() {
+        return Mockito.mock(VolumeApiService.class);
+    }
+    @Bean
+    public VolumeDataFactory volumeDataFactory() {
+        return Mockito.mock(VolumeDataFactory.class);
+    }
+    @Bean 
+    public VolumeOrchestrationService volumeOrchestrationService() {
+        return Mockito.mock(VolumeOrchestrationService.class);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6b5fab2f/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/ManagementServerMock.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/ManagementServerMock.java b/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/ManagementServerMock.java
new file mode 100644
index 0000000..82893f1
--- /dev/null
+++ b/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/ManagementServerMock.java
@@ -0,0 +1,393 @@
+// 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.network.contrail.management;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import javax.inject.Inject;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.command.admin.vlan.CreateVlanIpRangeCmd;
+import org.apache.log4j.Logger;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+import static org.junit.Assert.*;
+
+import com.cloud.agent.AgentManager;
+import com.cloud.agent.api.PlugNicAnswer;
+import com.cloud.agent.api.UnPlugNicAnswer;
+import com.cloud.agent.manager.Commands;
+import com.cloud.configuration.ConfigurationManager;
+import com.cloud.configuration.ConfigurationService;
+import com.cloud.dc.DataCenter;
+import com.cloud.dc.DataCenter.NetworkType;
+import com.cloud.dc.DataCenterVO;
+import com.cloud.dc.dao.DataCenterDao;
+import com.cloud.domain.Domain;
+import com.cloud.exception.AgentUnavailableException;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.OperationTimedoutException;
+import com.cloud.host.Host.Type;
+import com.cloud.host.HostVO;
+import com.cloud.host.Status;
+import com.cloud.host.dao.HostDao;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.network.Network;
+import com.cloud.network.Network.Provider;
+import com.cloud.network.NetworkService;
+import com.cloud.network.Networks.TrafficType;
+import com.cloud.network.PhysicalNetwork;
+import com.cloud.network.PhysicalNetwork.BroadcastDomainRange;
+import com.cloud.network.PhysicalNetworkServiceProvider;
+import com.cloud.network.PhysicalNetworkTrafficType;
+import com.cloud.network.dao.NetworkDao;
+import com.cloud.network.dao.NetworkVO;
+import com.cloud.network.dao.PhysicalNetworkDao;
+import com.cloud.network.dao.PhysicalNetworkVO;
+import com.cloud.offering.ServiceOffering;
+import com.cloud.resource.ResourceState;
+import com.cloud.service.ServiceOfferingVO;
+import com.cloud.service.dao.ServiceOfferingDao;
+import com.cloud.storage.Storage.StoragePoolType;
+import com.cloud.storage.VMTemplateVO;
+import com.cloud.storage.dao.VMTemplateDao;
+import com.cloud.user.Account;
+import com.cloud.user.AccountManager;
+import com.cloud.user.User;
+import com.cloud.uservm.UserVm;
+import com.cloud.utils.Pair;
+import com.cloud.utils.component.ComponentContext;
+import com.cloud.vm.NicProfile;
+import com.cloud.vm.UserVmVO;
+import com.cloud.vm.VirtualMachineManager;
+import com.cloud.vm.dao.UserVmDao;
+
+public class ManagementServerMock {
+    private static final Logger s_logger =
+            Logger.getLogger(ManagementServerMock.class);
+
+    @Inject private AccountManager _accountMgr;
+    @Inject private ConfigurationService _configService;
+    @Inject private DataCenterDao _zoneDao;
+    @Inject private NetworkService _networkService;
+    @Inject private NetworkDao _networksDao;
+    @Inject private PhysicalNetworkDao _physicalNetworkDao;
+    @Inject private UserVmDao _userVmDao;
+    @Inject private ServiceOfferingDao _serviceOfferingDao;
+    @Inject private VMTemplateDao _vmTemplateDao;
+    @Inject private HostDao _hostDao;
+    @Inject public AgentManager _agentMgr;
+    @Inject public VirtualMachineManager _vmMgr;
+
+    private DataCenterVO _zone;
+    private PhysicalNetwork _znet;
+
+    private long _host_id = -1L;
+
+    // TODO: Use the name parameter to retrieve the @Parameter annotation.
+    static void setParameter(BaseCmd cmd, String name, BaseCmd.CommandType field_type, Object value) {
+        Class<?> cls = cmd.getClass();
+        Field field;
+        try {
+            field = cls.getDeclaredField(name);
+        } catch (Exception ex) {
+            s_logger.warn("class: " + cls.getName() + "\t" + ex);
+            return;
+        }
+        field.setAccessible(true);
+        switch (field_type) {
+        case STRING:
+            try {
+                field.set(cmd, value);
+            } catch (Exception ex) {
+                s_logger.warn(ex);
+                return;
+            }
+            break;
+        case UUID:
+            if (value.equals("-1")) {
+                try {
+                    field.setLong(cmd, -1L);
+                } catch (Exception ex) {
+                    s_logger.warn(ex);
+                    return;
+                }
+            }
+            break;
+        case LONG:
+            try {
+                field.set(cmd, value);
+            } catch (Exception ex) {
+                s_logger.warn(ex);
+                return;
+            }
+            break;
+        default:
+            try {
+                field.set(cmd, value);
+            } catch (Exception ex) {
+                s_logger.warn(ex);
+                return;
+            }
+            break;
+        }
+    }
+
+    private void createHost() {
+        HostVO host = new HostVO(_host_id, "aa01", Type.BaremetalDhcp,
+                "192.168.1.1", "255.255.255.0", null,
+                null, null, null,
+                null, null, null,
+                null, null, null,
+                UUID.randomUUID().toString(), Status.Up, "1.0", null,
+                null, _zone.getId(), null, 0, 0, "aa", 0, StoragePoolType.NetworkFilesystem);
+        host.setResourceState(ResourceState.Enabled);
+        _hostDao.persist(host);
+        _host_id = host.getId();
+    }
+    private void createPublicVlanIpRange() {
+        CreateVlanIpRangeCmd cmd = new CreateVlanIpRangeCmd();
+        BaseCmd proxy = ComponentContext.inject(cmd);
+        Long public_net_id = null;
+
+        List<NetworkVO> nets = _networksDao.listByZoneAndTrafficType(_zone.getId(), TrafficType.Public);
+        if (nets != null && !nets.isEmpty()) {
+            NetworkVO public_net = nets.get(0); 
+            public_net_id = public_net.getId();
+        } else {
+            s_logger.debug("no public network found in the zone: " + _zone.getId());
+        }
+        Account system = _accountMgr.getSystemAccount();
+
+        setParameter(cmd, "accountName", BaseCmd.CommandType.STRING, system.getAccountName());
+        setParameter(cmd, "domainId", BaseCmd.CommandType.LONG, Domain.ROOT_DOMAIN);
+        setParameter(cmd, "startIp", BaseCmd.CommandType.STRING, "10.84.60.200");
+        setParameter(cmd, "endIp", BaseCmd.CommandType.STRING, "10.84.60.250");
+        setParameter(cmd, ApiConstants.GATEWAY, BaseCmd.CommandType.STRING, "10.84.60.254");
+        setParameter(cmd, ApiConstants.NETMASK, BaseCmd.CommandType.STRING, "255.255.255.0");
+        setParameter(cmd, "networkID", BaseCmd.CommandType.LONG, public_net_id);
+        setParameter(cmd, "zoneId", BaseCmd.CommandType.LONG, _zone.getId());
+        setParameter(cmd, "vlan", BaseCmd.CommandType.STRING, "untagged");
+        s_logger.debug("createPublicVlanIpRange execute : zone id: " + _zone.getId() + ", public net id: " + public_net_id);
+        try {
+           _configService.createVlanAndPublicIpRange(cmd);
+        } catch (Exception e) {
+           s_logger.debug("createPublicVlanIpRange: " + e);
+        }
+    }
+
+
+    public UserVm createVM(String name, Network network) {
+        VMTemplateVO tmpl = getVMTemplate();
+        assertNotNull(tmpl);
+        ServiceOffering small = getServiceByName("Small Instance");
+        assertNotNull(small);
+
+        Answer<?> callback = new Answer<Object>() {
+            public Object answer(InvocationOnMock invocation) {
+                Object[] args = invocation.getArguments();
+                Commands cmds = (Commands) args[1];
+                if (cmds == null) {
+                    return null;
+                }
+                PlugNicAnswer reply = new PlugNicAnswer(null, true, "PlugNic");
+                com.cloud.agent.api.Answer[] answers = { reply };
+                cmds.setAnswers(answers);
+                return null;
+            }
+        };
+        try {
+            Mockito.when(_agentMgr.send(Mockito.anyLong(), Mockito.any(Commands.class))).thenAnswer(callback);
+        } catch (AgentUnavailableException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (OperationTimedoutException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        long id = _userVmDao.getNextInSequence(Long.class, "id");
+        UserVmVO vm = new UserVmVO(id, name, name, tmpl.getId(), HypervisorType.XenServer, tmpl.getGuestOSId(),
+                false, false, _zone.getDomainId(), Account.ACCOUNT_ID_SYSTEM, small.getId(), null, name, null);
+        vm.setState(com.cloud.vm.VirtualMachine.State.Running);
+        vm.setHostId(_host_id);
+        vm.setDataCenterId(network.getDataCenterId());
+        _userVmDao.persist(vm);
+
+        NicProfile profile = new NicProfile();
+        try {
+            _vmMgr.addVmToNetwork(vm, network, profile);
+        } catch (Exception ex) {
+            // TODO Auto-generated catch block
+            //ex.printStackTrace();
+        }
+        return vm;
+    }
+
+    private void deleteHost() {
+        _hostDao.remove(_host_id);
+
+    }
+
+    public void deleteVM(UserVm vm, Network network) {
+        Answer<?> callback = new Answer<Object>() {
+            public Object answer(InvocationOnMock invocation) {
+                Object[] args = invocation.getArguments();
+                Commands cmds = (Commands) args[1];
+                if (cmds == null) {
+                    return null;
+                }
+                UnPlugNicAnswer reply = new UnPlugNicAnswer(null, true, "PlugNic");
+                com.cloud.agent.api.Answer[] answers = { reply };
+                cmds.setAnswers(answers);
+                return null;
+            }
+        };
+
+        try {
+            Mockito.when(_agentMgr.send(Mockito.anyLong(), Mockito.any(Commands.class))).thenAnswer(callback);
+        } catch (AgentUnavailableException e) {
+            e.printStackTrace();
+        } catch (OperationTimedoutException e) {
+            e.printStackTrace();
+        }
+        
+        _userVmDao.remove(vm.getId());
+    }
+
+    public void initialize(boolean oneShot) {
+        locateZone();
+        locatePhysicalNetwork();
+        createHost();
+        if (oneShot) {
+            createPublicVlanIpRange();
+        }
+    }
+
+    private VMTemplateVO getVMTemplate() {
+        List<VMTemplateVO> tmpl_list = _vmTemplateDao.listDefaultBuiltinTemplates();
+        for (VMTemplateVO tmpl: tmpl_list) {
+            if (tmpl.getHypervisorType() == HypervisorType.XenServer) {
+                return tmpl;
+            }
+        }    
+        return null;
+    }
+
+    private ServiceOffering getServiceByName(String name) {
+        List<ServiceOfferingVO> service_list = _serviceOfferingDao.findPublicServiceOfferings();
+        for (ServiceOfferingVO service: service_list) {
+            if (service.getName().equals(name)) {
+                return service;
+            }
+        }
+        return null;
+    }
+
+    public DataCenter getZone() {
+        return _zone;
+    }
+
+    private void locatePhysicalNetwork() {
+        // mandatory: name, zone-id
+        try {
+            long id = _networkService.findPhysicalNetworkId(_zone.getId(), "znet", TrafficType.Guest);
+            _znet = _networkService.getPhysicalNetwork(id);
+            List<PhysicalNetworkVO> nets = _physicalNetworkDao.listByZoneAndTrafficType(_zone.getId(), TrafficType.Public);
+            if (nets == null || nets.isEmpty()) {
+                _networkService.addTrafficTypeToPhysicalNetwork(_znet.getId(), TrafficType.Public.toString(), null, null, null, null, null);
+            }
+        } catch (InvalidParameterValueException e) {
+            List<String> isolationMethods = new ArrayList<String>();
+            isolationMethods.add("GRE");
+            _znet = _networkService.createPhysicalNetwork(_zone.getId(), null, null, isolationMethods,
+                    BroadcastDomainRange.ZONE.toString(), _zone.getDomainId(),
+                    null, "znet");
+            List<PhysicalNetworkVO> nets = _physicalNetworkDao.listByZoneAndTrafficType(_zone.getId(), TrafficType.Public);
+            if (nets == null || nets.isEmpty()) {
+                _networkService.addTrafficTypeToPhysicalNetwork(_znet.getId(), TrafficType.Public.toString(), null, null, null, null, null);
+            }
+        }
+        if (_znet.getState() != PhysicalNetwork.State.Enabled) {
+            _znet = _networkService.updatePhysicalNetwork(_znet.getId(), null, null, null,
+                    PhysicalNetwork.State.Enabled.toString());
+        }
+
+        // Ensure that the physical network supports Guest traffic.
+        Pair<List<? extends PhysicalNetworkTrafficType>, Integer> trafficTypes =
+                _networkService.listTrafficTypes(_znet.getId());
+        boolean found = false;
+        for (PhysicalNetworkTrafficType ttype: trafficTypes.first()) {
+            if (ttype.getTrafficType() == TrafficType.Guest) {
+                found = true;
+            }
+        }
+        if (!found) {
+            _networkService.addTrafficTypeToPhysicalNetwork(_znet.getId(), TrafficType.Guest.toString(),
+                    null, null, null, null, null);
+        }
+
+        Pair<List<? extends PhysicalNetworkServiceProvider>, Integer> providers =
+                _networkService.listNetworkServiceProviders(_znet.getId(), Provider.JuniperContrail.getName(),
+                        null, null, null);
+        if (providers.second() == 0) {
+            s_logger.debug("Add " + Provider.JuniperContrail.getName() + " to network " + _znet.getName());
+            PhysicalNetworkServiceProvider provider =
+                    _networkService.addProviderToPhysicalNetwork(_znet.getId(), Provider.JuniperContrail.getName(),
+                            null, null);
+            _networkService.updateNetworkServiceProvider(provider.getId(),
+                    PhysicalNetworkServiceProvider.State.Enabled.toString(), null);
+        } else {
+            PhysicalNetworkServiceProvider provider = providers.first().get(0);
+            if (provider.getState() != PhysicalNetworkServiceProvider.State.Enabled) {
+                _networkService.updateNetworkServiceProvider(provider.getId(),
+                        PhysicalNetworkServiceProvider.State.Enabled.toString(), null); 
+            }
+        }
+
+        providers = _networkService.listNetworkServiceProviders(_znet.getId(), null,
+                PhysicalNetworkServiceProvider.State.Enabled.toString(), null, null);
+        s_logger.debug(_znet.getName() + " has " + providers.second().toString() + " Enabled providers");
+        for (PhysicalNetworkServiceProvider provider: providers.first()) {
+            if (provider.getProviderName().equals(Provider.JuniperContrail.getName())) {
+                continue;
+            }
+            s_logger.debug("Disabling " + provider.getProviderName());
+            _networkService.updateNetworkServiceProvider(provider.getId(),
+                    PhysicalNetworkServiceProvider.State.Disabled.toString(), null);
+        }
+    }
+
+    private void locateZone() {
+        _zone = _zoneDao.findByName("default");
+        if (_zone == null) {
+            ConfigurationManager mgr = (ConfigurationManager) _configService;
+            _zone = mgr.createZone(User.UID_SYSTEM, "default", "8.8.8.8", null, "8.8.4.4", null,
+                    null /* cidr */, "ROOT", Domain.ROOT_DOMAIN,
+                    NetworkType.Advanced, null, null /* networkDomain */, false, false, null, null);
+        }
+    }
+    public void shutdown() {
+        deleteHost();
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6b5fab2f/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/MockAccountManager.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/MockAccountManager.java b/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/MockAccountManager.java
new file mode 100644
index 0000000..195e932
--- /dev/null
+++ b/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/MockAccountManager.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 org.apache.cloudstack.network.contrail.management;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.inject.Inject;
+import javax.naming.ConfigurationException;
+
+import org.apache.cloudstack.acl.ControlledEntity;
+import org.apache.cloudstack.acl.RoleType;
+import org.apache.cloudstack.acl.SecurityChecker.AccessType;
+import org.apache.cloudstack.api.command.admin.account.UpdateAccountCmd;
+import org.apache.cloudstack.api.command.admin.user.DeleteUserCmd;
+import org.apache.cloudstack.api.command.admin.user.RegisterCmd;
+import org.apache.cloudstack.api.command.admin.user.UpdateUserCmd;
+import org.apache.log4j.Logger;
+
+import com.cloud.utils.db.Transaction;
+import com.cloud.utils.db.TransactionCallbackNoReturn;
+import com.cloud.utils.db.TransactionStatus;
+
+import com.cloud.api.query.vo.ControlledViewEntity;
+import com.cloud.domain.Domain;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.PermissionDeniedException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.projects.Project.ListProjectResourcesCriteria;
+import com.cloud.user.Account;
+import com.cloud.user.AccountManager;
+import com.cloud.user.AccountVO;
+import com.cloud.user.User;
+import com.cloud.user.UserAccount;
+import org.apache.cloudstack.context.CallContext;
+import com.cloud.user.UserVO;
+import com.cloud.user.dao.AccountDao;
+import com.cloud.api.query.dao.AccountJoinDao;
+import com.cloud.configuration.dao.ResourceCountDao;
+import com.cloud.configuration.ResourceLimit;
+import com.cloud.api.query.vo.AccountJoinVO;
+import com.cloud.user.dao.UserDao;
+import com.cloud.utils.Pair;
+import com.cloud.utils.Ternary;
+import com.cloud.utils.component.ManagerBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+
+import org.mockito.Mockito;
+
+public class MockAccountManager extends ManagerBase implements AccountManager {
+    private static final Logger s_logger =
+            Logger.getLogger(MockAccountManager.class);
+
+	@Inject AccountDao _accountDao;
+        @Inject ResourceCountDao _resourceCountDao;
+
+        @Inject AccountJoinDao _accountJoinDao;
+	@Inject UserDao _userDao;
+	
+	UserVO _systemUser;
+	AccountVO _systemAccount;
+
+    @Override
+    public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
+        _systemAccount = _accountDao.findById(AccountVO.ACCOUNT_ID_SYSTEM);
+        if (_systemAccount == null) {
+            throw new ConfigurationException("Unable to find the system account using " + Account.ACCOUNT_ID_SYSTEM);
+        }
+
+        _systemUser = _userDao.findById(UserVO.UID_SYSTEM);
+        if (_systemUser == null) {
+            throw new ConfigurationException("Unable to find the system user using " + User.UID_SYSTEM);
+        }
+        CallContext.register(_systemUser, _systemAccount);
+        s_logger.info("MockAccountManager initialization successful");
+        return true;
+    }
+
+    @Override
+    public void checkAccess(Account arg0, Domain arg1)
+            throws PermissionDeniedException {
+        // TODO Auto-generated method stub
+        
+    }
+
+    @Override
+    public void checkAccess(Account arg0, AccessType arg1, boolean arg2,
+            ControlledEntity... arg3) throws PermissionDeniedException {
+        // TODO Auto-generated method stub
+        
+    }
+
+    @Override
+    public String[] createApiKeyAndSecretKey(RegisterCmd arg0) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public User createUser(String arg0, String arg1, String arg2, String arg3,
+            String arg4, String arg5, String arg6, Long arg7, String arg8) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public UserAccount createUserAccount(String arg0, String arg1, String arg2,
+            String arg3, String arg4, String arg5, String arg6, short arg7,
+            Long arg8, String arg9, Map<String, String> arg10, String arg11,
+            String arg12) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Account finalizeOwner(Account arg0, String arg1, Long arg2, Long arg3) {
+        return _systemAccount; 
+    }
+
+    @Override
+    public Account getActiveAccountByName(String arg0, Long arg1) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public User getActiveUser(long arg0) {
+        return _systemUser;
+    }
+
+    @Override
+    public User getActiveUserByRegistrationToken(String arg0) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public RoleType getRoleType(Account arg0) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Account getSystemAccount() {
+        return _systemAccount;
+    }
+
+    @Override
+    public User getSystemUser() {
+        return _systemUser;
+    }
+
+    @Override
+    public UserAccount getUserByApiKey(String arg0) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public User getUserIncludingRemoved(long arg0) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public boolean isAdmin(short arg0) {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    @Override
+    public boolean isRootAdmin(short arg0) {
+        // TODO Auto-generated method stub
+        return true;
+    }
+
+    @Override
+    public UserAccount lockUser(long arg0) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public void markUserRegistered(long arg0) {
+        // TODO Auto-generated method stub
+        
+    }
+
+    @Override
+    public UserAccount authenticateUser(String arg0, String arg1, Long arg2,
+            String arg3, Map<String, Object[]> arg4) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public void buildACLSearchBuilder(
+            SearchBuilder<? extends ControlledEntity> arg0, Long arg1,
+            boolean arg2, List<Long> arg3, ListProjectResourcesCriteria arg4) {
+        // TODO Auto-generated method stub
+        
+    }
+
+    @Override
+    public void buildACLSearchCriteria(
+            SearchCriteria<? extends ControlledEntity> arg0, Long arg1,
+            boolean arg2, List<Long> arg3, ListProjectResourcesCriteria arg4) {
+        // TODO Auto-generated method stub
+        
+    }
+
+    @Override
+    public void buildACLSearchParameters(Account arg0, Long arg1, String arg2,
+            Long arg3, List<Long> arg4,
+            Ternary<Long, Boolean, ListProjectResourcesCriteria> arg5,
+            boolean arg6, boolean arg7) {
+        // TODO Auto-generated method stub
+        
+    }
+
+    @Override
+    public void buildACLViewSearchBuilder(
+            SearchBuilder<? extends ControlledViewEntity> arg0, Long arg1,
+            boolean arg2, List<Long> arg3, ListProjectResourcesCriteria arg4) {
+        // TODO Auto-generated method stub
+        
+    }
+
+    @Override
+    public void buildACLViewSearchCriteria(
+            SearchCriteria<? extends ControlledViewEntity> arg0, Long arg1,
+            boolean arg2, List<Long> arg3, ListProjectResourcesCriteria arg4) {
+        // TODO Auto-generated method stub
+        
+    }
+
+    @Override
+    public Long checkAccessAndSpecifyAuthority(Account arg0, Long arg1) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public boolean deleteAccount(AccountVO arg0, long arg1, Account arg2) {
+        return true;
+    }
+
+    @Override
+    public boolean deleteUser(DeleteUserCmd arg0) {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    @Override
+    public boolean deleteUserAccount(long arg0) {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    @Override
+    public boolean disableAccount(long arg0)
+            throws ConcurrentOperationException, ResourceUnavailableException {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    @Override
+    public Account disableAccount(String arg0, Long arg1, Long arg2)
+            throws ConcurrentOperationException, ResourceUnavailableException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public UserAccount disableUser(long arg0) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public boolean enableAccount(long arg0) {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    @Override
+    public Account enableAccount(String arg0, Long arg1, Long arg2) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public UserAccount enableUser(long arg0) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Pair<User, Account> findUserByApiKey(String arg0) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Account lockAccount(String arg0, Long arg1, Long arg2) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Account updateAccount(UpdateAccountCmd arg0) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public UserAccount updateUser(UpdateUserCmd arg0) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+	@Override
+	public Account getActiveAccountById(long accountId) {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public Account getAccount(long accountId) {
+               return _systemAccount;
+	}
+
+	@Override
+	public Account createAccount(String accountName, short accountType,
+			Long domainId, String networkDomain, Map<String, String> details,
+			String uuid) {
+	    final AccountVO account = new AccountVO(accountName, domainId, networkDomain, accountType, uuid);
+	    Transaction.execute(new TransactionCallbackNoReturn() {
+	        @Override
+		public void doInTransactionWithoutResult(TransactionStatus status) {
+
+		    _accountDao.persist(account);
+		    _resourceCountDao.createResourceCounts(account.getId(), ResourceLimit.ResourceOwnerType.Account);
+		}
+	    });
+            return account;
+	}
+
+	@Override
+	public void logoutUser(long userId) {
+		// TODO Auto-generated method stub
+		
+	}
+    
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6b5fab2f/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/NetworkProviderTest.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/NetworkProviderTest.java b/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/NetworkProviderTest.java
new file mode 100644
index 0000000..40cd1ea
--- /dev/null
+++ b/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/NetworkProviderTest.java
@@ -0,0 +1,477 @@
+// 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.network.contrail.management;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import javax.inject.Inject;
+
+import junit.framework.TestCase;
+
+import org.apache.cloudstack.network.contrail.management.ContrailManager;
+import org.apache.cloudstack.network.contrail.management.ServerDBSync;
+
+import net.juniper.contrail.api.ApiConnector;
+import net.juniper.contrail.api.ApiConnectorFactory;
+import net.juniper.contrail.api.ApiConnectorMock;
+import net.juniper.contrail.api.types.InstanceIp;
+import net.juniper.contrail.api.types.NetworkIpam;
+import net.juniper.contrail.api.types.SubnetType;
+import net.juniper.contrail.api.types.VirtualMachine;
+import net.juniper.contrail.api.types.VirtualMachineInterface;
+import net.juniper.contrail.api.types.VirtualNetwork;
+import net.juniper.contrail.api.types.VnSubnetsType;
+import net.juniper.contrail.api.types.Project;
+
+import org.apache.log4j.Logger;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.command.user.project.CreateProjectCmd;
+import org.apache.cloudstack.api.command.user.project.DeleteProjectCmd;
+import org.apache.cloudstack.api.command.user.address.AssociateIPAddrCmd;
+import org.apache.cloudstack.api.command.user.nat.EnableStaticNatCmd;
+import org.apache.cloudstack.api.command.user.nat.DisableStaticNatCmd;
+import org.apache.cloudstack.api.command.user.network.CreateNetworkCmd;
+import org.junit.runner.RunWith;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.cloud.utils.db.Merovingian2;
+import com.cloud.utils.mgmt.JmxUtil;
+
+import org.apache.cloudstack.utils.identity.ManagementServerNode;
+
+import com.cloud.agent.AgentManager;
+import com.cloud.dc.DataCenter;
+import com.cloud.domain.Domain;
+import com.cloud.exception.CloudException;
+import com.cloud.network.Network;
+import com.cloud.network.NetworkService;
+import com.cloud.domain.DomainVO;
+import com.cloud.domain.dao.DomainDao;
+import com.cloud.projects.ProjectVO;
+import com.cloud.projects.dao.ProjectDao;
+import com.cloud.user.Account;
+import com.cloud.user.AccountManager;
+import com.cloud.user.User;
+import com.cloud.uservm.UserVm;
+import com.cloud.utils.component.ComponentContext;
+import com.cloud.utils.component.ComponentLifecycle;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Op;
+import com.cloud.vm.VirtualMachineManager;
+import com.cloud.network.dao.IPAddressDao;
+import com.cloud.network.dao.IPAddressVO;
+
+import org.apache.cloudstack.context.CallContext;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations="classpath:/providerContext.xml")
+/**
+ * Exercise the public API.
+ */
+public class NetworkProviderTest extends TestCase {
+    private static final Logger s_logger =
+            Logger.getLogger(NetworkProviderTest.class);
+
+    @Inject public ContrailManager _contrailMgr;
+    @Inject public ServerDBSync _dbSync;
+    @Inject public AccountManager _accountMgr;
+    @Inject IPAddressDao _ipAddressDao;
+    @Inject private NetworkService _networkService;
+
+    @Inject public VirtualMachineManager _vmMgr;
+
+    @Inject public DomainDao _domainDao;
+    @Inject public ProjectDao _projectDao;
+    @Inject public AgentManager _agentMgr;
+    
+    private ManagementServerMock _server;
+    private ApiConnector _api;
+    private static int _mysql_server_port;
+    private static long _msId;
+    private static Merovingian2 _lockMaster;
+    public static boolean _initDone = false;
+
+    @BeforeClass
+    public static void globalSetUp() throws Exception {
+        ApiConnectorFactory.setImplementation(ApiConnectorMock.class);
+        s_logger.info("mysql server is getting launched ");
+        _mysql_server_port = TestDbSetup.init(null);
+        s_logger.info("mysql server launched on port " + _mysql_server_port);
+
+        _msId = ManagementServerNode.getManagementServerId();
+        _lockMaster = Merovingian2.createLockMaster(_msId);        
+    }
+ 
+    @AfterClass
+    public static void globalTearDown() throws Exception {
+        _lockMaster.cleanupForServer(_msId);
+        JmxUtil.unregisterMBean("Locks", "Locks");
+        _lockMaster = null;
+        
+        AbstractApplicationContext ctx = (AbstractApplicationContext) ComponentContext.getApplicationContext();
+        Map<String, ComponentLifecycle> lifecycleComponents = ctx.getBeansOfType(ComponentLifecycle.class);
+        for (ComponentLifecycle bean: lifecycleComponents.values()) {
+            bean.stop();
+        }
+        ctx.close();
+        
+        s_logger.info("destroying mysql server instance running at port <" + _mysql_server_port + ">");
+        TestDbSetup.destroy(_mysql_server_port, null);
+    }
+
+    @Before
+    public void setUp() throws Exception {
+        try {
+            ComponentContext.initComponentsLifeCycle();
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            s_logger.error(ex.getMessage());
+        }
+        Account system = _accountMgr.getSystemAccount();
+        User user = _accountMgr.getSystemUser();
+        CallContext.register(user, system);
+        _server = ComponentContext.inject(new ManagementServerMock());
+
+        _server.initialize(!_initDone);
+        _initDone = false;
+        _api = _contrailMgr.getApiConnector();
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        _server.shutdown();
+    }
+
+    private void purgeTestNetwork() {
+        Account system = _accountMgr.getSystemAccount();
+        DataCenter zone = _server.getZone();
+        List<? extends Network> list =
+                _networkService.getIsolatedNetworksOwnedByAccountInZone(zone.getId(), system);
+        for (Network net : list) {
+            s_logger.debug("Delete network " + net.getName());
+            _networkService.deleteNetwork(net.getId());
+        }
+    }
+
+    private Network lookupTestNetwork(String name) {
+        Account system = _accountMgr.getSystemAccount();
+        DataCenter zone = _server.getZone();
+        List<? extends Network> list =
+                _networkService.getIsolatedNetworksOwnedByAccountInZone(zone.getId(), system);
+        for (Network net : list) {
+            if (net.getName().equals(name)) {
+                return net;
+            }
+        }
+        return null;
+    }
+
+    private Network createTestNetwork(String name) {
+        CreateNetworkCmd cmd = new CreateNetworkCmd();
+        ComponentContext.inject(cmd);
+        Account system = _accountMgr.getSystemAccount();
+        DataCenter zone = _server.getZone();
+
+        ManagementServerMock.setParameter(cmd, "accountName", BaseCmd.CommandType.STRING, system.getAccountName());
+        ManagementServerMock.setParameter(cmd, ApiConstants.NAME, BaseCmd.CommandType.STRING, name);
+        ManagementServerMock.setParameter(cmd, "displayText", BaseCmd.CommandType.STRING, "test network");
+        ManagementServerMock.setParameter(cmd, "networkOfferingId", BaseCmd.CommandType.LONG, _contrailMgr.getOffering().getId());
+        ManagementServerMock.setParameter(cmd, "zoneId", BaseCmd.CommandType.LONG, zone.getId());
+        ManagementServerMock.setParameter(cmd, ApiConstants.GATEWAY, BaseCmd.CommandType.STRING, "10.0.1.254");
+        ManagementServerMock.setParameter(cmd, ApiConstants.NETMASK, BaseCmd.CommandType.STRING, "255.255.255.0");
+        // Physical network id can't be specified for Guest traffic type.
+        // SetParameter(cmd, "physicalNetworkId", BaseCmd.CommandType.LONG, _znet.getId());
+
+        Network result = null;
+        try {
+            result = _networkService.createGuestNetwork(cmd);
+        } catch (CloudException e) {
+            e.printStackTrace();
+            return null;
+        }
+        return result;
+    }
+
+
+    @Test
+    //@Ignore
+    public void testCreateNetwork() {
+        purgeTestNetwork();
+        createTestNetwork("test");
+    }
+ 
+    @Test
+    public void testConnectivity() {
+        Network network = lookupTestNetwork("test");
+        if (network == null) {
+            network = createTestNetwork("test");
+        }
+        UserVm vm1 = _server.createVM("x01", network);
+        UserVm vm2 = _server.createVM("x02", network);
+
+        _server.deleteVM(vm1, network);
+        _server.deleteVM(vm2, network);
+    }
+
+    @Test
+    public void floatingIpTest() {
+        Network network = lookupTestNetwork("test-fip-net");
+        if (network == null) {
+            network = createTestNetwork("test-fip-net");
+        }
+        UserVm vm = _server.createVM("test-fip-vm", network);
+        try {
+            IPAddressVO ip = createFloatingIp(network, vm);
+            deleteFloatingIp(ip);
+        } catch (Exception e) {
+            fail("unable to create/delete floating ip");
+        }
+        _server.deleteVM(vm, network);
+    }
+
+    public void deleteFloatingIp(IPAddressVO ip) throws Exception{
+        BaseCmd cmd = new DisableStaticNatCmd();
+        BaseCmd proxy = ComponentContext.inject(cmd);
+        ManagementServerMock.setParameter(proxy, "ipAddressId", BaseCmd.CommandType.LONG, ip.getId());
+        try {
+            proxy.execute();
+        } catch (Exception e) {
+            s_logger.debug("DisableStaticNatCmd exception: " + e);
+            e.printStackTrace();
+            throw e;
+        }
+    }
+
+    public IPAddressVO createFloatingIp(Network network, UserVm vm) throws Exception {
+        BaseCmd cmd = new AssociateIPAddrCmd();
+        BaseCmd proxy = ComponentContext.inject(cmd);
+        Account system = _accountMgr.getSystemAccount();
+        DataCenter zone = _server.getZone();
+
+        ManagementServerMock.setParameter(proxy, "accountName", BaseCmd.CommandType.STRING, system.getAccountName());
+        ManagementServerMock.setParameter(proxy, "domainId", BaseCmd.CommandType.LONG, Domain.ROOT_DOMAIN);
+        ManagementServerMock.setParameter(proxy, "zoneId", BaseCmd.CommandType.LONG, zone.getId());
+        ManagementServerMock.setParameter(proxy, "networkId", BaseCmd.CommandType.LONG, network.getId());
+        try {
+            ((AssociateIPAddrCmd)cmd).create();
+            ((AssociateIPAddrCmd)cmd).execute();
+        } catch (Exception e) {
+            s_logger.debug("AssociateIPAddrCmd exception: " + e);
+            e.printStackTrace();
+            throw e;
+        }
+
+        SearchBuilder<IPAddressVO> searchBuilder = _ipAddressDao.createSearchBuilder();
+        searchBuilder.and("sourceNat", searchBuilder.entity().isSourceNat(), Op.EQ);
+        searchBuilder.and("network", searchBuilder.entity().getAssociatedWithNetworkId(), Op.EQ);
+        searchBuilder.and("dataCenterId", searchBuilder.entity().getDataCenterId(), Op.EQ);
+        searchBuilder.and("associatedWithVmId", searchBuilder.entity().getAssociatedWithVmId(), Op.NULL);
+        SearchCriteria<IPAddressVO> sc = searchBuilder.create();
+        sc.setParameters("sourceNat", false);
+        sc.setParameters("network", network.getId());
+
+        List<IPAddressVO> publicIps = _ipAddressDao.search(sc, null);
+        assertNotNull(publicIps);
+
+        cmd = new EnableStaticNatCmd();
+        proxy = ComponentContext.inject(cmd);
+        ManagementServerMock.setParameter(proxy, "ipAddressId", BaseCmd.CommandType.LONG, publicIps.get(0).getId());
+        ManagementServerMock.setParameter(proxy, "networkId", BaseCmd.CommandType.LONG, network.getId());
+        ManagementServerMock.setParameter(proxy, "virtualMachineId", BaseCmd.CommandType.LONG, vm.getId());
+
+        try {
+            proxy.execute();
+        } catch (Exception e) {
+            s_logger.debug("EnableStaticNatCmd exception: " + e);
+            e.printStackTrace();
+            throw e;
+        }
+        return publicIps.get(0);
+    }
+
+    public void createProject(String name) {
+        BaseCmd cmd = new CreateProjectCmd();
+        BaseCmd proxy = ComponentContext.inject(cmd);
+        Account system = _accountMgr.getSystemAccount();
+
+        ManagementServerMock.setParameter(proxy, "accountName", BaseCmd.CommandType.STRING, system.getAccountName());
+        ManagementServerMock.setParameter(proxy, "domainId", BaseCmd.CommandType.LONG, Domain.ROOT_DOMAIN);
+        ManagementServerMock.setParameter(proxy, "name", BaseCmd.CommandType.STRING, name);
+        ManagementServerMock.setParameter(proxy, "displayText", BaseCmd.CommandType.STRING, name);
+        try {
+            ((CreateProjectCmd)proxy).create();
+            ((CreateProjectCmd)proxy).execute();
+        } catch (Exception e) {
+            s_logger.debug("CreateProjectCmd exception: " + e);
+            e.printStackTrace();
+            fail("create project cmd failed");
+        }
+        DomainVO domain = _domainDao.findById(Domain.ROOT_DOMAIN);
+        try {
+            net.juniper.contrail.api.types.Domain vncDomain = (net.juniper.contrail.api.types.Domain)
+                    _api.findById(net.juniper.contrail.api.types.Domain.class, domain.getUuid());
+            if (_api.findByName(net.juniper.contrail.api.types.Project.class, vncDomain, name) == null) {
+                 fail("create project failed in vnc");
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("Exception while creating a project in vnc");
+        }
+    }
+
+    public void deleteProject(String name) {
+        BaseCmd cmd = new DeleteProjectCmd();
+        BaseCmd proxy = ComponentContext.inject(cmd);
+
+        ProjectVO project = _projectDao.findByNameAndDomain(name, Domain.ROOT_DOMAIN);
+        try {
+            ManagementServerMock.setParameter(proxy, "id", BaseCmd.CommandType.LONG, project.getId());
+            ((DeleteProjectCmd)proxy).execute();
+            if (_api.findById(net.juniper.contrail.api.types.Project.class, project.getUuid()) != null) {
+                 fail("unable to delete project in vnc");
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("Exception while deleting project");
+        }
+    }
+
+    @Test
+    public void testProject() {
+        createProject("test-project");
+        deleteProject("test-project");
+    }
+
+    @Test
+    public void dbSyncTest() {
+        Network network = lookupTestNetwork("test-db-only-net");
+        if (network == null) {
+            network = createTestNetwork("test-db-only-net");
+        }
+        UserVm vm = _server.createVM("test-db-only-vm", network);
+        try {
+            createFloatingIp(network, vm);
+        } catch (Exception e) {
+            fail("unable to create floating ip");
+        }
+
+        /* reset ApiServer objects to default config only, so above created objects 
+         * exists only in cludstack db but not in api server
+         */
+        ((ApiConnectorMock)_api).initConfig();
+        /* reset model cached objects */
+        _contrailMgr.getDatabase().initDb();
+
+        /* Create one object of each type directly in api-server - these objects does not exist in cloudstack */
+        net.juniper.contrail.api.types.Domain domain = new net.juniper.contrail.api.types.Domain();
+        domain.setName("test-vnc-only-domain--1");
+        domain.setUuid(UUID.randomUUID().toString());
+        try {
+            assertTrue(_api.create(domain));
+        } catch (IOException ex) {
+            fail(ex.getMessage());
+        }
+
+        Project project = new Project();
+        project.setName("test-vnc-only-project-1");
+        project.setUuid(UUID.randomUUID().toString());
+        project.setParent(domain);
+        try {
+            assertTrue(_api.create(project));
+        } catch (IOException ex) {
+            fail(ex.getMessage());
+        }
+
+        VirtualNetwork net = new VirtualNetwork();
+        net.setName("test-vnc-only-net-1");
+        net.setUuid(UUID.randomUUID().toString());
+        net.setParent(project);
+        
+        NetworkIpam ipam = null;
+        try {
+            // Find default-network-ipam
+            String ipam_id = _api.findByName(NetworkIpam.class, null, "default-network-ipam");
+            assertNotNull(ipam_id);
+            ipam = (NetworkIpam) _api.findById(NetworkIpam.class, ipam_id);
+            assertNotNull(ipam);
+        } catch (IOException ex) {
+            fail(ex.getMessage());
+        }
+
+        VnSubnetsType subnet = new VnSubnetsType();
+        subnet.addIpamSubnets(new SubnetType("10.0.2.0", 24), "10.0.2.254");
+
+        net.addNetworkIpam(ipam, subnet);
+
+        VirtualMachine vncVm = new VirtualMachine();
+        vncVm.setName("test-vnc-only-vm-1");
+        try {
+            assertTrue(_api.create(vncVm));
+        } catch (IOException ex) {
+            fail(ex.getMessage());
+        }
+
+        VirtualMachineInterface vmi = new VirtualMachineInterface();
+        vmi.setParent(vncVm);
+        vmi.setName("test-vnc-only-vmi-1");
+
+        try {
+            assertTrue(_api.create(vmi));
+            assertTrue(_api.create(net));
+        } catch (IOException ex) {
+            fail(ex.getMessage());
+        }
+        InstanceIp ip_obj = new InstanceIp();
+        ip_obj.setName(net.getName() + ":0");
+        ip_obj.setVirtualNetwork(net);
+        ip_obj.setVirtualMachineInterface(vmi);
+        try {
+            assertTrue(_api.create(ip_obj));
+            // Must perform a GET in order to update the object contents.
+            assertTrue(_api.read(ip_obj));
+            assertNotNull(ip_obj.getAddress());
+
+        } catch (IOException ex) {
+            fail(ex.getMessage());
+        }
+        
+        //now db sync
+        if (_dbSync.syncAll(DBSyncGeneric.SYNC_MODE_UPDATE) == ServerDBSync.SYNC_STATE_OUT_OF_SYNC) {
+            s_logger.info("# Cloudstack DB & VNC are out of sync - resync done");
+        }
+        
+        if (_dbSync.syncAll(DBSyncGeneric.SYNC_MODE_CHECK) == ServerDBSync.SYNC_STATE_OUT_OF_SYNC) {
+            s_logger.info("# Cloudstack DB & VNC are still out of sync");
+            fail("DB Sync failed"); 
+        }
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6b5fab2f/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/ProviderTestConfiguration.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/ProviderTestConfiguration.java b/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/ProviderTestConfiguration.java
new file mode 100644
index 0000000..818d6a0
--- /dev/null
+++ b/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/ProviderTestConfiguration.java
@@ -0,0 +1,12 @@
+package org.apache.cloudstack.network.contrail.management;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class ProviderTestConfiguration {
+	@Bean
+	ServerDBSync getServerDBSync() {
+		return new ServerDBSyncImpl();
+	}
+}


Mime
View raw message