Skip to content

Commit 7bb70bb

Browse files
authored
Add Secure Upgrade Test (#6816)
What is the motivation for this PR? We want to add a new secure upgrade test to validate non successful upgrade to non secure image. In details: If we have a secured image installed on a secured system, trying to install a non-secure image on it should fail and we should expect a relevant message indicating so. How did you verify/test it? By taking a secured system with secured image installed on it and a path to non secure image we created privately, we ran the test. Supported testbed topology if it's a new test case? Any topology is supported for the test. Documentation link to feature HLD: sonic-net/SONiC#1024
1 parent 9693616 commit 7bb70bb

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
"""
2+
This test checks secure upgrade feature. If we have a secure system with secured image installed
3+
on it, the system is expected to install only secured images on it. So trying to install non-secure image
4+
will cause fail and a print of failure message to console indicating it is not a secured image.
5+
This test case validates the error flow mentioned above.
6+
7+
In order to run this test, you need to specify the following argument:
8+
9+
--target_image_list (to contain one non-secure image path e.g. /tmp/images/my_non_secure_img.bin)
10+
11+
Example run from tests directory:
12+
"pytest platform_tests/test_secure_upgrade.py <regular arguments> --target_image_list non_secure_image.bin"
13+
"""
14+
import logging
15+
import pytest
16+
import re
17+
from tests.common.errors import RunAnsibleModuleFail
18+
from tests.common.helpers.assertions import pytest_assert
19+
from tests.upgrade_path.upgrade_helpers import install_sonic
20+
21+
pytestmark = [
22+
pytest.mark.topology('any'),
23+
pytest.mark.disable_loganalyzer,
24+
]
25+
26+
logger = logging.getLogger(__name__)
27+
28+
29+
@pytest.fixture(scope='function', autouse=True)
30+
def keep_same_version_installed(duthost):
31+
'''
32+
@summary: extract the current version installed as shown in the "show boot" output
33+
and restore original image installed after the test run
34+
:param duthost: device under test
35+
'''
36+
output = duthost.shell("show boot")['stdout']
37+
results = re.findall(r"Current\s*\:\s*(.*)\n", output)
38+
pytest_assert(len(results) > 0, "Current image is empty!")
39+
current_version = results[0]
40+
yield
41+
duthost.shell("sudo sonic-installer set-default {}", format(current_version))
42+
43+
44+
@pytest.fixture(scope='session')
45+
def non_secure_image_path(request):
46+
'''
47+
@summary: will extract the non secure image path from --target_image_list parameter
48+
:return: given non secure image path
49+
'''
50+
non_secure_img_path = request.config.getoption('target_image_list')
51+
return str(non_secure_img_path)
52+
53+
54+
def test_non_secure_boot_upgrade_failure(duthost, non_secure_image_path, tbinfo):
55+
"""
56+
@summary: This test case validates non successful upgrade of a given non secure image
57+
"""
58+
# install non secure image
59+
logger.info("install non secure image - expect fail, image path = {}".format(non_secure_image_path))
60+
result = "image install failure" # because we expect fail
61+
try:
62+
# in case of success result will take the target image name
63+
result = install_sonic(duthost, non_secure_image_path, tbinfo)
64+
except RunAnsibleModuleFail as err:
65+
output_msg = str(err.results._check_key("module_stdout"))
66+
err_msg = str(err.results._check_key("msg"))
67+
logger.info("Expected fail, err msg is : {}\n\noutput_msg is {}".format(err_msg, output_msg))
68+
pytest_assert(
69+
"Failure: CMS signature verification failed" in str(output_msg),
70+
"failure was not due to security limitations")
71+
finally:
72+
pytest_assert(result == "image install failure", "non-secure image was successfully installed")

0 commit comments

Comments
 (0)