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

Upgrade path fixes and improvements #2424

Merged
merged 3 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 14 additions & 5 deletions ansible/library/reduce_and_add_sonic_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@

def exec_command(module, cmd, ignore_error=False, msg="executing command"):
rc, out, err = module.run_command(cmd)
if not ignore_error and rc != 0:
if ignore_error:
return rc, out, err
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should restore the original code structure and change line 38 instead. With your change, the succeeded path will return different number of return values.

if rc != 0:
module.fail_json(msg="Failed %s: rc=%d, out=%s, err=%s" %
(msg, rc, out, err))
return out
Expand Down Expand Up @@ -68,10 +70,14 @@ def install_new_sonic_image(module, new_image_url):
# There is enough space to install directly
save_as = "/host/downloaded-sonic-image"
download_new_sonic_image(module, new_image_url, save_as)
exec_command(module,
rc, out, err = exec_command(module,
cmd="sonic_installer install {} -y".format(save_as),
msg="installing new image")
msg="installing new image", ignore_error=True)
# Always remove the downloaded temp image inside /host/ before proceeding
exec_command(module, cmd="rm -f {}".format(save_as))
if rc != 0:
module.fail_json(msg="Image installation failed: rc=%d, out=%s, err=%s" %
(rc, out, err))
else:
# Create a tmpfs partition to download image to install
exec_command(module, cmd="mkdir -p /tmp/tmpfs", ignore_error=True)
Expand All @@ -82,13 +88,16 @@ def install_new_sonic_image(module, new_image_url):
msg="mounting tmpfs")
save_as = "/tmp/tmpfs/downloaded-sonic-image"
download_new_sonic_image(module, new_image_url, save_as)
exec_command(module,
rc, out, err = exec_command(module,
cmd="sonic_installer install {} -y".format(save_as),
msg="installing new image")
msg="installing new image", ignore_error=True)

exec_command(module, cmd="sync", ignore_error=True)
exec_command(module, cmd="umount /tmp/tmpfs", ignore_error=True)
exec_command(module, cmd="rm -rf /tmp/tmpfs", ignore_error=True)
if rc != 0:
module.fail_json(msg="Image installation failed: rc=%d, out=%s, err=%s" %
(rc, out, err))

# If sonic device is configured with minigraph, remove config_db.json
# to force next image to load minigraph.
Expand Down
8 changes: 4 additions & 4 deletions ansible/roles/test/files/ptftests/advanced-reboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ def setUp(self):

self.limit = datetime.timedelta(seconds=self.test_params['reboot_limit_in_seconds'])
self.reboot_type = self.test_params['reboot_type']
if self.reboot_type not in ['fast-reboot', 'warm-reboot']:
if self.reboot_type not in ['fast-reboot', 'warm-reboot', 'warm-reboot -f']:
yxieca marked this conversation as resolved.
Show resolved Hide resolved
raise ValueError('Not supported reboot_type %s' % self.reboot_type)
self.dut_mac = self.test_params['dut_mac']

Expand Down Expand Up @@ -537,7 +537,7 @@ def setUp(self):
self.generate_ping_dut_lo()
self.generate_arp_ping_packet()

if self.reboot_type == 'warm-reboot':
if 'warm-reboot' in self.reboot_type:
self.log(self.get_sad_info())

# Pre-generate list of packets to be sent in send_in_background method.
Expand Down Expand Up @@ -876,7 +876,7 @@ def wait_for_ssh_threads():
if self.reboot_type == 'fast-reboot' and self.no_cp_replies < 0.95 * self.nr_vl_pkts:
self.fails['dut'].add("Dataplane didn't route to all servers, when control-plane was down: %d vs %d" % (self.no_cp_replies, self.nr_vl_pkts))

if self.reboot_type == 'warm-reboot':
if 'warm-reboot' in self.reboot_type:
if self.total_disrupt_time > self.limit.total_seconds():
self.fails['dut'].add("Total downtime period must be less then %s seconds. It was %s" \
% (str(self.limit), str(self.total_disrupt_time)))
Expand Down Expand Up @@ -985,7 +985,7 @@ def runTest(self):
self.wait_until_reboot()
if self.reboot_type == 'fast-reboot':
self.handle_fast_reboot_health_check()
if self.reboot_type == 'warm-reboot':
if 'warm-reboot' in self.reboot_type:
self.handle_warm_reboot_health_check()
self.handle_post_reboot_health_check()

Expand Down
2 changes: 2 additions & 0 deletions tests/common/fixtures/advanced_reboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ def __handleRebootImage(self):

logger.info('Remove config_db.json so the new image will reload minigraph')
self.duthost.shell('rm -f /host/old_config/config_db.json')
logger.info('Remove downloaded tempfile')
self.duthost.shell('rm -f {}'.format(tempfile))

def __setupTestbed(self):
'''
Expand Down
13 changes: 12 additions & 1 deletion tests/upgrade_path/test_upgrade_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ def ptf_params(duthost, nbrhosts, creds):
}
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 201911 to bypass ASIC config changed error
if 'SONiC-OS-201811' in current_os_version and 'SONiC-OS-201911' in next_os_version:
reboot_type = "warm-reboot -f"
else:
reboot_type = "warm-reboot"
return reboot_type

def check_sonic_version(duthost, target_version):
current_version = duthost.image_facts()['ansible_facts']['ansible_image_facts']['current']
Expand All @@ -134,7 +144,6 @@ def test_upgrade_path(localhost, duthost, ptfhost, upgrade_path_lists, ptf_param
from_list = from_list_images.split(',')
to_list = to_list_images.split(',')
assert (from_list and to_list)
test_params = ptf_params
for from_image in from_list:
for to_image in to_list:
logger.info("Test upgrade path from {} to {}".format(from_image, to_image))
Expand All @@ -148,7 +157,9 @@ def test_upgrade_path(localhost, duthost, ptfhost, upgrade_path_lists, ptf_param
# Install target image
logger.info("Upgrading to {}".format(to_image))
target_version = install_sonic(duthost, to_image)
test_params = ptf_params
test_params['target_version'] = target_version
test_params['reboot_type'] = get_reboot_type(duthost)
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'))

Expand Down