forked from sahana/eden
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving the request to edentest lib, removing rb http lib
- Loading branch information
1 parent
1f80b68
commit d25c6c4
Showing
3 changed files
with
32 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,41 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from robot.libraries.OperatingSystem import OperatingSystem | ||
import ast | ||
from robot.api import logger | ||
import os | ||
import requests | ||
|
||
class edentest_robot: | ||
|
||
def __init__(self, web2py, eden_path): | ||
logger.debug("Got arguments %s %s" % (web2py, eden_path), html=True) | ||
self.web2py = web2py | ||
self.eden_path = eden_path | ||
def __init__(self, server, appname): | ||
""" | ||
Initialize the class variables | ||
""" | ||
logger.debug("Arguments %s %s" % (server, appname), html=True) | ||
|
||
self.base_url = "http://" + server + "/" + appname | ||
|
||
def get_deployment_settings(self, *asked): | ||
""" | ||
Takes the required settings as arguments eg: Template Base Public Url | ||
Returns a list of values if len(list) > 1 else returns the first value as a | ||
string. | ||
Raises a warning if a setting is not found. | ||
Returns the deployment settings asked in a dict where key is the | ||
asked setting. It makes a get request to eden/default/edentest | ||
and uses s3cfg to get the settings. | ||
It uses env. proxy settings | ||
""" | ||
self._setcwd() | ||
|
||
logger.info("Getting values for - %s" % " ".join(asked), html=True) | ||
cmd = "python " + self.web2py + " --no-banner -S eden -M -R " + self.eden_path +"/tests/execution/libs/eden_interface.py -A -S" | ||
logger.console("base_url %s" % (self.base_url)) | ||
|
||
request_url = self.base_url + "/default/edentest/deployment_settings" | ||
for key in asked: | ||
cmd = cmd + " " + key | ||
|
||
rc, output = OperatingSystem().run_and_return_rc_and_output(cmd) | ||
|
||
logger.debug("Return code for the cmd %s is %d" % (cmd, rc)) | ||
logger.info("Returned Settings %s" % output) | ||
|
||
self._resetcwd() | ||
request_url += "/" + key | ||
logger.console("request_url %s" % (request_url)) | ||
|
||
output = ast.literal_eval(output) | ||
response = requests.get(request_url) | ||
if response.status_code != requests.codes.ok: | ||
logger.warn("Could not contact the Eden server") | ||
return {} | ||
output = response.json() | ||
|
||
for key in asked: | ||
if key not in output.keys(): | ||
if key not in output: | ||
logger.warn("Could not fetch the setting %s" % key) | ||
|
||
return output | ||
|
||
def _setcwd(self): | ||
""" | ||
Sets the CWD to the root of eden | ||
""" | ||
self._oldcwd = os.getcwd() | ||
self._newcwd = self._oldcwd.split("/eden/")[0] + "/eden/" | ||
os.chdir(self._newcwd) | ||
|
||
def _resetcwd(self): | ||
""" | ||
Resets the CWD to the directory from which tests were run | ||
""" | ||
os.chdir(self._oldcwd) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d25c6c4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Careful! This can hardly be merged as-is - some settings may be sensitive (passwords!) and this controller is entirely open (no access control at all). Either you require ADMIN permissions to access this controller (preferred) or you restrict which settings can be requested through it.