Fix controllerconfig subprocess py3 compatibility
Subprocess Popen.communicate and check_output return a string object on python2 and a bytes object on python3. Add universal_newlines=True parameter to keep backwards compatibility and to return a string object on python3 also. Story: 2008454 Task: 42675 Signed-off-by: Dan Voiculeasa <dan.voiculeasa@windriver.com> Change-Id: I89c8ab3b83c6567cf9282027889f38237657c71c
This commit is contained in:
parent
0bf05fafc7
commit
1fda925b50
|
@ -44,7 +44,8 @@ def configure_management():
|
|||
lldp_interface_list = list()
|
||||
|
||||
print("Enabling interfaces... ", end=' ')
|
||||
ip_link_output = subprocess.check_output(['ip', '-o', 'link'])
|
||||
ip_link_output = subprocess.check_output(['ip', '-o', 'link'],
|
||||
universal_newlines=True)
|
||||
|
||||
for line in ip_link_output.splitlines():
|
||||
interface = line.split()[1].rstrip(':')
|
||||
|
@ -66,7 +67,8 @@ def configure_management():
|
|||
|
||||
print("Retrieving neighbor details... ", end=' ')
|
||||
lldpcli_show_output = subprocess.check_output(
|
||||
['sudo', 'lldpcli', 'show', 'neighbors', 'summary', '-f', 'json'])
|
||||
['sudo', 'lldpcli', 'show', 'neighbors', 'summary', '-f', 'json'],
|
||||
universal_newlines=True)
|
||||
try:
|
||||
lldp_interfaces = json.loads(
|
||||
lldpcli_show_output)['lldp'][0]['interface']
|
||||
|
|
|
@ -205,7 +205,8 @@ def tidy_storage(result_file):
|
|||
"ls",
|
||||
"--pool",
|
||||
"images"],
|
||||
stderr=subprocess.STDOUT)
|
||||
stderr=subprocess.STDOUT,
|
||||
universal_newlines=True)
|
||||
except subprocess.CalledProcessError:
|
||||
LOG.error("Failed to access rbd images pool")
|
||||
raise TidyStorageFail("Failed to access rbd images pool")
|
||||
|
@ -229,7 +230,8 @@ def tidy_storage(result_file):
|
|||
["grep",
|
||||
"fsid",
|
||||
"/etc/ceph/ceph.conf"],
|
||||
stderr=subprocess.STDOUT)
|
||||
stderr=subprocess.STDOUT,
|
||||
universal_newlines=True)
|
||||
|
||||
ceph_cluster = [i.strip() for i in output.split('=')
|
||||
if i.find('fsid') == -1]
|
||||
|
@ -239,7 +241,9 @@ def tidy_storage(result_file):
|
|||
try:
|
||||
img_file = 'rbd:images/{}'.format(image)
|
||||
output = subprocess.check_output(
|
||||
["qemu-img", "info", img_file], stderr=subprocess.STDOUT)
|
||||
["qemu-img", "info", img_file],
|
||||
stderr=subprocess.STDOUT,
|
||||
universal_newlines=True)
|
||||
|
||||
fields['disk_format'] = 'qcow2'
|
||||
for line in output.split('\n'):
|
||||
|
@ -281,7 +285,8 @@ def tidy_storage(result_file):
|
|||
try:
|
||||
output = subprocess.check_output(
|
||||
["rbd", "ls", "--pool", "cinder-volumes"],
|
||||
stderr=subprocess.STDOUT)
|
||||
stderr=subprocess.STDOUT,
|
||||
universal_newlines=True)
|
||||
except subprocess.CalledProcessError:
|
||||
LOG.error("Failed to access rbd cinder-volumes pool")
|
||||
raise TidyStorageFail(
|
||||
|
@ -298,7 +303,8 @@ def tidy_storage(result_file):
|
|||
try:
|
||||
output = subprocess.check_output(
|
||||
["rbd", "snap", "list", volume],
|
||||
stderr=subprocess.STDOUT)
|
||||
stderr=subprocess.STDOUT,
|
||||
universal_newlines=True)
|
||||
|
||||
keep_snap = False
|
||||
for line in output.split('\n'):
|
||||
|
@ -358,7 +364,8 @@ def tidy_storage(result_file):
|
|||
try:
|
||||
output = subprocess.check_output(
|
||||
["rbd", "ls", "--pool", "cinder-volumes"],
|
||||
stderr=subprocess.STDOUT)
|
||||
stderr=subprocess.STDOUT,
|
||||
universal_newlines=True)
|
||||
except subprocess.CalledProcessError:
|
||||
LOG.error("Failed to access rbd cinder-volumes pool")
|
||||
raise TidyStorageFail("Failed to access rbd cinder-volumes pool")
|
||||
|
@ -383,7 +390,8 @@ def tidy_storage(result_file):
|
|||
# Find out if the volume is a bootable one
|
||||
output = subprocess.check_output(
|
||||
["rbd", "info", volume],
|
||||
stderr=subprocess.STDOUT)
|
||||
stderr=subprocess.STDOUT,
|
||||
universal_newlines=True)
|
||||
|
||||
bootable = False
|
||||
for line in output.split('\n'):
|
||||
|
@ -394,7 +402,9 @@ def tidy_storage(result_file):
|
|||
# Find out if the volume has any snapshots.
|
||||
print("Checking if volume %s has snapshots...\n" % vol_id)
|
||||
output = subprocess.check_output(
|
||||
["rbd", "snap", "list", volume], stderr=subprocess.STDOUT)
|
||||
["rbd", "snap", "list", volume],
|
||||
stderr=subprocess.STDOUT,
|
||||
universal_newlines=True)
|
||||
|
||||
snap_l = [item.strip() for item in output.split(' ')
|
||||
if item.find('snapshot-') != -1]
|
||||
|
@ -428,11 +438,13 @@ def tidy_storage(result_file):
|
|||
del_snap = '{}@{}'.format(volume, snap)
|
||||
output = subprocess.check_output(
|
||||
["rbd", "snap", "unprotect", del_snap],
|
||||
stderr=subprocess.STDOUT)
|
||||
stderr=subprocess.STDOUT,
|
||||
universal_newlines=True)
|
||||
|
||||
output = subprocess.check_output(
|
||||
["rbd", "snap", "rm", del_snap],
|
||||
stderr=subprocess.STDOUT)
|
||||
stderr=subprocess.STDOUT,
|
||||
universal_newlines=True)
|
||||
|
||||
except Exception as e:
|
||||
LOG.exception(e)
|
||||
|
@ -468,7 +480,8 @@ def tidy_storage(result_file):
|
|||
print("Checking if volume %s has snapshots...\n" % vol_id)
|
||||
output = subprocess.check_output(
|
||||
["rbd", "snap", "list", volume],
|
||||
stderr=subprocess.STDOUT)
|
||||
stderr=subprocess.STDOUT,
|
||||
universal_newlines=True)
|
||||
|
||||
snap_l = [item.strip() for item in output.split(' ')
|
||||
if item.find('snapshot-') != -1]
|
||||
|
|
|
@ -242,7 +242,8 @@ def create_simplex_backup(software_upgrade):
|
|||
'ansible-playbook',
|
||||
'-e', ' '.join(backup_vars),
|
||||
sysinv_constants.ANSIBLE_PLATFORM_BACKUP_PLAYBOOK]
|
||||
proc = subprocess.Popen(args, stdout=subprocess.PIPE)
|
||||
proc = subprocess.Popen(args, stdout=subprocess.PIPE,
|
||||
universal_newlines=True)
|
||||
out, _ = proc.communicate()
|
||||
LOG.info(out)
|
||||
if proc.returncode:
|
||||
|
|
|
@ -60,7 +60,8 @@ def restart_service(name):
|
|||
def check_sm_service(service, state):
|
||||
""" Check whether an SM service has the supplied state """
|
||||
try:
|
||||
output = subprocess.check_output(["sm-query", "service", service])
|
||||
output = subprocess.check_output(["sm-query", "service", service],
|
||||
universal_newlines=True)
|
||||
return state in output
|
||||
except subprocess.CalledProcessError:
|
||||
return False
|
||||
|
@ -321,7 +322,8 @@ def is_ssh_parent():
|
|||
"""Determine if current process is started from a ssh session"""
|
||||
command = ('pstree -s %d' % (os.getpid()))
|
||||
try:
|
||||
cmd_output = subprocess.check_output(command, shell=True)
|
||||
cmd_output = subprocess.check_output(command, shell=True,
|
||||
universal_newlines=True)
|
||||
if "ssh" in cmd_output:
|
||||
return True
|
||||
else:
|
||||
|
|
|
@ -56,14 +56,16 @@ def _command(arguments1, arguments2=None):
|
|||
process = subprocess.Popen(
|
||||
arguments1,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
stderr=subprocess.PIPE,
|
||||
universal_newlines=True)
|
||||
|
||||
if arguments2:
|
||||
process2 = subprocess.Popen(
|
||||
arguments2,
|
||||
stdin=process.stdout,
|
||||
stdout=subprocess.PIPE,
|
||||
shell=False)
|
||||
shell=False,
|
||||
universal_newlines=True)
|
||||
process.stdout.close()
|
||||
process = process2
|
||||
|
||||
|
@ -108,7 +110,8 @@ def get_sgdisk_info(device_path):
|
|||
try:
|
||||
sgdisk_process = subprocess.Popen(sgdisk_command,
|
||||
stdout=subprocess.PIPE,
|
||||
shell=True)
|
||||
shell=True,
|
||||
universal_newlines=True)
|
||||
except Exception as e:
|
||||
LOG.exception("Could not retrieve partition information: %s" % e)
|
||||
raise
|
||||
|
|
|
@ -51,7 +51,8 @@ def is_containerized_armada_installed():
|
|||
"--namespace armada --filter armada --output json " \
|
||||
"--kubeconfig {} ".format(KUBERNETES_ADMIN_CONF)
|
||||
result = subprocess.check_output(cmd, shell=True,
|
||||
stderr=subprocess.STDOUT)
|
||||
stderr=subprocess.STDOUT,
|
||||
universal_newlines=True)
|
||||
if not json.loads(result):
|
||||
return False
|
||||
return True
|
||||
|
@ -65,7 +66,9 @@ def update_armada_helmv3():
|
|||
upgrade_script = 'upgrade-k8s-armada-helm.yml'
|
||||
cmd = 'ansible-playbook {}/{}'.format(playbooks_root, upgrade_script)
|
||||
sub = subprocess.Popen(cmd, shell=True,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
universal_newlines=True)
|
||||
|
||||
stdout, stderr = sub.communicate()
|
||||
|
||||
|
|
|
@ -58,7 +58,9 @@ def main():
|
|||
|
||||
def execute_command(cmd):
|
||||
sub = subprocess.Popen(cmd, shell=True,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
universal_newlines=True)
|
||||
|
||||
stdout, stderr = sub.communicate()
|
||||
if sub.returncode != 0:
|
||||
|
|
|
@ -56,7 +56,9 @@ def create_deployment_ns():
|
|||
"kubectl --kubeconfig=/etc/kubernetes/admin.conf apply -f -" % \
|
||||
deployment_ns_yaml
|
||||
sub = subprocess.Popen(cmd, shell=True,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
universal_newlines=True)
|
||||
|
||||
stdout, stderr = sub.communicate()
|
||||
if sub.returncode != 0:
|
||||
|
|
|
@ -102,7 +102,9 @@ def update_dc_root_ca():
|
|||
"kubectl --kubeconfig=/etc/kubernetes/admin.conf apply -f -" % \
|
||||
resource
|
||||
sub = subprocess.Popen(cmd, shell=True,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
universal_newlines=True)
|
||||
|
||||
stdout, stderr = sub.communicate()
|
||||
if sub.returncode != 0:
|
||||
|
|
|
@ -77,7 +77,9 @@ def is_subcloud():
|
|||
|
||||
def execute_command(cmd):
|
||||
sub = subprocess.Popen(cmd, shell=True,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
universal_newlines=True)
|
||||
|
||||
stdout, stderr = sub.communicate()
|
||||
if sub.returncode != 0:
|
||||
|
|
|
@ -46,7 +46,9 @@ def apply_mandatory_psp_policies():
|
|||
"bringup-essential-services/files/psp-policies.yaml"
|
||||
|
||||
sub = subprocess.Popen(cmd, shell=True,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
universal_newlines=True)
|
||||
|
||||
stdout, stderr = sub.communicate()
|
||||
if sub.returncode != 0:
|
||||
|
|
Loading…
Reference in New Issue