You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by jo...@apache.org on 2015/01/09 17:54:52 UTC

ambari git commit: AMBARI-9063 - Ambari Builds Succeed With Python Unit Test Failures (jonathanhurley)

Repository: ambari
Updated Branches:
  refs/heads/trunk c87fa43be -> 11763dca2


AMBARI-9063 - Ambari Builds Succeed With Python Unit Test Failures (jonathanhurley)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/11763dca
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/11763dca
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/11763dca

Branch: refs/heads/trunk
Commit: 11763dca2e62b310ff97eb8cd03bd0ff89221663
Parents: c87fa43
Author: Jonathan Hurley <jh...@hortonworks.com>
Authored: Fri Jan 9 11:26:46 2015 -0500
Committer: Jonathan Hurley <jh...@hortonworks.com>
Committed: Fri Jan 9 11:28:33 2015 -0500

----------------------------------------------------------------------
 .../test/python/custom_actions/TestCheckHost.py |  9 +++++-
 .../custom_actions/TestInstallPackages.py       | 28 ++++++++---------
 ambari-server/src/test/python/unitTests.py      | 32 ++++++++++++--------
 3 files changed, 42 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/11763dca/ambari-server/src/test/python/custom_actions/TestCheckHost.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/custom_actions/TestCheckHost.py b/ambari-server/src/test/python/custom_actions/TestCheckHost.py
index cb934c9..f910d06 100644
--- a/ambari-server/src/test/python/custom_actions/TestCheckHost.py
+++ b/ambari-server/src/test/python/custom_actions/TestCheckHost.py
@@ -232,6 +232,8 @@ class TestCheckHost(TestCase):
     structured_out_mock.assert_called_with({})
 
 
+  @patch("platform.linux_distribution")
+  @patch("platform.system")
   @patch.object(Script, 'get_config')
   @patch.object(Script, 'get_tmp_dir')
   @patch('resource_management.libraries.script.Script.put_structured_out')
@@ -244,7 +246,12 @@ class TestCheckHost(TestCase):
   @patch('time.time')
   def testLastAgentEnv(self, time_mock, checkReverseLookup_mock, checkIptables_mock, getTransparentHugePage_mock,
                        getUMask_mock, checkLiveServices_mock, javaProcs_mock, put_structured_out_mock,
-                       get_tmp_dir_mock, get_config_mock):
+                       get_tmp_dir_mock, get_config_mock, systemMock, distMock):
+
+
+    systemMock.return_value = "Linux"
+    distMock.return_value = ("CentOS", "6.3", None)
+
     jsonFilePath = os.path.join("../resources/custom_actions", "check_last_agent_env.json")
     with open(jsonFilePath, "r") as jsonFile:
       jsonPayload = json.load(jsonFile)

http://git-wip-us.apache.org/repos/asf/ambari/blob/11763dca/ambari-server/src/test/python/custom_actions/TestInstallPackages.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/custom_actions/TestInstallPackages.py b/ambari-server/src/test/python/custom_actions/TestInstallPackages.py
index beb918b..0ad56c8 100644
--- a/ambari-server/src/test/python/custom_actions/TestInstallPackages.py
+++ b/ambari-server/src/test/python/custom_actions/TestInstallPackages.py
@@ -53,20 +53,20 @@ class TestInstallPackages(RMFTestCase):
                        'installed_repository_version': u'2.2.0.1-885',
                        'ambari_repositories': []})
     self.assertResourceCalled('Repository', 'HDP-UTILS-2.2.0.1-885',
-                              base_url='http://s3.amazonaws.com/dev.hortonworks.com/HDP/centos5/2.x/updates/2.2.0.0',
+                              base_url=u'http://s3.amazonaws.com/dev.hortonworks.com/HDP/centos5/2.x/updates/2.2.0.0',
                               action=['create'],
                               components=[u'HDP-UTILS', 'main'],
                               repo_template='repo_suse_rhel.j2',
-                              repo_file_name='HDP-2.2.0.1-885',
+                              repo_file_name=u'HDP-2.2.0.1-885',
                               mirror_list=None,
                               append_to_file=False,
     )
     self.assertResourceCalled('Repository', 'HDP-2.2.0.1-885',
-                              base_url='http://s3.amazonaws.com/dev.hortonworks.com/HDP/centos5/2.x/updates/2.2.0.0',
+                              base_url=u'http://s3.amazonaws.com/dev.hortonworks.com/HDP/centos5/2.x/updates/2.2.0.0',
                               action=['create'],
                               components=[u'HDP', 'main'],
                               repo_template='repo_suse_rhel.j2',
-                              repo_file_name='HDP-2.2.0.1-885',
+                              repo_file_name=u'HDP-2.2.0.1-885',
                               mirror_list=None,
                               append_to_file=True,
     )
@@ -99,10 +99,10 @@ class TestInstallPackages(RMFTestCase):
                        'installed_repository_version': u'2.2.0.1-885',
                        'ambari_repositories': ["HDP-UTILS-2.2.0.1-885"]})
     self.assertResourceCalled('Repository', 'HDP-UTILS-2.2.0.1-885',
-                              base_url='http://s3.amazonaws.com/dev.hortonworks.com/HDP/centos5/2.x/updates/2.2.0.0',
+                              base_url=u'http://s3.amazonaws.com/dev.hortonworks.com/HDP/centos5/2.x/updates/2.2.0.0',
                               action=['create'],
                               components=[u'HDP-UTILS', 'main'],
-                              repo_template='repo_suse_rhel.j2',
+                              repo_template=u'repo_suse_rhel.j2',
                               repo_file_name='HDP-2.2.0.1-885',
                               mirror_list=None,
                               append_to_file=False,
@@ -111,8 +111,8 @@ class TestInstallPackages(RMFTestCase):
                               base_url='http://s3.amazonaws.com/dev.hortonworks.com/HDP/centos5/2.x/updates/2.2.0.0',
                               action=['create'],
                               components=[u'HDP', 'main'],
-                              repo_template='repo_suse_rhel.j2',
-                              repo_file_name='HDP-2.2.0.1-885',
+                              repo_template=u'repo_suse_rhel.j2',
+                              repo_file_name=u'HDP-2.2.0.1-885',
                               mirror_list=None,
                               append_to_file=True,
     )
@@ -162,20 +162,20 @@ class TestInstallPackages(RMFTestCase):
                        'installed_repository_version': u'2.2.0.1-885',
                        'ambari_repositories': []})
     self.assertResourceCalled('Repository', 'HDP-UTILS-2.2.0.1-885',
-                              base_url='http://s3.amazonaws.com/dev.hortonworks.com/HDP/centos5/2.x/updates/2.2.0.0',
+                              base_url=u'http://s3.amazonaws.com/dev.hortonworks.com/HDP/centos5/2.x/updates/2.2.0.0',
                               action=['create'],
                               components=[u'HDP-UTILS', 'main'],
-                              repo_template='repo_suse_rhel.j2',
-                              repo_file_name='HDP-2.2.0.1-885',
+                              repo_template=u'repo_suse_rhel.j2',
+                              repo_file_name=u'HDP-2.2.0.1-885',
                               mirror_list=None,
                               append_to_file=False,
                               )
     self.assertResourceCalled('Repository', 'HDP-2.2.0.1-885',
-                              base_url='http://s3.amazonaws.com/dev.hortonworks.com/HDP/centos5/2.x/updates/2.2.0.0',
+                              base_url=u'http://s3.amazonaws.com/dev.hortonworks.com/HDP/centos5/2.x/updates/2.2.0.0',
                               action=['create'],
                               components=[u'HDP', 'main'],
-                              repo_template='repo_suse_rhel.j2',
-                              repo_file_name='HDP-2.2.0.1-885',
+                              repo_template=u'repo_suse_rhel.j2',
+                              repo_file_name=u'HDP-2.2.0.1-885',
                               mirror_list=None,
                               append_to_file=True,
                               )

http://git-wip-us.apache.org/repos/asf/ambari/blob/11763dca/ambari-server/src/test/python/unitTests.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/unitTests.py b/ambari-server/src/test/python/unitTests.py
index 7c9f089..e812b83 100644
--- a/ambari-server/src/test/python/unitTests.py
+++ b/ambari-server/src/test/python/unitTests.py
@@ -202,28 +202,35 @@ def main():
   for test_dir, msg in test_dirs:
     sys.stderr.write(msg)
     tests = get_test_files(test_dir, mask=test_mask, recursive=False)
-    #TODO Add an option to randomize the tests' execution
-    #shuffle(tests)
+
+    # TODO Add an option to randomize the tests' execution
+    # shuffle(tests)
+
     modules = [os.path.basename(s)[:-3] for s in tests]
-    suites = [unittest.defaultTestLoader.loadTestsFromName(name) for name in
-      modules]
+    suites = [unittest.defaultTestLoader.loadTestsFromName(name) for name in modules]
     testSuite = unittest.TestSuite(suites)
     textRunner = unittest.TextTestRunner(verbosity=2).run(testSuite)
     test_runs += textRunner.testsRun
+
     test_errors.extend(
       [(str(item[0]), str(item[1]), "ERROR") for item in textRunner.errors])
+
     test_failures.extend(
       [(str(item[0]), str(item[1]), "FAIL") for item in textRunner.failures])
-    tests_status = textRunner.wasSuccessful() and not has_failures
 
-  if not tests_status:
+  if len(test_errors) > 0 or len(test_failures) > 0:
+    has_failures = True
+
+  if has_failures:
     sys.stderr.write("----------------------------------------------------------------------\n")
     sys.stderr.write("Failed tests:\n")
-  for failed_tests in [test_errors,test_failures]:
-    for err in failed_tests:
-      sys.stderr.write("{0}: {1}\n".format(err[2],err[0]))
-      sys.stderr.write("----------------------------------------------------------------------\n")
-      sys.stderr.write("{0}\n".format(err[1]))
+
+    for failed_tests in [test_errors,test_failures]:
+      for err in failed_tests:
+        sys.stderr.write("{0}: {1}\n".format(err[2],err[0]))
+        sys.stderr.write("----------------------------------------------------------------------\n")
+        sys.stderr.write("{0}\n".format(err[1]))
+
   sys.stderr.write("----------------------------------------------------------------------\n")
   sys.stderr.write("Total run:{0}\n".format(test_runs))
   sys.stderr.write("Total errors:{0}\n".format(len(test_errors)))
@@ -233,12 +240,13 @@ def main():
   tempfile.tempdir = oldtmpdirpath
   tempfile.oldtmpdirpath = None
 
-  if tests_status:
+  if not has_failures:
     sys.stderr.write("OK\n")
     exit_code = 0
   else:
     sys.stderr.write("ERROR\n")
     exit_code = 1
+
   return exit_code