Fix scenario path in config detector

When running pytest with custom scenario name,
make config detection taking into account the scenario specific
molucule config file.

For example, some scenarios could use podman, while other ones -
a delegated driver.

Change-Id: Ied74290876d28f6fb2011aa3d9ccd77c0c90bea1
Signed-off-by: Bogdan Dobrelya <bdobreli@redhat.com>
This commit is contained in:
Bogdan Dobrelya 2022-08-10 17:59:26 +02:00
parent 640c525e7e
commit 54e7e2c1fa
2 changed files with 11 additions and 4 deletions

View File

@ -1,5 +1,9 @@
---
driver:
name: podman
log: true
platforms:
- name: centos
hostname: centos

View File

@ -18,10 +18,10 @@ import pytest
import yaml
def set_proper_molecule_config(role_path):
def set_proper_molecule_config(role_path, scenario='default'):
mol_config_file = "config.yml"
if os.path.exists(os.path.join(role_path, 'molecule', 'default/molecule.yml')):
molecule_path = os.path.join(role_path, 'molecule', 'default/molecule.yml')
if os.path.exists(os.path.join(role_path, 'molecule', f'{scenario}/molecule.yml')):
molecule_path = os.path.join(role_path, 'molecule', f'{scenario}/molecule.yml')
with open(molecule_path) as content:
data = yaml.safe_load(content)
if 'driver' in data.keys() and data['driver']['name'] == 'podman':
@ -35,8 +35,11 @@ def set_proper_molecule_config(role_path):
def test_molecule(pytestconfig):
cmd = ['python', '-m', 'molecule']
scenario = pytestconfig.getoption("scenario")
if not scenario:
scenario = 'default'
ansible_args = pytestconfig.getoption("ansible_args")
cmd.extend(['--base-config', set_proper_molecule_config(os.getcwd())])
cmd.extend(['--base-config', set_proper_molecule_config(os.getcwd(),
scenario)])
if ansible_args:
cmd.append('converge')