diff --git a/ambari-agent/conf/unix/agent-multiplier.py b/ambari-agent/conf/unix/agent-multiplier.py index 0c21c01b5e9..381f6c1f3f3 100644 --- a/ambari-agent/conf/unix/agent-multiplier.py +++ b/ambari-agent/conf/unix/agent-multiplier.py @@ -20,6 +20,7 @@ from ambari_commons import subprocess32 import shutil from optparse import OptionParser +import shlex class Host: @@ -226,7 +227,7 @@ def create_host_name_script(self, host_name, host_name_script): "echo HOSTNAME" with open(str(host_name_script), "w+") as f: f.writelines(template.replace("HOSTNAME", host_name)) - subprocess32.call("chmod +x %s" % host_name_script, shell=True) + subprocess32.call(shlex.split("chmod +x %s" % host_name_script), shell=False) def change_config(self, config_file, config_dict): """ @@ -321,21 +322,21 @@ def cmd_start(self): for host in self.hosts: cmd = "ambari-agent start --home %s" % (host.home_dir) os.environ['AMBARI_AGENT_CONF_DIR'] = os.path.join(host.home_dir, "etc/ambari-agent/conf") - subprocess32.call(cmd, shell=True, env=os.environ) + subprocess32.call(shlex.split(cmd), shell=False, env=os.environ) def cmd_stop(self): print "Stopping %d host(s)" % len(self.hosts) for host in self.hosts: cmd = "ambari-agent stop --home %s" % (host.home_dir) os.environ['AMBARI_AGENT_CONF_DIR'] = os.path.join(host.home_dir, "etc/ambari-agent/conf") - subprocess32.call(cmd, shell=True, env=os.environ) + subprocess32.call(shlex.split(cmd), shell=False, env=os.environ) def cmd_restart(self): print "Restarting %d host(s)" % len(self.hosts) for host in self.hosts: cmd = "ambari-agent restart --home %s" % (host.home_dir) os.environ['AMBARI_AGENT_CONF_DIR'] = os.path.join(host.home_dir, "etc/ambari-agent/conf") - subprocess32.call(cmd, shell=True, env=os.environ) + subprocess32.call(shlex.split(cmd), shell=False, env=os.environ) def cmd_status(self): print "Summary of Agent Status:" diff --git a/ambari-agent/src/main/python/ambari_agent/Controller.py b/ambari-agent/src/main/python/ambari_agent/Controller.py index cd9c05a94d7..eb88c5e60f4 100644 --- a/ambari-agent/src/main/python/ambari_agent/Controller.py +++ b/ambari-agent/src/main/python/ambari_agent/Controller.py @@ -37,6 +37,7 @@ import security import ssl import AmbariConfig +import shlex from ambari_agent.Heartbeat import Heartbeat from ambari_agent.Register import Register @@ -633,12 +634,12 @@ def move_data_dir_mount_file(self): if os.path.exists(source_file) and not os.path.exists(destination_file): command = "mkdir -p %s" % os.path.dirname(destination_file) logger.info("Moving Data Dir Mount History file. Executing command: %s" % command) - return_code = subprocess32.call(command, shell=True) + return_code = subprocess32.call(shlex.split(command), shell=False) logger.info("Return code: %d" % return_code) command = "mv %s %s" % (source_file, destination_file) logger.info("Moving Data Dir Mount History file. Executing command: %s" % command) - return_code = subprocess32.call(command, shell=True) + return_code = subprocess32.call(shlex.split(command), shell=False) logger.info("Return code: %d" % return_code) except Exception, e: logger.error("Exception in move_data_dir_mount_file(). Error: {0}".format(str(e))) diff --git a/ambari-agent/src/main/python/ambari_agent/PingPortListener.py b/ambari-agent/src/main/python/ambari_agent/PingPortListener.py index d2eca78d016..7b4e15796f6 100644 --- a/ambari-agent/src/main/python/ambari_agent/PingPortListener.py +++ b/ambari-agent/src/main/python/ambari_agent/PingPortListener.py @@ -23,6 +23,7 @@ import threading import socket from ambari_commons import subprocess32 +import shlex logger = logging.getLogger(__name__) FUSER_CMD = "fuser {0}/tcp 2>/dev/null | awk '{1}'" @@ -51,10 +52,10 @@ def __init__(self, config): def run_os_command_in_shell(self, command): - process = subprocess32.Popen(command, stdout=subprocess32.PIPE, + process = subprocess32.Popen(shlex.split(command), stdout=subprocess32.PIPE, stdin=subprocess32.PIPE, stderr=subprocess32.PIPE, - shell=True) + shell=False) return process.communicate() def __del__(self): diff --git a/ambari-agent/src/main/python/ambari_agent/hostname.py b/ambari-agent/src/main/python/ambari_agent/hostname.py index 82d868b9d0b..274134a89ee 100644 --- a/ambari-agent/src/main/python/ambari_agent/hostname.py +++ b/ambari-agent/src/main/python/ambari_agent/hostname.py @@ -24,6 +24,7 @@ import logging import traceback import sys +import shlex logger = logging.getLogger(__name__) @@ -80,7 +81,10 @@ def public_hostname(config): try: if config.has_option('agent', 'public_hostname_script'): scriptname = config.get('agent', 'public_hostname_script') - output = subprocess32.Popen(scriptname, stdout=subprocess32.PIPE, stderr=subprocess32.PIPE, shell=True) + output = subprocess32.Popen(shlex.split(scriptname), + stdout=subprocess32.PIPE, + stderr=subprocess32.PIPE, + shell=False) out, err = output.communicate() if (0 == output.returncode and 0 != len(out.strip())): cached_public_hostname = out.strip().lower() diff --git a/ambari-agent/src/main/python/ambari_agent/security.py b/ambari-agent/src/main/python/ambari_agent/security.py index e7c934c1a28..54860b71480 100644 --- a/ambari-agent/src/main/python/ambari_agent/security.py +++ b/ambari-agent/src/main/python/ambari_agent/security.py @@ -34,6 +34,7 @@ import threading from ambari_stomp.adapter.websocket import WsConnection from socket import error as socket_error +import shlex logger = logging.getLogger(__name__) @@ -303,7 +304,7 @@ def genAgentCrtReq(self, keyname): p = subprocess32.Popen(generate_script, stdout=subprocess32.PIPE) p.communicate() else: - p = subprocess32.Popen([generate_script], shell=True, + p = subprocess32.Popen(shlex.split(generate_script), shell=False, stdout=subprocess32.PIPE) p.communicate() # this is required to be 600 for security concerns. diff --git a/ambari-common/src/main/python/resource_management/core/providers/mount.py b/ambari-common/src/main/python/resource_management/core/providers/mount.py index 1b3358720ac..68ac9038e23 100644 --- a/ambari-common/src/main/python/resource_management/core/providers/mount.py +++ b/ambari-common/src/main/python/resource_management/core/providers/mount.py @@ -29,13 +29,14 @@ from resource_management.core.base import Fail from resource_management.core.providers import Provider from resource_management.core.logger import Logger +import shlex def get_mounted(): """ :return: Return a list of mount objects (dictionary type) that contain the device, mount point, and other options. """ - p = Popen("mount", stdout=PIPE, stderr=STDOUT, shell=True) + p = Popen(shlex.split("mount"), stdout=PIPE, stderr=STDOUT, shell=False) out = p.communicate()[0] if p.wait() != 0: raise Fail("Getting list of mounts (calling mount) failed") diff --git a/ambari-infra/ambari-infra-solr-client/src/main/python/migrationConfigGenerator.py b/ambari-infra/ambari-infra-solr-client/src/main/python/migrationConfigGenerator.py index 125b59d370b..a6144a767c7 100755 --- a/ambari-infra/ambari-infra-solr-client/src/main/python/migrationConfigGenerator.py +++ b/ambari-infra/ambari-infra-solr-client/src/main/python/migrationConfigGenerator.py @@ -32,6 +32,7 @@ import ConfigParser from subprocess import Popen, PIPE from random import randrange +import shlex SOLR_SERVICE_NAME = 'AMBARI_INFRA_SOLR' SOLR_COMPONENT_NAME ='INFRA_SOLR' @@ -138,7 +139,7 @@ def get_state_json_map(solr_urls, user='infra-solr', kerberos_enabled='false', k state_json_data={} request = GET_STATE_JSON_URL.format(get_random_solr_url(solr_urls)) get_state_json_cmd=create_solr_api_request_command(request, user, kerberos_enabled, keytab, principal) - process = Popen(get_state_json_cmd, stdout=PIPE, stderr=PIPE, shell=True) + process = Popen(shlex.split(get_state_json_cmd), stdout=PIPE, stderr=PIPE, shell=False) out, err = process.communicate() if process.returncode != 0: logger.error(str(err)) diff --git a/ambari-infra/ambari-infra-solr-client/src/main/python/migrationHelper.py b/ambari-infra/ambari-infra-solr-client/src/main/python/migrationHelper.py index 7914f36afd1..952887fe3be 100755 --- a/ambari-infra/ambari-infra-solr-client/src/main/python/migrationHelper.py +++ b/ambari-infra/ambari-infra-solr-client/src/main/python/migrationHelper.py @@ -37,6 +37,7 @@ from subprocess import Popen, PIPE import solrDataManager as solr_data_manager +import shlex HTTP_PROTOCOL = 'http' HTTPS_PROTOCOL = 'https' @@ -843,7 +844,7 @@ def monitor_solr_async_request(options, config, status_request, request_id): async_request_timed_out = False while not async_request_finished: tries = tries + 1 - process = Popen(request_status_json_cmd, stdout=PIPE, stderr=PIPE, shell=True) + process = Popen(shlex.split(request_status_json_cmd), stdout=PIPE, stderr=PIPE, shell=False) out, err = process.communicate() if process.returncode != 0: raise Exception("{0} command failed: {1}".format(request_status_json_cmd, str(err))) @@ -893,7 +894,7 @@ def delete_collection(options, config, collection, solr_urls, response_data_map) request = DELETE_SOLR_COLLECTION_URL.format(solr_url, collection, async_id) logger.debug("Solr request: {0}".format(request)) delete_collection_json_cmd=create_solr_api_request_command(request, config) - process = Popen(delete_collection_json_cmd, stdout=PIPE, stderr=PIPE, shell=True) + process = Popen(shlex.split(delete_collection_json_cmd), stdout=PIPE, stderr=PIPE, shell=False) out, err = process.communicate() if process.returncode != 0: raise Exception("{0} command failed: {1}".format(delete_collection_json_cmd, str(err))) @@ -910,7 +911,7 @@ def create_collection(options, config, solr_urls, collection, config_set, shards request = CREATE_SOLR_COLLECTION_URL.format(get_random_solr_url(solr_urls, options), collection, config_set, shards, replica, max_shards_per_node) logger.debug("Solr request: {0}".format(request)) create_collection_json_cmd=create_solr_api_request_command(request, config) - process = Popen(create_collection_json_cmd, stdout=PIPE, stderr=PIPE, shell=True) + process = Popen(shlex.split(create_collection_json_cmd), stdout=PIPE, stderr=PIPE, shell=False) out, err = process.communicate() if process.returncode != 0: raise Exception("{0} command failed: {1}".format(create_collection_json_cmd, str(err))) @@ -925,7 +926,7 @@ def reload_collection(options, config, solr_urls, collection): request = RELOAD_SOLR_COLLECTION_URL.format(get_random_solr_url(solr_urls, options), collection) logger.debug("Solr request: {0}".format(request)) reload_collection_json_cmd=create_solr_api_request_command(request, config) - process = Popen(reload_collection_json_cmd, stdout=PIPE, stderr=PIPE, shell=True) + process = Popen(shlex.split(reload_collection_json_cmd), stdout=PIPE, stderr=PIPE, shell=False) out, err = process.communicate() if process.returncode != 0: raise Exception("{0} command failed: {1}".format(reload_collection_json_cmd, str(err))) @@ -962,7 +963,7 @@ def get_replica_index_size(config, core_url, replica): request = CORE_DETAILS_URL.format(core_url) logger.debug("Solr request: {0}".format(request)) get_core_detaul_json_cmd=create_solr_api_request_command(request, config) - process = Popen(get_core_detaul_json_cmd, stdout=PIPE, stderr=PIPE, shell=True) + process = Popen(shlex.split(get_core_detaul_json_cmd), stdout=PIPE, stderr=PIPE, shell=False) out, err = process.communicate() if process.returncode != 0: raise Exception("{0} command failed: {1}".format(get_core_detaul_json_cmd, str(err))) @@ -980,7 +981,7 @@ def delete_znode(options, config, znode): logger.debug("Solr cli command: {0}".format(solr_cli_command)) sys.stdout.write('Deleting znode {0} ... '.format(znode)) sys.stdout.flush() - process = Popen(solr_cli_command, stdout=PIPE, stderr=PIPE, shell=True) + process = Popen(shlex.split(solr_cli_command), stdout=PIPE, stderr=PIPE, shell=False) out, err = process.communicate() if process.returncode != 0: sys.stdout.write(colors.FAIL + 'FAILED\n' + colors.ENDC) @@ -999,7 +1000,7 @@ def copy_znode(options, config, copy_src, copy_dest, copy_from_local=False, copy logger.debug("Solr cli command: {0}".format(solr_cli_command)) sys.stdout.write('Transferring data from {0} to {1} ... '.format(copy_src, copy_dest)) sys.stdout.flush() - process = Popen(solr_cli_command, stdout=PIPE, stderr=PIPE, shell=True) + process = Popen(shlex.split(solr_cli_command), stdout=PIPE, stderr=PIPE, shell=False) out, err = process.communicate() if process.returncode != 0: sys.stdout.write(colors.FAIL + 'FAILED\n' + colors.ENDC) @@ -1031,7 +1032,7 @@ def list_collections(options, config, output_file, include_number_of_docs=False) logger.debug("Solr cli command: {0}".format(solr_cli_command)) sys.stdout.write('Dumping collections data to {0} ... '.format(output_file)) sys.stdout.flush() - process = Popen(solr_cli_command, stdout=PIPE, stderr=PIPE, shell=True) + process = Popen(shlex.split(solr_cli_command), stdout=PIPE, stderr=PIPE, shell=False) out, err = process.communicate() if process.returncode != 0: sys.stdout.write(colors.FAIL + 'FAILED\n' + colors.ENDC) diff --git a/ambari-metrics/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_pssunos.py b/ambari-metrics/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_pssunos.py index 15520103b05..82942c83d45 100644 --- a/ambari-metrics/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_pssunos.py +++ b/ambari-metrics/ambari-metrics-host-monitoring/src/main/python/psutil/psutil/_pssunos.py @@ -18,6 +18,7 @@ from psutil._compat import namedtuple, PY3 import _psutil_posix import _psutil_sunos as cext +import shlex __extra__all__ = ["CONN_IDLE", "CONN_BOUND"] @@ -433,8 +434,10 @@ def _get_unix_sockets(self, pid): # TODO: rewrite this in C (...but the damn netstat source code # does not include this part! Argh!!) cmd = "pfiles %s" % pid - p = subprocess32.Popen(cmd, shell=True, stdout=subprocess32.PIPE, - stderr=subprocess32.PIPE) + p = subprocess32.Popen(shlex.split(cmd), + shell=False, + stdout=subprocess32.PIPE, + stderr=subprocess32.PIPE) stdout, stderr = p.communicate() if PY3: stdout, stderr = [x.decode(sys.stdout.encoding) diff --git a/ambari-metrics/ambari-metrics-timelineservice/conf/unix/sqlline/phoenix_utils.py b/ambari-metrics/ambari-metrics-timelineservice/conf/unix/sqlline/phoenix_utils.py index 492764bcf8c..6d60f40219a 100644 --- a/ambari-metrics/ambari-metrics-timelineservice/conf/unix/sqlline/phoenix_utils.py +++ b/ambari-metrics/ambari-metrics-timelineservice/conf/unix/sqlline/phoenix_utils.py @@ -22,6 +22,7 @@ import os import fnmatch import subprocess +import shlex def find(pattern, classPaths): paths = classPaths.split(os.pathsep) @@ -62,7 +63,7 @@ def which(file): def findClasspath(file): aPath = which(file) command = "%s%s" %(aPath, ' classpath') - return subprocess.Popen(command, shell=True, stdout=subprocess.PIPE).stdout.read() + return subprocess.Popen(shlex.split(command), shell=False, stdout=subprocess.PIPE).stdout.read() def setPath(): PHOENIX_CLIENT_JAR_PATTERN = "phoenix-*-client.jar" diff --git a/ambari-metrics/ambari-metrics-timelineservice/conf/unix/sqlline/sqlline.py b/ambari-metrics/ambari-metrics-timelineservice/conf/unix/sqlline/sqlline.py index 852f26415e4..f14d311dcf8 100644 --- a/ambari-metrics/ambari-metrics-timelineservice/conf/unix/sqlline/sqlline.py +++ b/ambari-metrics/ambari-metrics-timelineservice/conf/unix/sqlline/sqlline.py @@ -25,6 +25,7 @@ import phoenix_utils import atexit import fnmatch +import shlex # Set JAVA_HOME or JDK_HOME before running sqlline.py # Example: ./sqlline.py localhost:61181:/ams-hbase-unsecure @@ -95,7 +96,7 @@ def find_java(): print 'java command: %s' % str(java_cmd) -childProc = subprocess.Popen(java_cmd, shell=True) +childProc = subprocess.Popen(shlex.split(java_cmd), shell=False) #Wait for child process exit (output, error) = childProc.communicate() returncode = childProc.returncode diff --git a/ambari-server/src/main/python/ambari_server/serverSetup.py b/ambari-server/src/main/python/ambari_server/serverSetup.py index a32ac387654..85297468d6b 100644 --- a/ambari-server/src/main/python/ambari_server/serverSetup.py +++ b/ambari-server/src/main/python/ambari_server/serverSetup.py @@ -26,6 +26,7 @@ from ambari_commons import subprocess32 import getpass import logging +import shlex from ambari_commons.exceptions import FatalException from ambari_commons.firewall import Firewall @@ -846,11 +847,11 @@ def adjust_jce_permissions(self, jdk_path): cmd = " && ".join(cmds) - process = subprocess32.Popen(cmd, + process = subprocess32.Popen(shlex.split(cmd), stdout=subprocess32.PIPE, stdin=subprocess32.PIPE, stderr=subprocess32.PIPE, - shell=True + shell=False ) (stdoutdata, stderrdata) = process.communicate() @@ -1281,11 +1282,11 @@ def check_ambari_java_version_is_valid(java_home, java_bin, min_version, propert print 'Check JDK version for Ambari Server...' try: command = JDK_VERSION_CHECK_CMD.format(os.path.join(java_home, 'bin', java_bin)) - process = subprocess32.Popen(command, + process = subprocess32.Popen(shlex.split(command), stdout=subprocess32.PIPE, stdin=subprocess32.PIPE, stderr=subprocess32.PIPE, - shell=True + shell=False ) (out, err) = process.communicate() if process.returncode != 0: diff --git a/ambari-server/src/main/python/ambari_server/utils.py b/ambari-server/src/main/python/ambari_server/utils.py index a16d5826336..9f362a232c2 100644 --- a/ambari-server/src/main/python/ambari_server/utils.py +++ b/ambari-server/src/main/python/ambari_server/utils.py @@ -28,6 +28,7 @@ import logging import platform import xml.etree.ElementTree as ET +import shlex from ambari_commons import OSConst,OSCheck from ambari_commons.logging_utils import print_error_msg @@ -272,11 +273,11 @@ def get_postgre_hba_dir(OS_FAMILY): pg_hba_init_basename = os.path.basename(get_pg_hba_init_files()) # Get postgres_data location (default: /var/lib/pgsql/data) cmd = "alias basename='echo {0}; true' ; alias exit=return; source {1} status &>/dev/null; echo $PGDATA".format(pg_hba_init_basename, get_pg_hba_init_files()) - p = subprocess32.Popen(cmd, + p = subprocess32.Popen(shlex.split(cmd), stdout=subprocess32.PIPE, stdin=subprocess32.PIPE, stderr=subprocess32.PIPE, - shell=True) + shell=False) (PG_HBA_ROOT, err) = p.communicate() if PG_HBA_ROOT and len(PG_HBA_ROOT.strip()) > 0: diff --git a/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/utils.py b/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/utils.py index dd9c9a1eaa9..cb8b16d401c 100644 --- a/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/utils.py +++ b/ambari-server/src/main/resources/common-services/HAWQ/2.0.0/package/scripts/utils.py @@ -20,6 +20,7 @@ from resource_management.core.resources.system import Execute, Directory from resource_management.core.exceptions import Fail from resource_management.core.logger import Logger +import shlex import hawq_constants @@ -83,7 +84,11 @@ def exec_ssh_cmd(hostname, cmd): # Only gpadmin should be allowed to run command via ssh, thus not exposing user as a parameter cmd = "su - {0} -c \"ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null {1} \\\"{2} \\\" \"".format(hawq_constants.hawq_user, hostname, cmd) Logger.info("Command executed: {0}".format(cmd)) - process = subprocess32.Popen(cmd, stdout=subprocess32.PIPE, stdin=subprocess32.PIPE, stderr=subprocess32.PIPE, shell=True) + process = subprocess32.Popen(shlex.split(cmd), + stdout=subprocess32.PIPE, + stdin=subprocess32.PIPE, + stderr=subprocess32.PIPE, + shell=False) (stdout, stderr) = process.communicate() return process.returncode, stdout, stderr diff --git a/ambari-server/src/main/resources/common-services/PXF/3.0.0/package/scripts/pxf_utils.py b/ambari-server/src/main/resources/common-services/PXF/3.0.0/package/scripts/pxf_utils.py index 85d6ba39b0e..504fe320d38 100644 --- a/ambari-server/src/main/resources/common-services/PXF/3.0.0/package/scripts/pxf_utils.py +++ b/ambari-server/src/main/resources/common-services/PXF/3.0.0/package/scripts/pxf_utils.py @@ -21,6 +21,7 @@ import urllib2 import urllib from ambari_commons import subprocess32 +import shlex def makeHTTPCall(url, header={}, body=None): # timeout in seconds @@ -45,5 +46,5 @@ def makeHTTPCall(url, header={}, body=None): def runLocalCmd(cmd): - return subprocess32.call(cmd, shell=True) + return subprocess32.call(shlex.split(cmd), shell=False) diff --git a/dev-support/docker/docker/bin/ambaribuild.py b/dev-support/docker/docker/bin/ambaribuild.py index dfb7d60a765..d05fc4f2ae5 100755 --- a/dev-support/docker/docker/bin/ambaribuild.py +++ b/dev-support/docker/docker/bin/ambaribuild.py @@ -16,6 +16,7 @@ import json import datetime from optparse import OptionParser +import shlex SKIP_TEST="-DskipTests" AMBARI_AUTH_HEADERS = "--header 'Authorization:Basic YWRtaW46YWRtaW4=' --header 'X-Requested-By: PIVOTAL'" @@ -24,14 +25,14 @@ RETRY_MAX=20 def git_deep_cleaning(): - proc = subprocess.Popen("git clean -xdf", - shell=True, + proc = subprocess.Popen(shlex.split("git clean -xdf"), + shell=False, cwd="/tmp/ambari") return proc.wait() def ambariUnitTest(): - proc = subprocess.Popen("mvn -fae clean install", - shell=True, + proc = subprocess.Popen(shlex.split("mvn -fae clean install"), + shell=False, cwd="/tmp/ambari") return proc.wait() @@ -39,54 +40,54 @@ def buildAmbari(stack_distribution): stack_distribution_param = "" if stack_distribution is not None: stack_distribution_param = "-Dstack.distribution=" + stack_distribution - proc = subprocess.Popen("mvn -B clean install package rpm:rpm -Dmaven.clover.skip=true -Dfindbugs.skip=true " + proc = subprocess.Popen(shlex.split("mvn -B clean install package rpm:rpm -Dmaven.clover.skip=true -Dfindbugs.skip=true " + SKIP_TEST + " " - + stack_distribution_param + " -Dpython.ver=\"python >= 2.6\"", - shell=True, + + stack_distribution_param + " -Dpython.ver=\"python >= 2.6\""), + shell=False, cwd="/tmp/ambari") return proc.wait() def install_ambari_server(): - proc = subprocess.Popen("sudo yum install -y ambari-server-*.x86_64.rpm", - shell=True, + proc = subprocess.Popen(shlex.split("sudo yum install -y ambari-server-*.x86_64.rpm"), + shell=False, cwd="/tmp/ambari/ambari-server/target/rpm/ambari-server/RPMS/x86_64") return proc.wait() def install_ambari_agent(): - proc = subprocess.Popen("sudo yum install -y ambari-agent-*.x86_64.rpm", - shell=True, + proc = subprocess.Popen(shlex.split("sudo yum install -y ambari-agent-*.x86_64.rpm"), + shell=False, cwd="/tmp/ambari/ambari-agent/target/rpm/ambari-agent/RPMS/x86_64") return proc.wait() def setup_ambari_server(): - proc = subprocess.Popen("echo -e '\n\n\n\n' | sudo ambari-server setup", - shell=True) + proc = subprocess.Popen(shlex.split("echo -e '\n\n\n\n' | sudo ambari-server setup"), + shell=False) return proc.wait() def start_ambari_server(debug=False): - proc = subprocess.Popen("sudo ambari-server start" + (" --debug" if debug else ""), - shell=True) + proc = subprocess.Popen(shlex.split("sudo ambari-server start" + (" --debug" if debug else "")), + shell=False) return proc.wait() def start_dependant_services(): retcode = 0 - proc = subprocess.Popen("sudo service sshd start", shell=True) + proc = subprocess.Popen(shlex.split("sudo service sshd start"), shell=False) retcode += proc.wait() - proc = subprocess.Popen("sudo service ntpd start", shell=True) + proc = subprocess.Popen(shlex.split("sudo service ntpd start"), shell=False) retcode += proc.wait() return retcode def configure_ambari_agent(): - proc = subprocess.Popen("hostname -f", stdout=subprocess.PIPE, shell=True) + proc = subprocess.Popen(shlex.split("hostname -f"), stdout=subprocess.PIPE, shell=False) hostname = proc.stdout.read().rstrip() - proc = subprocess.Popen("sudo sed -i 's/hostname=localhost/hostname=" + hostname + "/g' /etc/ambari-agent/conf/ambari-agent.ini", - shell=True) + proc = subprocess.Popen(shlex.split("sudo sed -i 's/hostname=localhost/hostname=" + hostname + "/g' /etc/ambari-agent/conf/ambari-agent.ini"), + shell=False) return proc.wait() def start_ambari_agent(wait_until_registered = True): retcode = 0 - proc = subprocess.Popen("service ambari-agent start", - shell=True) + proc = subprocess.Popen(shlex.split("service ambari-agent start"), + shell=False) retcode += proc.wait() if wait_until_registered: if not wait_until_ambari_agent_registered(): @@ -103,11 +104,11 @@ def wait_until_ambari_agent_registered(): count = 0 while count < RETRY_MAX: count += 1 - proc = subprocess.Popen("curl " + + proc = subprocess.Popen(shlex.split("curl " + "http://localhost:8080/api/v1/hosts " + - AMBARI_AUTH_HEADERS, + AMBARI_AUTH_HEADERS), stdout=subprocess.PIPE, - shell=True) + shell=False) hosts_result_string = proc.stdout.read() hosts_result_json = json.loads(hosts_result_string) if len(hosts_result_json["items"]) != 0: @@ -116,19 +117,19 @@ def wait_until_ambari_agent_registered(): return False def post_blueprint(): - proc = subprocess.Popen("curl -X POST -D - " + + proc = subprocess.Popen(shlex.split("curl -X POST -D - " + "-d @single-node-HDP-2.1-blueprint1.json http://localhost:8080/api/v1/blueprints/myblueprint1 " + - AMBARI_AUTH_HEADERS , + AMBARI_AUTH_HEADERS ), cwd=AMBARI_BUILD_DOCKER_ROOT + "/blueprints", - shell=True) + shell=False) return proc.wait() def create_cluster(): - proc = subprocess.Popen("curl -X POST -D - " + + proc = subprocess.Popen(shlex.split("curl -X POST -D - " + "-d @single-node-hostmapping1.json http://localhost:8080/api/v1/clusters/mycluster1 " + - AMBARI_AUTH_HEADERS , + AMBARI_AUTH_HEADERS ), cwd=AMBARI_BUILD_DOCKER_ROOT + "/blueprints", - shell=True) + shell=False) return proc.wait() # Loop to not to exit Docker container