Skip to content

Commit

Permalink
Merge pull request #720 from grycap/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
micafer authored Nov 21, 2018
2 parents 487c7b1 + 164c391 commit 9cfc890
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 7 deletions.
12 changes: 12 additions & 0 deletions IM/REST.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 5 additions & 2 deletions IM/connectors/EC2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion IM/connectors/OpenStack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions doc/source/REST.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``. |
+-------------+-----------------------------------------------------+----------------------------------------------------+

+-------------+-----------------------------------------------+------------------------------------------------+
Expand Down Expand Up @@ -147,7 +147,8 @@ GET ``http://imserver.com/infrastructures/<infId>/<property_name>``
:``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).
Expand Down
4 changes: 4 additions & 0 deletions test/unit/REST.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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.")
Expand Down
31 changes: 29 additions & 2 deletions test/unit/connectors/OCCI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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]
Expand Down Expand Up @@ -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 = """<appdb:appdb>
<virtualization:provider id="4454G0" in_production="true">
<provider:name>CESNET-MetaCloud</provider:name>
</virtualization:provider>
<virtualization:provider id="id" in_production="true">
<provider:name>some</provider:name>
</virtualization:provider>
</appdb:appdb>"""
elif url == "/rest/1.0/va_providers/4454G0":
resp.status_code = 200
resp.text = """<appdb:appdb>
<virtualization:provider id="4454G0" in_production="true">
<provider:endpoint_url>https://carach5.ics.muni.cz:11443</provider:endpoint_url>
<provider:image
va_provider_image_id="http://url/os_tpl#image_id"
appcname="egi.docker.ubuntu.16.04"
voname="fedcloud.egi.eu"/>
<provider:image
va_provider_image_id="http://url/os_tpl#image_id2"
appcname="egi.ubuntu.16.04"
voname="fedcloud.egi.eu"/>
</virtualization:provider>
</appdb:appdb>"""
elif method == "POST":
if url == "/compute/":
if self.return_error:
Expand Down

0 comments on commit 9cfc890

Please sign in to comment.