# Copyright 2017 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.


AUTHOR = "chromeos-lab-infrastructure"
NAME = "provision_Cr50Update"
PURPOSE = "Provision a system to the correct firmware version."
TIME = "MEDIUM"
TEST_CATEGORY = "System"
TEST_CLASS = "provision"
TEST_TYPE = "Server"
DEPENDENCIES = "servo"

DOC = """
This is a test used by the provision control segment in autoserv to set the
cr50-version label of a host to the desired setting. This test attempts to
reprogram the cr50 firmware and set the cr50 chip board id using the given
params in value. value should a string with the
'prodsigned-rw_ver/image_bid/chip_bid' or 'selfsigned-build_info/chip_bid'.
build_info is something like 'reef-release/R61-9704.0.0'. For a prodsigned image
only the rw_ver is manditory. On selfsigned images only the build_info is
necessary. value is completely ignored if a valid release_path is given.

@param value: the release image information. Ignored if release_path is given
@param release_path: local path to release image
@param dev_path: local path to dev image
@param chip_bid: the desired cr50 chip board id string
"""

from autotest_lib.client.common_lib import error, utils


args_dict = utils.args_to_dict(args)
servo_args = hosts.CrosHost.get_servo_arguments(args_dict)


release_path = ''
chip_bid = ''
if not locals().get('value'):
    value = args_dict.get('value', '')
    release_path = args_dict.get('release_path', '')
    dev_path = args_dict.get('dev_path', '')
    chip_bid_str = args_dict.get('chip_bid', '')


def run(machine):
    host = hosts.create_host(machine, servo_args=servo_args)
    job.run_test('provision_Cr50Update', host=host, cmdline_args=args,
                 value=value, release_path=release_path,
                 chip_bid_str=chip_bid_str)


job.parallel_simple(run, machines)