cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wid...@apache.org
Subject [21/50] [abbrv] git commit: updated refs/heads/reporter to 28300b5
Date Wed, 08 Jul 2015 19:19:56 GMT
CLOUDSTACK-8590 - Refactoring NiciraNVP resource

   - Increasing test coverage
     - resource package: 86.7%
     - utils package: 95.1%
     - wrapper package: 97.5%

Signed-off-by: wilderrodrigues <wrodrigues@schubergphilis.com>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/c6013303
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/c6013303
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/c6013303

Branch: refs/heads/reporter
Commit: c6013303e9837c12922fbed28836d34991ec6ab3
Parents: 644458f
Author: wilderrodrigues <wrodrigues@schubergphilis.com>
Authored: Tue Jun 30 12:11:45 2015 +0200
Committer: wilderrodrigues <wrodrigues@schubergphilis.com>
Committed: Wed Jul 1 15:04:58 2015 +0200

----------------------------------------------------------------------
 .../network/resource/NiciraNvpUtilities.java    |   5 +
 ...vpUpdateLogicalSwitchPortCommandWrapper.java |   7 +-
 .../resource/NiciraNvpRequestWrapperTest.java   | 127 +++++++++++++++++++
 .../network/resource/NiciraNvpResourceTest.java |  17 ++-
 4 files changed, 154 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6013303/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/NiciraNvpUtilities.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/NiciraNvpUtilities.java
b/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/NiciraNvpUtilities.java
index 2ac79c8..4edf5c3 100644
--- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/NiciraNvpUtilities.java
+++ b/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/NiciraNvpUtilities.java
@@ -26,6 +26,7 @@ import com.cloud.agent.api.CreateLogicalSwitchPortCommand;
 import com.cloud.network.nicira.LogicalSwitch;
 import com.cloud.network.nicira.LogicalSwitchPort;
 import com.cloud.network.nicira.NiciraNvpTag;
+import com.cloud.network.nicira.VifAttachment;
 
 public class NiciraNvpUtilities {
 
@@ -57,4 +58,8 @@ public class NiciraNvpUtilities {
         final LogicalSwitchPort logicalSwitchPort = new LogicalSwitchPort(attachmentUuid,
tags, true);
         return logicalSwitchPort;
     }
+
+    public VifAttachment createVifAttachment(final String attachmentUuid) {
+        return new VifAttachment(attachmentUuid);
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6013303/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpUpdateLogicalSwitchPortCommandWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpUpdateLogicalSwitchPortCommandWrapper.java
b/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpUpdateLogicalSwitchPortCommandWrapper.java
index 9f65938..a0d7dc2 100644
--- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpUpdateLogicalSwitchPortCommandWrapper.java
+++ b/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/wrapper/NiciraNvpUpdateLogicalSwitchPortCommandWrapper.java
@@ -32,6 +32,7 @@ import com.cloud.network.nicira.NiciraNvpApiException;
 import com.cloud.network.nicira.NiciraNvpTag;
 import com.cloud.network.nicira.VifAttachment;
 import com.cloud.network.resource.NiciraNvpResource;
+import com.cloud.network.resource.NiciraNvpUtilities;
 import com.cloud.network.utils.CommandRetryUtility;
 import com.cloud.resource.CommandWrapper;
 import com.cloud.resource.ResourceWrapper;
@@ -41,6 +42,8 @@ public final class NiciraNvpUpdateLogicalSwitchPortCommandWrapper extends
Comman
 
     @Override
     public Answer execute(final UpdateLogicalSwitchPortCommand command, final NiciraNvpResource
niciraNvpResource) {
+        final NiciraNvpUtilities niciraNvpUtilities = niciraNvpResource.getNiciraNvpUtilities();
+
         final String logicalSwitchUuid = command.getLogicalSwitchUuid();
         final String logicalSwitchPortUuid = command.getLogicalSwitchPortUuid();
         final String attachmentUuid = command.getAttachmentUuid();
@@ -52,7 +55,9 @@ public final class NiciraNvpUpdateLogicalSwitchPortCommandWrapper extends
Comman
             final List<NiciraNvpTag> tags = new ArrayList<NiciraNvpTag>();
             tags.add(new NiciraNvpTag("cs_account", command.getOwnerName()));
 
-            niciraNvpApi.updateLogicalSwitchPortAttachment(logicalSwitchUuid, logicalSwitchPortUuid,
new VifAttachment(attachmentUuid));
+            final VifAttachment vifAttachment = niciraNvpUtilities.createVifAttachment(attachmentUuid);
+
+            niciraNvpApi.updateLogicalSwitchPortAttachment(logicalSwitchUuid, logicalSwitchPortUuid,
vifAttachment);
             return new UpdateLogicalSwitchPortAnswer(command, true, "Attachment for  " +
logicalSwitchPortUuid + " updated", logicalSwitchPortUuid);
         } catch (final NiciraNvpApiException e) {
             final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6013303/plugins/network-elements/nicira-nvp/test/com/cloud/network/resource/NiciraNvpRequestWrapperTest.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/test/com/cloud/network/resource/NiciraNvpRequestWrapperTest.java
b/plugins/network-elements/nicira-nvp/test/com/cloud/network/resource/NiciraNvpRequestWrapperTest.java
index 70e10e1..7fe6287 100644
--- a/plugins/network-elements/nicira-nvp/test/com/cloud/network/resource/NiciraNvpRequestWrapperTest.java
+++ b/plugins/network-elements/nicira-nvp/test/com/cloud/network/resource/NiciraNvpRequestWrapperTest.java
@@ -25,18 +25,28 @@ import static org.junit.Assert.fail;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.when;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.Mockito;
 
 import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.ConfigurePublicIpsOnLogicalRouterCommand;
 import com.cloud.agent.api.CreateLogicalSwitchCommand;
+import com.cloud.agent.api.DeleteLogicalRouterCommand;
 import com.cloud.agent.api.DeleteLogicalSwitchCommand;
+import com.cloud.agent.api.DeleteLogicalSwitchPortCommand;
 import com.cloud.agent.api.MaintainCommand;
 import com.cloud.agent.api.ReadyCommand;
+import com.cloud.agent.api.UpdateLogicalSwitchPortCommand;
+import com.cloud.network.nicira.LogicalRouterPort;
 import com.cloud.network.nicira.LogicalSwitch;
 import com.cloud.network.nicira.NiciraNvpApi;
 import com.cloud.network.nicira.NiciraNvpApiException;
+import com.cloud.network.nicira.NiciraNvpList;
+import com.cloud.network.nicira.VifAttachment;
 
 public class NiciraNvpRequestWrapperTest {
 
@@ -125,4 +135,121 @@ public class NiciraNvpRequestWrapperTest {
 
         assertTrue(answer.getResult());
     }
+
+    @Test
+    public void testConfigurePublicIpsOnLogicalRouterCommand() {
+        final NiciraNvpApi niciraNvpApi = Mockito.mock(NiciraNvpApi.class);
+        final LogicalRouterPort port1 = Mockito.mock(LogicalRouterPort.class);
+
+        final List<LogicalRouterPort> listPorts = new ArrayList<LogicalRouterPort>();
+        listPorts.add(port1);
+
+        final NiciraNvpList<LogicalRouterPort> ports = new NiciraNvpList<LogicalRouterPort>();
+        ports.setResults(listPorts);
+        ports.setResultCount(1);
+
+        final String logicalRouterUuid = "d2e05a9e-7120-4487-a5fc-414ab36d9345";
+        final String l3GatewayServiceUuid  = "d2e05a9e-7120-4487-a5fc-414ab36d9345";
+        final List<String> publicCidrs = new ArrayList<String>();
+        publicCidrs.add("10.1.1.0/24");
+
+        final ConfigurePublicIpsOnLogicalRouterCommand command = new ConfigurePublicIpsOnLogicalRouterCommand(logicalRouterUuid,
l3GatewayServiceUuid, publicCidrs);
+
+        when(niciraNvpResource.getNiciraNvpApi()).thenReturn(niciraNvpApi);
+
+        try {
+            when(niciraNvpApi.findLogicalRouterPortByGatewayServiceUuid(command.getLogicalRouterUuid(),
command.getL3GatewayServiceUuid())).thenReturn(ports);
+            doNothing().when(niciraNvpApi).updateLogicalRouterPort(command.getLogicalRouterUuid(),
port1);
+        } catch (final NiciraNvpApiException e) {
+            fail(e.getMessage());
+        }
+
+        final NiciraNvpRequestWrapper wrapper = NiciraNvpRequestWrapper.getInstance();
+        assertNotNull(wrapper);
+
+        final Answer answer = wrapper.execute(command, niciraNvpResource);
+
+        assertTrue(answer.getResult());
+    }
+
+    @Test
+    public void testDeleteLogicalSwitchPortCommand() {
+        final NiciraNvpApi niciraNvpApi = Mockito.mock(NiciraNvpApi.class);
+
+        final String logicalSwitchUuid = "d2e05a9e-7120-4487-a5fc-414ab36d9345";
+        final String logicalSwitchPortUuid  = "d2e05a9e-7120-4487-a5fc-414ab36d9345";
+
+        final DeleteLogicalSwitchPortCommand command = new DeleteLogicalSwitchPortCommand(logicalSwitchUuid,
logicalSwitchPortUuid);
+
+        when(niciraNvpResource.getNiciraNvpApi()).thenReturn(niciraNvpApi);
+
+        try {
+            doNothing().when(niciraNvpApi).deleteLogicalSwitchPort(command.getLogicalSwitchUuid(),
command.getLogicalSwitchPortUuid());
+        } catch (final NiciraNvpApiException e) {
+            fail(e.getMessage());
+        }
+
+        final NiciraNvpRequestWrapper wrapper = NiciraNvpRequestWrapper.getInstance();
+        assertNotNull(wrapper);
+
+        final Answer answer = wrapper.execute(command, niciraNvpResource);
+
+        assertTrue(answer.getResult());
+    }
+
+    @Test
+    public void testDeleteLogicalRouterCommand() {
+        final NiciraNvpApi niciraNvpApi = Mockito.mock(NiciraNvpApi.class);
+
+        final String logicalRouterUuid = "d2e05a9e-7120-4487-a5fc-414ab36d9345";
+
+        final DeleteLogicalRouterCommand command = new DeleteLogicalRouterCommand(logicalRouterUuid);
+
+        when(niciraNvpResource.getNiciraNvpApi()).thenReturn(niciraNvpApi);
+
+        try {
+            doNothing().when(niciraNvpApi).deleteLogicalRouter(command.getLogicalRouterUuid());
+        } catch (final NiciraNvpApiException e) {
+            fail(e.getMessage());
+        }
+
+        final NiciraNvpRequestWrapper wrapper = NiciraNvpRequestWrapper.getInstance();
+        assertNotNull(wrapper);
+
+        final Answer answer = wrapper.execute(command, niciraNvpResource);
+
+        assertTrue(answer.getResult());
+    }
+
+    @Test
+    public void testUpdateLogicalSwitchPortCommand() {
+        final NiciraNvpApi niciraNvpApi = Mockito.mock(NiciraNvpApi.class);
+        final NiciraNvpUtilities niciraNvpUtilities = Mockito.mock(NiciraNvpUtilities.class);
+        final VifAttachment vifAttachment = Mockito.mock(VifAttachment.class);
+
+        final String logicalSwitchPortUuid = "d2e05a9e-7120-4487-a5fc-414ab36d9345";
+        final String logicalSwitchUuid = "d2e05a9e-7120-4487-a5fc-414ab36d9345";
+        final String attachmentUuid = "d2e05a9e-7120-4487-a5fc-414ab36d9345";
+        final String ownerName = "admin";
+        final String nicName = "eth0";
+
+        final UpdateLogicalSwitchPortCommand command = new UpdateLogicalSwitchPortCommand(logicalSwitchPortUuid,
logicalSwitchUuid, attachmentUuid, ownerName, nicName);
+
+        when(niciraNvpResource.getNiciraNvpUtilities()).thenReturn(niciraNvpUtilities);
+        when(niciraNvpResource.getNiciraNvpApi()).thenReturn(niciraNvpApi);
+
+        try {
+            when(niciraNvpUtilities.createVifAttachment(attachmentUuid)).thenReturn(vifAttachment);
+            doNothing().when(niciraNvpApi).updateLogicalSwitchPortAttachment(logicalSwitchUuid,
logicalSwitchPortUuid, vifAttachment);
+        } catch (final NiciraNvpApiException e) {
+            fail(e.getMessage());
+        }
+
+        final NiciraNvpRequestWrapper wrapper = NiciraNvpRequestWrapper.getInstance();
+        assertNotNull(wrapper);
+
+        final Answer answer = wrapper.execute(command, niciraNvpResource);
+
+        assertTrue(answer.getResult());
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6013303/plugins/network-elements/nicira-nvp/test/com/cloud/network/resource/NiciraNvpResourceTest.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/test/com/cloud/network/resource/NiciraNvpResourceTest.java
b/plugins/network-elements/nicira-nvp/test/com/cloud/network/resource/NiciraNvpResourceTest.java
index ccee017..ddf2993 100644
--- a/plugins/network-elements/nicira-nvp/test/com/cloud/network/resource/NiciraNvpResourceTest.java
+++ b/plugins/network-elements/nicira-nvp/test/com/cloud/network/resource/NiciraNvpResourceTest.java
@@ -432,8 +432,23 @@ public class NiciraNvpResourceTest {
 
         when(cmd.getLogicalRouterUuid()).thenReturn("aaaaa");
         when(cmd.getL3GatewayServiceUuid()).thenReturn("bbbbb");
-        doThrow(new NiciraNvpApiException()).when(nvpApi).updateLogicalRouterPort((String)any(),
(LogicalRouterPort)any());
         when(nvpApi.findLogicalRouterPortByGatewayServiceUuid("aaaaa", "bbbbb")).thenReturn(list);
+        doThrow(new NiciraNvpApiException()).when(nvpApi).updateLogicalRouterPort((String)any(),
(LogicalRouterPort)any());
+
+        final ConfigurePublicIpsOnLogicalRouterAnswer answer = (ConfigurePublicIpsOnLogicalRouterAnswer)resource.executeRequest(cmd);
+        assertFalse(answer.getResult());
+
+    }
+
+    @Test
+    public void testConfigurePublicIpsOnLogicalRouterRetry() throws ConfigurationException,
NiciraNvpApiException {
+        resource.configure("NiciraNvpResource", parameters);
+
+        final ConfigurePublicIpsOnLogicalRouterCommand cmd = mock(ConfigurePublicIpsOnLogicalRouterCommand.class);
+
+        when(cmd.getLogicalRouterUuid()).thenReturn("aaaaa");
+        when(cmd.getL3GatewayServiceUuid()).thenReturn("bbbbb");
+        when(nvpApi.findLogicalRouterPortByGatewayServiceUuid("aaaaa", "bbbbb")).thenThrow(new
NiciraNvpApiException("retry 1")).thenThrow(new NiciraNvpApiException("retry 2"));
 
         final ConfigurePublicIpsOnLogicalRouterAnswer answer = (ConfigurePublicIpsOnLogicalRouterAnswer)resource.executeRequest(cmd);
         assertFalse(answer.getResult());


Mime
View raw message