From d684dd86e19de5289da10cfdab1af80156e665bd Mon Sep 17 00:00:00 2001 From: Sam Robertson Date: Sun, 20 Nov 2011 18:04:55 -0600 Subject: [PATCH] Added more reporting, Fixed bug with setting globals, Added info to README, minor tweaks --- tools/testClient/README | 8 ++++++++ tools/testClient/translator.py | 13 ++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/tools/testClient/README b/tools/testClient/README index 62246c3f08f..d2fc5129c06 100644 --- a/tools/testClient/README +++ b/tools/testClient/README @@ -6,6 +6,14 @@ CloudStack Test Client 1. generate Cloudstack API python code from an API XML spec file generated by step 0 python codegenerator.py -o where-to-put-the-cloudstack-api -s where-the-spec-file +1a. If you will be running XML based tests, you will need to run them through the + translator script. To do that execute translator.py -h for command line help. + Example: + python translator.py -i example.xml + + this will create an example.xml.py script in the current directory. Run + that to run the test. + 2. Facility it provides: 1. very handy cloudstack API python wrapper diff --git a/tools/testClient/translator.py b/tools/testClient/translator.py index 8547342eb9a..9095c563629 100644 --- a/tools/testClient/translator.py +++ b/tools/testClient/translator.py @@ -59,7 +59,7 @@ class xml_to_python(object): randValue = int(random.random() * 10000000) self._write("%s%s.%s = '%s-randomName'" % (INDENT, self.cmd_name_var, itemName, str(randValue))) if item.getAttribute("setparam") == "true" and itemParam is not None: - self._write("%s%s = '%s-randomName'" % (INDENT, itemName, str(randValue))) + self._write("%s%s = '%s-randomName'" % (INDENT, itemParam, str(randValue))) self.glos.append(itemParam) else: try: @@ -105,7 +105,10 @@ class xml_to_python(object): self.parse_parameters(cmd) # now we execute command self._write("%s%s = apiClient.%s(%s)" % (INDENT, self.cmd_name_resp, self.cmd_name, self.cmd_name_var)) - + self._write("%sif %s is None:" % (INDENT, self.cmd_name_resp)) + self._write("%sprint 'test [%s] failed'" % (INDENT2, testCaseName)) + self._write("%selse:" % INDENT) + self._write("%sprint 'test [%s] succeeded'" % (INDENT2, testCaseName)) self.parse_returnvalue(cmd) def generate_python_header(self, outfile): @@ -128,8 +131,8 @@ class xml_to_python(object): outfile.write("# End of globals\n\n") outfile.write("if __name__ == \"__main__\":\n") outfile.write("%s# Possible initialization parameters:\n" % INDENT) - outfile.write( - "%s# cloudstackTestClient(mgtSvr=None, port=8096, apiKey = None, securityKey = None, asyncTimeout=3600, defaultWorkerThreads=10, logging=None)\n" % INDENT) + outfile.write("%s# cloudstackTestClient(mgtSvr=None, port=8096, apiKey = None, securityKey = None,\n" % INDENT) + outfile.write("%s# asyncTimeout=3600, defaultWorkerThreads=10, logging=None)\n" % INDENT) outfile.write("%stestClient = cloudstackTestClient.cloudstackTestClient(\"localhost\")\n" % INDENT) outfile.write("%sapiClient = testClient.getApiClient()\n" % INDENT) @@ -182,7 +185,7 @@ if __name__ == "__main__": else: outFile = sys.stderr - print("<>" % (options.xmlfile, outFile.name)) + print("[Processing: %s Output: %s]" % (options.xmlfile, outFile.name)) processor = xml_to_python(options.debug)