]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
python-common: Move Drive Group tests
authorSebastian Wagner <sebastian.wagner@suse.com>
Mon, 8 Jul 2019 08:52:33 +0000 (10:52 +0200)
committerSebastian Wagner <sebastian.wagner@suse.com>
Fri, 26 Jul 2019 10:05:35 +0000 (12:05 +0200)
Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
src/pybind/mgr/orchestrator_cli/requirements.txt
src/pybind/mgr/orchestrator_cli/test_orchestrator.py
src/python-common/ceph/tests/__init__.py [new file with mode: 0644]
src/python-common/ceph/tests/test_drive_group.py [new file with mode: 0644]
src/python-common/tox.ini [new file with mode: 0644]
src/script/run_tox.sh [new file with mode: 0755]

index 8ef288ecc14c6a0b73af27b8aa4023165c8b51dd..62843e4929ea1a5ece739bbc1f8d80dd9617c49d 100644 (file)
@@ -1 +1,2 @@
 tox==2.9.1
+-e ../../../python-common
\ No newline at end of file
index 3374d5a3ca512322cb724d79543269c5439e5a39..bf2290391b5051322049ff1bbcc728232681423c 100644 (file)
@@ -2,39 +2,8 @@ from __future__ import absolute_import
 import pytest
 
 
-from ceph.deployment.drive_group import DriveGroupSpec, DeviceSelection, DriveGroupValidationError
 from orchestrator import InventoryDevice, ReadCompletion, raise_if_exception
 
-
-def test_DriveGroup():
-    dg_json = {
-        'host_pattern': 'hostname',
-        'data_devices': {'paths': ['/dev/sda']}
-    }
-
-    dg = DriveGroupSpec.from_json(dg_json)
-    assert dg.hosts(['hostname']) == ['hostname']
-    assert dg.data_devices.paths == ['/dev/sda']
-
-
-def test_DriveGroup_fail():
-    with pytest.raises(TypeError):
-        DriveGroupSpec.from_json({})
-
-
-def test_drivegroup_pattern():
-    dg = DriveGroupSpec('node[1-3]', DeviceSelection())
-    assert dg.hosts(['node{}'.format(i) for i in range(10)]) == ['node1', 'node2', 'node3']
-
-
-def test_drive_selection():
-    devs = DeviceSelection(paths=['/dev/sda'])
-    spec = DriveGroupSpec('node_name', data_devices=devs)
-    assert spec.data_devices.paths == ['/dev/sda']
-
-    with pytest.raises(DriveGroupValidationError, match='exclusive'):
-        DeviceSelection(paths=['/dev/sda'], rotates=False)
-
 def test_inventory_device():
     i_d = InventoryDevice()
     s = i_d.pretty_print()
diff --git a/src/python-common/ceph/tests/__init__.py b/src/python-common/ceph/tests/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/src/python-common/ceph/tests/test_drive_group.py b/src/python-common/ceph/tests/test_drive_group.py
new file mode 100644 (file)
index 0000000..71a3a16
--- /dev/null
@@ -0,0 +1,32 @@
+import pytest
+
+from ceph.deployment.drive_group import DriveGroupSpec, DeviceSelection, DriveGroupValidationError
+
+def test_DriveGroup():
+    dg_json = {
+        'host_pattern': 'hostname',
+        'data_devices': {'paths': ['/dev/sda']}
+    }
+
+    dg = DriveGroupSpec.from_json(dg_json)
+    assert dg.hosts(['hostname']) == ['hostname']
+    assert dg.data_devices.paths == ['/dev/sda']
+
+
+def test_DriveGroup_fail():
+    with pytest.raises(TypeError):
+        DriveGroupSpec.from_json({})
+
+
+def test_drivegroup_pattern():
+    dg = DriveGroupSpec('node[1-3]', DeviceSelection())
+    assert dg.hosts(['node{}'.format(i) for i in range(10)]) == ['node1', 'node2', 'node3']
+
+
+def test_drive_selection():
+    devs = DeviceSelection(paths=['/dev/sda'])
+    spec = DriveGroupSpec('node_name', data_devices=devs)
+    assert spec.data_devices.paths == ['/dev/sda']
+
+    with pytest.raises(DriveGroupValidationError, match='exclusive'):
+        DeviceSelection(paths=['/dev/sda'], rotates=False)
diff --git a/src/python-common/tox.ini b/src/python-common/tox.ini
new file mode 100644 (file)
index 0000000..96d5e0d
--- /dev/null
@@ -0,0 +1,18 @@
+[tox]
+envlist = py27, py35, py36, flake8
+skip_missing_interpreters = true
+
+[testenv]
+deps=
+  pytest
+commands=py.test -v {posargs:ceph/tests}
+
+[testenv:flake8]
+deps=flake8
+commands=flake8 {posargs:ceph}
+
+[tool:pytest]
+norecursedirs = .* _* virtualenv
+
+[flake8]
+select=F,E9
diff --git a/src/script/run_tox.sh b/src/script/run_tox.sh
new file mode 100755 (executable)
index 0000000..9ebc20f
--- /dev/null
@@ -0,0 +1,44 @@
+#!/usr/bin/env bash
+
+function dump_envvars {
+  echo "WITH_PYTHON2: ->$WITH_PYTHON2<-"
+  echo "WITH_PYTHON3: ->$WITH_PYTHON3<-"
+  echo "ENV_LIST: ->$ENV_LIST<-"
+}
+
+get_cmake_variable() {
+    grep "$1" $CEPH_BUILD_DIR/CMakeCache.txt | cut -d "=" -f 2
+}
+
+script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
+: ${CEPH_BUILD_DIR:=$script_dir/../../build}
+: ${WITH_PYTHON2:=$(get_cmake_variable WITH_PYTHON2)}
+: ${WITH_PYTHON3:=$(get_cmake_variable WITH_PYTHON3)}
+
+if [ -f ${TOX_VIRTUALENV}/bin/activate ]
+then
+  source ${TOX_VIRTUALENV}/bin/activate
+else
+  $script_dir/../tools/setup-virtualenv.sh tox_virtualenv
+  source tox_virtualenv/bin/activate
+  pip install tox
+fi
+
+# tox.ini will take care of this.
+export CEPH_BUILD_DIR=$CEPH_BUILD_DIR
+
+if [ "$WITH_PYTHON2" = "ON" ]; then
+  ENV_LIST+="py27,"
+fi
+# WITH_PYTHON3 might be set to "ON" or to the python3 RPM version number
+# prevailing on the system - e.g. "3", "36"
+if [[ "$WITH_PYTHON3" =~ (^3|^ON) ]]; then
+  ENV_LIST+="py3,"
+fi
+# use bash string manipulation to strip off any trailing comma
+ENV_LIST=${ENV_LIST%,}
+
+tox -c tox.ini -e "${ENV_LIST}" "$@"
+TOX_STATUS="$?"
+test "$TOX_STATUS" -ne "0" && dump_envvars
+exit $TOX_STATUS