blob: 146daf80b3a20bf465374f3ee6bfe72c8e90af3c [file] [log] [blame]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001from oeqa.selftest.case import OESelftestTestCase
2from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars, runqemu
3from oeqa.utils.sshcontrol import SSHControl
4from oeqa.core.decorator.oeid import OETestID
5import os
6import re
7import tempfile
8import shutil
9
10class TestExport(OESelftestTestCase):
11
12 @classmethod
13 def tearDownClass(cls):
14 runCmd("rm -rf /tmp/sdk")
15 super(TestExport, cls).tearDownClass()
16
17 @OETestID(1499)
18 def test_testexport_basic(self):
19 """
20 Summary: Check basic testexport functionality with only ping test enabled.
21 Expected: 1. testexport directory must be created.
22 2. runexported.py must run without any error/exception.
23 3. ping test must succeed.
24 Product: oe-core
25 Author: Mariano Lopez <mariano.lopez@intel.com>
26 """
27
28 features = 'INHERIT += "testexport"\n'
29 # These aren't the actual IP addresses but testexport class needs something defined
30 features += 'TEST_SERVER_IP = "192.168.7.1"\n'
31 features += 'TEST_TARGET_IP = "192.168.7.1"\n'
32 features += 'TEST_SUITES = "ping"\n'
33 self.write_config(features)
34
35 # Build tesexport for core-image-minimal
36 bitbake('core-image-minimal')
37 bitbake('-c testexport core-image-minimal')
38
39 testexport_dir = get_bb_var('TEST_EXPORT_DIR', 'core-image-minimal')
40
41 # Verify if TEST_EXPORT_DIR was created
42 isdir = os.path.isdir(testexport_dir)
43 self.assertEqual(True, isdir, 'Failed to create testexport dir: %s' % testexport_dir)
44
45 with runqemu('core-image-minimal') as qemu:
46 # Attempt to run runexported.py to perform ping test
47 test_path = os.path.join(testexport_dir, "oe-test")
48 data_file = os.path.join(testexport_dir, 'data', 'testdata.json')
49 manifest = os.path.join(testexport_dir, 'data', 'manifest')
50 cmd = ("%s runtime --test-data-file %s --packages-manifest %s "
51 "--target-ip %s --server-ip %s --quiet"
52 % (test_path, data_file, manifest, qemu.ip, qemu.server_ip))
53 result = runCmd(cmd)
54 # Verify ping test was succesful
55 self.assertEqual(0, result.status, 'oe-test runtime returned a non 0 status')
56
57 @OETestID(1641)
58 def test_testexport_sdk(self):
59 """
60 Summary: Check sdk functionality for testexport.
61 Expected: 1. testexport directory must be created.
62 2. SDK tarball must exists.
63 3. Uncompressing of tarball must succeed.
64 4. Check if the SDK directory is added to PATH.
65 5. Run tar from the SDK directory.
66 Product: oe-core
67 Author: Mariano Lopez <mariano.lopez@intel.com>
68 """
69
70 features = 'INHERIT += "testexport"\n'
71 # These aren't the actual IP addresses but testexport class needs something defined
72 features += 'TEST_SERVER_IP = "192.168.7.1"\n'
73 features += 'TEST_TARGET_IP = "192.168.7.1"\n'
74 features += 'TEST_SUITES = "ping"\n'
75 features += 'TEST_EXPORT_SDK_ENABLED = "1"\n'
76 features += 'TEST_EXPORT_SDK_PACKAGES = "nativesdk-tar"\n'
77 self.write_config(features)
78
79 # Build tesexport for core-image-minimal
80 bitbake('core-image-minimal')
81 bitbake('-c testexport core-image-minimal')
82
83 needed_vars = ['TEST_EXPORT_DIR', 'TEST_EXPORT_SDK_DIR', 'TEST_EXPORT_SDK_NAME']
84 bb_vars = get_bb_vars(needed_vars, 'core-image-minimal')
85 testexport_dir = bb_vars['TEST_EXPORT_DIR']
86 sdk_dir = bb_vars['TEST_EXPORT_SDK_DIR']
87 sdk_name = bb_vars['TEST_EXPORT_SDK_NAME']
88
89 # Check for SDK
90 tarball_name = "%s.sh" % sdk_name
91 tarball_path = os.path.join(testexport_dir, sdk_dir, tarball_name)
92 msg = "Couldn't find SDK tarball: %s" % tarball_path
93 self.assertEqual(os.path.isfile(tarball_path), True, msg)
94
95 # Extract SDK and run tar from SDK
96 result = runCmd("%s -y -d /tmp/sdk" % tarball_path)
97 self.assertEqual(0, result.status, "Couldn't extract SDK")
98
99 env_script = result.output.split()[-1]
100 result = runCmd(". %s; which tar" % env_script, shell=True)
101 self.assertEqual(0, result.status, "Couldn't setup SDK environment")
102 is_sdk_tar = True if "/tmp/sdk" in result.output else False
103 self.assertTrue(is_sdk_tar, "Couldn't setup SDK environment")
104
105 tar_sdk = result.output
106 result = runCmd("%s --version" % tar_sdk)
107 self.assertEqual(0, result.status, "Couldn't run tar from SDK")
108
109
110class TestImage(OESelftestTestCase):
111
112 @OETestID(1644)
113 def test_testimage_install(self):
114 """
115 Summary: Check install packages functionality for testimage/testexport.
116 Expected: 1. Import tests from a directory other than meta.
117 2. Check install/uninstall of socat.
118 Product: oe-core
119 Author: Mariano Lopez <mariano.lopez@intel.com>
120 """
121 if get_bb_var('DISTRO') == 'poky-tiny':
122 self.skipTest('core-image-full-cmdline not buildable for poky-tiny')
123
124 features = 'INHERIT += "testimage"\n'
125 features += 'TEST_SUITES = "ping ssh selftest"\n'
126 self.write_config(features)
127
128 # Build core-image-sato and testimage
129 bitbake('core-image-full-cmdline socat')
130 bitbake('-c testimage core-image-full-cmdline')
131
132 @OETestID(1883)
133 def test_testimage_dnf(self):
134 """
135 Summary: Check package feeds functionality for dnf
136 Expected: 1. Check that remote package feeds can be accessed
137 Product: oe-core
138 Author: Alexander Kanavin <alexander.kanavin@intel.com>
139 """
140 if get_bb_var('DISTRO') == 'poky-tiny':
141 self.skipTest('core-image-full-cmdline not buildable for poky-tiny')
142
143 features = 'INHERIT += "testimage"\n'
144 features += 'TEST_SUITES = "ping ssh dnf_runtime dnf.DnfBasicTest.test_dnf_help"\n'
145 # We don't yet know what the server ip and port will be - they will be patched
146 # in at the start of the on-image test
147 features += 'PACKAGE_FEED_URIS = "http://bogus_ip:bogus_port"\n'
148 features += 'EXTRA_IMAGE_FEATURES += "package-management"\n'
149 features += 'PACKAGE_CLASSES = "package_rpm"\n'
150
Brad Bishop6f8dcde2018-10-16 10:47:12 +0800151 bitbake('gnupg-native -c addto_recipe_sysroot')
152
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500153 # Enable package feed signing
154 self.gpg_home = tempfile.mkdtemp(prefix="oeqa-feed-sign-")
155 signing_key_dir = os.path.join(self.testlayer_path, 'files', 'signing')
Brad Bishop6f8dcde2018-10-16 10:47:12 +0800156 runCmd('gpg --batch --homedir %s --import %s' % (self.gpg_home, os.path.join(signing_key_dir, 'key.secret')), native_sysroot=get_bb_var("RECIPE_SYSROOT_NATIVE", "gnupg-native"))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500157 features += 'INHERIT += "sign_package_feed"\n'
158 features += 'PACKAGE_FEED_GPG_NAME = "testuser"\n'
159 features += 'PACKAGE_FEED_GPG_PASSPHRASE_FILE = "%s"\n' % os.path.join(signing_key_dir, 'key.passphrase')
160 features += 'GPG_PATH = "%s"\n' % self.gpg_home
161 self.write_config(features)
162
163 # Build core-image-sato and testimage
164 bitbake('core-image-full-cmdline socat')
165 bitbake('-c testimage core-image-full-cmdline')
166
167 # remove the oeqa-feed-sign temporal directory
168 shutil.rmtree(self.gpg_home, ignore_errors=True)
169
170class Postinst(OESelftestTestCase):
171 @OETestID(1540)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500172 @OETestID(1545)
173 def test_postinst_rootfs_and_boot(self):
174 """
175 Summary: The purpose of this test case is to verify Post-installation
176 scripts are called when rootfs is created and also test
177 that script can be delayed to run at first boot.
178 Dependencies: NA
179 Steps: 1. Add proper configuration to local.conf file
180 2. Build a "core-image-minimal" image
181 3. Verify that file created by postinst_rootfs recipe is
182 present on rootfs dir.
183 4. Boot the image created on qemu and verify that the file
184 created by postinst_boot recipe is present on image.
185 Expected: The files are successfully created during rootfs and boot
186 time for 3 different package managers: rpm,ipk,deb and
187 for initialization managers: sysvinit and systemd.
188
189 """
Brad Bishop316dfdd2018-06-25 12:45:53 -0400190
191 import oe.path
192
193 vars = get_bb_vars(("IMAGE_ROOTFS", "sysconfdir"), "core-image-minimal")
194 rootfs = vars["IMAGE_ROOTFS"]
195 self.assertIsNotNone(rootfs)
196 sysconfdir = vars["sysconfdir"]
197 self.assertIsNotNone(sysconfdir)
198 # Need to use oe.path here as sysconfdir starts with /
199 hosttestdir = oe.path.join(rootfs, sysconfdir, "postinst-test")
200 targettestdir = os.path.join(sysconfdir, "postinst-test")
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500201
202 for init_manager in ("sysvinit", "systemd"):
203 for classes in ("package_rpm", "package_deb", "package_ipk"):
204 with self.subTest(init_manager=init_manager, package_class=classes):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400205 features = 'CORE_IMAGE_EXTRA_INSTALL = "postinst-delayed-b"\n'
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500206 features += 'IMAGE_FEATURES += "package-management empty-root-password"\n'
207 features += 'PACKAGE_CLASSES = "%s"\n' % classes
208 if init_manager == "systemd":
209 features += 'DISTRO_FEATURES_append = " systemd"\n'
210 features += 'VIRTUAL-RUNTIME_init_manager = "systemd"\n'
211 features += 'DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"\n'
212 features += 'VIRTUAL-RUNTIME_initscripts = ""\n'
213 self.write_config(features)
214
215 bitbake('core-image-minimal')
216
Brad Bishop316dfdd2018-06-25 12:45:53 -0400217 self.assertTrue(os.path.isfile(os.path.join(hosttestdir, "rootfs")),
218 "rootfs state file was not created")
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500219
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500220 with runqemu('core-image-minimal') as qemu:
Brad Bishop316dfdd2018-06-25 12:45:53 -0400221 # Make the test echo a string and search for that as
222 # run_serial()'s status code is useless.'
223 for filename in ("rootfs", "delayed-a", "delayed-b"):
224 status, output = qemu.run_serial("test -f %s && echo found" % os.path.join(targettestdir, filename))
225 self.assertEqual(output, "found", "%s was not present on boot" % filename)
226
227
228
229 def test_failing_postinst(self):
230 """
231 Summary: The purpose of this test case is to verify that post-installation
232 scripts that contain errors are properly reported.
233 Expected: The scriptlet failure is properly reported.
234 The file that is created after the error in the scriptlet is not present.
235 Product: oe-core
236 Author: Alexander Kanavin <alexander.kanavin@intel.com>
237 """
238
239 import oe.path
240
241 vars = get_bb_vars(("IMAGE_ROOTFS", "sysconfdir"), "core-image-minimal")
242 rootfs = vars["IMAGE_ROOTFS"]
243 self.assertIsNotNone(rootfs)
244 sysconfdir = vars["sysconfdir"]
245 self.assertIsNotNone(sysconfdir)
246 # Need to use oe.path here as sysconfdir starts with /
247 hosttestdir = oe.path.join(rootfs, sysconfdir, "postinst-test")
248
249 for classes in ("package_rpm", "package_deb", "package_ipk"):
250 with self.subTest(package_class=classes):
251 features = 'CORE_IMAGE_EXTRA_INSTALL = "postinst-rootfs-failing"\n'
252 features += 'PACKAGE_CLASSES = "%s"\n' % classes
253 self.write_config(features)
254 bb_result = bitbake('core-image-minimal')
255 self.assertGreaterEqual(bb_result.output.find("Intentionally failing postinstall scriptlets of ['postinst-rootfs-failing'] to defer them to first boot is deprecated."), 0,
256 "Warning about a failed scriptlet not found in bitbake output: %s" %(bb_result.output))
257
258 self.assertTrue(os.path.isfile(os.path.join(hosttestdir, "rootfs-before-failure")),
259 "rootfs-before-failure file was not created")
260 self.assertFalse(os.path.isfile(os.path.join(hosttestdir, "rootfs-after-failure")),
261 "rootfs-after-failure file was created")
262