Translate python2 to python3

*opencas.py*: changed result class to contain text values instead of bytes,
translated chache configuring methods to py3,
*init script*: changed regex input on raw string to work in py3.

Signed-off-by: Slawomir_Jankowski <slawomir.jankowski@intel.com>
This commit is contained in:
Slawomir_Jankowski 2019-07-30 09:51:55 +02:00 committed by Slawomir_Jankowski
parent d01c26d629
commit 3d5d82f892
3 changed files with 10 additions and 12 deletions

View File

@ -1,10 +1,9 @@
#!/usr/bin/env python2 #!/usr/bin/env python3
# #
# Copyright(c) 2012-2019 Intel Corporation # Copyright(c) 2012-2019 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause-Clear # SPDX-License-Identifier: BSD-3-Clause-Clear
# #
from __future__ import print_function
import argparse import argparse
import sys import sys
import re import re
@ -42,7 +41,7 @@ def add_core_recursive(core, config):
.format(core.device, core.cache_id)) .format(core.device, core.cache_id))
exit(3) exit(3)
core.marked = True core.marked = True
match = re.match('/dev/cas(\d)-(\d).*', core.device) match = re.match(r'/dev/cas(\d)-(\d).*', core.device)
if match: if match:
cache_id,core_id = match.groups() cache_id,core_id = match.groups()
with_error = add_core_recursive(config.caches[int(cache_id)].cores[int(core_id)], config) with_error = add_core_recursive(config.caches[int(cache_id)].cores[int(core_id)], config)

View File

@ -1,10 +1,9 @@
#!/usr/bin/env python2 #!/usr/bin/env python3
# #
# Copyright(c) 2012-2019 Intel Corporation # Copyright(c) 2012-2019 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause-Clear # SPDX-License-Identifier: BSD-3-Clause-Clear
# #
from __future__ import print_function
import subprocess import subprocess
import time import time
import opencas import opencas

View File

@ -17,11 +17,11 @@ class casadm:
class result: class result:
def __init__(self, cmd): def __init__(self, cmd):
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) p = subprocess.run(cmd, universal_newlines=True, stdout=subprocess.PIPE,
self.exit_code = p.wait() stderr=subprocess.PIPE)
output = p.communicate() self.exit_code = p.returncode
self.stdout = output[0] self.stdout = p.stdout
self.stderr = output[1] self.stderr = p.stderr
class CasadmError(Exception): class CasadmError(Exception):
def __init__(self, result): def __init__(self, result):
@ -500,10 +500,10 @@ def start_cache(cache, load, force=False):
force=force) force=force)
def configure_cache(cache): def configure_cache(cache):
if cache.params.has_key('cleaning_policy'): if 'cleaning_policy' in cache.params:
casadm.set_param('cleaning', cache_id=cache.cache_id, casadm.set_param('cleaning', cache_id=cache.cache_id,
policy=cache.params['cleaning_policy']) policy=cache.params['cleaning_policy'])
if cache.params.has_key('ioclass_file'): if 'ioclass_file' in cache.params:
casadm.io_class_load_config(cache_id=cache.cache_id, casadm.io_class_load_config(cache_id=cache.cache_id,
ioclass_file=cache.params['ioclass_file']) ioclass_file=cache.params['ioclass_file'])