From 69cbb130531685937a16dcdc45cc75066bcd9ead Mon Sep 17 00:00:00 2001 From: Jibin Bao Date: Mon, 8 Aug 2022 17:00:01 +0800 Subject: [PATCH] Fix portstat case MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Becuase desigin change for "portstat -c -t filename", so change portstat test 1. Orignal design: After running “portstat -c -t filename”, status file will be created on the folder of /tmp/portstat-{uid}/{uid}-{filename} 2. New design: After running “portstat -c -t filename”, status file will be created on the folder of /tmp/cache/portstat/{uid}-{filename} Change-Id: Ia122a08b9a55a26fe6a299d74d2df1f1949c7ca3 --- tests/portstat/test_portstat.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/portstat/test_portstat.py b/tests/portstat/test_portstat.py index 0d93c4592d..91f9df6c00 100644 --- a/tests/portstat/test_portstat.py +++ b/tests/portstat/test_portstat.py @@ -72,16 +72,14 @@ def test_portstat_delete_all(duthosts, enum_rand_one_per_hwsku_frontend_hostname logger.info('Verify that the file names are in the /tmp directory') uid = duthost.command('id -u')['stdout'].strip() for stats_file in stats_files: - pytest_assert(duthost.stat(path='/tmp/portstat-{uid}/{uid}-{filename}'\ - .format(uid=uid, filename=stats_file))['stat']['exists']) + pytest_assert(get_tmp_portstat_file_existing_status(duthost, uid, stats_file)) logger.info('Run the command to be tested "{}"'.format(command)) duthost.command(command) logger.info('Verify that the file names are not in the /tmp directory') for stats_file in stats_files: - pytest_assert(not duthost.stat(path='/tmp/portstat-{uid}/{uid}-{filename}'\ - .format(uid=uid, filename=stats_file))['stat']['exists']) + pytest_assert(not get_tmp_portstat_file_existing_status(duthost, uid, stats_file)) @pytest.mark.parametrize('command', @@ -100,21 +98,23 @@ def test_portstat_delete_tag(duthosts, enum_rand_one_per_hwsku_frontend_hostname logger.info('Verify that the file names are in the /tmp directory') uid = duthost.command('id -u')['stdout'].strip() for stats_file in stats_files: - pytest_assert(duthost.stat(path='/tmp/portstat-{uid}/{uid}-{filename}'\ - .format(uid=uid, filename=stats_file))['stat']['exists']) + pytest_assert(get_tmp_portstat_file_existing_status(duthost, uid, stats_file)) full_delete_command = command + ' ' + file_to_delete logger.info('Run the command to be tested "{}"'.format(full_delete_command)) duthost.command(full_delete_command) logger.info('Verify that the deleted file name is not in the directory') - pytest_assert(not duthost.stat(path='/tmp/portstat-{uid}/{uid}-{filename}'\ - .format(uid=uid, filename=file_to_delete))['stat']['exists']) + pytest_assert(not get_tmp_portstat_file_existing_status(duthost, uid, file_to_delete)) logger.info('Verify that the remaining file names are in the directory') for stats_file in files_not_deleted: - pytest_assert(duthost.stat(path='/tmp/portstat-{uid}/{uid}-{filename}'\ - .format(uid=uid, filename=stats_file))['stat']['exists']) + pytest_assert(get_tmp_portstat_file_existing_status(duthost, uid, stats_file)) + + +def get_tmp_portstat_file_existing_status(duthost, uid, stats_file): + return duthost.stat(path='/tmp/cache/portstat/{uid}-{filename}'.format( + uid=uid, filename=stats_file))['stat']['exists'] @pytest.mark.parametrize('command', ['portstat -a', 'portstat --all'])