• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2020 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5# This test only checks whether the directory of the dependency package exists.
6# It is expected that the necessary path configuration will be done in the test.
7
8# IMPORTANT: This test should be updated whenever the dependencies specified change
9# for any of the environments.
10
11import logging
12import os
13import subprocess
14
15from autotest_lib.client.bin import utils as client_utils
16from autotest_lib.client.common_lib import error
17from autotest_lib.server import test, utils
18
19
20class cheets_LabDependencies(test.test):
21    """Check basic dependency requirements for running CTS tests."""
22    version = 1
23    """
24    Context: xTS P requires JDK 8 or 9, and xTS R requires JDK 9 or above.
25
26    LXC (container for running server-side autotest)
27    Runs xTS P and R. Uses JDK 8 as default, and JDK 9 on xTS R.
28    JDK 9 path is hardcoded in cheets_CTS_R.
29
30    moblab
31    Only runs CTS P. Uses JDK 9 (single JDK) on CTS P.
32    Currently this test does not run on moblab.
33    Because is_moblab does not work, test ignores the moblab component.
34    Need to move JDK's to /java. TODO(haddowk)
35    Will run when new distribution is released.
36
37    chroot (PFQ environment)
38    Runs CTS P and R. Uses JDK 11 as default, and JDK 8 on CTS P.
39    JDK 8 Path is hardcoded in cheets_CTS_P.
40    """
41
42    ENV_EXPECTED = {
43            'LXC': {
44                    'JDK': [
45                            '/usr/lib/jvm/jdk-9.0.4',
46                            '/usr/lib/jvm/java-8-openjdk-amd64',
47                    ],
48                    'DIR': '/usr/lib/jvm'
49            },
50            'moblab': {
51                    'JDK': [
52                            '/java/jdk-9.0.4',
53                    ],
54                    'DIR': '/java'
55            },
56            'chroot': {
57                    'JDK': [
58                            '/opt/icedtea-bin-3.4.0',
59                            '/opt/openjdk-bin-11',
60                    ],
61                    'DIR': '/opt'
62            }
63    }
64
65    def check_JDK(self, env):
66        """Check whether required JDK directories exist for the environment."""
67        for dep_path in self.ENV_EXPECTED[env]['JDK']:
68            """Raise TestFail if specified JDK directories do not exist."""
69            if not os.path.isdir(dep_path):
70                java_path = subprocess.check_output([
71                                'find', self.ENV_EXPECTED[env]['DIR'], '-path',
72                                '*bin/java'], stderr=subprocess.STDOUT)
73                if java_path:
74                    java_path = ', '.join(java_path.split('\n')[:-1])
75                raise error.TestFail(
76                        'Missing required JDK dependency %s for %s. '
77                        'Quick search shows currently installed versions are %s.'
78                        % (dep_path, env, java_path))
79
80    def run_once(self, host=None):
81        """Check the type of environment, and see if all dependencies are satisfied."""
82        if utils.is_in_container():
83            logging.info('[ENV] Running inside the LXC container')
84            env = 'LXC'
85        # is_moblab does not work. Run in moblab when new distribution is released.
86        elif client_utils.is_moblab():
87            logging.info('[ENV] Running inside moblab')
88            env = 'moblab'
89        else:
90            logging.info('[ENV] Running inside chroot environment')
91            env = 'chroot'
92        self.host = host
93        self.check_JDK(env)
94