use of com.cloud.dc.DataCenter in project cloudstack by apache.
the class IntegrationTestConfiguration method entityManager.
@Bean
public EntityManager entityManager() {
EntityManager mock = Mockito.mock(EntityManager.class);
try {
Mockito.when(mock.findById(Matchers.same(Account.class), Matchers.anyLong())).thenReturn(_accountDao.findById(Account.ACCOUNT_ID_SYSTEM));
Mockito.when(mock.findById(Matchers.same(User.class), Matchers.anyLong())).thenReturn(_userDao.findById(User.UID_SYSTEM));
Mockito.when(mock.findById(Matchers.same(NetworkOffering.class), Matchers.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(Matchers.same(IpAddress.class), Matchers.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(Matchers.same(DataCenter.class), Matchers.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;
}
use of com.cloud.dc.DataCenter in project cloudstack by apache.
the class NetworkProviderTest method purgeTestNetwork.
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(), false);
}
}
use of com.cloud.dc.DataCenter in project cloudstack by apache.
the class NetworkProviderTest method createFloatingIp.
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);
}
use of com.cloud.dc.DataCenter in project cloudstack by apache.
the class VxlanGuestNetworkGuruTest method testImplement.
@Test
public void testImplement() throws InsufficientVirtualNetworkCapacityException {
PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
when(physnetdao.findById(anyLong())).thenReturn(physnet);
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "VXLAN" }));
when(physnet.getId()).thenReturn(42L);
NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(42L);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
NetworkVO network = mock(NetworkVO.class);
when(network.getName()).thenReturn("testnetwork");
when(network.getState()).thenReturn(State.Implementing);
when(network.getPhysicalNetworkId()).thenReturn(42L);
DeployDestination dest = mock(DeployDestination.class);
DataCenter dc = mock(DataCenter.class);
when(dest.getDataCenter()).thenReturn(dc);
when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(42L);
//TODO(VXLAN): doesn't support VNI specified
//when(confsvr.getConfigValue((String) any(), (String) any(), anyLong())).thenReturn("true");
when(dcdao.allocateVnet(anyLong(), anyLong(), anyLong(), (String) any(), eq(true))).thenReturn("42");
doNothing().when(guru).allocateVnetComplete((Network) any(), (NetworkVO) any(), anyLong(), anyLong(), (String) any(), eq("42"));
Domain dom = mock(Domain.class);
when(dom.getName()).thenReturn("domain");
Account acc = mock(Account.class);
when(acc.getAccountName()).thenReturn("accountname");
ReservationContext res = mock(ReservationContext.class);
when(res.getDomain()).thenReturn(dom);
when(res.getAccount()).thenReturn(acc);
Network implementednetwork = guru.implement(network, offering, dest, res);
assertTrue(implementednetwork != null);
}
use of com.cloud.dc.DataCenter in project cloudstack by apache.
the class NetscalerElement method canHandle.
private boolean canHandle(Network config, Service service) {
DataCenter zone = _dcDao.findById(config.getDataCenterId());
boolean handleInAdvanceZone = (zone.getNetworkType() == NetworkType.Advanced && (config.getGuestType() == Network.GuestType.Isolated || config.getGuestType() == Network.GuestType.Shared) && config.getTrafficType() == TrafficType.Guest);
boolean handleInBasicZone = (zone.getNetworkType() == NetworkType.Basic && config.getGuestType() == Network.GuestType.Shared && config.getTrafficType() == TrafficType.Guest);
if (!(handleInAdvanceZone || handleInBasicZone)) {
s_logger.trace("Not handling network with Type " + config.getGuestType() + " and traffic type " + config.getTrafficType() + " in zone of type " + zone.getNetworkType());
return false;
}
return (_networkManager.isProviderForNetwork(getProvider(), config.getId()) && _ntwkSrvcDao.canProviderSupportServiceInNetwork(config.getId(), service, Network.Provider.Netscaler));
}
Aggregations