blob: 6f677b2f30660da493ac64e085863744ed70bc05 [file] [log] [blame]
# Copyright 2018 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import logging
import shutil
from autotest_lib.client.bin import test, utils
from autotest_lib.client.common_lib import error
from autotest_lib.client.cros.update_engine import update_engine_util
class UpdateEngineTest(test.test, update_engine_util.UpdateEngineUtil):
"""Base class for update engine client tests."""
_NETWORK_INTERFACES = ['eth0', 'eth1', 'eth2']
def initialize(self):
"""Initialize for this test."""
self._internet_was_disabled = False
def cleanup(self):
"""Cleanup for this test."""
# Make sure to grab the update engine log for every test run.
shutil.copy(self._UPDATE_ENGINE_LOG, self.resultsdir)
# Ensure ethernet adapters are back on
def _enable_internet(self, ping_server=''):
Re-enables the internet connection.
@param ping_server: The server to ping to check we are online.
if not self._internet_was_disabled:
self._internet_was_disabled = False
logging.debug('Before reconnect: %s','ifconfig'))
for eth in self._NETWORK_INTERFACES:'ifconfig %s up' % eth, ignore_status=True)
utils.start_service('recover_duts', ignore_status=True)
# Print ifconfig to help debug DUTs that stay offline.
logging.debug('After reconnect: %s','ifconfig'))
# We can't return right after reconnecting the network or the server
# test may not receive the message. So we wait a bit longer for the
# DUT to be reconnected.
tries=3, timeout=10) == 0,
'Ping failed after reconnecting network'))
def _disable_internet(self, ping_server=''):
"""Disable the internet connection"""
self._internet_was_disabled = True
logging.debug('Before disconnect: %s','ifconfig'))
# DUTs in the lab have a service called recover_duts that is used to
# check that the DUT is online and if it is not it will bring it
# back online. We will need to stop this service for the length
# of this test.
utils.stop_service('recover_duts', ignore_status=True)
for eth in self._NETWORK_INTERFACES:
result ='ifconfig %s down' % eth, ignore_status=True)
# Print ifconfig to help debug DUTs that stay online.
logging.debug('After disconnect: %s','ifconfig'))
# Make sure we are offline
timeout=5) != 0,
desc='Ping failure while offline.')
except (error.CmdError, utils.TimeoutError):
logging.exception('Failed to disconnect one or more interfaces.')
logging.debug('ifconfig', ignore_status=True))
raise error.TestFail('Disabling the internet connection failed.')