Bug 6938 - Handle unknown protocol name as bad request 96/47096/1
authorRitu Sood <ritu.sood@intel.com>
Tue, 18 Oct 2016 01:32:54 +0000 (18:32 -0700)
committerRitu Sood <ritu.sood@intel.com>
Tue, 18 Oct 2016 01:32:54 +0000 (18:32 -0700)
Fwaas, security group rule handled unknown protocol
name as internal server error. Changed that to respond
with bad request. lbaas ignored the wrong protocol field.
Also chaged that to respond with bad request.

Change-Id: I681d67b8704015b392ee811b0f4b1556a63b5809
Signed-off-by: Ritu Sood <ritu.sood@intel.com>
integration/test/src/test/java/org/opendaylight/neutron/e2etest/NeutronFirewallRuleTests.java
integration/test/src/test/java/org/opendaylight/neutron/e2etest/NeutronLBListenerTests.java
integration/test/src/test/java/org/opendaylight/neutron/e2etest/NeutronSecurityRuleTests.java
transcriber/src/main/java/org/opendaylight/neutron/transcriber/NeutronFirewallRuleInterface.java
transcriber/src/main/java/org/opendaylight/neutron/transcriber/NeutronLoadBalancerListenerInterface.java
transcriber/src/main/java/org/opendaylight/neutron/transcriber/NeutronSecurityRuleInterface.java

index 7d29c0257e6a9c359dd209eb6680f4334fea111e..93a37fcf17b6e6e5df860df22a08502b14ce831c 100644 (file)
@@ -76,6 +76,19 @@ public class NeutronFirewallRuleTests {
         ITNeutronE2E.test_fetch(url, false, "Firewall Rule Element Negative Get Failed");
     }
 
+    public String test_bug6398_fw_rule_create_test() {
+        String url = base + "/fw/firewall_rules";
+        String content = "{ \"firewall_rule\": { \"action\": \"allow\"," + "\"destination_ip_address\": null,"
+                + "\"destination_port_min\": \"80\", \"destination_port_max\": \"80\"," + "\"enabled\": true,"
+                + "\"firewall_policy_id\": null," + "\"id\": \"8722e0e0-9cc9-4490-9660-8c9a5732fbb0\","
+                + "\"ip_version\": 4, \"name\": \"ALLOW_HTTP\"," + "\"position\": null, \"protocol\": \"TCP\","
+                + "\"shared\": false, \"source_ip_address\": null,"
+                + "\"source_port_min\": null, \"source_port_max\": null,"
+                + "\"tenant_id\": \"45977fa2dbd7482098dd68d0d8970117\" } }";
+        ITNeutronE2E.test_create(url, 400, content, "Firewall Rule Singleton Post Bug 6398 regressed");
+        return content;
+    }
+
     public static void runTests(String base) {
         NeutronFirewallRuleTests fw_rule_tester = new NeutronFirewallRuleTests(base);
         String createJsonString = fw_rule_tester.singleton_fw_rule_create_test();
@@ -86,5 +99,6 @@ public class NeutronFirewallRuleTests {
         fw_rule_tester.fw_rule_modify_test();
         fw_rule_tester.fw_rule_delete_test();
         fw_rule_tester.fw_rule_element_negative_get_test();
+        fw_rule_tester.test_bug6398_fw_rule_create_test();
     }
 }
index 57887a3c6e652ffb197c5518ecb7f4a1d197412a..0ed164c0127b5746173cad6f519070f38731f60f 100644 (file)
@@ -72,6 +72,18 @@ public class NeutronLBListenerTests {
         ITNeutronE2E.test_delete(url, "LB Listener Element Delete Failed");
     }
 
+    public String test_bug6398_lb_listener_create_test() {
+        String url = base + "/lbaas/listeners";
+        String content = "{ \"listener\": { " + "\"admin_state_up\": true, " + "\"connection_limit\": 100, "
+                + "\"default_pool_id\": null, " + "\"description\": \"listener one\", "
+                + "\"id\": \"39de4d56-d663-46e5-85a1-5b9d5fa17829\", " + "\"loadbalancers\": [ { "
+                + "\"id\": \"a36c20d0-18e9-42ce-88fd-82a35977ee8c\" } ], " + "\"name\": \"listener1\", "
+                + "\"protocol\": \"http\", " + "\"protocol_port\": 80, "
+                + "\"tenant_id\": \"b7c1a69e88bf4b21a8148f787aef2081\" } }";
+        ITNeutronE2E.test_create(url, 400, content, "LB Listener Post Bug 6398 regressed");
+        return content;
+    }
+
     public static void runTests(String base) {
         NeutronLBListenerTests listener_tester = new NeutronLBListenerTests(base);
         String createJsonString = listener_tester.singleton_lb_listener_create_test();
@@ -82,5 +94,6 @@ public class NeutronLBListenerTests {
         listener_tester.listener_collection_get_test();
         listener_tester.listener_delete_test();
         listener_tester.listener_element_negative_get_test();
+        listener_tester.test_bug6398_lb_listener_create_test();
     }
 }
index b7c690e9cea13bc7ecc17e461d1b11b99b19f25f..a9dc42c9bb43732d2445a7150139fb2de19a1ada 100644 (file)
@@ -126,6 +126,17 @@ public class NeutronSecurityRuleTests {
         ITNeutronE2E.test_delete(url, "Security Rule Delete Failed");
     }
 
+    public String bug6398_sr_create_test() {
+        String url = base + "/security-group-rules";
+        String content = " {\"security_group_rule\": " + "{\"remote_group_id\": null, \"direction\": \"ingress\", "
+                + "\"remote_ip_prefix\": null, \"protocol\": \"TCP\", " + "\"ethertype\": \"IPv6\", \"tenant_id\": "
+                + "\"00f340c7c3b34ab7be1fc690c05a0275\", \"port_range_max\": 77, " + "\"port_range_min\": 77, "
+                + "\"id\": \"9b4be7fa-e56e-40fb-9516-1f0fa9185669\", " + "\"security_group_id\": "
+                + "\"b60490fe-60a5-40be-af63-1d641381b784\"}}";
+        ITNeutronE2E.test_create(url, 400, content, "Security Rule Singleton Post Bug 6398 regressed");
+        return content;
+    }
+
     public static void runTests(String base) {
         NeutronSecurityRuleTests securityRule_tester = new NeutronSecurityRuleTests(base);
         String createJsonString = securityRule_tester.singleton_sr_create_test();
@@ -140,5 +151,6 @@ public class NeutronSecurityRuleTests {
         securityRule_tester.bug5478_rule_delete_negative_test();
         securityRule_tester.bug4043_ipv4_test();
         securityRule_tester.bug4043_ipv6_test();
+        securityRule_tester.bug6398_sr_create_test();
     }
 }
index ef888635e08e7680364fc22ba533ebb9d7ac056e..f65a70e6412a165aaf9e42bd786edd1e0bc0f527 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.neutron.transcriber;
 import com.google.common.collect.ImmutableBiMap;
 import java.util.List;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.neutron.northbound.api.BadRequestException;
 import org.opendaylight.neutron.spi.INeutronFirewallRuleCRUD;
 import org.opendaylight.neutron.spi.NeutronFirewallRule;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.IpVersionBase;
@@ -118,8 +119,13 @@ public final class NeutronFirewallRuleInterface
         }
         if (rule.getFirewallRuleProtocol() != null) {
             final String protocolString = rule.getFirewallRuleProtocol();
-            final Protocol protocol = new Protocol(protocolString.toCharArray());
-            ruleBuilder.setProtocol(protocol);
+            try {
+                final Protocol protocol = new Protocol(protocolString.toCharArray());
+                ruleBuilder.setProtocol(protocol);
+            } catch (NumberFormatException e) {
+                throw new BadRequestException("Protocol {" + rule.getFirewallRuleProtocol()
+                        + "} is not supported");
+            }
         }
         if (rule.getFirewallRuleIpVer() != null) {
             final ImmutableBiMap<Integer, Class<? extends IpVersionBase>> mapper = IP_VERSION_MAP.inverse();
index f98ac24ff0ce0d5335320aa5717a230e4e63225d..7354b4d03b0010800959d3889a14e3148a0da37e 100644 (file)
@@ -12,6 +12,7 @@ import com.google.common.collect.ImmutableBiMap;
 import java.util.ArrayList;
 import java.util.List;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.neutron.northbound.api.BadRequestException;
 import org.opendaylight.neutron.spi.INeutronLoadBalancerListenerCRUD;
 import org.opendaylight.neutron.spi.NeutronLoadBalancerListener;
 import org.opendaylight.neutron.spi.Neutron_ID;
@@ -67,8 +68,13 @@ public final class NeutronLoadBalancerListenerInterface
         }
         if (listener.getNeutronLoadBalancerListenerProtocol() != null) {
             final ImmutableBiMap<String, Class<? extends ProtocolBase>> mapper = PROTOCOL_MAP.inverse();
-            listenerBuilder.setProtocol(
-                    (Class<? extends ProtocolBase>) mapper.get(listener.getNeutronLoadBalancerListenerProtocol()));
+            Class<? extends ProtocolBase> protocol = mapper.get(listener.getNeutronLoadBalancerListenerProtocol());
+            if (protocol != null) {
+                listenerBuilder.setProtocol(protocol);
+            } else {
+                throw new BadRequestException("Protocol {" + listener.getNeutronLoadBalancerListenerProtocol()
+                        + "} is not supported");
+            }
         }
         if (listener.getNeutronLoadBalancerListenerProtocolPort() != null) {
             listenerBuilder.setProtocolPort(Integer.valueOf(listener.getNeutronLoadBalancerListenerProtocolPort()));
index f3440452dc33b589e23f0ea79fc4d3fcfc61fdd6..a35ec17cbaaa1b7ac28f0611c2bc5d5b67a60797 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.neutron.transcriber;
 import com.google.common.collect.ImmutableBiMap;
 import java.util.List;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.neutron.northbound.api.BadRequestException;
 import org.opendaylight.neutron.spi.INeutronSecurityRuleCRUD;
 import org.opendaylight.neutron.spi.NeutronSecurityRule;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
@@ -116,8 +117,13 @@ public final class NeutronSecurityRuleInterface extends
         }
         if (securityRule.getSecurityRuleProtocol() != null) {
             final String protocolString = securityRule.getSecurityRuleProtocol();
-            final Protocol protocol = new Protocol(protocolString.toCharArray());
-            securityRuleBuilder.setProtocol(protocol);
+            try {
+                final Protocol protocol = new Protocol(protocolString.toCharArray());
+                securityRuleBuilder.setProtocol(protocol);
+            } catch (NumberFormatException e) {
+                throw new BadRequestException("Protocol {" + securityRule.getSecurityRuleProtocol()
+                        + "} is not supported");
+            }
         }
         if (securityRule.getSecurityRuleEthertype() != null) {
             final ImmutableBiMap<String, Class<? extends EthertypeBase>> mapper = ETHERTYPE_MAP.inverse();