Skip to content

Commit

Permalink
VNF: add cleanupnics to updateVnfTemplateCmd
Browse files Browse the repository at this point in the history
  • Loading branch information
weizhouapache committed Oct 11, 2023
1 parent f7800dc commit 0ed5089
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,7 @@ public class ApiConstants {
public static final String VNF_NICS = "vnfnics";
public static final String VNF_DETAILS = "vnfdetails";
public static final String CLEAN_UP_VNF_DETAILS = "cleanupvnfdetails";
public static final String CLEAN_UP_VNF_NICS = "cleanupvnfnics";

/**
* This enum specifies IO Drivers, each option controls specific policies on I/O.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,14 @@ public class UpdateVnfTemplateCmd extends UpdateTemplateCmd implements UserCmd {

@Parameter(name = ApiConstants.CLEAN_UP_VNF_DETAILS,
type = CommandType.BOOLEAN,
description = "optional boolean field, which indicates if VNF details should be cleaned up or not")
description = "optional boolean field, which indicates if VNF details will be cleaned up or not")
private Boolean cleanupVnfDetails = null;

@Parameter(name = ApiConstants.CLEAN_UP_VNF_NICS,
type = CommandType.BOOLEAN,
description = "optional boolean field, which indicates if VNF nics will be cleaned up or not")
private Boolean cleanupVnfNics = null;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand All @@ -75,4 +80,8 @@ public Map<String, String> getVnfDetails() {
public boolean isCleanupVnfDetails(){
return cleanupVnfDetails == null ? false : cleanupVnfDetails.booleanValue();
}

public boolean isCleanupVnfNics(){
return cleanupVnfNics == null ? false : cleanupVnfNics.booleanValue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,13 @@ private void updateVnfTemplateDetails(long templateId, UpdateVnfTemplateCmd cmd)
}

private void updateVnfTemplateNics(long templateId, UpdateVnfTemplateCmd cmd) {
List<VNF.VnfNic> nics = cmd.getVnfNics();
if (CollectionUtils.isEmpty(nics)) {
return;
boolean cleanupVnfNics = cmd.isCleanupVnfNics();
if (cleanupVnfNics) {
vnfTemplateNicDao.deleteByTemplateId(templateId);
} else if (CollectionUtils.isNotEmpty(cmd.getVnfNics())) {
vnfTemplateNicDao.deleteByTemplateId(templateId);
persistVnfTemplateNics(templateId, cmd.getVnfNics());
}
vnfTemplateNicDao.deleteByTemplateId(templateId);
persistVnfTemplateNics(templateId, nics);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@ public void testPersistVnfTemplateUpdate() {
public void testPersistVnfTemplateUpdateWithoutNics() {
UpdateVnfTemplateCmd cmd = new UpdateVnfTemplateCmd();
ReflectionTestUtils.setField(cmd,"vnfDetails", vnfDetails);
ReflectionTestUtils.setField(cmd,"cleanupVnfNics", true);

vnfTemplateManagerImpl.updateVnfTemplate(templateId, cmd);

Mockito.verify(vnfTemplateNicDao, Mockito.times(1)).deleteByTemplateId(templateId);
Mockito.verify(vnfTemplateNicDao, Mockito.times(0)).persist(any(VnfTemplateNicVO.class));
Mockito.verify(vnfTemplateDetailsDao, Mockito.times(1)).removeDetails(templateId);
Mockito.verify(vnfTemplateDetailsDao, Mockito.times(5)).addDetail(eq(templateId), anyString(), anyString(), eq(true));
Expand Down
3 changes: 3 additions & 0 deletions ui/src/views/image/TemplateVnfSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,9 @@ export default {
if (areNicsChanged) {
let i = 0
if (this.vnfNics.length === 0) {
params.cleanupvnfnics = true
}
for (var index = 0; index < this.vnfNics.length; index++) {
var nic = this.vnfNics[index]
params['vnfnics[' + i + '].deviceid'] = nic.deviceid
Expand Down

0 comments on commit 0ed5089

Please sign in to comment.