Skip to content

Commit 876c464

Browse files
[CLOUDSTACK-10301] Allow updating the network ACL list name and Description
1 parent 6233a77 commit 876c464

23 files changed

Lines changed: 203 additions & 12 deletions

File tree

api/src/main/java/com/cloud/network/vpc/NetworkACLService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.apache.cloudstack.api.command.user.network.CreateNetworkACLCmd;
2222
import org.apache.cloudstack.api.command.user.network.ListNetworkACLListsCmd;
2323
import org.apache.cloudstack.api.command.user.network.ListNetworkACLsCmd;
24+
import org.apache.cloudstack.api.command.user.network.UpdateNetworkACLListCmd;
2425

2526
import com.cloud.exception.ResourceUnavailableException;
2627
import com.cloud.utils.Pair;
@@ -131,6 +132,6 @@ NetworkACLItem updateNetworkACLItem(Long id, String protocol, List<String> sourc
131132
*/
132133
boolean replaceNetworkACLonPrivateGw(long aclId, long privateGatewayId) throws ResourceUnavailableException;
133134

134-
NetworkACL updateNetworkACL(Long id, String customId, Boolean forDisplay);
135+
NetworkACL updateNetworkACL(UpdateNetworkACLListCmd updateNetworkACLListCmd);
135136

136137
}

api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLListCmd.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ public class UpdateNetworkACLListCmd extends BaseAsyncCustomIdCmd {
4646

4747
@Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "an optional field, whether to the display the list to the end user or not", since = "4.4", authorized = {RoleType.Admin})
4848
private Boolean display;
49+
50+
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "Name of the network ACL list")
51+
private String name;
52+
53+
@Parameter(name = ApiConstants.DESCRIPTION, type = CommandType.STRING, description = "Description of the network ACL list")
54+
private String description;
4955

5056
/////////////////////////////////////////////////////
5157
/////////////////// Accessors ///////////////////////
@@ -85,7 +91,7 @@ public long getEntityOwnerId() {
8591

8692
@Override
8793
public void execute() throws ResourceUnavailableException {
88-
NetworkACL acl = _networkACLService.updateNetworkACL(id, this.getCustomId(), getDisplay());
94+
NetworkACL acl = _networkACLService.updateNetworkACL(this);
8995
NetworkACLResponse aclResponse = _responseGenerator.createNetworkACLResponse(acl);
9096
setResponseObject(aclResponse);
9197
aclResponse.setResponseName(getCommandName());
@@ -97,4 +103,12 @@ public void checkUuid() {
97103
_uuidMgr.checkUuid(this.getCustomId(), NetworkACL.class);
98104
}
99105
}
106+
107+
public String getDescription() {
108+
return description;
109+
}
110+
111+
public String getName() {
112+
return name;
113+
}
100114
}

engine/schema/src/main/java/com/cloud/network/vpc/NetworkACLVO.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,11 @@ public void setVpcId(long vpcId) {
101101
public boolean isDisplay() {
102102
return display;
103103
}
104+
105+
public void setDescription(String description) {
106+
this.description = description;
107+
}
108+
public void setName(String name) {
109+
this.name = name;
110+
}
104111
}

server/src/main/java/com/cloud/network/vpc/NetworkACLServiceImpl.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.cloudstack.api.command.user.network.CreateNetworkACLCmd;
2828
import org.apache.cloudstack.api.command.user.network.ListNetworkACLListsCmd;
2929
import org.apache.cloudstack.api.command.user.network.ListNetworkACLsCmd;
30+
import org.apache.cloudstack.api.command.user.network.UpdateNetworkACLListCmd;
3031
import org.apache.cloudstack.context.CallContext;
3132
import org.apache.commons.lang.StringUtils;
3233
import org.apache.log4j.Logger;
@@ -662,22 +663,31 @@ public NetworkACLItem updateNetworkACLItem(final Long id, final String protocol,
662663

663664
@Override
664665
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_ACL_UPDATE, eventDescription = "updating network acl", async = true)
665-
public NetworkACL updateNetworkACL(final Long id, final String customId, final Boolean forDisplay) {
666-
final NetworkACLVO acl = _networkACLDao.findById(id);
667-
final Vpc vpc = _entityMgr.findById(Vpc.class, acl.getVpcId());
668-
final Account caller = CallContext.current().getCallingAccount();
666+
public NetworkACL updateNetworkACL(UpdateNetworkACLListCmd updateNetworkACLListCmd) {
667+
Long id = updateNetworkACLListCmd.getId();
668+
NetworkACLVO acl = _networkACLDao.findById(id);
669+
Vpc vpc = _entityMgr.findById(Vpc.class, acl.getVpcId());
670+
Account caller = CallContext.current().getCallingAccount();
669671
_accountMgr.checkAccess(caller, null, true, vpc);
670672

671-
if (customId != null) {
673+
String name = updateNetworkACLListCmd.getName();
674+
if (StringUtils.isNotBlank(name)) {
675+
acl.setName(name);
676+
}
677+
String description = updateNetworkACLListCmd.getDescription();
678+
if (StringUtils.isNotBlank(description)) {
679+
acl.setDescription(description);
680+
}
681+
String customId = updateNetworkACLListCmd.getCustomId();
682+
if (StringUtils.isNotBlank(customId)) {
672683
acl.setUuid(customId);
673684
}
674-
685+
Boolean forDisplay = updateNetworkACLListCmd.getDisplay();
675686
if (forDisplay != null) {
676687
acl.setDisplay(forDisplay);
677688
}
678-
679689
_networkACLDao.update(id, acl);
680690
return _networkACLDao.findById(id);
681-
}
691+
}
682692

683693
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package com.cloud.network.vpc;
2+
3+
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
4+
import org.apache.cloudstack.api.command.user.network.UpdateNetworkACLListCmd;
5+
import org.apache.cloudstack.context.CallContext;
6+
import org.apache.commons.lang.StringUtils;
7+
import org.junit.Before;
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
import org.mockito.InOrder;
11+
import org.mockito.InjectMocks;
12+
import org.mockito.Mock;
13+
import org.mockito.Mockito;
14+
import org.mockito.Spy;
15+
import org.mockito.runners.MockitoJUnitRunner;
16+
import org.powermock.api.mockito.PowerMockito;
17+
import org.powermock.core.classloader.annotations.PrepareForTest;
18+
import org.powermock.modules.junit4.PowerMockRunner;
19+
20+
import com.cloud.network.vpc.dao.NetworkACLDao;
21+
import com.cloud.user.Account;
22+
import com.cloud.user.AccountManager;
23+
import com.cloud.utils.db.EntityManager;
24+
25+
@RunWith(PowerMockRunner.class)
26+
public class NetworkACLServiceImplTest {
27+
28+
@Spy
29+
@InjectMocks
30+
private NetworkACLServiceImpl networkACLServiceImpl = new NetworkACLServiceImpl();
31+
@Mock
32+
private NetworkACLDao networkACLDao;
33+
@Mock
34+
private AccountManager accountManager;
35+
@Mock
36+
private EntityManager entityManager;
37+
38+
@Mock
39+
private UpdateNetworkACLListCmd updateNetworkACLListCmdMock;
40+
@Mock
41+
private NetworkACLVO networkACLVOMock;
42+
43+
private long networkAclListId = 1l;
44+
45+
@Before
46+
public void before() {
47+
Mockito.when(networkACLDao.findById(networkAclListId)).thenReturn(networkACLVOMock);
48+
49+
PowerMockito.mockStatic(CallContext.class);
50+
PowerMockito.when(CallContext.current()).thenReturn(Mockito.mock(CallContext.class));
51+
}
52+
53+
@Test
54+
@PrepareForTest(CallContext.class)
55+
public void updateNetworkACLTestParametersNotNull() {
56+
String name = "name";
57+
String description = "desc";
58+
String customId = "customId";
59+
60+
Mockito.when(updateNetworkACLListCmdMock.getName()).thenReturn(name);
61+
Mockito.when(updateNetworkACLListCmdMock.getDescription()).thenReturn(description);
62+
Mockito.when(updateNetworkACLListCmdMock.getCustomId()).thenReturn(customId);
63+
Mockito.when(updateNetworkACLListCmdMock.getId()).thenReturn(networkAclListId);
64+
Mockito.when(updateNetworkACLListCmdMock.getDisplay()).thenReturn(false);
65+
66+
networkACLServiceImpl.updateNetworkACL(updateNetworkACLListCmdMock);
67+
68+
InOrder inOrder = Mockito.inOrder(networkACLDao, entityManager, entityManager, accountManager, networkACLVOMock);
69+
70+
inOrder.verify(networkACLDao).findById(networkAclListId);
71+
inOrder.verify(entityManager).findById(Mockito.eq(Vpc.class), Mockito.anyLong());
72+
inOrder.verify(accountManager).checkAccess(Mockito.any(Account.class), Mockito.isNull(AccessType.class), Mockito.eq(true), Mockito.any(Vpc.class));
73+
74+
inOrder.verify(networkACLVOMock).setName(name);
75+
inOrder.verify(networkACLVOMock).setDescription(description);
76+
inOrder.verify(networkACLVOMock).setUuid(customId);
77+
inOrder.verify(networkACLVOMock).setDisplay(false);
78+
79+
inOrder.verify(networkACLDao).update(networkAclListId, networkACLVOMock);
80+
inOrder.verify(networkACLDao).findById(networkAclListId);
81+
}
82+
83+
84+
@Test
85+
@PrepareForTest(CallContext.class)
86+
public void updateNetworkACLTestParametersWithNullValues() {
87+
Mockito.when(updateNetworkACLListCmdMock.getName()).thenReturn(null);
88+
Mockito.when(updateNetworkACLListCmdMock.getDescription()).thenReturn(null);
89+
Mockito.when(updateNetworkACLListCmdMock.getCustomId()).thenReturn(null);
90+
Mockito.when(updateNetworkACLListCmdMock.getId()).thenReturn(networkAclListId);
91+
Mockito.when(updateNetworkACLListCmdMock.getDisplay()).thenReturn(null);
92+
93+
networkACLServiceImpl.updateNetworkACL(updateNetworkACLListCmdMock);
94+
95+
InOrder inOrder = Mockito.inOrder(networkACLDao, entityManager, entityManager, accountManager, networkACLVOMock);
96+
97+
inOrder.verify(networkACLDao).findById(networkAclListId);
98+
inOrder.verify(entityManager).findById(Mockito.eq(Vpc.class), Mockito.anyLong());
99+
inOrder.verify(accountManager).checkAccess(Mockito.any(Account.class), Mockito.isNull(AccessType.class), Mockito.eq(true), Mockito.any(Vpc.class));
100+
101+
Mockito.verify(networkACLVOMock, Mockito.times(0)).setName(null);
102+
inOrder.verify(networkACLVOMock, Mockito.times(0)).setDescription(null);
103+
inOrder.verify(networkACLVOMock, Mockito.times(0)).setUuid(null);
104+
inOrder.verify(networkACLVOMock, Mockito.times(0)).setDisplay(false);
105+
106+
inOrder.verify(networkACLDao).update(networkAclListId, networkACLVOMock);
107+
inOrder.verify(networkACLDao).findById(networkAclListId);
108+
}
109+
}
110+

ui/l10n/ar.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ var dictionary = {
313313
"label.add.accounts": "إضافة حسابات",
314314
"label.add.accounts.to": "إضافة حسابات إلى",
315315
"label.add.acl.list": "Add ACL List",
316+
"label.edit.acl.list": "Edit ACL List",
316317
"label.add.affinity.group": "Add new affinity group",
317318
"label.add.baremetal.dhcp.device": "Add Baremetal DHCP Device",
318319
"label.add.baremetal.rack.configuration": "Add Baremetal Rack Configuration",

ui/l10n/ca.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ var dictionary = {
313313
"label.add.accounts": "Afegir comptes",
314314
"label.add.accounts.to": "Afegir comptes a",
315315
"label.add.acl.list": "Add ACL List",
316+
"label.edit.acl.list": "Edit ACL List",
316317
"label.add.affinity.group": "Add new affinity group",
317318
"label.add.baremetal.dhcp.device": "Add Baremetal DHCP Device",
318319
"label.add.baremetal.rack.configuration": "Add Baremetal Rack Configuration",

ui/l10n/de_DE.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ var dictionary = {
313313
"label.add.accounts": "Konten hinzufügen",
314314
"label.add.accounts.to": "Konten hinzufügen zu",
315315
"label.add.acl.list": "ACL-Liste hinzufügen",
316+
"label.edit.acl.list": "Edit ACL List",
316317
"label.add.affinity.group": "Neue Affinitätsgruppe hinzufügen",
317318
"label.add.baremetal.dhcp.device": "Baremetal DHCP-Gerät hinzufügen",
318319
"label.add.baremetal.rack.configuration": "Baremetal Rackkonfiguration hinzufügen",

ui/l10n/en.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ var dictionary = {"ICMP.code":"ICMP Code",
314314
"label.add.accounts":"Add accounts",
315315
"label.add.accounts.to":"Add accounts to",
316316
"label.add.acl.list":"Add ACL List",
317+
"label.edit.acl.list": "Edit ACL List",
317318
"label.add.affinity.group":"Add new affinity group",
318319
"label.add.baremetal.dhcp.device":"Add Baremetal DHCP Device",
319320
"label.add.baremetal.rack.configuration":"Add Baremetal Rack Configuration",

ui/l10n/es.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ var dictionary = {
313313
"label.add.accounts": "Agregar Cuentas",
314314
"label.add.accounts.to": "Agregar Cuentas a",
315315
"label.add.acl.list": "Agregar Lista ACL",
316+
"label.edit.acl.list": "Edit ACL List",
316317
"label.add.affinity.group": "Agregar un nuevo grupo de afinidad",
317318
"label.add.baremetal.dhcp.device": "Agregar dispositivo DHCP Baremetal",
318319
"label.add.baremetal.rack.configuration": "Agregar Configuración de Rack Baremetal",

0 commit comments

Comments
 (0)