Add ODL tests. 45/21745/1
authorThomas Duval <thomas.duval@orange.com>
Mon, 29 Aug 2016 12:33:28 +0000 (14:33 +0200)
committerThomas Duval <thomas.duval@orange.com>
Tue, 20 Sep 2016 08:38:37 +0000 (10:38 +0200)
Change-Id: Ic530a44671631e8f24bcf62651ce20d3ac882b61
(cherry picked from commit f0697f3024b81106f3d4dc43dd84948fe8afe036)

tests/run_tests.py

index 2b93203..e953e86 100755 (executable)
@@ -30,22 +30,59 @@ COPPER_REPO = dirs.get('dir_repo_moon')
 TEST_DB_URL = functest_yaml.get('results').get('test_db_url')
 
 logger = ft_logger.Logger("moon").getLogger()
+try:
+    # Python3 version
+    from urllib.request import urlopen, HTTPBasicAuthHandler, build_opener, install_opener
+except ImportError:
+    # Python2 version
+    from urllib import urlopen
+    from urllib2 import HTTPBasicAuthHandler, build_opener, install_opener
+
+
+def test_federation():
+    # Retrieve Moon token
+    url = urlopen('http://localhost:8080/moon/token',
+                  data='grant_type=password&username=admin&password=console'.encode('utf-8'))
+    code = url.getcode()
+    if code not in (200, 201, 202, 204):
+        return False, "Not able to retrieve Moon token."
+
+    # Retrieve ODL token
+    auth_handler = HTTPBasicAuthHandler()
+    auth_handler.add_password(realm='Moon',
+                              uri='http://localhost:8080/auth/v1/domains',
+                              user='admin',
+                              passwd='console')
+    opener = build_opener(auth_handler)
+    install_opener(opener)
+    url = urlopen('http://www.example.com/login.html')
+    code = url.getcode()
+    if code not in (200, 201, 202, 204):
+        return False, "Not able to retrieve ODL token."
+    return True, ""
+
+
+def test_moon_openstack():
+    cmd = "moon test --password console --self"
 
+    ret_val = functest_utils.execute_command(cmd, logger, exit_on_error=False)
 
-def main():
-    cmd = "moon test --password console --self"
+    return ret_val
 
+
+def main():
     start_time = time.time()
 
-    ret_val = functest_utils.execute_command(cmd, logger, exit_on_error=False)
+    result_os = test_moon_openstack()
+    result_odl = test_federation()
 
     stop_time = time.time()
     duration = round(stop_time - start_time, 1)
-    if ret_val == 0:
-        logger.info("MOON PASSED")
+    if result_os == 0 and result_odl[0]:
+        logger.info("OS MOON PASSED")
         test_status = 'PASS'
     else:
-        logger.info("MOON")
+        logger.info("OS MOON ERROR")
         test_status = 'FAIL'
 
     details = {
@@ -67,10 +104,13 @@ def main():
                                           details)
         logger.info("Moon results pushed to DB")
 
-    if ret_val != 0:
-        sys.exit(-1)
+    if result_os != 0 or not result_odl[0]:
+        return False
+    return True
 
-    sys.exit(0)
 
 if __name__ == '__main__':
-    main()
+    ret = main()
+    if ret:
+        sys.exit(0)
+    sys.exit(1)