How to use generate_control_file method in autotest

Best Python code snippet using autotest_python

trigger_unittest.py

Source:trigger_unittest.py Github

copy

Full Screen

1#!/usr/bin/python2# Copyright 2009 Google Inc. Released under the GPL v23import unittest4try:5 import autotest.common as common6except ImportError:7 import common8from autotest.mirror import trigger9from autotest.client.shared.test_utils import mock10class map_action_unittest(unittest.TestCase):11 def setUp(self):12 self.god = mock.mock_god()13 def tearDown(self):14 pass15 def test_machine_info_api(self):16 tests = object()17 configs = object()18 info = trigger.map_action.machine_info(tests, configs)19 self.assertEquals(tests, info.tests)20 self.assertEquals(configs, info.kernel_configs)21 @staticmethod22 def _make_control_dict(contents, is_server=False, synch_count=1,23 dependencies=()):24 class ControlFile(object):25 def __init__(self, contents, is_server, synch_count, dependencies):26 self.control_file = contents27 self.is_server = is_server28 self.synch_count = synch_count29 self.dependencies = dependencies30 return ControlFile(contents, is_server, synch_count, dependencies)31 def test_job_grouping(self):32 tests_map = {33 'mach1': trigger.map_action.machine_info(34 ('test1', 'test2'), {'2.6.20': 'config1'}),35 'mach2': trigger.map_action.machine_info(36 ('test3',), {'2.6.10': 'config2', '2.6.20': 'config1'}),37 'mach3': trigger.map_action.machine_info(38 ('test2', 'test3'), {'2.6.20': 'config1'}),39 }40 action = trigger.map_action(tests_map, 'jobname %s')41 self.assertTrue(isinstance(action._afe, trigger.frontend.AFE))42 action._afe = self.god.create_mock_class(trigger.frontend.AFE, 'AFE')43 control2 = self._make_control_dict('control contents2')44 (action._afe.generate_control_file.expect_call(45 tests=['test2'],46 kernel=[dict(version='2.6.21', config_file='config1')],47 upload_kernel_config=False)48 .and_return(control2))49 action._afe.create_job.expect_call(50 control2.control_file, 'jobname 2.6.21',51 control_type='Client', hosts=['mach1', 'mach3'])52 control3 = self._make_control_dict('control contents3', is_server=True)53 (action._afe.generate_control_file.expect_call(54 tests=['test3'],55 kernel=[dict(version='2.6.21', config_file='config1')],56 upload_kernel_config=False)57 .and_return(control3))58 action._afe.create_job.expect_call(59 control3.control_file, 'jobname 2.6.21',60 control_type='Server', hosts=['mach2', 'mach3'])61 control1 = self._make_control_dict('control contents1')62 (action._afe.generate_control_file.expect_call(63 tests=['test1'],64 kernel=[dict(version='2.6.21', config_file='config1')],65 upload_kernel_config=False)66 .and_return(control1))67 action._afe.create_job.expect_call(68 control1.control_file, 'jobname 2.6.21',69 control_type='Client', hosts=['mach1'])70 action(['2.6.21'])71 self.god.check_playback()72 def test_kver_cmp(self):73 def check_cmp(ver1, ver2):74 # function to make sure "cmp" invariants are followed75 cmp_func = trigger.map_action._kver_cmp76 if ver1 != ver2:77 self.assertEquals(cmp_func(ver1, ver2), -1)78 self.assertEquals(cmp_func(ver2, ver1), 1)79 else:80 self.assertEquals(cmp_func(ver1, ver2), 0)81 self.assertEquals(cmp_func(ver2, ver1), 0)82 check_cmp('2.6.20', '2.6.20')83 check_cmp('2.6.20', '2.6.21')84 check_cmp('2.6.20', '2.6.21-rc2')85 check_cmp('2.6.20-rc2-git2', '2.6.20-rc2')86 def test_upload_kernel_config(self):87 tests_map = {88 'mach1': trigger.map_action.machine_info(89 ('test1',), {'2.6.20': 'config1'}),90 'mach3': trigger.map_action.machine_info(91 ('test1',), {'2.6.20': 'config1'})92 }93 action = trigger.map_action(tests_map, 'jobname %s',94 upload_kernel_config=True)95 self.assertTrue(isinstance(action._afe, trigger.frontend.AFE))96 action._afe = self.god.create_mock_class(trigger.frontend.AFE, 'AFE')97 control = self._make_control_dict('control contents', is_server=True)98 (action._afe.generate_control_file.expect_call(99 tests=['test1'],100 kernel=[dict(version='2.6.21', config_file='config1')],101 upload_kernel_config=True)102 .and_return(control))103 action._afe.create_job.expect_call(104 control.control_file, 'jobname 2.6.21',105 control_type='Server', hosts=['mach1', 'mach3'])106 action(['2.6.21'])107 self.god.check_playback()108if __name__ == "__main__":...

Full Screen

Full Screen

autotest_distro_detect.py

Source:autotest_distro_detect.py Github

copy

Full Screen

1import os2import tempfile3import string4from virttest import utils_test5def generate_control_file(params):6 control_template = '''AUTHOR = "Cleber Rosa <crosa@redhat.com>"7NAME = "Distro Detect"8TIME = "SHORT"9TEST_CATEGORY = "Functional"10TEST_CLASS = "General"11TEST_TYPE = "client"12DOC = """13This test checks for the accuracy of the distro detection code of autotest14"""15import logging16from autotest.client.shared import distro17def step_init():18 job.next_step(step_test)19def step_test():20 expected_name = '$distro_name'21 expected_version = '$distro_version'22 expected_release = '$distro_release'23 expected_arch = '$distro_arch'24 detected = distro.detect()25 failures = []26 logging.debug("Expected distro name = %s", expected_name)27 logging.debug("Detected distro name = %s", detected.name)28 if expected_name != detected.name:29 failures.append("name")30 logging.debug("Expected distro version = %s", expected_version)31 logging.debug("Detected distro version = %s", detected.version)32 if expected_version != str(detected.version):33 failures.append("version")34 logging.debug("Expected distro release = %s", expected_release)35 logging.debug("Detected distro release = %s", detected.release)36 if expected_release != str(detected.release):37 failures.append("release")38 logging.debug("Expected distro arch = %s", expected_arch)39 logging.debug("Detected distro arch = %s", detected.arch)40 if expected_arch != detected.arch:41 failures.append("arch")42 if failures:43 msg = "Detection failed for distro: %s" % ", ".join(failures)44 raise error.TestFail(msg)45'''46 temp_fd, temp_path = tempfile.mkstemp()47 template = string.Template(control_template)48 control = template.substitute(params)49 os.write(temp_fd, control)50 os.close(temp_fd)51 return temp_path52def run(test, params, env):53 """54 Run an distro detection check on guest55 :param test: kvm test object.56 :param params: Dictionary with test parameters.57 :param env: Dictionary with the test environment.58 """59 vm = env.get_vm(params["main_vm"])60 vm.verify_alive()61 timeout = int(params.get("login_timeout", 360))62 session = vm.wait_for_login(timeout=timeout)63 # Collect test parameters64 timeout = int(params.get("test_timeout", 90))65 control_path = generate_control_file(params)66 outputdir = test.outputdir67 utils_test.run_autotest(vm, session, control_path, timeout, outputdir,...

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