Skip to content

Commit

Permalink
Merge pull request #482 from grycap/devel
Browse files Browse the repository at this point in the history
 Implements: #481
  • Loading branch information
micafer authored Nov 8, 2017
2 parents 52356b3 + a3671e1 commit d093243
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 26 deletions.
12 changes: 7 additions & 5 deletions IM/InfrastructureManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,14 +821,15 @@ def GetInfrastructureInfo(inf_id, auth):
return res

@staticmethod
def GetInfrastructureContMsg(inf_id, auth):
def GetInfrastructureContMsg(inf_id, auth, headeronly=False):
"""
Get cont msg of an infrastructure.
Args:
- inf_id(str): infrastructure id.
- auth(Authentication): parsed authentication tokens.
- headeronly(bool): Flag to return only the header part of the infra log.
Return: a str with the cont msg
"""
Expand All @@ -840,10 +841,11 @@ def GetInfrastructureContMsg(inf_id, auth):
sel_inf = InfrastructureManager.get_infrastructure(inf_id, auth)
res = sel_inf.cont_out

for vm in sel_inf.get_vm_list():
if vm.get_cont_msg():
res += "VM " + str(vm.id) + ":\n" + vm.get_cont_msg() + "\n"
res += "***************************************************************************\n"
if not headeronly:
for vm in sel_inf.get_vm_list():
if vm.get_cont_msg():
res += "VM " + str(vm.id) + ":\n" + vm.get_cont_msg() + "\n"
res += "***************************************************************************\n"

InfrastructureManager.logger.debug(res)
return res
Expand Down
12 changes: 11 additions & 1 deletion IM/REST.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,17 @@ def RESTGetInfrastructureProperty(infid=None, prop=None):

try:
if prop == "contmsg":
res = InfrastructureManager.GetInfrastructureContMsg(infid, auth)
headeronly = False
if "headeronly" in bottle.request.params.keys():
str_headeronly = bottle.request.params.get("headeronly").lower()
if str_headeronly in ['yes', 'true', '1']:
headeronly = True
elif str_headeronly in ['no', 'false', '0']:
headeronly = False
else:
return return_error(400, "Incorrect value in context parameter")

res = InfrastructureManager.GetInfrastructureContMsg(infid, auth, headeronly)
elif prop == "radl":
res = InfrastructureManager.GetInfrastructureRADL(infid, auth)
elif prop == "state":
Expand Down
5 changes: 3 additions & 2 deletions IM/ServiceRequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,10 @@ class Request_GetInfrastructureContMsg(IMBaseRequest):

def _call_function(self):
self._error_mesage = "Error gettinf the Inf. cont msg"
(inf_id, auth_data) = self.arguments
(inf_id, auth_data, headeronly) = self.arguments
return IM.InfrastructureManager.InfrastructureManager.GetInfrastructureContMsg(inf_id,
Authentication(auth_data))
Authentication(auth_data),
headeronly)


class Request_StartVM(IMBaseRequest):
Expand Down
2 changes: 2 additions & 0 deletions changelog
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,5 @@ IM 1.6.4
* Store tenant and project in OCCI connector.
* Fix error validating keystone token in OCCI conn.
* Decrease timeout getting ansible process results.
* Enable to get the initial infrastructure contextualization log.

5 changes: 4 additions & 1 deletion doc/source/REST.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,13 @@ GET ``http://imserver.com/infrastructures/<infId>``
GET ``http://imserver.com/infrastructures/<infId>/<property_name>``
:Response Content-type: text/plain or application/json
:ok response: 200 OK
:input fields: ``headeronly`` (optional)
:fail response: 401, 404, 400, 403

Return property ``property_name`` associated to the infrastructure with ID ``infId``. It has three properties:
:``contmsg``: a string with the contextualization message.
:``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.
:``state``: a JSON object with two elements:

Expand Down
6 changes: 4 additions & 2 deletions doc/source/xmlrpc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ This is the list of method names:
``GetInfrastructureContMsg``
:parameter 0: ``infId``: integer
:parameter 1: ``auth``: array of structs
:parameter 2: ``headeronly``: (optional, default value False) boolean
:ok response: [true, ``cont_out``: string]
:fail response: [false, ``error``: string]

Return the contextualization log associated to the
infrastructure with ID ``infId``.
Return the contextualization log associated to the infrastructure with ID ``infId``.
In case of ``headeronly`` flag is set to True. Only the initial part of the infrastructure
contextualization log will be returned (without any VM contextualization log).

``GetInfrastructureState``
:parameter 0: ``infId``: integer
Expand Down
4 changes: 2 additions & 2 deletions im_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ def GetVMContMsg(inf_id, vm_id, auth_data):
return WaitRequest(request)


def GetInfrastructureContMsg(inf_id, auth_data):
def GetInfrastructureContMsg(inf_id, auth_data, headeronly=False):
request = IMBaseRequest.create_request(
IMBaseRequest.GET_INFRASTRUCTURE_CONT_MSG, (inf_id, auth_data))
IMBaseRequest.GET_INFRASTRUCTURE_CONT_MSG, (inf_id, auth_data, headeronly))
return WaitRequest(request)


Expand Down
16 changes: 10 additions & 6 deletions test/integration/TestIM.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,18 @@ def test_13_getcontmsg(self):
"""
Test the GetInfrastructureContMsg IM function
"""
(success, cont_out) = self.server.GetInfrastructureContMsg(
self.inf_id, self.auth_data)
self.assertTrue(
success, msg="ERROR calling GetInfrastructureContMsg: " + str(cont_out))
self.assertGreater(
len(cont_out), 100, msg="Incorrect contextualization message: " + cont_out)
(success, cont_out) = self.server.GetInfrastructureContMsg(self.inf_id, self.auth_data)
self.assertTrue(success, msg="ERROR calling GetInfrastructureContMsg: " + str(cont_out))
self.assertGreater(len(cont_out), 100, msg="Incorrect contextualization message: " + cont_out)
self.assertIn("Select master VM", cont_out)
self.assertIn("NODENAME = front", cont_out)

(success, cont_out) = self.server.GetInfrastructureContMsg(self.inf_id, self.auth_data, True)
self.assertTrue(success, msg="ERROR calling GetInfrastructureContMsg: " + str(cont_out))
self.assertGreater(len(cont_out), 100, msg="Incorrect contextualization message: " + cont_out)
self.assertIn("Select master VM", cont_out)
self.assertNotIn("NODENAME = front", cont_out)

def test_14_getvmcontmsg(self):
"""
Test the GetVMContMsg IM function
Expand Down
12 changes: 6 additions & 6 deletions test/integration/TestREST.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,16 @@ def test_30_get_vm_info(self):

def test_32_get_vm_contmsg(self):
resp = self.create_request("GET", "/infrastructures/" + self.inf_id)
self.assertEqual(resp.status_code, 200,
msg="ERROR getting the infrastructure info:" + resp.text)
self.assertEqual(resp.status_code, 200, msg="ERROR getting the infrastructure info:" + resp.text)
vm_ids = resp.text.split("\n")

vm_uri = uriparse(vm_ids[0])
resp = self.create_request("GET", vm_uri[2] + "/contmsg")
self.assertEqual(resp.status_code, 200,
msg="ERROR getting VM contmsg:" + resp.text)
self.assertEqual(
len(resp.text), 0, msg="Incorrect VM contextualization message: " + resp.text)
self.assertEqual(resp.status_code, 200, msg="ERROR getting VM contmsg:" + resp.text)
self.assertEqual(len(resp.text), 0, msg="Incorrect VM contextualization message: " + resp.text)

resp2 = self.create_request("GET", vm_uri[2] + "/contmsg?headeronly=true")
self.assertEqual(resp2.status_code, 200, msg="ERROR getting VM contmsg:" + resp.text)

def test_33_get_contmsg(self):
resp = self.create_request("GET", "/infrastructures/" + self.inf_id + "/contmsg")
Expand Down
8 changes: 8 additions & 0 deletions test/unit/REST.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ def test_GetInfrastructureProperty(self, bottle_request, GetInfrastructureState,
res = RESTGetInfrastructureProperty("1", "contmsg")
self.assertEqual(res, "contmsg")

bottle_request.params = {'headeronly': 'yes'}
res = RESTGetInfrastructureProperty("1", "contmsg")
self.assertEqual(res, "contmsg")

bottle_request.params = {'headeronly': 'no'}
res = RESTGetInfrastructureProperty("1", "contmsg")
self.assertEqual(res, "contmsg")

res = RESTGetInfrastructureProperty("1", "radl")
self.assertEqual(res, "radl")

Expand Down
2 changes: 1 addition & 1 deletion test/unit/ServiceRequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_cont_msg(self, inflist):
import IM.ServiceRequests
req = IM.ServiceRequests.IMBaseRequest.create_request(IM.ServiceRequests.
IMBaseRequest.GET_INFRASTRUCTURE_CONT_MSG,
("", ""))
("", "", False))
req._call_function()

@patch('IM.InfrastructureManager.InfrastructureManager')
Expand Down
4 changes: 4 additions & 0 deletions test/unit/test_im_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,12 +717,16 @@ def test_get_vm_info(self):
contmsg = IM.GetVMContMsg(infId, "0", auth0)
self.assertEqual(contmsg, "")

InfrastructureList.infrastructure_list[infId].cont_out = "Header"
InfrastructureList.infrastructure_list[infId].vm_list[0].cloud_connector = MagicMock()
InfrastructureList.infrastructure_list[infId].vm_list[0].cloud_connector.error_messages = "TESTMSG"
contmsg = IM.GetInfrastructureContMsg(infId, auth0)
header_contmsg = IM.GetInfrastructureContMsg(infId, auth0, True)
InfrastructureList.infrastructure_list[infId].vm_list[0].cloud_connector = None

self.assertIn("TESTMSG", contmsg)
self.assertNotIn("TESTMSG", header_contmsg)
self.assertIn("Header", header_contmsg)

state = IM.GetInfrastructureState(infId, auth0)
self.assertEqual(state["state"], "running")
Expand Down

0 comments on commit d093243

Please sign in to comment.