diff --git a/.circleci/config.yml b/.circleci/config.yml index 3b17940..c4a7978 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,3 +7,4 @@ jobs: steps: - checkout - run: sudo test/test.sh + - run: sudo test/test_no_ssl.sh diff --git a/client b/client index f8dc54c..1452d4f 100755 --- a/client +++ b/client @@ -31,10 +31,12 @@ # import json +import os import time import socket import base64 import ssl + from test import testlib from urllib.request import Request, urlopen @@ -45,7 +47,16 @@ host = "localhost" port = 18700 path = "/targetrpc" id_num = 1 -use_ssl = True + +# Allow us to test without SSL. +proto = os.getenv("TARGETD_UT_PROTO", "https") +print("CONNECT=%s" % proto) + +if proto == "https": + use_ssl = True +else: + use_ssl = False + pools = ["vg-targetd/thin_pool", "zfs_targetd/block_pool"] fs_pools = ["/mnt/btrfs", "/zfs_targetd/fs_pool"] diff --git a/targetd/main.py b/targetd/main.py index 1fc489d..4696deb 100644 --- a/targetd/main.py +++ b/targetd/main.py @@ -316,6 +316,7 @@ def wrap_socket(s): wrapped = context.wrap_socket(s, server_side=True) return wrapped + def main(): signal.signal(signal.SIGINT, handler) diff --git a/test/lsm_test.sh b/test/lsm_test.sh index 4a399ac..5689ba5 100755 --- a/test/lsm_test.sh +++ b/test/lsm_test.sh @@ -15,6 +15,10 @@ if [ -f "/etc/redhat-release" ]; then FEDORA=1 fi + +CONNECT="${TARGETD_UT_PROTO:-https}" +echo "CONNECT = $CONNECT" + if [ $FEDORA -eq 0 ]; then export DEBIAN_FRONTEND="noninteractive" @@ -48,10 +52,25 @@ if [ $FEDORA -eq 0 ]; then # Start up the daemon PYTHONPATH=$PYENV daemon/lsmd -v -d --plugindir `pwd`/plugin > $LSMDLOG 2>&1 & - PYTHONPATH=$PYENV test/plugin_test.py -v --uri targetd+ssl://admin@localhost?ca_cert_file=/tmp/targetd_cert.pem --password targetd + + + # We also may want to test without SSL support + if [[ "$CONNECT" = "http" ]]; then + echo "Using NON-ssl URI!" + PYTHONPATH=$PYENV test/plugin_test.py -v --uri targetd://admin@localhost --password targetd + else + PYTHONPATH=$PYENV test/plugin_test.py -v --uri targetd+ssl://admin@localhost?ca_cert_file=/tmp/targetd_cert.pem --password targetd + fi + else systemctl start libstoragemgmt.service - python3 test/plugin_test.py.in -v --uri targetd+ssl://admin@localhost?ca_cert_file=/tmp/targetd_cert.pem --password targetd + + if [[ "$CONNECT" = "http" ]]; then + echo "Using NON-ssl URI!" + python3 test/plugin_test.py.in -v --uri targetd://admin@localhost --password targetd + else + python3 test/plugin_test.py.in -v --uri targetd+ssl://admin@localhost?ca_cert_file=/tmp/targetd_cert.pem --password targetd + fi fi rc=$? diff --git a/test/targetd_test.py b/test/targetd_test.py index 6bbdb96..ceece11 100755 --- a/test/targetd_test.py +++ b/test/targetd_test.py @@ -661,6 +661,9 @@ def test_gp_export_operations(self): for block_pool in self._block_pools(): # Create a volume, then export it vol = TestTargetd._vol_create(block_pool, rs(length=6)) + # On slow systems is can take a bit before the newly created block device + # is really available. + time.sleep(10) export = self._export_create(block_pool, vol) self._export_destroy(export) self._vol_destroy(block_pool, vol) diff --git a/test/test.sh b/test/test.sh index 5e9245e..5fdeed0 100755 --- a/test/test.sh +++ b/test/test.sh @@ -10,6 +10,9 @@ clean_up () pkill lsmd || echo "Warning: Unable to end lsmd process" + # Give lsmd a moment to stop + sleep 1 + $COV_CMD report || echo "Warning: Unable to generate report" if [ $FEDORA -eq 0 ]; then @@ -90,6 +93,21 @@ echo "password: targetd" >> /etc/target/targetd.yaml # it, so make a self signed cert for testing ./test/make_test_cert.sh || clean_up 1 + +CONNECT="${TARGETD_UT_PROTO:-https}" + +echo "CONNECT = $CONNECT" + +# We also may want to test without SSL support +if [[ "$CONNECT" = "http" ]]; then + echo "Changing targetd.yaml to disable ssl" + sed -e 's/ssl: true/ssl: false/' -i /etc/target/targetd.yaml +fi + +echo "======= /etc/target/targetd.yaml contents =============" +cat /etc/target/targetd.yaml +echo "=======================================================" + # Create the needed block devices for lvm, btrfs, and zfs for testing truncate -s 1T /tmp/block1.img || clean_up 1 truncate -s 1T /tmp/block2.img || clean_up 1 diff --git a/test/test_no_ssl.sh b/test/test_no_ssl.sh new file mode 100755 index 0000000..62a503f --- /dev/null +++ b/test/test_no_ssl.sh @@ -0,0 +1,11 @@ +#!/bin/bash + + +# Getting an env variable to work with circle ci is problematic... + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +export TARGETD_UT_PROTO=http + +"$SCRIPT_DIR"/test.sh "$@" || exit 1 +exit 0 \ No newline at end of file