How to use host_remove_labels method in autotest

Best Python code snippet using autotest_python Github


Full Screen

1# Copyright 2017 The Chromium OS Authors. All rights reserved.2# Use of this source code is governed by a BSD-style license that can be3# found in the LICENSE file.4import logging5import common6from autotest_lib.frontend.afe.json_rpc import proxy as rpc_proxy7from autotest_lib.server.hosts import host_info8from autotest_lib.server.cros.dynamic_suite import frontend_wrappers9class AfeStore(host_info.CachingHostInfoStore):10 """Directly interact with the (given) AFE for host information."""11 _RETRYING_AFE_TIMEOUT_MIN = 512 _RETRYING_AFE_RETRY_DELAY_SEC = 1013 def __init__(self, hostname, afe=None):14 """15 @param hostname: The name of the host for which we want to track host16 information.17 @param afe: A frontend.AFE object to make RPC calls. Will create one18 internally if None.19 """20 super(AfeStore, self).__init__()21 self._hostname = hostname22 self._afe = afe23 if self._afe is None:24 self._afe = frontend_wrappers.RetryingAFE(25 timeout_min=self._RETRYING_AFE_TIMEOUT_MIN,26 delay_sec=self._RETRYING_AFE_RETRY_DELAY_SEC)27 def _refresh_impl(self):28 """Obtains HostInfo directly from the AFE."""29 try:30 hosts = self._afe.get_hosts(hostname=self._hostname)31 except rpc_proxy.JSONRPCException as e:32 raise host_info.StoreError(e)33 if not hosts:34 raise host_info.StoreError('No hosts founds with hostname: %s' %35 self._hostname)36 if len(hosts) > 1:37 logging.warning(38 'Found %d hosts with the name %s. Picking the first one.',39 len(hosts), self._hostname)40 host = hosts[0]41 return host_info.HostInfo(host.labels, host.attributes)42 def _commit_impl(self, new_info):43 """Commits HostInfo back to the AFE.44 @param new_info: The new HostInfo to commit.45 """46 # TODO(pprabhu) # This method has a potentially malignent race condition. We obtain a48 # copy of HostInfo from the AFE and then add/remove labels / attribtes49 # based on that. If another user tries to commit it's changes in50 # parallel, we'll end up with corrupted labels / attributes.51 old_info = self._refresh_impl()52 self._remove_labels_on_afe(set(old_info.labels) - set(new_info.labels))53 self._add_labels_on_afe(set(new_info.labels) - set(old_info.labels))54 # TODO(pprabhu) Also commit attributes when we first replace a direct55 # AFE call for attribute update.56 if old_info.attributes != new_info.attributes:57 logging.warning(58 'Updating attributes is currently not supported. '59 'attributes update skipped. old attributes: %s, committed '60 'attributes: %s',61 old_info.attributes, new_info.attributes)62 def _remove_labels_on_afe(self, labels):63 """Requests the AFE to remove the given labels.64 @param labels: Remove these.65 """66 if not labels:67 return68 logging.debug('removing labels: %s', labels)69 try:70'host_remove_labels', id=self._hostname,71 labels=labels)72 except rpc_proxy.JSONRPCException as e:73 raise host_info.StoreError(e)74 def _add_labels_on_afe(self, labels):75 """Requests the AFE to add the given labels.76 @param labels: Add these.77 """78 if not labels:79 return80'adding labels: %s', labels)81 try:82'host_add_labels', id=self._hostname, labels=labels)83 except rpc_proxy.JSONRPCException as e:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:


You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?