Allow filtering of the port chain list by id 54/7154/2
authorschillinge <ablu@mail.uni-paderborn.de>
Wed, 30 Jan 2019 20:45:37 +0000 (21:45 +0100)
committerschillinge <ablu@mail.uni-paderborn.de>
Sun, 3 Feb 2019 20:05:44 +0000 (21:05 +0100)
Change-Id: I2d81c3836fe0b0d1ad9429922b59d42b4eab68f3
Signed-off-by: schillinge <ablu@mail.uni-paderborn.de>
src/emuvim/api/openstack/openstack_dummies/neutron_sfc_dummy_api.py
src/emuvim/test/unittests/test_openstack.py

index f2ea6bb..dbfb4b5 100644 (file)
@@ -114,10 +114,11 @@ class PortPairsList(SFC):
     def get(self):
         logging.debug("API CALL: %s GET" % str(self.__class__.__name__))
         try:
-            port_pair_list = []
-            for port_pair in self.api.compute.port_pairs.values():
-                port_pair_list.append(port_pair.create_dict(self.api.compute))
-            resp = {"port_pairs": port_pair_list}
+            port_pairs = self.api.compute.port_pairs.values()
+            id = request.args.get('id')
+            if id and any(id):
+                port_pairs = filter(lambda port_pair: port_pair.id == id, port_pairs)
+            resp = {"port_pairs": map(lambda port_pair: port_pair.create_dict(self.api.compute), port_pairs)}
 
             return Response(json.dumps(resp), status=200,
                             mimetype='application/json')
index a9273fb..93d7f4a 100755 (executable)
@@ -917,9 +917,18 @@ class testRestApi(ApiBaseOpenStack):
         url = "http://0.0.0.0:19696/v2.0/sfc/port_pairs"
         pp_list_resp = requests.get(url, headers=headers)
         self.assertEqual(pp_list_resp.status_code, 200)
+        pp_list = json.loads(pp_list_resp.content)["port_pairs"]
         # only pp1 and pp2 should be left
-        self.assertEqual(
-            len(json.loads(pp_list_resp.content)["port_pairs"]), 2)
+        self.assertEqual(len(pp_list), 2)
+
+        print('->>>>>>> test Neutron SFC Port Pair List filtered by id ->>>>>>>>>>>>>>>')
+        print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
+        url = "http://0.0.0.0:19696/v2.0/sfc/port_pairs?id=%s" % pp_list[0]["id"]
+        pp_list_filtered_by_id_resp = requests.get(url, headers=headers)
+        pp_list_filtered_by_id = json.loads(pp_list_filtered_by_id_resp.content)["port_pairs"]
+        self.assertEqual(pp_list_filtered_by_id_resp.status_code, 200)
+        self.assertEqual(len(pp_list_filtered_by_id), 1)
+        self.assertEqual(pp_list_filtered_by_id[0], pp_list[0])
 
         print('->>>>>>> test Neutron SFC Port Pair Show ->>>>>>>>>>>>>>>')
         print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')