How to use label_add_hosts method in autotest

Best Python code snippet using autotest_python

label_unittest.py

Source:label_unittest.py Github

copy

Full Screen

1#!/usr/bin/python2#3# Copyright 2008 Google Inc. All Rights Reserved.4"""Tests for label."""5import unittest6import sys7import os8try:9 import autotest.common as common10except ImportError:11 import common12from autotest.cli import cli_mock, topic_common13class label_list_unittest(cli_mock.cli_unittest):14 values = [{u'id': 180, # Valid label15 u'platform': False,16 u'name': u'label0',17 u'invalid': False,18 u'kernel_config': u'',19 u'only_if_needed': False},20 {u'id': 338, # Valid label21 u'platform': False,22 u'name': u'label1',23 u'invalid': False,24 u'kernel_config': u'',25 u'only_if_needed': False},26 {u'id': 340, # Invalid label27 u'platform': False,28 u'name': u'label2',29 u'invalid': True,30 u'kernel_config': u'',31 u'only_if_needed': False},32 {u'id': 350, # Valid platform33 u'platform': True,34 u'name': u'plat0',35 u'invalid': False,36 u'kernel_config': u'',37 u'only_if_needed': False},38 {u'id': 420, # Invalid platform39 u'platform': True,40 u'name': u'plat1',41 u'invalid': True,42 u'kernel_config': u'',43 u'only_if_needed': False}]44 def test_label_list_labels_only(self):45 self.run_cmd(argv=['atest', 'label', 'list', '--ignore_site_file'],46 rpcs=[('get_labels', {}, True, self.values)],47 out_words_ok=['label0', 'label1', 'label2'],48 out_words_no=['plat0', 'plat1'])49 def test_label_list_labels_only_valid(self):50 self.run_cmd(argv=['atest', 'label', 'list', '-d',51 '--ignore_site_file'],52 rpcs=[('get_labels', {}, True, self.values)],53 out_words_ok=['label0', 'label1'],54 out_words_no=['label2', 'plat0', 'plat1'])55 def test_label_list_labels_and_platforms(self):56 self.run_cmd(argv=['atest', 'label', 'list', '--all',57 '--ignore_site_file'],58 rpcs=[('get_labels', {}, True, self.values)],59 out_words_ok=['label0', 'label1', 'label2',60 'plat0', 'plat1'])61 def test_label_list_platforms_only(self):62 self.run_cmd(argv=['atest', 'label', 'list', '-t',63 '--ignore_site_file'],64 rpcs=[('get_labels', {}, True, self.values)],65 out_words_ok=['plat0', 'plat1'],66 out_words_no=['label0', 'label1', 'label2'])67 def test_label_list_platforms_only_valid(self):68 self.run_cmd(argv=['atest', 'label', 'list',69 '-t', '--valid-only', '--ignore_site_file'],70 rpcs=[('get_labels', {}, True, self.values)],71 out_words_ok=['plat0'],72 out_words_no=['label0', 'label1', 'label2',73 'plat1'])74class label_create_unittest(cli_mock.cli_unittest):75 def test_execute_create_two_labels(self):76 self.run_cmd(argv=['atest', 'label', 'create', 'label0', 'label1',77 '--ignore_site_file'],78 rpcs=[('add_label',79 {'name': 'label0', 'platform': False,80 'only_if_needed': False},81 True, 42),82 ('add_label',83 {'name': 'label1', 'platform': False,84 'only_if_needed': False},85 True, 43)],86 out_words_ok=['Created', 'label0', 'label1'])87 def test_execute_create_two_labels_bad(self):88 self.run_cmd(argv=['atest', 'label', 'create', 'label0', 'label1',89 '--ignore_site_file'],90 rpcs=[('add_label',91 {'name': 'label0', 'platform': False,92 'only_if_needed': False},93 True, 3),94 ('add_label',95 {'name': 'label1', 'platform': False,96 'only_if_needed': False},97 False,98 '''ValidationError: {'name':99 'This value must be unique (label0)'}''')],100 out_words_ok=['Created', 'label0'],101 out_words_no=['label1'],102 err_words_ok=['label1', 'ValidationError'])103class label_delete_unittest(cli_mock.cli_unittest):104 def test_execute_delete_labels(self):105 self.run_cmd(argv=['atest', 'label', 'delete', 'label0', 'label1',106 '--ignore_site_file'],107 rpcs=[('delete_label', {'id': 'label0'}, True, None),108 ('delete_label', {'id': 'label1'}, True, None)],109 out_words_ok=['Deleted', 'label0', 'label1'])110class label_add_unittest(cli_mock.cli_unittest):111 def test_execute_add_labels_to_hosts(self):112 self.run_cmd(argv=['atest', 'label', 'add', 'label0',113 '--machine', 'host0,host1', '--ignore_site_file'],114 rpcs=[('label_add_hosts', {'id': 'label0',115 'hosts': ['host1', 'host0']},116 True, None)],117 out_words_ok=['Added', 'label0', 'host0', 'host1'])118class label_remove_unittest(cli_mock.cli_unittest):119 def test_execute_remove_labels_from_hosts(self):120 self.run_cmd(argv=['atest', 'label', 'remove', 'label0',121 '--machine', 'host0,host1', '--ignore_site_file'],122 rpcs=[('label_remove_hosts', {'id': 'label0',123 'hosts': ['host1', 'host0']},124 True, None)],125 out_words_ok=['Removed', 'label0', 'host0', 'host1'])126if __name__ == '__main__':...

Full Screen

Full Screen

afe_utils.py

Source:afe_utils.py Github

copy

Full Screen

1# Copyright 2016 The Chromium 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.4"""Utility functions for AFE-based interactions.5NOTE: This module should only be used in the context of a running test. Any6 utilities that require accessing the AFE, should do so by creating7 their own instance of the AFE client and interact with it directly.8"""9import common10from autotest_lib.server import utils11from autotest_lib.server.cros.dynamic_suite import frontend_wrappers12AFE = frontend_wrappers.RetryingAFE(timeout_min=5, delay_sec=10)13def host_in_lab(host):14 """Check if the host is in the lab and an object the AFE knows.15 This check ensures that autoserv and the host's current job is running16 inside a fully Autotest instance, aka a lab environment. If this is the17 case it then verifies the host is registed with the configured AFE18 instance.19 @param host: Host object to verify.20 @returns The host model object.21 """22 if not host.job or not host.job.in_lab:23 return False24 return AFE.get_hosts(hostname=host.hostname)25def get_build(host):26 """Retrieve the current build for a given host from the AFE.27 Looks through a host's labels in the AFE to determine its build.28 @param host: Host object to get build.29 @returns The current build or None if it could not find it or if there30 were multiple build labels assigned to the host.31 """32 if not host_in_lab(host):33 return None34 return utils.get_build_from_afe(host.hostname, AFE)35def get_board(host):36 """Retrieve the board for a given host from the AFE.37 Contacts the AFE to retrieve the board for a given host.38 @param host: Host object to get board.39 @returns The current board or None if it could not find it.40 """41 if not host_in_lab(host):42 return None43 return utils.get_board_from_afe(host.hostname, AFE)44def clear_version_labels(host):45 """Clear version labels for a given host.46 @param host: Host whose version labels to clear.47 """48 if not host_in_lab(host):49 return50 host_list = [host.hostname]51 labels = AFE.get_labels(52 name__startswith=host.VERSION_PREFIX,53 host__hostname=host.hostname)54 for label in labels:55 label.remove_hosts(hosts=host_list)56def add_version_label(host, image_name):57 """Add version labels to a host.58 @param host: Host to add the version label for.59 @param image_name: Name of the build version to add to the host.60 """61 if not host_in_lab(host):62 return63 label = '%s:%s' % (host.VERSION_PREFIX, image_name)64 AFE.run('label_add_hosts', id=label, hosts=[host.hostname])65def machine_install_and_update_labels(host, *args, **dargs):66 """Calls machine_install and updates the version labels on a host.67 @param host: Host object to run machine_install on.68 @param *args: Args list to pass to machine_install.69 @param **dargs: dargs dict to pass to machine_install.70 """71 clear_version_labels(host)72 image_name = host.machine_install(*args, **dargs)73 add_version_label(host, image_name)74def get_stable_version(board, android=False):75 """Retrieves a board's stable version from the AFE.76 @param board: Board to lookup.77 @param android: If True, indicates we are looking up a Android/Brillo-based78 board. There is no default version that works for all79 Android/Brillo boards. If False, we are looking up a Chrome80 OS based board.81 @returns Stable version of the given board.82 """...

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:

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