From 2fb9e13c021d346d4b1ed5616b069afbc3c70c5d Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Tue, 26 Apr 2022 17:09:54 +0200 Subject: [PATCH] Prevent the enroll/deploy commands from running without venv Running them without sourcing the venv configuration results in a very confusing error message from ansible. Prevent that. Change-Id: I0cc408b475134eb76d3229b9cccefb9555b4bcba --- bifrost/cli.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/bifrost/cli.py b/bifrost/cli.py index 6003459fc..7e6e9f96b 100644 --- a/bifrost/cli.py +++ b/bifrost/cli.py @@ -191,7 +191,18 @@ def cmd_install(args): "See documentation for next steps") +def ensure_inside_venv(): + try: + import oslo_config # noqa + except ImportError: + sys.exit("This command must be executed inside the Bifrost virtual " + "environment. Try:\n" + f" $ source {VENV}/bin/activate\n" + " $ export OS_CLOUD=bifrost") + + def configure_inventory(args): + ensure_inside_venv() inventory = os.path.join(PLAYBOOKS, 'inventory', 'bifrost_inventory.py') if not args.inventory: os.environ['BIFROST_INVENTORY_SOURCE'] = 'ironic'