mirror of
https://github.com/flatcar/scripts.git
synced 2025-11-16 16:12:00 +01:00
Add ability to test machines with au test harness.
Change-Id: I913acd95c49b1cf0fd666b49fb5ec1e24f0f83d1 BUG=7285 TEST=Ran through test against with two test images. Review URL: http://codereview.chromium.org/3619009
This commit is contained in:
parent
db0fa3f9ac
commit
24680f0059
@ -13,12 +13,13 @@ sys.path.append(os.path.join(os.path.dirname(__file__), '../lib'))
|
|||||||
from cros_build_lib import RunCommand, Info, Warning, ReinterpretPathForChroot
|
from cros_build_lib import RunCommand, Info, Warning, ReinterpretPathForChroot
|
||||||
|
|
||||||
_KVM_PID_FILE = '/tmp/harness_pid'
|
_KVM_PID_FILE = '/tmp/harness_pid'
|
||||||
_SCRIPTS_DIR = os.path.join(os.path.dirname(__file__), '..')
|
|
||||||
_FULL_VDISK_SIZE = 6072
|
_FULL_VDISK_SIZE = 6072
|
||||||
_FULL_STATEFULFS_SIZE = 2048
|
_FULL_STATEFULFS_SIZE = 2048
|
||||||
|
|
||||||
|
# Globals to communicate options to unit tests.
|
||||||
global base_image_path
|
global base_image_path
|
||||||
global board
|
global board
|
||||||
|
global remote
|
||||||
global target_image_path
|
global target_image_path
|
||||||
|
|
||||||
_VERIFY_SUITE = 'suite_Smoke'
|
_VERIFY_SUITE = 'suite_Smoke'
|
||||||
@ -26,6 +27,20 @@ _VERIFY_SUITE = 'suite_Smoke'
|
|||||||
class AUTest(object):
|
class AUTest(object):
|
||||||
"""Abstract interface that defines an Auto Update test."""
|
"""Abstract interface that defines an Auto Update test."""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
unittest.TestCase.setUp(self)
|
||||||
|
# Set these up as they are used often.
|
||||||
|
self.crosutils = os.path.join(os.path.dirname(__file__), '..')
|
||||||
|
self.crosutilsbin = os.path.join(os.path.dirname(__file__))
|
||||||
|
|
||||||
|
def GetStatefulChangeFlag(self, stateful_change):
|
||||||
|
"""Returns the flag to pass to image_to_vm for the stateful change."""
|
||||||
|
stateful_change_flag = ''
|
||||||
|
if stateful_change:
|
||||||
|
stateful_change_flag = '--stateful_update_flag=%s' % stateful_change
|
||||||
|
|
||||||
|
return stateful_change_flag
|
||||||
|
|
||||||
def PrepareBase(self):
|
def PrepareBase(self):
|
||||||
"""Prepares target with base_image_path."""
|
"""Prepares target with base_image_path."""
|
||||||
pass
|
pass
|
||||||
@ -48,6 +63,11 @@ class AUTest(object):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def testFullUpdateKeepStateful(self):
|
def testFullUpdateKeepStateful(self):
|
||||||
|
"""Tests if we can update normally.
|
||||||
|
|
||||||
|
This test checks that we can update by updating the stateful partition
|
||||||
|
rather than wiping it.
|
||||||
|
"""
|
||||||
# Prepare and verify the base image has been prepared correctly.
|
# Prepare and verify the base image has been prepared correctly.
|
||||||
self.PrepareBase()
|
self.PrepareBase()
|
||||||
self.VerifyImage()
|
self.VerifyImage()
|
||||||
@ -62,7 +82,14 @@ class AUTest(object):
|
|||||||
self.UpdateImage(base_image_path)
|
self.UpdateImage(base_image_path)
|
||||||
self.VerifyImage()
|
self.VerifyImage()
|
||||||
|
|
||||||
def testFullUpdateWipeStateful(self):
|
# TODO(sosa): Re-enable once we have a good way of checking for version
|
||||||
|
# compatability.
|
||||||
|
def NotestFullUpdateWipeStateful(self):
|
||||||
|
"""Tests if we can update after cleaning the stateful partition.
|
||||||
|
|
||||||
|
This test checks that we can update successfully after wiping the
|
||||||
|
stateful partition.
|
||||||
|
"""
|
||||||
# Prepare and verify the base image has been prepared correctly.
|
# Prepare and verify the base image has been prepared correctly.
|
||||||
self.PrepareBase()
|
self.PrepareBase()
|
||||||
self.VerifyImage()
|
self.VerifyImage()
|
||||||
@ -78,6 +105,34 @@ class AUTest(object):
|
|||||||
self.VerifyImage()
|
self.VerifyImage()
|
||||||
|
|
||||||
|
|
||||||
|
class RealAUTest(unittest.TestCase, AUTest):
|
||||||
|
"""Test harness for updating real images."""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
AUTest.setUp(self)
|
||||||
|
|
||||||
|
def UpdateImage(self, image_path, stateful_change='old'):
|
||||||
|
"""Updates a remote image using image_to_live.sh."""
|
||||||
|
stateful_change_flag = self.GetStatefulChangeFlag(stateful_change)
|
||||||
|
|
||||||
|
RunCommand([
|
||||||
|
'%s/image_to_live.sh' % self.crosutils,
|
||||||
|
'--image=%s' % image_path,
|
||||||
|
'--remote=%s' % remote,
|
||||||
|
stateful_change_flag,
|
||||||
|
'--verify',
|
||||||
|
], enter_chroot=False)
|
||||||
|
|
||||||
|
|
||||||
|
def NotVerifyImage(self):
|
||||||
|
"""Verifies an image using run_remote_tests.sh with verification suite."""
|
||||||
|
RunCommand([
|
||||||
|
'%s/run_remote_tests.sh' % self.crosutils,
|
||||||
|
'--remote=%s' % remote,
|
||||||
|
_VERIFY_SUITE,
|
||||||
|
], error_ok=False, enter_chroot=False)
|
||||||
|
|
||||||
|
|
||||||
class VirtualAUTest(unittest.TestCase, AUTest):
|
class VirtualAUTest(unittest.TestCase, AUTest):
|
||||||
"""Test harness for updating virtual machines."""
|
"""Test harness for updating virtual machines."""
|
||||||
vm_image_path = None
|
vm_image_path = None
|
||||||
@ -95,7 +150,7 @@ class VirtualAUTest(unittest.TestCase, AUTest):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""Unit test overriden method. Is called before every test."""
|
"""Unit test overriden method. Is called before every test."""
|
||||||
|
AUTest.setUp(self)
|
||||||
self._KillExistingVM(_KVM_PID_FILE)
|
self._KillExistingVM(_KVM_PID_FILE)
|
||||||
|
|
||||||
def PrepareBase(self):
|
def PrepareBase(self):
|
||||||
@ -105,7 +160,7 @@ class VirtualAUTest(unittest.TestCase, AUTest):
|
|||||||
base_image_path))
|
base_image_path))
|
||||||
if not os.path.exists(self.vm_image_path):
|
if not os.path.exists(self.vm_image_path):
|
||||||
Info('Qemu image not found, creating one.')
|
Info('Qemu image not found, creating one.')
|
||||||
RunCommand(['%s/image_to_vm.sh' % _SCRIPTS_DIR,
|
RunCommand(['%s/image_to_vm.sh' % self.crosutils,
|
||||||
'--full',
|
'--full',
|
||||||
'--from %s' % ReinterpretPathForChroot(
|
'--from %s' % ReinterpretPathForChroot(
|
||||||
os.path.dirname(base_image_path)),
|
os.path.dirname(base_image_path)),
|
||||||
@ -120,12 +175,9 @@ class VirtualAUTest(unittest.TestCase, AUTest):
|
|||||||
|
|
||||||
def UpdateImage(self, image_path, stateful_change='old'):
|
def UpdateImage(self, image_path, stateful_change='old'):
|
||||||
"""Updates VM image with image_path."""
|
"""Updates VM image with image_path."""
|
||||||
|
stateful_change_flag = self.GetStatefulChangeFlag(stateful_change)
|
||||||
|
|
||||||
stateful_change_flag = ''
|
RunCommand(['%s/cros_run_vm_update' % self.crosutilsbin,
|
||||||
if stateful_change:
|
|
||||||
stateful_change_flag = '--stateful_flags=%s' % stateful_change
|
|
||||||
|
|
||||||
RunCommand(['%s/cros_run_vm_update' % os.path.dirname(__file__),
|
|
||||||
'--update_image_path=%s' % image_path,
|
'--update_image_path=%s' % image_path,
|
||||||
'--vm_image_path=%s' % self.vm_image_path,
|
'--vm_image_path=%s' % self.vm_image_path,
|
||||||
'--snapshot',
|
'--snapshot',
|
||||||
@ -136,18 +188,15 @@ class VirtualAUTest(unittest.TestCase, AUTest):
|
|||||||
|
|
||||||
def VerifyImage(self):
|
def VerifyImage(self):
|
||||||
"""Runs vm smoke suite to verify image."""
|
"""Runs vm smoke suite to verify image."""
|
||||||
|
|
||||||
# image_to_live already verifies lsb-release matching. This is just
|
# image_to_live already verifies lsb-release matching. This is just
|
||||||
# for additional steps.
|
# for additional steps.
|
||||||
|
RunCommand(['%s/cros_run_vm_test' % self.crosutilsbin,
|
||||||
# TODO(sosa): Compare output with results of base image.
|
|
||||||
RunCommand(['%s/cros_run_vm_test' % os.path.dirname(__file__),
|
|
||||||
'--image_path=%s' % self.vm_image_path,
|
'--image_path=%s' % self.vm_image_path,
|
||||||
'--snapshot',
|
'--snapshot',
|
||||||
'--persist',
|
'--persist',
|
||||||
'--kvm_pid=%s' % _KVM_PID_FILE,
|
'--kvm_pid=%s' % _KVM_PID_FILE,
|
||||||
'--test_case=%s' % _VERIFY_SUITE,
|
'--test_case=%s' % _VERIFY_SUITE,
|
||||||
], error_ok=True, enter_chroot=False)
|
], error_ok=False, enter_chroot=False)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@ -155,9 +204,13 @@ if __name__ == '__main__':
|
|||||||
parser.add_option('-b', '--base_image',
|
parser.add_option('-b', '--base_image',
|
||||||
help='path to the base image.')
|
help='path to the base image.')
|
||||||
parser.add_option('-t', '--target_image',
|
parser.add_option('-t', '--target_image',
|
||||||
help='path to the target image')
|
help='path to the target image.')
|
||||||
parser.add_option('-r', '--board',
|
parser.add_option('-r', '--board',
|
||||||
help='board for the images')
|
help='board for the images.')
|
||||||
|
parser.add_option('-p', '--type', default='vm',
|
||||||
|
help='type of test to run: [vm, real]. Default: vm.')
|
||||||
|
parser.add_option('-m', '--remote',
|
||||||
|
help='Remote address for real test.')
|
||||||
# Set the usage to include flags.
|
# Set the usage to include flags.
|
||||||
parser.set_usage(parser.format_help())
|
parser.set_usage(parser.format_help())
|
||||||
# Parse existing sys.argv so we can pass rest to unittest.main.
|
# Parse existing sys.argv so we can pass rest to unittest.main.
|
||||||
@ -176,4 +229,17 @@ if __name__ == '__main__':
|
|||||||
if not board:
|
if not board:
|
||||||
parser.error('Need board to convert base image to vm.')
|
parser.error('Need board to convert base image to vm.')
|
||||||
|
|
||||||
unittest.main()
|
# Only run the test harness we care about.
|
||||||
|
if options.type == 'vm':
|
||||||
|
suite = unittest.TestLoader().loadTestsFromTestCase(VirtualAUTest)
|
||||||
|
unittest.TextTestRunner(verbosity=2).run(suite)
|
||||||
|
elif options.type == 'real':
|
||||||
|
if not options.remote:
|
||||||
|
parser.error('Real tests require a remote test machine.')
|
||||||
|
else:
|
||||||
|
remote = options.remote
|
||||||
|
|
||||||
|
suite = unittest.TestLoader().loadTestsFromTestCase(RealAUTest)
|
||||||
|
unittest.TextTestRunner(verbosity=2).run(suite)
|
||||||
|
else:
|
||||||
|
parser.error('Could not parse harness type %s.' % options.type)
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
. "$(dirname $0)/../common.sh"
|
. "$(dirname $0)/../common.sh"
|
||||||
. "$(dirname $0)/../lib/cros_vm_lib.sh"
|
. "$(dirname $0)/../lib/cros_vm_lib.sh"
|
||||||
|
|
||||||
DEFINE_string stateful_flags "" "Flags to pass to stateful update." s
|
DEFINE_string stateful_update_flag "" "Flags to pass to stateful update." s
|
||||||
DEFINE_string update_image_path "" "Path of the image to update to." u
|
DEFINE_string update_image_path "" "Path of the image to update to." u
|
||||||
DEFINE_string vm_image_path "" "Path of the VM image to update from." v
|
DEFINE_string vm_image_path "" "Path of the VM image to update from." v
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ start_kvm "${FLAGS_vm_image_path}"
|
|||||||
$(dirname $0)/../image_to_live.sh \
|
$(dirname $0)/../image_to_live.sh \
|
||||||
--remote=${HOSTNAME} \
|
--remote=${HOSTNAME} \
|
||||||
--ssh_port=${FLAGS_ssh_port} \
|
--ssh_port=${FLAGS_ssh_port} \
|
||||||
--stateful_update_flag=${stateful_flags} \
|
--stateful_update_flag=${FLAGS_stateful_update_flag} \
|
||||||
--verify \
|
--verify \
|
||||||
--image=$(readlink -f ${FLAGS_update_image_path})
|
--image=$(readlink -f ${FLAGS_update_image_path})
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user