blob: bec0ea51824098f4c24a366fde0fc71a1e128f31 [file] [log] [blame]
jadmanski68ef26e2008-08-18 21:01:35 +00001#!/usr/bin/python
2
3import unittest, os
4import common
5from autotest_lib.client.common_lib import utils as common_utils
6from autotest_lib.client.common_lib.test_utils import mock
7from autotest_lib.server import rpm_kernel, utils, hosts
8from autotest_lib.server.hosts import bootloader
9
10
11class TestRpmKernel(unittest.TestCase):
12 def setUp(self):
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"
17
18
19 def tearDown(self):
20 self.god.unstub_all()
21
22
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,
26 "bootloader")
27 self.god.stub_function(self.kernel, "get_image_name")
jadmanski5664cff2008-12-03 18:00:03 +000028 self.god.stub_function(self.kernel, "get_vmlinux_name")
jadmanski68ef26e2008-08-18 21:01:35 +000029 rpm = self.kernel.source_material
30 rpm_package = "package.rpm"
31
32 # record
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)
jadmanski5664cff2008-12-03 18:00:03 +000044 self.kernel.get_vmlinux_name.expect_call().and_return("/boot/vmlinux")
45 host.run.expect_call('cd /;rpm2cpio %s | cpio -imuv ./boot/vmlinux' %
46 remote_rpm)
47 host.run.expect_call('ls /boot/vmlinux')
mbligh1a639fb2008-09-10 19:59:14 +000048 host.bootloader.remove_kernel.expect_call('autotest')
49 host.bootloader.add_kernel.expect_call("vmlinuz", 'autotest',
jadmanski68ef26e2008-08-18 21:01:35 +000050 args='', default=False)
mbligh1a639fb2008-09-10 19:59:14 +000051 host.bootloader.boot_once.expect_call('autotest')
jadmanski68ef26e2008-08-18 21:01:35 +000052
53 # run and test
54 self.kernel.install(host)
55 self.god.check_playback()
56
57
58 def test_get_version(self):
59 # record
60 result = common_utils.CmdResult()
61 result.exit_status = 0
62 result.stdout = "image"
63
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)
67
68 # run and test
69 self.assertEquals(self.kernel.get_version(), result.stdout)
70 self.god.check_playback()
71
72
73 def test_get_image_name(self):
74 # record
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'
79 ).and_return(result)
80
81 # run and test
82 self.assertEquals(self.kernel.get_image_name(), result.stdout)
83 self.god.check_playback()
84
85
86 def test_get_vmlinux_name(self):
87 # record
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'
92 ).and_return(result)
93
94 # run and test
95 self.assertEquals(self.kernel.get_vmlinux_name(), result.stdout)
96 self.god.check_playback()
97
98
99 def test_get_initrd_name(self):
100 # record
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)
105
106 # run and test
107 self.kernel.get_initrd_name()
108 self.god.check_playback()
109
110
111if __name__ == "__main__":
112 unittest.main()