Search in sources :

Example 51 with Account

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);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Account(com.cloud.user.Account) NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ArrayList(java.util.ArrayList) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) AccountVO(com.cloud.user.AccountVO) Before(org.junit.Before)

Example 52 with Account

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");
}
Also used : Account(com.cloud.user.Account) VlanDao(com.cloud.dc.dao.VlanDao) IPAddressDao(com.cloud.network.dao.IPAddressDao) Ip(com.cloud.utils.net.Ip) ArrayList(java.util.ArrayList) IPAddressVO(com.cloud.network.dao.IPAddressVO) VlanVO(com.cloud.dc.VlanVO) SearchCriteria(com.cloud.utils.db.SearchCriteria) Test(org.junit.Test)

Example 53 with Account

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();
    }
}
Also used : Field(java.lang.reflect.Field) Account(com.cloud.user.Account) UserVO(com.cloud.user.UserVO) AssignVMCmd(com.cloud.api.command.admin.vm.AssignVMCmd) AccountVO(com.cloud.user.AccountVO) Test(org.junit.Test)

Example 54 with Account

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();
    }
}
Also used : Field(java.lang.reflect.Field) Account(com.cloud.user.Account) UserVO(com.cloud.user.UserVO) DeployDestination(com.cloud.deploy.DeployDestination) ArrayList(java.util.ArrayList) AccountService(com.cloud.user.AccountService) ResourceLimitService(com.cloud.user.ResourceLimitService) Service(com.cloud.network.Network.Service) NetworkOrchestrationService(com.cloud.engine.orchestration.service.NetworkOrchestrationService) VolumeOrchestrationService(com.cloud.engine.orchestration.service.VolumeOrchestrationService) UpdateVmNicIpCmd(com.cloud.api.command.user.vm.UpdateVmNicIpCmd) AccountVO(com.cloud.user.AccountVO) Test(org.junit.Test)

Example 55 with Account

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();
    }
}
Also used : Field(java.lang.reflect.Field) Account(com.cloud.user.Account) UserVO(com.cloud.user.UserVO) ArrayList(java.util.ArrayList) AccountService(com.cloud.user.AccountService) ResourceLimitService(com.cloud.user.ResourceLimitService) Service(com.cloud.network.Network.Service) NetworkOrchestrationService(com.cloud.engine.orchestration.service.NetworkOrchestrationService) VolumeOrchestrationService(com.cloud.engine.orchestration.service.VolumeOrchestrationService) UpdateVmNicIpCmd(com.cloud.api.command.user.vm.UpdateVmNicIpCmd) AccountVO(com.cloud.user.AccountVO) Test(org.junit.Test)

Aggregations

Account (com.cloud.user.Account)1088 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)308 ArrayList (java.util.ArrayList)293 ActionEvent (com.cloud.event.ActionEvent)243 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)216 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)207 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)170 User (com.cloud.user.User)149 List (java.util.List)147 DB (com.cloud.utils.db.DB)130 Test (org.junit.Test)123 Pair (com.cloud.utils.Pair)115 AccountVO (com.cloud.user.AccountVO)113 Network (com.cloud.network.Network)104 Filter (com.cloud.utils.db.Filter)103 TransactionStatus (com.cloud.utils.db.TransactionStatus)95 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)94 DomainVO (com.cloud.domain.DomainVO)91 Domain (com.cloud.domain.Domain)87 UserVO (com.cloud.user.UserVO)86