def run_once(self, image_url, image_size, sha256):
        # Start an omaha instance on the DUT that will return a response with
        # two Urls. This matches what test and production omaha does today.
        self._omaha = nano_omaha_devserver.NanoOmahaDevserver()
        self._omaha.set_image_params(image_url, image_size, sha256)
        self._omaha.start()

        # Start the update.
        self._check_for_update(port=self._omaha.get_port())
        self._wait_for_progress(0.2)

        # Pull the network cable so the update fails.
        self._disable_internet()

        # It will retry 21 times before giving up.
        self._wait_for_update_to_fail()

        # Check that we are moving to the next Url.
        self._enable_internet()
        self._check_update_engine_log_for_entry('Reached max number of '
                                                'failures for Url')

        # The next update attempt should resume and finish successfully.
        self._check_for_update(port=self._omaha.get_port())
        self._wait_for_update_to_complete()
        self._check_update_engine_log_for_entry('Resuming an update that was '
                                                'previously started.')
Exemple #2
0
    def __init__(self, image_url, image_size, sha256, to_build=_MAX_BUILD,
                 from_build=_MIN_BUILD, is_rollback=False, is_critical=False):
        """
        Start a Nano Omaha instance and intialize variables.

        @param image_url: Url of update image.
        @param image_size: Size of the update.
        @param sha256: Sha256 hash of the update.
        @param to_build: String of the build number Nano Omaha should serve.
        @param from_build: String of the build number this device should say
                           it is on by setting lsb_release.
        @param is_rollback: whether the build should serve with the rollback
                            flag.
        @param is_critical: whether the build should serve marked as critical.

        """
        self._omaha = nano_omaha_devserver.NanoOmahaDevserver()
        self._omaha.set_image_params(image_url, image_size, sha256,
                                     build=to_build, is_rollback=is_rollback)
        self._omaha.start()

        self._au_util = update_engine_util.UpdateEngineUtil()

        update_url = self._omaha.get_update_url()
        self._au_util._create_custom_lsb_release(from_build, update_url)

        self._is_rollback = is_rollback
        self._is_critical = is_critical
    def run_once(self):
        # Start a devserver to return a response with eol entry.
        self._omaha = nano_omaha_devserver.NanoOmahaDevserver(eol=True)
        self._omaha.start()

        # Try to update using the omaha server. It will fail with noupdate.
        self._check_for_update(port=self._omaha.get_port(),
                               ignore_status=True,
                               wait_for_completion=True)

        self._check_eol_status()
        self._check_eol_notification()
    def run_once(self):
        utils.run('restart update-engine')

        # Start a devserver to return a response with eol entry.
        self._omaha = nano_omaha_devserver.NanoOmahaDevserver(eol=True)
        self._omaha.start()

        # Try to update using the omaha server. It will fail with noupdate.
        utils.run('update_engine_client -update -omaha_url=' +
                  'http://127.0.0.1:%d/update ' % self._omaha.get_port(),
                  ignore_status=True)

        self._check_eol_status()
        self._check_eol_notification()
    def run_once(self, image_url, image_size, sha256, backoff):
        self._no_ignore_backoff = os.path.join(
            self._UPDATE_ENGINE_PREFS_DIR, self._NO_IGNORE_BACKOFF_PREF)
        self._backoff_expiry_time = os.path.join(
            self._UPDATE_ENGINE_PREFS_DIR, self._BACKOFF_EXPIRY_TIME_PREF)
        utils.run('touch %s' % self._no_ignore_backoff, ignore_status=True)

        # Only set one URL in the omaha response so we can test the backoff
        # functionality quicker.
        self._omaha = nano_omaha_devserver.NanoOmahaDevserver(
            backoff=backoff, num_urls=1)
        self._omaha.set_image_params(image_url, image_size, sha256)
        self._omaha.start()

        # Start the update.
        self._check_for_update(port=self._omaha.get_port(), interactive=False)
        self._wait_for_progress(0.2)

        # Disable internet so the update fails.
        self._disable_internet()
        self._wait_for_update_to_fail()
        self._enable_internet()

        if backoff:
            self._check_update_engine_log_for_entry(self._BACKOFF_ENABLED,
                                                    raise_error=True)
            utils.run('cat %s' % self._backoff_expiry_time)
            try:
                self._check_for_update(port=self._omaha.get_port(),
                                       interactive=False,
                                       wait_for_completion=True)
            except error.CmdError as e:
                logging.info('Update failed as expected.')
                logging.error(e)
                self._check_update_engine_log_for_entry(self._BACKOFF_ERROR,
                                                        raise_error=True)
                return

            raise error.TestFail('Second update attempt succeeded. It was '
                                 'supposed to have failed due to backoff.')
        else:
            self._check_update_engine_log_for_entry(self._BACKOFF_DISABLED,
                                                    raise_error=True)
            self._check_for_update(port=self._omaha.get_port(),
                                   interactive=False)
            self._wait_for_update_to_complete()
    def run_once(self, image_url, image_size, sha256, metadata_size=None):
        """
        Tests update_engine can deal with invalid data in the omaha response.

        @param image_url: The payload url.
        @param image_size: The payload size.
        @param sha256: The payloads SHA256 value.
        @param metadata_size: The payloads metadata_size.

        """
        self._omaha = nano_omaha_devserver.NanoOmahaDevserver()

        # Setup an omaha response with a bad metadata size.
        if metadata_size is not None:
            self._setup_bad_metadata_response(image_url, image_size, sha256,
                                              metadata_size)
            self._test_update_fails_as_expected(self._METADATA_SIZE_ERROR)
        # Setup an omaha response with a bad SHA256 value.
        else:
            self._setup_bad_sha256_response(image_url, image_size, sha256)
            self._test_update_fails_as_expected(self._SHA256_ERROR)
Exemple #7
0
    def run_once(self,
                 image_url,
                 image_size,
                 image_sha256,
                 allow_failure=False,
                 metadata_size=None,
                 metadata_signature=None,
                 public_key=None,
                 use_cellular=False,
                 is_delta=False):

        self._omaha = nano_omaha_devserver.NanoOmahaDevserver()
        self._omaha.set_image_params(image_url, image_size, image_sha256,
                                     metadata_size, metadata_signature,
                                     public_key, is_delta)

        if use_cellular:
            # Setup DUT so that we have ssh over ethernet but DUT uses
            # cellular as main connection.
            try:
                test_env = test_environment.CellularOTATestEnvironment()
                CONNECT_TIMEOUT = 120
                with test_env:
                    service = test_env.shill.wait_for_cellular_service_object()
                    if not service:
                        raise error.TestError('No cellular service found.')
                    test_env.shill.connect_service_synchronous(
                        service, CONNECT_TIMEOUT)
                    self.run_canned_update(allow_failure)
            except error.TestError as e:
                # Raise as test failure so it is propagated to server test
                # failure message.
                logging.error('Failed setting up cellular connection.')
                raise error.TestFail(e)
        else:
            self.run_canned_update(allow_failure)
    def run_once(self,
                 image_url,
                 cellular=False,
                 payload_info=None,
                 full_payload=True,
                 critical_update=True):
        """
        Test that will start a forced update at OOBE.

        @param image_url: The omaha URL to call. It contains the payload url
                          for cellular tests.
        @param cellular: True if we should run this test using a sim card.
        @payload_payload_info: For cellular tests we need to have our own
                               omaha instance and this is a dictionary of
                               payload information to be used in the omaha
                               response.
        @full_payload: True for full payloads, False for delta.

        """
        utils.run('restart update-engine')
        self._critical_update = critical_update

        if cellular:
            try:
                test_env = test_environment.CellularOTATestEnvironment()
                CONNECT_TIMEOUT = 120
                with test_env:
                    service = test_env.shill.wait_for_cellular_service_object()
                    if not service:
                        raise error.TestError('No cellular service found.')
                    test_env.shill.connect_service_synchronous(
                        service, CONNECT_TIMEOUT)

                    # Setup an omaha instance on the DUT because we cant reach
                    # devservers over cellular.
                    self._omaha = nano_omaha_devserver.NanoOmahaDevserver()
                    self._omaha.set_image_params(image_url,
                                                 payload_info['size'],
                                                 payload_info['sha256'],
                                                 is_delta=not full_payload,
                                                 critical=True)
                    self._omaha.start()

                    # We will tell OOBE to call localhost for update requests.
                    url = 'http://127.0.0.1:%d/update' % self._omaha.get_port()
                    self._start_oobe_update(url)

                    # Remove the custom omaha server from lsb release because
                    # after we reboot it will no longer be running.
                    utils.run('rm %s' % self._CUSTOM_LSB_RELEASE,
                              ignore_status=True)

                    # We need to return from the client test before OOBE
                    # reboots or the server side test will hang. But we cannot
                    # return right away when the OOBE update starts because
                    # all of the code from using a cellular connection is in
                    # client side and we will switch back to ethernet. So we
                    # need to wait for the update to get as close to the end as
                    # possible so that we are done downloading the payload
                    # via cellular and don't  need to ping omaha again. When
                    # the DUT reboots it will send a final update ping to
                    # production omaha and then move to the sign in screen.
                    self._wait_for_update_to_complete()
            except error.TestError as e:
                logging.error('Failure setting up sim card.')
                raise error.TestFail(e)

        else:
            self._start_oobe_update(image_url)