You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by fb...@apache.org on 2015/07/22 22:37:22 UTC
ambari git commit: AMBARI-12204 Windows unit tests: Agent unit tests:
adapt the existing unit tests to Windows
Repository: ambari
Updated Branches:
refs/heads/trunk b5c303ac5 -> e39eca7e0
AMBARI-12204 Windows unit tests: Agent unit tests: adapt the existing unit tests to Windows
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/e39eca7e
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/e39eca7e
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/e39eca7e
Branch: refs/heads/trunk
Commit: e39eca7e06d8c8b06df86e7c18dbdccead207e19
Parents: b5c303a
Author: Florian Barca <fb...@hortonworks.com>
Authored: Tue Jul 21 12:59:57 2015 -0700
Committer: Florian Barca <fb...@hortonworks.com>
Committed: Wed Jul 22 13:35:54 2015 -0700
----------------------------------------------------------------------
.../test/python/ambari_agent/TestActionQueue.py | 27 ++++++++++++++------
.../TestClusterConfigurationCache.py | 11 +++++---
.../src/test/python/ambari_agent/TestMain.py | 17 ++++++++++--
ambari-agent/src/test/python/unitTests.py | 15 ++++++++---
4 files changed, 53 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/e39eca7e/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py b/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py
index 5a22843..6e22bf8 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py
@@ -40,6 +40,8 @@ from ambari_agent.FileCache import FileCache
from ambari_commons import OSCheck
from only_for_platform import not_for_platform, os_distro_value, PLATFORM_WINDOWS
+import logging
+
class TestActionQueue(TestCase):
def setUp(self):
# save original open() method for later use
@@ -49,6 +51,8 @@ class TestActionQueue(TestCase):
def tearDown(self):
sys.stdout = sys.__stdout__
+ logger = logging.getLogger()
+
datanode_install_command = {
'commandType': 'EXECUTION_COMMAND',
'role': u'DATANODE',
@@ -253,7 +257,7 @@ class TestActionQueue(TestCase):
actionQueue.stop()
actionQueue.join()
self.assertEqual(actionQueue.stopped(), True, 'Action queue is not stopped.')
- self.assertTrue(process_command_mock.call_count > 1)
+ self.assertGreater(process_command_mock.call_count, 1)
@patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@@ -372,9 +376,12 @@ class TestActionQueue(TestCase):
# Continue command execution
unfreeze_flag.set()
# wait until ready
- while actionQueue.tasks_in_progress_or_pending():
- time.sleep(0.1)
+ check_queue = True
+ while check_queue:
report = actionQueue.result()
+ if not actionQueue.tasks_in_progress_or_pending():
+ break
+ time.sleep(0.1)
self.assertEqual(len(report['reports']), 0)
@@ -388,10 +395,11 @@ class TestActionQueue(TestCase):
unfreeze_flag.set()
# check in progress report
# wait until ready
- report = actionQueue.result()
- while actionQueue.tasks_in_progress_or_pending():
- time.sleep(0.1)
+ while check_queue:
report = actionQueue.result()
+ if not actionQueue.tasks_in_progress_or_pending():
+ break
+ time.sleep(0.1)
self.assertEqual(len(report['reports']), 0)
@@ -839,7 +847,11 @@ class TestActionQueue(TestCase):
'structuredOut': '',
'status': 'FAILED'
}
- time_mock.side_effect = [4, 8, 10, 14, 18, 22]
+
+ times_arr = [8, 10, 14, 18, 22]
+ if self.logger.isEnabledFor(logging.INFO):
+ times_arr.insert(0, 4)
+ time_mock.side_effect = times_arr
def side_effect(command, tmpoutfile, tmperrfile, override_output_files=True, retry=False):
return python_execution_result_dict
@@ -954,7 +966,6 @@ class TestActionQueue(TestCase):
report = actionQueue.result()
self.assertEqual(len(report['reports']),1)
- @not_for_platform(PLATFORM_WINDOWS)
@patch.object(CustomServiceOrchestrator, "get_py_executor")
@patch.object(CustomServiceOrchestrator, "resolve_script_path")
@patch.object(StackVersionsFileHandler, "read_stack_version")
http://git-wip-us.apache.org/repos/asf/ambari/blob/e39eca7e/ambari-agent/src/test/python/ambari_agent/TestClusterConfigurationCache.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestClusterConfigurationCache.py b/ambari-agent/src/test/python/ambari_agent/TestClusterConfigurationCache.py
index bd754b2..e82fca2 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestClusterConfigurationCache.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestClusterConfigurationCache.py
@@ -18,6 +18,7 @@ See the License for the specific language governing permissions and
limitations under the License.
'''
+import os
import sys
from ambari_agent.ClusterConfiguration import ClusterConfiguration
@@ -42,9 +43,9 @@ class TestClusterConfigurationCache(TestCase):
open_mock = mock_open(read_data=configuration_json)
with patch("__builtin__.open", open_mock):
- cluster_configuration = ClusterConfiguration("/foo/bar/baz")
+ cluster_configuration = ClusterConfiguration(os.path.join(os.sep, "foo", "bar", "baz"))
- open_mock.assert_called_with("/foo/bar/baz/configurations.json", 'r')
+ open_mock.assert_called_with(os.sep + "foo" + os.sep + "bar" + os.sep + "baz" + os.sep + "configurations.json", 'r')
self.assertEqual('bar', cluster_configuration.get_configuration_value('c1', 'foo-site/foo') )
self.assertEqual('baz', cluster_configuration.get_configuration_value('c1', 'foo-site/foobar') )
@@ -52,6 +53,7 @@ class TestClusterConfigurationCache(TestCase):
self.assertEqual(None, cluster_configuration.get_configuration_value('c1', 'INVALID/INVALID') )
self.assertEqual(None, cluster_configuration.get_configuration_value('INVALID', 'foo-site/foo') )
self.assertEqual(None, cluster_configuration.get_configuration_value('INVALID', 'foo-site/foobar') )
+ pass
@patch("ambari_simplejson.dump")
@@ -63,9 +65,10 @@ class TestClusterConfigurationCache(TestCase):
}
file_mock = self.__update_cluster_configuration(cluster_configuration, configuration)
- file_mock.assert_called_with('/foo/bar/baz/configurations.json', 'w')
+ file_mock.assert_called_with(os.sep + "foo" + os.sep + "bar" + os.sep + "baz" + os.sep + "configurations.json", 'w')
json_dump_mock.assert_called_with({'c1': {'foo-site': {'baz': 'rendered-baz', 'bar': 'rendered-bar'}}}, ANY, indent=2)
+ pass
def __get_cluster_configuration(self):
"""
@@ -75,7 +78,7 @@ class TestClusterConfigurationCache(TestCase):
"""
with patch("__builtin__.open") as open_mock:
open_mock.side_effect = self.open_side_effect
- cluster_configuration = ClusterConfiguration("/foo/bar/baz")
+ cluster_configuration = ClusterConfiguration(os.path.join(os.sep, "foo", "bar", "baz"))
return cluster_configuration
http://git-wip-us.apache.org/repos/asf/ambari/blob/e39eca7e/ambari-agent/src/test/python/ambari_agent/TestMain.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestMain.py b/ambari-agent/src/test/python/ambari_agent/TestMain.py
index 7a3dc71..6218b59 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestMain.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestMain.py
@@ -28,6 +28,7 @@ import tempfile
import ConfigParser
from ambari_commons import OSCheck
+from ambari_commons.os_family_impl import OsFamilyFuncImpl, OsFamilyImpl
from only_for_platform import get_platform, not_for_platform, os_distro_value, PLATFORM_WINDOWS
from mock.mock import MagicMock, patch, ANY, Mock
@@ -283,6 +284,16 @@ class TestMain(unittest.TestCase):
self.assertTrue(sys_exit_mock.called)
+ @OsFamilyFuncImpl(OSConst.WINSRV_FAMILY)
+ def init_ambari_config_mock(self):
+ return os.path.normpath(
+ os.path.join(os.path.dirname(__file__), "..", "..", "..", "..", "conf", "windows", "ambari-agent.ini"))
+
+ @OsFamilyFuncImpl(OsFamilyImpl.DEFAULT)
+ def init_ambari_config_mock(self):
+ return os.path.normpath(
+ os.path.join(os.path.dirname(__file__), "..", "..", "..", "..", "conf", "unix", "ambari-agent.ini"))
+
@patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@patch.object(socket, "gethostbyname")
@patch.object(main, "setup_logging")
@@ -315,7 +326,7 @@ class TestMain(unittest.TestCase):
parse_args_mock.return_value = (options, MagicMock)
try_to_connect_mock.return_value = (0, True)
# use default unix config
- ambari_config_mock.return_value = os.path.abspath("../../../conf/unix/ambari-agent.ini")
+ ambari_config_mock.return_value = self.init_ambari_config_mock()
#testing call without command-line arguments
main.main()
@@ -335,10 +346,12 @@ class TestMain(unittest.TestCase):
self.assertTrue(data_clean_start_mock.called)
self.assertTrue(ping_port_init_mock.called)
self.assertTrue(ping_port_start_mock.called)
- self.assertTrue(cleanup_mock.called)
+ if not OSCheck.get_os_family() == OSConst.WINSRV_FAMILY:
+ self.assertTrue(cleanup_mock.called)
perform_prestart_checks_mock.reset_mock()
# Testing call with --expected-hostname parameter
options.expected_hostname = "test.hst"
main.main()
perform_prestart_checks_mock.assert_called_once_with(options.expected_hostname)
+ pass
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/e39eca7e/ambari-agent/src/test/python/unitTests.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/unitTests.py b/ambari-agent/src/test/python/unitTests.py
index a7763be..ba8bc6e 100644
--- a/ambari-agent/src/test/python/unitTests.py
+++ b/ambari-agent/src/test/python/unitTests.py
@@ -154,9 +154,18 @@ def main():
if __name__ == '__main__':
import os
import sys
- sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
- sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + os.sep + 'main' + os.sep + 'python')
- sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + os.sep + 'main' + os.sep + 'python' + os.sep + 'ambari_agent')
+
+ pwd = os.path.abspath(__file__)
+ ambari_agent_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(pwd))))
+ src_dir = os.path.dirname(ambari_agent_dir)
+ ambari_common_dir = os.path.join(src_dir, "ambari-common")
+
+ sys.path.insert(0, os.path.join(ambari_agent_dir, "src", "main", "python"))
+ sys.path.insert(0, os.path.join(ambari_agent_dir, "src", "main", "python", "ambari_agent"))
+ sys.path.insert(0, os.path.join(ambari_common_dir, "src", "main", "python"))
+ sys.path.insert(0, os.path.join(ambari_common_dir, "src", "main", "python", "ambari_jinja2"))
+ sys.path.insert(0, os.path.join(ambari_common_dir, "src", "test", "python"))
+
logger = logging.getLogger()
logger.setLevel(logging.INFO)
formatter = logging.Formatter("[%(levelname)s] %(message)s")