• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Lint as: python2, python3
2# Copyright 2017 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.server import autotest
10from autotest_lib.server import test
11from autotest_lib.server import utils
12
13
14class platform_ImageLoaderServer(test.test):
15    """Does the server side file downloading for the ImageLoader autotest.
16    """
17    version = 1
18
19    def _run_client_test(self, version1, version2, version3):
20        """Runs client test."""
21        try:
22            self.autotest_client.run_test(
23                'platform_ImageLoader',
24                component1=version1,
25                component2=version2,
26                component3=version3,
27                check_client_result=True)
28            logging.info('platform_ImageLoader succeeded')
29        except:
30            raise error.TestFail('Failed: platform_ImageLoader')
31
32    def run_once(self, host):
33        """Runs platform ImageLoader tests."""
34        self.host = host
35        self.autotest_client = autotest.Autotest(self.host)
36        # Download sample production signed components for simulated updates
37        # from Google Storage. This needs to be done by a server test as the
38        # client is unable to access Google Storage.
39        try:
40            version1 = '/tmp/prod_signed_23.0.0.207.tar.gz'
41            utils.run('gsutil',
42                      args=('cp', 'gs://chromeos-localmirror-private/'
43                            'testing/components/prod_signed_23.0.0.207.tar.gz',
44                            version1),
45                      timeout=300,
46                      ignore_status=False,
47                      verbose=True,
48                      stderr_is_expected=False,
49                      ignore_timeout=False)
50
51            version2 = '/tmp/prod_signed_24.0.0.186.tar.gz'
52            utils.run('gsutil',
53                      args=('cp', 'gs://chromeos-localmirror-private/'
54                            'testing/components/prod_signed_24.0.0.186.tar.gz',
55                            version2),
56                      timeout=300,
57                      ignore_status=False,
58                      verbose=True,
59                      stderr_is_expected=False,
60                      ignore_timeout=False)
61
62            version3 = '/tmp/prod_signed_10209.0.0.tar.gz'
63            utils.run('gsutil',
64                      args=('cp', 'gs://chromeos-localmirror-private/'
65                            'testing/components/prod_signed_10209.0.0.tar.gz',
66                            version3),
67                      timeout=300,
68                      ignore_status=False,
69                      verbose=True,
70                      stderr_is_expected=False,
71                      ignore_timeout=False)
72        except error.CmdTimeoutError:
73            raise error.TestError('Slow network')
74        except error.CmdError:
75            raise error.TestError('Lack of Google Storage access permissions.')
76
77        self.host.send_file(version1, version1)
78        self.host.send_file(version2, version2)
79        self.host.send_file(version3, version3)
80
81        self.host.run('tar xvf "%s" -C "%s"' % (version1, '/home/chronos'))
82        self.host.run('tar xvf "%s" -C "%s"' % (version2, '/home/chronos'))
83        self.host.run('tar xvf "%s" -C "%s"' % (version3, '/home/chronos'))
84        version1_unpack = '/home/chronos/prod_signed_23.0.0.207'
85        version2_unpack = '/home/chronos/prod_signed_24.0.0.186'
86        version3_unpack = '/home/chronos/prod_signed_10209.0.0'
87        self.host.run('chmod -R 0755 "%s"' % (version1_unpack))
88        self.host.run('chmod -R 0755 "%s"' % (version2_unpack))
89        self.host.run('chmod -R 0755 "%s"' % (version3_unpack))
90        # Run the actual test (installing and verifying component updates on
91        # the client.
92        self._run_client_test(version1_unpack, version2_unpack, version3_unpack)
93
94        self.host.run('rm -rf "%s" "%s" "%s" "%s" "%s" "%s"'
95                      % (version1,
96                         version2,
97                         version3,
98                         version1_unpack,
99                         version2_unpack,
100                         version3_unpack))
101