vpc,event: fix events for createVpc (#9055)

Fixes #8496

* vpc,event: fix events for createVpc
This commit is contained in:
Abhishek Kumar 2024-06-12 12:56:08 +05:30 committed by GitHub
parent edf7394919
commit ca59720015
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 16 additions and 8 deletions

View File

@ -132,6 +132,8 @@ public interface VpcService {
*/
boolean startVpc(long vpcId, boolean destroyOnFailure) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException;
void startVpc(CreateVPCCmd cmd) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException;
/**
* Shuts down the VPC which includes shutting down all VPC provider and rules cleanup on the backend
*

View File

@ -210,11 +210,7 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd implements UserCmd {
public void execute() {
Vpc vpc = null;
try {
if (isStart()) {
_vpcService.startVpc(getEntityId(), true);
} else {
s_logger.debug("Not starting VPC as " + ApiConstants.START + "=false was passed to the API");
}
_vpcService.startVpc(this);
vpc = _entityMgr.findById(Vpc.class, getEntityId());
} catch (ResourceUnavailableException ex) {
s_logger.warn("Exception: ", ex);

View File

@ -167,17 +167,16 @@ public class CreateVPCCmdTest extends TestCase {
@Test
public void testExecute() throws ResourceUnavailableException, InsufficientCapacityException {
ReflectionTestUtils.setField(cmd, "start", true);
Vpc vpc = Mockito.mock(Vpc.class);
VpcResponse response = Mockito.mock(VpcResponse.class);
ReflectionTestUtils.setField(cmd, "id", 1L);
responseGenerator = Mockito.mock(ResponseGenerator.class);
Mockito.when(_vpcService.startVpc(1L, true)).thenReturn(true);
Mockito.doNothing().when(_vpcService).startVpc(cmd);
Mockito.when(_entityMgr.findById(Mockito.eq(Vpc.class), Mockito.any(Long.class))).thenReturn(vpc);
cmd._responseGenerator = responseGenerator;
Mockito.when(responseGenerator.createVpcResponse(ResponseObject.ResponseView.Restricted, vpc)).thenReturn(response);
cmd.execute();
Mockito.verify(_vpcService, Mockito.times(1)).startVpc(Mockito.anyLong(), Mockito.anyBoolean());
Mockito.verify(_vpcService, Mockito.times(1)).startVpc(cmd);
}
}

View File

@ -1677,6 +1677,17 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
return result;
}
@Override
@ActionEvent(eventType = EventTypes.EVENT_VPC_CREATE, eventDescription = "creating vpc", async = true)
public void startVpc(final CreateVPCCmd cmd) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
if (!cmd.isStart()) {
s_logger.debug("Not starting VPC as " + ApiConstants.START + "=false was passed to the API");
return;
}
startVpc(cmd.getEntityId(), true);
}
protected boolean startVpc(final Vpc vpc, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException,
InsufficientCapacityException {
// deploy provider