use of com.cloud.user.Account in project cosmic by MissionCriticalCloud.
the class CreatePrivateNetworkTest method setup.
@Before
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
networkService._accountMgr = _accountMgr;
networkService._networkOfferingDao = _networkOfferingDao;
networkService._physicalNetworkDao = _physicalNetworkDao;
networkService._dcDao = _dcDao;
networkService._networksDao = _networkDao;
networkService._networkMgr = _networkMgr;
networkService._privateIpDao = _privateIpDao;
final Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
when(networkService._accountMgr.getAccount(anyLong())).thenReturn(account);
final NetworkOfferingVO ntwkOff = new NetworkOfferingVO("offer", "fakeOffer", TrafficType.Guest, true, true, null, null, false, null, null, GuestType.Isolated, false, false, false, false, false, false, false, false, false, false, false, false, false);
when(networkService._networkOfferingDao.findById(anyLong())).thenReturn(ntwkOff);
final List<NetworkOfferingVO> netofferlist = new ArrayList<>();
netofferlist.add(ntwkOff);
when(networkService._networkOfferingDao.listSystemNetworkOfferings()).thenReturn(netofferlist);
final PhysicalNetworkVO physicalNetwork = new PhysicalNetworkVO(1L, 1L, "2-5", "200", 1L, null, "testphysicalnetwork");
when(networkService._physicalNetworkDao.findById(anyLong())).thenReturn(physicalNetwork);
final DataCenterVO dc = new DataCenterVO(1L, "DC", "Datacenter", "1.2.3.4", null, null, null, "10.1.1.0/24", "unreal.net", 1L, NetworkType.Advanced, null, null);
when(networkService._dcDao.lockRow(anyLong(), anyBoolean())).thenReturn(dc);
when(networkService._networksDao.getPrivateNetwork(anyString(), anyString(), eq(1L), eq(1L), anyLong())).thenReturn(null);
final Network net = new NetworkVO(1L, TrafficType.Guest, Mode.None, BroadcastDomainType.Vlan, 1L, 1L, 1L, 1L, "bla", "fake", "eet.net", GuestType.Isolated, 1L, 1L, ACLType.Account, false, 1L, false, "1.2.3.4", null, null);
when(networkService._networkMgr.createGuestNetwork(eq(ntwkOff.getId()), eq("bla"), eq("fake"), eq("10.1.1.1"), eq("10.1.1.0/24"), anyString(), anyString(), eq(account), anyLong(), eq(physicalNetwork), eq(physicalNetwork.getDataCenterId()), eq(ACLType.Account), anyBoolean(), eq(1L), anyString(), anyString(), anyBoolean(), anyString(), eq("1.2.3.4"), eq(null), eq(null))).thenReturn(net);
when(networkService._privateIpDao.findByIpAndSourceNetworkId(net.getId(), "10.1.1.2")).thenReturn(null);
when(networkService._privateIpDao.findByIpAndSourceNetworkIdAndVpcId(eq(1L), anyString(), eq(1L))).thenReturn(null);
}
use of com.cloud.user.Account in project cosmic by MissionCriticalCloud.
the class NetworkModelTest method testGetSourceNatIpAddressForGuestNetwork.
@Test
public void testGetSourceNatIpAddressForGuestNetwork() {
final IPAddressDao ipAddressDao = mock(IPAddressDao.class);
modelImpl._ipAddressDao = ipAddressDao;
final List<IPAddressVO> fakeList = new ArrayList<>();
final IPAddressVO fakeIp = new IPAddressVO(new Ip("75.75.75.75"), 1, 0xaabbccddeeffL, 10, false);
fakeList.add(fakeIp);
final SearchBuilder<IPAddressVO> fakeSearch = mock(SearchBuilder.class);
modelImpl.IpAddressSearch = fakeSearch;
final VlanDao fakeVlanDao = mock(VlanDao.class);
when(fakeVlanDao.findById(anyLong())).thenReturn(mock(VlanVO.class));
modelImpl._vlanDao = fakeVlanDao;
when(fakeSearch.create()).thenReturn(mock(SearchCriteria.class));
when(ipAddressDao.search(any(SearchCriteria.class), (Filter) org.mockito.Matchers.isNull())).thenReturn(fakeList);
when(ipAddressDao.findById(anyLong())).thenReturn(fakeIp);
final Account fakeAccount = mock(Account.class);
when(fakeAccount.getId()).thenReturn(1L);
final Network fakeNetwork = mock(Network.class);
when(fakeNetwork.getId()).thenReturn(1L);
PublicIpAddress answer = modelImpl.getSourceNatIpAddressForGuestNetwork(fakeAccount, fakeNetwork);
Assert.assertNull(answer);
final IPAddressVO fakeIp2 = new IPAddressVO(new Ip("76.75.75.75"), 1, 0xaabb10ddeeffL, 10, true);
fakeList.add(fakeIp2);
when(ipAddressDao.findById(anyLong())).thenReturn(fakeIp2);
answer = modelImpl.getSourceNatIpAddressForGuestNetwork(fakeAccount, fakeNetwork);
Assert.assertNotNull(answer);
Assert.assertEquals(answer.getAddress().addr(), "76.75.75.75");
}
use of com.cloud.user.Account in project cosmic by MissionCriticalCloud.
the class UserVmManagerTest method testMoveVmToUser1.
// Test Move VM b/w accounts where caller is not ROOT/Domain admin
@Test(expected = InvalidParameterValueException.class)
public void testMoveVmToUser1() throws Exception {
final AssignVMCmd cmd = new AssignVMCmd();
final Class<?> _class = cmd.getClass();
final Field virtualmachineIdField = _class.getDeclaredField("virtualMachineId");
virtualmachineIdField.setAccessible(true);
virtualmachineIdField.set(cmd, 1L);
final Field accountNameField = _class.getDeclaredField("accountName");
accountNameField.setAccessible(true);
accountNameField.set(cmd, "account");
final Field domainIdField = _class.getDeclaredField("domainId");
domainIdField.setAccessible(true);
domainIdField.set(cmd, 1L);
// caller is of type 0
final Account caller = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
final UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
CallContext.register(user, caller);
try {
_userVmMgr.moveVMToUser(cmd);
} finally {
CallContext.unregister();
}
}
use of com.cloud.user.Account in project cosmic by MissionCriticalCloud.
the class UserVmManagerTest method testUpdateVmNicIpSuccess1.
@Test
public void testUpdateVmNicIpSuccess1() throws Exception {
final UpdateVmNicIpCmd cmd = new UpdateVmNicIpCmd();
final Class<?> _class = cmd.getClass();
final Field virtualmachineIdField = _class.getDeclaredField("nicId");
virtualmachineIdField.setAccessible(true);
virtualmachineIdField.set(cmd, 1L);
final Field accountNameField = _class.getDeclaredField("ipAddr");
accountNameField.setAccessible(true);
accountNameField.set(cmd, "10.10.10.10");
final NicVO nic = new NicVO("nic", 1L, 2L, VirtualMachine.Type.User);
when(_nicDao.findById(anyLong())).thenReturn(nic);
when(_vmDao.findById(anyLong())).thenReturn(_vmMock);
when(_networkDao.findById(anyLong())).thenReturn(_networkMock);
doReturn(9L).when(_networkMock).getNetworkOfferingId();
when(_networkOfferingDao.findByIdIncludingRemoved(anyLong())).thenReturn(_networkOfferingMock);
doReturn(10L).when(_networkOfferingMock).getId();
final List<Service> services = new ArrayList<>();
services.add(Service.Dhcp);
when(_networkModel.listNetworkOfferingServices(anyLong())).thenReturn(services);
when(_vmMock.getState()).thenReturn(State.Stopped);
doNothing().when(_accountMgr).checkAccess(_account, null, true, _vmMock);
when(_accountDao.findByIdIncludingRemoved(anyLong())).thenReturn(_accountMock);
when(_networkMock.getState()).thenReturn(Network.State.Implemented);
when(_networkMock.getDataCenterId()).thenReturn(3L);
when(_networkMock.getGuestType()).thenReturn(GuestType.Isolated);
when(zoneRepository.findOne(anyLong())).thenReturn(zone);
when(zone.getNetworkType()).thenReturn(NetworkType.Advanced);
when(_ipAddrMgr.allocateGuestIP(Mockito.eq(_networkMock), anyString())).thenReturn("10.10.10.10");
doNothing().when(_networkMgr).implementNetworkElementsAndResources(Mockito.any(DeployDestination.class), Mockito.any(ReservationContext.class), Mockito.eq(_networkMock), Mockito.eq(_networkOfferingMock));
when(_nicDao.persist(any(NicVO.class))).thenReturn(nic);
final Account caller = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
final UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
CallContext.register(user, caller);
try {
_userVmMgr.updateNicIpForVirtualMachine(cmd);
} finally {
CallContext.unregister();
}
}
use of com.cloud.user.Account in project cosmic by MissionCriticalCloud.
the class UserVmManagerTest method testUpdateVmNicIpSuccess2.
@Test
public void testUpdateVmNicIpSuccess2() throws Exception {
final UpdateVmNicIpCmd cmd = new UpdateVmNicIpCmd();
final Class<?> _class = cmd.getClass();
final Field virtualmachineIdField = _class.getDeclaredField("nicId");
virtualmachineIdField.setAccessible(true);
virtualmachineIdField.set(cmd, 1L);
final Field accountNameField = _class.getDeclaredField("ipAddr");
accountNameField.setAccessible(true);
accountNameField.set(cmd, "10.10.10.10");
final NicVO nic = new NicVO("nic", 1L, 2L, VirtualMachine.Type.User);
when(_nicDao.findById(anyLong())).thenReturn(nic);
when(_vmDao.findById(anyLong())).thenReturn(_vmMock);
when(_networkDao.findById(anyLong())).thenReturn(_networkMock);
doReturn(9L).when(_networkMock).getNetworkOfferingId();
when(_networkOfferingDao.findByIdIncludingRemoved(anyLong())).thenReturn(_networkOfferingMock);
doReturn(10L).when(_networkOfferingMock).getId();
final List<Service> services = new ArrayList<>();
when(_networkModel.listNetworkOfferingServices(anyLong())).thenReturn(services);
when(_vmMock.getState()).thenReturn(State.Running);
doNothing().when(_accountMgr).checkAccess(_account, null, true, _vmMock);
when(_accountDao.findByIdIncludingRemoved(anyLong())).thenReturn(_accountMock);
when(_networkMock.getState()).thenReturn(Network.State.Implemented);
when(_networkMock.getDataCenterId()).thenReturn(3L);
when(_networkMock.getGuestType()).thenReturn(GuestType.Shared);
when(zoneRepository.findOne(anyLong())).thenReturn(zone);
when(zone.getNetworkType()).thenReturn(NetworkType.Advanced);
when(_ipAddrMgr.allocatePublicIpForGuestNic(Mockito.eq(_networkMock), anyLong(), Mockito.eq(_accountMock), anyString())).thenReturn("10.10.10.10");
when(_ipAddressDao.findByIpAndSourceNetworkId(anyLong(), anyString())).thenReturn(null);
when(_nicDao.persist(any(NicVO.class))).thenReturn(nic);
final Account caller = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
final UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
CallContext.register(user, caller);
try {
_userVmMgr.updateNicIpForVirtualMachine(cmd);
} finally {
CallContext.unregister();
}
}
Aggregations