From 3d5d82f8922319f7f38d342969b4c522d336f773 Mon Sep 17 00:00:00 2001 From: Slawomir_Jankowski Date: Tue, 30 Jul 2019 09:51:55 +0200 Subject: [PATCH] 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 --- utils/casctl | 5 ++--- utils/open-cas-loader | 3 +-- utils/opencas.py | 14 +++++++------- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/utils/casctl b/utils/casctl index 89fb7bd..26efdae 100755 --- a/utils/casctl +++ b/utils/casctl @@ -1,10 +1,9 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # # Copyright(c) 2012-2019 Intel Corporation # SPDX-License-Identifier: BSD-3-Clause-Clear # -from __future__ import print_function import argparse import sys import re @@ -42,7 +41,7 @@ def add_core_recursive(core, config): .format(core.device, core.cache_id)) exit(3) core.marked = True - match = re.match('/dev/cas(\d)-(\d).*', core.device) + match = re.match(r'/dev/cas(\d)-(\d).*', core.device) if match: cache_id,core_id = match.groups() with_error = add_core_recursive(config.caches[int(cache_id)].cores[int(core_id)], config) diff --git a/utils/open-cas-loader b/utils/open-cas-loader index e1ffe31..b760d8a 100755 --- a/utils/open-cas-loader +++ b/utils/open-cas-loader @@ -1,10 +1,9 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # # Copyright(c) 2012-2019 Intel Corporation # SPDX-License-Identifier: BSD-3-Clause-Clear # -from __future__ import print_function import subprocess import time import opencas diff --git a/utils/opencas.py b/utils/opencas.py index b0e7900..1d4b640 100644 --- a/utils/opencas.py +++ b/utils/opencas.py @@ -17,11 +17,11 @@ class casadm: class result: def __init__(self, cmd): - p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - self.exit_code = p.wait() - output = p.communicate() - self.stdout = output[0] - self.stderr = output[1] + p = subprocess.run(cmd, universal_newlines=True, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + self.exit_code = p.returncode + self.stdout = p.stdout + self.stderr = p.stderr class CasadmError(Exception): def __init__(self, result): @@ -500,10 +500,10 @@ def start_cache(cache, load, force=False): force=force) 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, 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, ioclass_file=cache.params['ioclass_file'])