charmed-kubernetes / pytest-operator

Apache License 2.0
6 stars 13 forks source link

lxd builds fail due to using fully qualified module names in juju model #26

Closed techalchemy closed 2 years ago

techalchemy commented 2 years ago

Hey there, thanks for putting the plugin together. I have been trying to get this up and running, but as of right now, building on LXD seems to fail due to the automatic name generation approach, which uses the module __name__ and translates _ to -.

My operator is a machine operator (i.e. not K8s) and is structured such that the relevant tests are all based in <project_root>/tests/test_integration.py (and in this case are filtered with an integration marker).

Here is what I am seeing:

```console $ tox -r -e integration ...... integration run-test: commands[0] | pytest -v --tb native --show-capture=no --log-cli-level=INFO -s -m integration /home/techalchemy/git/artifactory-operator/tests =================================================================== test session starts =================================================================== platform linux -- Python 3.8.7, pytest-6.2.4, py-1.10.0, pluggy-0.13.1 -- /home/techalchemy/git/artifactory-operator/.tox/integration/bin/python cachedir: .tox/integration/.pytest_cache rootdir: /home/techalchemy/git/artifactory-operator, configfile: pyproject.toml plugins: operator-0.8.1, asyncio-0.15.1 collected 65 items / 63 deselected / 2 selected tests/test_integration.py::test_build_and_deploy /snap/bin/juju /home/techalchemy/git/artifactory-operator/.tox/integration/bin/charmcraft --------------------------------------------------------------------- live log setup ---------------------------------------------------------------------- INFO pytest_operator.plugin:plugin.py:155 Using tmp_path: /home/techalchemy/git/artifactory-operator/.tox/integration/tmp/pytest/tests.test-integration-k3aa0 INFO pytest_operator.plugin:plugin.py:217 Adding model overlord:tests.test-integration-k3aa ERROR tests/test_integration.py::test_bundle ERROR ========================================================================= ERRORS ========================================================================== _________________________________________________________ ERROR at setup of test_build_and_deploy _________________________________________________________ Traceback (most recent call last): File "/home/techalchemy/git/artifactory-operator/.tox/integration/lib/python3.8/site-packages/pytest_asyncio/plugin.py", line 142, in wrapper return loop.run_until_complete(setup()) File "/home/techalchemy/.pyenv/versions/3.8.7/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete return future.result() File "/home/techalchemy/git/artifactory-operator/.tox/integration/lib/python3.8/site-packages/pytest_asyncio/plugin.py", line 123, in setup res = await gen_obj.__anext__() File "/home/techalchemy/git/artifactory-operator/.tox/integration/lib/python3.8/site-packages/pytest_operator/plugin.py", line 144, in ops_test await ops_test._setup_model() File "/home/techalchemy/git/artifactory-operator/.tox/integration/lib/python3.8/site-packages/pytest_operator/plugin.py", line 218, in _setup_model self.model = await self._controller.add_model( File "/home/techalchemy/git/artifactory-operator/.tox/integration/lib/python3.8/site-packages/juju/controller.py", line 354, in add_model model_info = await model_facade.CreateModel( File "/home/techalchemy/git/artifactory-operator/.tox/integration/lib/python3.8/site-packages/juju/client/facade.py", line 480, in wrapper reply = await f(*args, **kwargs) File "/home/techalchemy/git/artifactory-operator/.tox/integration/lib/python3.8/site-packages/juju/client/_client5.py", line 5515, in CreateModel reply = await self.rpc(msg) File "/home/techalchemy/git/artifactory-operator/.tox/integration/lib/python3.8/site-packages/juju/client/facade.py", line 623, in rpc result = await self.connection.rpc(msg, encoder=TypeEncoder) File "/home/techalchemy/git/artifactory-operator/.tox/integration/lib/python3.8/site-packages/juju/client/connection.py", line 495, in rpc raise errors.JujuAPIError(result) juju.errors.JujuAPIError: failed to create config: creating config from values failed: "tests.test-integration-k3aa" is not a valid name: model names may only contain lowercase letters, digits and hyphens ______________________________________________________________ ERROR at setup of test_bundle ______________________________________________________________ Traceback (most recent call last): File "/home/techalchemy/git/artifactory-operator/.tox/integration/lib/python3.8/site-packages/pytest_asyncio/plugin.py", line 142, in wrapper return loop.run_until_complete(setup()) File "/home/techalchemy/.pyenv/versions/3.8.7/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete return future.result() File "/home/techalchemy/git/artifactory-operator/.tox/integration/lib/python3.8/site-packages/pytest_asyncio/plugin.py", line 123, in setup res = await gen_obj.__anext__() File "/home/techalchemy/git/artifactory-operator/.tox/integration/lib/python3.8/site-packages/pytest_operator/plugin.py", line 144, in ops_test await ops_test._setup_model() File "/home/techalchemy/git/artifactory-operator/.tox/integration/lib/python3.8/site-packages/pytest_operator/plugin.py", line 218, in _setup_model self.model = await self._controller.add_model( File "/home/techalchemy/git/artifactory-operator/.tox/integration/lib/python3.8/site-packages/juju/controller.py", line 354, in add_model model_info = await model_facade.CreateModel( File "/home/techalchemy/git/artifactory-operator/.tox/integration/lib/python3.8/site-packages/juju/client/facade.py", line 480, in wrapper reply = await f(*args, **kwargs) File "/home/techalchemy/git/artifactory-operator/.tox/integration/lib/python3.8/site-packages/juju/client/_client5.py", line 5515, in CreateModel reply = await self.rpc(msg) File "/home/techalchemy/git/artifactory-operator/.tox/integration/lib/python3.8/site-packages/juju/client/facade.py", line 623, in rpc result = await self.connection.rpc(msg, encoder=TypeEncoder) File "/home/techalchemy/git/artifactory-operator/.tox/integration/lib/python3.8/site-packages/juju/client/connection.py", line 495, in rpc raise errors.JujuAPIError(result) juju.errors.JujuAPIError: failed to create config: creating config from values failed: "tests.test-integration-k3aa" is not a valid name: model names may only contain lowercase letters, digits and hyphens ==================================================================== warnings summary ===================================================================== .tox/integration/lib/python3.8/site-packages/_pytest/config/__init__.py:1233 /home/techalchemy/git/artifactory-operator/.tox/integration/lib/python3.8/site-packages/_pytest/config/__init__.py:1233: PytestConfigWarning: Unknown config option: flake8-ignore self._warn_or_fail_if_strict(f"Unknown config option: {key}\n") .tox/integration/lib/python3.8/site-packages/_pytest/config/__init__.py:1233 /home/techalchemy/git/artifactory-operator/.tox/integration/lib/python3.8/site-packages/_pytest/config/__init__.py:1233: PytestConfigWarning: Unknown config option: plugins self._warn_or_fail_if_strict(f"Unknown config option: {key}\n") -- Docs: https://docs.pytest.org/en/stable/warnings.html ================================================================= short test summary info ================================================================= ERROR tests/test_integration.py::test_build_and_deploy - juju.errors.JujuAPIError: failed to create config: creating config from values failed: "tests.t... ERROR tests/test_integration.py::test_bundle - juju.errors.JujuAPIError: failed to create config: creating config from values failed: "tests.test-integr... ====================================================== 63 deselected, 2 warnings, 2 errors in 0.23s ======================================================= ERROR: InvocationError for command /home/techalchemy/git/artifactory-operator/.tox/integration/bin/pytest -v --tb native --show-capture=no --log-cli-level=INFO -s -m integration tests (exited with code 1) _________________________________________________________________________ summary _________________________________________________________________________ ERROR: integration: commands failed ```

The relevant code appears to be at https://github.com/charmed-kubernetes/pytest-operator/blob/6efd734b98c63b062dfa7ac5c07b314710dbdb66/pytest_operator/plugin.py#L172-L177

As a workaround, I have modified my tests/test_integration.py to include the following line:

_, _, __name__ = __name__.rpartition(".")

And this seems to have provided a temporary solution.