Forráskód Böngészése

AMBARI-10501. shell.call and shell.checked_call should be always mocked in RMFTestCase (aonishuk)

Andrew Onishuk 10 éve
szülő
commit
70fb033b77

+ 23 - 23
ambari-server/src/test/python/stacks/2.0.6/HDFS/test_datanode.py

@@ -459,9 +459,8 @@ class TestDatanode(RMFTestCase):
 
 
   @patch('time.sleep')
-  @patch.object(shell, "call")
-  def test_post_rolling_restart(self, process_mock, time_mock):
-    process_output = """
+  def test_post_rolling_restart(self, time_mock):
+    shell_call_output = """
       Live datanodes (2):
 
       Name: 192.168.64.102:50010 (c6401.ambari.apache.org)
@@ -481,57 +480,58 @@ class TestDatanode(RMFTestCase):
       Xceivers: 2
       Last contact: Fri Dec 12 20:47:21 UTC 2014
     """
-
-    process_mock.return_value = (0, process_output)
-
+    mocks_dict = {}
     self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/datanode.py",
                        classname = "DataNode",
                        command = "post_rolling_restart",
                        config_file = "default.json",
                        hdp_stack_version = self.STACK_VERSION,
-                       target = RMFTestCase.TARGET_COMMON_SERVICES
+                       target = RMFTestCase.TARGET_COMMON_SERVICES,
+                       call_mocks = [(0, shell_call_output)],
+                       mocks_dict = mocks_dict
     )
+    
+    self.assertTrue(mocks_dict['call'].called)
+    self.assertEqual(mocks_dict['call'].call_count,1)
 
-    self.assertTrue(process_mock.called)
-    self.assertEqual(process_mock.call_count,1)
 
 
   @patch('time.sleep')
-  @patch.object(shell, "call")
-  def test_post_rolling_restart_datanode_not_ready(self, process_mock, time_mock):
-    process_mock.return_value = (0, 'There are no DataNodes here!')
-
+  def test_post_rolling_restart_datanode_not_ready(self, time_mock):
+    mocks_dict = {}
     try:
       self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/datanode.py",
                          classname = "DataNode",
                          command = "post_rolling_restart",
                          config_file = "default.json",
                          hdp_stack_version = self.STACK_VERSION,
-                         target = RMFTestCase.TARGET_COMMON_SERVICES
+                         target = RMFTestCase.TARGET_COMMON_SERVICES,
+                         call_mocks = [(0, 'There are no DataNodes here!')],
+                         mocks_dict = mocks_dict
       )
       self.fail('Missing DataNode should have caused a failure')
     except Fail,fail:
-      self.assertTrue(process_mock.called)
-      self.assertEqual(process_mock.call_count,12)
+      self.assertTrue(mocks_dict['call'].called)
+      self.assertEqual(mocks_dict['call'].call_count,12)
 
 
   @patch('time.sleep')
-  @patch.object(shell, "call")
-  def test_post_rolling_restart_bad_returncode(self, process_mock, time_mock):
-    process_mock.return_value = (0, 'some')
-
+  def test_post_rolling_restart_bad_returncode(self, time_mock):
     try:
+      mocks_dict = {}
       self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/datanode.py",
                          classname = "DataNode",
                          command = "post_rolling_restart",
                          config_file = "default.json",
                          hdp_stack_version = self.STACK_VERSION,
-                         target = RMFTestCase.TARGET_COMMON_SERVICES
+                         target = RMFTestCase.TARGET_COMMON_SERVICES,
+                         call_mocks = [(0, 'some')],
+                         mocks_dict = mocks_dict
       )
       self.fail('Invalid return code should cause a failure')
     except Fail,fail:
-      self.assertTrue(process_mock.called)
-      self.assertEqual(process_mock.call_count,12)
+      self.assertTrue(mocks_dict['call'].called)
+      self.assertEqual(mocks_dict['call'].call_count,12)
 
   @patch("resource_management.libraries.functions.security_commons.build_expectations")
   @patch("resource_management.libraries.functions.security_commons.get_params_from_filesystem")

+ 9 - 13
ambari-server/src/test/python/stacks/2.0.6/HDFS/test_namenode.py

@@ -43,14 +43,14 @@ class TestNamenode(RMFTestCase):
     self.assert_configure_default()
     self.assertNoMoreResources()
 
-  @patch.object(shell, "call", new=MagicMock(return_value=(5,"")))
   def test_start_default_alt_fs(self):
     self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/namenode.py",
                        classname = "NameNode",
                        command = "start",
                        config_file = "altfs_plus_hdfs.json",
                        hdp_stack_version = self.STACK_VERSION,
-                       target = RMFTestCase.TARGET_COMMON_SERVICES
+                       target = RMFTestCase.TARGET_COMMON_SERVICES,
+                       call_mocks = [(5,"")],
     )
     self.assert_configure_default()
     self.assertResourceCalled('Execute', 'ls /hadoop/hdfs/namenode | wc -l  | grep -q ^0$',)
@@ -135,14 +135,14 @@ class TestNamenode(RMFTestCase):
     self.assertNoMoreResources()
     pass
 
-  @patch.object(shell, "call", new=MagicMock(return_value=(5,"")))
   def test_start_default(self):
     self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/namenode.py",
                        classname = "NameNode",
                        command = "start",
                        config_file = "default.json",
                        hdp_stack_version = self.STACK_VERSION,
-                       target = RMFTestCase.TARGET_COMMON_SERVICES
+                       target = RMFTestCase.TARGET_COMMON_SERVICES,
+                       call_mocks = [(5,"")],
     )
     self.assert_configure_default()
     self.assertResourceCalled('Execute', 'ls /hadoop/hdfs/namenode | wc -l  | grep -q ^0$',)
@@ -259,14 +259,14 @@ class TestNamenode(RMFTestCase):
     self.assertNoMoreResources()
 
 
-  @patch.object(shell, "call", new=MagicMock(return_value=(5,"")))
   def test_start_secured(self):
     self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/namenode.py",
                        classname = "NameNode",
                        command = "start",
                        config_file = "secured.json",
                        hdp_stack_version = self.STACK_VERSION,
-                       target = RMFTestCase.TARGET_COMMON_SERVICES
+                       target = RMFTestCase.TARGET_COMMON_SERVICES,
+                       call_mocks = [(5,"")],
     )
     self.assert_configure_secured()
     self.assertResourceCalled('Execute', 'ls /hadoop/hdfs/namenode | wc -l  | grep -q ^0$',)
@@ -1082,23 +1082,19 @@ class TestNamenode(RMFTestCase):
                               )
     self.assertNoMoreResources()
 
-
-  @patch.object(shell, "call")
-  def test_prepare_rolling_upgrade__upgrade(self, shell_call_mock):
+  def test_prepare_rolling_upgrade__upgrade(self):
     config_file = self.get_src_folder()+"/test/python/stacks/2.0.6/configs/secured.json"
     with open(config_file, "r") as f:
       json_content = json.load(f)
     json_content['commandParams']['upgrade_direction'] = 'upgrade'
 
-    # Mock safemode_check call
-    shell_call_mock.return_value = 0, "Safe mode is OFF in c6401.ambari.apache.org"
-
     self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/namenode.py",
                        classname = "NameNode",
                        command = "prepare_rolling_upgrade",
                        config_dict = json_content,
                        hdp_stack_version = self.STACK_VERSION,
-                       target = RMFTestCase.TARGET_COMMON_SERVICES)
+                       target = RMFTestCase.TARGET_COMMON_SERVICES,
+                       call_mocks = [(0, "Safe mode is OFF in c6401.ambari.apache.org")])
     self.assertResourceCalled('Execute', '/usr/bin/kinit -kt /etc/security/keytabs/hdfs.headless.keytab hdfs',)
     self.assertResourceCalled('Execute', 'hdfs dfsadmin -rollingUpgrade prepare',
                               logoutput = True,

+ 0 - 2
ambari-server/src/test/python/stacks/2.0.6/HDFS/test_zkfc.py

@@ -207,7 +207,6 @@ class TestZkfc(RMFTestCase):
                               )
     self.assertNoMoreResources()
 
-  @patch.object(shell, "call", new=MagicMock(return_value=(0,"")))
   def test_start_with_ha_active_namenode_bootstrap(self):
     self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/zkfc_slave.py",
                        classname = "ZkfcSlave",
@@ -270,7 +269,6 @@ class TestZkfc(RMFTestCase):
                               )
     self.assertNoMoreResources()
 
-  @patch.object(shell, "call", new=MagicMock(return_value=(2,"")))
   def test_start_with_ha_standby_namenode_bootstrap(self):
     self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/zkfc_slave.py",
                        classname = "ZkfcSlave",

+ 13 - 13
ambari-server/src/test/python/stacks/2.0.6/HIVE/test_hive_server.py

@@ -25,6 +25,7 @@ from resource_management.core import shell
 from resource_management.libraries.functions import dynamic_variable_interpretation
 from stacks.utils.RMFTestCase import *
 
+@patch("resource_management.libraries.functions.check_thrift_port_sasl", new=MagicMock())
 class TestHiveServer(RMFTestCase):
   COMMON_SERVICES_PACKAGE_DIR = "HIVE/0.12.0.2.0/package"
   STACK_VERSION = "2.0.6"
@@ -41,11 +42,9 @@ class TestHiveServer(RMFTestCase):
     self.assert_configure_default()
     self.assertNoMoreResources()
 
-  @patch.object(shell, "call", new=MagicMock(return_value=(0, '')))
-  @patch.object(subprocess,"Popen")
   @patch("socket.socket")
   @patch.object(dynamic_variable_interpretation, "copy_tarballs_to_hdfs", new=MagicMock())
-  def test_start_default(self, socket_mock, popen_mock):
+  def test_start_default(self, socket_mock):
     s = socket_mock.return_value
     
     self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/hive_server.py",
@@ -57,6 +56,11 @@ class TestHiveServer(RMFTestCase):
     )
 
     self.assert_configure_default()
+
+    self.assertResourceCalled('Execute', 'hive --config /etc/hive/conf.server --service metatool -updateLocation hdfs://c6401.ambari.apache.org:8020 OK.',
+        environment = {'PATH': '/bin:/usr/lib/hive/bin:/usr/bin'},
+        user = 'hive',
+    )
     self.assertResourceCalled('Execute', '/tmp/start_hiveserver2_script /var/log/hive/hive-server2.out /var/log/hive/hive-server2.log /var/run/hive/hive-server.pid /etc/hive/conf.server /var/log/hive',
                               not_if = 'ls /var/run/hive/hive-server.pid >/dev/null 2>&1 && ps -p `cat /var/run/hive/hive-server.pid` >/dev/null 2>&1',
                               environment = {'HADOOP_HOME' : '/usr', 'JAVA_HOME':'/usr/jdk64/jdk1.7.0_45'},
@@ -98,7 +102,6 @@ class TestHiveServer(RMFTestCase):
     )
     
     self.assertNoMoreResources()
-    self.assertFalse(socket_mock.called)
 
     
   def test_configure_secured(self):
@@ -175,7 +178,6 @@ class TestHiveServer(RMFTestCase):
     )
     
     self.assertNoMoreResources()
-    self.assertFalse(socket_mock.called)
 
   def assert_configure_default(self):
     self.assertResourceCalled('HdfsDirectory', '/apps/hive/warehouse',
@@ -469,20 +471,19 @@ class TestHiveServer(RMFTestCase):
       self.fail("Script failure due to socket error was expected")
     except:
       self.assert_configure_default()
-      self.assertFalse(socket_mock.called)
-      self.assertFalse(s.close.called)
 
 
   @patch("hive_server.HiveServer.pre_rolling_restart")
   @patch("hive_server.HiveServer.start")
-  @patch.object(shell, "call", new=MagicMock(return_value=(0,"hive-server2 - 2.2.0.0-2041")))
   def test_stop_during_upgrade(self, hive_server_start_mock,
     hive_server_pre_rolling_mock):
     
     self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/hive_server.py",
      classname = "HiveServer", command = "restart", config_file = "hive-upgrade.json",
      hdp_stack_version = self.UPGRADE_STACK_VERSION,
-     target = RMFTestCase.TARGET_COMMON_SERVICES )
+     target = RMFTestCase.TARGET_COMMON_SERVICES,
+     call_mocks = [(0,"hive-server2 - 2.2.0.0-2041"), (0,"hive-server2 - 2.2.0.0-2041")]
+    )
 
     self.assertResourceCalled('Execute', 'hive --service hiveserver2 --deregister 2.2.0.0-2041',
       path=['/bin:/usr/hdp/current/hive-server2/bin:/usr/hdp/current/hadoop-client/bin'],
@@ -493,14 +494,13 @@ class TestHiveServer(RMFTestCase):
 
   @patch("hive_server.HiveServer.pre_rolling_restart")
   @patch("hive_server.HiveServer.start")
-  @patch.object(shell, "call", new=MagicMock(return_value=(0,"BAD VERSION")))
-  def test_stop_during_upgrade_bad_hive_version(self, hive_server_start_mock,
-    hive_server_pre_rolling_mock):
+  def test_stop_during_upgrade_bad_hive_version(self, hive_server_start_mock, hive_server_pre_rolling_mock):
     try:
       self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/hive_server.py",
        classname = "HiveServer", command = "restart", config_file = "hive-upgrade.json",
        hdp_stack_version = self.UPGRADE_STACK_VERSION,
-       target = RMFTestCase.TARGET_COMMON_SERVICES )
+       target = RMFTestCase.TARGET_COMMON_SERVICES,
+       call_mocks = [(0,"BAD VERSION")])
 
       self.fail("Invalid hive version should have caused an exception")
     except:

+ 8 - 14
ambari-server/src/test/python/stacks/2.0.6/OOZIE/test_oozie_server.py

@@ -794,8 +794,7 @@ class TestOozieServer(RMFTestCase):
   @patch("shutil.rmtree", new = MagicMock())
   @patch("glob.iglob")
   @patch("shutil.copy2", new = MagicMock())
-  @patch.object(shell, "call")
-  def test_upgrade(self, call_mock, glob_mock, chmod_mock, remove_mock,
+  def test_upgrade(self, glob_mock, chmod_mock, remove_mock,
       isfile_mock, exists_mock, isdir_mock, tarfile_open_mock):
 
     isdir_mock.return_value = True
@@ -806,12 +805,12 @@ class TestOozieServer(RMFTestCase):
     prepare_war_stdout = """INFO: Adding extension: libext/mysql-connector-java.jar
     New Oozie WAR file with added 'JARs' at /var/lib/oozie/oozie-server/webapps/oozie.war"""
 
-    call_mock.return_value = (0, prepare_war_stdout)
-
     self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
      classname = "OozieServer", command = "pre_rolling_restart", config_file = "oozie-upgrade.json",
      hdp_stack_version = self.UPGRADE_STACK_VERSION,
-     target = RMFTestCase.TARGET_COMMON_SERVICES )
+     target = RMFTestCase.TARGET_COMMON_SERVICES,
+     call_mocks = [(0, prepare_war_stdout)]
+    )
 
     # 2 calls to tarfile.open (1 directories, read + write)
     self.assertTrue(tarfile_open_mock.called)
@@ -846,8 +845,7 @@ class TestOozieServer(RMFTestCase):
   @patch("os.chmod")
   @patch("shutil.rmtree", new = MagicMock())
   @patch("shutil.copy2", new = MagicMock())
-  @patch.object(shell, "call")
-  def test_downgrade_no_compression_library_copy(self, call_mock, chmod_mock, remove_mock,
+  def test_downgrade_no_compression_library_copy(self, chmod_mock, remove_mock,
       isfile_mock, exists_mock, isdir_mock, tarfile_open_mock):
 
     isdir_mock.return_value = True
@@ -857,12 +855,11 @@ class TestOozieServer(RMFTestCase):
     prepare_war_stdout = """INFO: Adding extension: libext/mysql-connector-java.jar
     New Oozie WAR file with added 'JARs' at /var/lib/oozie/oozie-server/webapps/oozie.war"""
 
-    call_mock.return_value = (0, prepare_war_stdout)
-
     self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
      classname = "OozieServer", command = "pre_rolling_restart", config_file = "oozie-downgrade.json",
      hdp_stack_version = self.UPGRADE_STACK_VERSION,
-     target = RMFTestCase.TARGET_COMMON_SERVICES )
+     target = RMFTestCase.TARGET_COMMON_SERVICES,
+     call_mocks = [(0, prepare_war_stdout)])
 
     # 2 calls to tarfile.open (1 directories, read + write)
     self.assertTrue(tarfile_open_mock.called)
@@ -892,16 +889,13 @@ class TestOozieServer(RMFTestCase):
   @patch("shutil.rmtree", new = MagicMock())
   @patch("glob.iglob", new = MagicMock(return_value=["/usr/hdp/2.2.1.0-2187/hadoop/lib/hadoop-lzo-0.6.0.2.2.1.0-2187.jar"]))
   @patch("shutil.copy2")
-  @patch.object(shell, "call")
-  def test_upgrade_failed_prepare_war(self, call_mock, shutil_copy_mock, chmod_mock, remove_mock,
+  def test_upgrade_failed_prepare_war(self, shutil_copy_mock, chmod_mock, remove_mock,
       isfile_mock, exists_mock, isdir_mock, tarfile_open_mock):
 
     isdir_mock.return_value = True
     exists_mock.side_effect = [False,False,True]
     isfile_mock.return_value = True
 
-    call_mock.return_value = (0, 'Whoops, you messed up the WAR.')
-
     try:
       self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py",
        classname = "OozieServer", command = "pre_rolling_restart", config_file = "oozie-upgrade.json",

+ 23 - 23
ambari-server/src/test/python/stacks/2.0.6/YARN/test_nodemanager.py

@@ -631,34 +631,32 @@ class TestNodeManager(RMFTestCase):
                               )
 
   @patch('time.sleep')
-  @patch.object(shell, "call")
-  def test_post_rolling_restart(self, process_mock, time_mock):
+  def test_post_rolling_restart(self, time_mock):
     process_output = """
       c6401.ambari.apache.org:45454  RUNNING  c6401.ambari.apache.org:8042  0
     """
-
-    process_mock.return_value = (0, process_output)
-
+    mocks_dict = {}
+    
     self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/nodemanager.py",
                        classname="Nodemanager",
                        command = "post_rolling_restart",
                        config_file="default.json",
                        hdp_stack_version = self.STACK_VERSION,
-                       target = RMFTestCase.TARGET_COMMON_SERVICES
+                       target = RMFTestCase.TARGET_COMMON_SERVICES,
+                       call_mocks = [(0, process_output)],
+                       mocks_dict = mocks_dict
     )
 
-    self.assertTrue(process_mock.called)
-    self.assertEqual(process_mock.call_count,1)
+    self.assertTrue(mocks_dict['call'].called)
+    self.assertEqual(mocks_dict['call'].call_count,1)
 
 
   @patch('time.sleep')
-  @patch.object(shell, "call")
-  def test_post_rolling_restart_nodemanager_not_ready(self, process_mock, time_mock):
+  def test_post_rolling_restart_nodemanager_not_ready(self, time_mock):
     process_output = """
       c9999.ambari.apache.org:45454  RUNNING  c9999.ambari.apache.org:8042  0
     """
-
-    process_mock.return_value = (0, process_output)
+    mocks_dict = {}
 
     try:
       self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/nodemanager.py",
@@ -666,35 +664,37 @@ class TestNodeManager(RMFTestCase):
                          command = "post_rolling_restart",
                          config_file="default.json",
                          hdp_stack_version = self.STACK_VERSION,
-                         target = RMFTestCase.TARGET_COMMON_SERVICES
+                         target = RMFTestCase.TARGET_COMMON_SERVICES,
+                         call_mocks = [(0, process_output)],
+                         mocks_dict = mocks_dict,
       )
       self.fail('Missing NodeManager should have caused a failure')
     except Fail,fail:
-      self.assertTrue(process_mock.called)
-      self.assertEqual(process_mock.call_count,12)
+      self.assertTrue(mocks_dict['call'].called)
+      self.assertEqual(mocks_dict['call'].call_count,12)
 
 
   @patch('time.sleep')
-  @patch.object(shell, "call")
-  def test_post_rolling_restart_nodemanager_not_ready(self, process_mock, time_mock):
+  def test_post_rolling_restart_nodemanager_not_ready(self, time_mock):
     process_output = """
       c6401.ambari.apache.org:45454  RUNNING  c6401.ambari.apache.org:8042  0
     """
-
-    process_mock.return_value = (999, process_output)
-
+    mocks_dict = {}
+    
     try:
       self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/nodemanager.py",
                          classname="Nodemanager",
                          command = "post_rolling_restart",
                          config_file="default.json",
                          hdp_stack_version = self.STACK_VERSION,
-                         target = RMFTestCase.TARGET_COMMON_SERVICES
+                         target = RMFTestCase.TARGET_COMMON_SERVICES,
+                         call_mocks = [(999, process_output)],
+                         mocks_dict = mocks_dict,
       )
       self.fail('Invalid return code should cause a failure')
     except Fail,fail:
-      self.assertTrue(process_mock.called)
-      self.assertEqual(process_mock.call_count,12)
+      self.assertTrue(mocks_dict['call'].called)
+      self.assertEqual(mocks_dict['call'].call_count,12)
 
   @patch("resource_management.libraries.functions.security_commons.build_expectations")
   @patch("resource_management.libraries.functions.security_commons.get_params_from_filesystem")

+ 15 - 10
ambari-server/src/test/python/stacks/utils/RMFTestCase.py

@@ -26,6 +26,7 @@ import os
 import imp
 import sys
 import pprint
+import itertools
 from mock.mock import MagicMock, patch
 import platform
 
@@ -61,11 +62,13 @@ class RMFTestCase(TestCase):
                     # common mocks for all the scripts
                     config_overrides = None,
                     hdp_stack_version = None,
-                    shell_mock_value = (0, "OK."), 
+                    checked_call_mocks = itertools.cycle([(0, "OK.")]),
+                    call_mocks = itertools.cycle([(0, "OK.")]),
                     os_type=('Suse','11','Final'),
                     kinit_path_local="/usr/bin/kinit",
                     os_env={'PATH':'/bin'},
-                    target=TARGET_STACKS
+                    target=TARGET_STACKS,
+                    mocks_dict={}
                     ):
     norm_path = os.path.normpath(path)
     src_dir = RMFTestCase.get_src_folder()
@@ -131,14 +134,16 @@ class RMFTestCase(TestCase):
 
     # run
     with Environment(basedir, test_mode=True) as RMFTestCase.env:
-      with patch('resource_management.core.shell.checked_call', return_value=shell_mock_value): # we must always mock any shell calls
-        with patch.object(Script, 'get_config', return_value=self.config_dict): # mocking configurations
-          with patch.object(Script, 'get_tmp_dir', return_value="/tmp"):
-            with patch.object(Script, 'install_packages'):
-              with patch('resource_management.libraries.functions.get_kinit_path', return_value=kinit_path_local):
-                with patch.object(platform, 'linux_distribution', return_value=os_type):
-                  with patch.object(os, "environ", new=os_env):
-                    method(RMFTestCase.env)
+      with patch('resource_management.core.shell.checked_call', side_effect=checked_call_mocks) as mocks_dict['checked_call']:
+        with patch('resource_management.core.shell.call', side_effect=call_mocks) as mocks_dict['call']:
+          with patch.object(Script, 'get_config', return_value=self.config_dict) as mocks_dict['get_config']: # mocking configurations
+            with patch.object(Script, 'get_tmp_dir', return_value="/tmp") as mocks_dict['get_tmp_dir']:
+              with patch.object(Script, 'install_packages') as mocks_dict['install_packages']:
+                with patch('resource_management.libraries.functions.get_kinit_path', return_value=kinit_path_local) as mocks_dict['get_kinit_path']:
+                  with patch.object(platform, 'linux_distribution', return_value=os_type) as mocks_dict['linux_distribution']:
+                    with patch.object(os, "environ", new=os_env) as mocks_dict['environ']:
+                      method(RMFTestCase.env)
+                      
     sys.path.remove(scriptsdir)
   
   def getConfig(self):