diff options
Diffstat (limited to 'meta/lib/oeqa/runtime/cases/smart.py')
-rw-r--r-- | meta/lib/oeqa/runtime/cases/smart.py | 218 |
1 files changed, 218 insertions, 0 deletions
diff --git a/meta/lib/oeqa/runtime/cases/smart.py b/meta/lib/oeqa/runtime/cases/smart.py new file mode 100644 index 0000000000..dde1c4d792 --- /dev/null +++ b/meta/lib/oeqa/runtime/cases/smart.py | |||
@@ -0,0 +1,218 @@ | |||
1 | import unittest | ||
2 | import re | ||
3 | import oe | ||
4 | import subprocess | ||
5 | from oeqa.oetest import oeRuntimeTest, skipModule | ||
6 | from oeqa.utils.decorators import * | ||
7 | from oeqa.utils.httpserver import HTTPService | ||
8 | |||
9 | def setUpModule(): | ||
10 | if not oeRuntimeTest.hasFeature("package-management"): | ||
11 | skipModule("Image doesn't have package management feature") | ||
12 | if not oeRuntimeTest.hasPackage("smartpm"): | ||
13 | skipModule("Image doesn't have smart installed") | ||
14 | if "package_rpm" != oeRuntimeTest.tc.d.getVar("PACKAGE_CLASSES").split()[0]: | ||
15 | skipModule("Rpm is not the primary package manager") | ||
16 | |||
17 | class SmartTest(oeRuntimeTest): | ||
18 | |||
19 | @skipUnlessPassed('test_smart_help') | ||
20 | def smart(self, command, expected = 0): | ||
21 | command = 'smart %s' % command | ||
22 | status, output = self.target.run(command, 1500) | ||
23 | message = os.linesep.join([command, output]) | ||
24 | self.assertEqual(status, expected, message) | ||
25 | self.assertFalse("Cannot allocate memory" in output, message) | ||
26 | return output | ||
27 | |||
28 | class SmartBasicTest(SmartTest): | ||
29 | |||
30 | @testcase(716) | ||
31 | @skipUnlessPassed('test_ssh') | ||
32 | def test_smart_help(self): | ||
33 | self.smart('--help') | ||
34 | |||
35 | @testcase(968) | ||
36 | def test_smart_version(self): | ||
37 | self.smart('--version') | ||
38 | |||
39 | @testcase(721) | ||
40 | def test_smart_info(self): | ||
41 | self.smart('info python-smartpm') | ||
42 | |||
43 | @testcase(421) | ||
44 | def test_smart_query(self): | ||
45 | self.smart('query python-smartpm') | ||
46 | |||
47 | @testcase(720) | ||
48 | def test_smart_search(self): | ||
49 | self.smart('search python-smartpm') | ||
50 | |||
51 | @testcase(722) | ||
52 | def test_smart_stats(self): | ||
53 | self.smart('stats') | ||
54 | |||
55 | class SmartRepoTest(SmartTest): | ||
56 | |||
57 | @classmethod | ||
58 | def create_index(self, arg): | ||
59 | index_cmd = arg | ||
60 | try: | ||
61 | bb.note("Executing '%s' ..." % index_cmd) | ||
62 | result = subprocess.check_output(index_cmd, stderr=subprocess.STDOUT, shell=True).decode("utf-8") | ||
63 | except subprocess.CalledProcessError as e: | ||
64 | return("Index creation command '%s' failed with return code %d:\n%s" % | ||
65 | (e.cmd, e.returncode, e.output.decode("utf-8"))) | ||
66 | if result: | ||
67 | bb.note(result) | ||
68 | return None | ||
69 | |||
70 | @classmethod | ||
71 | def setUpClass(self): | ||
72 | self.repolist = [] | ||
73 | |||
74 | # Index RPMs | ||
75 | rpm_createrepo = bb.utils.which(os.getenv('PATH'), "createrepo") | ||
76 | index_cmds = [] | ||
77 | rpm_dirs_found = False | ||
78 | archs = (oeRuntimeTest.tc.d.getVar('ALL_MULTILIB_PACKAGE_ARCHS') or "").replace('-', '_').split() | ||
79 | for arch in archs: | ||
80 | rpm_dir = os.path.join(oeRuntimeTest.tc.d.getVar('DEPLOY_DIR_RPM'), arch) | ||
81 | idx_path = os.path.join(oeRuntimeTest.tc.d.getVar('WORKDIR'), 'rpm', arch) | ||
82 | db_path = os.path.join(oeRuntimeTest.tc.d.getVar('WORKDIR'), 'rpmdb', arch) | ||
83 | if not os.path.isdir(rpm_dir): | ||
84 | continue | ||
85 | if os.path.exists(db_path): | ||
86 | bb.utils.remove(dbpath, True) | ||
87 | lockfilename = oeRuntimeTest.tc.d.getVar('DEPLOY_DIR_RPM') + "/rpm.lock" | ||
88 | lf = bb.utils.lockfile(lockfilename, False) | ||
89 | oe.path.copyhardlinktree(rpm_dir, idx_path) | ||
90 | # Full indexes overload a 256MB image so reduce the number of rpms | ||
91 | # in the feed. Filter to p* since we use the psplash packages and | ||
92 | # this leaves some allarch and machine arch packages too. | ||
93 | bb.utils.remove(idx_path + "*/[a-oq-z]*.rpm") | ||
94 | bb.utils.unlockfile(lf) | ||
95 | index_cmds.append("%s --dbpath %s --update -q %s" % (rpm_createrepo, db_path, idx_path)) | ||
96 | rpm_dirs_found = True | ||
97 | # Create repodata¬ | ||
98 | result = oe.utils.multiprocess_exec(index_cmds, self.create_index) | ||
99 | if result: | ||
100 | bb.fatal('%s' % ('\n'.join(result))) | ||
101 | self.repo_server = HTTPService(oeRuntimeTest.tc.d.getVar('WORKDIR'), oeRuntimeTest.tc.target.server_ip) | ||
102 | self.repo_server.start() | ||
103 | |||
104 | @classmethod | ||
105 | def tearDownClass(self): | ||
106 | self.repo_server.stop() | ||
107 | for i in self.repolist: | ||
108 | oeRuntimeTest.tc.target.run('smart channel -y --remove '+str(i)) | ||
109 | |||
110 | @testcase(1143) | ||
111 | def test_smart_channel(self): | ||
112 | self.smart('channel', 1) | ||
113 | |||
114 | @testcase(719) | ||
115 | def test_smart_channel_add(self): | ||
116 | image_pkgtype = self.tc.d.getVar('IMAGE_PKGTYPE') | ||
117 | deploy_url = 'http://%s:%s/%s' %(self.target.server_ip, self.repo_server.port, image_pkgtype) | ||
118 | pkgarchs = self.tc.d.getVar('PACKAGE_ARCHS').replace("-","_").split() | ||
119 | for arch in os.listdir('%s/%s' % (self.repo_server.root_dir, image_pkgtype)): | ||
120 | if arch in pkgarchs: | ||
121 | self.smart('channel -y --add {a} type=rpm-md baseurl={u}/{a}'.format(a=arch, u=deploy_url)) | ||
122 | self.repolist.append(arch) | ||
123 | self.smart('update') | ||
124 | |||
125 | @testcase(969) | ||
126 | def test_smart_channel_help(self): | ||
127 | self.smart('channel --help') | ||
128 | |||
129 | @testcase(970) | ||
130 | def test_smart_channel_list(self): | ||
131 | self.smart('channel --list') | ||
132 | |||
133 | @testcase(971) | ||
134 | def test_smart_channel_show(self): | ||
135 | self.smart('channel --show') | ||
136 | |||
137 | @testcase(717) | ||
138 | def test_smart_channel_rpmsys(self): | ||
139 | self.smart('channel --show rpmsys') | ||
140 | self.smart('channel --disable rpmsys') | ||
141 | self.smart('channel --enable rpmsys') | ||
142 | |||
143 | @testcase(1144) | ||
144 | @skipUnlessPassed('test_smart_channel_add') | ||
145 | def test_smart_install(self): | ||
146 | self.smart('remove -y psplash-default') | ||
147 | self.smart('install -y psplash-default') | ||
148 | |||
149 | @testcase(728) | ||
150 | @skipUnlessPassed('test_smart_install') | ||
151 | def test_smart_install_dependency(self): | ||
152 | self.smart('remove -y psplash') | ||
153 | self.smart('install -y psplash-default') | ||
154 | |||
155 | @testcase(723) | ||
156 | @skipUnlessPassed('test_smart_channel_add') | ||
157 | def test_smart_install_from_disk(self): | ||
158 | self.smart('remove -y psplash-default') | ||
159 | self.smart('download psplash-default') | ||
160 | self.smart('install -y ./psplash-default*') | ||
161 | |||
162 | @testcase(725) | ||
163 | @skipUnlessPassed('test_smart_channel_add') | ||
164 | def test_smart_install_from_http(self): | ||
165 | output = self.smart('download --urls psplash-default') | ||
166 | url = re.search('(http://.*/psplash-default.*\.rpm)', output) | ||
167 | self.assertTrue(url, msg="Couln't find download url in %s" % output) | ||
168 | self.smart('remove -y psplash-default') | ||
169 | self.smart('install -y %s' % url.group(0)) | ||
170 | |||
171 | @testcase(729) | ||
172 | @skipUnlessPassed('test_smart_install') | ||
173 | def test_smart_reinstall(self): | ||
174 | self.smart('reinstall -y psplash-default') | ||
175 | |||
176 | @testcase(727) | ||
177 | @skipUnlessPassed('test_smart_channel_add') | ||
178 | def test_smart_remote_repo(self): | ||
179 | self.smart('update') | ||
180 | self.smart('install -y psplash') | ||
181 | self.smart('remove -y psplash') | ||
182 | |||
183 | @testcase(726) | ||
184 | def test_smart_local_dir(self): | ||
185 | self.target.run('mkdir /tmp/myrpmdir') | ||
186 | self.smart('channel --add myrpmdir type=rpm-dir path=/tmp/myrpmdir -y') | ||
187 | self.target.run('cd /tmp/myrpmdir') | ||
188 | self.smart('download psplash') | ||
189 | output = self.smart('channel --list') | ||
190 | for i in output.split("\n"): | ||
191 | if ("rpmsys" != str(i)) and ("myrpmdir" != str(i)): | ||
192 | self.smart('channel --disable '+str(i)) | ||
193 | self.target.run('cd $HOME') | ||
194 | self.smart('install psplash') | ||
195 | for i in output.split("\n"): | ||
196 | if ("rpmsys" != str(i)) and ("myrpmdir" != str(i)): | ||
197 | self.smart('channel --enable '+str(i)) | ||
198 | self.smart('channel --remove myrpmdir -y') | ||
199 | self.target.run("rm -rf /tmp/myrpmdir") | ||
200 | |||
201 | @testcase(718) | ||
202 | def test_smart_add_rpmdir(self): | ||
203 | self.target.run('mkdir /tmp/myrpmdir') | ||
204 | self.smart('channel --add myrpmdir type=rpm-dir path=/tmp/myrpmdir -y') | ||
205 | self.smart('channel --disable myrpmdir -y') | ||
206 | output = self.smart('channel --show myrpmdir') | ||
207 | self.assertTrue("disabled = yes" in output, msg="Failed to disable rpm dir") | ||
208 | self.smart('channel --enable myrpmdir -y') | ||
209 | output = self.smart('channel --show myrpmdir') | ||
210 | self.assertFalse("disabled = yes" in output, msg="Failed to enable rpm dir") | ||
211 | self.smart('channel --remove myrpmdir -y') | ||
212 | self.target.run("rm -rf /tmp/myrpmdir") | ||
213 | |||
214 | @testcase(731) | ||
215 | @skipUnlessPassed('test_smart_channel_add') | ||
216 | def test_smart_remove_package(self): | ||
217 | self.smart('install -y psplash') | ||
218 | self.smart('remove -y psplash') | ||