From db2237d174c99b9884bb25567677b1d4693d464b Mon Sep 17 00:00:00 2001 From: Xin Wang Date: Thu, 23 Jul 2020 20:32:59 +0800 Subject: [PATCH] Render some username and password in creds fixture Some username and password retrieved using the creds fixture may have reference to other variables. If the username and password are not consumed by ansible, they would not be rendered. This fix renders some of the username and password in the creds fixture. Signed-off-by: Xin Wang --- tests/conftest.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index ef3006563ce..06331ea13a6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -12,6 +12,7 @@ import pytest import csv import yaml +import jinja2 import ipaddr as ipaddress from collections import defaultdict @@ -359,6 +360,13 @@ def creds(duthost): creds.update(v) else: logging.info("skip empty var file {}".format(f)) + + cred_vars = ["sonicadmin_user", "sonicadmin_password"] + hostvars = duthost.host.options['variable_manager']._hostvars[duthost.hostname] + for cred_var in cred_vars: + if cred_var in creds: + creds[cred_var] = jinja2.Template(creds[cred_var]).render(**hostvars) + return creds