Add more neutron network IT cases 18/24018/2
authorRyan Moats <rmoats@us.ibm.com>
Fri, 10 Jul 2015 20:06:47 +0000 (15:06 -0500)
committerRyan Moats <rmoats@us.ibm.com>
Fri, 10 Jul 2015 20:45:42 +0000 (15:45 -0500)
This patch is a cadidate for cherry picking to stable/lithium.
However, it changes the semantics of the canNetworkBeUpdated
part of the INetworkAware interface and so before we change
that, we need to communicate with other projects.

Change-Id: Ie9c3774fb98ebdb044d9523477bc0fb3112beaba
Signed-off-by: Ryan Moats <rmoats@us.ibm.com>
integration/test/src/test/java/org/opendaylight/neutron/e2etest/ITNeutronE2E.java
integration/test/src/test/java/org/opendaylight/neutron/e2etest/NeutronNetworkTests.java
northbound-api/src/main/java/org/opendaylight/neutron/northbound/api/NeutronNetworksNorthbound.java
transcriber/src/main/java/org/opendaylight/neutron/transcriber/NeutronNetworkInterface.java

index 77e3adc7bd5f61636214c55e4fa51a945f916c6a..633c7bc4bfcec673d68cd096a460635c55c736a1 100644 (file)
@@ -89,6 +89,11 @@ public class ITNeutronE2E {
         network_tester.network_collection_get_test();
         network_tester.singleton_network_create_test();
        network_tester.external_network_create_test(); //needed for router test
+        network_tester.bulk_network_create_test();
+        network_tester.network_update_test();
+        network_tester.network_element_get_test();
+        network_tester.network_delete_test();
+        network_tester.network_element_negative_get_test();
 
         NeutronSubnetTests subnet_tester = new NeutronSubnetTests(base);
         subnet_tester.subnet_collection_get_test();
@@ -233,6 +238,21 @@ public class ITNeutronE2E {
         }
     }
 
+    static void test_fetch(String url_s, boolean positiveTest, String context) {
+        try {
+            URL url = new URL(url_s);
+            HttpURLConnection httpConn = HttpURLConnectionFactoryGet(url);
+            if (positiveTest) {
+                Assert.assertEquals(context, 200, httpConn.getResponseCode());
+            } else {
+                Assert.assertEquals(context, 404, httpConn.getResponseCode());
+            }
+        } catch (Exception e) {
+            e.printStackTrace(); // temporary, remove me
+            Assert.assertFalse("E2E Tests Failed", true);
+        }
+    }
+
     static void test_delete(String url_s, String context) {
         try {
             URL url = new URL(url_s);
index 4ad302938afbada386ee85ebda5fc9dcbf3294fd..2c7ee4bcd4d74bfd5b9ffdc8971584050c12779f 100644 (file)
@@ -78,4 +78,62 @@ public class NeutronNetworkTests {
             " \"id\": \"8ca37218-28ff-41cb-9b10-039601ea7e6b\" } } ";
         ITNeutronE2E.test_create(url, content,"External Network Post Failed NB");
     }
+
+    //TODO handle SB check
+    public void bulk_network_create_test() {
+        String url = base + "/networks";
+        String content = "{ \"networks\": [ { "
+            + "\"status\": \"ACTIVE\", \"subnets\": [], "
+            + "\"name\": \"sample_network3\", "
+            + "\"provider:physical_network\": null, "
+            + "\"admin_state_up\": true, "
+            + "\"tenant_id\": \"4fd44f30292945e481c7b8a0c8908869\", "
+            + "\"provider:network_type\": \"local\", "
+            + "\"shared\": false, "
+            + "\"id\": \"bc1a76cb-8767-4c3a-bb95-018b822f2130\", "
+            + "\"provider:segmentation_id\": null }, { "
+            + "\"status\": \"ACTIVE\", "
+            + "\"subnets\": [], "
+            + "\"name\": \"sample_network4\", "
+            + "\"provider:physical_network\": null, "
+            + "\"admin_state_up\": true, "
+            + "\"tenant_id\": \"4fd44f30292945e481c7b8a0c8908869\", "
+            + "\"provider:network_type\": \"local\", "
+            + "\"shared\": false, "
+            + "\"id\": \"af374017-c9ae-4a1d-b799-ab73111476e2\", "
+            + "\"provider:segmentation_id\": null } ] } ";
+        ITNeutronE2E.test_create(url, content,"Bulk Network Post Failed");
+    }
+
+    //TODO handle SB check
+    public void network_update_test() {
+        String url = base + "/networks/bc1a76cb-8767-4c3a-bb95-018b822f2130";
+        String content = " { \"network\": { "
+            +"\"status\": \"ACTIVE\", "
+            +"\"subnets\": [], "
+            +"\"name\": \"sample_network_5_updated\", "
+            +"\"provider:physical_network\": null, "
+            +"\"admin_state_up\": true, "
+            +"\"tenant_id\": \"4fd44f30292945e481c7b8a0c8908869\", "
+            +"\"provider:network_type\": \"local\", "
+            +"\"router:external\": false, "
+            +"\"shared\": false, "
+            +"\"provider:segmentation_id\": null } } ";
+        ITNeutronE2E.test_modify(url, content,"Network Put Failed");
+    }
+   
+    public void network_element_get_test() {
+        String url = base + "/networks/bc1a76cb-8767-4c3a-bb95-018b822f2130";
+        ITNeutronE2E.test_fetch(url, true ,"Network Element Get Failed");
+    }
+
+    public void network_element_negative_get_test() {
+        String url = base + "/networks/bc1a76cb-8767-4c3a-bb95-018b822f2130";
+        ITNeutronE2E.test_fetch(url, false ,"Network Element Negative Get Failed");
+    }
+
+    public void network_delete_test() {
+        String url = base + "/networks/bc1a76cb-8767-4c3a-bb95-018b822f2130";
+        ITNeutronE2E.test_delete(url, "Network Element Delete Failed");
+    }
 }
index 87e12e1974770441b24e3b525c9f5d90d7e3b5fa..f6e0bc8d4025cbd81e7d397738b9a3c38d3c673a 100644 (file)
@@ -315,7 +315,7 @@ public class NeutronNetworksNorthbound {
         INeutronNetworkCRUD networkInterface = getNeutronInterfaces().getNetworkInterface();
 
         /*
-         * network has to exist and only a single delta is supported
+         * network has to exist and only a single object is supported
          */
         if (!networkInterface.networkExists(netUUID)) {
             throw new ResourceNotFoundException(UUID_NO_EXIST);
@@ -323,23 +323,23 @@ public class NeutronNetworksNorthbound {
         if (!input.isSingleton()) {
             throw new BadRequestException("only singleton edits supported");
         }
-        NeutronNetwork delta = input.getSingleton();
+        NeutronNetwork updatedObject = input.getSingleton();
 
         /*
-         * transitions forbidden by Neutron
+         *  note: what we get appears to not be a delta but 
+         * rather an incomplete updated object.  So we need to set
+         * the ID to complete the object and then send that down
+         * for folks to check
          */
-        if (delta.getID() != null || delta.getTenantID() != null ||
-                delta.getStatus() != null) {
-            throw new BadRequestException("attribute edit blocked by Neutron");
-        }
 
+        updatedObject.setID(netUUID);
         Object[] instances = NeutronUtil.getInstances(INeutronNetworkAware.class, this);
         if (instances != null) {
             if (instances.length > 0) {
                 for (Object instance : instances) {
                     INeutronNetworkAware service = (INeutronNetworkAware) instance;
                     NeutronNetwork original = networkInterface.getNetwork(netUUID);
-                    int status = service.canUpdateNetwork(delta, original);
+                    int status = service.canUpdateNetwork(updatedObject, original);
                     if (status < HTTP_OK_BOTTOM || status > HTTP_OK_TOP) {
                         return Response.status(status).build();
                     }
@@ -351,17 +351,16 @@ public class NeutronNetworksNorthbound {
             throw new ServiceUnavailableException(NO_PROVIDER_LIST);
         }
 
-        // update network object and return the modified object
-                networkInterface.updateNetwork(netUUID, delta);
-                NeutronNetwork updatedSingleton = networkInterface.getNetwork(netUUID);
-                if (instances != null) {
-                    for (Object instance : instances) {
-                        INeutronNetworkAware service = (INeutronNetworkAware) instance;
-                        service.neutronNetworkUpdated(updatedSingleton);
-                    }
-                }
-                return Response.status(HttpURLConnection.HTTP_OK).entity(
-                        new NeutronNetworkRequest(networkInterface.getNetwork(netUUID))).build();
+        // update network object 
+        networkInterface.updateNetwork(netUUID, updatedObject);
+        if (instances != null) {
+            for (Object instance : instances) {
+                INeutronNetworkAware service = (INeutronNetworkAware) instance;
+                service.neutronNetworkUpdated(updatedObject);
+            }
+        }
+        return Response.status(HttpURLConnection.HTTP_OK).entity(
+                new NeutronNetworkRequest(networkInterface.getNetwork(netUUID))).build();
     }
 
     /**
index b5b6dcf67fdabc7b0e54fdd2e0ad58676bf3644f..909987ba21f2c52428770d0725a2cda8f544a8a7 100644 (file)
@@ -91,12 +91,12 @@ public class NeutronNetworkInterface extends AbstractNeutronInterface<Network,Ne
         if (!networkExists(uuid)) {
             return false;
         }
-        NeutronNetwork target = networkDB.get(uuid);
-        boolean rc = overwrite(target, delta);
-        if (rc) {
-            updateMd(networkDB.get(uuid));
-        }
-        return rc;
+/* note: because what we get is *not* a delta but (at this point) the updated
+ * object, this is much simpler - just replace the value and update the mdsal
+ * with it */
+        networkDB.replace(uuid, delta);
+        updateMd(delta);
+        return true;
     }
 
     @Override