mirror of https://github.com/apache/cloudstack.git
fix: NsxResource.executeRequest DeleteNsxNatRuleCommand comparison bug (#12833)
Fixes an issue in NsxResource.executeRequest where Network.Service comparison failed when DeleteNsxNatRuleCommand was executed in a different process. Due to serialization/deserialization, the deserialized Network.Service instance was not equal to the static instances Network.Service.StaticNat and Network.Service.PortForwarding, causing the comparison to always return false. Co-authored-by: Andrey Volchkov <avolchkov@playtika.com>
This commit is contained in:
parent
e2d18c0748
commit
30dd234b00
|
|
@ -54,6 +54,13 @@ public class DeleteNsxNatRuleCommand extends NsxNetworkCommand {
|
|||
return protocol;
|
||||
}
|
||||
|
||||
public String getNetworkServiceName() {
|
||||
if (service != null) {
|
||||
return service.getName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
|
|
|
|||
|
|
@ -415,10 +415,10 @@ public class NsxResource implements ServerResource {
|
|||
|
||||
private NsxAnswer executeRequest(DeleteNsxNatRuleCommand cmd) {
|
||||
String ruleName = null;
|
||||
if (cmd.getService() == Network.Service.StaticNat) {
|
||||
if (Network.Service.StaticNat.getName().equals(cmd.getNetworkServiceName())) {
|
||||
ruleName = NsxControllerUtils.getStaticNatRuleName(cmd.getDomainId(), cmd.getAccountId(), cmd.getZoneId(),
|
||||
cmd.getNetworkResourceId(), cmd.isResourceVpc());
|
||||
} else if (cmd.getService() == Network.Service.PortForwarding) {
|
||||
} else if (Network.Service.PortForwarding.getName().equals(cmd.getNetworkServiceName())) {
|
||||
ruleName = NsxControllerUtils.getPortForwardRuleName(cmd.getDomainId(), cmd.getAccountId(), cmd.getZoneId(),
|
||||
cmd.getNetworkResourceId(), cmd.getRuleId(), cmd.isResourceVpc());
|
||||
}
|
||||
|
|
@ -456,7 +456,7 @@ public class NsxResource implements ServerResource {
|
|||
try {
|
||||
nsxApiClient.deleteNsxLbResources(tier1GatewayName, cmd.getLbId());
|
||||
} catch (Exception e) {
|
||||
logger.error(String.format("Failed to add NSX load balancer rule %s for network: %s", ruleName, cmd.getNetworkResourceName()));
|
||||
logger.error(String.format("Failed to delete NSX load balancer rule %s for network: %s", ruleName, cmd.getNetworkResourceName()));
|
||||
return new NsxAnswer(cmd, new CloudRuntimeException(e.getMessage()));
|
||||
}
|
||||
return new NsxAnswer(cmd, true, null);
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
// under the License.
|
||||
package org.apache.cloudstack.resource;
|
||||
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.dao.NetworkVO;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.vmware.nsx.model.TransportZone;
|
||||
|
|
@ -61,6 +62,7 @@ import static org.mockito.ArgumentMatchers.anyLong;
|
|||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
|
|
@ -247,8 +249,12 @@ public class NsxResourceTest {
|
|||
@Test
|
||||
public void testDeleteNsxNatRule() {
|
||||
DeleteNsxNatRuleCommand cmd = new DeleteNsxNatRuleCommand(domainId, accountId, zoneId, 3L, "VPC01", true, 2L, 5L, "22", "tcp");
|
||||
Network.Service service = mock(Network.Service.class);
|
||||
when(service.getName()).thenReturn("PortForwarding");
|
||||
cmd.setService(service);
|
||||
NsxAnswer answer = (NsxAnswer) nsxResource.executeRequest(cmd);
|
||||
assertTrue(answer.getResult());
|
||||
verify(nsxApi).deleteNatRule(service, "22", "tcp", "VPC01", "D1-A2-Z1-V3", "D1-A2-Z1-V3-PF5");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Reference in New Issue