5 from autotest_lib
.client
.common_lib
import utils
as common_utils
6 from autotest_lib
.client
.common_lib
.test_utils
import mock
7 from autotest_lib
.server
import rpm_kernel
, utils
, hosts
8 from autotest_lib
.server
.hosts
import bootloader
11 class TestRpmKernel(unittest
.TestCase
):
13 self
.god
= mock
.mock_god()
14 self
.kernel
= rpm_kernel
.RPMKernel()
15 self
.god
.stub_function(utils
, "run")
16 self
.kernel
.source_material
= "source.rpm"
23 def test_install(self
):
24 host
= self
.god
.create_mock_class(hosts
.RemoteHost
, "host")
25 host
.bootloader
= self
.god
.create_mock_class(bootloader
.Bootloader
,
27 self
.god
.stub_function(self
.kernel
, "get_image_name")
28 self
.god
.stub_function(self
.kernel
, "get_vmlinux_name")
29 rpm
= self
.kernel
.source_material
30 rpm_package
= "package.rpm"
33 remote_tmpdir
= 'remote_tmp_dir'
34 host
.get_tmp_dir
.expect_call().and_return(remote_tmpdir
)
35 remote_rpm
= os
.path
.join(remote_tmpdir
, os
.path
.basename(rpm
))
36 result
= common_utils
.CmdResult()
37 result
.exit_status
= 0
38 result
.stdout
= rpm_package
39 utils
.run
.expect_call('/usr/bin/rpm -q -p %s' % rpm
).and_return(result
)
40 self
.kernel
.get_image_name
.expect_call().and_return("vmlinuz")
41 host
.send_file
.expect_call(rpm
, remote_rpm
)
42 host
.run
.expect_call('rpm -e ' + rpm_package
, ignore_status
= True)
43 host
.run
.expect_call('rpm --force -i ' + remote_rpm
)
44 self
.kernel
.get_vmlinux_name
.expect_call().and_return("/boot/vmlinux")
45 host
.run
.expect_call('cd /;rpm2cpio %s | cpio -imuv ./boot/vmlinux' %
47 host
.run
.expect_call('ls /boot/vmlinux')
48 host
.bootloader
.remove_kernel
.expect_call('autotest')
49 host
.bootloader
.add_kernel
.expect_call("vmlinuz", 'autotest',
50 args
='', default
=False)
51 host
.bootloader
.boot_once
.expect_call('autotest')
54 self
.kernel
.install(host
)
55 self
.god
.check_playback()
58 def test_get_version(self
):
60 result
= common_utils
.CmdResult()
61 result
.exit_status
= 0
62 result
.stdout
= "image"
64 cmd
= ('rpm -qpi %s | grep Version | awk \'{print($3);}\'' %
65 (utils
.sh_escape("source.rpm")))
66 utils
.run
.expect_call(cmd
).and_return(result
)
69 self
.assertEquals(self
.kernel
.get_version(), result
.stdout
)
70 self
.god
.check_playback()
73 def test_get_image_name(self
):
75 result
= common_utils
.CmdResult()
76 result
.exit_status
= 0
77 result
.stdout
= "image"
78 utils
.run
.expect_call('rpm -q -l -p source.rpm | grep /boot/vmlinuz'
82 self
.assertEquals(self
.kernel
.get_image_name(), result
.stdout
)
83 self
.god
.check_playback()
86 def test_get_vmlinux_name(self
):
88 result
= common_utils
.CmdResult()
89 result
.exit_status
= 0
90 result
.stdout
= "vmlinuz"
91 utils
.run
.expect_call('rpm -q -l -p source.rpm | grep /boot/vmlinux'
95 self
.assertEquals(self
.kernel
.get_vmlinux_name(), result
.stdout
)
96 self
.god
.check_playback()
99 def test_get_initrd_name(self
):
101 result
= common_utils
.CmdResult()
102 result
.exit_status
= 0
103 utils
.run
.expect_call('rpm -q -l -p %s | grep /boot/initrd'
104 % "source.rpm", ignore_status
=True).and_return(result
)
107 self
.kernel
.get_initrd_name()
108 self
.god
.check_playback()
111 if __name__
== "__main__":