How to use get_autodir method in autotest

Best Python code snippet using autotest_python

autotest_unittest.py

Source:autotest_unittest.py Github

copy

Full Screen

1#!/usr/bin/python2#pylint: disable-msg=C01113__author__ = "raphtee@google.com (Travis Miller)"4import unittest, os, tempfile, logging5import common6from autotest_lib.server import autotest, utils, hosts, server_job, profilers7from autotest_lib.client.bin import sysinfo8from autotest_lib.client.common_lib import packages9from autotest_lib.client.common_lib import error10from autotest_lib.client.common_lib.test_utils import mock11class TestAutotest(unittest.TestCase):12 def setUp(self):13 # create god14 self.god = mock.mock_god()15 # create mock host object16 self.host = self.god.create_mock_class(hosts.RemoteHost, "host")17 self.host.hostname = "hostname"18 self.host.job = self.god.create_mock_class(server_job.server_job,19 "job")20 self.host.job.run_test_cleanup = True21 self.host.job.sysinfo = self.god.create_mock_class(22 sysinfo.sysinfo, "sysinfo")23 self.host.job.profilers = self.god.create_mock_class(24 profilers.profilers, "profilers")25 self.host.job.profilers.add_log = {}26 self.host.job.tmpdir = "/job/tmp"27 self.host.job.default_profile_only = False28 self.host.job.args = []29 self.host.job.record = lambda *args: None30 # stubs31 self.god.stub_function(utils, "get_server_dir")32 self.god.stub_function(utils, "run")33 self.god.stub_function(utils, "get")34 self.god.stub_function(utils, "read_keyval")35 self.god.stub_function(utils, "write_keyval")36 self.god.stub_function(utils, "system")37 self.god.stub_function(tempfile, "mkstemp")38 self.god.stub_function(tempfile, "mktemp")39 self.god.stub_function(os, "getcwd")40 self.god.stub_function(os, "system")41 self.god.stub_function(os, "chdir")42 self.god.stub_function(os, "makedirs")43 self.god.stub_function(os, "remove")44 self.god.stub_function(os, "fdopen")45 self.god.stub_function(os.path, "exists")46 self.god.stub_function(autotest, "open")47 self.god.stub_function(autotest.global_config.global_config,48 "get_config_value")49 self.god.stub_function(logging, "exception")50 self.god.stub_class(autotest, "_Run")51 self.god.stub_class(autotest, "log_collector")52 def tearDown(self):53 self.god.unstub_all()54 def construct(self):55 # setup56 self.serverdir = "serverdir"57 # record58 utils.get_server_dir.expect_call().and_return(self.serverdir)59 # create the autotest object60 self.autotest = autotest.Autotest(self.host)61 self.autotest.job = self.host.job62 self.god.stub_function(self.autotest, "_install_using_send_file")63 # stub out abspath64 self.god.stub_function(os.path, "abspath")65 # check66 self.god.check_playback()67 def record_install_prologue(self):68 self.construct()69 # setup70 self.god.stub_class(packages, "PackageManager")71 self.autotest.got = False72 location = os.path.join(self.serverdir, '../client')73 location = os.path.abspath.expect_call(location).and_return(location)74 # record75 utils.get.expect_call(os.path.join(self.serverdir,76 '../client')).and_return('source_material')77 self.host.wait_up.expect_call(timeout=30)78 self.host.setup.expect_call()79 self.host.get_autodir.expect_call().and_return("autodir")80 self.host.set_autodir.expect_call("autodir")81 self.host.run.expect_call('mkdir -p autodir')82 self.host.run.expect_call('rm -rf autodir/results/*',83 ignore_status=True)84 def test_constructor(self):85 self.construct()86 # we should check the calls87 self.god.check_playback()88 def test_full_client_install(self):89 self.record_install_prologue()90 self.host.run.expect_call('rm -f "autodir/packages.checksum"')91 c = autotest.global_config.global_config92 c.get_config_value.expect_call('PACKAGES',93 'serve_packages_from_autoserv',94 type=bool).and_return(False)95 self.host.send_file.expect_call('source_material', 'autodir',96 delete_dest=True)97 self.god.stub_function(autotest.Autotest, "_send_shadow_config")98 autotest.Autotest._send_shadow_config.expect_call()99 # run and check100 self.autotest.install_full_client()101 self.god.check_playback()102 def test_autoserv_install(self):103 self.record_install_prologue()104 c = autotest.global_config.global_config105 c.get_config_value.expect_call('PACKAGES',106 'fetch_location', type=list, default=[]).and_return([])107 os.path.exists.expect_call('/etc/cros_chroot_version').and_return(True)108 c.get_config_value.expect_call('PACKAGES',109 'serve_packages_from_autoserv',110 type=bool).and_return(True)111 self.autotest._install_using_send_file.expect_call(self.host,112 'autodir')113 self.god.stub_function(autotest.Autotest, "_send_shadow_config")114 autotest.Autotest._send_shadow_config.expect_call()115 # run and check116 self.autotest.install()117 self.god.check_playback()118 def test_packaging_install(self):119 self.record_install_prologue()120 c = autotest.global_config.global_config121 c.get_config_value.expect_call('PACKAGES',122 'fetch_location', type=list, default=[]).and_return(['repo'])123 os.path.exists.expect_call('/etc/cros_chroot_version').and_return(True)124 pkgmgr = packages.PackageManager.expect_new('autodir',125 repo_urls=['repo'], hostname='hostname', do_locking=False,126 run_function=self.host.run, run_function_dargs=dict(timeout=600))127 pkg_dir = os.path.join('autodir', 'packages')128 cmd = ('cd autodir && ls | grep -v "^packages$" | '129 'grep -v "^result_tools$" | '130 'xargs rm -rf && rm -rf .[!.]*')131 self.host.run.expect_call(cmd)132 pkgmgr.install_pkg.expect_call('autotest', 'client', pkg_dir,133 'autodir', preserve_install_dir=True)134 # run and check135 self.autotest.install()136 self.god.check_playback()137 def test_run(self):138 self.construct()139 # setup140 control = "control"141 # stub out install142 self.god.stub_function(self.autotest, "install")143 # record144 self.autotest.install.expect_call(self.host, use_packaging=True)145 self.host.wait_up.expect_call(timeout=30)146 os.path.abspath.expect_call('.').and_return('.')147 run_obj = autotest._Run.expect_new(self.host, '.', None, False, False)148 tag = None149 run_obj.manual_control_file = os.path.join('autodir',150 'control.%s' % tag)151 run_obj.remote_control_file = os.path.join('autodir',152 'control.%s.autoserv' % tag)153 run_obj.tag = tag154 run_obj.autodir = 'autodir'155 run_obj.verify_machine.expect_call()156 run_obj.background = False157 debug = os.path.join('.', 'debug')158 os.makedirs.expect_call(debug)159 delete_file_list = [run_obj.remote_control_file,160 run_obj.remote_control_file + '.state',161 run_obj.manual_control_file,162 run_obj.manual_control_file + '.state']163 cmd = ';'.join('rm -f ' + control for control in delete_file_list)164 self.host.run.expect_call(cmd, ignore_status=True)165 utils.get.expect_call(control, local_copy=True).and_return("temp")166 c = autotest.global_config.global_config167 c.get_config_value.expect_call("PACKAGES",168 'fetch_location', type=list, default=[]).and_return(['repo'])169 cfile = self.god.create_mock_class(file, "file")170 cfile_orig = "original control file"171 cfile_new = "args = []\njob.add_repository(['repo'])\n"172 cfile_new += cfile_orig173 os.path.exists.expect_call('/etc/cros_chroot_version').and_return(True)174 autotest.open.expect_call("temp").and_return(cfile)175 cfile.read.expect_call().and_return(cfile_orig)176 autotest.open.expect_call("temp", 'w').and_return(cfile)177 cfile.write.expect_call(cfile_new)178 self.host.job.preprocess_client_state.expect_call().and_return(179 '/job/tmp/file1')180 self.host.send_file.expect_call(181 "/job/tmp/file1", "autodir/control.None.autoserv.init.state")182 os.remove.expect_call("/job/tmp/file1")183 self.host.send_file.expect_call("temp", run_obj.remote_control_file)184 os.path.abspath.expect_call('temp').and_return('control_file')185 os.path.abspath.expect_call('control').and_return('control')186 os.remove.expect_call("temp")187 run_obj.execute_control.expect_call(timeout=30,188 client_disconnect_timeout=240)189 # run and check output190 self.autotest.run(control, timeout=30)191 self.god.check_playback()192 def _stub_get_client_autodir_paths(self):193 def mock_get_client_autodir_paths(cls, host):194 return ['/some/path', '/another/path']195 self.god.stub_with(autotest.Autotest, 'get_client_autodir_paths',196 classmethod(mock_get_client_autodir_paths))197 def _expect_failed_run(self, command):198 (self.host.run.expect_call(command)199 .and_raises(error.AutoservRunError('dummy', object())))200 def test_get_installed_autodir(self):201 self._stub_get_client_autodir_paths()202 self.host.get_autodir.expect_call().and_return(None)203 self._expect_failed_run('test -x /some/path/bin/autotest')204 self.host.run.expect_call('test -x /another/path/bin/autotest')205 self.host.run.expect_call('test -w /another/path')206 autodir = autotest.Autotest.get_installed_autodir(self.host)207 self.assertEquals(autodir, '/another/path')208 def test_get_install_dir(self):209 self._stub_get_client_autodir_paths()210 self.host.get_autodir.expect_call().and_return(None)211 self._expect_failed_run('test -x /some/path/bin/autotest')212 self._expect_failed_run('test -x /another/path/bin/autotest')213 self._expect_failed_run('mkdir -p /some/path')214 self.host.run.expect_call('mkdir -p /another/path')215 self.host.run.expect_call('test -w /another/path')216 install_dir = autotest.Autotest.get_install_dir(self.host)217 self.assertEquals(install_dir, '/another/path')218 def test_client_logger_process_line_log_copy_collection_failure(self):219 collector = autotest.log_collector.expect_new(self.host, '', '')220 logger = autotest.client_logger(self.host, '', '')221 collector.collect_client_job_results.expect_call().and_raises(222 Exception('log copy failure'))223 logging.exception.expect_call(mock.is_string_comparator())224 logger._process_line('AUTOTEST_TEST_COMPLETE:/autotest/fifo1')225 def test_client_logger_process_line_log_copy_fifo_failure(self):226 collector = autotest.log_collector.expect_new(self.host, '', '')227 logger = autotest.client_logger(self.host, '', '')228 collector.collect_client_job_results.expect_call()229 self.host.run.expect_call('echo A > /autotest/fifo2').and_raises(230 Exception('fifo failure'))231 logging.exception.expect_call(mock.is_string_comparator())232 logger._process_line('AUTOTEST_TEST_COMPLETE:/autotest/fifo2')233 def test_client_logger_process_line_package_install_fifo_failure(self):234 collector = autotest.log_collector.expect_new(self.host, '', '')235 logger = autotest.client_logger(self.host, '', '')236 self.god.stub_function(logger, '_send_tarball')237 c = autotest.global_config.global_config238 c.get_config_value.expect_call('PACKAGES',239 'serve_packages_from_autoserv',240 type=bool).and_return(True)241 c.get_config_value.expect_call('PACKAGES',242 'serve_packages_from_autoserv',243 type=bool).and_return(True)244 logger._send_tarball.expect_call('pkgname.tar.bz2', '/autotest/dest/')245 self.host.run.expect_call('echo B > /autotest/fifo3').and_raises(246 Exception('fifo failure'))247 logging.exception.expect_call(mock.is_string_comparator())248 logger._process_line('AUTOTEST_FETCH_PACKAGE:pkgname.tar.bz2:'249 '/autotest/dest/:/autotest/fifo3')250if __name__ == "__main__":...

Full Screen

Full Screen

autotest_test.py

Source:autotest_test.py Github

copy

Full Screen

...27 def run(self, command, ignore_status=False):28 self.commands.append(command)29 def wait_up(self, timeout):30 pass31 def get_autodir(self):32 pass33 host = MockInstallHost()34 self.assertEqual(_TOP_PATH,35 autotest_remote.Autotest.get_installed_autodir(host))36 def testInstallFromDir(self):37 class MockInstallHost:38 def __init__(self):39 self.commands = []40 self.hostname = 'autotest-client.foo.com'41 def run(self, command, ignore_status=False):42 self.commands.append(command)43 def send_file(self, src, dst, delete_dest=False):44 self.commands.append("send_file: %s %s" % (src, dst))45 def wait_up(self, timeout):46 pass47 def get_autodir(self):48 pass49 def set_autodir(self, autodir):50 pass51 def setup(self):52 pass53 host = MockInstallHost()54 tmpdir = utils.get_tmp_dir()55 self.autotest.get(tmpdir)56 self.autotest.install(host)57 self.assertEqual(host.commands[0],58 'test -x %s/bin/autotest' % _TOP_PATH)59 self.assertEqual(host.commands[1], 'test -w %s' % _TOP_PATH)60 self.assertEqual(host.commands[2], 'mkdir -p %s' % _TOP_PATH)61 self.assertTrue(host.commands[4].startswith('send_file: []'))...

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