|
@@ -21,6 +21,9 @@ from ambari_commons import OSCheck
|
|
|
from ambari_commons import OSCheck
|
|
|
from mock.mock import MagicMock, patch
|
|
|
from stacks.utils.RMFTestCase import *
|
|
|
+import resource_management
|
|
|
+
|
|
|
+import subprocess
|
|
|
|
|
|
|
|
|
@patch.object(OSCheck,"get_os_type", new = MagicMock(return_value='suse'))
|
|
@@ -451,10 +454,42 @@ class TestNamenode(RMFTestCase):
|
|
|
recursive = True,
|
|
|
mode = 0755,
|
|
|
)
|
|
|
-# def test_rebalance_hdfs(self): ##Does not work because of exectuteScript Framework does not works with strcuturedoutput
|
|
|
-# self.executeScript("2.0.6/services/HDFS/package/scripts/namenode.py",
|
|
|
-# classname = "NameNode",
|
|
|
-# command = "rebalancehdfs",
|
|
|
-# config_file="rebalancehdfs_default.json"
|
|
|
-# )
|
|
|
+
|
|
|
+ @patch("resource_management.libraries.script.Script.put_structured_out")
|
|
|
+ def test_rebalance_hdfs(self, pso):
|
|
|
+ Popen_Mock.return_value = 1
|
|
|
+ with patch("subprocess.Popen", new_callable=Popen_Mock):
|
|
|
+ ll = subprocess.Popen()
|
|
|
+ self.assertTrue(isinstance(ll.stdout.readline(),str))
|
|
|
+ try:
|
|
|
+ self.executeScript("2.0.6/services/HDFS/package/scripts/namenode.py",
|
|
|
+ classname = "NameNode",
|
|
|
+ command = "rebalancehdfs",
|
|
|
+ config_file="rebalancehdfs_default.json"
|
|
|
+ )
|
|
|
+ self.fail("Exception was not thrown")
|
|
|
+ except resource_management.core.exceptions.Fail:
|
|
|
+ pass ##expected
|
|
|
+
|
|
|
+ pso.reset_mock()
|
|
|
+ Popen_Mock.return_value = 0
|
|
|
+ ll = subprocess.Popen()
|
|
|
+ self.assertTrue(isinstance(ll.stdout.readline(),str))
|
|
|
+ self.executeScript("2.0.6/services/HDFS/package/scripts/namenode.py",
|
|
|
+ classname = "NameNode",
|
|
|
+ command = "rebalancehdfs",
|
|
|
+ config_file="rebalancehdfs_default.json"
|
|
|
+ )
|
|
|
+ self.assertEqual(pso.call_count, 2, "Output was not parsed properly")
|
|
|
|
|
|
+class Popen_Mock:
|
|
|
+ return_value = 1
|
|
|
+ lines = ['Time Stamp Iteration# Bytes Already Moved Bytes Left To Move Bytes Being Moved\n',
|
|
|
+ 'Jul 28, 2014 5:01:49 PM 0 0 B 5.74 GB 9.79 GB\n',
|
|
|
+ 'Jul 28, 2014 5:03:00 PM 1 0 B 5.58 GB 9.79 GB\n',
|
|
|
+ '']
|
|
|
+ def __call__(self, *args,**kwargs):
|
|
|
+ popen = MagicMock()
|
|
|
+ popen.returncode = Popen_Mock.return_value
|
|
|
+ popen.stdout.readline = MagicMock(side_effect = Popen_Mock.lines)
|
|
|
+ return popen
|