Home | History | Annotate | Download | only in ssp_PackageInstall
      1 # Copyright 2015 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 import logging
      6 
      7 from autotest_lib.client.bin import utils
      8 from autotest_lib.client.common_lib import error
      9 from autotest_lib.server import test
     10 from autotest_lib.site_utils import lxc
     11 
     12 
     13 class ssp_PackageInstall(test.test):
     14     """Tests that server tests can install packages inside containers."""
     15     version = 1
     16 
     17     def install_os_packages(self, packages):
     18         """Install OS package in the test container.
     19 
     20         @param packages: OS packages to be installed.
     21         """
     22         for package in packages:
     23             logging.debug('Installing package %s...', package)
     24             lxc.install_package(package)
     25 
     26 
     27     def install_python_packages(self, packages):
     28         """Install python package in the test container.
     29 
     30         @param packages: Python packages to be installed.
     31         """
     32         for package in packages:
     33             logging.debug('Installing package %s...', package)
     34             lxc.install_python_package(package)
     35 
     36 
     37     def initialize(self):
     38         """Initialize test.
     39         """
     40         self.install_os_packages(['sox'])
     41         self.install_python_packages(['selenium'])
     42 
     43 
     44     def run_once(self):
     45         """There is no body for this test.
     46 
     47         @raise: error.TestError if the test is not running inside container or
     48                 any of the given packages failed to be installed.
     49 
     50         """
     51         if not utils.is_in_container():
     52             raise error.TestError('Install OS package is only supported in '
     53                                   'server-side packaging.')
     54         # Test OS package can be used.
     55         utils.run('sox --help')
     56         logging.info('Found sox executable.')
     57 
     58         # Test python module can be used.
     59         from selenium import webdriver
     60         logging.info('Found webdriver at %s', webdriver.__file__)
     61 
     62         return