def test_upgrade_path(localhost, duthosts, rand_one_dut_hostname, ptfhost,
                      upgrade_path_lists, setup, creds, tbinfo):
    duthost = duthosts[rand_one_dut_hostname]
    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)
    for from_image in from_list:
        for to_image in to_list:
            logger.info("Test upgrade path from {} to {}".format(
                from_image, to_image))
            # Install base image
            logger.info("Installing {}".format(from_image))
            target_version = install_sonic(duthost, from_image, tbinfo)
            # Perform a cold reboot
            logger.info(
                "Cold reboot the DUT to make the base image as current")
            reboot(duthost, localhost)
            check_sonic_version(duthost, target_version)

            # Install target image
            logger.info("Upgrading to {}".format(to_image))
            target_version = install_sonic(duthost, to_image, tbinfo)
            test_params = ptf_params(duthost, creds, tbinfo, upgrade_type)
            test_params['target_version'] = target_version
            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'))
            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:
                if test_params['reboot_type'] == reboot_ctrl_dict.get(
                        REBOOT_TYPE_SOFT).get("command"):
                    # advance-reboot test (on ptf) does not support SOFT reboot yet
                    reboot(duthost, localhost, REBOOT_TYPE_SOFT)
                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(upgrade_type))
            pytest_assert(
                reboot_cause == upgrade_type,
                "Reboot cause {} did not match the trigger - {}".format(
                    reboot_cause, upgrade_type))
            check_services(duthost)
Ejemplo n.º 2
0
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