def test_get_custom_actions_base_dir(self, provide_directory_mock): provide_directory_mock.return_value = "dummy value" fileCache = FileCache(self.config) res = fileCache.get_custom_actions_base_dir("server_url_pref") self.assertEquals( pprint.pformat(provide_directory_mock.call_args_list[0][0]), "('/var/lib/ambari-agent/cache', 'custom_actions', 'server_url_pref')") self.assertEquals(res, "dummy value")
def actionexecute(self, env): resolve_ambari_config() # Parse parameters from command json file. config = Script.get_config() host_name = socket.gethostname() version = default('/roleParams/version', None) # These 2 variables are optional service_package_folder = default('/roleParams/service_package_folder', None) hooks_folder = default('/roleParams/hooks_folder', None) tasks = json.loads(config['roleParams']['tasks']) if tasks: for t in tasks: task = ExecuteTask(t) Logger.info(str(task)) # If a (script, function) exists, it overwrites the command. if task.script and task.function: file_cache = FileCache(agent_config) server_url_prefix = default('/hostLevelParams/jdk_location', "") if service_package_folder and hooks_folder: command_paths = { "commandParams": { "service_package_folder": service_package_folder, "hooks_folder": hooks_folder } } base_dir = file_cache.get_service_base_dir(command_paths, server_url_prefix) else: base_dir = file_cache.get_custom_actions_base_dir(server_url_prefix) script_path = os.path.join(base_dir, task.script) if not os.path.exists(script_path): message = "Script %s does not exist" % str(script_path) raise Fail(message) # Notice that the script_path is now the fully qualified path, and the # same command-#.json file is used. # Also, the python wrapper is used, since it sets up the correct environment variables command_params = ["/usr/bin/ambari-python-wrap", script_path, task.function, self.command_data_file, self.basedir, self.stroutfile, self.logging_level, Script.get_tmp_dir()] task.command = "source /var/lib/ambari-agent/ambari-env.sh ; " + " ".join(command_params) # Replace redundant whitespace to make the unit tests easier to validate task.command = re.sub("\s+", " ", task.command).strip() if task.command: task.command = replace_variables(task.command, host_name, version) shell.checked_call(task.command, logoutput=True, quiet=True)
def actionexecute(self, env): resolve_ambari_config() # Parse parameters from command json file. config = Script.get_config() host_name = socket.gethostname() version = default('/roleParams/version', None) # These 2 variables are optional service_package_folder = default( '/commandParams/service_package_folder', None) if service_package_folder is None: service_package_folder = default( '/serviceLevelParams/service_package_folder', None) hooks_folder = default('/commandParams/hooks_folder', None) tasks = json.loads(config['roleParams']['tasks']) if tasks: for t in tasks: task = ExecuteTask(t) Logger.info(str(task)) # If a (script, function) exists, it overwrites the command. if task.script and task.function: file_cache = FileCache(agent_config) if service_package_folder and hooks_folder: command_paths = { "commandParams": { "service_package_folder": service_package_folder, }, "clusterLevelParams": { "hooks_folder": hooks_folder }, "ambariLevelParams": { "jdk_location": default('/ambariLevelParams/jdk_location', "") } } base_dir = file_cache.get_service_base_dir( command_paths) else: base_dir = file_cache.get_custom_actions_base_dir({ "ambariLevelParams": { "jdk_location": default('/ambariLevelParams/jdk_location', "") } }) script_path = os.path.join(base_dir, task.script) if not os.path.exists(script_path): message = "Script %s does not exist" % str(script_path) raise Fail(message) # Notice that the script_path is now the fully qualified path, and the # same command-#.json file is used. # Also, the python wrapper is used, since it sets up the correct environment variables command_params = [ "/usr/bin/ambari-python-wrap", script_path, task.function, self.command_data_file, self.basedir, self.stroutfile, self.logging_level, Script.get_tmp_dir() ] task.command = "source /var/lib/ambari-agent/ambari-env.sh ; " + " ".join( command_params) # Replace redundant whitespace to make the unit tests easier to validate task.command = re.sub("\s+", " ", task.command).strip() if task.command: task.command = replace_variables(task.command, host_name, version) shell.checked_call(task.command, logoutput=True, quiet=True)