summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyo Nakamura <upa@haeena.net>2023-03-12 20:37:57 +0900
committerRyo Nakamura <upa@haeena.net>2023-03-12 20:37:57 +0900
commite2da5811ce2c9006ecb4319d8b1c40128ac2ff67 (patch)
tree537e53bd38af01766c250bfdb0c48bd0dd722d29
parent597a7a8cbae48a4f1026d6970e78b43b157bc70b (diff)
test: add test_python.py for testing python-mscp
Dockerfiles also adapt themselvs for testing python-mscp bindings.
-rw-r--r--docker/alpine-3.17.Dockerfile14
-rw-r--r--docker/centos-8.Dockerfile5
-rw-r--r--docker/rocky-8.6.Dockerfile6
-rw-r--r--docker/ubuntu-20.04.Dockerfile6
-rw-r--r--docker/ubuntu-22.04.Dockerfile7
-rwxr-xr-xscripts/test-in-container.sh2
-rw-r--r--test/test_e2e.py5
-rw-r--r--test/test_python.py104
8 files changed, 142 insertions, 7 deletions
diff --git a/docker/alpine-3.17.Dockerfile b/docker/alpine-3.17.Dockerfile
index bf5679e..d2c899b 100644
--- a/docker/alpine-3.17.Dockerfile
+++ b/docker/alpine-3.17.Dockerfile
@@ -21,10 +21,11 @@ RUN cd ${mscpdir} \
&& cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake \
- -DBUILD_STATIC=ON -DBUILD_CONAN=ON \
+ -DBUILD_CONAN=ON -DBUILD_STATIC=ON \
&& make \
&& cp mscp /usr/bin/ \
- && cp mscp /mscp/build/mscp_0.0.6-alpine-3.17-x86_64.static
+ && cp mscp /mscp/build/mscp_$(cat ${mscpdir}/VERSION)-alpine-3.17-x86_64.static \
+ && cp mscp /mscp/build/mscp.linux.x86.static
# copy mscp to PKG FILE NAME because this build doesn't use CPACK
@@ -33,3 +34,12 @@ RUN ssh-keygen -A
RUN mkdir /var/run/sshd \
&& ssh-keygen -f /root/.ssh/id_rsa -N "" \
&& mv /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys
+
+# install mscp python module
+RUN cd ${mscpdir} \
+ && python3 setup.py install --user
+
+# Need Fix: A trick putting libmscp.so to python mscp module dir does not work on alpine,
+# so install libmscp.
+RUN cd ${mscpdir}/build \
+ && make install
diff --git a/docker/centos-8.Dockerfile b/docker/centos-8.Dockerfile
index d9a4f20..3059715 100644
--- a/docker/centos-8.Dockerfile
+++ b/docker/centos-8.Dockerfile
@@ -11,7 +11,7 @@ RUN sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|
# install pytest, sshd for test, and rpm-build
RUN set -ex && yum -y update && yum -y install \
- python3 python3-pip openssh openssh-server openssh-clients rpm-build
+ python3 python3-pip python3-devel openssh openssh-server openssh-clients rpm-build
RUN python3 -m pip install pytest
@@ -34,3 +34,6 @@ RUN cd ${mscpdir} \
&& cpack -G RPM CPackConfig.cmake \
&& rpm -iv *.rpm
+# install mscp python module
+RUN cd ${mscpdir} \
+ && python3 setup.py install --user
diff --git a/docker/rocky-8.6.Dockerfile b/docker/rocky-8.6.Dockerfile
index abb2cf5..35d18a8 100644
--- a/docker/rocky-8.6.Dockerfile
+++ b/docker/rocky-8.6.Dockerfile
@@ -6,7 +6,7 @@ COPY . ${mscpdir}
# install pytest, sshd for test, and rpm-build
RUN set -ex && yum -y install \
- python3 python3-pip openssh openssh-server openssh-clients rpm-build
+ python3 python3-pip python3-devel openssh openssh-server openssh-clients rpm-build
RUN python3 -m pip install pytest
@@ -29,3 +29,7 @@ RUN cd ${mscpdir} \
&& cpack -G RPM CPackConfig.cmake \
&& rpm -iv *.rpm
+# install mscp python module
+RUN cd ${mscpdir} \
+ && python3 setup.py install --user
+
diff --git a/docker/ubuntu-20.04.Dockerfile b/docker/ubuntu-20.04.Dockerfile
index e1dac03..d00f7c8 100644
--- a/docker/ubuntu-20.04.Dockerfile
+++ b/docker/ubuntu-20.04.Dockerfile
@@ -10,7 +10,7 @@ RUN set -ex && apt-get update && apt-get install -y --no-install-recommends \
# install pytest, and sshd for test
RUN apt-get install -y --no-install-recommends \
- python3 python3-pip openssh-server
+ python3 python3-pip python3-dev openssh-server
RUN python3 -m pip install pytest
@@ -33,3 +33,7 @@ RUN cd ${mscpdir} \
&& make \
&& cpack -G DEB CPackConfig.cmake \
&& dpkg -i *.deb
+
+# install mscp python module
+RUN cd ${mscpdir} \
+ && python3 setup.py install --user
diff --git a/docker/ubuntu-22.04.Dockerfile b/docker/ubuntu-22.04.Dockerfile
index 26ba009..e2c6f47 100644
--- a/docker/ubuntu-22.04.Dockerfile
+++ b/docker/ubuntu-22.04.Dockerfile
@@ -10,7 +10,7 @@ RUN set -ex && apt-get update && apt-get install -y --no-install-recommends \
# install pytest, and sshd for test
RUN apt-get install -y --no-install-recommends \
- python3 python3-pip openssh-server
+ python3 python3-pip python3-dev openssh-server
RUN python3 -m pip install pytest
@@ -33,3 +33,8 @@ RUN cd ${mscpdir} \
&& make \
&& cpack -G DEB CPackConfig.cmake \
&& dpkg -i *.deb
+
+# install mscp python module
+RUN cd ${mscpdir} \
+ && python3 setup.py install --user
+
diff --git a/scripts/test-in-container.sh b/scripts/test-in-container.sh
index 49891c7..1e003b3 100755
--- a/scripts/test-in-container.sh
+++ b/scripts/test-in-container.sh
@@ -13,5 +13,7 @@ if [ ! -e /var/run/sshd.pid ]; then
/usr/sbin/sshd
fi
+ssh-keyscan localhost >> ${HOME}/.ssh/known_hosts
+
# Run test
python3 -m pytest ../test -v
diff --git a/test/test_e2e.py b/test/test_e2e.py
index 66c6f63..018be96 100644
--- a/test/test_e2e.py
+++ b/test/test_e2e.py
@@ -1,6 +1,9 @@
+"""
+test_e2e.py: End-to-End test for mscp executable.
+"""
+
import pytest
-import hashlib
import os
from subprocess import check_call, CalledProcessError, PIPE
diff --git a/test/test_python.py b/test/test_python.py
new file mode 100644
index 0000000..3038b76
--- /dev/null
+++ b/test/test_python.py
@@ -0,0 +1,104 @@
+
+"""
+test_python.py: Testing libmscp through the mscp python binding.
+"""
+
+import pytest
+import mscp
+import os
+from util import File, check_same_md5sum
+
+def test_create_and_release():
+ m = mscp.mscp("localhost", mscp.LOCAL2REMOTE)
+ m.cleanup()
+
+
+""" copy test """
+
+remote = "localhost"
+remote_prefix = "{}/".format(os.getcwd()) # use current dir
+param_remote_prefix_and_direction = [
+ ("", remote_prefix, mscp.LOCAL2REMOTE), (remote_prefix, "", mscp.REMOTE2LOCAL)
+]
+
+
+param_single_copy = [
+ (File("src", size = 64), File("dst")),
+ (File("src", size = 4096 * 1), File("dst")),
+ (File("src", size = 128 * 1024 * 1024), File("dst")),
+]
+
+@pytest.mark.parametrize("src_prefix, dst_prefix, direction",
+ param_remote_prefix_and_direction)
+@pytest.mark.parametrize("src, dst", param_single_copy)
+def test_single_copy(src_prefix, dst_prefix, direction, src, dst):
+ src.make()
+ m = mscp.mscp(remote, direction)
+ m.copy(src_prefix + src.path, dst_prefix + dst.path)
+ assert check_same_md5sum(src, dst)
+ src.cleanup()
+ dst.cleanup()
+
+
+param_double_copy = [
+ (File("src1", size = 1024 * 1024), File("src2", size = 1024 * 1024),
+ File("dst/src1"), File("dst/src2")
+ )
+]
+@pytest.mark.parametrize("src_prefix, dst_prefix, direction",
+ param_remote_prefix_and_direction)
+@pytest.mark.parametrize("s1, s2, d1, d2", param_double_copy)
+def test_double_copy(src_prefix, dst_prefix, direction, s1, s2, d1, d2):
+ s1.make()
+ s2.make()
+ mscp.mscp(remote, direction).copy([src_prefix + s1.path, src_prefix + s2.path],
+ dst_prefix + "dst")
+ assert check_same_md5sum(s1, d1)
+ assert check_same_md5sum(s2, d2)
+ s1.cleanup()
+ s2.cleanup()
+ d1.cleanup()
+ d2.cleanup()
+
+
+param_single_copy = [
+ (File("src", size = 1024 * 1024 * 4), File("dst")),
+]
+
+param_kwargs = [
+ { "nr_threads": 6 },
+ { "nr_ahead": 64 },
+ { "min_chunk_sz": 1 * 1024 * 1024 },
+ { "max_chunk_sz": 64 * 1024 * 1024 },
+ { "coremask": "0x0f" },
+ { "severity": mscp.SEVERITY_NONE },
+ { "cipher": "aes128-gcm@openssh.com" },
+ { "compress": "yes" },
+ { "no_hostkey_check": True },
+ { "enable_nagle": True },
+]
+
+@pytest.mark.parametrize("src_prefix, dst_prefix, direction",
+ param_remote_prefix_and_direction)
+@pytest.mark.parametrize("src, dst", param_single_copy)
+@pytest.mark.parametrize("kw", param_kwargs)
+def test_kwargs(src_prefix, dst_prefix, direction, src, dst, kw):
+ src.make()
+ m = mscp.mscp(remote, direction, **kw)
+ m.copy(src_prefix + src.path, dst_prefix + dst.path)
+ assert check_same_md5sum(src, dst)
+ src.cleanup()
+ dst.cleanup()
+
+def test_login_failed():
+ m = mscp.mscp("asdfasdf@" + remote, mscp.LOCAL2REMOTE)
+ with pytest.raises(RuntimeError) as e:
+ m.connect()
+
+ m = mscp.mscp(remote, mscp.LOCAL2REMOTE, login_name = "asdfadsf")
+ with pytest.raises(RuntimeError) as e:
+ m.connect()
+
+ m = mscp.mscp(remote, mscp.LOCAL2REMOTE, port = "65534")
+ with pytest.raises(RuntimeError) as e:
+ m.connect()