From 9c040dd02b139ddaef6734d24ed34ba63bfed830 Mon Sep 17 00:00:00 2001 From: micafer Date: Tue, 20 Nov 2018 11:06:24 +0100 Subject: [PATCH 1/3] Improve test --- test/unit/connectors/OCCI.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/test/unit/connectors/OCCI.py b/test/unit/connectors/OCCI.py index a2406c82b..8b87eb212 100755 --- a/test/unit/connectors/OCCI.py +++ b/test/unit/connectors/OCCI.py @@ -112,7 +112,8 @@ def test_10_concrete(self): self.assertEqual(len(concrete), 1) self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue()) - def test_15_concrete_appdb(self): + @patch('requests.request') + def test_15_concrete_appdb(self, requests): radl_data = """ network net () system test ( @@ -133,11 +134,12 @@ def test_15_concrete_appdb(self): occi_cloud = self.get_occi_cloud() occi_cloud.cloud.server = "carach5.ics.muni.cz" + requests.side_effect = self.get_response concrete = occi_cloud.concreteSystem(radl_system, auth) self.assertEqual(len(concrete), 1) self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue()) - def get_response(self, method, url, verify, cert, headers, data): + def get_response(self, method, url, verify, cert=None, headers=None, data=None): resp = MagicMock() parts = uriparse(url) url = parts[2] @@ -173,6 +175,31 @@ def get_response(self, method, url, verify, cert, headers, data): resp.headers = {'X-Subject-Token': 'token1'} elif url.endswith("/link/storagelink/compute_10_disk_1"): resp.status_code = 404 + elif url == "/rest/1.0/va_providers": + resp.status_code = 200 + resp.text = """ + + CESNET-MetaCloud + + + some + + """ + elif url == "/rest/1.0/va_providers/4454G0": + resp.status_code = 200 + resp.text = """ + + https://carach5.ics.muni.cz:11443 + + + + """ elif method == "POST": if url == "/compute/": if self.return_error: From 20f0c4aee1f5ef246af7244c51461d70ac3bc2eb Mon Sep 17 00:00:00 2001 From: micafer Date: Tue, 20 Nov 2018 16:44:04 +0100 Subject: [PATCH 2/3] Delete all the sgs: #690 --- IM/connectors/EC2.py | 7 +++++-- IM/connectors/OpenStack.py | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/IM/connectors/EC2.py b/IM/connectors/EC2.py index 7f287da7f..572c3c39e 100644 --- a/IM/connectors/EC2.py +++ b/IM/connectors/EC2.py @@ -1318,9 +1318,12 @@ def _get_security_groups(self, conn, vm): """ Get all the SGs where the VM is included """ + sg_names = ["im-%s" % str(vm.inf.id)] + for net in vm.inf.radl.networks: + sg_names.append("im-%s-%s" % (str(vm.inf.id), net.id)) + sgs = [] - for net in vm.info.networks: - sg_name = "im-%s-%s" % (str(vm.inf.id), net.id) + for sg_name in sg_names: try: sgs.extend(conn.get_all_security_groups(filters={'group-name': sg_name})) except Exception: diff --git a/IM/connectors/OpenStack.py b/IM/connectors/OpenStack.py index 601493e38..c0f4f87c7 100644 --- a/IM/connectors/OpenStack.py +++ b/IM/connectors/OpenStack.py @@ -984,9 +984,11 @@ def delete_security_groups(self, driver, inf, timeout=180, delay=10): """ Delete the SG of this inf """ + sg_names = ["im-%s" % str(inf.id)] for net in inf.radl.networks: - sg_name = "im-%s-%s" % (str(inf.id), net.id) + sg_names.append("im-%s-%s" % (str(inf.id), net.id)) + for sg_name in sg_names: # wait it to terminate and then remove the SG cont = 0 deleted = False From 164c39193c558ff4b6fabb050bfdb6a5f7228ff5 Mon Sep 17 00:00:00 2001 From: micafer Date: Wed, 21 Nov 2018 08:27:07 +0100 Subject: [PATCH 3/3] Implements: #719 --- IM/REST.py | 12 ++++++++++++ doc/source/REST.rst | 5 +++-- test/unit/REST.py | 4 ++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/IM/REST.py b/IM/REST.py index 742b1fac2..31af4708a 100644 --- a/IM/REST.py +++ b/IM/REST.py @@ -375,6 +375,18 @@ def RESTGetInfrastructureProperty(infid=None, prop=None): res = InfrastructureManager.GetInfrastructureContMsg(infid, auth, headeronly) elif prop == "radl": res = InfrastructureManager.GetInfrastructureRADL(infid, auth) + elif prop == "tosca": + accept = get_media_type('Accept') + if accept and "application/json" not in accept and "*/*" not in accept and "application/*" not in accept: + return return_error(415, "Unsupported Accept Media Types: %s" % accept) + bottle.response.content_type = "application/json" + auth = InfrastructureManager.check_auth_data(auth) + sel_inf = InfrastructureManager.get_infrastructure(infid, auth) + if "TOSCA" in sel_inf.extra_info: + res = sel_inf.extra_info["TOSCA"].serialize() + else: + bottle.abort( + 403, "'tosca' infrastructure property is not valid in this infrastructure") elif prop == "state": accept = get_media_type('Accept') if accept and "application/json" not in accept and "*/*" not in accept and "application/*" not in accept: diff --git a/doc/source/REST.rst b/doc/source/REST.rst index 43e86cfa5..5768fc9e2 100644 --- a/doc/source/REST.rst +++ b/doc/source/REST.rst @@ -40,7 +40,7 @@ Next tables summaries the resources and the HTTP methods available. | **GET** | | **Get** the specified property ``property_name`` | | **Get** the specified property ``property_name`` | | | | associated to the machine ``vmId`` in ``infId``. | | associated to the infrastructure ``infId``. | | | | It has one special property: ``contmsg``. | | It has five properties: ``contmsg``, ``radl``, | -| | | | ``state``, ``outputs`` and ``data``. | +| | | | ``state``, ``outputs``, ``tosca`` and ``data``. | +-------------+-----------------------------------------------------+----------------------------------------------------+ +-------------+-----------------------------------------------+------------------------------------------------+ @@ -147,7 +147,8 @@ GET ``http://imserver.com/infrastructures//`` :``contmsg``: a string with the contextualization message. In case of ``headeronly`` flag is set to 'yes', 'true' or '1' only the initial part of the infrastructure contextualization log will be returned (without any VM contextualization log). - :``radl``: a string with the original specified RADL of the infrastructure. + :``radl``: a string with the original specified RADL of the infrastructure. + :``tosca``: a string with the TOSCA representation of the infrastructure. :``data``: a string with the JSOMN serialized data of the infrastructure. In case of ``delete`` flag is set to 'yes', 'true' or '1' the data not only will be exported but also the infrastructure will be set deleted (the virtual infrastructure will not be modified). diff --git a/test/unit/REST.py b/test/unit/REST.py index a6f8ab1db..6efe0ecaf 100755 --- a/test/unit/REST.py +++ b/test/unit/REST.py @@ -159,6 +159,7 @@ def test_GetInfrastructureProperty(self, bottle_request, get_infrastructure, Get tosca = MagicMock() inf.extra_info = {"TOSCA": tosca} tosca.get_outputs.return_value = "outputs" + tosca.serialize.return_value = "tosca" res = RESTGetInfrastructureProperty("1", "state") self.assertEqual(json.loads(res)["state"]["state"], "running") @@ -177,6 +178,9 @@ def test_GetInfrastructureProperty(self, bottle_request, get_infrastructure, Get res = RESTGetInfrastructureProperty("1", "radl") self.assertEqual(res, "radl") + res = RESTGetInfrastructureProperty("1", "tosca") + self.assertEqual(res, "tosca") + GetInfrastructureRADL.side_effect = DeletedInfrastructureException() res = RESTGetInfrastructureProperty("1", "radl") self.assertEqual(res, "Error Getting Inf. prop: Deleted infrastructure.")