From e6918187568dbd01842d8d1d2c808ce16a894239 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 21 Apr 2024 13:54:28 +0200 Subject: Adding upstream version 18.2.2. Signed-off-by: Daniel Baumann --- qa/tasks/tests/__init__.py | 0 qa/tasks/tests/conftest.py | 12 +++++++++ qa/tasks/tests/test_devstack.py | 48 ++++++++++++++++++++++++++++++++++++ qa/tasks/tests/test_import_yaml.py | 5 ++++ qa/tasks/tests/test_radosgw_admin.py | 31 +++++++++++++++++++++++ 5 files changed, 96 insertions(+) create mode 100644 qa/tasks/tests/__init__.py create mode 100644 qa/tasks/tests/conftest.py create mode 100644 qa/tasks/tests/test_devstack.py create mode 100644 qa/tasks/tests/test_import_yaml.py create mode 100644 qa/tasks/tests/test_radosgw_admin.py (limited to 'qa/tasks/tests') diff --git a/qa/tasks/tests/__init__.py b/qa/tasks/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/qa/tasks/tests/conftest.py b/qa/tasks/tests/conftest.py new file mode 100644 index 000000000..7cc617a41 --- /dev/null +++ b/qa/tasks/tests/conftest.py @@ -0,0 +1,12 @@ +import glob + + +def pytest_addoption(parser): + parser.addoption("--suite-dir", help="suite dir") + +def pytest_generate_tests(metafunc): + if "yaml_file" in metafunc.fixturenames: + suite_dir = metafunc.config.getoption("--suite-dir") + files = glob.glob(f"{suite_dir}/**/*.yaml", recursive=True) + + metafunc.parametrize("yaml_file", list(set(files))) diff --git a/qa/tasks/tests/test_devstack.py b/qa/tasks/tests/test_devstack.py new file mode 100644 index 000000000..39b94a64c --- /dev/null +++ b/qa/tasks/tests/test_devstack.py @@ -0,0 +1,48 @@ +from textwrap import dedent + +from tasks import devstack + + +class TestDevstack(object): + def test_parse_os_table(self): + table_str = dedent(""" + +---------------------+--------------------------------------+ + | Property | Value | + +---------------------+--------------------------------------+ + | attachments | [] | + | availability_zone | nova | + | bootable | false | + | created_at | 2014-02-21T17:14:47.548361 | + | display_description | None | + | display_name | NAME | + | id | ffdbd1bb-60dc-4d95-acfe-88774c09ad3e | + | metadata | {} | + | size | 1 | + | snapshot_id | None | + | source_volid | None | + | status | creating | + | volume_type | None | + +---------------------+--------------------------------------+ + """).strip() + expected = { + 'Property': 'Value', + 'attachments': '[]', + 'availability_zone': 'nova', + 'bootable': 'false', + 'created_at': '2014-02-21T17:14:47.548361', + 'display_description': 'None', + 'display_name': 'NAME', + 'id': 'ffdbd1bb-60dc-4d95-acfe-88774c09ad3e', + 'metadata': '{}', + 'size': '1', + 'snapshot_id': 'None', + 'source_volid': 'None', + 'status': 'creating', + 'volume_type': 'None'} + + vol_info = devstack.parse_os_table(table_str) + assert vol_info == expected + + + + diff --git a/qa/tasks/tests/test_import_yaml.py b/qa/tasks/tests/test_import_yaml.py new file mode 100644 index 000000000..d6e0e2640 --- /dev/null +++ b/qa/tasks/tests/test_import_yaml.py @@ -0,0 +1,5 @@ +import yaml + + +def test_load_yaml(yaml_file): + yaml.safe_load(open(yaml_file)) diff --git a/qa/tasks/tests/test_radosgw_admin.py b/qa/tasks/tests/test_radosgw_admin.py new file mode 100644 index 000000000..8506eda7b --- /dev/null +++ b/qa/tasks/tests/test_radosgw_admin.py @@ -0,0 +1,31 @@ +from unittest.mock import Mock + +from tasks import radosgw_admin + +acl_with_version = b"""fooFoofooFooFULL_CONTROL +""" # noqa + + +acl_without_version = b"""fooFoofooFooFULL_CONTROL +""" # noqa + + +class TestGetAcl(object): + + def setup(self): + self.key = Mock() + + def test_removes_xml_version(self): + self.key.get_xml_acl = Mock(return_value=acl_with_version) + result = radosgw_admin.get_acl(self.key) + assert result.startswith('