blob: 126d614638f3f7add6ebfebcb443cf215b8ac0ec [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001import unittest
2import re
3from oeqa.oetest import oeRuntimeTest, skipModule
4from oeqa.utils.decorators import *
5from oeqa.utils.httpserver import HTTPService
6
7def setUpModule():
8 if not oeRuntimeTest.hasFeature("package-management"):
9 skipModule("Image doesn't have package management feature")
10 if not oeRuntimeTest.hasPackage("smart"):
11 skipModule("Image doesn't have smart installed")
12 if "package_rpm" != oeRuntimeTest.tc.d.getVar("PACKAGE_CLASSES", True).split()[0]:
13 skipModule("Rpm is not the primary package manager")
14
15class SmartTest(oeRuntimeTest):
16
17 @skipUnlessPassed('test_smart_help')
18 def smart(self, command, expected = 0):
19 command = 'smart %s' % command
20 status, output = self.target.run(command, 1500)
21 message = os.linesep.join([command, output])
22 self.assertEqual(status, expected, message)
23 self.assertFalse("Cannot allocate memory" in output, message)
24 return output
25
26class SmartBasicTest(SmartTest):
27
28 @testcase(716)
29 @skipUnlessPassed('test_ssh')
30 def test_smart_help(self):
31 self.smart('--help')
32
33 @testcase(968)
34 def test_smart_version(self):
35 self.smart('--version')
36
37 @testcase(721)
38 def test_smart_info(self):
39 self.smart('info python-smartpm')
40
41 @testcase(421)
42 def test_smart_query(self):
43 self.smart('query python-smartpm')
44
45 @testcase(720)
46 def test_smart_search(self):
47 self.smart('search python-smartpm')
48
49 @testcase(722)
50 def test_smart_stats(self):
51 self.smart('stats')
52
53class SmartRepoTest(SmartTest):
54
55 @classmethod
56 def setUpClass(self):
57 self.repolist = []
58 self.repo_server = HTTPService(oeRuntimeTest.tc.d.getVar('DEPLOY_DIR', True), oeRuntimeTest.tc.target.server_ip)
59 self.repo_server.start()
60
61 @classmethod
62 def tearDownClass(self):
63 self.repo_server.stop()
64 for i in self.repolist:
65 oeRuntimeTest.tc.target.run('smart channel -y --remove '+str(i))
66
67 @testcase(1143)
68 def test_smart_channel(self):
69 self.smart('channel', 1)
70
71 @testcase(719)
72 def test_smart_channel_add(self):
73 image_pkgtype = self.tc.d.getVar('IMAGE_PKGTYPE', True)
74 deploy_url = 'http://%s:%s/%s' %(self.target.server_ip, self.repo_server.port, image_pkgtype)
75 pkgarchs = self.tc.d.getVar('PACKAGE_ARCHS', True).replace("-","_").split()
76 for arch in os.listdir('%s/%s' % (self.repo_server.root_dir, image_pkgtype)):
77 if arch in pkgarchs:
78 self.smart('channel -y --add {a} type=rpm-md baseurl={u}/{a}'.format(a=arch, u=deploy_url))
79 self.repolist.append(arch)
80 self.smart('update')
81
82 @testcase(969)
83 def test_smart_channel_help(self):
84 self.smart('channel --help')
85
86 @testcase(970)
87 def test_smart_channel_list(self):
88 self.smart('channel --list')
89
90 @testcase(971)
91 def test_smart_channel_show(self):
92 self.smart('channel --show')
93
94 @testcase(717)
95 def test_smart_channel_rpmsys(self):
96 self.smart('channel --show rpmsys')
97 self.smart('channel --disable rpmsys')
98 self.smart('channel --enable rpmsys')
99
100 @testcase(1144)
101 @skipUnlessPassed('test_smart_channel_add')
102 def test_smart_install(self):
103 self.smart('remove -y psplash-default')
104 self.smart('install -y psplash-default')
105
106 @testcase(728)
107 @skipUnlessPassed('test_smart_install')
108 def test_smart_install_dependency(self):
109 self.smart('remove -y psplash')
110 self.smart('install -y psplash-default')
111
112 @testcase(723)
113 @skipUnlessPassed('test_smart_channel_add')
114 def test_smart_install_from_disk(self):
115 self.smart('remove -y psplash-default')
116 self.smart('download psplash-default')
117 self.smart('install -y ./psplash-default*')
118
119 @testcase(725)
120 @skipUnlessPassed('test_smart_channel_add')
121 def test_smart_install_from_http(self):
122 output = self.smart('download --urls psplash-default')
123 url = re.search('(http://.*/psplash-default.*\.rpm)', output)
124 self.assertTrue(url, msg="Couln't find download url in %s" % output)
125 self.smart('remove -y psplash-default')
126 self.smart('install -y %s' % url.group(0))
127
128 @testcase(729)
129 @skipUnlessPassed('test_smart_install')
130 def test_smart_reinstall(self):
131 self.smart('reinstall -y psplash-default')
132
133 @testcase(727)
134 @skipUnlessPassed('test_smart_channel_add')
135 def test_smart_remote_repo(self):
136 self.smart('update')
137 self.smart('install -y psplash')
138 self.smart('remove -y psplash')
139
140 @testcase(726)
141 def test_smart_local_dir(self):
142 self.target.run('mkdir /tmp/myrpmdir')
143 self.smart('channel --add myrpmdir type=rpm-dir path=/tmp/myrpmdir -y')
144 self.target.run('cd /tmp/myrpmdir')
145 self.smart('download psplash')
146 output = self.smart('channel --list')
147 for i in output.split("\n"):
148 if ("rpmsys" != str(i)) and ("myrpmdir" != str(i)):
149 self.smart('channel --disable '+str(i))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500150 self.target.run('cd $HOME')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500151 self.smart('install psplash')
152 for i in output.split("\n"):
153 if ("rpmsys" != str(i)) and ("myrpmdir" != str(i)):
154 self.smart('channel --enable '+str(i))
155 self.smart('channel --remove myrpmdir -y')
156 self.target.run("rm -rf /tmp/myrpmdir")
157
158 @testcase(718)
159 def test_smart_add_rpmdir(self):
160 self.target.run('mkdir /tmp/myrpmdir')
161 self.smart('channel --add myrpmdir type=rpm-dir path=/tmp/myrpmdir -y')
162 self.smart('channel --disable myrpmdir -y')
163 output = self.smart('channel --show myrpmdir')
164 self.assertTrue("disabled = yes" in output, msg="Failed to disable rpm dir")
165 self.smart('channel --enable myrpmdir -y')
166 output = self.smart('channel --show myrpmdir')
167 self.assertFalse("disabled = yes" in output, msg="Failed to enable rpm dir")
168 self.smart('channel --remove myrpmdir -y')
169 self.target.run("rm -rf /tmp/myrpmdir")
170
171 @testcase(731)
172 @skipUnlessPassed('test_smart_channel_add')
173 def test_smart_remove_package(self):
174 self.smart('install -y psplash')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500175 self.smart('remove -y psplash')