xref: /aosp_15_r20/external/autotest/server/site_tests/autoupdate_Basic/autoupdate_Basic.py (revision 9c5db1993ded3edbeafc8092d69fe5de2ee02df7)
1# Lint as: python2, python3
2# Copyright 2020 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 import error
9from autotest_lib.client.common_lib.cros import dev_server
10from autotest_lib.client.common_lib.cros import kernel_utils
11from autotest_lib.client.cros import cryptohome
12from autotest_lib.server.cros import provisioner
13from autotest_lib.server.cros.update_engine import update_engine_test
14
15class autoupdate_Basic(update_engine_test.UpdateEngineTest):
16    """Performs a simple AU using Nebraska."""
17    version = 1
18
19    def cleanup(self):
20        super(autoupdate_Basic, self).cleanup()
21
22
23    def run_once(self,
24                 full_payload,
25                 job_repo_url=None,
26                 build=None,
27                 m2n=False,
28                 running_at_desk=False,
29                 pin_login=False):
30        """
31        Performs a N-to-N autoupdate with Nebraska.
32
33        @param full_payload: True for full payload, False for delta
34        @param job_repo_url: A url pointing to the devserver where the autotest
35            package for this build should be staged.
36        @param build: An optional parameter to specify the target build for the
37                      update when running locally. job_repo_url will override
38                      this value.
39        @m2n: M -> N update. This means we install the current stable version
40              of this board before updating to ToT.
41        @param running_at_desk: Indicates test is run locally from workstation.
42                                Flag does not work with M2N tests.
43        @param pin_login: True to use login via PIN.
44
45        """
46        if pin_login:
47            if not cryptohome.is_low_entropy_credentials_supported(self._host):
48                raise error.TestNAError(
49                        'Skip test: No hardware support for PIN login')
50
51        # Get a payload to use for the test.
52        payload_url = self.get_payload_for_nebraska(
53                job_repo_url=job_repo_url,
54                build=build,
55                full_payload=full_payload,
56                public_bucket=running_at_desk)
57
58        self._m2n = m2n
59        if self._m2n:
60            if self._host.get_board().endswith("-kernelnext"):
61                raise error.TestNAError("Skipping test on kernelnext board")
62
63            # Provision latest stable build for the current build.
64            build_name = self._get_latest_serving_stable_build()
65            logging.debug('build name is %s', build_name)
66
67            # Install the matching build with quick provision.
68            if running_at_desk:
69                self._copy_quick_provision_to_dut()
70                update_url = self._get_provision_url_on_public_bucket(
71                        build_name)
72            else:
73                autotest_devserver = dev_server.ImageServer.resolve(
74                        build_name, self._host.hostname)
75                update_url = autotest_devserver.get_update_url(build_name)
76
77            logging.info('Installing source image with update url: %s',
78                         update_url)
79            provisioner.ChromiumOSProvisioner(
80                    update_url,
81                    host=self._host,
82                    is_release_bucket=True,
83                    public_bucket=running_at_desk).run_provision()
84
85        # Login to device before update
86        if pin_login:
87            self._run_client_test_and_check_result(self._LOGIN_TEST_PIN,
88                                                   tag='before')
89        else:
90            self._run_client_test_and_check_result(
91                    self._LOGIN_TEST,
92                    username=self._LOGIN_TEST_USERNAME,
93                    password=self._LOGIN_TEST_PASSWORD,
94                    tag='before')
95
96        # Record DUT state before the update.
97        active, inactive = kernel_utils.get_kernel_state(self._host)
98
99        # Perform the update.
100        self._run_client_test_and_check_result('autoupdate_CannedOmahaUpdate',
101                                               payload_url=payload_url)
102
103        # Verify the update completed successfully.
104        self._host.reboot()
105        kernel_utils.verify_boot_expectations(inactive, host=self._host)
106        rootfs_hostlog, _ = self._create_hostlog_files()
107        self.verify_update_events(self._FORCED_UPDATE, rootfs_hostlog)
108
109        if self._m2n:
110            # Bring stateful version to the same version as rootfs.
111            logging.info('Restoring stateful partition to ToT version')
112            self._update_stateful()
113        # Check we can login with the same user after update.
114        if pin_login:
115            self._run_client_test_and_check_result(self._LOGIN_TEST_PIN,
116                                                   tag='after',
117                                                   setup_pin=False)
118        else:
119            self._run_client_test_and_check_result(
120                    self._LOGIN_TEST,
121                    tag='after',
122                    username=self._LOGIN_TEST_USERNAME,
123                    password=self._LOGIN_TEST_PASSWORD,
124                    dont_override_profile=True)
125