Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAAS cloud model name issue when initializing ops_test fixture #124

Open
dashmage opened this issue Feb 20, 2024 · 0 comments
Open

MAAS cloud model name issue when initializing ops_test fixture #124

dashmage opened this issue Feb 20, 2024 · 0 comments

Comments

@dashmage
Copy link

While running tests on a MAAS juju cloud where the model is named admin/mymodel according to the <user>/<model> convention, the ops_test fixture does not work.


Steps to reproduce error

Models are named admin/mymodel and admin/controller.

Have a simple test that calls the ops_test fixture.

def test_something(ops_test):
    assert True

And run pytest path/to/test.py --model admin/mymodel to execute the tests.

Analysis

I was trying to reuse my existing model by providing --model admin/mymodel but this still tried to create a new model (and promptly failed since I wasn't the admin user on the cloud). Upon tracing the execution flow from the plugin.py -> ops_test -> _setup_model -> track_model -> _model_exists where the last method is used to set the value of the use_existing variable which was getting the wrong value (should be True, getting False).

This seemed to be due to the fact that the self._controller.list_models() returns the models but without prefixing the user name (without "admin" in this instance).

async def _model_exists(self, model_name: str) -> bool:
    """
    returns True when the model_name exists in the model.
    """
    all_models = await self._controller.list_models()
    return model_name in all_models

# all_models had the value ['controller', 'mymodel'] but model_name is "admin/mymodel"

As seen above, the _model_exists method returns False when the self._controller.list_models() returns the wrong name for the current model.

Temporary workaround

Made changes here.

return model_name.split("/")[-1] in all_models
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant