mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
InternalLB: allow domain admin to stop/start internal lb vms
This commit is contained in:
parent
10380cea41
commit
eff7587d51
@ -603,9 +603,9 @@ listLoadBalancers=15
|
||||
deleteLoadBalancer=15
|
||||
|
||||
#Internal Load Balancer Element commands
|
||||
configureInternalLoadBalancerElement=1
|
||||
createInternalLoadBalancerElement=1
|
||||
listInternalLoadBalancerElements=1
|
||||
configureInternalLoadBalancerElement=7
|
||||
createInternalLoadBalancerElement=7
|
||||
listInternalLoadBalancerElements=7
|
||||
|
||||
|
||||
#### Affinity group commands
|
||||
|
||||
@ -117,6 +117,7 @@ import com.cloud.vm.VirtualMachineProfile.Param;
|
||||
import com.cloud.vm.dao.DomainRouterDao;
|
||||
import com.cloud.vm.dao.NicDao;
|
||||
|
||||
|
||||
@Component
|
||||
@Local(value = { InternalLoadBalancerVMManager.class, InternalLoadBalancerVMService.class})
|
||||
public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements
|
||||
@ -543,12 +544,15 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements
|
||||
|
||||
@Override
|
||||
public VirtualRouter stopInternalLbVm(long vmId, boolean forced, Account caller, long callerUserId) throws ConcurrentOperationException,
|
||||
ResourceUnavailableException {
|
||||
ResourceUnavailableException {
|
||||
DomainRouterVO internalLbVm = _internalLbVmDao.findById(vmId);
|
||||
if (internalLbVm == null || internalLbVm.getRole() != Role.INTERNAL_LB_VM) {
|
||||
throw new InvalidParameterValueException("Can't find internal lb vm by id specified");
|
||||
}
|
||||
|
||||
//check permissions
|
||||
_accountMgr.checkAccess(caller, null, true, internalLbVm);
|
||||
|
||||
return stopInternalLbVm(internalLbVm, forced, caller, callerUserId);
|
||||
}
|
||||
|
||||
@ -946,6 +950,9 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements
|
||||
throw new InvalidParameterValueException("Can't find internal lb vm by id specified");
|
||||
}
|
||||
|
||||
//check permissions
|
||||
_accountMgr.checkAccess(caller, null, true, internalLbVm);
|
||||
|
||||
return startInternalLbVm(internalLbVm, caller, callerUserId, null);
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,11 +47,15 @@ import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountManager;
|
||||
import com.cloud.user.AccountVO;
|
||||
import com.cloud.user.User;
|
||||
import com.cloud.user.UserVO;
|
||||
import com.cloud.utils.component.ComponentContext;
|
||||
import com.cloud.vm.DomainRouterVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachineManager;
|
||||
import com.cloud.vm.dao.DomainRouterDao;
|
||||
import com.cloud.user.UserContext;
|
||||
import com.cloud.user.dao.AccountDao;
|
||||
|
||||
|
||||
/**
|
||||
* Set of unittests for InternalLoadBalancerVMService
|
||||
@ -70,6 +74,7 @@ public class InternalLBVMServiceTest extends TestCase {
|
||||
@Inject ServiceOfferingDao _svcOffDao;
|
||||
@Inject DomainRouterDao _domainRouterDao;
|
||||
@Inject VirtualMachineManager _itMgr;
|
||||
@Inject AccountDao _accountDao;
|
||||
|
||||
long validVmId = 1L;
|
||||
long nonExistingVmId = 2L;
|
||||
@ -86,6 +91,12 @@ public class InternalLBVMServiceTest extends TestCase {
|
||||
|
||||
ComponentContext.initComponentsLifeCycle();
|
||||
|
||||
Mockito.when(_accountMgr.getSystemUser()).thenReturn(new UserVO(1));
|
||||
Mockito.when(_accountMgr.getSystemAccount()).thenReturn(new AccountVO(2));
|
||||
Mockito.when(_accountDao.findByIdIncludingRemoved(Mockito.anyLong())).thenReturn(new AccountVO(2));
|
||||
UserContext.registerContext(_accountMgr.getSystemUser().getId(), _accountMgr.getSystemAccount(), null, false);
|
||||
|
||||
|
||||
DomainRouterVO validVm = new DomainRouterVO(validVmId,off.getId(),1,"alena",1,HypervisorType.XenServer,1,1,1,
|
||||
false, 0,false,null,false,false,
|
||||
VirtualMachine.Type.InternalLoadBalancerVm, null);
|
||||
@ -145,12 +156,6 @@ public class InternalLBVMServiceTest extends TestCase {
|
||||
} catch (ResourceUnavailableException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (InvalidParameterValueException e) {
|
||||
expectedExcText = e.getMessage();
|
||||
throw e;
|
||||
} finally {
|
||||
assertEquals("Test failed. The non-existing internal lb vm was attempted to start"
|
||||
+ expectedExcText, expectedExcText, "Can't find internal lb vm by id specified");
|
||||
}
|
||||
}
|
||||
|
||||
@ -171,12 +176,6 @@ public class InternalLBVMServiceTest extends TestCase {
|
||||
} catch (ResourceUnavailableException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}catch (InvalidParameterValueException e) {
|
||||
expectedExcText = e.getMessage();
|
||||
throw e;
|
||||
} finally {
|
||||
assertEquals("Test failed. The existing vm of not Internal lb vm type was attempted to start"
|
||||
+ expectedExcText, expectedExcText, "Can't find internal lb vm by id specified");
|
||||
}
|
||||
}
|
||||
|
||||
@ -218,12 +217,6 @@ public class InternalLBVMServiceTest extends TestCase {
|
||||
} catch (ResourceUnavailableException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (InvalidParameterValueException e) {
|
||||
expectedExcText = e.getMessage();
|
||||
throw e;
|
||||
} finally {
|
||||
assertEquals("Test failed. The non-existing internal lb vm was attempted to stop"
|
||||
+ expectedExcText, expectedExcText, "Can't find internal lb vm by id specified");
|
||||
}
|
||||
}
|
||||
|
||||
@ -242,12 +235,6 @@ public class InternalLBVMServiceTest extends TestCase {
|
||||
} catch (ResourceUnavailableException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}catch (InvalidParameterValueException e) {
|
||||
expectedExcText = e.getMessage();
|
||||
throw e;
|
||||
} finally {
|
||||
assertEquals("Test failed. The existing vm of not Internal lb vm type was attempted to stop"
|
||||
+ expectedExcText, expectedExcText, "Can't find internal lb vm by id specified");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -50,6 +50,7 @@ import com.cloud.utils.net.NetUtils;
|
||||
import com.cloud.vm.VirtualMachineManager;
|
||||
import com.cloud.vm.dao.DomainRouterDao;
|
||||
import com.cloud.vm.dao.NicDao;
|
||||
import com.cloud.user.dao.AccountDao;
|
||||
|
||||
|
||||
@Configuration
|
||||
@ -161,6 +162,13 @@ import com.cloud.vm.dao.NicDao;
|
||||
return Mockito.mock(ConfigurationServer.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AccountDao accountDao() {
|
||||
return Mockito.mock(AccountDao.class);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
|
||||
mdr.getClassMetadata().getClassName();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user