Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for fast and cold upgrade in test_upgrade_path #3047

Merged
merged 2 commits into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions ansible/library/reduce_and_add_sonic_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ def download_new_sonic_image(module, new_image_url, save_as):
cmd="rm -f {}".format(save_as),
msg="clean up previously downloaded image",
ignore_error=True)

exec_command(module,
cmd="curl -o {} {}".format(save_as, new_image_url),
msg="downloading new image")
if new_image_url:
exec_command(module,
cmd="curl -o {} {}".format(save_as, new_image_url),
msg="downloading new image")

if path.exists(save_as):
_, out, _ = exec_command(module, cmd="sonic_installer binary_version {}".format(save_as))
Expand Down
9 changes: 8 additions & 1 deletion tests/upgrade_path/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
def pytest_addoption(parser):
options_group = parser.getgroup("Upgrade_path test suite options")

options_group.addoption(
"--upgrade_type",
default="warm",
help="Specify the type (warm/fast/cold) of upgrade that is needed from source to target image",
)

options_group.addoption(
"--base_image_list",
default="",
Expand Down Expand Up @@ -33,7 +39,8 @@ def pytest_runtest_setup(item):

@pytest.fixture(scope="module")
def upgrade_path_lists(request):
upgrade_type = request.config.getoption('upgrade_type')
from_list = request.config.getoption('base_image_list')
to_list = request.config.getoption('target_image_list')
restore_to_image = request.config.getoption('restore_to_image')
return from_list, to_list, restore_to_image
return upgrade_type, from_list, to_list, restore_to_image
67 changes: 34 additions & 33 deletions tests/upgrade_path/test_upgrade_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from tests.common.helpers.assertions import pytest_assert
from tests.common.platform.ssh_utils import prepare_testbed_ssh_keys
from tests.common import reboot
from tests.common.reboot import get_reboot_cause
from tests.common.reboot import REBOOT_TYPE_WARM
from tests.common.reboot import get_reboot_cause, reboot_ctrl_dict
from tests.common.reboot import REBOOT_TYPE_WARM, REBOOT_TYPE_COLD


from tests.common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import]
Expand Down Expand Up @@ -44,7 +44,7 @@ def setup(localhost, ptfhost, duthosts, rand_one_dut_hostname, upgrade_path_list


def cleanup(localhost, ptfhost, duthost, upgrade_path_lists, tbinfo):
_, _, restore_to_image = upgrade_path_lists
_, _, _, restore_to_image = upgrade_path_lists
if restore_to_image:
logger.info("Preparing to cleanup and restore to {}".format(restore_to_image))
# restore orignial image
Expand Down Expand Up @@ -89,7 +89,7 @@ def prepare_ptf(ptfhost, duthost, tbinfo):


@pytest.fixture(scope="module")
def ptf_params(duthosts, rand_one_dut_hostname, nbrhosts, creds, tbinfo):
def ptf_params(duthosts, rand_one_dut_hostname, creds, tbinfo):
duthost = duthosts[rand_one_dut_hostname]

if duthost.facts['platform'] == 'x86_64-kvm_x86_64-r0':
Expand All @@ -105,12 +105,10 @@ def ptf_params(duthosts, rand_one_dut_hostname, nbrhosts, creds, tbinfo):
lo_v6_prefix = str(ipaddr.IPNetwork(intf['addr'] + '/64').network) + '/64'
break

vm_hosts = []
nbrs = nbrhosts
for key, value in nbrs.items():
#TODO:Update to vm_hosts.append(value['host'].host.mgmt_ip)
vm_hosts.append(value['host'].host.options['inventory_manager'].get_host(value['host'].hostname).vars['ansible_host'])

mgFacts = duthost.get_extended_minigraph_facts(tbinfo)
vm_hosts = [
attr['mgmt_addr'] for dev, attr in mgFacts['minigraph_devices'].items() if attr['hwsku'] == 'Arista-VM'
]
sonicadmin_alt_password = duthost.host.options['variable_manager']._hostvars[duthost.hostname].get("ansible_altpassword")
ptf_params = {
"verbose": False,
Expand All @@ -135,16 +133,15 @@ def ptf_params(duthosts, rand_one_dut_hostname, nbrhosts, creds, tbinfo):
return ptf_params


def get_reboot_type(duthost):
next_os_version = duthost.shell('sonic_installer list | grep Next | cut -f2 -d " "')['stdout']
current_os_version = duthost.shell('sonic_installer list | grep Current | cut -f2 -d " "')['stdout']

# warm-reboot has to be forced for an upgrade from 201811 to 201811+ to bypass ASIC config changed error
if 'SONiC-OS-201811' in current_os_version and 'SONiC-OS-201811' not in next_os_version:
reboot_type = "warm-reboot -f"
else:
reboot_type = "warm-reboot"
return reboot_type
def get_reboot_command(duthost, upgrade_type):
reboot_command = reboot_ctrl_dict.get(upgrade_type).get("command")
if upgrade_type == REBOOT_TYPE_WARM:
next_os_version = duthost.shell('sonic_installer list | grep Next | cut -f2 -d " "')['stdout']
current_os_version = duthost.shell('sonic_installer list | grep Current | cut -f2 -d " "')['stdout']
# warm-reboot has to be forced for an upgrade from 201811 to 201811+ to bypass ASIC config changed error
if 'SONiC-OS-201811' in current_os_version and 'SONiC-OS-201811' not in next_os_version:
reboot_command = "warm-reboot -f"
return reboot_command


def check_sonic_version(duthost, target_version):
Expand Down Expand Up @@ -182,6 +179,7 @@ def install_sonic(duthost, image_url, tbinfo):
duthost.shell("mkdir -p /tmp/tmpfs", module_ignore_errors=True)
duthost.shell("umount /tmp/tmpfs", module_ignore_errors=True)
duthost.shell("mount -t tmpfs -o size=1300M tmpfs /tmp/tmpfs", module_ignore_errors=True)
logger.info("Image exists locally. Copying the image {} into the device path {}".format(image_url, save_as))
duthost.copy(src=image_url, dest=save_as)
res = duthost.reduce_and_add_sonic_images(save_as=save_as)

Expand Down Expand Up @@ -213,7 +211,7 @@ def check_services(duthost):
@pytest.mark.device_type('vs')
def test_upgrade_path(localhost, duthosts, rand_one_dut_hostname, ptfhost, upgrade_path_lists, ptf_params, setup, tbinfo):
duthost = duthosts[rand_one_dut_hostname]
from_list_images, to_list_images, _ = upgrade_path_lists
upgrade_type, from_list_images, to_list_images, _ = upgrade_path_lists
from_list = from_list_images.split(',')
to_list = to_list_images.split(',')
assert (from_list and to_list)
Expand All @@ -233,20 +231,23 @@ def test_upgrade_path(localhost, duthosts, rand_one_dut_hostname, ptfhost, upgra
target_version = install_sonic(duthost, to_image, tbinfo)
test_params = ptf_params
test_params['target_version'] = target_version
test_params['reboot_type'] = get_reboot_type(duthost)
test_params['reboot_type'] = get_reboot_command(duthost, upgrade_type)
prepare_testbed_ssh_keys(duthost, ptfhost, test_params['dut_username'])
log_file = "/tmp/advanced-reboot.ReloadTest.{}.log".format(datetime.now().strftime('%Y-%m-%d-%H:%M:%S'))

ptf_runner(ptfhost,
"ptftests",
"advanced-reboot.ReloadTest",
platform_dir="ptftests",
params=test_params,
platform="remote",
qlen=10000,
log_file=log_file)
if test_params['reboot_type'] == reboot_ctrl_dict.get(REBOOT_TYPE_COLD).get("command"):
# advance-reboot test (on ptf) does not support cold reboot yet
reboot(duthost, localhost)
else:
ptf_runner(ptfhost,
"ptftests",
"advanced-reboot.ReloadTest",
platform_dir="ptftests",
params=test_params,
platform="remote",
qlen=10000,
log_file=log_file)
reboot_cause = get_reboot_cause(duthost)
logger.info("Check reboot cause. Expected cause {}".format(REBOOT_TYPE_WARM))
pytest_assert(reboot_cause == REBOOT_TYPE_WARM, "Reboot cause {} did not match the trigger - {}".format(reboot_cause, REBOOT_TYPE_WARM))
logger.info("Check reboot cause. Expected cause {}".format(upgrade_type))
pytest_assert(reboot_cause == upgrade_type, "Reboot cause {} did not match the trigger - {}".format(reboot_cause, upgrade_type))
check_services(duthost)