Skip to content

Commit

Permalink
Merge pull request #103 from tasleson/no_ssl_testing
Browse files Browse the repository at this point in the history
test: allow for testing without SSL
  • Loading branch information
tasleson authored Mar 1, 2024
2 parents 78a7e2b + 4dee26a commit 0b8eec6
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 3 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ jobs:
steps:
- checkout
- run: sudo test/test.sh
- run: sudo test/test_no_ssl.sh
13 changes: 12 additions & 1 deletion client
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]

Expand Down
1 change: 1 addition & 0 deletions targetd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 21 additions & 2 deletions test/lsm_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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=$?
Expand Down
3 changes: 3 additions & 0 deletions test/targetd_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions test/test_no_ssl.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0b8eec6

Please sign in to comment.