1# Lint as: python2, python3
2# Copyright 2018 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6import logging
7
8from autotest_lib.client.common_lib.cros import dev_server
9from autotest_lib.server.cros import provisioner
10from autotest_lib.server.cros.update_engine import update_engine_test
11
12
13class autoupdate_DataPreserved(update_engine_test.UpdateEngineTest):
14    """Ensure user data and preferences are preserved during an update."""
15
16    version = 1
17    _USER_DATA_TEST = 'autoupdate_UserData'
18
19
20    def cleanup(self):
21        self._save_extra_update_engine_logs(number_of_logs=2)
22        super(autoupdate_DataPreserved, self).cleanup()
23        self._restore_stateful()
24
25
26    def run_once(self, full_payload=True, job_repo_url=None):
27        """
28        Tests that users timezone, input methods, and downloads are preserved
29        during an update.
30
31        @param full_payload: True for a full payload. False for delta.
32        @param job_repo_url: Used for debugging locally. This is used to figure
33                             out the current build and the devserver to use.
34                             The test will read this from a host argument
35                             when run in the lab.
36
37        """
38        # Provision latest stable build for the current board.
39        build_name = self._get_latest_serving_stable_build()
40
41        # Install the matching build with quick provision.
42        autotest_devserver = dev_server.ImageServer.resolve(
43                build_name, self._host.hostname)
44        update_url = autotest_devserver.get_update_url(build_name)
45        logging.info('Installing source image with update url: %s', update_url)
46        provisioner.ChromiumOSProvisioner(
47                update_url, host=self._host,
48                is_release_bucket=True).run_provision()
49
50        # Get payload for the update to ToT.
51        payload_url = self.get_payload_for_nebraska(job_repo_url,
52                                                    full_payload=full_payload)
53
54        # Change input method and timezone, create a file, then start update.
55        self._run_client_test_and_check_result(self._USER_DATA_TEST,
56                                               payload_url=payload_url,
57                                               tag='before_update')
58        self._host.reboot()
59
60        # Ensure preferences and downloads are the same as before the update.
61        self._run_client_test_and_check_result(self._USER_DATA_TEST,
62                                               tag='after_update')
63