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/01/06 02:15:14 UTC
ambari git commit: AMBARI-8933 Ambari Agent Component Cannot Run
Tests on OSX
Repository: ambari
Updated Branches:
refs/heads/trunk 685f9dd73 -> 2c9820f69
AMBARI-8933 Ambari Agent Component Cannot Run Tests on OSX
Updated the mocks + a few missing OS-dependent implementations
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/2c9820f6
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/2c9820f6
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/2c9820f6
Branch: refs/heads/trunk
Commit: 2c9820f694bb54cfbf109824f5b7c793f0da1fc9
Parents: 685f9dd
Author: Florian Barca <fb...@hortonworks.com>
Authored: Mon Jan 5 17:15:04 2015 -0800
Committer: Florian Barca <fb...@hortonworks.com>
Committed: Mon Jan 5 17:15:04 2015 -0800
----------------------------------------------------------------------
.../src/main/python/ambari_agent/HostCleanup.py | 14 ++++++++++++--
.../src/test/python/ambari_agent/TestActionQueue.py | 6 ++++++
.../python/ambari_agent/TestActualConfigHandler.py | 16 +++++++++++++++-
.../test/python/ambari_agent/TestCertGeneration.py | 9 +++++++++
.../ambari_agent/TestCustomServiceOrchestrator.py | 9 +++++++++
.../src/test/python/ambari_agent/TestDataCleaner.py | 8 ++++++++
.../src/test/python/ambari_agent/TestHostname.py | 12 ++++++++++--
.../src/test/python/ambari_agent/TestLiveStatus.py | 11 ++++++++++-
.../src/test/python/ambari_agent/TestMain.py | 3 +++
.../src/test/python/ambari_agent/TestNetUtil.py | 10 +++++++++-
.../test/python/ambari_agent/TestPythonExecutor.py | 12 ++++++++++++
.../src/test/python/ambari_agent/TestSecurity.py | 9 +++++++++
12 files changed, 112 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/2c9820f6/ambari-agent/src/main/python/ambari_agent/HostCleanup.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/HostCleanup.py b/ambari-agent/src/main/python/ambari_agent/HostCleanup.py
index 35e7b51..a128dad 100644
--- a/ambari-agent/src/main/python/ambari_agent/HostCleanup.py
+++ b/ambari-agent/src/main/python/ambari_agent/HostCleanup.py
@@ -18,6 +18,8 @@ See the License for the specific language governing permissions and
limitations under the License.
'''
import sys
+from ambari_commons.os_family_impl import OsFamilyImpl, OsFamilyFuncImpl
+
# For compatibility with different OSes
# Edit PYTHONPATH to be able to import common_functions
sys.path.append("/usr/lib/python2.6/site-packages/")
@@ -34,8 +36,6 @@ import shlex
import datetime
from AmbariConfig import AmbariConfig
from ambari_commons import OSCheck, OSConst
-if OSCheck.get_os_family() != OSConst.WINSRV_FAMILY:
- from pwd import getpwnam
logger = logging.getLogger()
@@ -423,7 +423,17 @@ class HostCleanup:
self.do_erase_dir_silent([fileToCheck])
logger.info("Deleting file/folder: " + fileToCheck)
+ @OsFamilyFuncImpl(os_family=OSConst.WINSRV_FAMILY)
def get_user_ids(self, userList):
+
+ userIds = []
+ # No user ids to check in Windows for now
+ return userIds
+
+ @OsFamilyFuncImpl(os_family=OsFamilyImpl.DEFAULT)
+ def get_user_ids(self, userList):
+ from pwd import getpwnam
+
userIds = []
if userList:
for user in userList:
http://git-wip-us.apache.org/repos/asf/ambari/blob/2c9820f6/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 53cad62..6c14e33 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestActionQueue.py
@@ -222,6 +222,7 @@ class TestActionQueue(TestCase):
self.assertTrue(process_command_mock.call_count > 1)
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@patch("traceback.print_exc")
@patch.object(ActionQueue, "execute_command")
@patch.object(ActionQueue, "execute_status_command")
@@ -441,6 +442,7 @@ class TestActionQueue(TestCase):
self.assertEqual(len(report['reports']), 0)
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@patch.object(CustomServiceOrchestrator, "runCommand")
@patch("CommandStatusDict.CommandStatusDict")
@patch.object(ActionQueue, "status_update_callback")
@@ -481,6 +483,7 @@ class TestActionQueue(TestCase):
self.assertEqual(len(report['reports']), 1)
self.assertEqual(expected, report['reports'][0])
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@patch.object(ActualConfigHandler, "write_client_components")
@patch.object(CustomServiceOrchestrator, "runCommand")
@patch("CommandStatusDict.CommandStatusDict")
@@ -523,6 +526,7 @@ class TestActionQueue(TestCase):
self.assertEqual(expected, report['reports'][0])
self.assertFalse(write_client_components_mock.called)
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@patch.object(ActionQueue, "status_update_callback")
@patch.object(StackVersionsFileHandler, "read_stack_version")
@patch.object(CustomServiceOrchestrator, "requestComponentStatus")
@@ -555,6 +559,7 @@ class TestActionQueue(TestCase):
self.assertEqual(report['componentStatus'][0], expected)
self.assertTrue(requestComponentStatus_mock.called)
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@patch.object(ActionQueue, "status_update_callback")
@patch.object(StackVersionsFileHandler, "read_stack_version")
@patch.object(CustomServiceOrchestrator, "requestComponentStatus")
@@ -627,6 +632,7 @@ class TestActionQueue(TestCase):
actionQueue.join()
self.assertEqual(actionQueue.stopped(), True, 'Action queue is not stopped.')
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@patch.object(StackVersionsFileHandler, "read_stack_version")
@patch.object(CustomServiceOrchestrator, "runCommand")
@patch.object(CustomServiceOrchestrator, "__init__")
http://git-wip-us.apache.org/repos/asf/ambari/blob/2c9820f6/ambari-agent/src/test/python/ambari_agent/TestActualConfigHandler.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestActualConfigHandler.py b/ambari-agent/src/test/python/ambari_agent/TestActualConfigHandler.py
index 166fd57..7f88e17 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestActualConfigHandler.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestActualConfigHandler.py
@@ -21,8 +21,15 @@ import tempfile
from unittest import TestCase
import os
import logging
-from mock.mock import patch
+from mock.mock import patch, MagicMock, call
from ambari_agent.LiveStatus import LiveStatus
+from ambari_commons import OSCheck
+from only_for_platform import only_for_platform, get_platform, PLATFORM_LINUX, PLATFORM_WINDOWS
+
+if get_platform() != PLATFORM_WINDOWS:
+ os_distro_value = ('Suse','11','Final')
+else:
+ os_distro_value = ('win2012serverr2','6.3','WindowsServer')
with patch("platform.linux_distribution", return_value = ('Suse','11','Final')):
from ambari_agent.AmbariConfig import AmbariConfig
@@ -132,6 +139,7 @@ class TestActualConfigHandler(TestCase):
logger = logging.getLogger()
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
def test_read_write(self):
config = AmbariConfig().getConfig()
tmpdir = tempfile.gettempdir()
@@ -144,6 +152,7 @@ class TestActualConfigHandler(TestCase):
self.assertEquals(tags, output)
os.remove(os.path.join(tmpdir, ActualConfigHandler.CONFIG_NAME))
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
def test_read_empty(self):
config = AmbariConfig().getConfig()
tmpdir = tempfile.gettempdir()
@@ -158,6 +167,7 @@ class TestActualConfigHandler(TestCase):
self.assertEquals(None, output)
os.remove(os.path.join(tmpdir, ActualConfigHandler.CONFIG_NAME))
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
def test_read_write_component(self):
config = AmbariConfig().getConfig()
tmpdir = tempfile.gettempdir()
@@ -184,6 +194,7 @@ class TestActualConfigHandler(TestCase):
os.remove(os.path.join(tmpdir, "FOO_" + ActualConfigHandler.CONFIG_NAME))
os.remove(os.path.join(tmpdir, ActualConfigHandler.CONFIG_NAME))
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
def test_write_actual_component_and_client_components(self):
config = AmbariConfig().getConfig()
tmpdir = tempfile.gettempdir()
@@ -208,6 +219,7 @@ class TestActualConfigHandler(TestCase):
os.remove(os.path.join(tmpdir, "HBASE_CLIENT_" + ActualConfigHandler.CONFIG_NAME))
os.remove(os.path.join(tmpdir, "HDFS_CLIENT_" + ActualConfigHandler.CONFIG_NAME))
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@patch.object(ActualConfigHandler, "write_file")
def test_write_client_components(self, write_file_mock):
config = AmbariConfig().getConfig()
@@ -228,6 +240,7 @@ class TestActualConfigHandler(TestCase):
self.assertTrue(write_file_mock.called)
self.assertEqual(1, write_file_mock.call_count)
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@patch.object(ActualConfigHandler, "write_file")
def test_write_empty_client_components(self, write_file_mock):
config = AmbariConfig().getConfig()
@@ -247,6 +260,7 @@ class TestActualConfigHandler(TestCase):
self.assertEquals(tags1, handler.read_actual_component('HBASE_CLIENT'))
self.assertFalse(write_file_mock.called)
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@patch.object(ActualConfigHandler, "write_file")
@patch.object(ActualConfigHandler, "read_file")
def test_read_actual_component_inmemory(self, read_file_mock, write_file_mock):
http://git-wip-us.apache.org/repos/asf/ambari/blob/2c9820f6/ambari-agent/src/test/python/ambari_agent/TestCertGeneration.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestCertGeneration.py b/ambari-agent/src/test/python/ambari_agent/TestCertGeneration.py
index c724c31..d188dbd 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestCertGeneration.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestCertGeneration.py
@@ -25,8 +25,17 @@ import ConfigParser
import security
from security import CertificateManager
from ambari_agent import AmbariConfig
+from mock.mock import patch, MagicMock
+from ambari_commons import OSCheck
+from only_for_platform import only_for_platform, get_platform, PLATFORM_LINUX, PLATFORM_WINDOWS
+
+if get_platform() != PLATFORM_WINDOWS:
+ os_distro_value = ('Suse','11','Final')
+else:
+ os_distro_value = ('win2012serverr2','6.3','WindowsServer')
class TestCertGeneration(TestCase):
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
config = AmbariConfig.AmbariConfig()
http://git-wip-us.apache.org/repos/asf/ambari/blob/2c9820f6/ambari-agent/src/test/python/ambari_agent/TestCustomServiceOrchestrator.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestCustomServiceOrchestrator.py b/ambari-agent/src/test/python/ambari_agent/TestCustomServiceOrchestrator.py
index f9c94b0..811cf26 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestCustomServiceOrchestrator.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestCustomServiceOrchestrator.py
@@ -41,8 +41,13 @@ from FileCache import FileCache
from LiveStatus import LiveStatus
from BackgroundCommandExecutionHandle import BackgroundCommandExecutionHandle
from ambari_agent.ActionQueue import ActionQueue
+from ambari_commons import OSCheck
from only_for_platform import get_platform, PLATFORM_WINDOWS
+if get_platform() != PLATFORM_WINDOWS:
+ os_distro_value = ('Suse','11','Final')
+else:
+ os_distro_value = ('win2012serverr2','6.3','WindowsServer')
class TestCustomServiceOrchestrator(TestCase):
@@ -62,6 +67,7 @@ class TestCustomServiceOrchestrator(TestCase):
self.config.set('python', 'custom_actions_dir', tmpdir)
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@patch.object(FileCache, "__init__")
def test_add_reg_listener_to_controller(self, FileCache_mock):
FileCache_mock.return_value = None
@@ -73,6 +79,7 @@ class TestCustomServiceOrchestrator(TestCase):
self.assertTrue(dummy_controller.registration_listeners.append.called)
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@patch.object(CustomServiceOrchestrator, 'decompressClusterHostInfo')
@patch("hostname.public_hostname")
@patch("os.path.isfile")
@@ -136,6 +143,7 @@ class TestCustomServiceOrchestrator(TestCase):
self.assertTrue(unlink_mock.called)
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@patch("os.path.exists")
@patch.object(FileCache, "__init__")
def test_resolve_script_path(self, FileCache_mock, exists_mock):
@@ -325,6 +333,7 @@ class TestCustomServiceOrchestrator(TestCase):
from ambari_agent.StackVersionsFileHandler import StackVersionsFileHandler
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@patch("ambari_commons.shell.kill_process_with_children")
@patch.object(FileCache, "__init__")
@patch.object(CustomServiceOrchestrator, "resolve_script_path")
http://git-wip-us.apache.org/repos/asf/ambari/blob/2c9820f6/ambari-agent/src/test/python/ambari_agent/TestDataCleaner.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestDataCleaner.py b/ambari-agent/src/test/python/ambari_agent/TestDataCleaner.py
index 0ec6b69..3ecb46a 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestDataCleaner.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestDataCleaner.py
@@ -24,6 +24,13 @@ from mock.mock import patch, MagicMock, call, Mock
from ambari_agent import DataCleaner
import AmbariConfig
import os
+from ambari_commons import OSCheck
+from only_for_platform import only_for_platform, get_platform, PLATFORM_LINUX, PLATFORM_WINDOWS
+
+if get_platform() != PLATFORM_WINDOWS:
+ os_distro_value = ('Suse','11','Final')
+else:
+ os_distro_value = ('win2012serverr2','6.3','WindowsServer')
class TestDataCleaner(unittest.TestCase):
@@ -42,6 +49,7 @@ class TestDataCleaner(unittest.TestCase):
cleaner = DataCleaner.DataCleaner(config)
self.assertFalse(DataCleaner.logger.warn.called)
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
def test_config(self):
"""
Verify that if the config does not have a property, default values are used.
http://git-wip-us.apache.org/repos/asf/ambari/blob/2c9820f6/ambari-agent/src/test/python/ambari_agent/TestHostname.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestHostname.py b/ambari-agent/src/test/python/ambari_agent/TestHostname.py
index 5dbd095..87c69b8 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestHostname.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestHostname.py
@@ -26,11 +26,18 @@ import socket
import tempfile
import shutil
import os, pprint, json,stat
-from mock.mock import patch
-from only_for_platform import only_for_platform, PLATFORM_LINUX
+from mock.mock import patch, MagicMock
+from ambari_commons import OSCheck
+from only_for_platform import only_for_platform, get_platform, PLATFORM_LINUX, PLATFORM_WINDOWS
+
+if get_platform() != PLATFORM_WINDOWS:
+ os_distro_value = ('Suse','11','Final')
+else:
+ os_distro_value = ('win2012serverr2','6.3','WindowsServer')
class TestHostname(TestCase):
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
def test_hostname(self):
hostname.cached_hostname = None
hostname.cached_public_hostname = None
@@ -87,6 +94,7 @@ class TestHostname(TestCase):
config.remove_option('agent', 'public_hostname_script')
pass
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@patch.object(socket, "getfqdn")
def test_caching(self, getfqdn_mock):
hostname.cached_hostname = None
http://git-wip-us.apache.org/repos/asf/ambari/blob/2c9820f6/ambari-agent/src/test/python/ambari_agent/TestLiveStatus.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestLiveStatus.py b/ambari-agent/src/test/python/ambari_agent/TestLiveStatus.py
index a080d49..24fad3c 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestLiveStatus.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestLiveStatus.py
@@ -23,9 +23,16 @@ from ambari_agent.LiveStatus import LiveStatus
from ambari_agent.AmbariConfig import AmbariConfig
import os, sys, StringIO
from ambari_agent import ActualConfigHandler
-from mock.mock import patch
+from mock.mock import patch, MagicMock
import pprint
from ambari_agent import StatusCheck
+from ambari_commons import OSCheck
+from only_for_platform import only_for_platform, get_platform, PLATFORM_LINUX, PLATFORM_WINDOWS
+
+if get_platform() != PLATFORM_WINDOWS:
+ os_distro_value = ('Suse','11','Final')
+else:
+ os_distro_value = ('win2012serverr2','6.3','WindowsServer')
class TestLiveStatus(TestCase):
@@ -137,6 +144,7 @@ class TestLiveStatus(TestCase):
# enable stdout
sys.stdout = sys.__stdout__
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@patch.object(ActualConfigHandler.ActualConfigHandler, "read_actual_component")
def test_build(self, read_actual_component_mock):
for component in LiveStatus.COMPONENTS:
@@ -174,6 +182,7 @@ class TestLiveStatus(TestCase):
self.assertTrue(len(result) > 0, 'Livestatus should not be empty')
self.assertTrue(result['status'], LiveStatus.LIVE_STATUS)
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@patch.object(ActualConfigHandler.ActualConfigHandler, "read_actual_component")
@patch.object(StatusCheck.StatusCheck, "getStatus")
def test_build_predefined(self, getStatus_mock, read_actual_component_mock):
http://git-wip-us.apache.org/repos/asf/ambari/blob/2c9820f6/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 19966e7..3cf36f5 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestMain.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestMain.py
@@ -97,6 +97,7 @@ class TestMain(unittest.TestCase):
setLevel_mock.assert_called_with(logging.DEBUG)
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@patch.object(main.logger, "setLevel")
@patch("logging.basicConfig")
def test_update_log_level(self, basicConfig_mock, setLevel_mock):
@@ -155,6 +156,7 @@ class TestMain(unittest.TestCase):
self.assertFalse(read_mock.called)
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@patch("sys.exit")
@patch("os.path.isfile")
@patch("os.path.isdir")
@@ -275,6 +277,7 @@ class TestMain(unittest.TestCase):
self.assertTrue(True)
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@patch.object(socket, "gethostbyname")
@patch.object(main, "setup_logging")
@patch.object(main, "bind_signal_handlers")
http://git-wip-us.apache.org/repos/asf/ambari/blob/2c9820f6/ambari-agent/src/test/python/ambari_agent/TestNetUtil.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestNetUtil.py b/ambari-agent/src/test/python/ambari_agent/TestNetUtil.py
index 287ea3c..3d8083b 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestNetUtil.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestNetUtil.py
@@ -22,9 +22,17 @@ from ambari_agent import NetUtil
from mock.mock import MagicMock, patch
import unittest
import threading
-from only_for_platform import only_for_platform, PLATFORM_LINUX
+from ambari_commons import OSCheck
+from only_for_platform import only_for_platform, get_platform, PLATFORM_LINUX, PLATFORM_WINDOWS
+
+if get_platform() != PLATFORM_WINDOWS:
+ os_distro_value = ('Suse','11','Final')
+else:
+ os_distro_value = ('win2012serverr2','6.3','WindowsServer')
+
class TestNetUtil(unittest.TestCase):
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@patch("urlparse.urlparse")
@patch("httplib.HTTPSConnection")
def test_checkURL(self, httpsConMock, parseMock):
http://git-wip-us.apache.org/repos/asf/ambari/blob/2c9820f6/ambari-agent/src/test/python/ambari_agent/TestPythonExecutor.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestPythonExecutor.py b/ambari-agent/src/test/python/ambari_agent/TestPythonExecutor.py
index bd3a7f3..d3bcd31 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestPythonExecutor.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestPythonExecutor.py
@@ -29,9 +29,17 @@ from threading import Thread
from PythonExecutor import PythonExecutor
from AmbariConfig import AmbariConfig
from mock.mock import MagicMock, patch
+from ambari_commons import OSCheck
+from only_for_platform import only_for_platform, get_platform, PLATFORM_LINUX, PLATFORM_WINDOWS
+
+if get_platform() != PLATFORM_WINDOWS:
+ os_distro_value = ('Suse','11','Final')
+else:
+ os_distro_value = ('win2012serverr2','6.3','WindowsServer')
class TestPythonExecutor(TestCase):
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
@patch("ambari_commons.shell.kill_process_with_children")
def test_watchdog_1(self, kill_process_with_children_mock):
"""
@@ -65,6 +73,7 @@ class TestPythonExecutor(TestCase):
self.assertTrue(callback_method.called)
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
def test_watchdog_2(self):
"""
Tries to catch false positive watchdog invocations
@@ -98,6 +107,7 @@ class TestPythonExecutor(TestCase):
self.assertEquals(subproc_mock.returncode, 0, "Subprocess should not be terminated before timeout")
self.assertTrue(callback_method.called)
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
def test_execution_results(self):
subproc_mock = self.Subprocess_mockup()
executor = PythonExecutor("/tmp", AmbariConfig().getConfig())
@@ -129,6 +139,7 @@ class TestPythonExecutor(TestCase):
'structuredOut': {}})
self.assertTrue(callback_method.called)
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
def test_is_successfull(self):
executor = PythonExecutor("/tmp", AmbariConfig().getConfig())
@@ -141,6 +152,7 @@ class TestPythonExecutor(TestCase):
self.assertFalse(executor.isSuccessfull(1))
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
def test_python_command(self):
executor = PythonExecutor("/tmp", AmbariConfig().getConfig())
command = executor.python_command("script", ["script_param1"])
http://git-wip-us.apache.org/repos/asf/ambari/blob/2c9820f6/ambari-agent/src/test/python/ambari_agent/TestSecurity.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestSecurity.py b/ambari-agent/src/test/python/ambari_agent/TestSecurity.py
index d745864..52ddbdb 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestSecurity.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestSecurity.py
@@ -29,6 +29,14 @@ import ssl
import os
import tempfile
+from ambari_commons import OSCheck
+from only_for_platform import only_for_platform, get_platform, PLATFORM_LINUX, PLATFORM_WINDOWS
+
+if get_platform() != PLATFORM_WINDOWS:
+ os_distro_value = ('Suse','11','Final')
+else:
+ os_distro_value = ('win2012serverr2','6.3','WindowsServer')
+
with patch("platform.linux_distribution", return_value = ('Suse','11','Final')):
from ambari_agent import NetUtil
from ambari_agent.security import CertificateManager
@@ -40,6 +48,7 @@ with patch("platform.linux_distribution", return_value = ('Suse','11','Final')):
aa = mock.mock.mock_open()
class TestSecurity(unittest.TestCase):
+ @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
def setUp(self):
# disable stdout
out = StringIO.StringIO()