From: Sebastian Wagner Date: Mon, 8 Jul 2019 08:52:33 +0000 (+0200) Subject: python-common: Move Drive Group tests X-Git-Tag: v15.1.0~2025^2~3 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=04254df56df5386bf3c82547793ee6f0c5c525c9;p=ceph-ci.git python-common: Move Drive Group tests Signed-off-by: Sebastian Wagner --- diff --git a/src/pybind/mgr/orchestrator_cli/requirements.txt b/src/pybind/mgr/orchestrator_cli/requirements.txt index 8ef288ecc14..62843e4929e 100644 --- a/src/pybind/mgr/orchestrator_cli/requirements.txt +++ b/src/pybind/mgr/orchestrator_cli/requirements.txt @@ -1 +1,2 @@ tox==2.9.1 +-e ../../../python-common \ No newline at end of file diff --git a/src/pybind/mgr/orchestrator_cli/test_orchestrator.py b/src/pybind/mgr/orchestrator_cli/test_orchestrator.py index 3374d5a3ca5..bf2290391b5 100644 --- a/src/pybind/mgr/orchestrator_cli/test_orchestrator.py +++ b/src/pybind/mgr/orchestrator_cli/test_orchestrator.py @@ -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 index 00000000000..e69de29bb2d 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 index 00000000000..71a3a16d874 --- /dev/null +++ b/src/python-common/ceph/tests/test_drive_group.py @@ -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 index 00000000000..96d5e0da8d7 --- /dev/null +++ b/src/python-common/tox.ini @@ -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 index 00000000000..9ebc20fc610 --- /dev/null +++ b/src/script/run_tox.sh @@ -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