Fix bandit error: SPDK driver:[B602:subprocess_popen_with_shell_equals_true]

This patch fixes one of the cyborg-tox-bandit Failures[0] in Zuul check.

[0]https://c3f93530c9211d80493c-aff6bc2b39e4d26360d25c473974606e.ssl.cf5.rackcdn.com/696089/16/check/cyborg-tox-bandit/e8316b7/job-output.txt

Change-Id: I70d8295db2b73e3c21e6d0bc38525fa679773a88
This commit is contained in:
Yumeng Bao 2020-04-16 06:24:10 -07:00
parent ef0b2199c1
commit 3af3a3e0d6

View File

@ -16,8 +16,11 @@ import psutil
import re import re
import subprocess import subprocess
from oslo_concurrency import processutils
from oslo_log import log as logging from oslo_log import log as logging
import cyborg.privsep
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -28,6 +31,7 @@ class PySPDK(object):
self.pid = None self.pid = None
self.pname = pname self.pname = pname
@cyborg.privsep.sys_admin_pctxt.entrypoint
def start_server(self, spdk_dir, server_name): def start_server(self, spdk_dir, server_name):
if not self.is_alive(): if not self.is_alive():
self.init_hugepages(spdk_dir) self.init_hugepages(spdk_dir)
@ -35,23 +39,18 @@ class PySPDK(object):
file_dir = self._search_file(server_dir, server_name) file_dir = self._search_file(server_dir, server_name)
LOG.info(file_dir) LOG.info(file_dir)
os.chdir(file_dir) os.chdir(file_dir)
p = subprocess.Popen( cmd = ['bash', server_name]
'sudo ./%s' % server_name, out, err = processutils.execute(*cmd)
shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = p.communicate()
return out return out
@cyborg.privsep.sys_admin_pctxt.entrypoint
def init_hugepages(self, spdk_dir): def init_hugepages(self, spdk_dir):
huge_dir = os.path.join(spdk_dir, 'scripts/') huge_dir = os.path.join(spdk_dir, 'scripts/')
file_dir = self._search_file(huge_dir, 'setup.sh') file_dir = self._search_file(huge_dir, 'setup.sh')
LOG.info(file_dir) LOG.info(file_dir)
os.chdir(file_dir) os.chdir(file_dir)
p = subprocess.Popen( cmd = ['bash', 'setup.sh']
'sudo ./setup.sh', out, err = processutils.execute(*cmd)
shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = p.communicate()
return out return out
@staticmethod @staticmethod