From: schillinge Date: Wed, 30 Jan 2019 20:45:37 +0000 (+0100) Subject: Allow filtering of the port chain list by id X-Git-Tag: v6.0.0~40^2 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F54%2F7154%2F2;p=osm%2Fvim-emu.git Allow filtering of the port chain list by id Change-Id: I2d81c3836fe0b0d1ad9429922b59d42b4eab68f3 Signed-off-by: schillinge --- diff --git a/src/emuvim/api/openstack/openstack_dummies/neutron_sfc_dummy_api.py b/src/emuvim/api/openstack/openstack_dummies/neutron_sfc_dummy_api.py index f2ea6bb..dbfb4b5 100644 --- a/src/emuvim/api/openstack/openstack_dummies/neutron_sfc_dummy_api.py +++ b/src/emuvim/api/openstack/openstack_dummies/neutron_sfc_dummy_api.py @@ -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') diff --git a/src/emuvim/test/unittests/test_openstack.py b/src/emuvim/test/unittests/test_openstack.py index a9273fb..93d7f4a 100755 --- a/src/emuvim/test/unittests/test_openstack.py +++ b/src/emuvim/test/unittests/test_openstack.py @@ -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('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')