Search in sources :

Example 46 with TransactionLegacy

use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.

the class DedicateGuestVlanRangesTest method runDedicateGuestVlanRangeInvalidFormat.

void runDedicateGuestVlanRangeInvalidFormat() throws Exception {
    TransactionLegacy txn = TransactionLegacy.open("runDedicateGuestVlanRangeInvalidFormat");
    Field dedicateVlanField = _dedicateGuestVlanRangeClass.getDeclaredField("vlan");
    dedicateVlanField.setAccessible(true);
    dedicateVlanField.set(dedicateGuestVlanRangesCmd, "2");
    PhysicalNetworkVO physicalNetwork = new PhysicalNetworkVO(1L, 1L, "2-5", "200", 1L, null, "testphysicalnetwork");
    physicalNetwork.addIsolationMethod("VLAN");
    when(networkService._physicalNetworkDao.findById(anyLong())).thenReturn(physicalNetwork);
    try {
        networkService.dedicateGuestVlanRange(dedicateGuestVlanRangesCmd);
    } catch (Exception e) {
        Assert.assertTrue(e.getMessage().contains("Invalid format for parameter value vlan"));
    } finally {
        txn.close("runDedicateGuestVlanRangeInvalidFormat");
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) Field(java.lang.reflect.Field) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO)

Example 47 with TransactionLegacy

use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.

the class DedicateGuestVlanRangesTest method runDedicateGuestVlanRangeDedicatedRange.

void runDedicateGuestVlanRangeDedicatedRange() throws Exception {
    TransactionLegacy txn = TransactionLegacy.open("runDedicateGuestVlanRangeDedicatedRange");
    Field dedicateVlanField = _dedicateGuestVlanRangeClass.getDeclaredField("vlan");
    dedicateVlanField.setAccessible(true);
    dedicateVlanField.set(dedicateGuestVlanRangesCmd, "2-5");
    PhysicalNetworkVO physicalNetwork = new PhysicalNetworkVO(1L, 1L, "2-5", "200", 1L, null, "testphysicalnetwork");
    physicalNetwork.addIsolationMethod("VLAN");
    when(networkService._physicalNetworkDao.findById(anyLong())).thenReturn(physicalNetwork);
    when(networkService._datacneterVnet.listAllocatedVnetsInRange(anyLong(), anyLong(), anyInt(), anyInt())).thenReturn(null);
    List<AccountGuestVlanMapVO> guestVlanMaps = new ArrayList<AccountGuestVlanMapVO>();
    AccountGuestVlanMapVO accountGuestVlanMap = new AccountGuestVlanMapVO(1L, 1L);
    accountGuestVlanMap.setGuestVlanRange("2-5");
    guestVlanMaps.add(accountGuestVlanMap);
    when(networkService._accountGuestVlanMapDao.listAccountGuestVlanMapsByPhysicalNetwork(anyLong())).thenReturn(guestVlanMaps);
    try {
        networkService.dedicateGuestVlanRange(dedicateGuestVlanRangesCmd);
    } catch (Exception e) {
        Assert.assertTrue(e.getMessage().contains("Vlan range is already dedicated"));
    } finally {
        txn.close("runDedicateGuestVlanRangeDedicatedRange");
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) Field(java.lang.reflect.Field) AccountGuestVlanMapVO(com.cloud.network.dao.AccountGuestVlanMapVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ArrayList(java.util.ArrayList)

Example 48 with TransactionLegacy

use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.

the class DedicateGuestVlanRangesTest method runDedicateGuestVlanRangeInvalidRangeValue.

void runDedicateGuestVlanRangeInvalidRangeValue() throws Exception {
    TransactionLegacy txn = TransactionLegacy.open("runDedicateGuestVlanRangeInvalidRangeValue");
    Field dedicateVlanField = _dedicateGuestVlanRangeClass.getDeclaredField("vlan");
    dedicateVlanField.setAccessible(true);
    dedicateVlanField.set(dedicateGuestVlanRangesCmd, "2-5");
    PhysicalNetworkVO physicalNetwork = new PhysicalNetworkVO(1L, 1L, "6-10", "200", 1L, null, "testphysicalnetwork");
    physicalNetwork.addIsolationMethod("VLAN");
    when(networkService._physicalNetworkDao.findById(anyLong())).thenReturn(physicalNetwork);
    try {
        networkService.dedicateGuestVlanRange(dedicateGuestVlanRangesCmd);
    } catch (Exception e) {
        Assert.assertTrue(e.getMessage().contains("Unable to find guest vlan by range"));
    } finally {
        txn.close("runDedicateGuestVlanRangeInvalidRangeValue");
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) Field(java.lang.reflect.Field) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO)

Example 49 with TransactionLegacy

use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.

the class DedicateGuestVlanRangesTest method runDedicateGuestVlanRangeAllocatedVlans.

void runDedicateGuestVlanRangeAllocatedVlans() throws Exception {
    TransactionLegacy txn = TransactionLegacy.open("runDedicateGuestVlanRangeAllocatedVlans");
    Field dedicateVlanField = _dedicateGuestVlanRangeClass.getDeclaredField("vlan");
    dedicateVlanField.setAccessible(true);
    dedicateVlanField.set(dedicateGuestVlanRangesCmd, "2-5");
    PhysicalNetworkVO physicalNetwork = new PhysicalNetworkVO(1L, 1L, "2-5", "200", 1L, null, "testphysicalnetwork");
    physicalNetwork.addIsolationMethod("VLAN");
    when(networkService._physicalNetworkDao.findById(anyLong())).thenReturn(physicalNetwork);
    List<DataCenterVnetVO> dataCenterList = new ArrayList<DataCenterVnetVO>();
    DataCenterVnetVO dataCenter = new DataCenterVnetVO("2-5", 1L, 1L);
    dataCenter.setAccountId(1L);
    dataCenterList.add(dataCenter);
    when(networkService._datacneterVnet.listAllocatedVnetsInRange(anyLong(), anyLong(), anyInt(), anyInt())).thenReturn(dataCenterList);
    try {
        networkService.dedicateGuestVlanRange(dedicateGuestVlanRangesCmd);
    } catch (Exception e) {
        Assert.assertTrue(e.getMessage().contains("is allocated to a different account"));
    } finally {
        txn.close("runDedicateGuestVlanRangeAllocatedVlans");
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) Field(java.lang.reflect.Field) DataCenterVnetVO(com.cloud.dc.DataCenterVnetVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ArrayList(java.util.ArrayList)

Example 50 with TransactionLegacy

use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.

the class ConfigurationManagerTest method runDedicatePublicIpRangePostiveTest.

void runDedicatePublicIpRangePostiveTest() throws Exception {
    TransactionLegacy txn = TransactionLegacy.open("runDedicatePublicIpRangePostiveTest");
    when(configurationMgr._vlanDao.findById(anyLong())).thenReturn(vlan);
    when(configurationMgr._accountVlanMapDao.listAccountVlanMapsByAccount(anyLong())).thenReturn(null);
    DataCenterVO dc = new DataCenterVO(UUID.randomUUID().toString(), "test", "8.8.8.8", null, "10.0.0.1", null, "10.0.0.1/24", null, null, NetworkType.Advanced, null, null, true, true, null, null);
    when(configurationMgr._zoneDao.findById(anyLong())).thenReturn(dc);
    List<IPAddressVO> ipAddressList = new ArrayList<IPAddressVO>();
    IPAddressVO ipAddress = new IPAddressVO(new Ip("75.75.75.75"), 1, 0xaabbccddeeffL, 10, false);
    ipAddressList.add(ipAddress);
    when(configurationMgr._publicIpAddressDao.listByVlanId(anyLong())).thenReturn(ipAddressList);
    try {
        Vlan result = configurationMgr.dedicatePublicIpRange(dedicatePublicIpRangesCmd);
        Assert.assertNotNull(result);
    } catch (Exception e) {
        s_logger.info("exception in testing runDedicatePublicIpRangePostiveTest message: " + e.toString());
    } finally {
        txn.close("runDedicatePublicIpRangePostiveTest");
    }
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) Ip(com.cloud.utils.net.Ip) ArrayList(java.util.ArrayList) IPAddressVO(com.cloud.network.dao.IPAddressVO) Vlan(com.cloud.dc.Vlan) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Aggregations

TransactionLegacy (com.cloud.utils.db.TransactionLegacy)368 PreparedStatement (java.sql.PreparedStatement)174 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)149 SQLException (java.sql.SQLException)133 ResultSet (java.sql.ResultSet)102 ArrayList (java.util.ArrayList)98 DB (com.cloud.utils.db.DB)95 ConfigurationException (javax.naming.ConfigurationException)54 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)35 Date (java.util.Date)34 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)31 HashMap (java.util.HashMap)29 URISyntaxException (java.net.URISyntaxException)28 AccountVO (com.cloud.user.AccountVO)21 CloudException (com.cloud.exception.CloudException)20 Account (com.cloud.user.Account)20 Field (java.lang.reflect.Field)19 MockVolumeVO (com.cloud.simulator.MockVolumeVO)18 AgentManager (com.cloud.agent.AgentManager)13 IPAddressDao (com.cloud.network.dao.IPAddressDao)13