def test_get_vm_info(self): """ Test GetVMInfo and GetVMProperty and GetVMContMsg and GetInfrastructureRADL and GetInfrastructureContMsg and GetInfrastructureState. """ radl = RADL() radl.add( system("s0", [ Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"), Feature("disk.0.os.credentials.username", "=", "user"), Feature("disk.0.os.credentials.password", "=", "pass") ])) radl.add(deploy("s0", 1)) auth0 = self.getAuth([0], [], [("Dummy", 0)]) infId = IM.CreateInfrastructure(str(radl), auth0) radl_info = IM.GetVMInfo(infId, "0", auth0) parsed_radl_info = parse_radl(str(radl_info)) self.assertEqual(parsed_radl_info.systems[0].getValue("state"), "running") radl_info = IM.GetVMInfo(infId, "0", auth0, True) parsed_radl_info = parse_radl_json(radl_info) self.assertEqual(parsed_radl_info.systems[0].getValue("state"), "running") state = IM.GetVMProperty(infId, "0", "state", auth0) self.assertEqual(state, "running") 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") self.assertEqual(state["vm_states"]["0"], "running") radl_info = IM.GetInfrastructureRADL(infId, auth0) parsed_radl_info = parse_radl(str(radl_info)) self.assertEqual( parsed_radl_info.systems[0].getValue( "disk.0.os.credentials.username"), "user") IM.DestroyInfrastructure(infId, auth0)
def RESTGetVMInfo(infid=None, vmid=None): try: auth = get_auth_header() except Exception: return return_error(401, "No authentication data provided") try: radl = InfrastructureManager.GetVMInfo(infid, vmid, auth) return format_output(radl, field_name="radl") except DeletedInfrastructureException as ex: return return_error(404, "Error Getting VM. info: %s" % get_ex_error(ex)) except IncorrectInfrastructureException as ex: return return_error(404, "Error Getting VM. info: %s" % get_ex_error(ex)) except UnauthorizedUserException as ex: return return_error(403, "Error Getting VM. info: %s" % get_ex_error(ex)) except DeletedVMException as ex: return return_error(404, "Error Getting VM. info: %s" % get_ex_error(ex)) except IncorrectVMException as ex: return return_error(404, "Error Getting VM. info: %s" % get_ex_error(ex)) except Exception as ex: logger.exception("Error Getting VM info") return return_error(400, "Error Getting VM info: %s" % get_ex_error(ex))
def RESTGetVMInfo(infid=None, vmid=None): try: auth = get_auth_header() except: return return_error(401, "No authentication data provided") try: radl = InfrastructureManager.GetVMInfo(infid, vmid, auth) return format_output(radl, field_name="radl") except DeletedInfrastructureException, ex: return return_error(404, "Error Getting VM. info: " + str(ex))
def test_get_vm_info(self): """ Test GetVMInfo and GetVMProperty and GetVMContMsg and GetInfrastructureRADL and GetInfrastructureContMsg and GetInfrastructureState. """ radl = RADL() radl.add( system("s0", [ Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"), Feature("disk.0.os.credentials.username", "=", "user"), Feature("disk.0.os.credentials.password", "=", "pass") ])) radl.add(deploy("s0", 1)) auth0 = self.getAuth([0], [], [("Dummy", 0)]) infId = IM.CreateInfrastructure(str(radl), auth0) radl_info = IM.GetVMInfo(infId, "0", auth0) parsed_radl_info = parse_radl(str(radl_info)) self.assertEqual(parsed_radl_info.systems[0].getValue("state"), "running") state = IM.GetVMProperty(infId, "0", "state", auth0) self.assertEqual(state, "running") contmsg = IM.GetVMContMsg(infId, "0", auth0) self.assertEqual(contmsg, "") contmsg = IM.GetInfrastructureContMsg(infId, auth0) state = IM.GetInfrastructureState(infId, auth0) self.assertEqual(state["state"], "running") self.assertEqual(state["vm_states"]["0"], "running") radl_info = IM.GetInfrastructureRADL(infId, auth0) parsed_radl_info = parse_radl(str(radl_info)) self.assertEqual( parsed_radl_info.systems[0].getValue( "disk.0.os.credentials.username"), "user") IM.DestroyInfrastructure(infId, auth0)