From 22c09773d8a48186b9050b442167b99632c2d2d1 Mon Sep 17 00:00:00 2001 From: Pradnya Mohite Date: Mon, 6 Apr 2020 21:13:20 -0700 Subject: [PATCH 1/7] add test for show features command --- tests/test_features.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/test_features.py diff --git a/tests/test_features.py b/tests/test_features.py new file mode 100644 index 0000000000..5fc1444b27 --- /dev/null +++ b/tests/test_features.py @@ -0,0 +1,37 @@ +import pytest +import logging + +logger = logging.getLogger(__name__) + +def get_dict_stdout(cmd_out): + """Extract dictionary from show features command output + """ + result = "" + out_dict = {} + cmd = cmd_out[2:] + for x in cmd: + result = x.encode('UTF-8') + r = result.split() + out_dict[r[0]] = r[1] + return out_dict + +def get_status_redisout(status_out): + """Extract status value for feature in redis + """ + status_list = status_out[1:] + status = "" + for s in status_list: + status = s.encode('UTF-8') + return status + +def test_show_features(duthost): + """Verify show features command output against CONFIG_DB + """ + features_stdout = duthost.shell('show features', module_ignore_errors=True)['stdout_lines'] + features_dict = get_dict_stdout(features_stdout) + for k,v in features_dict.items(): + feature = str(k) + status_out = duthost.shell('/usr/bin/redis-cli -n 4 hgetall "FEATURE|{}"'.format(feature), module_ignore_errors=False)['stdout_lines'] + redis_value = get_status_redisout(status_out) + if str(redis_value) == str(v): + assert True, "{} is {} which matches with config_db".format(k,v) \ No newline at end of file From 44031a1e4460721b01f01bf6980abb91b34d3218 Mon Sep 17 00:00:00 2001 From: Pradnya Mohite Date: Tue, 7 Apr 2020 22:58:36 -0700 Subject: [PATCH 2/7] resolve PR comments --- tests/test_features.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/test_features.py b/tests/test_features.py index 5fc1444b27..aac69116ad 100644 --- a/tests/test_features.py +++ b/tests/test_features.py @@ -1,8 +1,6 @@ import pytest import logging -logger = logging.getLogger(__name__) - def get_dict_stdout(cmd_out): """Extract dictionary from show features command output """ @@ -27,7 +25,7 @@ def get_status_redisout(status_out): def test_show_features(duthost): """Verify show features command output against CONFIG_DB """ - features_stdout = duthost.shell('show features', module_ignore_errors=True)['stdout_lines'] + features_stdout = duthost.shell('show features', module_ignore_errors=False)['stdout_lines'] features_dict = get_dict_stdout(features_stdout) for k,v in features_dict.items(): feature = str(k) From 6d4d2d4e8870af59b443a1c6d70eebcd49bd9019 Mon Sep 17 00:00:00 2001 From: Pradnya Mohite Date: Tue, 7 Apr 2020 23:00:39 -0700 Subject: [PATCH 3/7] adding newline --- tests/test_features.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_features.py b/tests/test_features.py index aac69116ad..71d1ea3bc4 100644 --- a/tests/test_features.py +++ b/tests/test_features.py @@ -32,4 +32,4 @@ def test_show_features(duthost): status_out = duthost.shell('/usr/bin/redis-cli -n 4 hgetall "FEATURE|{}"'.format(feature), module_ignore_errors=False)['stdout_lines'] redis_value = get_status_redisout(status_out) if str(redis_value) == str(v): - assert True, "{} is {} which matches with config_db".format(k,v) \ No newline at end of file + assert True, "{} is {} which matches with config_db".format(k,v) From 6c5cff16bddb4999ca616bc64933081fa286cf41 Mon Sep 17 00:00:00 2001 From: Pradnya Mohite Date: Wed, 8 Apr 2020 14:57:10 -0700 Subject: [PATCH 4/7] remove unused import statements --- tests/test_features.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/test_features.py b/tests/test_features.py index 71d1ea3bc4..fa39809755 100644 --- a/tests/test_features.py +++ b/tests/test_features.py @@ -1,6 +1,4 @@ -import pytest -import logging - +# Helper Functions def get_dict_stdout(cmd_out): """Extract dictionary from show features command output """ @@ -22,6 +20,7 @@ def get_status_redisout(status_out): status = s.encode('UTF-8') return status +#Test Functions def test_show_features(duthost): """Verify show features command output against CONFIG_DB """ From e02d021f21dc9e3ffc9ab8251bdd92d6b86226c3 Mon Sep 17 00:00:00 2001 From: Pradnya Mohite Date: Thu, 16 Apr 2020 14:14:39 -0700 Subject: [PATCH 5/7] changing assert condition --- tests/test_features.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/test_features.py b/tests/test_features.py index fa39809755..ba5c289ea3 100644 --- a/tests/test_features.py +++ b/tests/test_features.py @@ -26,9 +26,8 @@ def test_show_features(duthost): """ features_stdout = duthost.shell('show features', module_ignore_errors=False)['stdout_lines'] features_dict = get_dict_stdout(features_stdout) - for k,v in features_dict.items(): - feature = str(k) + for cmd_key,cmd_value in features_dict.items(): + feature = str(cmd_key) status_out = duthost.shell('/usr/bin/redis-cli -n 4 hgetall "FEATURE|{}"'.format(feature), module_ignore_errors=False)['stdout_lines'] redis_value = get_status_redisout(status_out) - if str(redis_value) == str(v): - assert True, "{} is {} which matches with config_db".format(k,v) + assert str(redis_value) == str(cmd_value), "{} is {} which does not match with config_db".format(cmd_key, cmd_value) From d38121cc425cccabaa0195ba69d30edf5a7ec49e Mon Sep 17 00:00:00 2001 From: Pradnya Mohite Date: Thu, 16 Apr 2020 17:21:08 -0700 Subject: [PATCH 6/7] add assert condition and update message --- tests/test_features.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_features.py b/tests/test_features.py index ba5c289ea3..89ab73b372 100644 --- a/tests/test_features.py +++ b/tests/test_features.py @@ -30,4 +30,5 @@ def test_show_features(duthost): feature = str(cmd_key) status_out = duthost.shell('/usr/bin/redis-cli -n 4 hgetall "FEATURE|{}"'.format(feature), module_ignore_errors=False)['stdout_lines'] redis_value = get_status_redisout(status_out) - assert str(redis_value) == str(cmd_value), "{} is {} which does not match with config_db".format(cmd_key, cmd_value) + status_value_expected = str(cmd_value) + assert str(redis_value) == status_value_expected, "'{}' is '{}' which does not match with config_db".format(cmd_key, cmd_value) From 18ccaaa2b03574766050fcd32937349f8b7d33f1 Mon Sep 17 00:00:00 2001 From: Pradnya Mohite Date: Thu, 16 Apr 2020 17:24:56 -0700 Subject: [PATCH 7/7] adding space after , --- tests/test_features.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_features.py b/tests/test_features.py index 89ab73b372..a6058cb59a 100644 --- a/tests/test_features.py +++ b/tests/test_features.py @@ -20,13 +20,13 @@ def get_status_redisout(status_out): status = s.encode('UTF-8') return status -#Test Functions +# Test Functions def test_show_features(duthost): """Verify show features command output against CONFIG_DB """ features_stdout = duthost.shell('show features', module_ignore_errors=False)['stdout_lines'] features_dict = get_dict_stdout(features_stdout) - for cmd_key,cmd_value in features_dict.items(): + for cmd_key, cmd_value in features_dict.items(): feature = str(cmd_key) status_out = duthost.shell('/usr/bin/redis-cli -n 4 hgetall "FEATURE|{}"'.format(feature), module_ignore_errors=False)['stdout_lines'] redis_value = get_status_redisout(status_out)