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
11 class TestDebKernel(unittest
.TestCase
):
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")
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
,
35 def test_install(self
):
39 self
.host
.run
.expect_call('dpkg -i "%s"' %
40 (utils
.sh_escape(self
.remote_filename
)))
42 result
= common_utils
.CmdResult()
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"')
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')
58 self
.kernel
.install(self
.host
)
59 self
.god
.check_playback()
62 def test_extract(self
):
65 content_dir
= os
.path
.join(self
.remote_tmpdir
, "contents")
68 self
.host
.run
.expect_call('dpkg -x "%s" "%s"' %
69 (utils
.sh_escape(self
.remote_filename
),
70 utils
.sh_escape(content_dir
)))
73 self
.kernel
.extract(self
.host
)
74 self
.god
.check_playback()
77 if __name__
== "__main__":