Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion tests/tacacs/test_ro_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

logger = logging.getLogger(__name__)

SLEEP_TIME = 10
TIMEOUT_LIMIT = 120

def ssh_remote_run(localhost, remote_ip, username, password, cmd):
res = localhost.shell("sshpass -p {} ssh "\
"-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null "\
Expand Down Expand Up @@ -49,6 +52,24 @@ def ssh_remote_ban_run(localhost, remote_ip, username, password, cmd):
logger.info("check command \"{}\" rc={}".format(cmd, res['rc']))
return res['rc'] != 0 and "Make sure your account has RW permission to current device" in res['stderr']

def wait_for_tacacs(localhost, remote_ip, username, password):
current_attempt = 0
cmd = 'systemctl status hostcfgd.service'
while (True):
# Wait for tacacs to finish configuration from hostcfgd
logger.info("Check if hostcfgd started and configured tacac attempt = {}".format(current_attempt))
time.sleep(SLEEP_TIME)
output = localhost.shell("sshpass -p {} ssh "\
"-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null "\
"{}@{} {}".format(
password, username, remote_ip, cmd), module_ignore_errors=True)['stdout_lines']
if "active (running)" in str(output):
return
else:
if current_attempt >= TIMEOUT_LIMIT/SLEEP_TIME:
pytest_assert(False, "hostcfgd did not start after {} seconds".format(TIMEOUT_LIMIT))
else:
current_attempt += 1

def test_ro_user(localhost, duthosts, enum_rand_one_per_hwsku_hostname, creds_all_duts, test_tacacs):
duthost = duthosts[enum_rand_one_per_hwsku_hostname]
Expand Down Expand Up @@ -153,7 +174,8 @@ def test_ro_user_banned_command(localhost, duthosts, enum_rand_one_per_hwsku_hos
]

# Wait until hostcfgd started and configured tacas authorization
time.sleep(100)
wait_for_tacacs(localhost, dutip, creds_all_duts[duthost]['tacacs_ro_user'], creds_all_duts[duthost]['tacacs_ro_user_passwd'])

for command in commands:
banned = ssh_remote_ban_run(localhost, dutip, creds_all_duts[duthost]['tacacs_ro_user'],
creds_all_duts[duthost]['tacacs_ro_user_passwd'], command)
Expand Down