rafaelweingartner closed pull request #2461: [CLOUDSTACK-10301] Allow updating
the network ACL list name and Description
URL: https://github.com/apache/cloudstack/pull/2461
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/api/src/main/java/com/cloud/network/vpc/NetworkACLService.java
b/api/src/main/java/com/cloud/network/vpc/NetworkACLService.java
index f08fff5425d..5249f035084 100644
--- a/api/src/main/java/com/cloud/network/vpc/NetworkACLService.java
+++ b/api/src/main/java/com/cloud/network/vpc/NetworkACLService.java
@@ -21,6 +21,7 @@
import org.apache.cloudstack.api.command.user.network.CreateNetworkACLCmd;
import org.apache.cloudstack.api.command.user.network.ListNetworkACLListsCmd;
import org.apache.cloudstack.api.command.user.network.ListNetworkACLsCmd;
+import org.apache.cloudstack.api.command.user.network.UpdateNetworkACLListCmd;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.utils.Pair;
@@ -28,109 +29,65 @@
public interface NetworkACLService {
/**
* Creates Network ACL for the specified VPC
- * @param name
- * @param description
- * @param vpcId
- * @param forDisplay TODO
- * @return
*/
NetworkACL createNetworkACL(String name, String description, long vpcId,
Boolean forDisplay);
/**
* Get Network ACL with specified Id
- * @param id
- * @return
*/
NetworkACL getNetworkACL(long id);
/**
* List NetworkACLs by Id/Name/Network or Vpc it belongs to
- * @param cmd
- * @return
*/
Pair<List<? extends NetworkACL>, Integer>
listNetworkACLs(ListNetworkACLListsCmd cmd);
/**
* Delete specified network ACL. Deletion fails if the list is not empty
- * @param id
- * @return
*/
boolean deleteNetworkACL(long id);
/**
* Associates ACL with specified Network
- * @param aclId
- * @param networkId
- * @return
- * @throws ResourceUnavailableException
*/
boolean replaceNetworkACL(long aclId, long networkId) throws
ResourceUnavailableException;
/**
* Applied ACL to associated networks
- * @param aclId
- * @return
- * @throws ResourceUnavailableException
*/
boolean applyNetworkACL(long aclId) throws ResourceUnavailableException;
/**
* Creates a Network ACL Item within an ACL and applies the ACL to
associated networks
- * @param createNetworkACLCmd
- * @return
*/
NetworkACLItem createNetworkACLItem(CreateNetworkACLCmd aclItemCmd);
/**
* Return ACL item with specified Id
- * @param ruleId
- * @return
*/
NetworkACLItem getNetworkACLItem(long ruleId);
/**
* Lists Network ACL Items by Id, Network, ACLId, Traffic Type, protocol
- * @param listNetworkACLsCmd
- * @return
*/
Pair<List<? extends NetworkACLItem>, Integer>
listNetworkACLItems(ListNetworkACLsCmd cmd);
/**
* Revoke ACL Item with specified Id
- * @param ruleId
- * @return
*/
boolean revokeNetworkACLItem(long ruleId);
/**
* Updates existing aclItem applies to associated networks
- * @param id
- * @param protocol
- * @param sourceCidrList
- * @param trafficType
- * @param action
- * @param number
- * @param sourcePortStart
- * @param sourcePortEnd
- * @param icmpCode
- * @param icmpType
- * @param newUUID TODO
- * @param forDisplay TODO
- * @return
- * @throws ResourceUnavailableException
*/
- NetworkACLItem updateNetworkACLItem(Long id, String protocol, List<String>
sourceCidrList, NetworkACLItem.TrafficType trafficType, String action, Integer
number,
- Integer sourcePortStart, Integer sourcePortEnd, Integer icmpCode,
Integer icmpType, String newUUID, Boolean forDisplay) throws
ResourceUnavailableException;
+ NetworkACLItem updateNetworkACLItem(Long id, String protocol, List<String>
sourceCidrList, NetworkACLItem.TrafficType trafficType, String action, Integer
number, Integer sourcePortStart,
+ Integer sourcePortEnd, Integer icmpCode, Integer icmpType, String
newUUID, Boolean forDisplay) throws ResourceUnavailableException;
/**
* Associates ACL with specified Network
- * @param aclId
- * @param privateGatewayId
- * @return
- * @throws ResourceUnavailableException
*/
boolean replaceNetworkACLonPrivateGw(long aclId, long privateGatewayId)
throws ResourceUnavailableException;
- NetworkACL updateNetworkACL(Long id, String customId, Boolean forDisplay);
+ NetworkACL updateNetworkACL(UpdateNetworkACLListCmd
updateNetworkACLListCmd);
}
diff --git
a/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLListCmd.java
b/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLListCmd.java
index aa1f557e72b..22eaf2180ca 100644
---
a/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLListCmd.java
+++
b/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLListCmd.java
@@ -31,8 +31,7 @@
import com.cloud.network.vpc.NetworkACL;
import com.cloud.user.Account;
-@APICommand(name = "updateNetworkACLList", description = "Updates network ACL
list", responseObject = SuccessResponse.class, since = "4.4",
- requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
+@APICommand(name = "updateNetworkACLList", description = "Updates network ACL
list", responseObject = SuccessResponse.class, since = "4.4",
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
public class UpdateNetworkACLListCmd extends BaseAsyncCustomIdCmd {
public static final Logger s_logger =
Logger.getLogger(UpdateNetworkACLListCmd.class.getName());
private static final String s_name = "updatenetworkacllistresponse";
@@ -44,9 +43,16 @@
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType =
NetworkACLResponse.class, required = true, description = "the ID of the network
ACL")
private Long id;
- @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})
+ @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})
private Boolean display;
+ @Parameter(name = ApiConstants.NAME, type = CommandType.STRING,
description = "Name of the network ACL list")
+ private String name;
+
+ @Parameter(name = ApiConstants.DESCRIPTION, type = CommandType.STRING,
description = "Description of the network ACL list")
+ private String description;
+
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@@ -85,7 +91,7 @@ public long getEntityOwnerId() {
@Override
public void execute() throws ResourceUnavailableException {
- NetworkACL acl = _networkACLService.updateNetworkACL(id,
this.getCustomId(), getDisplay());
+ NetworkACL acl = _networkACLService.updateNetworkACL(this);
NetworkACLResponse aclResponse =
_responseGenerator.createNetworkACLResponse(acl);
setResponseObject(aclResponse);
aclResponse.setResponseName(getCommandName());
@@ -97,4 +103,12 @@ public void checkUuid() {
_uuidMgr.checkUuid(this.getCustomId(), NetworkACL.class);
}
}
+
+ public String getDescription() {
+ return description;
+ }
+
+ public String getName() {
+ return name;
+ }
}
diff --git
a/engine/schema/src/main/java/com/cloud/network/vpc/NetworkACLVO.java
b/engine/schema/src/main/java/com/cloud/network/vpc/NetworkACLVO.java
index fb6a239c58d..4eaa2b575e0 100644
--- a/engine/schema/src/main/java/com/cloud/network/vpc/NetworkACLVO.java
+++ b/engine/schema/src/main/java/com/cloud/network/vpc/NetworkACLVO.java
@@ -101,4 +101,12 @@ public void setVpcId(long vpcId) {
public boolean isDisplay() {
return display;
}
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
}
diff --git
a/server/src/main/java/com/cloud/network/vpc/NetworkACLServiceImpl.java
b/server/src/main/java/com/cloud/network/vpc/NetworkACLServiceImpl.java
index 1743f5c322e..278a5fb45d1 100644
--- a/server/src/main/java/com/cloud/network/vpc/NetworkACLServiceImpl.java
+++ b/server/src/main/java/com/cloud/network/vpc/NetworkACLServiceImpl.java
@@ -27,6 +27,7 @@
import org.apache.cloudstack.api.command.user.network.CreateNetworkACLCmd;
import org.apache.cloudstack.api.command.user.network.ListNetworkACLListsCmd;
import org.apache.cloudstack.api.command.user.network.ListNetworkACLsCmd;
+import org.apache.cloudstack.api.command.user.network.UpdateNetworkACLListCmd;
import org.apache.cloudstack.context.CallContext;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
@@ -67,31 +68,29 @@
private static final Logger s_logger =
Logger.getLogger(NetworkACLServiceImpl.class);
@Inject
- AccountManager _accountMgr;
+ private AccountManager _accountMgr;
@Inject
- NetworkModel _networkMgr;
+ private NetworkModel _networkMgr;
@Inject
- ResourceTagDao _resourceTagDao;
+ private ResourceTagDao _resourceTagDao;
@Inject
- NetworkACLDao _networkACLDao;
+ private NetworkACLDao _networkACLDao;
@Inject
- NetworkACLItemDao _networkACLItemDao;
+ private NetworkACLItemDao _networkACLItemDao;
@Inject
- NetworkModel _networkModel;
+ private NetworkModel _networkModel;
@Inject
- NetworkDao _networkDao;
+ private NetworkDao _networkDao;
@Inject
- NetworkACLManager _networkAclMgr;
+ private NetworkACLManager _networkAclMgr;
@Inject
- VpcGatewayDao _vpcGatewayDao;
+ private VpcGatewayDao _vpcGatewayDao;
@Inject
- VpcManager _vpcMgr;
+ private EntityManager _entityMgr;
@Inject
- EntityManager _entityMgr;
+ private VpcDao _vpcDao;
@Inject
- VpcDao _vpcDao;
- @Inject
- VpcService _vpcSvc;
+ private VpcService _vpcSvc;
@Override
public NetworkACL createNetworkACL(final String name, final String
description, final long vpcId, final Boolean forDisplay) {
@@ -146,7 +145,7 @@ public NetworkACL getNetworkACL(final long id) {
sc.setParameters("display", display);
}
- if(id != null){
+ if (id != null) {
sc.setParameters("id", id);
}
@@ -173,10 +172,8 @@ public NetworkACL getNetworkACL(final long id) {
final String accountName = cmd.getAccountName();
final Long projectId = cmd.getProjectId();
final boolean listAll = cmd.listAll();
- final Ternary<Long, Boolean, ListProjectResourcesCriteria>
domainIdRecursiveListProject = new Ternary<Long, Boolean,
- ListProjectResourcesCriteria>(domainId, isRecursive, null);
- _accountMgr.buildACLSearchParameters(caller, id, accountName,
projectId, permittedAccounts, domainIdRecursiveListProject,
- listAll, false);
+ final Ternary<Long, Boolean, ListProjectResourcesCriteria>
domainIdRecursiveListProject = new Ternary<Long, Boolean,
ListProjectResourcesCriteria>(domainId, isRecursive, null);
+ _accountMgr.buildACLSearchParameters(caller, id, accountName,
projectId, permittedAccounts, domainIdRecursiveListProject, listAll, false);
domainId = domainIdRecursiveListProject.first();
isRecursive = domainIdRecursiveListProject.second();
final ListProjectResourcesCriteria listProjectResourcesCriteria =
domainIdRecursiveListProject.third();
@@ -199,7 +196,7 @@ public NetworkACL getNetworkACL(final long id) {
}
final Filter filter = new Filter(NetworkACLVO.class, "id", false,
null, null);
- final Pair<List<NetworkACLVO>, Integer> acls =
_networkACLDao.searchAndCount(sc, filter);
+ final Pair<List<NetworkACLVO>, Integer> acls =
_networkACLDao.searchAndCount(sc, filter);
return new Pair<List<? extends NetworkACL>, Integer>(acls.first(),
acls.second());
}
@@ -261,7 +258,7 @@ public boolean replaceNetworkACLonPrivateGw(final long
aclId, final long private
final PrivateGateway privateGateway =
_vpcSvc.getVpcPrivateGateway(gateway.getId());
_accountMgr.checkAccess(caller, null, true, privateGateway);
- return _networkAclMgr.replaceNetworkACLForPrivateGw(acl,
privateGateway);
+ return _networkAclMgr.replaceNetworkACLForPrivateGw(acl,
privateGateway);
}
@@ -376,12 +373,11 @@ public NetworkACLItem createNetworkACLItem(final
CreateNetworkACLCmd aclItemCmd)
}
}
- validateNetworkACLItem(aclItemCmd.getSourcePortStart(),
aclItemCmd.getSourcePortEnd(), aclItemCmd.getSourceCidrList(),
aclItemCmd.getProtocol(),
- aclItemCmd.getIcmpCode(), aclItemCmd.getIcmpType(),
aclItemCmd.getAction(), aclItemCmd.getNumber());
+ validateNetworkACLItem(aclItemCmd.getSourcePortStart(),
aclItemCmd.getSourcePortEnd(), aclItemCmd.getSourceCidrList(),
aclItemCmd.getProtocol(), aclItemCmd.getIcmpCode(),
+ aclItemCmd.getIcmpType(), aclItemCmd.getAction(),
aclItemCmd.getNumber());
- return
_networkAclMgr.createNetworkACLItem(aclItemCmd.getSourcePortStart(),
aclItemCmd.getSourcePortEnd(), aclItemCmd.getProtocol(),
- aclItemCmd.getSourceCidrList(), aclItemCmd.getIcmpCode(),
aclItemCmd.getIcmpType(), aclItemCmd.getTrafficType(), aclId,
aclItemCmd.getAction(),
- aclItemCmd.getNumber(), aclItemCmd.getDisplay());
+ return
_networkAclMgr.createNetworkACLItem(aclItemCmd.getSourcePortStart(),
aclItemCmd.getSourcePortEnd(), aclItemCmd.getProtocol(),
aclItemCmd.getSourceCidrList(), aclItemCmd.getIcmpCode(),
+ aclItemCmd.getIcmpType(), aclItemCmd.getTrafficType(), aclId,
aclItemCmd.getAction(), aclItemCmd.getNumber(), aclItemCmd.getDisplay());
}
private void validateNetworkACLItem(final Integer portStart, final Integer
portEnd, final List<String> sourceCidrList, final String protocol, final
Integer icmpCode, final Integer icmpType,
@@ -446,8 +442,7 @@ private void validateNetworkACLItem(final Integer
portStart, final Integer portE
}
if (icmpCode != null) {
if (icmpCode.longValue() != -1 &&
!NetUtils.validateIcmpCode(icmpCode.longValue())) {
- throw new InvalidParameterValueException("Invalid icmp
code; should belong to [0-15] range and can"
- + " be defined when icmpType belongs to [0-40]
range");
+ throw new InvalidParameterValueException("Invalid icmp
code; should belong to [0-15] range and can" + " be defined when icmpType
belongs to [0-40] range");
}
}
}
@@ -524,7 +519,7 @@ public boolean applyNetworkACL(final long aclId) throws
ResourceUnavailableExcep
if (networkId != null) {
final Network network = _networkDao.findById(networkId);
aclId = network.getNetworkACLId();
- if( aclId == null){
+ if (aclId == null) {
// No aclId associated with the network.
//Return empty list
return new Pair(new ArrayList<NetworkACLItem>(), 0);
@@ -549,7 +544,6 @@ public boolean applyNetworkACL(final long aclId) throws
ResourceUnavailableExcep
} else {
//ToDo: Add accountId to network_acl_item table for permission
check
-
// aclId is not specified
// List permitted VPCs and filter aclItems
final List<Long> permittedAccounts = new ArrayList<Long>();
@@ -558,10 +552,8 @@ public boolean applyNetworkACL(final long aclId) throws
ResourceUnavailableExcep
final String accountName = cmd.getAccountName();
final Long projectId = cmd.getProjectId();
final boolean listAll = cmd.listAll();
- final Ternary<Long, Boolean, ListProjectResourcesCriteria>
domainIdRecursiveListProject = new Ternary<Long, Boolean,
- ListProjectResourcesCriteria>(domainId, isRecursive, null);
- _accountMgr.buildACLSearchParameters(caller, id, accountName,
projectId, permittedAccounts, domainIdRecursiveListProject,
- listAll, false);
+ final Ternary<Long, Boolean, ListProjectResourcesCriteria>
domainIdRecursiveListProject = new Ternary<Long, Boolean,
ListProjectResourcesCriteria>(domainId, isRecursive, null);
+ _accountMgr.buildACLSearchParameters(caller, id, accountName,
projectId, permittedAccounts, domainIdRecursiveListProject, listAll, false);
domainId = domainIdRecursiveListProject.first();
isRecursive = domainIdRecursiveListProject.second();
final ListProjectResourcesCriteria listProjectResourcesCriteria =
domainIdRecursiveListProject.third();
@@ -599,7 +591,7 @@ public boolean applyNetworkACL(final long aclId) throws
ResourceUnavailableExcep
final Pair<List<NetworkACLItemVO>, Integer> result =
_networkACLItemDao.searchAndCount(sc, filter);
final List<NetworkACLItemVO> aclItemVOs = result.first();
- for (final NetworkACLItemVO item: aclItemVOs) {
+ for (final NetworkACLItemVO item : aclItemVOs) {
_networkACLItemDao.loadCidrs(item);
}
return new Pair<List<? extends NetworkACLItem>, Integer>(aclItemVOs,
result.second());
@@ -609,12 +601,12 @@ public boolean applyNetworkACL(final long aclId) throws
ResourceUnavailableExcep
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_ACL_ITEM_DELETE,
eventDescription = "Deleting Network ACL Item", async = true)
public boolean revokeNetworkACLItem(final long ruleId) {
final NetworkACLItemVO aclItem = _networkACLItemDao.findById(ruleId);
- if(aclItem != null){
+ if (aclItem != null) {
final NetworkACL acl =
_networkAclMgr.getNetworkACL(aclItem.getAclId());
final Vpc vpc = _entityMgr.findById(Vpc.class, acl.getVpcId());
- if(aclItem.getAclId() == NetworkACL.DEFAULT_ALLOW ||
aclItem.getAclId() == NetworkACL.DEFAULT_DENY){
+ if (aclItem.getAclId() == NetworkACL.DEFAULT_ALLOW ||
aclItem.getAclId() == NetworkACL.DEFAULT_DENY) {
throw new InvalidParameterValueException("ACL Items in default
ACL cannot be deleted");
}
@@ -628,7 +620,8 @@ public boolean revokeNetworkACLItem(final long ruleId) {
@Override
public NetworkACLItem updateNetworkACLItem(final Long id, final String
protocol, final List<String> sourceCidrList, final NetworkACLItem.TrafficType
trafficType, final String action,
- final Integer number, final Integer sourcePortStart, final Integer
sourcePortEnd, final Integer icmpCode, final Integer icmpType, final String
newUUID, final Boolean forDisplay) throws ResourceUnavailableException {
+ final Integer number, final Integer sourcePortStart, final Integer
sourcePortEnd, final Integer icmpCode, final Integer icmpType, final String
newUUID, final Boolean forDisplay)
+ throws ResourceUnavailableException {
final NetworkACLItemVO aclItem = _networkACLItemDao.findById(id);
if (aclItem == null) {
throw new InvalidParameterValueException("Unable to find ACL Item
cannot be found");
@@ -654,28 +647,37 @@ public NetworkACLItem updateNetworkACLItem(final Long id,
final String protocol,
}
}
- validateNetworkACLItem(sourcePortStart == null ?
aclItem.getSourcePortStart() : sourcePortStart, sourcePortEnd == null ?
aclItem.getSourcePortEnd()
- : sourcePortEnd, sourceCidrList, protocol, icmpCode, icmpType
== null ? aclItem.getIcmpType() : icmpType, action, number);
+ validateNetworkACLItem(sourcePortStart == null ?
aclItem.getSourcePortStart() : sourcePortStart, sourcePortEnd == null ?
aclItem.getSourcePortEnd() : sourcePortEnd, sourceCidrList, protocol,
+ icmpCode, icmpType == null ? aclItem.getIcmpType() : icmpType,
action, number);
return _networkAclMgr.updateNetworkACLItem(id, protocol,
sourceCidrList, trafficType, action, number, sourcePortStart, sourcePortEnd,
icmpCode, icmpType, newUUID, forDisplay);
}
@Override
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_ACL_UPDATE,
eventDescription = "updating network acl", async = true)
- public NetworkACL updateNetworkACL(final Long id, final String customId,
final Boolean forDisplay) {
- final NetworkACLVO acl = _networkACLDao.findById(id);
- final Vpc vpc = _entityMgr.findById(Vpc.class, acl.getVpcId());
- final Account caller = CallContext.current().getCallingAccount();
+ public NetworkACL updateNetworkACL(UpdateNetworkACLListCmd
updateNetworkACLListCmd) {
+ Long id = updateNetworkACLListCmd.getId();
+ NetworkACLVO acl = _networkACLDao.findById(id);
+ Vpc vpc = _entityMgr.findById(Vpc.class, acl.getVpcId());
+ Account caller = CallContext.current().getCallingAccount();
_accountMgr.checkAccess(caller, null, true, vpc);
- if (customId != null) {
+ String name = updateNetworkACLListCmd.getName();
+ if (StringUtils.isNotBlank(name)) {
+ acl.setName(name);
+ }
+ String description = updateNetworkACLListCmd.getDescription();
+ if (StringUtils.isNotBlank(description)) {
+ acl.setDescription(description);
+ }
+ String customId = updateNetworkACLListCmd.getCustomId();
+ if (StringUtils.isNotBlank(customId)) {
acl.setUuid(customId);
}
-
+ Boolean forDisplay = updateNetworkACLListCmd.getDisplay();
if (forDisplay != null) {
acl.setDisplay(forDisplay);
}
-
_networkACLDao.update(id, acl);
return _networkACLDao.findById(id);
}
diff --git
a/server/src/test/java/com/cloud/network/vpc/NetworkACLServiceImplTest.java
b/server/src/test/java/com/cloud/network/vpc/NetworkACLServiceImplTest.java
new file mode 100644
index 00000000000..1ae86693811
--- /dev/null
+++ b/server/src/test/java/com/cloud/network/vpc/NetworkACLServiceImplTest.java
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.cloud.network.vpc;
+
+import org.apache.cloudstack.acl.SecurityChecker.AccessType;
+import org.apache.cloudstack.api.command.user.network.UpdateNetworkACLListCmd;
+import org.apache.cloudstack.context.CallContext;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.Spy;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import com.cloud.network.vpc.dao.NetworkACLDao;
+import com.cloud.user.Account;
+import com.cloud.user.AccountManager;
+import com.cloud.utils.db.EntityManager;
+
+@RunWith(PowerMockRunner.class)
+public class NetworkACLServiceImplTest {
+
+ @Spy
+ @InjectMocks
+ private NetworkACLServiceImpl networkACLServiceImpl = new
NetworkACLServiceImpl();
+ @Mock
+ private NetworkACLDao networkACLDao;
+ @Mock
+ private AccountManager accountManager;
+ @Mock
+ private EntityManager entityManager;
+
+ @Mock
+ private UpdateNetworkACLListCmd updateNetworkACLListCmdMock;
+ @Mock
+ private NetworkACLVO networkACLVOMock;
+
+ private long networkAclListId = 1l;
+
+ @Before
+ public void before() {
+
Mockito.when(networkACLDao.findById(networkAclListId)).thenReturn(networkACLVOMock);
+
+ PowerMockito.mockStatic(CallContext.class);
+
PowerMockito.when(CallContext.current()).thenReturn(Mockito.mock(CallContext.class));
+ }
+
+ @Test
+ @PrepareForTest(CallContext.class)
+ public void updateNetworkACLTestParametersNotNull() {
+ String name = "name";
+ String description = "desc";
+ String customId = "customId";
+
+ Mockito.when(updateNetworkACLListCmdMock.getName()).thenReturn(name);
+
Mockito.when(updateNetworkACLListCmdMock.getDescription()).thenReturn(description);
+
Mockito.when(updateNetworkACLListCmdMock.getCustomId()).thenReturn(customId);
+
Mockito.when(updateNetworkACLListCmdMock.getId()).thenReturn(networkAclListId);
+
Mockito.when(updateNetworkACLListCmdMock.getDisplay()).thenReturn(false);
+
+ networkACLServiceImpl.updateNetworkACL(updateNetworkACLListCmdMock);
+
+ InOrder inOrder = Mockito.inOrder(networkACLDao, entityManager,
entityManager, accountManager, networkACLVOMock);
+
+ inOrder.verify(networkACLDao).findById(networkAclListId);
+ inOrder.verify(entityManager).findById(Mockito.eq(Vpc.class),
Mockito.anyLong());
+ inOrder.verify(accountManager).checkAccess(Mockito.any(Account.class),
Mockito.isNull(AccessType.class), Mockito.eq(true), Mockito.any(Vpc.class));
+
+ inOrder.verify(networkACLVOMock).setName(name);
+ inOrder.verify(networkACLVOMock).setDescription(description);
+ inOrder.verify(networkACLVOMock).setUuid(customId);
+ inOrder.verify(networkACLVOMock).setDisplay(false);
+
+ inOrder.verify(networkACLDao).update(networkAclListId,
networkACLVOMock);
+ inOrder.verify(networkACLDao).findById(networkAclListId);
+ }
+
+ @Test
+ @PrepareForTest(CallContext.class)
+ public void updateNetworkACLTestParametersWithNullValues() {
+ Mockito.when(updateNetworkACLListCmdMock.getName()).thenReturn(null);
+
Mockito.when(updateNetworkACLListCmdMock.getDescription()).thenReturn(null);
+
Mockito.when(updateNetworkACLListCmdMock.getCustomId()).thenReturn(null);
+
Mockito.when(updateNetworkACLListCmdMock.getId()).thenReturn(networkAclListId);
+
Mockito.when(updateNetworkACLListCmdMock.getDisplay()).thenReturn(null);
+
+ networkACLServiceImpl.updateNetworkACL(updateNetworkACLListCmdMock);
+
+ InOrder inOrder = Mockito.inOrder(networkACLDao, entityManager,
entityManager, accountManager, networkACLVOMock);
+
+ inOrder.verify(networkACLDao).findById(networkAclListId);
+ inOrder.verify(entityManager).findById(Mockito.eq(Vpc.class),
Mockito.anyLong());
+ inOrder.verify(accountManager).checkAccess(Mockito.any(Account.class),
Mockito.isNull(AccessType.class), Mockito.eq(true), Mockito.any(Vpc.class));
+
+ Mockito.verify(networkACLVOMock, Mockito.times(0)).setName(null);
+ inOrder.verify(networkACLVOMock,
Mockito.times(0)).setDescription(null);
+ inOrder.verify(networkACLVOMock, Mockito.times(0)).setUuid(null);
+ inOrder.verify(networkACLVOMock, Mockito.times(0)).setDisplay(false);
+
+ inOrder.verify(networkACLDao).update(networkAclListId,
networkACLVOMock);
+ inOrder.verify(networkACLDao).findById(networkAclListId);
+ }
+}
diff --git a/ui/l10n/ar.js b/ui/l10n/ar.js
index 3b560a86e72..54ba836e624 100644
--- a/ui/l10n/ar.js
+++ b/ui/l10n/ar.js
@@ -313,6 +313,7 @@ var dictionary = {
"label.add.accounts": "????? ??????",
"label.add.accounts.to": "????? ?????? ???",
"label.add.acl.list": "Add ACL List",
+ "label.edit.acl.list": "Edit ACL List",
"label.add.affinity.group": "Add new affinity group",
"label.add.baremetal.dhcp.device": "Add Baremetal DHCP Device",
"label.add.baremetal.rack.configuration": "Add Baremetal Rack
Configuration",
diff --git a/ui/l10n/ca.js b/ui/l10n/ca.js
index f6ae80f81f3..620dad7ae0c 100644
--- a/ui/l10n/ca.js
+++ b/ui/l10n/ca.js
@@ -313,6 +313,7 @@ var dictionary = {
"label.add.accounts": "Afegir comptes",
"label.add.accounts.to": "Afegir comptes a",
"label.add.acl.list": "Add ACL List",
+ "label.edit.acl.list": "Edit ACL List",
"label.add.affinity.group": "Add new affinity group",
"label.add.baremetal.dhcp.device": "Add Baremetal DHCP Device",
"label.add.baremetal.rack.configuration": "Add Baremetal Rack
Configuration",
diff --git a/ui/l10n/de_DE.js b/ui/l10n/de_DE.js
index 934f8f98c09..7c5eb305bef 100644
--- a/ui/l10n/de_DE.js
+++ b/ui/l10n/de_DE.js
@@ -313,6 +313,7 @@ var dictionary = {
"label.add.accounts": "Konten hinzuf?gen",
"label.add.accounts.to": "Konten hinzuf?gen zu",
"label.add.acl.list": "ACL-Liste hinzuf?gen",
+ "label.edit.acl.list": "Edit ACL List",
"label.add.affinity.group": "Neue Affinit?tsgruppe hinzuf?gen",
"label.add.baremetal.dhcp.device": "Baremetal DHCP-Ger?t hinzuf?gen",
"label.add.baremetal.rack.configuration": "Baremetal Rackkonfiguration
hinzuf?gen",
diff --git a/ui/l10n/en.js b/ui/l10n/en.js
index 7b19946b1ed..6e9d7d49603 100644
--- a/ui/l10n/en.js
+++ b/ui/l10n/en.js
@@ -314,6 +314,7 @@ var dictionary = {"ICMP.code":"ICMP Code",
"label.add.accounts":"Add accounts",
"label.add.accounts.to":"Add accounts to",
"label.add.acl.list":"Add ACL List",
+"label.edit.acl.list": "Edit ACL List",
"label.add.affinity.group":"Add new affinity group",
"label.add.baremetal.dhcp.device":"Add Baremetal DHCP Device",
"label.add.baremetal.rack.configuration":"Add Baremetal Rack Configuration",
diff --git a/ui/l10n/es.js b/ui/l10n/es.js
index 35257d47989..9cf79aa0bf0 100644
--- a/ui/l10n/es.js
+++ b/ui/l10n/es.js
@@ -313,6 +313,7 @@ var dictionary = {
"label.add.accounts": "Agregar Cuentas",
"label.add.accounts.to": "Agregar Cuentas a",
"label.add.acl.list": "Agregar Lista ACL",
+ "label.edit.acl.list": "Edit ACL List",
"label.add.affinity.group": "Agregar un nuevo grupo de afinidad",
"label.add.baremetal.dhcp.device": "Agregar dispositivo DHCP Baremetal",
"label.add.baremetal.rack.configuration": "Agregar Configuraci?n de Rack
Baremetal",
diff --git a/ui/l10n/fr_FR.js b/ui/l10n/fr_FR.js
index 9935a818021..ae9e503d74d 100644
--- a/ui/l10n/fr_FR.js
+++ b/ui/l10n/fr_FR.js
@@ -313,6 +313,7 @@ var dictionary = {
"label.add.accounts": "Ajouter des comptes",
"label.add.accounts.to": "Ajouter des comptes sur",
"label.add.acl.list": "Ajouter Liste ACL",
+ "label.edit.acl.list": "Edit ACL List",
"label.add.affinity.group": "Ajouter nouveau groupe d'affinit?",
"label.add.baremetal.dhcp.device": "Ajouter un DHCP Baremetal",
"label.add.baremetal.rack.configuration": "Ajouter Configuration Rack
Baremetal",
diff --git a/ui/l10n/hu.js b/ui/l10n/hu.js
index 912ecf9a49d..4ac6255d032 100644
--- a/ui/l10n/hu.js
+++ b/ui/l10n/hu.js
@@ -313,6 +313,7 @@ var dictionary = {
"label.add.accounts": "Sz?ml?k felv?tele",
"label.add.accounts.to": "Sz?mla felv?tele:",
"label.add.acl.list": "ACL lista felv?tele",
+ "label.edit.acl.list": "Edit ACL List",
"label.add.affinity.group": "?j affin?t?si csoport felv?tele",
"label.add.baremetal.dhcp.device": "Baremetal DHCP eszk?z felv?tele",
"label.add.baremetal.rack.configuration": "Baremetal rack konfigur?ci?
felv?tele",
diff --git a/ui/l10n/it_IT.js b/ui/l10n/it_IT.js
index f725584e08b..18c77553088 100644
--- a/ui/l10n/it_IT.js
+++ b/ui/l10n/it_IT.js
@@ -313,6 +313,7 @@ var dictionary = {
"label.add.accounts": "Aggiungere utenti",
"label.add.accounts.to": "Aggiungere utenti a",
"label.add.acl.list": "Add ACL List",
+ "label.edit.acl.list": "Edit ACL List",
"label.add.affinity.group": "Aggiungere un nuovo gruppo di affinit?",
"label.add.baremetal.dhcp.device": "Add Baremetal DHCP Device",
"label.add.baremetal.rack.configuration": "Add Baremetal Rack
Configuration",
diff --git a/ui/l10n/ja_JP.js b/ui/l10n/ja_JP.js
index 40cf38fd857..f884b8eca6e 100644
--- a/ui/l10n/ja_JP.js
+++ b/ui/l10n/ja_JP.js
@@ -313,6 +313,7 @@ var dictionary = {
"label.add.accounts": "????????",
"label.add.accounts.to": "?????????:",
"label.add.acl.list": "ACL ?????",
+ "label.edit.acl.list": "Edit ACL List",
"label.add.affinity.group": "????????? ???????",
"label.add.baremetal.dhcp.device": "????? DHCP ???????",
"label.add.baremetal.rack.configuration": "?????????????",
diff --git a/ui/l10n/ko_KR.js b/ui/l10n/ko_KR.js
index f6980bc067e..c28fb4fa62e 100644
--- a/ui/l10n/ko_KR.js
+++ b/ui/l10n/ko_KR.js
@@ -313,6 +313,7 @@ var dictionary = {
"label.add.accounts": "?? ?? ??",
"label.add.accounts.to": "?? ?? ??:",
"label.add.acl.list": "Add ACL List",
+ "label.edit.acl.list": "Edit ACL List",
"label.add.affinity.group": "Add new affinity group",
"label.add.baremetal.dhcp.device": "Add Baremetal DHCP Device",
"label.add.baremetal.rack.configuration": "Add Baremetal Rack
Configuration",
diff --git a/ui/l10n/nb_NO.js b/ui/l10n/nb_NO.js
index 28cd09c3b9a..f71e135e813 100644
--- a/ui/l10n/nb_NO.js
+++ b/ui/l10n/nb_NO.js
@@ -313,6 +313,7 @@ var dictionary = {
"label.add.accounts": "Legg til kontoer",
"label.add.accounts.to": "Legg kontoer til",
"label.add.acl.list": "Legg til ACL liste",
+ "label.edit.acl.list": "Edit ACL List",
"label.add.affinity.group": "Legg til affinitetsgruppe",
"label.add.baremetal.dhcp.device": "Legg Til Barmetall DHCP Enhet",
"label.add.baremetal.rack.configuration": "Legg Til Barmetall Rack
Konfigurering",
diff --git a/ui/l10n/nl_NL.js b/ui/l10n/nl_NL.js
index 4508241ad30..1c5449c2c67 100644
--- a/ui/l10n/nl_NL.js
+++ b/ui/l10n/nl_NL.js
@@ -313,6 +313,7 @@ var dictionary = {
"label.add.accounts": "Voeg accounts toe",
"label.add.accounts.to": "Voeg accounts toe aan",
"label.add.acl.list": "voeg een ACL lijst toe",
+ "label.edit.acl.list": "Edit ACL List",
"label.add.affinity.group": "Nieuwe affinity groep toevoegen",
"label.add.baremetal.dhcp.device": "Voeg Baremetal DHCP Apparaat toe",
"label.add.baremetal.rack.configuration": "voeg baremetal rek configuratie
toe",
diff --git a/ui/l10n/pl.js b/ui/l10n/pl.js
index 30c04b9ff75..6467f2670ea 100644
--- a/ui/l10n/pl.js
+++ b/ui/l10n/pl.js
@@ -313,6 +313,7 @@ var dictionary = {
"label.add.accounts": "Dodaj konta",
"label.add.accounts.to": "Dodaj konto do",
"label.add.acl.list": "Add ACL List",
+ "label.edit.acl.list": "Edit ACL List",
"label.add.affinity.group": "Add new affinity group",
"label.add.baremetal.dhcp.device": "Add Baremetal DHCP Device",
"label.add.baremetal.rack.configuration": "Add Baremetal Rack
Configuration",
diff --git a/ui/l10n/pt_BR.js b/ui/l10n/pt_BR.js
index ccfa59ae7d3..1aa9e2cff5e 100644
--- a/ui/l10n/pt_BR.js
+++ b/ui/l10n/pt_BR.js
@@ -313,6 +313,7 @@ var dictionary = {
"label.add.accounts": "Adicionar contas",
"label.add.accounts.to": "Adicionar contas para",
"label.add.acl.list": "Adiciona Lista ACL",
+ "label.edit.acl.list": "Editar Lista ACL",
"label.add.affinity.group": "Adicionar um grupo de afinidade",
"label.add.baremetal.dhcp.device": "Adiciona Dispositivo DHCP Baremetal",
"label.add.baremetal.rack.configuration": "Adicionar Configura??o de Rack
de Baremetal",
diff --git a/ui/l10n/ru_RU.js b/ui/l10n/ru_RU.js
index 6a11b38a0f7..a5973ae5ded 100644
--- a/ui/l10n/ru_RU.js
+++ b/ui/l10n/ru_RU.js
@@ -313,6 +313,7 @@ var dictionary = {
"label.add.accounts": "???????? ??????? ??????",
"label.add.accounts.to": "???????? ??????? ??????",
"label.add.acl.list": "Add ACL List",
+ "label.edit.acl.list": "Edit ACL List",
"label.add.affinity.group": "???????? ????? affinity group",
"label.add.baremetal.dhcp.device": "Add Baremetal DHCP Device",
"label.add.baremetal.rack.configuration": "Add Baremetal Rack
Configuration",
diff --git a/ui/l10n/zh_CN.js b/ui/l10n/zh_CN.js
index dc44fdb9a96..96728d1528e 100644
--- a/ui/l10n/zh_CN.js
+++ b/ui/l10n/zh_CN.js
@@ -313,6 +313,7 @@ var dictionary = {
"label.add.accounts": "????",
"label.add.accounts.to": "?????",
"label.add.acl.list": "?? ACL ??",
+ "label.edit.acl.list": "Edit ACL List",
"label.add.affinity.group": "???????",
"label.add.baremetal.dhcp.device": "???? DHCP ??",
"label.add.baremetal.rack.configuration": "?? Baremetal Rack ??",
diff --git a/ui/scripts/ui/widgets/detailView.js
b/ui/scripts/ui/widgets/detailView.js
index 2ce72a25789..350ee839a4e 100644
--- a/ui/scripts/ui/widgets/detailView.js
+++ b/ui/scripts/ui/widgets/detailView.js
@@ -606,7 +606,7 @@
} else {
$loading.appendTo($detailView);
cloudStack.ui.notifications.add(
- $.extend(true, {},
action.notification, notificationArgs),
+ $.extend(true, {}, notificationArgs,
action.notification),
function(args) {
replaceListViewItem($detailView,
data);
diff --git a/ui/scripts/vpc.js b/ui/scripts/vpc.js
index 14e41af2b23..23f63b72c6a 100644
--- a/ui/scripts/vpc.js
+++ b/ui/scripts/vpc.js
@@ -1286,6 +1286,37 @@
notification: {
poll: pollAsyncJobResult
}
+ },
+ edit: {
+ label: 'label.edit.acl.list',
+ action: function(args) {
+ var data = args.data;
+ data.id = args.context.aclLists[0].id;
+ $.ajax({
+ url: createURL('updateNetworkACLList'),
+ type: "POST",
+ data: data,
+ success: function(json) {
+ var jid =
json.updatenetworkacllistresponse.jobid;
+ args.response.success({
+ _custom: {
+ jobId: jid,
+ getUpdatedItem: function()
{
+
$(window).trigger('cloudStack.fullRefresh');
+
jQuery('div[id=breadcrumbs] ul:visible li span').last().html(data.name);
+ }
+ }
+ });
+ },
+ error: function(json) {
+
args.response.error(parseXMLHttpResponse(json));
+ }
+ });
+ },
+ notification: {
+ poll: pollAsyncJobResult,
+ desc: 'label.edit.acl.list'
+ }
}
},
@@ -1298,7 +1329,8 @@
isEditable: true
},
description: {
- label: 'label.description'
+ label: 'label.description',
+ isEditable: true
},
id: {
label: 'label.id'
@@ -1313,6 +1345,7 @@
var allowedActions = [];
if (items.vpcid != null) {
allowedActions.push("remove");
+
allowedActions.push("edit");
}
return allowedActions;
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services