How to use _install_using_send_file 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 TestBaseAutotest(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.last_boot_tag = 'Autotest'22 self.host.job.sysinfo = self.god.create_mock_class(23 sysinfo.sysinfo, "sysinfo")24 self.host.job.profilers = self.god.create_mock_class(25 profilers.profilers, "profilers")26 self.host.job.profilers.add_log = {}27 self.host.job.tmpdir = "/job/tmp"28 self.host.job.default_profile_only = False29 self.host.job.args = []30 self.host.job.record = lambda *args: None31 # stubs32 self.god.stub_function(utils, "get_server_dir")33 self.god.stub_function(utils, "run")34 self.god.stub_function(utils, "get")35 self.god.stub_function(utils, "read_keyval")36 self.god.stub_function(utils, "write_keyval")37 self.god.stub_function(utils, "system")38 self.god.stub_function(tempfile, "mkstemp")39 self.god.stub_function(tempfile, "mktemp")40 self.god.stub_function(os, "getcwd")41 self.god.stub_function(os, "system")42 self.god.stub_function(os, "chdir")43 self.god.stub_function(os, "makedirs")44 self.god.stub_function(os, "remove")45 self.god.stub_function(os, "fdopen")46 self.god.stub_function(os.path, "exists")47 self.god.stub_function(autotest, "open")48 self.god.stub_function(autotest.global_config.global_config,49 "get_config_value")50 self.god.stub_function(logging, "exception")51 self.god.stub_class(autotest, "_Run")52 self.god.stub_class(autotest, "log_collector")53 def tearDown(self):54 self.god.unstub_all()55 def construct(self):56 # setup57 self.serverdir = "serverdir"58 # record59 utils.get_server_dir.expect_call().and_return(self.serverdir)60 # create the autotest object61 self.base_autotest = autotest.BaseAutotest(self.host)62 self.base_autotest.job = self.host.job63 self.god.stub_function(self.base_autotest, "_install_using_send_file")64 # stub out abspath65 self.god.stub_function(os.path, "abspath")66 # check67 self.god.check_playback()68 def record_install_prologue(self):69 self.construct()70 # setup71 self.god.stub_class(packages, "PackageManager")72 self.base_autotest.got = False73 location = os.path.join(self.serverdir, '../client')74 location = os.path.abspath.expect_call(location).and_return(location)75 # record76 os.getcwd.expect_call().and_return('cwd')77 os.chdir.expect_call(os.path.join(self.serverdir, '../client'))78 utils.system.expect_call('tools/make_clean', ignore_status=True)79 os.chdir.expect_call('cwd')80 utils.get.expect_call(os.path.join(self.serverdir,81 '../client')).and_return('source_material')82 self.host.wait_up.expect_call(timeout=30)83 self.host.setup.expect_call()84 self.host.get_autodir.expect_call().and_return("autodir")85 self.host.set_autodir.expect_call("autodir")86 self.host.run.expect_call('mkdir -p autodir')87 self.host.run.expect_call('rm -rf autodir/results/*',88 ignore_status=True)89 def test_constructor(self):90 self.construct()91 # we should check the calls92 self.god.check_playback()93 def test_full_client_install(self):94 self.record_install_prologue()95 self.host.run.expect_call('rm -f "autodir/packages.checksum"')96 c = autotest.global_config.global_config97 c.get_config_value.expect_call('PACKAGES',98 'serve_packages_from_autoserv',99 type=bool).and_return(False)100 self.host.send_file.expect_call('source_material', 'autodir',101 delete_dest=True)102 # run and check103 self.base_autotest.install_full_client()104 self.god.check_playback()105 def test_autoserv_install(self):106 self.record_install_prologue()107 c = autotest.global_config.global_config108 c.get_config_value.expect_call('PACKAGES',109 'fetch_location', type=list, default=[]).and_return([])110 c.get_config_value.expect_call('PACKAGES',111 'serve_packages_from_autoserv',112 type=bool).and_return(True)113 self.base_autotest._install_using_send_file.expect_call(self.host,114 'autodir')115 # run and check116 self.base_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 pkgmgr = packages.PackageManager.expect_new('autodir',124 repo_urls=['repo'], hostname='hostname', do_locking=False,125 run_function=self.host.run, run_function_dargs=dict(timeout=600))126 pkg_dir = os.path.join('autodir', 'packages')127 cmd = ('cd autodir && ls | grep -v "^packages$"'128 ' | xargs rm -rf && rm -rf .[!.]*')129 self.host.run.expect_call(cmd)130 pkgmgr.install_pkg.expect_call('autotest', 'client', pkg_dir,131 'autodir', preserve_install_dir=True)132 # run and check133 self.base_autotest.install()134 self.god.check_playback()135 def test_run(self):136 self.construct()137 # setup138 control = "control"139 # stub out install140 self.god.stub_function(self.base_autotest, "install")141 # record142 self.base_autotest.install.expect_call(self.host, use_packaging=True)143 self.host.wait_up.expect_call(timeout=30)144 os.path.abspath.expect_call('.').and_return('.')145 run_obj = autotest._Run.expect_new(self.host, '.', None, False, False)146 tag = None147 run_obj.manual_control_file = os.path.join('autodir',148 'control.%s' % tag)149 run_obj.remote_control_file = os.path.join('autodir',150 'control.%s.autoserv' % tag)151 run_obj.tag = tag152 run_obj.autodir = 'autodir'153 run_obj.verify_machine.expect_call()154 run_obj.background = False155 debug = os.path.join('.', 'debug')156 os.makedirs.expect_call(debug)157 delete_file_list = [run_obj.remote_control_file,158 run_obj.remote_control_file + '.state',159 run_obj.manual_control_file,160 run_obj.manual_control_file + '.state']161 cmd = ';'.join('rm -f ' + control for control in delete_file_list)162 self.host.run.expect_call(cmd, ignore_status=True)163 utils.get.expect_call(control, local_copy=True).and_return("temp")164 c = autotest.global_config.global_config165 c.get_config_value.expect_call("PACKAGES",166 'fetch_location', type=list, default=[]).and_return(['repo'])167 cfile = self.god.create_mock_class(file, "file")168 cfile_orig = "original control file"169 cfile_new = "args = []\njob.add_repository(['repo'])\n"170 cfile_new += cfile_orig171 autotest.open.expect_call("temp").and_return(cfile)172 cfile.read.expect_call().and_return(cfile_orig)173 autotest.open.expect_call("temp", 'w').and_return(cfile)174 cfile.write.expect_call(cfile_new)175 self.host.job.preprocess_client_state.expect_call().and_return(176 '/job/tmp/file1')177 self.host.send_file.expect_call(178 "/job/tmp/file1", "autodir/control.None.autoserv.init.state")179 os.remove.expect_call("/job/tmp/file1")180 self.host.send_file.expect_call("temp", run_obj.remote_control_file)181 os.path.abspath.expect_call('temp').and_return('control_file')182 os.path.abspath.expect_call('control').and_return('control')183 os.remove.expect_call("temp")184 run_obj.execute_control.expect_call(timeout=30,185 client_disconnect_timeout=240)186 # run and check output187 self.base_autotest.run(control, timeout=30)188 self.god.check_playback()189 def _stub_get_client_autodir_paths(self):190 def mock_get_client_autodir_paths(cls, host):191 return ['/some/path', '/another/path']192 self.god.stub_with(autotest.Autotest, 'get_client_autodir_paths',193 classmethod(mock_get_client_autodir_paths))194 def _expect_failed_run(self, command):195 (self.host.run.expect_call(command)196 .and_raises(error.AutoservRunError('dummy', object())))197 def test_get_installed_autodir(self):198 self._stub_get_client_autodir_paths()199 self.host.get_autodir.expect_call().and_return(None)200 self._expect_failed_run('test -x /some/path/bin/autotest')201 self.host.run.expect_call('test -x /another/path/bin/autotest')202 self.host.run.expect_call('test -w /another/path')203 autodir = autotest.Autotest.get_installed_autodir(self.host)204 self.assertEquals(autodir, '/another/path')205 def test_get_install_dir(self):206 self._stub_get_client_autodir_paths()207 self.host.get_autodir.expect_call().and_return(None)208 self._expect_failed_run('test -x /some/path/bin/autotest')209 self._expect_failed_run('test -x /another/path/bin/autotest')210 self._expect_failed_run('mkdir -p /some/path')211 self.host.run.expect_call('mkdir -p /another/path')212 self.host.run.expect_call('test -w /another/path')213 install_dir = autotest.Autotest.get_install_dir(self.host)214 self.assertEquals(install_dir, '/another/path')215 def test_client_logger_process_line_log_copy_collection_failure(self):216 collector = autotest.log_collector.expect_new(self.host, '', '')217 logger = autotest.client_logger(self.host, '', '')218 collector.collect_client_job_results.expect_call().and_raises(219 Exception('log copy failure'))220 logging.exception.expect_call(mock.is_string_comparator())221 logger._process_line('AUTOTEST_TEST_COMPLETE:/autotest/fifo1')222 def test_client_logger_process_line_log_copy_fifo_failure(self):223 collector = autotest.log_collector.expect_new(self.host, '', '')224 logger = autotest.client_logger(self.host, '', '')225 collector.collect_client_job_results.expect_call()226 self.host.run.expect_call('echo A > /autotest/fifo2').and_raises(227 Exception('fifo failure'))228 logging.exception.expect_call(mock.is_string_comparator())229 logger._process_line('AUTOTEST_TEST_COMPLETE:/autotest/fifo2')230 def test_client_logger_process_line_package_install_fifo_failure(self):231 collector = autotest.log_collector.expect_new(self.host, '', '')232 logger = autotest.client_logger(self.host, '', '')233 self.god.stub_function(logger, '_send_tarball')234 c = autotest.global_config.global_config235 c.get_config_value.expect_call('PACKAGES',236 'serve_packages_from_autoserv',237 type=bool).and_return(True)238 c.get_config_value.expect_call('PACKAGES',239 'serve_packages_from_autoserv',240 type=bool).and_return(True)241 logger._send_tarball.expect_call('pkgname.tar.bz2', '/autotest/dest/')242 self.host.run.expect_call('echo B > /autotest/fifo3').and_raises(243 Exception('fifo failure'))244 logging.exception.expect_call(mock.is_string_comparator())245 logger._process_line('AUTOTEST_FETCH_PACKAGE:pkgname.tar.bz2:'246 '/autotest/dest/:/autotest/fifo3')247if __name__ == "__main__":...

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