Skip to content

Commit eff7587

Browse files
author
Alena Prokharchyk
committed
InternalLB: allow domain admin to stop/start internal lb vms
1 parent 10380ce commit eff7587

4 files changed

Lines changed: 30 additions & 28 deletions

File tree

‎client/tomcatconf/commands.properties.in‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,9 +603,9 @@ listLoadBalancers=15
603603
deleteLoadBalancer=15
604604

605605
#Internal Load Balancer Element commands
606-
configureInternalLoadBalancerElement=1
607-
createInternalLoadBalancerElement=1
608-
listInternalLoadBalancerElements=1
606+
configureInternalLoadBalancerElement=7
607+
createInternalLoadBalancerElement=7
608+
listInternalLoadBalancerElements=7
609609

610610

611611
#### Affinity group commands

‎plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
import com.cloud.vm.dao.DomainRouterDao;
118118
import com.cloud.vm.dao.NicDao;
119119

120+
120121
@Component
121122
@Local(value = { InternalLoadBalancerVMManager.class, InternalLoadBalancerVMService.class})
122123
public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements
@@ -543,12 +544,15 @@ public boolean destroyInternalLbVm(long vmId, Account caller, Long callerUserId)
543544

544545
@Override
545546
public VirtualRouter stopInternalLbVm(long vmId, boolean forced, Account caller, long callerUserId) throws ConcurrentOperationException,
546-
ResourceUnavailableException {
547+
ResourceUnavailableException {
547548
DomainRouterVO internalLbVm = _internalLbVmDao.findById(vmId);
548549
if (internalLbVm == null || internalLbVm.getRole() != Role.INTERNAL_LB_VM) {
549550
throw new InvalidParameterValueException("Can't find internal lb vm by id specified");
550551
}
551552

553+
//check permissions
554+
_accountMgr.checkAccess(caller, null, true, internalLbVm);
555+
552556
return stopInternalLbVm(internalLbVm, forced, caller, callerUserId);
553557
}
554558

@@ -946,6 +950,9 @@ public VirtualRouter startInternalLbVm(long internalLbVmId, Account caller, long
946950
throw new InvalidParameterValueException("Can't find internal lb vm by id specified");
947951
}
948952

953+
//check permissions
954+
_accountMgr.checkAccess(caller, null, true, internalLbVm);
955+
949956
return startInternalLbVm(internalLbVm, caller, callerUserId, null);
950957
}
951958
}

‎plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvmmgr/InternalLBVMServiceTest.java‎

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,15 @@
4747
import com.cloud.user.AccountManager;
4848
import com.cloud.user.AccountVO;
4949
import com.cloud.user.User;
50+
import com.cloud.user.UserVO;
5051
import com.cloud.utils.component.ComponentContext;
5152
import com.cloud.vm.DomainRouterVO;
5253
import com.cloud.vm.VirtualMachine;
5354
import com.cloud.vm.VirtualMachineManager;
5455
import com.cloud.vm.dao.DomainRouterDao;
56+
import com.cloud.user.UserContext;
57+
import com.cloud.user.dao.AccountDao;
58+
5559

5660
/**
5761
* Set of unittests for InternalLoadBalancerVMService
@@ -70,6 +74,7 @@ public class InternalLBVMServiceTest extends TestCase {
7074
@Inject ServiceOfferingDao _svcOffDao;
7175
@Inject DomainRouterDao _domainRouterDao;
7276
@Inject VirtualMachineManager _itMgr;
77+
@Inject AccountDao _accountDao;
7378

7479
long validVmId = 1L;
7580
long nonExistingVmId = 2L;
@@ -86,6 +91,12 @@ public void setUp() {
8691

8792
ComponentContext.initComponentsLifeCycle();
8893

94+
Mockito.when(_accountMgr.getSystemUser()).thenReturn(new UserVO(1));
95+
Mockito.when(_accountMgr.getSystemAccount()).thenReturn(new AccountVO(2));
96+
Mockito.when(_accountDao.findByIdIncludingRemoved(Mockito.anyLong())).thenReturn(new AccountVO(2));
97+
UserContext.registerContext(_accountMgr.getSystemUser().getId(), _accountMgr.getSystemAccount(), null, false);
98+
99+
89100
DomainRouterVO validVm = new DomainRouterVO(validVmId,off.getId(),1,"alena",1,HypervisorType.XenServer,1,1,1,
90101
false, 0,false,null,false,false,
91102
VirtualMachine.Type.InternalLoadBalancerVm, null);
@@ -145,12 +156,6 @@ public void startNonExistingVm() {
145156
} catch (ResourceUnavailableException e) {
146157
// TODO Auto-generated catch block
147158
e.printStackTrace();
148-
} catch (InvalidParameterValueException e) {
149-
expectedExcText = e.getMessage();
150-
throw e;
151-
} finally {
152-
assertEquals("Test failed. The non-existing internal lb vm was attempted to start"
153-
+ expectedExcText, expectedExcText, "Can't find internal lb vm by id specified");
154159
}
155160
}
156161

@@ -171,12 +176,6 @@ public void startNonInternalLbVmVm() {
171176
} catch (ResourceUnavailableException e) {
172177
// TODO Auto-generated catch block
173178
e.printStackTrace();
174-
}catch (InvalidParameterValueException e) {
175-
expectedExcText = e.getMessage();
176-
throw e;
177-
} finally {
178-
assertEquals("Test failed. The existing vm of not Internal lb vm type was attempted to start"
179-
+ expectedExcText, expectedExcText, "Can't find internal lb vm by id specified");
180179
}
181180
}
182181

@@ -218,12 +217,6 @@ public void stopNonExistingVm() {
218217
} catch (ResourceUnavailableException e) {
219218
// TODO Auto-generated catch block
220219
e.printStackTrace();
221-
} catch (InvalidParameterValueException e) {
222-
expectedExcText = e.getMessage();
223-
throw e;
224-
} finally {
225-
assertEquals("Test failed. The non-existing internal lb vm was attempted to stop"
226-
+ expectedExcText, expectedExcText, "Can't find internal lb vm by id specified");
227220
}
228221
}
229222

@@ -242,12 +235,6 @@ public void stopNonInternalLbVmVm() {
242235
} catch (ResourceUnavailableException e) {
243236
// TODO Auto-generated catch block
244237
e.printStackTrace();
245-
}catch (InvalidParameterValueException e) {
246-
expectedExcText = e.getMessage();
247-
throw e;
248-
} finally {
249-
assertEquals("Test failed. The existing vm of not Internal lb vm type was attempted to stop"
250-
+ expectedExcText, expectedExcText, "Can't find internal lb vm by id specified");
251238
}
252239
}
253240

‎plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvmmgr/LbChildTestConfiguration.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import com.cloud.vm.VirtualMachineManager;
5151
import com.cloud.vm.dao.DomainRouterDao;
5252
import com.cloud.vm.dao.NicDao;
53+
import com.cloud.user.dao.AccountDao;
5354

5455

5556
@Configuration
@@ -161,6 +162,13 @@ public ConfigurationServer configurationServer() {
161162
return Mockito.mock(ConfigurationServer.class);
162163
}
163164

165+
@Bean
166+
public AccountDao accountDao() {
167+
return Mockito.mock(AccountDao.class);
168+
}
169+
170+
171+
164172
@Override
165173
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
166174
mdr.getClassMetadata().getClassName();

0 commit comments

Comments
 (0)