运行测试

尽管测试在 CI 中持续运行,但我们投入了大量精力使其易于在任何环境中运行,只要满足一些要求即可。

依赖项

有一些 Python 依赖项,列在 tests/ 目录中的 requirements.txt 文件中。这些依赖项旨在使用 Python 安装工具(在本例中为 pip)安装

pip install -r tests/requirements.txt

对于虚拟化,需要 libvirt 或 VirtualBox(测试工具对两者都有原生支持)。这使得测试工具更加灵活,因为大多数平台都可以通过 VirtualBox 或 libvirt 涵盖。

运行场景

测试由 tox 驱动,这是一个命令行工具,用于运行配置文件(在本例中为项目根目录下的 tox.ini)中定义的测试矩阵。

有关场景的详细描述,请参阅 测试场景

要运行单个场景,请通过列出它们来确保它可用(应在 tox.ini 中定义)

tox -l

在此示例中,我们将使用 luminous-ansible2.4-xenial_cluster。测试工具默认使用 VirtualBox 作为后端,因此如果您的系统上安装了它,则此命令应该可以正常工作

tox -e luminous-ansible2.4-xenial_cluster

对于 libvirt,它将是

tox -e luminous-ansible2.4-xenial_cluster -- --provider=libvirt

警告

根据场景类型和可用资源,在个人计算机上本地运行这些测试可能会非常消耗资源。

注意

大多数测试运行需要 20 到 40 分钟,具体取决于系统资源

该命令应该会启动测试所需的机器,使用 ceph-ansible 配置它们,运行测试,并在最后拆除整个环境。

输出将类似于此精简版本

luminous-ansible2.4-xenial_cluster create: /Users/alfredo/python/upstream/ceph-ansible/.tox/luminous-ansible2.4-xenial_cluster
luminous-ansible2.4-xenial_cluster installdeps: ansible==2.4.2, -r/Users/alfredo/python/upstream/ceph-ansible/tests/requirements.txt
luminous-ansible2.4-xenial_cluster runtests: commands[0] | vagrant up --no-provision --provider=virtualbox
Bringing machine 'client0' up with 'virtualbox' provider...
Bringing machine 'rgw0' up with 'virtualbox' provider...
Bringing machine 'mds0' up with 'virtualbox' provider...
Bringing machine 'mon0' up with 'virtualbox' provider...
Bringing machine 'mon1' up with 'virtualbox' provider...
Bringing machine 'mon2' up with 'virtualbox' provider...
Bringing machine 'osd0' up with 'virtualbox' provider...
...

在所有节点启动后,ceph-ansible 将配置它们,并运行 playbook

 ...
 PLAY RECAP *********************************************************************
 client0                    : ok=4    changed=0    unreachable=0    failed=0
 mds0                       : ok=4    changed=0    unreachable=0    failed=0
mon0                       : ok=4    changed=0    unreachable=0    failed=0
 mon1                       : ok=4    changed=0    unreachable=0    failed=0
 mon2                       : ok=4    changed=0    unreachable=0    failed=0
 osd0                       : ok=4    changed=0    unreachable=0    failed=0
 rgw0                       : ok=4    changed=0    unreachable=0    failed=0
 ...

一旦整个环境全部运行,测试将被发送到主机,输出类似于此

luminous-ansible2.4-xenial_cluster runtests: commands[4] | testinfra -n 4 --sudo -v --connection=ansible --ansible-inventory=/Users/alfredo/python/upstream/ceph-ansible/tests/functional/ubuntu/16.04/cluster/hosts /Users/alfredo/python/upstream/ceph-ansible/tests/functional/tests
============================ test session starts ===========================
platform darwin -- Python 2.7.8, pytest-3.0.7, py-1.4.33, pluggy-0.4.0 -- /Users/alfredo/python/upstream/ceph-ansible/.tox/luminous-ansible2.4-xenial_cluster/bin/python
cachedir: ../../../../.cache
rootdir: /Users/alfredo/python/upstream/ceph-ansible/tests, inifile: pytest.ini
plugins: testinfra-1.5.4, xdist-1.15.0
[gw0] darwin Python 2.7.8 cwd: /Users/alfredo/python/upstream/ceph-ansible/tests/functional/ubuntu/16.04/cluster
[gw1] darwin Python 2.7.8 cwd: /Users/alfredo/python/upstream/ceph-ansible/tests/functional/ubuntu/16.04/cluster
[gw2] darwin Python 2.7.8 cwd: /Users/alfredo/python/upstream/ceph-ansible/tests/functional/ubuntu/16.04/cluster
[gw3] darwin Python 2.7.8 cwd: /Users/alfredo/python/upstream/ceph-ansible/tests/functional/ubuntu/16.04/cluster
[gw0] Python 2.7.8 (v2.7.8:ee879c0ffa11, Jun 29 2014, 21:07:35)  -- [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
[gw1] Python 2.7.8 (v2.7.8:ee879c0ffa11, Jun 29 2014, 21:07:35)  -- [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
[gw2] Python 2.7.8 (v2.7.8:ee879c0ffa11, Jun 29 2014, 21:07:35)  -- [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
[gw3] Python 2.7.8 (v2.7.8:ee879c0ffa11, Jun 29 2014, 21:07:35)  -- [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
gw0 [154] / gw1 [154] / gw2 [154] / gw3 [154]
scheduling tests via LoadScheduling

../../../tests/test_install.py::TestInstall::test_ceph_dir_exists[ansible:/mon0]
../../../tests/test_install.py::TestInstall::test_ceph_dir_is_a_directory[ansible:/mon0]
../../../tests/test_install.py::TestInstall::test_ceph_conf_is_a_file[ansible:/mon0]
../../../tests/test_install.py::TestInstall::test_ceph_dir_is_a_directory[ansible:/mon1]
[gw2] PASSED ../../../tests/test_install.py::TestCephConf::test_ceph_config_has_mon_host_line[ansible:/mon0]
../../../tests/test_install.py::TestInstall::test_ceph_conf_exists[ansible:/mon1]
[gw3] PASSED ../../../tests/test_install.py::TestCephConf::test_mon_host_line_has_correct_value[ansible:/mon0]
../../../tests/test_install.py::TestInstall::test_ceph_conf_is_a_file[ansible:/mon1]
[gw1] PASSED ../../../tests/test_install.py::TestInstall::test_ceph_command_exists[ansible:/mon1]
../../../tests/test_install.py::TestCephConf::test_mon_host_line_has_correct_value[ansible:/mon1]
...

最后,整个环境被拆除

luminous-ansible2.4-xenial_cluster runtests: commands[5] | vagrant destroy --force
==> osd0: Forcing shutdown of VM...
==> osd0: Destroying VM and associated drives...
==> mon2: Forcing shutdown of VM...
==> mon2: Destroying VM and associated drives...
==> mon1: Forcing shutdown of VM...
==> mon1: Destroying VM and associated drives...
==> mon0: Forcing shutdown of VM...
==> mon0: Destroying VM and associated drives...
==> mds0: Forcing shutdown of VM...
==> mds0: Destroying VM and associated drives...
==> rgw0: Forcing shutdown of VM...
==> rgw0: Destroying VM and associated drives...
==> client0: Forcing shutdown of VM...
==> client0: Destroying VM and associated drives...

并显示已运行的场景的简要摘要

________________________________________________ summary _________________________________________________
  luminous-ansible2.4-xenial_cluster: commands succeeded
  congratulations :)