Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1169)

Unified Diff: bin/cros_au_test_harness.py

Issue 5632002: Create a transparent proxy for test programs to use, with the (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/crosutils.git@master
Patch Set: Address review issues, remove extend. Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | image_to_live.sh » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bin/cros_au_test_harness.py
diff --git a/bin/cros_au_test_harness.py b/bin/cros_au_test_harness.py
index 3ffdac53cc24a276a0ce69a9ceff8cf0c6730268..5129aeaf6bbfd346ac65d0741ccf9f9adc0dd734 100755
--- a/bin/cros_au_test_harness.py
+++ b/bin/cros_au_test_harness.py
@@ -8,6 +8,8 @@ import optparse
import os
import re
import sys
+import thread
+import time
import unittest
import urllib
@@ -19,6 +21,8 @@ from cros_build_lib import RunCommand
from cros_build_lib import RunCommandCaptureOutput
from cros_build_lib import Warning
+import cros_test_proxy
+
# VM Constants.
_FULL_VDISK_SIZE = 6072
_FULL_STATEFULFS_SIZE = 3074
@@ -89,20 +93,21 @@ class AUTest(object):
else:
self._UpdateImageReportError(image)
- def _UpdateImageReportError(self, image_path, stateful_change='old'):
+ def _UpdateImageReportError(self, image_path, stateful_change='old',
+ proxy_port=None):
"""Calls UpdateImage and reports any error to the console.
Still throws the exception.
"""
try:
- self.UpdateImage(image_path, stateful_change)
+ self.UpdateImage(image_path, stateful_change, proxy_port)
except UpdateException as err:
# If the update fails, print it out
Warning(err.stdout)
raise
def _AttemptUpdateWithPayloadExpectedFailure(self, payload, expected_msg):
- # This update is expected to fail...
+ """Attempt a payload update, expect it to fail with expected log"""
try:
self.UpdateUsingPayload(payload)
except UpdateException as err:
@@ -114,11 +119,29 @@ class AUTest(object):
Warning(err.stdout)
self.fail('We managed to update when failure was expected')
+ def _AttemptUpdateWithFilter(self, filter):
+ """Update through a proxy, with a specified filter, and expect success."""
+
+ self.PrepareBase(target_image_path)
+
+ proxy_port = 8081
+ proxy = cros_test_proxy.CrosTestProxy(port_in=proxy_port,
+ address_out='127.0.0.1',
+ port_out=8080,
+ filter=filter)
+ proxy.serve_forever_in_thread()
+
+ # This update is expected to fail...
+ try:
+ self._UpdateImageReportError(target_image_path, proxy_port=proxy_port)
+ finally:
+ proxy.shutdown()
+
def PrepareBase(self, image_path):
"""Prepares target with base_image_path."""
pass
- def UpdateImage(self, image_path, stateful_change='old'):
+ def UpdateImage(self, image_path, stateful_change='old', proxy_port=None):
"""Updates target with the image given by the image_path.
Args:
@@ -128,15 +151,22 @@ class AUTest(object):
'old': Don't modify stateful partition. Just update normally.
'clean': Uses clobber-state to wipe the stateful partition with the
exception of code needed for ssh.
+ proxy_port: Port to have the client connect to. For use with
+ CrosTestProxy.
"""
pass
- def UpdateUsingPayload(self, update_path, stateful_change='old'):
+ def UpdateUsingPayload(self,
+ update_path,
+ stateful_change='old',
+ proxy_port=None):
"""Updates target with the pre-generated update stored in update_path
Args:
update_path: Path to the image to update with. This directory should
- contain both update.gz, and stateful.image.gz
+ contain both update.gz, and stateful.image.gz
+ proxy_port: Port to have the client connect to. For use with
+ CrosTestProxy.
"""
pass
@@ -185,7 +215,7 @@ class AUTest(object):
"""
# Just make sure some tests pass on original image. Some old images
# don't pass many tests.
- self.PrepareBase(image_path=base_image_path)
+ self.PrepareBase(base_image_path)
# TODO(sosa): move to 100% once we start testing using the autotest paired
# with the dev channel.
percent_passed = self.VerifyImage(10)
@@ -208,7 +238,7 @@ class AUTest(object):
"""
# Just make sure some tests pass on original image. Some old images
# don't pass many tests.
- self.PrepareBase(image_path=base_image_path)
+ self.PrepareBase(base_image_path)
# TODO(sosa): move to 100% once we start testing using the autotest paired
# with the dev channel.
percent_passed = self.VerifyImage(10)
@@ -226,7 +256,7 @@ class AUTest(object):
def testPartialUpdate(self):
"""Tests what happens if we attempt to update with a truncated payload."""
# Preload with the version we are trying to test.
- self.PrepareBase(image_path=target_image_path)
+ self.PrepareBase(target_image_path)
# Image can be updated at:
# ~chrome-eng/chromeos/localmirror/autest-images
@@ -243,7 +273,7 @@ class AUTest(object):
def testCorruptedUpdate(self):
"""Tests what happens if we attempt to update with a corrupted payload."""
# Preload with the version we are trying to test.
- self.PrepareBase(image_path=target_image_path)
+ self.PrepareBase(target_image_path)
# Image can be updated at:
# ~chrome-eng/chromeos/localmirror/autest-images
@@ -258,6 +288,71 @@ class AUTest(object):
expected_msg='zlib inflate() error:-3'
self._AttemptUpdateWithPayloadExpectedFailure(payload, expected_msg)
+ def testInterruptedUpdate(self):
+ """Tests what happens if we interrupt payload delivery 3 times."""
+
+ class InterruptionFilter(cros_test_proxy.Filter):
+ """This filter causes the proxy to interrupt the download 3 times
+
+ It does this by closing the first three connections to transfer
+ 2M total in the outbound connection after they transfer the
+ 2M.
+ """
+ def __init__(self):
+ """Defines variable shared across all connections"""
+ self.close_count = 0
+
+ def setup(self):
+ """Called once at the start of each connection."""
+ self.data_size = 0
+
+ def OutBound(self, data):
+ """Called once per packet for outgoing data.
+
+ The first three connections transferring more than 2M
+ outbound will be closed.
+ """
+ if self.close_count < 3:
+ if self.data_size > (2 * 1024 * 1024):
+ self.close_count += 1
+ return None
+
+ self.data_size += len(data)
+ return data
+
+ self._AttemptUpdateWithFilter(InterruptionFilter())
+
+ def testDelayedUpdate(self):
+ """Tests what happens if some data is delayed during update delivery"""
+
+ class DelayedFilter(cros_test_proxy.Filter):
+ """Causes intermittent delays in data transmission.
+
+ It does this by inserting 3 20 second delays when transmitting
+ data after 2M has been sent.
+ """
+ def setup(self):
+ """Called once at the start of each connection."""
+ self.data_size = 0
+ self.delay_count = 0
+
+ def OutBound(self, data):
+ """Called once per packet for outgoing data.
+
+ The first three packets after we reach 2M transferred
+ are delayed by 20 seconds.
+ """
+ if self.delay_count < 3:
+ if self.data_size > (2 * 1024 * 1024):
+ self.delay_count += 1
+ time.sleep(20)
+
+ self.data_size += len(data)
+ return data
+
+
+ self._AttemptUpdateWithFilter(DelayedFilter())
+
class RealAUTest(unittest.TestCase, AUTest):
"""Test harness for updating real images."""
@@ -268,10 +363,14 @@ class RealAUTest(unittest.TestCase, AUTest):
"""Auto-update to base image to prepare for test."""
self._UpdateImageReportError(image_path)
- def UpdateImage(self, image_path, stateful_change='old'):
+ def UpdateImage(self, image_path, stateful_change='old', proxy_port=None):
"""Updates a remote image using image_to_live.sh."""
stateful_change_flag = self.GetStatefulChangeFlag(stateful_change)
+ port_flags = []
+ if proxy_port:
+ port_flags.append('--proxy_port=%s' % proxy_port)
+
(code, stdout, stderr) = RunCommandCaptureOutput([
'%s/image_to_live.sh' % self.crosutils,
'--image=%s' % image_path,
@@ -279,22 +378,29 @@ class RealAUTest(unittest.TestCase, AUTest):
stateful_change_flag,
'--verify',
'--src_image=%s' % self.source_image
- ])
+ ] + port_flags)
dgarrett 2010/12/09 00:48:38 Turns out that extend returns None. I prefer keepi
if code != 0:
raise UpdateException(code, stdout)
- def UpdateUsingPayload(self, update_path, stateful_change='old'):
+ def UpdateUsingPayload(self,
+ update_path,
+ stateful_change='old',
+ proxy_port=None):
"""Updates a remote image using image_to_live.sh."""
stateful_change_flag = self.GetStatefulChangeFlag(stateful_change)
+ port_flags = []
+ if proxy_port:
+ port_flags.append('--proxy_port=%s' % proxy_port)
+
(code, stdout, stderr) = RunCommandCaptureOutput([
'%s/image_to_live.sh' % self.crosutils,
'--payload=%s' % update_path,
'--remote=%s' % remote,
stateful_change_flag,
'--verify',
- ])
+ ] + port_flags)
if code != 0:
raise UpdateException(code, stdout)
@@ -354,12 +460,16 @@ class VirtualAUTest(unittest.TestCase, AUTest):
self.assertTrue(os.path.exists(self.vm_image_path))
- def UpdateImage(self, image_path, stateful_change='old'):
+ def UpdateImage(self, image_path, stateful_change='old', proxy_port=None):
"""Updates VM image with image_path."""
stateful_change_flag = self.GetStatefulChangeFlag(stateful_change)
if self.source_image == base_image_path:
self.source_image = self.vm_image_path
+ port_flags = []
+ if proxy_port:
+ port_flags.append('--proxy_port=%s' % proxy_port)
+
(code, stdout, stderr) = RunCommandCaptureOutput([
'%s/cros_run_vm_update' % self.crosutilsbin,
'--update_image_path=%s' % image_path,
@@ -370,17 +480,24 @@ class VirtualAUTest(unittest.TestCase, AUTest):
'--kvm_pid=%s' % _KVM_PID_FILE,
stateful_change_flag,
'--src_image=%s' % self.source_image,
- ])
+ ] + port_flags)
if code != 0:
raise UpdateException(code, stdout)
- def UpdateUsingPayload(self, update_path, stateful_change='old'):
+ def UpdateUsingPayload(self,
+ update_path,
+ stateful_change='old',
+ proxy_port=None):
"""Updates a remote image using image_to_live.sh."""
stateful_change_flag = self.GetStatefulChangeFlag(stateful_change)
if self.source_image == base_image_path:
self.source_image = self.vm_image_path
+ port_flags = []
+ if proxy_port:
+ port_flags.append('--proxy_port=%s' % proxy_port)
+
(code, stdout, stderr) = RunCommandCaptureOutput([
'%s/cros_run_vm_update' % self.crosutilsbin,
'--payload=%s' % update_path,
@@ -391,7 +508,7 @@ class VirtualAUTest(unittest.TestCase, AUTest):
'--kvm_pid=%s' % _KVM_PID_FILE,
stateful_change_flag,
'--src_image=%s' % self.source_image,
- ])
+ ] + port_flags)
if code != 0:
raise UpdateException(code, stdout)
« no previous file with comments | « no previous file | image_to_live.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698