Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

Commit

Permalink
Merge pull request #104 from otcshare/pylint_fixes
Browse files Browse the repository at this point in the history
OP-4034 and OP-4062 pylint fixes
  • Loading branch information
relhwigi authored Sep 29, 2020
2 parents 0caeaf5 + 7565279 commit bc17b87
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 358 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
""" EIS integration module """
import enum
import os
import sys
import json
import logging
import argparse
import shlex
import subprocess
import zmq
import zmq.auth
Expand Down Expand Up @@ -47,8 +44,9 @@ def load_json(json_path):
try:
with open(json_path, 'r') as json_file:
return json.load(json_file)
except IOError as e:
logging.error("I/O error occurred during loading of {} json file: {}".format(json_path, e))
except IOError as err:
logging.error("I/O error occurred during loading of %s json file: %s",
json_path, err)
raise EisIntegError(CODES.FILE_SYSTEM_ERROR)


Expand All @@ -62,13 +60,13 @@ def put_zmqkeys(appname):

try:
etcd_put("/Publickeys/" + appname, pub_key)
except Exception:
logging.error("Error putting Etcd public key for {}".format(appname))
except RuntimeError:
logging.error("Error putting Etcd public key for %s", appname)

try:
etcd_put("/" + appname + "/private_key", secret_key)
except Exception:
logging.error("Error putting Etcd private key for {}".format(appname))
except RuntimeError:
logging.error("Error putting Etcd private key for %s", appname)

def check_zmqkeys(appname):
""" Check if public/private key already exist in etcd for given app. Returns
Expand Down Expand Up @@ -97,13 +95,16 @@ def check_zmqkeys(appname):
def enable_etcd_auth(password):
""" Enable Auth for etcd and Create root user with root role """
try:
subprocess.check_output(["etcdctl", "user", "add", "root:"+password], stderr=subprocess.STDOUT)
subprocess.check_output(["etcdctl", "role", "add", "root"], stderr=subprocess.STDOUT)
subprocess.check_output(["etcdctl", "user", "grant-role", "root", "root"], stderr=subprocess.STDOUT)
subprocess.check_output(["etcdctl", "user", "add", "root:"+password],
stderr=subprocess.STDOUT)
subprocess.check_output(["etcdctl", "role", "add", "root"],
stderr=subprocess.STDOUT)
subprocess.check_output(["etcdctl", "user", "grant-role", "root", "root"],
stderr=subprocess.STDOUT)
subprocess.check_output(["etcdctl", "auth", "enable"], stderr=subprocess.STDOUT)
logging.info("Authentication has been enabled.")
except subprocess.CalledProcessError as e:
logging.error("Error while enabling authentication: {}".format(e))
except subprocess.CalledProcessError as err:
logging.error("Error while enabling authentication: %s", err)
raise EisIntegError(CODES.EXT_CMD_ERROR)

def etcd_put(key, value):
Expand All @@ -114,16 +115,16 @@ def etcd_put(key, value):
"""
try:
subprocess.check_output(["etcdctl", "put", "--", key, value], stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
logging.error("Error returned while adding the {} key to the etcd: {}".format(key, e))
except subprocess.CalledProcessError as err:
logging.error("Error returned while adding the %s key to the etcd: %s", key, err)
raise EisIntegError(CODES.EXT_CMD_ERROR)


def etcd_put_json(json_data):
""" Adds the contents of the json file to the etcd database """
for key, value in json_data.items():
etcd_put(key, bytes(json.dumps(value, indent=4).encode()))
logging.info("Value for the {} key has been added to the etcd.".format(key))
logging.info("Value for the %s key has been added to the etcd.", key)

def create_etcd_users(appname):
""" Create etcd user and role for given app. Allow Read only access
Expand All @@ -133,22 +134,28 @@ def create_etcd_users(appname):
:type appname: String
"""
try:
subprocess.check_output(["etcdctl", "user", "add", appname, "--no-password"], stderr=subprocess.STDOUT)
logging.info("User {} has been created.".format(appname))
except subprocess.CalledProcessError as e:
logging.error("Error while creating {} user: {}".format(appname, e))
subprocess.check_output(["etcdctl", "user", "add", appname, "--no-password"],
stderr=subprocess.STDOUT)
logging.info("User %s has been created.", appname)
except subprocess.CalledProcessError as err:
logging.error("Error while creating %s user: %s", appname, err)
raise EisIntegError(CODES.EXT_CMD_ERROR)

try:
subprocess.check_output(["etcdctl", "role", "add", appname], stderr=subprocess.STDOUT)
subprocess.check_output(["etcdctl", "user", "grant-role", appname, appname], stderr=subprocess.STDOUT)
subprocess.check_output(["etcdctl", "role", "grant-permission", appname, "read", "/"+appname+"/", "--prefix"], stderr=subprocess.STDOUT)
subprocess.check_output(["etcdctl", "role", "grant-permission", appname, "readwrite", "/"+appname+"/datastore", "--prefix"], stderr=subprocess.STDOUT)
subprocess.check_output(["etcdctl", "role", "grant-permission", appname, "read", "/Publickeys/", "--prefix"], stderr=subprocess.STDOUT)
subprocess.check_output(["etcdctl", "role", "grant-permission", appname, "read", "/GlobalEnv/", "--prefix"], stderr=subprocess.STDOUT)
logging.info("Role {} has been created.".format(appname))
except subprocess.CalledProcessError as e:
logging.error("Error while creating {} role: {}".format(appname, e))
subprocess.check_output(["etcdctl", "user", "grant-role", appname, appname],
stderr=subprocess.STDOUT)
subprocess.check_output(["etcdctl", "role", "grant-permission", appname,
"read", "/"+appname+"/", "--prefix"], stderr=subprocess.STDOUT)
subprocess.check_output(["etcdctl", "role", "grant-permission", appname, "readwrite",
"/"+appname+"/datastore", "--prefix"], stderr=subprocess.STDOUT)
subprocess.check_output(["etcdctl", "role", "grant-permission", appname,
"read", "/Publickeys/", "--prefix"], stderr=subprocess.STDOUT)
subprocess.check_output(["etcdctl", "role", "grant-permission", appname,
"read", "/GlobalEnv/", "--prefix"], stderr=subprocess.STDOUT)
logging.info("Role %s has been created.", appname)
except subprocess.CalledProcessError as err:
logging.error("Error while creating %s role: %s", appname, err)
raise EisIntegError(CODES.EXT_CMD_ERROR)


Expand All @@ -159,7 +166,7 @@ def read_config(client):
:type client: String
"""
logging.info("Read the configuration from etcd")
subprocess.run(["etcdctl", "get", client, "--prefix"])
subprocess.run(["etcdctl", "get", client, "--prefix"], check=True)

def etcd_remove_key(key):
""" Remove key from etcd
Expand All @@ -180,8 +187,8 @@ def remove_user_privilege(name):
try:
subprocess.check_output(["etcdctl", "role", "delete", name], stderr=subprocess.STDOUT)
logging.info("Role {} has been removed.".format(name))
except subprocess.CalledProcessError as e:
logging.error("Error returned while removing the {} role: {}".format(name, e))
except subprocess.CalledProcessError as err:
logging.error("Error returned while removing the {} role: {}".format(name, err))
raise EisIntegError(CODES.EXT_CMD_ERROR)

def remove_user(name):
Expand All @@ -191,9 +198,9 @@ def remove_user(name):
"""
try:
subprocess.check_output(["etcdctl", "user", "delete", name], stderr=subprocess.STDOUT)
logging.info("User {} has been removed.".format(name))
except subprocess.CalledProcessError as e:
logging.error("Error returned while removing the {} user: {}".format(name, e))
logging.info("User %s has been removed.", name)
except subprocess.CalledProcessError as err:
logging.error("Error returned while removing the %s user: %s", name, err)
raise EisIntegError(CODES.EXT_CMD_ERROR)

def deploy_eis_app():
Expand All @@ -219,7 +226,7 @@ def remove_eis_app(appname, del_keys=False):

def remove_eis_key(key):
""" Remove existing eis key. """
subprocess.run(["etcdctl", "del", key, "--prefix"])
subprocess.run(["etcdctl", "del", key, "--prefix"], check=True)


def init_logger():
Expand All @@ -240,11 +247,11 @@ def extract_etcd_endpoint():

try:
etcd_endpoint_ip = subprocess.check_output(["kubectl", "get", "svc", "-n", "eis", "-o",
jsonpath_ip_string]).decode('utf-8')
jsonpath_ip_string]).decode('utf-8')
etcd_endpoint_port = subprocess.check_output(["kubectl", "get", "svc", "-n", "eis", "-o",
jsonpath_port_string]).decode('utf-8')
except subprocess.CalledProcessError as e:
logging.error("Failed to call kubectl command to extract ETCD endpoint: '{}'".format(e))
jsonpath_port_string]).decode('utf-8')
except subprocess.CalledProcessError as err:
logging.error("Failed to call kubectl command to extract ETCD endpoint: '%s'", err)
raise EisIntegError(CODES.EXT_CMD_ERROR)

return etcd_endpoint_ip + ':' + etcd_endpoint_port
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import logging
import os
import sys
import traceback
import eis_integ

def parse_arguments(_cli_args):
Expand Down Expand Up @@ -51,5 +50,5 @@ def main(args):
try:
sys.exit(main(parse_arguments(sys.argv[1:])).value)
except eis_integ.EisIntegError as exception:
logging.error("Error while doing operations on ETCD users: {}".format(exception))
logging.error("Error while doing operations on ETCD users: %s", exception)
sys.exit(exception.code.value)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import logging
import os
import sys
import traceback
import eis_integ

def parse_arguments(_cli_args):
Expand Down Expand Up @@ -37,5 +36,5 @@ def main(args):
try:
sys.exit(main(parse_arguments(sys.argv[1:])).value)
except eis_integ.EisIntegError as exception:
logging.error("Error while adding entries to ETCD database: {}".format(exception))
logging.error("Error while adding entries to ETCD database: %s", exception)
sys.exit(exception.code.value)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import logging
import os
import sys
import traceback
import eis_integ


Expand Down Expand Up @@ -47,5 +46,5 @@ def main(args):
try:
sys.exit(main(parse_arguments(sys.argv[1:])).value)
except eis_integ.EisIntegError as exception:
logging.error("Error while generating ZMQ keys: {}".format(exception))
logging.error("Error while generating ZMQ keys: %s", str(exception))
sys.exit(exception.code.value)
2 changes: 1 addition & 1 deletion network-functions/xran/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ verifyTests()

echo "STEP 2: VERIFY TESTS RESULTS"

python "$XRAN_DIR/app/test_verification.py" --ran "$tech" --cat "$cat" --testcase "$tc" --mu "$mu" --b "$bw" --verbose "$TEST_VERBOSE"
python "$XRAN_DIR/app/test_verification.py" --ran "$tech" --cat "$cat" --testcase "$tc" --m_u "$mu" --b "$bw" --verbose "$TEST_VERBOSE"
echo -e "\t$(date) xRAN sample app test and test verififaction completed"

}
Expand Down
Loading

0 comments on commit bc17b87

Please sign in to comment.