How to use host_remove_labels method in autotest

Best Python code snippet using autotest_python

afe_store.py

Source: afe_store.py Github

copy

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) crbug.com/​68032247 # 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 self._afe.run('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 logging.info('adding labels: %s', labels)81 try:82 self._afe.run('host_add_labels', id=self._hostname, labels=labels)83 except rpc_proxy.JSONRPCException as e:...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Scala Testing: A Comprehensive Guide

Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.

What Agile Testing (Actually) Is

So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.

How To Choose The Right Mobile App Testing Tools

Did you know that according to Statista, the number of smartphone users will reach 18.22 billion by 2025? Let’s face it, digital transformation is skyrocketing and will continue to do so. This swamps the mobile app development market with various options and gives rise to the need for the best mobile app testing tools

A Complete Guide To CSS Houdini

As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????

Appium Testing Tutorial For Mobile Applications

The count of mobile users is on a steep rise. According to the research, by 2025, it is expected to reach 7.49 billion users worldwide. 70% of all US digital media time comes from mobile apps, and to your surprise, the average smartphone owner uses ten apps per day and 30 apps each month.

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:

YouTube

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?

Helpful

NotHelpful