Commit for fixes described in https://review.openstack.org/#/c/362762/
Change-Id: Ib4e9a43381af29b0ca1e2eee05de4a4976dd8794
This commit is contained in:
parent
3c33d51dd4
commit
4771a6e490
@ -1,7 +1,7 @@
|
||||
import json
|
||||
import requests
|
||||
|
||||
from synergy.common import utils
|
||||
from synergy.common.utils import objectHookHandler
|
||||
from tabulate import tabulate
|
||||
|
||||
|
||||
@ -35,32 +35,16 @@ class HTTPCommand(object):
|
||||
def configureParser(self, subparser):
|
||||
raise NotImplementedError("not implemented!")
|
||||
|
||||
def objectHookHandler(self, parsed_dict):
|
||||
if "synergy_object" in parsed_dict:
|
||||
synergy_object = parsed_dict["synergy_object"]
|
||||
try:
|
||||
objClass = utils.import_class(synergy_object["name"])
|
||||
|
||||
objInstance = objClass()
|
||||
return objInstance.deserialize(parsed_dict)
|
||||
except Exception as ex:
|
||||
print(ex)
|
||||
raise ex
|
||||
else:
|
||||
return parsed_dict
|
||||
|
||||
def execute(self, synergy_url, payload=None):
|
||||
request = requests.get(synergy_url, params=payload)
|
||||
|
||||
if request.status_code != requests.codes.ok:
|
||||
# print(request.reason)
|
||||
# print(request.status_code)
|
||||
request.raise_for_status()
|
||||
|
||||
self.results = request.json()
|
||||
|
||||
try:
|
||||
return json.loads(request.text, object_hook=self.objectHookHandler)
|
||||
return json.loads(request.text, object_hook=objectHookHandler)
|
||||
except Exception:
|
||||
return request.json()
|
||||
|
||||
|
@ -176,7 +176,6 @@ def main():
|
||||
print("command %r not found!" % command_name)
|
||||
|
||||
commands[command_name].execute(synergy_url, args)
|
||||
# commands[command_name].log()
|
||||
except KeyboardInterrupt as e:
|
||||
print("Shutting down synergyclient")
|
||||
sys.exit(1)
|
||||
|
@ -92,11 +92,9 @@ class SynergyObject(object):
|
||||
|
||||
try:
|
||||
objName = synergy_object["name"]
|
||||
# objVer = synergy_object['version']
|
||||
objClass = utils.import_class(objName)
|
||||
objInstance = objClass()
|
||||
except Exception as ex:
|
||||
print(ex)
|
||||
raise Exception("error on deserializing the object %r: %s"
|
||||
% (objName, ex))
|
||||
|
||||
|
@ -31,3 +31,16 @@ def import_class(import_str):
|
||||
raise ImportError(
|
||||
'Class %s cannot be found (%s)' %
|
||||
(class_str, traceback.format_exception(*sys.exc_info())))
|
||||
|
||||
|
||||
def objectHookHandler(parsed_dict):
|
||||
if "synergy_object" in parsed_dict:
|
||||
synergy_object = parsed_dict["synergy_object"]
|
||||
try:
|
||||
objClass = import_class(synergy_object["name"])
|
||||
objInstance = objClass()
|
||||
return objInstance.deserialize(parsed_dict)
|
||||
except Exception as ex:
|
||||
raise ex
|
||||
else:
|
||||
return parsed_dict
|
||||
|
@ -23,7 +23,7 @@ import sys
|
||||
import time
|
||||
|
||||
from mock import Mock
|
||||
from synergy.common import utils
|
||||
from synergy.common.utils import objectHookHandler
|
||||
from synergy.service import Synergy
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
@ -48,21 +48,6 @@ def getLogger(name):
|
||||
return logger
|
||||
|
||||
|
||||
def objectHookHandler(parsed_dict):
|
||||
if "synergy_object" in parsed_dict:
|
||||
synergy_object = parsed_dict["synergy_object"]
|
||||
try:
|
||||
objClass = utils.import_class(synergy_object["name"])
|
||||
|
||||
objInstance = objClass()
|
||||
return objInstance.deserialize(parsed_dict)
|
||||
except Exception as ex:
|
||||
print(ex)
|
||||
raise ex
|
||||
else:
|
||||
return parsed_dict
|
||||
|
||||
|
||||
class SynergyTests(unittest.TestCase):
|
||||
|
||||
@mock.patch('synergy.service.LOG', LOG)
|
||||
|
@ -13,5 +13,4 @@ testrepository>=0.0.18
|
||||
testscenarios>=0.4
|
||||
testtools>=1.4.0
|
||||
mock==2.0.0
|
||||
tabulate>=0.7.2,<0.8.0
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user