Added a upload_kernel_config (default False) keyword parameter to
generate_control_file RPC that produces server side code to download and
transfer on the client the kernel config (if it's an URL) and point the
client to the new location. This allows to have kernel config URLs point
to servers that are reachable on the server side but not on the client
side.
Signed-off-by: Mihai Rusu <dizzy@google.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@3920 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/frontend/afe/control_file.py b/frontend/afe/control_file.py
index ae3d425..2a23850 100644
--- a/frontend/afe/control_file.py
+++ b/frontend/afe/control_file.py
@@ -56,9 +56,12 @@
from autotest_lib.client.common_lib import error
at = autotest.Autotest()
+
+%%(upload_config_func)s
def install_kernel(machine, kernel_info):
host = hosts.create_host(machine)
at.install(host=host)
+ %%(call_upload_config)s
at.run(kernel_install_control %%%%
{'client_kernel_list': repr([kernel_info])}, host=host)
@@ -105,6 +108,40 @@
CLIENT_STEP_TEMPLATE = " job.next_step('step%d')\n"
SERVER_STEP_TEMPLATE = ' step%d()\n'
+UPLOAD_CONFIG_FUNC = """
+def upload_kernel_config(host, kernel_info):
+ \"""
+ If the kernel_info['config_file'] is a URL it will be downloaded
+ locally and then uploaded to the client and a copy of the original
+ dictionary with the new path to the config file will be returned.
+ If the config file is not a URL the function returns the original
+ dictionary.
+ \"""
+ import os
+ from autotest_lib.client.common_lib import autotemp, utils
+
+ config_orig = kernel_info.get('config_file')
+
+ # if the file is not an URL then we assume it's a local client path
+ if not config_orig or not utils.is_url(config_orig):
+ return kernel_info
+
+ # download it locally (on the server) and send it to the client
+ config_tmp = autotemp.tempfile('kernel_config_upload', dir=job.tmpdir)
+ try:
+ utils.urlretrieve(config_orig, config_tmp.name)
+ config_new = os.path.join(host.get_autodir(), 'tmp',
+ os.path.basename(config_orig))
+ host.send_file(config_tmp.name, config_new)
+ finally:
+ config_tmp.clean()
+
+ return dict(kernel_info, config_file=config_new)
+
+"""
+
+CALL_UPLOAD_CONFIG = 'kernel_info = upload_kernel_config(host, kernel_info)'
+
def kernel_config_file(kernel, platform):
if (not kernel.endswith('.rpm') and platform and
@@ -121,7 +158,7 @@
def get_kernel_stanza(kernel_list, platform=None, kernel_args='',
- is_server=False):
+ is_server=False, upload_kernel_config=False):
template_args = {'kernel_args' : kernel_args}
@@ -142,6 +179,13 @@
# leave client_kernel_list as a placeholder
template_args['client_kernel_list'] = '%(client_kernel_list)s'
template_args['server_kernel_list'] = repr(new_kernel_list)
+
+ if upload_kernel_config:
+ template_args['call_upload_config'] = CALL_UPLOAD_CONFIG
+ template_args['upload_config_func'] = UPLOAD_CONFIG_FUNC
+ else:
+ template_args['call_upload_config'] = ''
+ template_args['upload_config_func'] = ''
else:
template = CLIENT_KERNEL_TEMPLATE
template_args['client_kernel_list'] = repr(new_kernel_list)
@@ -269,7 +313,8 @@
return prepend, append
-def _sanity_check_generate_control(is_server, client_control_file, kernels):
+def _sanity_check_generate_control(is_server, client_control_file, kernels,
+ upload_kernel_config):
"""
Sanity check some of the parameters to generate_control().
@@ -299,9 +344,15 @@
'version' not in kernel_info):
raise kernel_error
+ if upload_kernel_config and not is_server:
+ raise model_logic.ValidationError(
+ {'upload_kernel_config': 'Cannot use upload_kernel_config '
+ 'with client side tests'})
+
def generate_control(tests, kernels=None, platform=None, is_server=False,
- profilers=(), client_control_file='', profile_only=None):
+ profilers=(), client_control_file='', profile_only=None,
+ upload_kernel_config=False):
"""
Generate a control file for a sequence of tests.
@@ -315,16 +366,22 @@
last test after everything in tests. Requires is_server=False.
@param profile_only bool, should this control file run all tests in
profile_only mode by default
+ @param upload_kernel_config: if enabled it will generate server control
+ file code that uploads the kernel config file to the client and
+ tells the client of the new (local) path when compiling the kernel;
+ the tests must be server side tests
@returns The control file text as a string.
"""
_sanity_check_generate_control(is_server=is_server, kernels=kernels,
- client_control_file=client_control_file)
+ client_control_file=client_control_file,
+ upload_kernel_config=upload_kernel_config)
control_file_text = ''
if kernels:
- control_file_text = get_kernel_stanza(kernels, platform,
- is_server=is_server)
+ control_file_text = get_kernel_stanza(
+ kernels, platform, is_server=is_server,
+ upload_kernel_config=upload_kernel_config)
else:
control_file_text = EMPTY_TEMPLATE