Skip to content

Commit 16031e5

Browse files
authored
[SSH] Fix SSH login session limit test case randomly failed issue. #5426 (#5516)
### Description of PR Fix SSH login session limit test case randomly failed issue. The issue is because update config file with 'tee' command, and tee command will exit when receive pipeline close command. ### Type of change - [ ] Bug fix - [ ] Testbed and Framework(new/improvement) - [x] Test case(new/improvement) ### Back port request ### Approach #### What is the motivation for this PR? Fix SSH login session limit test case randomly failed issue. #### How did you do it? Code change: 1. Not use tee command to update template file in template folder. 2. Create template file with pipeline in home folder and move to template folder. #### How did you verify/test it? Run new UT make sure they are all pass. Make sure all current UT not break during merge validation. #### Any platform specific information? N/A #### Supported testbed topology if it's a new test case?
1 parent efdb18a commit 16031e5

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

tests/ssh/test_ssh_limit.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626

2727
PAM_LIMITS_TEMPLATE_PATH = "/usr/share/sonic/templates/pam_limits.j2"
2828
LIMITS_CONF_TEMPLATE_PATH = "/usr/share/sonic/templates/limits.conf.j2"
29-
LIMITS_CONF_TEMPLATE = "echo \"{{% if hwsku == '{0}' and type == '{1}'%}}\n{2}\n{{% endif %}}\" | sudo tee {3}"
29+
LIMITS_CONF_TEMPLATE_TO_HOME = "echo \"{{% if hwsku == '{0}' and type == '{1}'%}}\n{2}\n{{% endif %}}\" > ~/temp_config_file"
30+
TEMPLATE_MOVE_COMMAND = "sudo mv ~/temp_config_file {0}"
3031

3132
def get_device_type(duthost):
3233
device_config_db = json.loads(duthost.shell("sonic-cfggen -d --print-data")['stdout'])
@@ -42,7 +43,12 @@ def get_device_type(duthost):
4243
def modify_template(admin_session, template_path, additional_content, hwsku, type):
4344
admin_session.exec_command(TEMPLATE_BACKUP_COMMAND.format(template_path))
4445
admin_session.exec_command(TEMPLATE_CREATE_COMMAND.format(template_path))
45-
admin_session.exec_command(LIMITS_CONF_TEMPLATE.format(hwsku, type, additional_content, template_path))
46+
admin_session.exec_command(LIMITS_CONF_TEMPLATE_TO_HOME.format(hwsku, type, additional_content))
47+
admin_session.exec_command(TEMPLATE_MOVE_COMMAND.format(template_path))
48+
49+
stdin, stdout, stderr = admin_session.exec_command('sudo cat {0}'.format(template_path))
50+
config_file_content = stdout.readlines()
51+
logging.info("Updated template file: {0}".format(config_file_content))
4652

4753
def modify_templates(duthost, tacacs_creds, creds):
4854
dut_ip = duthost.mgmt_ip
@@ -86,10 +92,6 @@ def setup_limit(duthosts, rand_one_dut_hostname, tacacs_creds, creds):
8692
modify_templates(duthost, tacacs_creds, creds)
8793
restart_hostcfgd(duthost)
8894

89-
# for debug, print rendered config file
90-
config_file_content = duthost.shell('sudo cat /etc/security/limits.conf', module_ignore_errors=False)['stdout_lines']
91-
logging.debug("Updated config file: {0}".format(config_file_content))
92-
9395
yield
9496

9597
if template_file_exist:

0 commit comments

Comments
 (0)