From bdf78b17aab0d51f49fb43dd809d7ae020335430 Mon Sep 17 00:00:00 2001 From: Mike Christie Date: Fri, 30 Mar 2018 02:04:25 -0500 Subject: [PATCH 1/2] drop OS and kernel check in pre_reqs_errors This drops the OS and kernel checks in pre_reqs_errors. We will rely on the kernel exporting the needed features and if not present we will return error for the specific command that is not supported. This also fixes the error code for gw creation so you get a error code like Failed : iscsi1 failed package validation checks - Found ceph_iscsi_config 2.3. 102.3 or newer required. instead of the Failed : Malformed REST API response due to the bug Mar 30 02:01:16 iscsi1 rbd-target-api[4050]: this_ver, this_rel = this_kernel.split('-') Mar 30 02:01:16 iscsi1 rbd-target-api[4050]: ValueError: need more than 1 value to unpack Signed-off-by: Mike Christie --- rbd-target-api.py | 67 +++++++++++++++-------------------------------- 1 file changed, 21 insertions(+), 46 deletions(-) diff --git a/rbd-target-api.py b/rbd-target-api.py index afbf1ba..43dd8c2 100755 --- a/rbd-target-api.py +++ b/rbd-target-api.py @@ -17,6 +17,8 @@ from rpm import labelCompare import rados +import pkg_resources + import werkzeug from flask import Flask, jsonify, make_response, request from rtslib_fb.utils import RTSLibError, normalize_wwn @@ -28,7 +30,7 @@ from ceph_iscsi_config.client import GWClient, CHAP from ceph_iscsi_config.common import Config from ceph_iscsi_config.utils import (get_ip, this_host, ipv4_addresses, - gen_file_hash, valid_rpm) + gen_file_hash) from gwcli.utils import (this_host, APIRequest, valid_gateway, valid_disk, valid_client, GatewayAPIError) @@ -1453,57 +1455,30 @@ def call_api(gateway_list, endpoint, element, http_method='put', api_vars=None): def pre_reqs_errors(): """ - function to check pre-req rpms are installed and at the relevant versions + function to check pre-req packages are installed and at the relevant version :return: list of configuration errors detected """ - valid_dists = ["redhat"] - valid_versions = ['7.4'] - - required_rpms = [ - {"name": "python-rtslib", - "version": "2.1.fb64", - "release": "0.1"}, - {"name": "tcmu-runner", - "version": "1.3.0", - "release": "0.2.3"} - ] - - k_vers = '3.10.0' - k_rel = '823.el7' - errors_found = [] + required_pkgs = [ + {"name": "rtslib_fb", + "version": "2.1.64"}, + {"name": "ceph_iscsi_config", + "version": "2.3"} + ] - dist, rel, dist_id = platform.linux_distribution(full_distribution_name=0) - - if dist.lower() in valid_dists: - if rel not in valid_versions: - errors_found.append("OS version is unsupported") - - # check rpm versions are OK - for rpm in required_rpms: - if not valid_rpm(rpm): - logger.error("RPM check for {} failed") - errors_found.append("{} rpm must be installed at >= " - "{}-{}".format(rpm['name'], - rpm['version'], - rpm['release'])) - else: - errors_found.append("OS is unsupported") - - # check the running kernel is OK (required kernel has patches to rbd.ko) - os_info = os.uname() - this_arch = os_info[-1] - this_kernel = os_info[2].replace(".{}".format(this_arch), '') - this_ver, this_rel = this_kernel.split('-', 1) - - # use labelCompare from the rpm module to handle the comparison - if labelCompare(('1', this_ver, this_rel), ('1', k_vers, k_rel)) < 0: - logger.error("Kernel version check failed") - errors_found.append("Kernel version too old - {}-{} " - "or above needed".format(k_vers, - k_rel)) + # We only check these 2 because ceph-iscsi-config via rtslib will check + # the kernel and tcmu-runner have support for the needed features we + # require dynamically. We can then more easily support distro kernels + # with backported tcmu patches. + + for pkg in required_pkgs: + version_str = pkg_resources.require(pkg['name'])[0].version + version = pkg_resources.parse_version(version_str) + if version < pkg_resources.parse_version(pkg['version']): + errors_found.append("Found {} {}. {} or newer required.".format( + pkg['name'], version_str, pkg['version'])) return errors_found From 66f739195035ad3c715b3ba69ef00dab4f3a6e8e Mon Sep 17 00:00:00 2001 From: Mike Christie Date: Fri, 30 Mar 2018 02:30:10 -0500 Subject: [PATCH 2/2] Return detail error during lun creation The last patch removed the OS and kernel checks. We instead rely on tcmu-runner and rtslib to check the kernel for us. This patch has us return a detailed error message. Instead of: Failed : disk create/update failed on iscsi1. LUN allocation failure we get something like: Failed : disk create/update failed on iscsi1. Could not set LIO device attribute cmd_time_out/qfull_time_out for device: rbd.disk_2. Kernel not supported. - error(Cannot find attribute: qfull_time_out) Signed-off-by: Mike Christie --- rbd-target-api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rbd-target-api.py b/rbd-target-api.py index 43dd8c2..01606e1 100755 --- a/rbd-target-api.py +++ b/rbd-target-api.py @@ -731,7 +731,7 @@ def _disk(image_id): lun.allocate() if lun.error: logger.error("LUN alloc problem - {}".format(lun.error_msg)) - return jsonify(message="LUN allocation failure"), 500 + return jsonify(message=lun.error_msg), 500 if request.form['mode'] == 'create': # new disk is allocated, so refresh the local config object