From 8475cc02d67e412bac72bc55f4049fd48703f478 Mon Sep 17 00:00:00 2001 From: Anderson Dantas Date: Thu, 18 Apr 2019 11:47:40 -0300 Subject: [PATCH 01/29] Started implementing assertion utils --- .../authentication_service/service_tests.py | 7 +++--- service_test/common/assertion.py | 9 +++++++ service_test/common/test_factory.py | 11 ++------ service_test/common/test_suite.py | 25 +++++++++++++------ service_test/main.py | 13 ++++------ 5 files changed, 36 insertions(+), 29 deletions(-) create mode 100644 service_test/common/assertion.py diff --git a/service_test/authentication_service/service_tests.py b/service_test/authentication_service/service_tests.py index d64919b..f7e032e 100644 --- a/service_test/authentication_service/service_tests.py +++ b/service_test/authentication_service/service_tests.py @@ -31,9 +31,8 @@ def setup(self): self.setpid(pid) def teardown(self): - print('tasketeeee') - # self.kill_background_process(self.pid) - # shutil.rmtree(self.workdir) + self.kill_background_process(self.pid) + shutil.rmtree(self.workdir) def run(self): self.createtoken() @@ -52,4 +51,4 @@ def setpid(self, pid): @classmethod def required_resources(self): - return ['auth_credentials'] + return ['auth_credentials', 'invalid_auth_credentials'] diff --git a/service_test/common/assertion.py b/service_test/common/assertion.py new file mode 100644 index 0000000..f205c98 --- /dev/null +++ b/service_test/common/assertion.py @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- + +class Assertion(object): + + def __init__(self, expected, obtained, compare): + self.compare = compare + + def __call__(): + print('i was called') diff --git a/service_test/common/test_factory.py b/service_test/common/test_factory.py index 67cff4a..f12f14a 100644 --- a/service_test/common/test_factory.py +++ b/service_test/common/test_factory.py @@ -45,7 +45,7 @@ def create(self, resource, **kwargs): body = kwargs.get('body', self.body) req = FogbowRequest(url=url, headers=headers, body=body, method=str(HttpMethods.POST)) - self.last_create = req.build() + self.last_create = req.execute() return json.loads(self.last_create.text) @@ -59,13 +59,6 @@ def __init__(self, url, method = 'get', body = {}, headers = {}): self.body = body self.method = method - def build(self): + def execute(self): verb_requester = getattr(requests, self.method) return verb_requester(url=self.url, json=self.body, headers=self.headers) - -class Response: - def __init__(self, **entries): - self.__dict__.update(entries) -# class WaitConditions: -# def ready(self, instance): -# return instance['state'] == InstanceState.READY diff --git a/service_test/common/test_suite.py b/service_test/common/test_suite.py index 80e49ce..443ed2f 100644 --- a/service_test/common/test_suite.py +++ b/service_test/common/test_suite.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- +import operator import os import re import shutil import subprocess -import sys import tempfile import time import uuid @@ -34,16 +34,16 @@ def nexttextcase(cls): return cls.test_number def setup(self, pid): - self.__nope__('setup') + raise NotImplementedError def run(self): - self.__nope__('run') + raise NotImplementedError def teardown(self): - self.__nope__('teardown') + raise NotImplementedError - def __nope__(self, phase): - print('Not Implemented %s method' % phase) + @classmethod + def required_resources(self): raise NotImplementedError def goto_workdir(self): @@ -101,10 +101,19 @@ def getpidbyport(self, port): content = Utils.file_get_contents(temp_file_name) if not content: - time.sleep(1) - return self.getpidbyport(port) + time.sleep(1) + return self.getpidbyport(port) return content def kill_background_process(self, pid): command = "kill -KILL %s " % pid os.system(command) + + def __getattribute__(self, assertion): + comparation_functions = ['eq', 'ne', 'lt', 'le', 'gt', 'ge'] + assertstr = 'assert' + print('eeeeeeeeooooooooooooo', assertion) + for cmp in comparation_functions: + if(assertion == assertstr+cmp): + return Assertion(cmp) + raise AttributeError diff --git a/service_test/main.py b/service_test/main.py index ddc9d1b..637ede8 100644 --- a/service_test/main.py +++ b/service_test/main.py @@ -36,13 +36,10 @@ def getresources(service_resources,required_resources): print('###### Starting tests ######') - a = ServiceTest(service_under_test, configuration, service_resources) - # tests = list(filter(lambda x: x[0] != '_', dir(a))) - # for t in tests: - # if not hasattr(TestSuite, t): - # getattr(a, t).__call__() - a.setup() - a.run() - a.teardown() + servicetest = ServiceTest(service_under_test, configuration, service_resources) + servicetest.asserteq() + # servicetest.setup() + # servicetest.run() + # servicetest.teardown() print('###### Tests are over ######') From 2ef0bd40f1e7ee0ec3965d3be3d2b0dface74e1d Mon Sep 17 00:00:00 2001 From: Anderson Dantas Date: Tue, 23 Apr 2019 10:44:54 -0300 Subject: [PATCH 02/29] Add assertttrue function to TestSuite --- .gitignore | 3 +++ service_test/common/test_suite.py | 23 +++++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bfcf896 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +**/*.pyc +**/__pycache__/ +**/private/* diff --git a/service_test/common/test_suite.py b/service_test/common/test_suite.py index 443ed2f..1ac2634 100644 --- a/service_test/common/test_suite.py +++ b/service_test/common/test_suite.py @@ -11,6 +11,7 @@ from .constants import CommonConstants from .utils import Utils +from .assertion import Assertion __all__ = ['TestSuite'] @@ -23,6 +24,8 @@ def __init__(self, service): self.service = service self.service_dir = os.getcwd() + '/' + service self.service_instance = {} + self.assert_count = 0 + self.assert_succ = 0 @classmethod def logTest(cls, msg): @@ -109,11 +112,23 @@ def kill_background_process(self, pid): command = "kill -KILL %s " % pid os.system(command) - def __getattribute__(self, assertion): + def __getattr__(self, attribute): comparation_functions = ['eq', 'ne', 'lt', 'le', 'gt', 'ge'] assertstr = 'assert' - print('eeeeeeeeooooooooooooo', assertion) for cmp in comparation_functions: - if(assertion == assertstr+cmp): - return Assertion(cmp) + if(attribute == assertstr+cmp): + return Assertion(self, getattr(operator, cmp)) + + truestr = 'true' + if attribute == assertstr+truestr: + return Assertion(self, lambda value: value == True) + raise AttributeError + + def assertion_ok(self): + self.assert_count += 1 + self.assert_succ += 1 + + def assertion_fail(self): + self.assert_count += 1 + From 3a211b56a84bee0746f82c2861e261979f175907 Mon Sep 17 00:00:00 2001 From: Anderson Dantas Date: Tue, 23 Apr 2019 10:45:23 -0300 Subject: [PATCH 03/29] Implemented framework for TestAssertions --- .../authentication_service/service_tests.py | 1 + service_test/common/assertion.py | 18 +++++++++++++++--- service_test/common/test_suite.py | 4 ---- service_test/main.py | 9 +++++---- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/service_test/authentication_service/service_tests.py b/service_test/authentication_service/service_tests.py index f7e032e..d3c717f 100644 --- a/service_test/authentication_service/service_tests.py +++ b/service_test/authentication_service/service_tests.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- + import requests import shutil diff --git a/service_test/common/assertion.py b/service_test/common/assertion.py index f205c98..7f22ab6 100644 --- a/service_test/common/assertion.py +++ b/service_test/common/assertion.py @@ -1,9 +1,21 @@ # -*- coding: utf-8 -*- +""" Util class for TestSuite """ class Assertion(object): - def __init__(self, expected, obtained, compare): + def __init__(self, suite, compare): self.compare = compare + self.suite = suite - def __call__(): - print('i was called') + def __call__(self, obtained, expected=None): + print("Run to the hills", obtained, expected) + + assertresult = self.compare(obtained, expected) if expected \ + else self.compare(obtained) + + if assertresult: + self.suite.assertion_ok() + else: + self.suite.assertion_fail() + + \ No newline at end of file diff --git a/service_test/common/test_suite.py b/service_test/common/test_suite.py index 1ac2634..13bf2a9 100644 --- a/service_test/common/test_suite.py +++ b/service_test/common/test_suite.py @@ -118,10 +118,6 @@ def __getattr__(self, attribute): for cmp in comparation_functions: if(attribute == assertstr+cmp): return Assertion(self, getattr(operator, cmp)) - - truestr = 'true' - if attribute == assertstr+truestr: - return Assertion(self, lambda value: value == True) raise AttributeError diff --git a/service_test/main.py b/service_test/main.py index 637ede8..57b2724 100644 --- a/service_test/main.py +++ b/service_test/main.py @@ -37,9 +37,10 @@ def getresources(service_resources,required_resources): print('###### Starting tests ######') servicetest = ServiceTest(service_under_test, configuration, service_resources) - servicetest.asserteq() - # servicetest.setup() - # servicetest.run() - # servicetest.teardown() + servicetest.asserttrue(True) + servicetest.asserteq(1,2) + servicetest.setup() + servicetest.run() + servicetest.teardown() print('###### Tests are over ######') From 9d708acbc39872a670d6fc82953d03029f60061a Mon Sep 17 00:00:00 2001 From: Anderson Dantas Date: Tue, 23 Apr 2019 11:26:55 -0300 Subject: [PATCH 04/29] attemp to implement hook at test method --- service_test/common/assertion.py | 8 ++++---- service_test/common/test_suite.py | 33 +++++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/service_test/common/assertion.py b/service_test/common/assertion.py index 7f22ab6..7eb81ad 100644 --- a/service_test/common/assertion.py +++ b/service_test/common/assertion.py @@ -10,12 +10,12 @@ def __init__(self, suite, compare): def __call__(self, obtained, expected=None): print("Run to the hills", obtained, expected) - assertresult = self.compare(obtained, expected) if expected \ + assertpassed = self.compare(obtained, expected) if expected \ else self.compare(obtained) - if assertresult: - self.suite.assertion_ok() + if assertpassed: + self.suite.__assertion_ok__() else: - self.suite.assertion_fail() + self.suite.__assertion_fail__() \ No newline at end of file diff --git a/service_test/common/test_suite.py b/service_test/common/test_suite.py index 13bf2a9..1a2b494 100644 --- a/service_test/common/test_suite.py +++ b/service_test/common/test_suite.py @@ -26,10 +26,22 @@ def __init__(self, service): self.service_instance = {} self.assert_count = 0 self.assert_succ = 0 + self.failed_tests = [] + self.tests_info = {} @classmethod - def logTest(cls, msg): - print("-- Test {}: {}".format(cls.nexttextcase(), msg)) + def starttest(cls, msg): + testid = cls.nexttextcase() + self.tests_info[testid] = msg + print("-- Test {}: {}".format(testid, msg)) + + @classmethod + def endtest(cls, msg): + if self.assert_count > 0: + if self.assert_count != self.assert_succ: + self.failed_tests.append(self.test_number) + self.assert_count = 0 + self.assert_succ = 0 @classmethod def nexttextcase(cls): @@ -112,6 +124,12 @@ def kill_background_process(self, pid): command = "kill -KILL %s " % pid os.system(command) + def __getattribute__(self, attribute): + func = object.__getattribute__(self, attribute) + if not self.__issystemtestfunction__(attribute): + return fun + + def __getattr__(self, attribute): comparation_functions = ['eq', 'ne', 'lt', 'le', 'gt', 'ge'] assertstr = 'assert' @@ -121,10 +139,17 @@ def __getattr__(self, attribute): raise AttributeError - def assertion_ok(self): + def __assertion_ok__(self): self.assert_count += 1 self.assert_succ += 1 - def assertion_fail(self): + def __assertion_fail__(self): self.assert_count += 1 + def __issystemtestfunction__(self, name): + suite_functions = ['setup', 'run', 'teardown', 'required_resources'] + + if name[0] == '_' or name in suite_functions: + return False + else: + return True \ No newline at end of file From 6a22e91508477387ac7d67e9ff601aa2c0f0729c Mon Sep 17 00:00:00 2001 From: Anderson Dantas Date: Tue, 23 Apr 2019 11:27:26 -0300 Subject: [PATCH 05/29] Removed __getattribute__ from TestSuite --- service_test/common/test_suite.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/service_test/common/test_suite.py b/service_test/common/test_suite.py index 1a2b494..4687514 100644 --- a/service_test/common/test_suite.py +++ b/service_test/common/test_suite.py @@ -124,12 +124,6 @@ def kill_background_process(self, pid): command = "kill -KILL %s " % pid os.system(command) - def __getattribute__(self, attribute): - func = object.__getattribute__(self, attribute) - if not self.__issystemtestfunction__(attribute): - return fun - - def __getattr__(self, attribute): comparation_functions = ['eq', 'ne', 'lt', 'le', 'gt', 'ge'] assertstr = 'assert' From 31901f41b9c0fd155db7bda04be2f06f56f3facb Mon Sep 17 00:00:00 2001 From: Anderson Dantas Date: Wed, 24 Apr 2019 11:08:36 -0300 Subject: [PATCH 06/29] Refactor some tests on AS service test --- .../authentication_service/__init__.py | 3 +- .../general_configuration_test.py | 13 ---- .../authentication_service/service_tests.py | 31 +++++++-- service_test/common/assertion.py | 2 - service_test/common/test_factory.py | 2 +- service_test/common/test_suite.py | 63 +++++++++++-------- service_test/main.py | 2 - 7 files changed, 65 insertions(+), 51 deletions(-) delete mode 100644 service_test/authentication_service/general_configuration_test.py diff --git a/service_test/authentication_service/__init__.py b/service_test/authentication_service/__init__.py index b9534c8..3a662b9 100644 --- a/service_test/authentication_service/__init__.py +++ b/service_test/authentication_service/__init__.py @@ -1,8 +1,7 @@ # -*- coding: utf-8 -*- from .service_tests import * -from .general_configuration_test import * -modules = [service_tests, general_configuration_test] +modules = [service_tests] __all__ = [prop for module in modules for prop in module.__all__] diff --git a/service_test/authentication_service/general_configuration_test.py b/service_test/authentication_service/general_configuration_test.py deleted file mode 100644 index 056fe78..0000000 --- a/service_test/authentication_service/general_configuration_test.py +++ /dev/null @@ -1,13 +0,0 @@ -# -*- coding: utf-8 -*- - -__all__ = ['GeneralConfigurations'] - -class GeneralConfigurations: - application_repo_url = 'https://github.com/fogbow/authentication-service.git' - application_branch_under_test = 'develop' - application = { - 'port': 8080 - } - commands = { - 'run_application': "/usr/bin/mvn spring-boot:run" - } diff --git a/service_test/authentication_service/service_tests.py b/service_test/authentication_service/service_tests.py index d3c717f..3fde032 100644 --- a/service_test/authentication_service/service_tests.py +++ b/service_test/authentication_service/service_tests.py @@ -36,16 +36,35 @@ def teardown(self): shutil.rmtree(self.workdir) def run(self): - self.createtoken() + try: + self.createtoken() + self.failcreatetoken() + except Exception as e: + self.fail() + print("Interruped execution due to runtime error") + raise e + finally: + self.logresults() def createtoken(self): - self.logTest('Creating token') + self.__createtokentest__('Creating token', \ + self.resources['auth_credentials'], \ + self.assertlt) + + def failcreatetoken(self): + self.__createtokentest__('Fail attemp to creating token', \ + self.resources['invalid_auth_credentials'], \ + self.assertge) + + def __createtokentest__ (self, message, credentials, assertion): + self.starttest(message) + test = TestEngine(self.origin) - credentials = self.resources['auth_credentials'] res = test.create('token', body=credentials) - token = res['token'] - print('Token %s was obtained' % token) - # body = json.lao + + assertion(res.status_code, 400) + + self.endtest() def setpid(self, pid): self.pid = pid diff --git a/service_test/common/assertion.py b/service_test/common/assertion.py index 7eb81ad..75d7182 100644 --- a/service_test/common/assertion.py +++ b/service_test/common/assertion.py @@ -8,8 +8,6 @@ def __init__(self, suite, compare): self.suite = suite def __call__(self, obtained, expected=None): - print("Run to the hills", obtained, expected) - assertpassed = self.compare(obtained, expected) if expected \ else self.compare(obtained) diff --git a/service_test/common/test_factory.py b/service_test/common/test_factory.py index f12f14a..37d1334 100644 --- a/service_test/common/test_factory.py +++ b/service_test/common/test_factory.py @@ -47,7 +47,7 @@ def create(self, resource, **kwargs): req = FogbowRequest(url=url, headers=headers, body=body, method=str(HttpMethods.POST)) self.last_create = req.execute() - return json.loads(self.last_create.text) + return self.last_create def addHeader(self, header, headervalue): self.headers[header] = headervalue diff --git a/service_test/common/test_suite.py b/service_test/common/test_suite.py index 4687514..21b330e 100644 --- a/service_test/common/test_suite.py +++ b/service_test/common/test_suite.py @@ -19,29 +19,45 @@ class TestSuite(object): test_number = 0 workdir = tempfile.mkdtemp() + failed_tests = [] + tests_info = {} + assert_count = 0 + assert_succ = 0 def __init__(self, service): self.service = service self.service_dir = os.getcwd() + '/' + service - self.service_instance = {} - self.assert_count = 0 - self.assert_succ = 0 - self.failed_tests = [] - self.tests_info = {} - + @classmethod def starttest(cls, msg): testid = cls.nexttextcase() - self.tests_info[testid] = msg + cls.tests_info[testid] = msg print("-- Test {}: {}".format(testid, msg)) @classmethod - def endtest(cls, msg): - if self.assert_count > 0: - if self.assert_count != self.assert_succ: - self.failed_tests.append(self.test_number) - self.assert_count = 0 - self.assert_succ = 0 + def endtest(cls): + if cls.assert_count > 0: + if cls.assert_count != cls.assert_succ: + cls.failed_tests.append(cls.test_number) + cls.assert_count = 0 + cls.assert_succ = 0 + + @classmethod + def fail(cls): + cls.assert_count += 1 + cls.assert_succ = 0 + cls.endtest() + + @classmethod + def logresults(cls): + print("%d tests were run" % cls.test_number) + print("%d tests passed" % (cls.test_number - len(cls.failed_tests))) + print("%d tests failed" % len(cls.failed_tests)) + + if cls.failed_tests: + print("\n\n-- Failed tests --\n\n") + for test in cls.failed_tests: + print("%d -- %s" % (test, cls.tests_info[test])) @classmethod def nexttextcase(cls): @@ -109,7 +125,10 @@ def run_in_background(self, command, port): return self.getpidbyport(port) """ Use this with care """ - def getpidbyport(self, port): + def getpidbyport(self, port, ttl=20): + if ttl == 0: + return '' + temp_file_name = str(uuid.uuid4()) with open(temp_file_name, 'w') as file: subprocess.call("lsof -t -i:%s" % port, shell=True, stdout=file) @@ -117,7 +136,7 @@ def getpidbyport(self, port): content = Utils.file_get_contents(temp_file_name) if not content: time.sleep(1) - return self.getpidbyport(port) + return self.getpidbyport(port, ttl-1) return content def kill_background_process(self, pid): @@ -129,21 +148,15 @@ def __getattr__(self, attribute): assertstr = 'assert' for cmp in comparation_functions: if(attribute == assertstr+cmp): - return Assertion(self, getattr(operator, cmp)) + return Assertion(TestSuite, getattr(operator, cmp)) raise AttributeError + @classmethod def __assertion_ok__(self): self.assert_count += 1 self.assert_succ += 1 + @classmethod def __assertion_fail__(self): - self.assert_count += 1 - - def __issystemtestfunction__(self, name): - suite_functions = ['setup', 'run', 'teardown', 'required_resources'] - - if name[0] == '_' or name in suite_functions: - return False - else: - return True \ No newline at end of file + self.assert_count += 1 \ No newline at end of file diff --git a/service_test/main.py b/service_test/main.py index 57b2724..d53a26e 100644 --- a/service_test/main.py +++ b/service_test/main.py @@ -37,8 +37,6 @@ def getresources(service_resources,required_resources): print('###### Starting tests ######') servicetest = ServiceTest(service_under_test, configuration, service_resources) - servicetest.asserttrue(True) - servicetest.asserteq(1,2) servicetest.setup() servicetest.run() servicetest.teardown() From e0a3e4c3d23cd07e5169c57f331f38056ceebcf5 Mon Sep 17 00:00:00 2001 From: Anderson Dantas Date: Wed, 24 Apr 2019 11:16:37 -0300 Subject: [PATCH 07/29] Removed unecessary checks --- service_test/common/test_suite.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/service_test/common/test_suite.py b/service_test/common/test_suite.py index 21b330e..b72146a 100644 --- a/service_test/common/test_suite.py +++ b/service_test/common/test_suite.py @@ -107,10 +107,6 @@ def copy_conf_files(self): print('Configuration files source is "%s" and target is "%s"' % (source, target)) - # It's important to remove any noise from destination folder - shutil.rmtree(target) - shutil.copytree(source, target) - def run_in_background(self, command, port): print("service dir is %s" % self.service_dir) print("Workdir is %s" % os.getcwd()) From 36aae4b8de095e32abc2636ce80649961e12c9a1 Mon Sep 17 00:00:00 2001 From: Anderson Dantas Date: Wed, 24 Apr 2019 11:27:49 -0300 Subject: [PATCH 08/29] Started installing dependencies.properties --- service_test/common/constants.py | 2 ++ service_test/common/test_suite.py | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/service_test/common/constants.py b/service_test/common/constants.py index 21410f0..a702443 100644 --- a/service_test/common/constants.py +++ b/service_test/common/constants.py @@ -3,3 +3,5 @@ class CommonConstants: resource_path = 'src/main/resources/' private = 'private' + dependencies_properties = 'dependencies.properties' + install_dependencies_script = 'python2 ../scripts/install-dependencies.properities.py' diff --git a/service_test/common/test_suite.py b/service_test/common/test_suite.py index b72146a..7ae6a56 100644 --- a/service_test/common/test_suite.py +++ b/service_test/common/test_suite.py @@ -90,6 +90,17 @@ def download_repo(self, url, branch): repository = re.search("[^/]+(?=\.git)", url).group(0) return repository + def install_dependencies(self): + # TODO: Fix this setup + dep_propr_path = CommonConstants.resource_path + \ + CommonConstants.dependencies_properties + + script = CommonConstants.install_dependencies_script + + command = '{} {}'.format(script, dep_propr_path) + + os.system(command) + def clonerepo(self, url, branch = "master"): repository = self.download_repo(url, branch) @@ -97,6 +108,7 @@ def clonerepo(self, url, branch = "master"): os.chdir(self.workdir) self.reponame = repository + # self.install_dependencies() return self.workdir From 3bb87203ce19c621f5935587c6797420c0f8a9ff Mon Sep 17 00:00:00 2001 From: Anderson Dantas Date: Thu, 25 Apr 2019 10:48:09 -0300 Subject: [PATCH 09/29] Fixed installation of dependencies.properties --- .../authentication_service/service_tests.py | 6 +- service_test/common/__init__.py | 4 +- service_test/common/assertion.py | 2 +- service_test/common/constants.py | 2 +- ...test_suite.py => service_test_instance.py} | 23 +++--- service_test/common/start_service.sh | 2 - service_test/common/test_factory.py | 1 - service_test/membership_service/__init__.py | 7 ++ .../membership_service/service_tests.py | 74 +++++++++++++++++++ 9 files changed, 102 insertions(+), 19 deletions(-) rename service_test/common/{test_suite.py => service_test_instance.py} (88%) delete mode 100644 service_test/common/start_service.sh create mode 100644 service_test/membership_service/__init__.py create mode 100644 service_test/membership_service/service_tests.py diff --git a/service_test/authentication_service/service_tests.py b/service_test/authentication_service/service_tests.py index 3fde032..93e450b 100644 --- a/service_test/authentication_service/service_tests.py +++ b/service_test/authentication_service/service_tests.py @@ -3,14 +3,14 @@ import requests import shutil -from common import TestSuite, TestEngine +from common import ServiceTestInstance, TestEngine __all__ = ['AuthTest'] -class AuthTest(TestSuite): +class AuthTest(ServiceTestInstance): def __init__(self, service, configuration, resources): - TestSuite.__init__(self, service) + ServiceTestInstance.__init__(self, service) self.conf = configuration self.pid = None self.resources = resources diff --git a/service_test/common/__init__.py b/service_test/common/__init__.py index dae5803..2368c91 100644 --- a/service_test/common/__init__.py +++ b/service_test/common/__init__.py @@ -2,10 +2,10 @@ from .constants import * from .http_methods import * from .instance_states import * +from .service_test_instance import * from .test_factory import * -from .test_suite import * from .utils import * -modules = [constants, http_methods, instance_states, test_suite, test_factory, utils] +modules = [constants, http_methods, instance_states, service_test_instance, test_factory, utils] __all__ = [prop for module in modules for prop in module.__all__] diff --git a/service_test/common/assertion.py b/service_test/common/assertion.py index 75d7182..8fff239 100644 --- a/service_test/common/assertion.py +++ b/service_test/common/assertion.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -""" Util class for TestSuite """ +""" Util class for ServiceTestInstance """ class Assertion(object): def __init__(self, suite, compare): diff --git a/service_test/common/constants.py b/service_test/common/constants.py index a702443..fd64d0a 100644 --- a/service_test/common/constants.py +++ b/service_test/common/constants.py @@ -4,4 +4,4 @@ class CommonConstants: resource_path = 'src/main/resources/' private = 'private' dependencies_properties = 'dependencies.properties' - install_dependencies_script = 'python2 ../scripts/install-dependencies.properities.py' + install_dependencies_script = 'python2 {}/../../scripts/install-dependencies.properities.py' diff --git a/service_test/common/test_suite.py b/service_test/common/service_test_instance.py similarity index 88% rename from service_test/common/test_suite.py rename to service_test/common/service_test_instance.py index 7ae6a56..b6a5289 100644 --- a/service_test/common/test_suite.py +++ b/service_test/common/service_test_instance.py @@ -13,9 +13,9 @@ from .utils import Utils from .assertion import Assertion -__all__ = ['TestSuite'] +__all__ = ['ServiceTestInstance'] -class TestSuite(object): +class ServiceTestInstance(object): test_number = 0 workdir = tempfile.mkdtemp() @@ -92,14 +92,15 @@ def download_repo(self, url, branch): def install_dependencies(self): # TODO: Fix this setup - dep_propr_path = CommonConstants.resource_path + \ + dep_propr_path = self.workdir + '/' + CommonConstants.resource_path + \ CommonConstants.dependencies_properties - script = CommonConstants.install_dependencies_script + script = CommonConstants.install_dependencies_script.format(self.service_dir) command = '{} {}'.format(script, dep_propr_path) - + print("command", command) os.system(command) + os.chdir(self.workdir) def clonerepo(self, url, branch = "master"): repository = self.download_repo(url, branch) @@ -108,8 +109,7 @@ def clonerepo(self, url, branch = "master"): os.chdir(self.workdir) self.reponame = repository - # self.install_dependencies() - + return self.workdir def copy_conf_files(self): @@ -119,7 +119,12 @@ def copy_conf_files(self): print('Configuration files source is "%s" and target is "%s"' % (source, target)) + # It's important to remove any noise from destination folder + shutil.rmtree(target) + shutil.copytree(source, target) + def run_in_background(self, command, port): + self.install_dependencies() print("service dir is %s" % self.service_dir) print("Workdir is %s" % os.getcwd()) self.copy_conf_files() @@ -134,7 +139,7 @@ def run_in_background(self, command, port): """ Use this with care """ def getpidbyport(self, port, ttl=20): - if ttl == 0: + if ttl <= 0: return '' temp_file_name = str(uuid.uuid4()) @@ -156,7 +161,7 @@ def __getattr__(self, attribute): assertstr = 'assert' for cmp in comparation_functions: if(attribute == assertstr+cmp): - return Assertion(TestSuite, getattr(operator, cmp)) + return Assertion(ServiceTestInstance, getattr(operator, cmp)) raise AttributeError diff --git a/service_test/common/start_service.sh b/service_test/common/start_service.sh deleted file mode 100644 index 95b1837..0000000 --- a/service_test/common/start_service.sh +++ /dev/null @@ -1,2 +0,0 @@ -nohup $1 > $2 2>&1 & -echo $! > save_pid.txt diff --git a/service_test/common/test_factory.py b/service_test/common/test_factory.py index 37d1334..8286042 100644 --- a/service_test/common/test_factory.py +++ b/service_test/common/test_factory.py @@ -3,7 +3,6 @@ import json import requests -from collections import namedtuple from os import path from . import HttpMethods diff --git a/service_test/membership_service/__init__.py b/service_test/membership_service/__init__.py new file mode 100644 index 0000000..3a662b9 --- /dev/null +++ b/service_test/membership_service/__init__.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- + +from .service_tests import * + +modules = [service_tests] + +__all__ = [prop for module in modules for prop in module.__all__] diff --git a/service_test/membership_service/service_tests.py b/service_test/membership_service/service_tests.py new file mode 100644 index 0000000..02e9b52 --- /dev/null +++ b/service_test/membership_service/service_tests.py @@ -0,0 +1,74 @@ +# -*- coding: utf-8 -*- + +import requests +import shutil + +from common import ServiceTestInstance, TestEngine + +__all__ = ['AuthTest'] + +class AuthTest(ServiceTestInstance): + + def __init__(self, service, configuration, resources): + ServiceTestInstance.__init__(self, service) + self.conf = configuration + self.pid = None + self.resources = resources + self.port = self.conf['application']['port'] + self.origin = 'http://localhost:' + str(self.port) + + def setup(self): + repo_url = self.conf['application']['repo_url'] + branch = self.conf['application']['branch_under_test'] + + self.clonerepo(repo_url, branch) + + command = self.conf['commands']['run_application'] + port = self.port + + pid = self.run_in_background(command, port) + + print("pid for proccess is %s" % pid) + self.setpid(pid) + + def teardown(self): + self.kill_background_process(self.pid) + shutil.rmtree(self.workdir) + + def run(self): + try: + self.createtoken() + self.failcreatetoken() + except Exception as e: + self.fail() + print("Interruped execution due to runtime error") + raise e + finally: + self.logresults() + + def createtoken(self): + self.__createtokentest__('Creating token', \ + self.resources['auth_credentials'], \ + self.assertlt) + + def failcreatetoken(self): + self.__createtokentest__('Fail attemp to creating token', \ + self.resources['invalid_auth_credentials'], \ + self.assertge) + + def __createtokentest__ (self, message, credentials, assertion): + self.starttest(message) + + test = TestEngine(self.origin) + res = test.create('token', body=credentials) + + assertion(res.status_code, 400) + + self.endtest() + + def setpid(self, pid): + self.pid = pid + + @classmethod + def required_resources(self): + return [] From 22e8abab42cc256100848d227036ad25350dd77c Mon Sep 17 00:00:00 2001 From: Anderson Dantas Date: Thu, 25 Apr 2019 15:06:28 -0300 Subject: [PATCH 10/29] Implemented tests for version and public key --- .gitignore | 1 + scripts/install-dependencies.properities.py | 21 +++---- .../authentication_service/service_tests.py | 35 ++--------- service_test/common/__init__.py | 4 +- service_test/common/assertion.py | 2 +- service_test/common/check_version.py | 25 ++++++++ .../common/check_version_and_public_key.py | 26 ++++++++ service_test/common/service_test_instance.py | 58 ++++++++++++------ service_test/common/test_factory.py | 17 ++++++ service_test/main.py | 5 +- .../membership_service/service_tests.py | 61 ++++--------------- 11 files changed, 144 insertions(+), 111 deletions(-) create mode 100644 service_test/common/check_version.py create mode 100644 service_test/common/check_version_and_public_key.py diff --git a/.gitignore b/.gitignore index bfcf896..d73b0e9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ **/*.pyc **/__pycache__/ **/private/* +**/.vscode diff --git a/scripts/install-dependencies.properities.py b/scripts/install-dependencies.properities.py index e79ea51..3fd7de8 100755 --- a/scripts/install-dependencies.properities.py +++ b/scripts/install-dependencies.properities.py @@ -5,39 +5,38 @@ import re if len(sys.argv) == 1: - print "No argument passed" + print("No argument passed") exit(1) if len(sys.argv) > 2: - print "More than 1 parameter given" + print("More than 1 parameter given") exit(-1) with open(sys.argv[1]) as f: content = f.readlines() - for line in content: os.chdir('..') - + dependency, target = line.split('=') if target == None or target == '': target = 'develop' - + project = dependency.split("/")[-1].split(".")[0] repository = re.search("[^/]+(?=\.git)", dependency).group(0) - - print "> git clone \"%s\" into \"%s\"" % (dependency, project) + + print("> git clone \"%s\" into \"%s\"" % (dependency, project)) os.system("git clone " + dependency) - print "> cd %s" % repository + print("> cd %s" % repository) os.chdir(repository) - print "> git checkout " + target + print("> git checkout " + target) os.system("git checkout " + target) - print os.getcwd() + print(os.getcwd()) - print "> mvn install" + print("> mvn install") os.system("mvn install") \ No newline at end of file diff --git a/service_test/authentication_service/service_tests.py b/service_test/authentication_service/service_tests.py index 93e450b..cbf6a9c 100644 --- a/service_test/authentication_service/service_tests.py +++ b/service_test/authentication_service/service_tests.py @@ -3,40 +3,18 @@ import requests import shutil -from common import ServiceTestInstance, TestEngine +from common import TestEngine, VersionandPublicKeyCheck __all__ = ['AuthTest'] -class AuthTest(ServiceTestInstance): +class AuthTest(VersionandPublicKeyCheck): def __init__(self, service, configuration, resources): - ServiceTestInstance.__init__(self, service) - self.conf = configuration - self.pid = None - self.resources = resources - self.port = self.conf['application']['port'] - self.origin = 'http://localhost:' + str(self.port) - - def setup(self): - repo_url = self.conf['application']['repo_url'] - branch = self.conf['application']['branch_under_test'] - - self.clonerepo(repo_url, branch) - - command = self.conf['commands']['run_application'] - port = self.port - - pid = self.run_in_background(command, port) - - print("pid for proccess is %s" % pid) - self.setpid(pid) - - def teardown(self): - self.kill_background_process(self.pid) - shutil.rmtree(self.workdir) + super().__init__(service, configuration, resources) def run(self): try: + super().run() self.createtoken() self.failcreatetoken() except Exception as e: @@ -52,7 +30,7 @@ def createtoken(self): self.assertlt) def failcreatetoken(self): - self.__createtokentest__('Fail attemp to creating token', \ + self.__createtokentest__('Fail attemp to create token', \ self.resources['invalid_auth_credentials'], \ self.assertge) @@ -66,9 +44,6 @@ def __createtokentest__ (self, message, credentials, assertion): self.endtest() - def setpid(self, pid): - self.pid = pid - @classmethod def required_resources(self): return ['auth_credentials', 'invalid_auth_credentials'] diff --git a/service_test/common/__init__.py b/service_test/common/__init__.py index 2368c91..7a464e8 100644 --- a/service_test/common/__init__.py +++ b/service_test/common/__init__.py @@ -5,7 +5,9 @@ from .service_test_instance import * from .test_factory import * from .utils import * +from .check_version import * +from .check_version_and_public_key import * -modules = [constants, http_methods, instance_states, service_test_instance, test_factory, utils] +modules = [constants, http_methods, instance_states, service_test_instance, test_factory, utils, check_version, check_version_and_public_key] __all__ = [prop for module in modules for prop in module.__all__] diff --git a/service_test/common/assertion.py b/service_test/common/assertion.py index 8fff239..f612ec3 100644 --- a/service_test/common/assertion.py +++ b/service_test/common/assertion.py @@ -8,7 +8,7 @@ def __init__(self, suite, compare): self.suite = suite def __call__(self, obtained, expected=None): - assertpassed = self.compare(obtained, expected) if expected \ + assertpassed = self.compare(obtained, expected) if expected != None \ else self.compare(obtained) if assertpassed: diff --git a/service_test/common/check_version.py b/service_test/common/check_version.py new file mode 100644 index 0000000..a6ca30d --- /dev/null +++ b/service_test/common/check_version.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- + +from .service_test_instance import ServiceTestInstance +from .test_factory import TestEngine + +__all__ = ['VersionCheck'] + +class VersionCheck(ServiceTestInstance): + + def __init__(self, service, configuration, resources): + return super().__init__(service, configuration, resources) + + def run(self): + self.version() + + def version(self): + self.starttest('Requesting version') + + test = TestEngine(self.origin) + res = test.get('version').json() + version = res['version'] + + self.assertgt(len(version), 0) + + self.endtest() \ No newline at end of file diff --git a/service_test/common/check_version_and_public_key.py b/service_test/common/check_version_and_public_key.py new file mode 100644 index 0000000..d06ac7d --- /dev/null +++ b/service_test/common/check_version_and_public_key.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- + +from .service_test_instance import ServiceTestInstance +from .test_factory import TestEngine +from .check_version import VersionCheck + +__all__ = ['VersionandPublicKeyCheck'] + +class VersionandPublicKeyCheck(VersionCheck): + + def __init__(self, service, configuration, resources): + return super().__init__(service, configuration, resources) + + def run(self): + super().run() + self.publickey() + + def publickey(self): + self.starttest('Requesting public key') + + test = TestEngine(self.origin) + res = test.get('public-key').json() + version = res['publicKey'] + self.asserteq(len(version)%3, 0) + + self.endtest() \ No newline at end of file diff --git a/service_test/common/service_test_instance.py b/service_test/common/service_test_instance.py index b6a5289..9a11bbc 100644 --- a/service_test/common/service_test_instance.py +++ b/service_test/common/service_test_instance.py @@ -24,10 +24,15 @@ class ServiceTestInstance(object): assert_count = 0 assert_succ = 0 - def __init__(self, service): + def __init__(self, service, configuration, resources): + self.conf = configuration self.service = service self.service_dir = os.getcwd() + '/' + service - + self.pid = None + self.resources = resources + self.port = self.conf['application']['port'] + self.origin = 'http://localhost:' + str(self.port) + @classmethod def starttest(cls, msg): testid = cls.nexttextcase() @@ -45,7 +50,7 @@ def endtest(cls): @classmethod def fail(cls): cls.assert_count += 1 - cls.assert_succ = 0 + # cls.assert_succ = 0 cls.endtest() @classmethod @@ -64,18 +69,33 @@ def nexttextcase(cls): cls.test_number += 1 return cls.test_number - def setup(self, pid): - raise NotImplementedError - def run(self): raise NotImplementedError - def teardown(self): - raise NotImplementedError - @classmethod def required_resources(self): raise NotImplementedError + + def setup(self): + repo_url = self.conf['application']['repo_url'] + branch = self.conf['application']['branch_under_test'] + + self.clonerepo(repo_url, branch) + + command = self.conf['commands']['run_application'] + port = self.port + + pid = self.run_in_background(command, port) + if not pid: + print('Could not start the service. Exiting...') + exit(-1) + + print("pid for proccess is %s" % pid) + self.pid = pid + + def teardown(self): + self.kill_background_process(self.pid) + shutil.rmtree(self.workdir) def goto_workdir(self): if os.path.exists(self.workdir): @@ -86,20 +106,18 @@ def goto_workdir(self): def download_repo(self, url, branch): self.goto_workdir() - os.system("git clone --single-branch --branch %s %s " % (branch, url)) + self.__runcommand__("git clone --single-branch --branch %s %s " % (branch, url)) repository = re.search("[^/]+(?=\.git)", url).group(0) return repository def install_dependencies(self): - # TODO: Fix this setup dep_propr_path = self.workdir + '/' + CommonConstants.resource_path + \ CommonConstants.dependencies_properties script = CommonConstants.install_dependencies_script.format(self.service_dir) command = '{} {}'.format(script, dep_propr_path) - print("command", command) - os.system(command) + self.__runcommand__(command) os.chdir(self.workdir) def clonerepo(self, url, branch = "master"): @@ -120,12 +138,14 @@ def copy_conf_files(self): print('Configuration files source is "%s" and target is "%s"' % (source, target)) # It's important to remove any noise from destination folder - shutil.rmtree(target) + if os.path.exists(target): + shutil.rmtree(target) + shutil.copytree(source, target) def run_in_background(self, command, port): self.install_dependencies() - print("service dir is %s" % self.service_dir) + print("Service dir is %s" % self.service_dir) print("Workdir is %s" % os.getcwd()) self.copy_conf_files() @@ -154,7 +174,7 @@ def getpidbyport(self, port, ttl=20): def kill_background_process(self, pid): command = "kill -KILL %s " % pid - os.system(command) + self.__runcommand__(command) def __getattr__(self, attribute): comparation_functions = ['eq', 'ne', 'lt', 'le', 'gt', 'ge'] @@ -172,4 +192,8 @@ def __assertion_ok__(self): @classmethod def __assertion_fail__(self): - self.assert_count += 1 \ No newline at end of file + self.assert_count += 1 + + def __runcommand__(self, command): + print('\n>', command) + os.system(command) \ No newline at end of file diff --git a/service_test/common/test_factory.py b/service_test/common/test_factory.py index 8286042..3289275 100644 --- a/service_test/common/test_factory.py +++ b/service_test/common/test_factory.py @@ -48,6 +48,23 @@ def create(self, resource, **kwargs): return self.last_create + def get(self, resource, **kwargs): + available_endpoints = { + 'members': '/members', + 'public-key': '/publicKey', + 'version': '/version' + } + + urlpath = available_endpoints[resource] + url = self.service_url + '/' + urlpath + + headers = kwargs.get('headers', self.headers) + body = kwargs.get('body', self.body) + + req = FogbowRequest(url=url, headers=headers, body=body, method=str(HttpMethods.GET)) + + return req.execute() + def addHeader(self, header, headervalue): self.headers[header] = headervalue diff --git a/service_test/main.py b/service_test/main.py index d53a26e..874d25b 100644 --- a/service_test/main.py +++ b/service_test/main.py @@ -3,7 +3,7 @@ import json import sys from authentication_service import AuthTest -from collections import namedtuple +from membership_service import MembersTest from common import * from os import path @@ -21,7 +21,8 @@ def getresources(service_resources,required_resources): if __name__ == "__main__": services = { - 'authentication_service': AuthTest + 'authentication_service': AuthTest, + 'membership_service': MembersTest } resources_path = 'test_resources' diff --git a/service_test/membership_service/service_tests.py b/service_test/membership_service/service_tests.py index 02e9b52..3658b31 100644 --- a/service_test/membership_service/service_tests.py +++ b/service_test/membership_service/service_tests.py @@ -3,42 +3,19 @@ import requests import shutil -from common import ServiceTestInstance, TestEngine +from common import TestEngine, VersionCheck -__all__ = ['AuthTest'] +__all__ = ['MembersTest'] -class AuthTest(ServiceTestInstance): +class MembersTest(VersionCheck): def __init__(self, service, configuration, resources): - ServiceTestInstance.__init__(self, service) - self.conf = configuration - self.pid = None - self.resources = resources - self.port = self.conf['application']['port'] - self.origin = 'http://localhost:' + str(self.port) - - def setup(self): - repo_url = self.conf['application']['repo_url'] - branch = self.conf['application']['branch_under_test'] - - self.clonerepo(repo_url, branch) - - command = self.conf['commands']['run_application'] - port = self.port - - pid = self.run_in_background(command, port) - - print("pid for proccess is %s" % pid) - self.setpid(pid) - - def teardown(self): - self.kill_background_process(self.pid) - shutil.rmtree(self.workdir) + super().__init__(service, configuration, resources) def run(self): try: - self.createtoken() - self.failcreatetoken() + super().run() + self.listmembers() except Exception as e: self.fail() print("Interruped execution due to runtime error") @@ -46,29 +23,15 @@ def run(self): finally: self.logresults() - def createtoken(self): - self.__createtokentest__('Creating token', \ - self.resources['auth_credentials'], \ - self.assertlt) - - def failcreatetoken(self): - self.__createtokentest__('Fail attemp to creating token', \ - self.resources['invalid_auth_credentials'], \ - self.assertge) - - def __createtokentest__ (self, message, credentials, assertion): - self.starttest(message) - - test = TestEngine(self.origin) - res = test.create('token', body=credentials) - - assertion(res.status_code, 400) + def listmembers(self): + self.starttest('List members') + test = TestEngine(self.origin) + res = test.get('members').json() + members = res['members'] + self.asserteq(type(members), list) self.endtest() - def setpid(self, pid): - self.pid = pid - @classmethod def required_resources(self): return [] From b3a5de8a57aade2b265e08b7341b0fb5808f2490 Mon Sep 17 00:00:00 2001 From: Anderson Dantas Date: Mon, 29 Apr 2019 17:23:18 -0300 Subject: [PATCH 11/29] More tests for MS --- service_test/membership_service/service_tests.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/service_test/membership_service/service_tests.py b/service_test/membership_service/service_tests.py index 3658b31..d5684a3 100644 --- a/service_test/membership_service/service_tests.py +++ b/service_test/membership_service/service_tests.py @@ -2,6 +2,7 @@ import requests import shutil +import re from common import TestEngine, VersionCheck @@ -29,7 +30,10 @@ def listmembers(self): test = TestEngine(self.origin) res = test.get('members').json() members = res['members'] + self.asserteq(type(members), list) + self.assertge(len(members), 1) + self.endtest() @classmethod From 7e8225ba1300a2ba9d37dd4aaf130ddd9919edaa Mon Sep 17 00:00:00 2001 From: Anderson Dantas Date: Tue, 7 May 2019 11:44:49 -0300 Subject: [PATCH 12/29] Started implementing RAS system tests --- .../authentication_service/service_tests.py | 3 --- service_test/common/assertion.py | 6 +++-- .../common/check_version_and_public_key.py | 5 ++-- service_test/common/service_test_instance.py | 7 +++--- service_test/main.py | 14 +++++++---- .../membership_service/service_tests.py | 4 ---- .../resource_allocation_service/__init__.py | 7 ++++++ .../service_tests.py | 24 +++++++++++++++++++ 8 files changed, 50 insertions(+), 20 deletions(-) create mode 100644 service_test/resource_allocation_service/__init__.py create mode 100644 service_test/resource_allocation_service/service_tests.py diff --git a/service_test/authentication_service/service_tests.py b/service_test/authentication_service/service_tests.py index cbf6a9c..b5ae63a 100644 --- a/service_test/authentication_service/service_tests.py +++ b/service_test/authentication_service/service_tests.py @@ -1,8 +1,5 @@ # -*- coding: utf-8 -*- -import requests -import shutil - from common import TestEngine, VersionandPublicKeyCheck __all__ = ['AuthTest'] diff --git a/service_test/common/assertion.py b/service_test/common/assertion.py index f612ec3..28af4ed 100644 --- a/service_test/common/assertion.py +++ b/service_test/common/assertion.py @@ -8,8 +8,10 @@ def __init__(self, suite, compare): self.suite = suite def __call__(self, obtained, expected=None): - assertpassed = self.compare(obtained, expected) if expected != None \ - else self.compare(obtained) + if expected != None: + assertpassed = self.compare(obtained,expected) + else: + assertpassed = self.compare(obtained) if assertpassed: self.suite.__assertion_ok__() diff --git a/service_test/common/check_version_and_public_key.py b/service_test/common/check_version_and_public_key.py index d06ac7d..10f0938 100644 --- a/service_test/common/check_version_and_public_key.py +++ b/service_test/common/check_version_and_public_key.py @@ -20,7 +20,8 @@ def publickey(self): test = TestEngine(self.origin) res = test.get('public-key').json() - version = res['publicKey'] - self.asserteq(len(version)%3, 0) + publickey = res['publicKey'] + + self.asserteq(len(publickey)%3, 0) self.endtest() \ No newline at end of file diff --git a/service_test/common/service_test_instance.py b/service_test/common/service_test_instance.py index 9a11bbc..f200a25 100644 --- a/service_test/common/service_test_instance.py +++ b/service_test/common/service_test_instance.py @@ -36,6 +36,8 @@ def __init__(self, service, configuration, resources): @classmethod def starttest(cls, msg): testid = cls.nexttextcase() + cls.assert_count = 0 + cls.assert_succ = 0 cls.tests_info[testid] = msg print("-- Test {}: {}".format(testid, msg)) @@ -44,13 +46,10 @@ def endtest(cls): if cls.assert_count > 0: if cls.assert_count != cls.assert_succ: cls.failed_tests.append(cls.test_number) - cls.assert_count = 0 - cls.assert_succ = 0 @classmethod def fail(cls): cls.assert_count += 1 - # cls.assert_succ = 0 cls.endtest() @classmethod @@ -158,7 +157,7 @@ def run_in_background(self, command, port): return self.getpidbyport(port) """ Use this with care """ - def getpidbyport(self, port, ttl=20): + def getpidbyport(self, port, ttl=50): if ttl <= 0: return '' diff --git a/service_test/main.py b/service_test/main.py index 874d25b..e75846c 100644 --- a/service_test/main.py +++ b/service_test/main.py @@ -1,18 +1,19 @@ # -*- coding: utf-8 -*- import json +import os import sys from authentication_service import AuthTest from membership_service import MembersTest +from resource_allocation_service import RASTest from common import * -from os import path def getresources(service_resources,required_resources): resources = {} jsonsuffix = '.json' for res in required_resources: - resource_path = path.join(service_resources, res + jsonsuffix) + resource_path = os.path.join(service_resources, res + jsonsuffix) resourcejson = Utils.load_json(resource_path) resources[res] = resourcejson @@ -20,19 +21,22 @@ def getresources(service_resources,required_resources): if __name__ == "__main__": + curdir = os.getcwd() + services = { 'authentication_service': AuthTest, - 'membership_service': MembersTest + 'membership_service': MembersTest, + 'resource_allocation_service': RASTest } resources_path = 'test_resources' service_under_test = sys.argv[1] ServiceTest = services[service_under_test] - test_config_path = path.join(resources_path, service_under_test, 'service_test_conf.json') + test_config_path = os.path.join(resources_path, service_under_test, 'service_test_conf.json') configuration = Utils.load_json(test_config_path) - service_resources_path = path.join(resources_path, service_under_test) + service_resources_path = os.path.join(resources_path, service_under_test) service_resources = getresources(service_resources_path, ServiceTest.required_resources()) print('###### Starting tests ######') diff --git a/service_test/membership_service/service_tests.py b/service_test/membership_service/service_tests.py index d5684a3..aee8220 100644 --- a/service_test/membership_service/service_tests.py +++ b/service_test/membership_service/service_tests.py @@ -1,9 +1,5 @@ # -*- coding: utf-8 -*- -import requests -import shutil -import re - from common import TestEngine, VersionCheck __all__ = ['MembersTest'] diff --git a/service_test/resource_allocation_service/__init__.py b/service_test/resource_allocation_service/__init__.py new file mode 100644 index 0000000..3a662b9 --- /dev/null +++ b/service_test/resource_allocation_service/__init__.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- + +from .service_tests import * + +modules = [service_tests] + +__all__ = [prop for module in modules for prop in module.__all__] diff --git a/service_test/resource_allocation_service/service_tests.py b/service_test/resource_allocation_service/service_tests.py new file mode 100644 index 0000000..c233969 --- /dev/null +++ b/service_test/resource_allocation_service/service_tests.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- + +from common import TestEngine, VersionandPublicKeyCheck + +__all__ = ['RASTest'] + +class RASTest(VersionandPublicKeyCheck): + + def __init__(self, service, configuration, resources): + super().__init__(service, configuration, resources) + + def run(self): + try: + super().run() + except Exception as e: + self.fail() + print("Interruped execution due to runtime error") + raise e + finally: + self.logresults() + + @classmethod + def required_resources(self): + return [] From 614f158d9a9ceeab72ba32327d1c875464e5d332 Mon Sep 17 00:00:00 2001 From: Anderson Dantas Date: Wed, 8 May 2019 15:44:32 -0300 Subject: [PATCH 13/29] Implemented support to dependent services --- service_test/common/__init__.py | 5 +- service_test/common/assertion.py | 3 +- service_test/common/response_store.py | 16 ++++++ service_test/common/test_factory.py | 16 +++++- service_test/main.py | 57 +++++++++++++++---- .../service_tests.py | 15 +++++ 6 files changed, 96 insertions(+), 16 deletions(-) create mode 100644 service_test/common/response_store.py diff --git a/service_test/common/__init__.py b/service_test/common/__init__.py index 7a464e8..46ff7b8 100644 --- a/service_test/common/__init__.py +++ b/service_test/common/__init__.py @@ -3,11 +3,14 @@ from .http_methods import * from .instance_states import * from .service_test_instance import * +from .response_store import * from .test_factory import * from .utils import * from .check_version import * from .check_version_and_public_key import * -modules = [constants, http_methods, instance_states, service_test_instance, test_factory, utils, check_version, check_version_and_public_key] +modules = [constants, http_methods, instance_states, service_test_instance, + test_factory, utils, check_version, check_version_and_public_key, + response_store] __all__ = [prop for module in modules for prop in module.__all__] diff --git a/service_test/common/assertion.py b/service_test/common/assertion.py index 28af4ed..6881589 100644 --- a/service_test/common/assertion.py +++ b/service_test/common/assertion.py @@ -17,5 +17,6 @@ def __call__(self, obtained, expected=None): self.suite.__assertion_ok__() else: self.suite.__assertion_fail__() - + + return assertpassed \ No newline at end of file diff --git a/service_test/common/response_store.py b/service_test/common/response_store.py new file mode 100644 index 0000000..cfca165 --- /dev/null +++ b/service_test/common/response_store.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- + +from collections import defaultdict + +__all__ = ['ResourceStore'] + +class ResourceStore: + data = defaultdict(list) + + @classmethod + def addresourceid(cls, resource, resid): + cls.data[resource].append(resid) + + @classmethod + def getresourceidd(cls, resource): + return cls.data[resource] \ No newline at end of file diff --git a/service_test/common/test_factory.py b/service_test/common/test_factory.py index 3289275..193966d 100644 --- a/service_test/common/test_factory.py +++ b/service_test/common/test_factory.py @@ -5,6 +5,7 @@ from os import path from . import HttpMethods +from . import ResourceStore __all__ = ['TestEngine'] @@ -15,7 +16,7 @@ def __init__(self, service_url): self.body = {} self.headers = {} - def wait_until_ready(self, tries = -1): + def wait_until_ready(self, tries = 50): if tries == 0: return None lasturl = str(self.last_create.url) @@ -46,6 +47,11 @@ def create(self, resource, **kwargs): req = FogbowRequest(url=url, headers=headers, body=body, method=str(HttpMethods.POST)) self.last_create = req.execute() + if self.last_create.status_code < 400 and resource == 'token': + token = self.last_create.json().get('token', None) + self.addHeader('Fogbow-User-Token', token) + + return self.last_create def get(self, resource, **kwargs): @@ -66,7 +72,13 @@ def get(self, resource, **kwargs): return req.execute() def addHeader(self, header, headervalue): - self.headers[header] = headervalue + if header and headervalue: + print('Setting default header "{}" to "{}"'.format(header, headervalue)) + self.headers[header] = headervalue + else: + print("Ignoring header setting. One or more parameters were empty.") + print("Header: {}".format(header)) + print("Header content: {}".format(headervalue)) class FogbowRequest: def __init__(self, url, method = 'get', body = {}, headers = {}): diff --git a/service_test/main.py b/service_test/main.py index e75846c..a1ebacb 100644 --- a/service_test/main.py +++ b/service_test/main.py @@ -8,7 +8,9 @@ from resource_allocation_service import RASTest from common import * -def getresources(service_resources,required_resources): +resources_path = 'test_resources' + +def getresources(service_resources ,required_resources): resources = {} jsonsuffix = '.json' @@ -19,31 +21,62 @@ def getresources(service_resources,required_resources): return resources -if __name__ == "__main__": - - curdir = os.getcwd() +def getserviceconf(servicename): + test_config_path = os.path.join(resources_path, servicename, 'service_test_conf.json') + return Utils.load_json(test_config_path) +def getservice(servicename): services = { 'authentication_service': AuthTest, 'membership_service': MembersTest, 'resource_allocation_service': RASTest } + + ServiceTest = services[servicename] + + configuration = getserviceconf(servicename) + + service_resources_path = os.path.join(resources_path, servicename) + service_resources = getresources(service_resources_path, ServiceTest.required_resources()) + + return ServiceTest(servicename, configuration, service_resources) + +if __name__ == "__main__": + + curdir = os.getcwd() - resources_path = 'test_resources' service_under_test = sys.argv[1] - ServiceTest = services[service_under_test] - test_config_path = os.path.join(resources_path, service_under_test, 'service_test_conf.json') - configuration = Utils.load_json(test_config_path) + servicetest = getservice(service_under_test) + conf = getserviceconf(service_under_test) + dependencies_services = [] - service_resources_path = os.path.join(resources_path, service_under_test) - service_resources = getresources(service_resources_path, ServiceTest.required_resources()) + # start dependencies services + for servicename in conf['services']: + serviceinstance = getservice(servicename) + serviceinstance.setup() + + print(servicename, serviceinstance) + + dependencies_services.append(serviceinstance) + + # those setups may change current dir + os.chdir(curdir) print('###### Starting tests ######') - servicetest = ServiceTest(service_under_test, configuration, service_resources) servicetest.setup() servicetest.run() - servicetest.teardown() print('###### Tests are over ######') + print('###### Tearing down ######') + + servicetest.teardown() + + for serviceinstance in dependencies_services: + serviceinstance.teardown() + + # these teardowns may change current dir + os.chdir(curdir) + + print('###### Done ######') diff --git a/service_test/resource_allocation_service/service_tests.py b/service_test/resource_allocation_service/service_tests.py index c233969..6e4a603 100644 --- a/service_test/resource_allocation_service/service_tests.py +++ b/service_test/resource_allocation_service/service_tests.py @@ -19,6 +19,21 @@ def run(self): finally: self.logresults() + def getimages(self): + pass + + def createnetwork(self): + pass + + def createcompute(self): + pass + + def createvolume(self): + pass + + def createattachment(self): + pass + @classmethod def required_resources(self): return [] From ccbcd313018c97cb35f6c0348673fa7eef9d7432 Mon Sep 17 00:00:00 2001 From: Anderson Dantas Date: Wed, 8 May 2019 19:23:09 -0300 Subject: [PATCH 14/29] Remvoed unnecessary __init__ overrides --- service_test/common/check_version.py | 3 --- service_test/common/check_version_and_public_key.py | 3 --- service_test/common/test_factory.py | 7 ++++++- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/service_test/common/check_version.py b/service_test/common/check_version.py index a6ca30d..a8e5101 100644 --- a/service_test/common/check_version.py +++ b/service_test/common/check_version.py @@ -7,9 +7,6 @@ class VersionCheck(ServiceTestInstance): - def __init__(self, service, configuration, resources): - return super().__init__(service, configuration, resources) - def run(self): self.version() diff --git a/service_test/common/check_version_and_public_key.py b/service_test/common/check_version_and_public_key.py index 10f0938..733bc5d 100644 --- a/service_test/common/check_version_and_public_key.py +++ b/service_test/common/check_version_and_public_key.py @@ -8,9 +8,6 @@ class VersionandPublicKeyCheck(VersionCheck): - def __init__(self, service, configuration, resources): - return super().__init__(service, configuration, resources) - def run(self): super().run() self.publickey() diff --git a/service_test/common/test_factory.py b/service_test/common/test_factory.py index 193966d..9a228f3 100644 --- a/service_test/common/test_factory.py +++ b/service_test/common/test_factory.py @@ -55,10 +55,15 @@ def create(self, resource, **kwargs): return self.last_create def get(self, resource, **kwargs): + + memberid = kwargs.get('memberid', '') + cloud = kwargs.get('cloud', '') + available_endpoints = { + 'images': '/images/{}/{}/'.format(memberid, cloud), 'members': '/members', + 'version': '/version', 'public-key': '/publicKey', - 'version': '/version' } urlpath = available_endpoints[resource] From ba76848a5f9b068dd6792dc3afc9904287b3b0a6 Mon Sep 17 00:00:00 2001 From: Anderson Dantas Date: Thu, 9 May 2019 18:37:44 -0300 Subject: [PATCH 15/29] Implemented logging of REST requests and fixed logic problems with assertions --- service_test/common/__init__.py | 4 +- .../common/check_version_and_public_key.py | 4 +- service_test/common/response_store.py | 16 ----- service_test/common/service_test_instance.py | 15 ++--- service_test/common/test_factory.py | 43 +++++++++---- service_test/main.py | 49 +++++++++------ .../service_tests.py | 63 ++++++++++++++++++- 7 files changed, 130 insertions(+), 64 deletions(-) delete mode 100644 service_test/common/response_store.py diff --git a/service_test/common/__init__.py b/service_test/common/__init__.py index 46ff7b8..3eeb720 100644 --- a/service_test/common/__init__.py +++ b/service_test/common/__init__.py @@ -3,14 +3,12 @@ from .http_methods import * from .instance_states import * from .service_test_instance import * -from .response_store import * from .test_factory import * from .utils import * from .check_version import * from .check_version_and_public_key import * modules = [constants, http_methods, instance_states, service_test_instance, - test_factory, utils, check_version, check_version_and_public_key, - response_store] + test_factory, utils, check_version, check_version_and_public_key] __all__ = [prop for module in modules for prop in module.__all__] diff --git a/service_test/common/check_version_and_public_key.py b/service_test/common/check_version_and_public_key.py index 733bc5d..67ee502 100644 --- a/service_test/common/check_version_and_public_key.py +++ b/service_test/common/check_version_and_public_key.py @@ -19,6 +19,6 @@ def publickey(self): res = test.get('public-key').json() publickey = res['publicKey'] - self.asserteq(len(publickey)%3, 0) - + self.assertgt(len(publickey), 0) + self.endtest() \ No newline at end of file diff --git a/service_test/common/response_store.py b/service_test/common/response_store.py deleted file mode 100644 index cfca165..0000000 --- a/service_test/common/response_store.py +++ /dev/null @@ -1,16 +0,0 @@ -# -*- coding: utf-8 -*- - -from collections import defaultdict - -__all__ = ['ResourceStore'] - -class ResourceStore: - data = defaultdict(list) - - @classmethod - def addresourceid(cls, resource, resid): - cls.data[resource].append(resid) - - @classmethod - def getresourceidd(cls, resource): - return cls.data[resource] \ No newline at end of file diff --git a/service_test/common/service_test_instance.py b/service_test/common/service_test_instance.py index f200a25..c29133f 100644 --- a/service_test/common/service_test_instance.py +++ b/service_test/common/service_test_instance.py @@ -33,26 +33,23 @@ def __init__(self, service, configuration, resources): self.port = self.conf['application']['port'] self.origin = 'http://localhost:' + str(self.port) - @classmethod def starttest(cls, msg): + cls.endtest() testid = cls.nexttextcase() - cls.assert_count = 0 - cls.assert_succ = 0 cls.tests_info[testid] = msg print("-- Test {}: {}".format(testid, msg)) - @classmethod def endtest(cls): if cls.assert_count > 0: if cls.assert_count != cls.assert_succ: cls.failed_tests.append(cls.test_number) + cls.assert_count = 0 + cls.assert_succ = 0 - @classmethod def fail(cls): cls.assert_count += 1 cls.endtest() - @classmethod def logresults(cls): print("%d tests were run" % cls.test_number) print("%d tests passed" % (cls.test_number - len(cls.failed_tests))) @@ -180,16 +177,16 @@ def __getattr__(self, attribute): assertstr = 'assert' for cmp in comparation_functions: if(attribute == assertstr+cmp): - return Assertion(ServiceTestInstance, getattr(operator, cmp)) + return Assertion(self, getattr(operator, cmp)) raise AttributeError - @classmethod + # @classmethod def __assertion_ok__(self): self.assert_count += 1 self.assert_succ += 1 - @classmethod + # @classmethod def __assertion_fail__(self): self.assert_count += 1 diff --git a/service_test/common/test_factory.py b/service_test/common/test_factory.py index 9a228f3..7abfc1d 100644 --- a/service_test/common/test_factory.py +++ b/service_test/common/test_factory.py @@ -5,7 +5,6 @@ from os import path from . import HttpMethods -from . import ResourceStore __all__ = ['TestEngine'] @@ -47,15 +46,30 @@ def create(self, resource, **kwargs): req = FogbowRequest(url=url, headers=headers, body=body, method=str(HttpMethods.POST)) self.last_create = req.execute() - if self.last_create.status_code < 400 and resource == 'token': - token = self.last_create.json().get('token', None) - self.addHeader('Fogbow-User-Token', token) - - return self.last_create def get(self, resource, **kwargs): + url = self.__getserviceendpoint__(resource, **kwargs) + + return self.__executeget__(url, **kwargs) + + def getbyid(self, resource, _id, **kwargs): + url = self.__getserviceendpoint__(resource, **kwargs) + + url = url + '/' + _id + + return self.__executeget__(url, **kwargs) + + def __executeget__(self, url, **kwargs): + + headers = kwargs.get('headers', self.headers) + body = kwargs.get('body', self.body) + + req = FogbowRequest(url=url, headers=headers, body=body, method=str(HttpMethods.GET)) + + return req.execute() + def __getserviceendpoint__(self, resource, **kwargs): memberid = kwargs.get('memberid', '') cloud = kwargs.get('cloud', '') @@ -69,12 +83,7 @@ def get(self, resource, **kwargs): urlpath = available_endpoints[resource] url = self.service_url + '/' + urlpath - headers = kwargs.get('headers', self.headers) - body = kwargs.get('body', self.body) - - req = FogbowRequest(url=url, headers=headers, body=body, method=str(HttpMethods.GET)) - - return req.execute() + return url def addHeader(self, header, headervalue): if header and headervalue: @@ -94,4 +103,12 @@ def __init__(self, url, method = 'get', body = {}, headers = {}): def execute(self): verb_requester = getattr(requests, self.method) - return verb_requester(url=self.url, json=self.body, headers=self.headers) + res = verb_requester(url=self.url, json=self.body, headers=self.headers) + + print("\n---- Begin Response ----\n") + print("url: %s\n" % res.url) + print("headers: %s\n" % res.headers) + print("json: %s\n" % res.json()) + print("\n---- End Response ----\n") + + return res diff --git a/service_test/main.py b/service_test/main.py index a1ebacb..67df432 100644 --- a/service_test/main.py +++ b/service_test/main.py @@ -8,6 +8,8 @@ from resource_allocation_service import RASTest from common import * +SKIP_SETUP_FLAG = '--skip-setup' +SKIP_TEARDOWN_FLAG = '--skip-teardown' resources_path = 'test_resources' def getresources(service_resources ,required_resources): @@ -51,32 +53,41 @@ def getservice(servicename): conf = getserviceconf(service_under_test) dependencies_services = [] - # start dependencies services - for servicename in conf['services']: - serviceinstance = getservice(servicename) - serviceinstance.setup() + print('###### Starting tests ######') + + runsetup = SKIP_SETUP_FLAG not in sys.argv - print(servicename, serviceinstance) - - dependencies_services.append(serviceinstance) - - # those setups may change current dir - os.chdir(curdir) + if runsetup: - print('###### Starting tests ######') + # start dependencies services + for servicename in conf['services']: + serviceinstance = getservice(servicename) + serviceinstance.setup() + serviceinstance.run() + + dependencies_services.append(serviceinstance) + + # those setups may change current dir + os.chdir(curdir) - servicetest.setup() + + servicetest.setup() + servicetest.run() print('###### Tests are over ######') - print('###### Tearing down ######') - servicetest.teardown() - - for serviceinstance in dependencies_services: - serviceinstance.teardown() + runteardown = SKIP_TEARDOWN_FLAG not in sys.argv + + if runteardown: + print('###### Tearing down ######') + + servicetest.teardown() - # these teardowns may change current dir - os.chdir(curdir) + for serviceinstance in dependencies_services: + serviceinstance.teardown() + + # these teardowns may change current dir + os.chdir(curdir) print('###### Done ######') diff --git a/service_test/resource_allocation_service/service_tests.py b/service_test/resource_allocation_service/service_tests.py index 6e4a603..baadee3 100644 --- a/service_test/resource_allocation_service/service_tests.py +++ b/service_test/resource_allocation_service/service_tests.py @@ -8,10 +8,24 @@ class RASTest(VersionandPublicKeyCheck): def __init__(self, service, configuration, resources): super().__init__(service, configuration, resources) + + self.imageskwargs = { + 'memberid': self.conf['memberid'], + 'cloud': self.conf['cloud'] + } def run(self): + self.__rasrequester__ = TestEngine(self.origin) + + pubkey = self.__getpubkey__() + + token = self.__createtoken__(pubkey) + self.__rasrequester__.addHeader('Fogbow-User-Token', token) + try: super().run() + self.getimages() + self.getimagebyid() except Exception as e: self.fail() print("Interruped execution due to runtime error") @@ -20,7 +34,37 @@ def run(self): self.logresults() def getimages(self): - pass + self.starttest('GET Images') + + res = self.__rasrequester__.get('images', **self.imageskwargs).json() + images = res.keys() + + self.assertgt(len(images), 0) + self.endtest() + + def getimagebyid(self): + self.starttest('GET Image by id') + + res = self.__rasrequester__.get('images', **self.imageskwargs).json() + images = list(res.keys()) + + imageid = images[0] + imagedata = self.__rasrequester__.getbyid('images', imageid, **self.imageskwargs).json() + + _id = imagedata['id'] + _name = imagedata['name'] + _size = imagedata['size'] + + if self.asserteq(type(_id), str): + self.assertgt(len(_id), 0) + + if self.asserteq(type(_name), str): + self.assertgt(len(_name), 0) + + if self.asserteq(type(_size), int): + self.assertgt(_size, 0) + + self.endtest() def createnetwork(self): pass @@ -36,4 +80,19 @@ def createattachment(self): @classmethod def required_resources(self): - return [] + return ['auth_credentials'] + + def __getpubkey__(self): + res = self.__rasrequester__.get('public-key').json() + return res['publicKey'] + + def __createtoken__(self, pubkey): + + as_url = self.conf['as_url'] + asrequester = TestEngine(as_url) + + credentials = self.resources['auth_credentials'] + credentials['publicKey'] = pubkey + + res = asrequester.create('token', body=credentials).json() + return res['token'] \ No newline at end of file From 07a996f31a25850cbf66c0ad366a7622d1da8909 Mon Sep 17 00:00:00 2001 From: Anderson Dantas Date: Mon, 13 May 2019 09:23:23 -0300 Subject: [PATCH 16/29] Implemented ceration of Compute and Network --- service_test/common/test_factory.py | 10 +++---- .../service_tests.py | 30 +++++++++++++++++-- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/service_test/common/test_factory.py b/service_test/common/test_factory.py index 7abfc1d..d2aa9f0 100644 --- a/service_test/common/test_factory.py +++ b/service_test/common/test_factory.py @@ -33,12 +33,7 @@ def wait_until_ready(self, tries = 50): return ret def create(self, resource, **kwargs): - available_endpoints = { - 'token': '/tokens' - } - - urlpath = available_endpoints[resource] - url = self.service_url + '/' + urlpath + url = self.__getserviceendpoint__(resource, **kwargs) headers = kwargs.get('headers', self.headers) body = kwargs.get('body', self.body) @@ -74,10 +69,13 @@ def __getserviceendpoint__(self, resource, **kwargs): cloud = kwargs.get('cloud', '') available_endpoints = { + 'token': '/tokens', 'images': '/images/{}/{}/'.format(memberid, cloud), 'members': '/members', 'version': '/version', 'public-key': '/publicKey', + 'networks': '/networks', + 'compute': '/computes' } urlpath = available_endpoints[resource] diff --git a/service_test/resource_allocation_service/service_tests.py b/service_test/resource_allocation_service/service_tests.py index baadee3..be8ea60 100644 --- a/service_test/resource_allocation_service/service_tests.py +++ b/service_test/resource_allocation_service/service_tests.py @@ -24,8 +24,12 @@ def run(self): try: super().run() + self.getimages() self.getimagebyid() + + networkid = self.createnetwork() + computeid = self.createcompute() except Exception as e: self.fail() print("Interruped execution due to runtime error") @@ -67,10 +71,30 @@ def getimagebyid(self): self.endtest() def createnetwork(self): - pass + self.starttest('POST network') + + body = self.resources['create_network'] + res = self.__rasrequester__.create('networks', body=body) + + self.assertlt(res.status_code, 400) + + self.endtest() + + ret = res.json() + return ret['id'] def createcompute(self): - pass + self.starttest('POST compute') + + body = self.resources['create_compute'] + res = self.__rasrequester__.create('compute', body=body) + + self.assertlt(res.status_code, 400) + + self.endtest() + + ret = res.json() + return ret['id'] def createvolume(self): pass @@ -80,7 +104,7 @@ def createattachment(self): @classmethod def required_resources(self): - return ['auth_credentials'] + return ['auth_credentials', 'create_network', 'create_compute'] def __getpubkey__(self): res = self.__rasrequester__.get('public-key').json() From b9a53dfafd8746ffebd925666bf2b2d7937eebd1 Mon Sep 17 00:00:00 2001 From: Anderson Dantas Date: Mon, 13 May 2019 10:08:17 -0300 Subject: [PATCH 17/29] Implement create volume and attachemnt tests --- service_test/common/service_test_instance.py | 1 - service_test/common/test_factory.py | 22 +++++----- .../service_tests.py | 42 ++++++++++++++++--- 3 files changed, 47 insertions(+), 18 deletions(-) diff --git a/service_test/common/service_test_instance.py b/service_test/common/service_test_instance.py index c29133f..163396f 100644 --- a/service_test/common/service_test_instance.py +++ b/service_test/common/service_test_instance.py @@ -48,7 +48,6 @@ def endtest(cls): def fail(cls): cls.assert_count += 1 - cls.endtest() def logresults(cls): print("%d tests were run" % cls.test_number) diff --git a/service_test/common/test_factory.py b/service_test/common/test_factory.py index d2aa9f0..9132ff0 100644 --- a/service_test/common/test_factory.py +++ b/service_test/common/test_factory.py @@ -15,18 +15,14 @@ def __init__(self, service_url): self.body = {} self.headers = {} - def wait_until_ready(self, tries = 50): - if tries == 0: + def wait_until_ready(self, resource, instance_id, tries = 50): + if tries <= 0: return None - lasturl = str(self.last_create.url) - last_create = json.loads(self.last_create) - instance_id = last_create['id'] - url = lasturl + '/' + instance_id - response_json = requests.get(url=url, headers=headers).json() - response = json.loads(response_json) - - if response['state'] == InstanceState.READY: - ret = response + + res = self.getbyid(resource, id) + + if res['state'] == InstanceState.READY: + ret = res else: ret = self.wait_until_ready(tries-1) @@ -75,7 +71,9 @@ def __getserviceendpoint__(self, resource, **kwargs): 'version': '/version', 'public-key': '/publicKey', 'networks': '/networks', - 'compute': '/computes' + 'compute': '/computes', + 'volume': '/volumes', + 'attachment': '/attachments' } urlpath = available_endpoints[resource] diff --git a/service_test/resource_allocation_service/service_tests.py b/service_test/resource_allocation_service/service_tests.py index be8ea60..49fae99 100644 --- a/service_test/resource_allocation_service/service_tests.py +++ b/service_test/resource_allocation_service/service_tests.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +import time from common import TestEngine, VersionandPublicKeyCheck __all__ = ['RASTest'] @@ -30,6 +31,9 @@ def run(self): networkid = self.createnetwork() computeid = self.createcompute() + volumeid = self.createvolume() + + attachment = self.createattachment(volumeid, computeid) except Exception as e: self.fail() print("Interruped execution due to runtime error") @@ -97,14 +101,36 @@ def createcompute(self): return ret['id'] def createvolume(self): - pass + self.starttest('POST volume') + + body = self.resources['create_volume'] + res = self.__rasrequester__.create('volume', body=body) + + self.assertlt(res.status_code, 400) + + ret = res.json() + self.endtest() + + return ret['id'] - def createattachment(self): - pass + def createattachment(self, volumeid, computeid): + self.starttest('POST attachment') + + body = self.__attachmentbodyrequests__(volumeid, computeid) + res = self.__rasrequester__.create('attachment', body=body) + + self.assertlt(res.status_code, 400) + + print(res, res.json()) + + self.endtest() + ret = res.json() + return ret['id'] @classmethod def required_resources(self): - return ['auth_credentials', 'create_network', 'create_compute'] + return ['auth_credentials', 'create_network', 'create_compute', + 'create_volume'] def __getpubkey__(self): res = self.__rasrequester__.get('public-key').json() @@ -119,4 +145,10 @@ def __createtoken__(self, pubkey): credentials['publicKey'] = pubkey res = asrequester.create('token', body=credentials).json() - return res['token'] \ No newline at end of file + return res['token'] + + def __attachmentbodyrequests__ (self, volumeid, computeid): + return { + "computeId": volumeid, + "volumeId": computeid + } \ No newline at end of file From d98db59095eab59131f4a189191dd2c11d8351b6 Mon Sep 17 00:00:00 2001 From: Anderson Dantas Date: Mon, 13 May 2019 17:42:06 -0300 Subject: [PATCH 18/29] Decouple order creation from assertions --- service_test/common/instance_states.py | 15 ++- service_test/common/test_factory.py | 28 +++--- .../service_tests.py | 97 ++++++++++--------- 3 files changed, 73 insertions(+), 67 deletions(-) diff --git a/service_test/common/instance_states.py b/service_test/common/instance_states.py index c066937..2277797 100644 --- a/service_test/common/instance_states.py +++ b/service_test/common/instance_states.py @@ -1,12 +1,11 @@ # -*- coding: utf-8 -*- -from enum import Enum, auto __all__ = ['InstanceState'] -class InstanceState(Enum): - DISPATCHED = auto() - READY = "READY" - CREATING = auto() - UNAVAILABLE = auto() - FAILED = auto() - INCONSISTENT = auto() +class InstanceState: + DISPATCHED = 'DISPATCHED' + READY = 'READY' + CREATING = 'CREATING' + UNAVAILABLE = 'UNAVAILABLE' + FAILED = 'FAILED' + INCONSISTENT = 'INCONSISTENT' diff --git a/service_test/common/test_factory.py b/service_test/common/test_factory.py index 9132ff0..fdc6440 100644 --- a/service_test/common/test_factory.py +++ b/service_test/common/test_factory.py @@ -2,16 +2,17 @@ import json import requests +import time from os import path -from . import HttpMethods +from . import HttpMethods, InstanceState __all__ = ['TestEngine'] class TestEngine(object): def __init__(self, service_url): self.last_create = None - self.service_url = service_url; + self.service_url = service_url self.body = {} self.headers = {} @@ -19,12 +20,13 @@ def wait_until_ready(self, resource, instance_id, tries = 50): if tries <= 0: return None - res = self.getbyid(resource, id) - - if res['state'] == InstanceState.READY: + res = self.getbyid(resource, instance_id) + state = res.json()['state'] + if state == InstanceState.READY: ret = res else: - ret = self.wait_until_ready(tries-1) + time.sleep(1) + ret = self.wait_until_ready(resource, instance_id, tries-1) return ret @@ -46,8 +48,7 @@ def get(self, resource, **kwargs): def getbyid(self, resource, _id, **kwargs): url = self.__getserviceendpoint__(resource, **kwargs) - - url = url + '/' + _id + url += '/' + _id return self.__executeget__(url, **kwargs) @@ -70,7 +71,7 @@ def __getserviceendpoint__(self, resource, **kwargs): 'members': '/members', 'version': '/version', 'public-key': '/publicKey', - 'networks': '/networks', + 'network': '/networks', 'compute': '/computes', 'volume': '/volumes', 'attachment': '/attachments' @@ -101,10 +102,13 @@ def execute(self): verb_requester = getattr(requests, self.method) res = verb_requester(url=self.url, json=self.body, headers=self.headers) - print("\n---- Begin Response ----\n") + print("---- Request ----") print("url: %s\n" % res.url) print("headers: %s\n" % res.headers) - print("json: %s\n" % res.json()) - print("\n---- End Response ----\n") + print("method: %s\n" % self.method.upper()) + print("body: %s\n" % self.body) + print("---- Response ----") + print("reponse: %s\n" % res.json()) + print("------------------") return res diff --git a/service_test/resource_allocation_service/service_tests.py b/service_test/resource_allocation_service/service_tests.py index 49fae99..bed25ce 100644 --- a/service_test/resource_allocation_service/service_tests.py +++ b/service_test/resource_allocation_service/service_tests.py @@ -26,13 +26,16 @@ def run(self): try: super().run() - self.getimages() - self.getimagebyid() + self.testgetimages() + self.testgetimagebyid() networkid = self.createnetwork() computeid = self.createcompute() volumeid = self.createvolume() + # # remove after implementing wait + # time.sleep(10) + attachment = self.createattachment(volumeid, computeid) except Exception as e: self.fail() @@ -41,23 +44,18 @@ def run(self): finally: self.logresults() - def getimages(self): + def testgetimages(self): self.starttest('GET Images') - res = self.__rasrequester__.get('images', **self.imageskwargs).json() - images = res.keys() + images = self.getimages() self.assertgt(len(images), 0) self.endtest() - - def getimagebyid(self): + + def testgetimagebyid(self): self.starttest('GET Image by id') - res = self.__rasrequester__.get('images', **self.imageskwargs).json() - images = list(res.keys()) - - imageid = images[0] - imagedata = self.__rasrequester__.getbyid('images', imageid, **self.imageskwargs).json() + imagedata = self.getimagebyid() _id = imagedata['id'] _name = imagedata['name'] @@ -74,44 +72,25 @@ def getimagebyid(self): self.endtest() + def getimages(self): + res = self.__rasrequester__.get('images', **self.imageskwargs).json() + return res.keys() + + def getimagebyid(self): + res = self.__rasrequester__.get('images', **self.imageskwargs).json() + images = list(res.keys()) + + imageid = images[0] + return self.__rasrequester__.getbyid('images', imageid, **self.imageskwargs).json() + def createnetwork(self): - self.starttest('POST network') - - body = self.resources['create_network'] - res = self.__rasrequester__.create('networks', body=body) - - self.assertlt(res.status_code, 400) - - self.endtest() - - ret = res.json() - return ret['id'] + return self.__testgenericorder__('network') def createcompute(self): - self.starttest('POST compute') - - body = self.resources['create_compute'] - res = self.__rasrequester__.create('compute', body=body) - - self.assertlt(res.status_code, 400) - - self.endtest() - - ret = res.json() - return ret['id'] + return self.__testgenericorder__('compute', True) def createvolume(self): - self.starttest('POST volume') - - body = self.resources['create_volume'] - res = self.__rasrequester__.create('volume', body=body) - - self.assertlt(res.status_code, 400) - - ret = res.json() - self.endtest() - - return ret['id'] + return self.__testgenericorder__('volume', True) def createattachment(self, volumeid, computeid): self.starttest('POST attachment') @@ -121,8 +100,6 @@ def createattachment(self, volumeid, computeid): self.assertlt(res.status_code, 400) - print(res, res.json()) - self.endtest() ret = res.json() return ret['id'] @@ -147,6 +124,32 @@ def __createtoken__(self, pubkey): res = asrequester.create('token', body=credentials).json() return res['token'] + def __creategenericorder__(self, resource, parseresponse=False): + body = self.resources['create_{}'.format(resource.lower())] + res = self.__rasrequester__.create(resource.lower(), body=body) + + if parseresponse: + res = res.json()['id'] + + return res + + def __testgenericorder__(self, resource, waitready=False): + self.starttest('POST {}'.format(resource.capitalize())) + + res = self.__creategenericorder__(resource) + + self.assertlt(res.status_code, 400) + + _id = res.json()['id'] + + if waitready: + res = self.__rasrequester__.wait_until_ready(resource, _id) + if not res: + raise Exception('Wait for order to be ready failed, resource: {} , id: {}'.format(resource, _id)) + + self.endtest() + return res.json()['id'] + def __attachmentbodyrequests__ (self, volumeid, computeid): return { "computeId": volumeid, From 593e2c1c90fa0520292b273a02c913da7ffc932a Mon Sep 17 00:00:00 2001 From: Anderson Dantas Date: Tue, 14 May 2019 11:24:53 -0300 Subject: [PATCH 19/29] Wrap ras API calls in model class --- service_test/common/test_factory.py | 35 ++++-- .../resource_allocation_service/__init__.py | 3 +- .../resource_allocation_service/ras_model.py | 72 ++++++++++++ .../service_tests.py | 111 +++++++----------- 4 files changed, 140 insertions(+), 81 deletions(-) create mode 100644 service_test/resource_allocation_service/ras_model.py diff --git a/service_test/common/test_factory.py b/service_test/common/test_factory.py index fdc6440..8e5ada2 100644 --- a/service_test/common/test_factory.py +++ b/service_test/common/test_factory.py @@ -43,7 +43,13 @@ def create(self, resource, **kwargs): def get(self, resource, **kwargs): url = self.__getserviceendpoint__(resource, **kwargs) + + return self.__executeget__(url, **kwargs) + def getall(self, resource, **kwargs): + url = self.__getserviceendpoint__(resource, **kwargs) + url += '/status' + return self.__executeget__(url, **kwargs) def getbyid(self, resource, _id, **kwargs): @@ -74,6 +80,8 @@ def __getserviceendpoint__(self, resource, **kwargs): 'network': '/networks', 'compute': '/computes', 'volume': '/volumes', + 'cloud': '/clouds', + 'publicIp': '/publicIps', 'attachment': '/attachments' } @@ -92,23 +100,26 @@ def addHeader(self, header, headervalue): print("Header content: {}".format(headervalue)) class FogbowRequest: - def __init__(self, url, method = 'get', body = {}, headers = {}): + def __init__(self, url, **kwargs): self.url = url - self.headers = headers - self.body = body - self.method = method + self.headers = kwargs.get('headers', {}) + self.body = kwargs.get('body', {}) + self.method = kwargs.get('method', 'get') + self.enablelog = kwargs.get('enablelog', True) def execute(self): verb_requester = getattr(requests, self.method) + # print('before request', 'url=',self.url, 'json=',self.body, 'headers=',self.headers) res = verb_requester(url=self.url, json=self.body, headers=self.headers) - print("---- Request ----") - print("url: %s\n" % res.url) - print("headers: %s\n" % res.headers) - print("method: %s\n" % self.method.upper()) - print("body: %s\n" % self.body) - print("---- Response ----") - print("reponse: %s\n" % res.json()) - print("------------------") + if self.enablelog: + print("---- Request ----") + print("url: %s\n" % res.url) + print("headers: %s\n" % res.headers) + print("method: %s\n" % self.method.upper()) + print("body: %s\n" % self.body) + print("---- Response ----") + print("reponse: %s\n" % res.json()) + print("------------------") return res diff --git a/service_test/resource_allocation_service/__init__.py b/service_test/resource_allocation_service/__init__.py index 3a662b9..f1d865c 100644 --- a/service_test/resource_allocation_service/__init__.py +++ b/service_test/resource_allocation_service/__init__.py @@ -1,7 +1,8 @@ # -*- coding: utf-8 -*- +from .ras_model import * from .service_tests import * -modules = [service_tests] +modules = [service_tests, ras_model] __all__ = [prop for module in modules for prop in module.__all__] diff --git a/service_test/resource_allocation_service/ras_model.py b/service_test/resource_allocation_service/ras_model.py new file mode 100644 index 0000000..b5cf2b8 --- /dev/null +++ b/service_test/resource_allocation_service/ras_model.py @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- + +from common import TestEngine + +__all__ = ['RasModel'] + +class RasModel(object): + + def __init__(self, origin, resources, conf): + self.resources = resources + self.conf = conf + self.__rasrequester__ = TestEngine(origin) + + pubkey = self.getpubkey() + + token = self.createtoken(pubkey) + self.__rasrequester__.addHeader('Fogbow-User-Token', token) + + self.imageskwargs = { + 'memberid': self.conf['memberid'], + 'cloud': self.conf['cloud'] + } + + def getpubkey(self): + res = self.__rasrequester__.get('public-key').json() + return res['publicKey'] + + def createtoken(self, pubkey): + + as_url = self.conf['as_url'] + asrequester = TestEngine(as_url) + + credentials = self.resources['auth_credentials'] + credentials['publicKey'] = pubkey + + res = asrequester.create('token', body=credentials).json() + return res['token'] + + def create(self, resource, **kwargs): + return self.__rasrequester__.create(resource, **kwargs) + + def get(self, resource, **kwargs): + return self.__rasrequester__.get(resource, **kwargs) + + def getall(self, resource, **kwargs): + return self.__rasrequester__.getall(resource, **kwargs) + + def getbyid(self, resource, _id, **kwargs): + return self.__rasrequester__.getbyid(resource, _id, **kwargs) + + def creategenericorder(self, resource, parseresponse=False): + body = self.resources['create_{}'.format(resource.lower())] + res = self.__rasrequester__.create(resource.lower(), body=body) + + if parseresponse: + res = res.json()['id'] + + return res + + def wait_until_ready(self, resource, _id): + return self.__rasrequester__.wait_until_ready(resource, _id) + + def getimages(self): + res = self.__rasrequester__.get('images', **self.imageskwargs).json() + return res.keys() + + def getimagebyid(self): + res = self.__rasrequester__.get('images', **self.imageskwargs).json() + images = list(res.keys()) + + imageid = images[0] + return self.__rasrequester__.getbyid('images', imageid, **self.imageskwargs).json() \ No newline at end of file diff --git a/service_test/resource_allocation_service/service_tests.py b/service_test/resource_allocation_service/service_tests.py index bed25ce..c44db97 100644 --- a/service_test/resource_allocation_service/service_tests.py +++ b/service_test/resource_allocation_service/service_tests.py @@ -1,53 +1,55 @@ # -*- coding: utf-8 -*- import time + from common import TestEngine, VersionandPublicKeyCheck +from . import RasModel __all__ = ['RASTest'] class RASTest(VersionandPublicKeyCheck): - def __init__(self, service, configuration, resources): - super().__init__(service, configuration, resources) + # def __init__(self, service, configuration, resources): + # super().__init__(service, configuration, resources) - self.imageskwargs = { - 'memberid': self.conf['memberid'], - 'cloud': self.conf['cloud'] - } - - def run(self): - self.__rasrequester__ = TestEngine(self.origin) - pubkey = self.__getpubkey__() - token = self.__createtoken__(pubkey) - self.__rasrequester__.addHeader('Fogbow-User-Token', token) - + def run(self): try: super().run() + self.rasmodel = RasModel(self.origin, self.resources, self.conf) self.testgetimages() self.testgetimagebyid() + + self.testgetstatus() - networkid = self.createnetwork() - computeid = self.createcompute() - volumeid = self.createvolume() + networkid = self.testcreatenetwork() + computeid = self.testcreatecompute() + volumeid = self.testcreatevolume() - # # remove after implementing wait - # time.sleep(10) + attachment = self.testcreateattachment(volumeid, computeid) - attachment = self.createattachment(volumeid, computeid) except Exception as e: + self.fail() print("Interruped execution due to runtime error") + print(e) raise e + finally: self.logresults() + def testgetstatus(self): + resources = ['attachment', 'compute', 'network', 'publicIp', 'volume'] + + for resource in resources: + self.__testgetalloders__(resource) + def testgetimages(self): self.starttest('GET Images') - images = self.getimages() + images = self.rasmodel.getimages() self.assertgt(len(images), 0) self.endtest() @@ -55,7 +57,7 @@ def testgetimages(self): def testgetimagebyid(self): self.starttest('GET Image by id') - imagedata = self.getimagebyid() + imagedata = self.rasmodel.getimagebyid() _id = imagedata['id'] _name = imagedata['name'] @@ -72,31 +74,20 @@ def testgetimagebyid(self): self.endtest() - def getimages(self): - res = self.__rasrequester__.get('images', **self.imageskwargs).json() - return res.keys() - - def getimagebyid(self): - res = self.__rasrequester__.get('images', **self.imageskwargs).json() - images = list(res.keys()) - - imageid = images[0] - return self.__rasrequester__.getbyid('images', imageid, **self.imageskwargs).json() - - def createnetwork(self): - return self.__testgenericorder__('network') + def testcreatenetwork(self): + return self.__testcreategenericorder__('network') - def createcompute(self): - return self.__testgenericorder__('compute', True) + def testcreatecompute(self): + return self.__testcreategenericorder__('compute', True) - def createvolume(self): - return self.__testgenericorder__('volume', True) + def testcreatevolume(self): + return self.__testcreategenericorder__('volume', True) - def createattachment(self, volumeid, computeid): + def testcreateattachment(self, volumeid, computeid): self.starttest('POST attachment') body = self.__attachmentbodyrequests__(volumeid, computeid) - res = self.__rasrequester__.create('attachment', body=body) + res = self.rasmodel.create('attachment', body=body) self.assertlt(res.status_code, 400) @@ -109,49 +100,33 @@ def required_resources(self): return ['auth_credentials', 'create_network', 'create_compute', 'create_volume'] - def __getpubkey__(self): - res = self.__rasrequester__.get('public-key').json() - return res['publicKey'] - - def __createtoken__(self, pubkey): - - as_url = self.conf['as_url'] - asrequester = TestEngine(as_url) - - credentials = self.resources['auth_credentials'] - credentials['publicKey'] = pubkey - - res = asrequester.create('token', body=credentials).json() - return res['token'] - - def __creategenericorder__(self, resource, parseresponse=False): - body = self.resources['create_{}'.format(resource.lower())] - res = self.__rasrequester__.create(resource.lower(), body=body) - - if parseresponse: - res = res.json()['id'] - - return res - - def __testgenericorder__(self, resource, waitready=False): + def __testcreategenericorder__(self, resource, waitready=False): self.starttest('POST {}'.format(resource.capitalize())) - res = self.__creategenericorder__(resource) + res = self.rasmodel.creategenericorder(resource) self.assertlt(res.status_code, 400) _id = res.json()['id'] if waitready: - res = self.__rasrequester__.wait_until_ready(resource, _id) + res = self.rasmodel.wait_until_ready(resource, _id) if not res: raise Exception('Wait for order to be ready failed, resource: {} , id: {}'.format(resource, _id)) self.endtest() return res.json()['id'] + def __testgetalloders__(self, resource): + self.starttest('GET {}s/status'.format(resource)) + + response = self.rasmodel.getall(resource) + self.assertlt(response.status_code, 400) + + self.endtest() + def __attachmentbodyrequests__ (self, volumeid, computeid): return { "computeId": volumeid, "volumeId": computeid - } \ No newline at end of file + } From bfbd0f5dc739cf8afd575f8f105448ae0c3ef57d Mon Sep 17 00:00:00 2001 From: Anderson Dantas Date: Wed, 15 May 2019 11:24:43 -0300 Subject: [PATCH 20/29] Implemented some fail to deleting network and computes --- service_test/common/test_factory.py | 18 ++++++---- service_test/main.py | 1 - .../resource_allocation_service/ras_model.py | 3 ++ .../service_tests.py | 35 +++++++++++++++---- 4 files changed, 44 insertions(+), 13 deletions(-) diff --git a/service_test/common/test_factory.py b/service_test/common/test_factory.py index 8e5ada2..c3656f8 100644 --- a/service_test/common/test_factory.py +++ b/service_test/common/test_factory.py @@ -44,26 +44,33 @@ def create(self, resource, **kwargs): def get(self, resource, **kwargs): url = self.__getserviceendpoint__(resource, **kwargs) - return self.__executeget__(url, **kwargs) + return self.__execute__(url, **kwargs) def getall(self, resource, **kwargs): url = self.__getserviceendpoint__(resource, **kwargs) url += '/status' - return self.__executeget__(url, **kwargs) + return self.__execute__(url, **kwargs) def getbyid(self, resource, _id, **kwargs): url = self.__getserviceendpoint__(resource, **kwargs) url += '/' + _id - return self.__executeget__(url, **kwargs) + return self.__execute__(url, **kwargs) - def __executeget__(self, url, **kwargs): + def delete(self, resource, _id, **kwargs): + url = self.__getserviceendpoint__(resource, **kwargs) + url += '/' + _id + + return self.__execute__(url, method=HttpMethods.DELETE, **kwargs) + + def __execute__(self, url, **kwargs): headers = kwargs.get('headers', self.headers) body = kwargs.get('body', self.body) + method = kwargs.get('method', HttpMethods.GET) - req = FogbowRequest(url=url, headers=headers, body=body, method=str(HttpMethods.GET)) + req = FogbowRequest(url=url, headers=headers, body=body, method=method) return req.execute() @@ -109,7 +116,6 @@ def __init__(self, url, **kwargs): def execute(self): verb_requester = getattr(requests, self.method) - # print('before request', 'url=',self.url, 'json=',self.body, 'headers=',self.headers) res = verb_requester(url=self.url, json=self.body, headers=self.headers) if self.enablelog: diff --git a/service_test/main.py b/service_test/main.py index 67df432..51f68c6 100644 --- a/service_test/main.py +++ b/service_test/main.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- -import json import os import sys from authentication_service import AuthTest diff --git a/service_test/resource_allocation_service/ras_model.py b/service_test/resource_allocation_service/ras_model.py index b5cf2b8..15da82a 100644 --- a/service_test/resource_allocation_service/ras_model.py +++ b/service_test/resource_allocation_service/ras_model.py @@ -48,6 +48,9 @@ def getall(self, resource, **kwargs): def getbyid(self, resource, _id, **kwargs): return self.__rasrequester__.getbyid(resource, _id, **kwargs) + def delete(self, resource, _id, **kwargs): + return self.__rasrequester__.delete(resource, _id, **kwargs) + def creategenericorder(self, resource, parseresponse=False): body = self.resources['create_{}'.format(resource.lower())] res = self.__rasrequester__.create(resource.lower(), body=body) diff --git a/service_test/resource_allocation_service/service_tests.py b/service_test/resource_allocation_service/service_tests.py index c44db97..0b112d2 100644 --- a/service_test/resource_allocation_service/service_tests.py +++ b/service_test/resource_allocation_service/service_tests.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +import copy import time from common import TestEngine, VersionandPublicKeyCheck @@ -9,10 +10,9 @@ class RASTest(VersionandPublicKeyCheck): - # def __init__(self, service, configuration, resources): - # super().__init__(service, configuration, resources) - - + def __init__(self, service, configuration, resources): + super().__init__(service, configuration, resources) + self.resources = resources def run(self): try: @@ -29,6 +29,10 @@ def run(self): volumeid = self.testcreatevolume() attachment = self.testcreateattachment(volumeid, computeid) + computewithnetwork = self.testcreatecomputewithnetwork(networkid) + + self.testdeletenetworkwithcomputeattached(networkid) + self.testdeleteattachedcompute(computeid) except Exception as e: @@ -95,6 +99,25 @@ def testcreateattachment(self, volumeid, computeid): ret = res.json() return ret['id'] + def testcreatecomputewithnetwork(self, network): + self.starttest('POST compute passign some network') + + body = copy.deepcopy(self.resources['create_compute']) + body['networkIds'] = [network] + + res = self.rasmodel.create('compute', body=body) + + self.assertlt(res.status_code, 400) + self.endtest() + + def testdeletenetworkwithcomputeattached(self, network): + self.starttest('DELETE network with orders attached (should fail)') + + res = self.rasmodel.delete('network', network) + + self.assertge(res.status_code, 400) + self.endtest() + @classmethod def required_resources(self): return ['auth_credentials', 'create_network', 'create_compute', @@ -127,6 +150,6 @@ def __testgetalloders__(self, resource): def __attachmentbodyrequests__ (self, volumeid, computeid): return { - "computeId": volumeid, - "volumeId": computeid + "computeId": computeid, + "volumeId": volumeid } From fc278b23da5d33abe5cd2b3db5b4bd1c89e0dce8 Mon Sep 17 00:00:00 2001 From: Anderson Dantas Date: Wed, 15 May 2019 17:28:33 -0300 Subject: [PATCH 21/29] Removed verbose log of REST requests --- service_test/common/test_factory.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/service_test/common/test_factory.py b/service_test/common/test_factory.py index c3656f8..7303fe6 100644 --- a/service_test/common/test_factory.py +++ b/service_test/common/test_factory.py @@ -119,13 +119,6 @@ def execute(self): res = verb_requester(url=self.url, json=self.body, headers=self.headers) if self.enablelog: - print("---- Request ----") - print("url: %s\n" % res.url) - print("headers: %s\n" % res.headers) - print("method: %s\n" % self.method.upper()) - print("body: %s\n" % self.body) - print("---- Response ----") - print("reponse: %s\n" % res.json()) - print("------------------") + print("\n{} {}".format(self.method.upper(), res.url, )) return res From 5e9a36046134cd3345cc35e7d88997ab037466e4 Mon Sep 17 00:00:00 2001 From: Anderson Dantas Date: Wed, 15 May 2019 17:29:13 -0300 Subject: [PATCH 22/29] Implemented more tests for computes and networks --- service_test/common/assertion.py | 1 + service_test/common/service_test_instance.py | 4 +- .../resource_allocation_service/ras_model.py | 15 +++ .../service_tests.py | 111 +++++++++++++++--- 4 files changed, 110 insertions(+), 21 deletions(-) diff --git a/service_test/common/assertion.py b/service_test/common/assertion.py index 6881589..3aeddc1 100644 --- a/service_test/common/assertion.py +++ b/service_test/common/assertion.py @@ -16,6 +16,7 @@ def __call__(self, obtained, expected=None): if assertpassed: self.suite.__assertion_ok__() else: + print("Assertion failed: given: {}, expected {}".format(obtained, expected)) self.suite.__assertion_fail__() return assertpassed diff --git a/service_test/common/service_test_instance.py b/service_test/common/service_test_instance.py index 163396f..106fc66 100644 --- a/service_test/common/service_test_instance.py +++ b/service_test/common/service_test_instance.py @@ -37,7 +37,7 @@ def starttest(cls, msg): cls.endtest() testid = cls.nexttextcase() cls.tests_info[testid] = msg - print("-- Test {}: {}".format(testid, msg)) + print("\n-- Test {}: {}".format(testid, msg)) def endtest(cls): if cls.assert_count > 0: @@ -180,12 +180,10 @@ def __getattr__(self, attribute): raise AttributeError - # @classmethod def __assertion_ok__(self): self.assert_count += 1 self.assert_succ += 1 - # @classmethod def __assertion_fail__(self): self.assert_count += 1 diff --git a/service_test/resource_allocation_service/ras_model.py b/service_test/resource_allocation_service/ras_model.py index 15da82a..21ca69c 100644 --- a/service_test/resource_allocation_service/ras_model.py +++ b/service_test/resource_allocation_service/ras_model.py @@ -39,6 +39,21 @@ def createtoken(self, pubkey): def create(self, resource, **kwargs): return self.__rasrequester__.create(resource, **kwargs) + def createmany(self, resource, howmany=1, **kwargs): + responses = [] + + for i in range(howmany): + res = self.__rasrequester__.create(resource, **kwargs) + + wait_until_ready = kwargs.get('wait_ready', False) + if wait_until_ready: + _id = res.json()['id'] + res = self.__rasrequester__.wait_until_ready('compute', _id) + + responses.append(res) + + return responses + def get(self, resource, **kwargs): return self.__rasrequester__.get(resource, **kwargs) diff --git a/service_test/resource_allocation_service/service_tests.py b/service_test/resource_allocation_service/service_tests.py index 0b112d2..a413ae0 100644 --- a/service_test/resource_allocation_service/service_tests.py +++ b/service_test/resource_allocation_service/service_tests.py @@ -18,21 +18,38 @@ def run(self): try: super().run() self.rasmodel = RasModel(self.origin, self.resources, self.conf) - + + # # GET {resource}/status self.testgetimages() self.testgetimagebyid() - self.testgetstatus() + - networkid = self.testcreatenetwork() + # Create a attachment computeid = self.testcreatecompute() volumeid = self.testcreatevolume() + attachmentid = self.testcreateattachment(volumeid, computeid) + + self.test_fail_delete_compute_with_volume_attached(computeid) + self.test_fail_delete_volume_attached_to_compute(volumeid) - attachment = self.testcreateattachment(volumeid, computeid) - computewithnetwork = self.testcreatecomputewithnetwork(networkid) + self.testdeleteattchment(attachmentid) + self.testdeletecompute(computeid) + self.testdeletevolume(volumeid) - self.testdeletenetworkwithcomputeattached(networkid) - self.testdeleteattachedcompute(computeid) + # Create a single computes in the same network + networkid = self.testcreatenetwork() + computewithnetwork = self.testcreatecomputewithnetwork(networkid) + self.test_fail_delete_network_with_compute_attached(networkid) + self.testdeletecompute(computewithnetwork) + self.testdeletenetwork(networkid) + + # Create a bunch of computes in the same network + networkid = self.testcreatenetwork() + computes = self.testcreatemanycomputeswithnetwork(networkid) + self.test_fail_delete_network_with_compute_attached(networkid) + self.testdeletemanycomputes(computes) + self.testdeletenetwork(networkid) except Exception as e: @@ -79,7 +96,7 @@ def testgetimagebyid(self): self.endtest() def testcreatenetwork(self): - return self.__testcreategenericorder__('network') + return self.__testcreategenericorder__('network', True) def testcreatecompute(self): return self.__testcreategenericorder__('compute', True) @@ -99,23 +116,60 @@ def testcreateattachment(self, volumeid, computeid): ret = res.json() return ret['id'] - def testcreatecomputewithnetwork(self, network): - self.starttest('POST compute passign some network') + def testcreatecomputewithnetwork(self, networkid): + self.starttest('POST compute passing a network') - body = copy.deepcopy(self.resources['create_compute']) - body['networkIds'] = [network] + body = self.__getcompuebodyrequest__(networkid) res = self.rasmodel.create('compute', body=body) self.assertlt(res.status_code, 400) self.endtest() + ret = res.json() + return ret['id'] + + def test_fail_delete_network_with_compute_attached(self, networkid): + self.__testfaildeletebusyorder__('network', networkid) + + def test_fail_delete_compute_with_volume_attached(self, computeid): + self.__testfaildeletebusyorder__('compute', computeid) + + def test_fail_delete_volume_attached_to_compute(self, volumeid): + self.__testfaildeletebusyorder__('volume', volumeid) + + def testdeleteattchment(self, attachmentid): + self.__testgenericdelete__('attachment', attachmentid) + + def testdeletecompute(self, computeid): + self.__testgenericdelete__('compute', computeid) + + def testdeletevolume(self, volumeid): + self.__testgenericdelete__('volume', volumeid) + + def testdeletenetwork(self, networkid): + self.__testgenericdelete__('network', networkid) + + def testcreatemanycomputeswithnetwork(self, networkid, howmany=5): + self.starttest("POST many computes with network {}".format(networkid)) + + body = self.__getcompuebodyrequest__(networkid) + computesresponses = self.rasmodel.createmany('compute', howmany, body=body, wait_ready=True) + + for res in computesresponses: + self.assertlt(res.status_code, 400) + + self.endtest() + return computesresponses + + def testdeletemanycomputes(self, computes): + self.starttest("Deleting many computes") + + for compute in computes: + data = compute.json() + computeid = data['id'] + response = self.rasmodel.delete('compute', computeid) + self.assertlt(response.status_code, 400) - def testdeletenetworkwithcomputeattached(self, network): - self.starttest('DELETE network with orders attached (should fail)') - - res = self.rasmodel.delete('network', network) - - self.assertge(res.status_code, 400) self.endtest() @classmethod @@ -123,6 +177,14 @@ def required_resources(self): return ['auth_credentials', 'create_network', 'create_compute', 'create_volume'] + def __testfaildeletebusyorder__(self, resource, _id): + self.starttest('DELETE {} with orders attached (should fail)'.format(resource.capitalize())) + + res = self.rasmodel.delete(resource, _id) + + self.assertge(res.status_code, 400) + self.endtest() + def __testcreategenericorder__(self, resource, waitready=False): self.starttest('POST {}'.format(resource.capitalize())) @@ -148,8 +210,21 @@ def __testgetalloders__(self, resource): self.endtest() + def __testgenericdelete__(self, resource, _id): + self.starttest('DELETE {} with id {}'.format(resource.capitalize(), _id)) + + res = self.rasmodel.delete(resource, _id) + + self.assertlt(res.status_code, 400) + self.endtest() + def __attachmentbodyrequests__ (self, volumeid, computeid): return { "computeId": computeid, "volumeId": volumeid } + + def __getcompuebodyrequest__(self, networkid): + body = copy.deepcopy(self.resources['create_compute']) + body['networkIds'] = [networkid] + return body \ No newline at end of file From 4f928951f8e15a08d1f0af77b78d31fe85fdab00 Mon Sep 17 00:00:00 2001 From: Anderson Dantas Date: Thu, 23 May 2019 15:13:43 -0300 Subject: [PATCH 23/29] Implemented Emulated Cloud Public Ip Plugin --- service_test/common/test_factory.py | 2 +- service_test/main.py | 3 +- .../resource_allocation_service/ras_model.py | 11 ++++- .../service_tests.py | 45 +++++++++++++++++-- 4 files changed, 54 insertions(+), 7 deletions(-) diff --git a/service_test/common/test_factory.py b/service_test/common/test_factory.py index 7303fe6..9897db9 100644 --- a/service_test/common/test_factory.py +++ b/service_test/common/test_factory.py @@ -88,7 +88,7 @@ def __getserviceendpoint__(self, resource, **kwargs): 'compute': '/computes', 'volume': '/volumes', 'cloud': '/clouds', - 'publicIp': '/publicIps', + 'public-ip': '/publicIps', 'attachment': '/attachments' } diff --git a/service_test/main.py b/service_test/main.py index 51f68c6..1a9206d 100644 --- a/service_test/main.py +++ b/service_test/main.py @@ -78,7 +78,8 @@ def getservice(servicename): runteardown = SKIP_TEARDOWN_FLAG not in sys.argv - if runteardown: + # There's no point on tearing down if you don't setup + if runsetup and runteardown: print('###### Tearing down ######') servicetest.teardown() diff --git a/service_test/resource_allocation_service/ras_model.py b/service_test/resource_allocation_service/ras_model.py index 21ca69c..ad31b28 100644 --- a/service_test/resource_allocation_service/ras_model.py +++ b/service_test/resource_allocation_service/ras_model.py @@ -42,10 +42,16 @@ def create(self, resource, **kwargs): def createmany(self, resource, howmany=1, **kwargs): responses = [] + # TODO: First create all instances and after that wait + # for instances to be ready. Current implementation + # create a single instance and then wait it for be ready + # which takes take a lot of time when the number of + # requested instances are high for i in range(howmany): res = self.__rasrequester__.create(resource, **kwargs) wait_until_ready = kwargs.get('wait_ready', False) + if wait_until_ready: _id = res.json()['id'] res = self.__rasrequester__.wait_until_ready('compute', _id) @@ -87,4 +93,7 @@ def getimagebyid(self): images = list(res.keys()) imageid = images[0] - return self.__rasrequester__.getbyid('images', imageid, **self.imageskwargs).json() \ No newline at end of file + return self.__rasrequester__.getbyid('images', imageid, **self.imageskwargs).json() + + def genericrequest(self, url): + return self.__rasrequester__.__execute__(url) \ No newline at end of file diff --git a/service_test/resource_allocation_service/service_tests.py b/service_test/resource_allocation_service/service_tests.py index a413ae0..9fca6fa 100644 --- a/service_test/resource_allocation_service/service_tests.py +++ b/service_test/resource_allocation_service/service_tests.py @@ -19,18 +19,20 @@ def run(self): super().run() self.rasmodel = RasModel(self.origin, self.resources, self.conf) - # # GET {resource}/status + # GET {resource}/status self.testgetimages() self.testgetimagebyid() self.testgetstatus() + # GET clouds + self.testgetclouds() # Create a attachment computeid = self.testcreatecompute() volumeid = self.testcreatevolume() attachmentid = self.testcreateattachment(volumeid, computeid) - self.test_fail_delete_compute_with_volume_attached(computeid) + self.test_fail_delete_compute_with_order_attached(computeid) self.test_fail_delete_volume_attached_to_compute(volumeid) self.testdeleteattchment(attachmentid) @@ -51,6 +53,13 @@ def run(self): self.testdeletemanycomputes(computes) self.testdeletenetwork(networkid) + # Create Public Ip + computeid = self.testcreatecompute() + publicip = self.testcreatepublicip(computeid) + self.test_fail_delete_compute_with_order_attached(computeid) + self.testdeletepublicip(publicip) + self.testdeletecompute(computeid) + except Exception as e: self.fail() @@ -95,6 +104,19 @@ def testgetimagebyid(self): self.endtest() + def testgetclouds(self): + self.starttest("GET cloud(s)") + cloudsendpoint = self.origin + '/clouds' + cloudsresponse = self.rasmodel.genericrequest(cloudsendpoint) + + if self.assertlt(cloudsresponse.status_code, 400): + + clouds = cloudsresponse.json().get('clouds') + + self.asserteq(type(clouds), list) + + self.endtest() + def testcreatenetwork(self): return self.__testcreategenericorder__('network', True) @@ -128,10 +150,22 @@ def testcreatecomputewithnetwork(self, networkid): ret = res.json() return ret['id'] + def testcreatepublicip(self, computeid): + self.starttest('POST public ip for compute: {}'.format(computeid)) + + body = {'computeId': computeid} + res = self.rasmodel.create('public-ip', body=body) + + self.assertlt(res.status_code, 400) + self.endtest() + + ret = res.json() + return ret['id'] + def test_fail_delete_network_with_compute_attached(self, networkid): self.__testfaildeletebusyorder__('network', networkid) - def test_fail_delete_compute_with_volume_attached(self, computeid): + def test_fail_delete_compute_with_order_attached(self, computeid): self.__testfaildeletebusyorder__('compute', computeid) def test_fail_delete_volume_attached_to_compute(self, volumeid): @@ -149,6 +183,9 @@ def testdeletevolume(self, volumeid): def testdeletenetwork(self, networkid): self.__testgenericdelete__('network', networkid) + def testdeletepublicip(self, publicip): + self.__testgenericdelete__('public-ip', publicip) + def testcreatemanycomputeswithnetwork(self, networkid, howmany=5): self.starttest("POST many computes with network {}".format(networkid)) @@ -192,7 +229,7 @@ def __testcreategenericorder__(self, resource, waitready=False): self.assertlt(res.status_code, 400) - _id = res.json()['id'] + _id = res.json().get('id') if waitready: res = self.rasmodel.wait_until_ready(resource, _id) From e5a96b866609a7425ade439c7c62920b4b270dc9 Mon Sep 17 00:00:00 2001 From: Anderson Dantas Date: Fri, 24 May 2019 18:48:04 -0300 Subject: [PATCH 24/29] Add test_resources to repo --- service_test/.gitignore | 2 -- .../resource_allocation_service/service_tests.py | 8 ++++---- .../authentication_service/auth_credentials.json | 6 ++++++ .../invalid_auth_credentials.json | 6 ++++++ .../authentication_service/service_test_conf.json | 11 +++++++++++ .../membership_service/service_test_conf.json | 11 +++++++++++ .../auth_credentials.json | 5 +++++ .../create_compute.json | 7 +++++++ .../create_network.json | 7 +++++++ .../resource_allocation_service/create_volume.json | 6 ++++++ .../service_test_conf.json | 14 ++++++++++++++ 11 files changed, 77 insertions(+), 6 deletions(-) delete mode 100644 service_test/.gitignore create mode 100644 service_test/test_resources/authentication_service/auth_credentials.json create mode 100644 service_test/test_resources/authentication_service/invalid_auth_credentials.json create mode 100644 service_test/test_resources/authentication_service/service_test_conf.json create mode 100644 service_test/test_resources/membership_service/service_test_conf.json create mode 100644 service_test/test_resources/resource_allocation_service/auth_credentials.json create mode 100644 service_test/test_resources/resource_allocation_service/create_compute.json create mode 100644 service_test/test_resources/resource_allocation_service/create_network.json create mode 100644 service_test/test_resources/resource_allocation_service/create_volume.json create mode 100644 service_test/test_resources/resource_allocation_service/service_test_conf.json diff --git a/service_test/.gitignore b/service_test/.gitignore deleted file mode 100644 index 3629d0c..0000000 --- a/service_test/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -workdir/ -test_resources/ diff --git a/service_test/resource_allocation_service/service_tests.py b/service_test/resource_allocation_service/service_tests.py index 9fca6fa..31163d3 100644 --- a/service_test/resource_allocation_service/service_tests.py +++ b/service_test/resource_allocation_service/service_tests.py @@ -71,7 +71,7 @@ def run(self): self.logresults() def testgetstatus(self): - resources = ['attachment', 'compute', 'network', 'publicIp', 'volume'] + resources = ['attachment', 'compute', 'network', 'public-ip', 'volume'] for resource in resources: self.__testgetalloders__(resource) @@ -136,7 +136,7 @@ def testcreateattachment(self, volumeid, computeid): self.endtest() ret = res.json() - return ret['id'] + return ret.get('id') def testcreatecomputewithnetwork(self, networkid): self.starttest('POST compute passing a network') @@ -148,7 +148,7 @@ def testcreatecomputewithnetwork(self, networkid): self.assertlt(res.status_code, 400) self.endtest() ret = res.json() - return ret['id'] + return ret.get('id') def testcreatepublicip(self, computeid): self.starttest('POST public ip for compute: {}'.format(computeid)) @@ -160,7 +160,7 @@ def testcreatepublicip(self, computeid): self.endtest() ret = res.json() - return ret['id'] + return ret.get('id') def test_fail_delete_network_with_compute_attached(self, networkid): self.__testfaildeletebusyorder__('network', networkid) diff --git a/service_test/test_resources/authentication_service/auth_credentials.json b/service_test/test_resources/authentication_service/auth_credentials.json new file mode 100644 index 0000000..76db7fe --- /dev/null +++ b/service_test/test_resources/authentication_service/auth_credentials.json @@ -0,0 +1,6 @@ +{ + "credentials": { + "username": "fogbow" + }, + "publicKey": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvjN7kmdcZlOnx+sTuc018+uogz7sZdyZwdy9aijElRD7kFOf67dgONg0zXRG8odqBLSq6NH5GeqCFLXTMs8bbGbTmNKMTwfEVXCHmYQAtB41dCYPvvLyxNdyv71DVRxFW29cBgjZcOfx/HfmR41TOy9LzPRqFiMOQ3ou+fs5g9p8U/20PE41VA2553FjIV1BI/Jz5OEyt+fqcRtBOAZR0nK43AvLmQAz+gD3PBDgeSuIGCpJIsBmkogoR9xWRYnz5EXJHwxnsQqbHtJwDsJqdEMGPWtxUGgHSNy7P72367ib+Va1aAChnGVAzQuQKsCwb1ef5BaJbfILa6kB2P/i3QIDAQAB" +} diff --git a/service_test/test_resources/authentication_service/invalid_auth_credentials.json b/service_test/test_resources/authentication_service/invalid_auth_credentials.json new file mode 100644 index 0000000..d6446d0 --- /dev/null +++ b/service_test/test_resources/authentication_service/invalid_auth_credentials.json @@ -0,0 +1,6 @@ +{ + "credentials": { + "username": "invalid-user-credential" + }, + "publicKey": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvjN7kmdcZlOnx+sTuc018+uogz7sZdyZwdy9aijElRD7kFOf67dgONg0zXRG8odqBLSq6NH5GeqCFLXTMs8bbGbTmNKMTwfEVXCHmYQAtB41dCYPvvLyxNdyv71DVRxFW29cBgjZcOfx/HfmR41TOy9LzPRqFiMOQ3ou+fs5g9p8U/20PE41VA2553FjIV1BI/Jz5OEyt+fqcRtBOAZR0nK43AvLmQAz+gD3PBDgeSuIGCpJIsBmkogoR9xWRYnz5EXJHwxnsQqbHtJwDsJqdEMGPWtxUGgHSNy7P72367ib+Va1aAChnGVAzQuQKsCwb1ef5BaJbfILa6kB2P/i3QIDAQAB" +} diff --git a/service_test/test_resources/authentication_service/service_test_conf.json b/service_test/test_resources/authentication_service/service_test_conf.json new file mode 100644 index 0000000..f5c3d01 --- /dev/null +++ b/service_test/test_resources/authentication_service/service_test_conf.json @@ -0,0 +1,11 @@ +{ + "services": [], + "application": { + "branch_under_test": "develop", + "repo_url": "https://github.com/fogbow/authentication-service.git", + "port": 8081 + }, + "commands": { + "run_application": "./mvnw spring-boot:run -Drun.profiles=dev" + } +} \ No newline at end of file diff --git a/service_test/test_resources/membership_service/service_test_conf.json b/service_test/test_resources/membership_service/service_test_conf.json new file mode 100644 index 0000000..7a29a78 --- /dev/null +++ b/service_test/test_resources/membership_service/service_test_conf.json @@ -0,0 +1,11 @@ +{ + "services": [], + "application": { + "branch_under_test": "develop", + "repo_url": "https://github.com/fogbow/membership-service.git", + "port": 8080 + }, + "commands": { + "run_application": "/usr/bin/mvn spring-boot:run" + } +} diff --git a/service_test/test_resources/resource_allocation_service/auth_credentials.json b/service_test/test_resources/resource_allocation_service/auth_credentials.json new file mode 100644 index 0000000..bade7c3 --- /dev/null +++ b/service_test/test_resources/resource_allocation_service/auth_credentials.json @@ -0,0 +1,5 @@ +{ + "credentials": { + "username": "fogbow" + } +} diff --git a/service_test/test_resources/resource_allocation_service/create_compute.json b/service_test/test_resources/resource_allocation_service/create_compute.json new file mode 100644 index 0000000..4fde900 --- /dev/null +++ b/service_test/test_resources/resource_allocation_service/create_compute.json @@ -0,0 +1,7 @@ +{ + "name": "qa-anderson", + "vCPU" : 1, + "memory" : 512, + "disk" : 20, + "publicKey": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC21jUErmtVB14GJ9lZg0mGj1GlHj9KTP1P6uyqEqxVMVnGCMEL7eanXIbZl3Brz0EBhYWR4eg/RPMUPS7YOxvp2NeX/4O3J/eCrlUzZyxPqmxASp2U47sGzbgun9VbjHIb9zKEw6AkfxQvapoW3lcFacX07owNoWEAVK7/zs6IPrOOOPaj7WtFpqcVoc9UwabWFb8A6cr5TxSwaNwLtitec/R1LAnXIl/B5uswKrpSnywGS1BctshgahEXiEnsymvIJ4IPIPbwTaXaFWzelzisWqc7aZsfFYXP4ynWWkoe10DmwJbweZHInn4upx8gd1pMwPLT5JzKgg7iLEA/sdI2IvzkEse9WDXAJcV+Gki2mtksmqctogf5wrh0p/2j/JuX6v6FBIOW6n1hYycxSm0yddkoainRhv8fHVCHnRq5WYEntMMGOU3krjy6dWVmXcVf436qNpxCndZf1buEsWWnXduqphD292qYrLELmWGx4NiDlGSzANJ4rb7MTKcNPbqMhTVmC3Xm0vQ9hluLGSnLWzxmqVOa0k1KZNrzTfJRTNWo0f2myOU1l+UxQZ+gy/V4zctyYMepQ9xBiwo+XQiTIKOhxSXo6ohmnc+FSnjxkPXmfs9KfHttKxUAX8hqrMUmE+TLuVlL1nV4TPCXh2PD+nUPUq5FJP0d4enkn5xFJQ== anderson@lsd.ufcg.edu.br" + } \ No newline at end of file diff --git a/service_test/test_resources/resource_allocation_service/create_network.json b/service_test/test_resources/resource_allocation_service/create_network.json new file mode 100644 index 0000000..6561d09 --- /dev/null +++ b/service_test/test_resources/resource_allocation_service/create_network.json @@ -0,0 +1,7 @@ +{ + "gateway" : "10.10.0.1", + "cidr" : "10.10.0.0/24", + "allocationMode" : "dynamic", + "name": "mock-anderson", + "provider": "anderson-member1.lsd.ufcg.edu.br" +} \ No newline at end of file diff --git a/service_test/test_resources/resource_allocation_service/create_volume.json b/service_test/test_resources/resource_allocation_service/create_volume.json new file mode 100644 index 0000000..ab97e28 --- /dev/null +++ b/service_test/test_resources/resource_allocation_service/create_volume.json @@ -0,0 +1,6 @@ +{ + "volumeSize" : 10, + "name": "anderson-for-QA", + "provider" : "anderson-member1.lsd.ufcg.edu.br" + } + \ No newline at end of file diff --git a/service_test/test_resources/resource_allocation_service/service_test_conf.json b/service_test/test_resources/resource_allocation_service/service_test_conf.json new file mode 100644 index 0000000..116cb19 --- /dev/null +++ b/service_test/test_resources/resource_allocation_service/service_test_conf.json @@ -0,0 +1,14 @@ +{ + "services": ["authentication_service"], + "as_url": "http://localhost:8081", + "memberid": "anderson-member1.lsd.ufcg.edu.br", + "cloud": "emulated", + "application": { + "branch_under_test": "emulated-plugins", + "repo_url": "https://github.com/fogbow/resource-allocation-service.git", + "port": 8080 + }, + "commands": { + "run_application": "/usr/bin/mvn spring-boot:run" + } +} From 76d972df98b0bf3e5e57a1f0c152b62e66a2d2d6 Mon Sep 17 00:00:00 2001 From: Anderson Dantas Date: Wed, 5 Jun 2019 10:10:40 -0300 Subject: [PATCH 25/29] WIP: refactor security rules tests --- service_test/common/service_test_instance.py | 3 +- service_test/common/test_factory.py | 13 +++---- .../resource_allocation_service/__init__.py | 3 +- .../resource_allocation_service/ras_model.py | 14 +++---- .../resource_allocation_service/ras_urls.py | 7 ++++ .../service_tests.py | 37 +++++++++++++++---- .../service_test_conf.json | 3 +- .../membership_service/service_test_conf.json | 3 +- .../create_securityrule.json | 8 ++++ .../service_test_conf.json | 5 ++- 10 files changed, 66 insertions(+), 30 deletions(-) create mode 100644 service_test/resource_allocation_service/ras_urls.py create mode 100644 service_test/test_resources/resource_allocation_service/create_securityrule.json diff --git a/service_test/common/service_test_instance.py b/service_test/common/service_test_instance.py index 106fc66..ecf2771 100644 --- a/service_test/common/service_test_instance.py +++ b/service_test/common/service_test_instance.py @@ -31,7 +31,8 @@ def __init__(self, service, configuration, resources): self.pid = None self.resources = resources self.port = self.conf['application']['port'] - self.origin = 'http://localhost:' + str(self.port) + self.api_endpoint = self.conf['application']['api_endpoint'] + self.origin = self.api_endpoint def starttest(cls, msg): cls.endtest() diff --git a/service_test/common/test_factory.py b/service_test/common/test_factory.py index 9897db9..112176e 100644 --- a/service_test/common/test_factory.py +++ b/service_test/common/test_factory.py @@ -11,7 +11,6 @@ class TestEngine(object): def __init__(self, service_url): - self.last_create = None self.service_url = service_url self.body = {} self.headers = {} @@ -37,9 +36,7 @@ def create(self, resource, **kwargs): body = kwargs.get('body', self.body) req = FogbowRequest(url=url, headers=headers, body=body, method=str(HttpMethods.POST)) - self.last_create = req.execute() - - return self.last_create + return req.execute() def get(self, resource, **kwargs): url = self.__getserviceendpoint__(resource, **kwargs) @@ -75,8 +72,9 @@ def __execute__(self, url, **kwargs): return req.execute() def __getserviceendpoint__(self, resource, **kwargs): - memberid = kwargs.get('memberid', '') - cloud = kwargs.get('cloud', '') + memberid = kwargs.get('memberid') + cloud = kwargs.get('cloud') + pubip = kwargs.get('pubip') available_endpoints = { 'token': '/tokens', @@ -89,7 +87,8 @@ def __getserviceendpoint__(self, resource, **kwargs): 'volume': '/volumes', 'cloud': '/clouds', 'public-ip': '/publicIps', - 'attachment': '/attachments' + 'attachment': '/attachments', + 'secrule-publicip': '/publicIps/{}/securityRules/'.format(pubip) } urlpath = available_endpoints[resource] diff --git a/service_test/resource_allocation_service/__init__.py b/service_test/resource_allocation_service/__init__.py index f1d865c..3a38320 100644 --- a/service_test/resource_allocation_service/__init__.py +++ b/service_test/resource_allocation_service/__init__.py @@ -1,8 +1,9 @@ # -*- coding: utf-8 -*- +from .ras_urls import * from .ras_model import * from .service_tests import * -modules = [service_tests, ras_model] +modules = [ras_urls, ras_model, service_tests] __all__ = [prop for module in modules for prop in module.__all__] diff --git a/service_test/resource_allocation_service/ras_model.py b/service_test/resource_allocation_service/ras_model.py index ad31b28..c91a65d 100644 --- a/service_test/resource_allocation_service/ras_model.py +++ b/service_test/resource_allocation_service/ras_model.py @@ -77,7 +77,7 @@ def creategenericorder(self, resource, parseresponse=False): res = self.__rasrequester__.create(resource.lower(), body=body) if parseresponse: - res = res.json()['id'] + res = res.json().get('id') return res @@ -86,14 +86,10 @@ def wait_until_ready(self, resource, _id): def getimages(self): res = self.__rasrequester__.get('images', **self.imageskwargs).json() - return res.keys() + return res - def getimagebyid(self): - res = self.__rasrequester__.get('images', **self.imageskwargs).json() - images = list(res.keys()) - - imageid = images[0] + def getimagebyid(self, imageid): return self.__rasrequester__.getbyid('images', imageid, **self.imageskwargs).json() - def genericrequest(self, url): - return self.__rasrequester__.__execute__(url) \ No newline at end of file + def genericrequest(self, url, **kwargs): + return self.__rasrequester__.__execute__(url, **kwargs) \ No newline at end of file diff --git a/service_test/resource_allocation_service/ras_urls.py b/service_test/resource_allocation_service/ras_urls.py new file mode 100644 index 0000000..4c34c20 --- /dev/null +++ b/service_test/resource_allocation_service/ras_urls.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- + +__all__ = ['RasUrls'] + +class RasUrls: + # public ip security rule + pubipsecrule = '/publicIps/{}/securityRules/' \ No newline at end of file diff --git a/service_test/resource_allocation_service/service_tests.py b/service_test/resource_allocation_service/service_tests.py index 31163d3..0cb40ef 100644 --- a/service_test/resource_allocation_service/service_tests.py +++ b/service_test/resource_allocation_service/service_tests.py @@ -3,8 +3,8 @@ import copy import time -from common import TestEngine, VersionandPublicKeyCheck -from . import RasModel +from common import TestEngine, VersionandPublicKeyCheck, HttpMethods +from . import RasModel, RasUrls __all__ = ['RASTest'] @@ -20,8 +20,8 @@ def run(self): self.rasmodel = RasModel(self.origin, self.resources, self.conf) # GET {resource}/status - self.testgetimages() - self.testgetimagebyid() + images = self.testgetimages() + self.testgetimagebyid(images) self.testgetstatus() # GET clouds @@ -57,6 +57,9 @@ def run(self): computeid = self.testcreatecompute() publicip = self.testcreatepublicip(computeid) self.test_fail_delete_compute_with_order_attached(computeid) + + # Test Create SecurityRule over public ip + securityrule = self.testcreatesecurityrule(publicip) self.testdeletepublicip(publicip) self.testdeletecompute(computeid) @@ -79,17 +82,20 @@ def testgetstatus(self): def testgetimages(self): self.starttest('GET Images') + print('images received', ) images = self.rasmodel.getimages() + self.assertgt(len(images), 0) self.endtest() + return images - def testgetimagebyid(self): + def testgetimagebyid(self, images): self.starttest('GET Image by id') + _id = images[0]['id'] - imagedata = self.rasmodel.getimagebyid() + imagedata = self.rasmodel.getimagebyid(_id) - _id = imagedata['id'] _name = imagedata['name'] _size = imagedata['size'] @@ -209,10 +215,25 @@ def testdeletemanycomputes(self, computes): self.endtest() + def testcreatesecurityrule(self, pubip): + self.starttest('POST security rule on public ip') + + body = self.resources['create_securityrule'].copy() + _id = self.rasmodel.create('secrule-publicip', body=body, pubip=pubip) + # path = RasUrls.pubipsecrule.format(pubip) + # url = self.origin + path + + # res = self.rasmodel.genericrequest(url, body=body, method=HttpMethods.POST) + + self.assertlt(res.status_code, 400) + + self.endtest() + + @classmethod def required_resources(self): return ['auth_credentials', 'create_network', 'create_compute', - 'create_volume'] + 'create_volume', 'create_securityrule'] def __testfaildeletebusyorder__(self, resource, _id): self.starttest('DELETE {} with orders attached (should fail)'.format(resource.capitalize())) diff --git a/service_test/test_resources/authentication_service/service_test_conf.json b/service_test/test_resources/authentication_service/service_test_conf.json index f5c3d01..17769b9 100644 --- a/service_test/test_resources/authentication_service/service_test_conf.json +++ b/service_test/test_resources/authentication_service/service_test_conf.json @@ -3,7 +3,8 @@ "application": { "branch_under_test": "develop", "repo_url": "https://github.com/fogbow/authentication-service.git", - "port": 8081 + "port": 8081, + "api_endpoint": "http://localhost:8081/as" }, "commands": { "run_application": "./mvnw spring-boot:run -Drun.profiles=dev" diff --git a/service_test/test_resources/membership_service/service_test_conf.json b/service_test/test_resources/membership_service/service_test_conf.json index 7a29a78..dddd164 100644 --- a/service_test/test_resources/membership_service/service_test_conf.json +++ b/service_test/test_resources/membership_service/service_test_conf.json @@ -3,7 +3,8 @@ "application": { "branch_under_test": "develop", "repo_url": "https://github.com/fogbow/membership-service.git", - "port": 8080 + "port": 8080, + "api_endpoint": "http://localhost:8081/ms" }, "commands": { "run_application": "/usr/bin/mvn spring-boot:run" diff --git a/service_test/test_resources/resource_allocation_service/create_securityrule.json b/service_test/test_resources/resource_allocation_service/create_securityrule.json new file mode 100644 index 0000000..4834f1a --- /dev/null +++ b/service_test/test_resources/resource_allocation_service/create_securityrule.json @@ -0,0 +1,8 @@ +{ + "direction": "IN", + "portFrom": 99, + "portTo": 3752, + "cidr": "0.0.0.0/0", + "etherType": "IPv4", + "protocol": "TCP" +} \ No newline at end of file diff --git a/service_test/test_resources/resource_allocation_service/service_test_conf.json b/service_test/test_resources/resource_allocation_service/service_test_conf.json index 116cb19..37232d4 100644 --- a/service_test/test_resources/resource_allocation_service/service_test_conf.json +++ b/service_test/test_resources/resource_allocation_service/service_test_conf.json @@ -1,12 +1,13 @@ { "services": ["authentication_service"], - "as_url": "http://localhost:8081", + "as_url": "http://localhost:8081/as", "memberid": "anderson-member1.lsd.ufcg.edu.br", "cloud": "emulated", "application": { "branch_under_test": "emulated-plugins", "repo_url": "https://github.com/fogbow/resource-allocation-service.git", - "port": 8080 + "port": 8080, + "api_endpoint": "http://localhost:8080/ras" }, "commands": { "run_application": "/usr/bin/mvn spring-boot:run" From 59f16298069077698734bf0b9061c601c7bd329e Mon Sep 17 00:00:00 2001 From: Anderson Dantas Date: Wed, 5 Jun 2019 15:53:51 -0300 Subject: [PATCH 26/29] Change command to run services --- .../authentication_service/service_test_conf.json | 2 +- .../test_resources/membership_service/service_test_conf.json | 4 ++-- .../resource_allocation_service/service_test_conf.json | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/service_test/test_resources/authentication_service/service_test_conf.json b/service_test/test_resources/authentication_service/service_test_conf.json index 17769b9..3baf5ed 100644 --- a/service_test/test_resources/authentication_service/service_test_conf.json +++ b/service_test/test_resources/authentication_service/service_test_conf.json @@ -7,6 +7,6 @@ "api_endpoint": "http://localhost:8081/as" }, "commands": { - "run_application": "./mvnw spring-boot:run -Drun.profiles=dev" + "run_application": "/usr/bin/mvn spring-boot:run -Dspring.profiles.active=dev" } } \ No newline at end of file diff --git a/service_test/test_resources/membership_service/service_test_conf.json b/service_test/test_resources/membership_service/service_test_conf.json index dddd164..2ff47e3 100644 --- a/service_test/test_resources/membership_service/service_test_conf.json +++ b/service_test/test_resources/membership_service/service_test_conf.json @@ -4,9 +4,9 @@ "branch_under_test": "develop", "repo_url": "https://github.com/fogbow/membership-service.git", "port": 8080, - "api_endpoint": "http://localhost:8081/ms" + "api_endpoint": "http://localhost:8080/ms" }, "commands": { - "run_application": "/usr/bin/mvn spring-boot:run" + "run_application": "/usr/bin/mvn spring-boot:run -Dspring.profiles.active=dev" } } diff --git a/service_test/test_resources/resource_allocation_service/service_test_conf.json b/service_test/test_resources/resource_allocation_service/service_test_conf.json index 37232d4..32b5c29 100644 --- a/service_test/test_resources/resource_allocation_service/service_test_conf.json +++ b/service_test/test_resources/resource_allocation_service/service_test_conf.json @@ -1,5 +1,5 @@ { - "services": ["authentication_service"], + "services": ["authentication_service", "membership_service"], "as_url": "http://localhost:8081/as", "memberid": "anderson-member1.lsd.ufcg.edu.br", "cloud": "emulated", @@ -10,6 +10,6 @@ "api_endpoint": "http://localhost:8080/ras" }, "commands": { - "run_application": "/usr/bin/mvn spring-boot:run" + "run_application": "/usr/bin/mvn spring-boot:run -Dspring.profiles.active=dev" } } From bfd34f75fb5911e0fc7185901ecc4040b7ebf3ce Mon Sep 17 00:00:00 2001 From: Anderson Dantas Date: Fri, 7 Jun 2019 18:14:25 -0300 Subject: [PATCH 27/29] WIP: test remote clouds --- service_test/common/test_factory.py | 24 +++++++++++++++---- service_test/main.py | 2 ++ .../resource_allocation_service/ras_model.py | 16 ++++++++++--- .../service_tests.py | 17 +++++++------ .../membership_service/service_test_conf.json | 4 ++-- .../service_test_conf.json | 1 + 6 files changed, 45 insertions(+), 19 deletions(-) diff --git a/service_test/common/test_factory.py b/service_test/common/test_factory.py index 112176e..83fe40e 100644 --- a/service_test/common/test_factory.py +++ b/service_test/common/test_factory.py @@ -7,7 +7,7 @@ from os import path from . import HttpMethods, InstanceState -__all__ = ['TestEngine'] +__all__ = ['TestEngine', 'FogbowRequest'] class TestEngine(object): def __init__(self, service_url): @@ -15,17 +15,19 @@ def __init__(self, service_url): self.body = {} self.headers = {} - def wait_until_ready(self, resource, instance_id, tries = 50): + def wait_until_ready(self, resource, instance_id, **kwargs): + tries = kwargs.get('tries', 50) if tries <= 0: return None - res = self.getbyid(resource, instance_id) + res = self.getbyid(resource, instance_id, **kwargs) state = res.json()['state'] if state == InstanceState.READY: ret = res else: time.sleep(1) - ret = self.wait_until_ready(resource, instance_id, tries-1) + kwargs['tries'] = tries-1 + ret = self.wait_until_ready(resource, instance_id, **kwargs) return ret @@ -106,6 +108,11 @@ def addHeader(self, header, headervalue): print("Header content: {}".format(headervalue)) class FogbowRequest: + + commonsettings = { + 'body': {} + } + def __init__(self, url, **kwargs): self.url = url self.headers = kwargs.get('headers', {}) @@ -113,9 +120,16 @@ def __init__(self, url, **kwargs): self.method = kwargs.get('method', 'get') self.enablelog = kwargs.get('enablelog', True) + @classmethod + def addsetting(cls, key, setting): + cls.commonsettings[key] = setting + def execute(self): verb_requester = getattr(requests, self.method) - res = verb_requester(url=self.url, json=self.body, headers=self.headers) + + body = { **self.commonsettings, **self.body } + + res = verb_requester(url=self.url, json=body, headers=self.headers) if self.enablelog: print("\n{} {}".format(self.method.upper(), res.url, )) diff --git a/service_test/main.py b/service_test/main.py index 1a9206d..e9e6949 100644 --- a/service_test/main.py +++ b/service_test/main.py @@ -43,6 +43,8 @@ def getservice(servicename): return ServiceTest(servicename, configuration, service_resources) if __name__ == "__main__": + # Delete me + FogbowRequest.addsetting('body', {'foo': 'barz'}) curdir = os.getcwd() diff --git a/service_test/resource_allocation_service/ras_model.py b/service_test/resource_allocation_service/ras_model.py index c91a65d..c956a91 100644 --- a/service_test/resource_allocation_service/ras_model.py +++ b/service_test/resource_allocation_service/ras_model.py @@ -12,8 +12,8 @@ def __init__(self, origin, resources, conf): self.__rasrequester__ = TestEngine(origin) pubkey = self.getpubkey() - token = self.createtoken(pubkey) + self.__rasrequester__.addHeader('Fogbow-User-Token', token) self.imageskwargs = { @@ -36,6 +36,16 @@ def createtoken(self, pubkey): res = asrequester.create('token', body=credentials).json() return res['token'] + def getmembers(self): + ms_url = self.conf['as_url'] + msrequester = TestEngine(ms_url) + + credentials = self.resources['auth_credentials'] + credentials['publicKey'] = pubkey + + res = asrequester.create('token', body=credentials).json() + return res['token'] + def create(self, resource, **kwargs): return self.__rasrequester__.create(resource, **kwargs) @@ -81,8 +91,8 @@ def creategenericorder(self, resource, parseresponse=False): return res - def wait_until_ready(self, resource, _id): - return self.__rasrequester__.wait_until_ready(resource, _id) + def wait_until_ready(self, resource, _id, **kwargs): + return self.__rasrequester__.wait_until_ready(resource, _id, **kwargs) def getimages(self): res = self.__rasrequester__.get('images', **self.imageskwargs).json() diff --git a/service_test/resource_allocation_service/service_tests.py b/service_test/resource_allocation_service/service_tests.py index 0cb40ef..3d6ea25 100644 --- a/service_test/resource_allocation_service/service_tests.py +++ b/service_test/resource_allocation_service/service_tests.py @@ -161,12 +161,14 @@ def testcreatepublicip(self, computeid): body = {'computeId': computeid} res = self.rasmodel.create('public-ip', body=body) + _id = res.json().get('id') + + self.rasmodel.wait_until_ready('public-ip', _id) self.assertlt(res.status_code, 400) self.endtest() - ret = res.json() - return ret.get('id') + return _id def test_fail_delete_network_with_compute_attached(self, networkid): self.__testfaildeletebusyorder__('network', networkid) @@ -217,14 +219,11 @@ def testdeletemanycomputes(self, computes): def testcreatesecurityrule(self, pubip): self.starttest('POST security rule on public ip') - + body = self.resources['create_securityrule'].copy() - _id = self.rasmodel.create('secrule-publicip', body=body, pubip=pubip) - # path = RasUrls.pubipsecrule.format(pubip) - # url = self.origin + path - - # res = self.rasmodel.genericrequest(url, body=body, method=HttpMethods.POST) - + res = self.rasmodel.create('secrule-publicip', body=body, pubip=pubip) + _id = res.json().get('id') + self.assertlt(res.status_code, 400) self.endtest() diff --git a/service_test/test_resources/membership_service/service_test_conf.json b/service_test/test_resources/membership_service/service_test_conf.json index 2ff47e3..8dc8280 100644 --- a/service_test/test_resources/membership_service/service_test_conf.json +++ b/service_test/test_resources/membership_service/service_test_conf.json @@ -3,8 +3,8 @@ "application": { "branch_under_test": "develop", "repo_url": "https://github.com/fogbow/membership-service.git", - "port": 8080, - "api_endpoint": "http://localhost:8080/ms" + "port": 8083, + "api_endpoint": "http://localhost:8083/ms" }, "commands": { "run_application": "/usr/bin/mvn spring-boot:run -Dspring.profiles.active=dev" diff --git a/service_test/test_resources/resource_allocation_service/service_test_conf.json b/service_test/test_resources/resource_allocation_service/service_test_conf.json index 32b5c29..be46b0e 100644 --- a/service_test/test_resources/resource_allocation_service/service_test_conf.json +++ b/service_test/test_resources/resource_allocation_service/service_test_conf.json @@ -1,6 +1,7 @@ { "services": ["authentication_service", "membership_service"], "as_url": "http://localhost:8081/as", + "ms_url": "http://localhost:8083/ms", "memberid": "anderson-member1.lsd.ufcg.edu.br", "cloud": "emulated", "application": { From 405e23b40ecd9671e3681608cc0f0b94fc9622ba Mon Sep 17 00:00:00 2001 From: Anderson Dantas Date: Tue, 11 Jun 2019 09:52:23 -0300 Subject: [PATCH 28/29] Chaanges old test_factory class to FogbowHttpUtil for clearer naming --- .../authentication_service/service_tests.py | 4 ++-- service_test/common/__init__.py | 4 ++-- service_test/common/check_version.py | 4 ++-- service_test/common/check_version_and_public_key.py | 4 ++-- .../common/{test_factory.py => fogbow_http_util.py} | 4 ++-- service_test/membership_service/service_tests.py | 4 ++-- .../resource_allocation_service/ras_model.py | 13 +++++-------- .../resource_allocation_service/service_tests.py | 2 +- 8 files changed, 18 insertions(+), 21 deletions(-) rename service_test/common/{test_factory.py => fogbow_http_util.py} (98%) diff --git a/service_test/authentication_service/service_tests.py b/service_test/authentication_service/service_tests.py index b5ae63a..1f9b028 100644 --- a/service_test/authentication_service/service_tests.py +++ b/service_test/authentication_service/service_tests.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from common import TestEngine, VersionandPublicKeyCheck +from common import FogbowHttpUtil, VersionandPublicKeyCheck __all__ = ['AuthTest'] @@ -34,7 +34,7 @@ def failcreatetoken(self): def __createtokentest__ (self, message, credentials, assertion): self.starttest(message) - test = TestEngine(self.origin) + test = FogbowHttpUtil(self.origin) res = test.create('token', body=credentials) assertion(res.status_code, 400) diff --git a/service_test/common/__init__.py b/service_test/common/__init__.py index 3eeb720..473194c 100644 --- a/service_test/common/__init__.py +++ b/service_test/common/__init__.py @@ -3,12 +3,12 @@ from .http_methods import * from .instance_states import * from .service_test_instance import * -from .test_factory import * +from .fogbow_http_util import * from .utils import * from .check_version import * from .check_version_and_public_key import * modules = [constants, http_methods, instance_states, service_test_instance, - test_factory, utils, check_version, check_version_and_public_key] + fogbow_http_util, utils, check_version, check_version_and_public_key] __all__ = [prop for module in modules for prop in module.__all__] diff --git a/service_test/common/check_version.py b/service_test/common/check_version.py index a8e5101..deefb04 100644 --- a/service_test/common/check_version.py +++ b/service_test/common/check_version.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from .service_test_instance import ServiceTestInstance -from .test_factory import TestEngine +from .fogbow_http_util import FogbowHttpUtil __all__ = ['VersionCheck'] @@ -13,7 +13,7 @@ def run(self): def version(self): self.starttest('Requesting version') - test = TestEngine(self.origin) + test = FogbowHttpUtil(self.origin) res = test.get('version').json() version = res['version'] diff --git a/service_test/common/check_version_and_public_key.py b/service_test/common/check_version_and_public_key.py index 67ee502..a5b6bae 100644 --- a/service_test/common/check_version_and_public_key.py +++ b/service_test/common/check_version_and_public_key.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from .service_test_instance import ServiceTestInstance -from .test_factory import TestEngine +from .fogbow_http_util import FogbowHttpUtil from .check_version import VersionCheck __all__ = ['VersionandPublicKeyCheck'] @@ -15,7 +15,7 @@ def run(self): def publickey(self): self.starttest('Requesting public key') - test = TestEngine(self.origin) + test = FogbowHttpUtil(self.origin) res = test.get('public-key').json() publickey = res['publicKey'] diff --git a/service_test/common/test_factory.py b/service_test/common/fogbow_http_util.py similarity index 98% rename from service_test/common/test_factory.py rename to service_test/common/fogbow_http_util.py index 83fe40e..5a1ff8a 100644 --- a/service_test/common/test_factory.py +++ b/service_test/common/fogbow_http_util.py @@ -7,9 +7,9 @@ from os import path from . import HttpMethods, InstanceState -__all__ = ['TestEngine', 'FogbowRequest'] +__all__ = ['FogbowHttpUtil', 'FogbowRequest'] -class TestEngine(object): +class FogbowHttpUtil(object): def __init__(self, service_url): self.service_url = service_url self.body = {} diff --git a/service_test/membership_service/service_tests.py b/service_test/membership_service/service_tests.py index aee8220..e03c0b7 100644 --- a/service_test/membership_service/service_tests.py +++ b/service_test/membership_service/service_tests.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from common import TestEngine, VersionCheck +from common import FogbowHttpUtil, VersionCheck __all__ = ['MembersTest'] @@ -23,7 +23,7 @@ def run(self): def listmembers(self): self.starttest('List members') - test = TestEngine(self.origin) + test = FogbowHttpUtil(self.origin) res = test.get('members').json() members = res['members'] diff --git a/service_test/resource_allocation_service/ras_model.py b/service_test/resource_allocation_service/ras_model.py index c956a91..75e590f 100644 --- a/service_test/resource_allocation_service/ras_model.py +++ b/service_test/resource_allocation_service/ras_model.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from common import TestEngine +from common import FogbowHttpUtil __all__ = ['RasModel'] @@ -9,7 +9,7 @@ class RasModel(object): def __init__(self, origin, resources, conf): self.resources = resources self.conf = conf - self.__rasrequester__ = TestEngine(origin) + self.__rasrequester__ = FogbowHttpUtil(origin) pubkey = self.getpubkey() token = self.createtoken(pubkey) @@ -28,7 +28,7 @@ def getpubkey(self): def createtoken(self, pubkey): as_url = self.conf['as_url'] - asrequester = TestEngine(as_url) + asrequester = FogbowHttpUtil(as_url) credentials = self.resources['auth_credentials'] credentials['publicKey'] = pubkey @@ -38,12 +38,9 @@ def createtoken(self, pubkey): def getmembers(self): ms_url = self.conf['as_url'] - msrequester = TestEngine(ms_url) + msrequester = FogbowHttpUtil(ms_url) - credentials = self.resources['auth_credentials'] - credentials['publicKey'] = pubkey - - res = asrequester.create('token', body=credentials).json() + res = msrequester.create('token', body=credentials).json() return res['token'] def create(self, resource, **kwargs): diff --git a/service_test/resource_allocation_service/service_tests.py b/service_test/resource_allocation_service/service_tests.py index 3d6ea25..2013086 100644 --- a/service_test/resource_allocation_service/service_tests.py +++ b/service_test/resource_allocation_service/service_tests.py @@ -3,7 +3,7 @@ import copy import time -from common import TestEngine, VersionandPublicKeyCheck, HttpMethods +from common import FogbowHttpUtil, VersionandPublicKeyCheck, HttpMethods from . import RasModel, RasUrls __all__ = ['RASTest'] From 7e3f1fbd962e758896b5ccdc9ef936b084d2ce68 Mon Sep 17 00:00:00 2001 From: Anderson Dantas Date: Tue, 11 Jun 2019 15:51:36 -0300 Subject: [PATCH 29/29] RAS tests check all clouds and members --- service_test/common/fogbow_http_util.py | 6 ++++- .../resource_allocation_service/ras_model.py | 9 ++++++- .../service_tests.py | 26 ++++++++++++++++--- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/service_test/common/fogbow_http_util.py b/service_test/common/fogbow_http_util.py index 5a1ff8a..f437e48 100644 --- a/service_test/common/fogbow_http_util.py +++ b/service_test/common/fogbow_http_util.py @@ -125,9 +125,13 @@ def addsetting(cls, key, setting): cls.commonsettings[key] = setting def execute(self): + print("settings:", self.commonsettings) verb_requester = getattr(requests, self.method) - body = { **self.commonsettings, **self.body } + body = {**self.body} + + if self.method == HttpMethods.POST: + body = { **self.commonsettings, **body } res = verb_requester(url=self.url, json=body, headers=self.headers) diff --git a/service_test/resource_allocation_service/ras_model.py b/service_test/resource_allocation_service/ras_model.py index 75e590f..5cd3b0f 100644 --- a/service_test/resource_allocation_service/ras_model.py +++ b/service_test/resource_allocation_service/ras_model.py @@ -99,4 +99,11 @@ def getimagebyid(self, imageid): return self.__rasrequester__.getbyid('images', imageid, **self.imageskwargs).json() def genericrequest(self, url, **kwargs): - return self.__rasrequester__.__execute__(url, **kwargs) \ No newline at end of file + return self.__rasrequester__.__execute__(url, **kwargs) + + def setmemberid(self, memberid): + self.imageskwargs['memberid'] = memberid + + def setcloud(self, cloud): + self.imageskwargs['cloud'] = cloud + \ No newline at end of file diff --git a/service_test/resource_allocation_service/service_tests.py b/service_test/resource_allocation_service/service_tests.py index 2013086..846b1d0 100644 --- a/service_test/resource_allocation_service/service_tests.py +++ b/service_test/resource_allocation_service/service_tests.py @@ -3,7 +3,7 @@ import copy import time -from common import FogbowHttpUtil, VersionandPublicKeyCheck, HttpMethods +from common import FogbowHttpUtil, FogbowRequest, VersionandPublicKeyCheck, HttpMethods from . import RasModel, RasUrls __all__ = ['RASTest'] @@ -13,11 +13,31 @@ class RASTest(VersionandPublicKeyCheck): def __init__(self, service, configuration, resources): super().__init__(service, configuration, resources) self.resources = resources - + def run(self): + self.rasmodel = RasModel(self.origin, self.resources, self.conf) + res = self.rasmodel.get('cloud').json() + clouds = res.get('clouds') + + # ms_url + membersrequest = FogbowHttpUtil(self.conf['ms_url']) + res = membersrequest.get('members').json() + members = res.get('members') + + for member in members: + for cloudio in clouds: + print ('Running tests for member:', member, \ + ', at cloud:', cloudio) + + self.tests_battery(member, cloudio) + + def tests_battery(self, memberid, cloudioname="emulated"): try: super().run() - self.rasmodel = RasModel(self.origin, self.resources, self.conf) + FogbowRequest.addsetting('body', { + 'provider': memberid, + 'cloudName': cloudioname + }) # GET {resource}/status images = self.testgetimages()