blob: 7a83fdf9baa14a309d53c2f56b6dfa4f49444309 [file] [log] [blame]
# Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import logging
import os
import re
from autotest_lib.client.common_lib import error, global_config
from autotest_lib.server import test
from autotest_lib.server.hosts import moblab_host
DEFAULT_IMAGE_STORAGE_SERVER = global_config.global_config.get_config_value(
'CROS', 'image_storage_server')
class MoblabTest(test.test):
"""Base class for Moblab tests.
def initialize(self, host, boto_path='',
"""Initialize the Moblab Host.
* Installs a boto file.
* Sets up the image storage server for this test.
* Finds and adds DUTs on the testing subnet.
@param boto_path: Path to the boto file we want to install.
@param image_storage_server: image storage server to use for grabbing
images from Google Storage.
super(MoblabTest, self).initialize()
self._host = host
def install_boto_file(self, boto_path=''):
"""Install a boto file on the Moblab device.
@param boto_path: Path to the boto file to install. If None, sends the
boto file in the current HOME directory.
@raises error.TestError if the boto file does not exist.
if not boto_path:
boto_path = os.path.join(os.getenv('HOME'), '.boto')
if not os.path.exists(boto_path):
raise error.TestError('Boto File:%s does not exist.' % boto_path)
self._host.send_file(boto_path, moblab_host.MOBLAB_BOTO_LOCATION)'chown moblab:moblab %s' %
def set_image_storage_server(self, image_storage_server):
"""Set the image storage server.
@param image_storage_server: Name of image storage server to use. Must
follow format or gs://bucket-name/
(Note trailing slash is required).
@raises error.TestError if the image_storage_server is incorrectly
if not re.match(STORAGE_SERVER_REGEX, image_storage_server):
raise error.TestError(
'Image Storage Server supplied is not in the correct '
'format. Must start with gs:// and end with a trailing '
'slash: %s' % image_storage_server)
logging.debug('Setting image_storage_server to %s',
# If the image_storage_server is already set, delete it.'sed -i /image_storage_server/d %s' %
moblab_host.SHADOW_CONFIG_PATH, ignore_status=True)"sed -i '/\[CROS\]/ a\image_storage_server: "
"%s' %s" %(image_storage_server,