1 #!/usr/bin/python 2 3 import unittest, os 4 import common 5 from autotest_lib.client.common_lib.test_utils import mock 6 from autotest_lib.client.common_lib import utils as common_utils 7 from autotest_lib.server import deb_kernel, utils, hosts 8 from autotest_lib.server.hosts import bootloader 9 10 11 class TestDebKernel(unittest.TestCase): 12 def setUp(self): 13 self.god = mock.mock_god() 14 self.kernel = deb_kernel.DEBKernel() 15 self.host = self.god.create_mock_class(hosts.RemoteHost, "host") 16 self.host.bootloader = self.god.create_mock_class( 17 bootloader.Bootloader, "bootloader") 18 self.god.stub_function(utils, "run") 19 20 21 def tearDown(self): 22 self.god.unstub_all() 23 24 25 def common_code(self): 26 self.kernel.source_material = "source.rpm" 27 basename = os.path.basename(self.kernel.source_material) 28 self.remote_tmpdir = "remote/tmp/dir" 29 self.remote_filename = os.path.join(self.remote_tmpdir, basename) 30 self.host.get_tmp_dir.expect_call().and_return(self.remote_tmpdir) 31 self.host.send_file.expect_call(self.kernel.source_material, 32 self.remote_filename) 33 34 35 def test_install(self): 36 self.common_code() 37 38 # record 39 self.host.run.expect_call('dpkg -i "%s"' % 40 (utils.sh_escape(self.remote_filename))) 41 42 result = common_utils.CmdResult() 43 result.stdout = "1" 44 utils.run.expect_call('dpkg-deb -f "%s" version' % 45 utils.sh_escape(self.kernel.source_material)).and_return(result) 46 utils.run.expect_call('dpkg-deb -f "%s" version' % 47 utils.sh_escape(self.kernel.source_material)).and_return(result) 48 self.host.run.expect_call('mkinitramfs -o "/boot/initrd.img-1" "1"') 49 50 utils.run.expect_call('dpkg-deb -f "%s" version' % 51 utils.sh_escape(self.kernel.source_material)).and_return(result) 52 utils.run.expect_call('dpkg-deb -f "%s" version' % 53 utils.sh_escape(self.kernel.source_material)).and_return(result) 54 self.host.bootloader.add_kernel.expect_call('/boot/vmlinuz-1', 55 initrd='/boot/initrd.img-1') 56 57 # run and check 58 self.kernel.install(self.host) 59 self.god.check_playback() 60 61 62 def test_extract(self): 63 # setup 64 self.common_code() 65 content_dir= os.path.join(self.remote_tmpdir, "contents") 66 67 # record 68 self.host.run.expect_call('dpkg -x "%s" "%s"' % 69 (utils.sh_escape(self.remote_filename), 70 utils.sh_escape(content_dir))) 71 72 # run and test 73 self.kernel.extract(self.host) 74 self.god.check_playback() 75 76 77 if __name__ == "__main__": 78 unittest.main() 79