diff options
author | Mariano Lopez <mariano.lopez@linux.intel.com> | 2017-01-13 10:47:53 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-01-23 12:05:20 +0000 |
commit | 58789be270c903bf75c1946a4c626b37a5bcdc72 (patch) | |
tree | db84f05a6ab1fdeac5cdd1224558216e562f35d6 | |
parent | f8d7db1905902c048d22c86ecddd1be98419bbaf (diff) | |
download | poky-58789be270c903bf75c1946a4c626b37a5bcdc72.tar.gz |
testimage.bbclass: Add package install feature
This allows to use the package install feature with
the new OEQA framework.
[YOCTO #10234]
(From OE-Core rev: 077dc19445574457769eb4f231de97e8059cb75e)
Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta/classes/testimage.bbclass | 27 | ||||
-rw-r--r-- | meta/lib/oeqa/core/utils/test.py | 10 | ||||
-rw-r--r-- | meta/lib/oeqa/runtime/case.py | 9 | ||||
-rw-r--r-- | meta/lib/oeqa/runtime/context.py | 12 | ||||
-rw-r--r-- | meta/lib/oeqa/utils/package_manager.py | 46 |
5 files changed, 69 insertions, 35 deletions
diff --git a/meta/classes/testimage.bbclass b/meta/classes/testimage.bbclass index 1dfbc490de..96e41c6c87 100644 --- a/meta/classes/testimage.bbclass +++ b/meta/classes/testimage.bbclass | |||
@@ -159,7 +159,6 @@ def testimage_main(d): | |||
159 | pn = d.getVar("PN") | 159 | pn = d.getVar("PN") |
160 | 160 | ||
161 | bb.utils.mkdirhier(d.getVar("TEST_LOG_DIR")) | 161 | bb.utils.mkdirhier(d.getVar("TEST_LOG_DIR")) |
162 | #test_create_extract_dirs(d) | ||
163 | 162 | ||
164 | image_name = ("%s/%s" % (d.getVar('DEPLOY_DIR_IMAGE'), | 163 | image_name = ("%s/%s" % (d.getVar('DEPLOY_DIR_IMAGE'), |
165 | d.getVar('IMAGE_LINK_NAME'))) | 164 | d.getVar('IMAGE_LINK_NAME'))) |
@@ -170,6 +169,8 @@ def testimage_main(d): | |||
170 | image_manifest = "%s.manifest" % image_name | 169 | image_manifest = "%s.manifest" % image_name |
171 | image_packages = OERuntimeTestContextExecutor.readPackagesManifest(image_manifest) | 170 | image_packages = OERuntimeTestContextExecutor.readPackagesManifest(image_manifest) |
172 | 171 | ||
172 | extract_dir = d.getVar("TEST_EXTRACTED_DIR") | ||
173 | |||
173 | # Get machine | 174 | # Get machine |
174 | machine = d.getVar("MACHINE") | 175 | machine = d.getVar("MACHINE") |
175 | 176 | ||
@@ -236,7 +237,8 @@ def testimage_main(d): | |||
236 | d.getVar("TEST_SERVER_IP"), **target_kwargs) | 237 | d.getVar("TEST_SERVER_IP"), **target_kwargs) |
237 | 238 | ||
238 | # test context | 239 | # test context |
239 | tc = OERuntimeTestContext(td, logger, target, host_dumper, image_packages) | 240 | tc = OERuntimeTestContext(td, logger, target, host_dumper, |
241 | image_packages, extract_dir) | ||
240 | 242 | ||
241 | # Load tests before starting the target | 243 | # Load tests before starting the target |
242 | test_paths = get_runtime_paths(d) | 244 | test_paths = get_runtime_paths(d) |
@@ -343,22 +345,13 @@ def package_extraction(d, test_suites): | |||
343 | from oeqa.utils.package_manager import find_packages_to_extract | 345 | from oeqa.utils.package_manager import find_packages_to_extract |
344 | from oeqa.utils.package_manager import extract_packages | 346 | from oeqa.utils.package_manager import extract_packages |
345 | 347 | ||
346 | test_create_extract_dirs(d) | 348 | bb.utils.remove(d.getVar("TEST_NEEDED_PACKAGES_DIR"), recurse=True) |
347 | packages = find_packages_to_extract(test_suites) | 349 | packages = find_packages_to_extract(test_suites) |
348 | extract_packages(d, packages) | 350 | if packages: |
349 | 351 | bb.utils.mkdirhier(d.getVar("TEST_INSTALL_TMP_DIR")) | |
350 | def test_create_extract_dirs(d): | 352 | bb.utils.mkdirhier(d.getVar("TEST_PACKAGED_DIR")) |
351 | install_path = d.getVar("TEST_INSTALL_TMP_DIR") | 353 | bb.utils.mkdirhier(d.getVar("TEST_EXTRACTED_DIR")) |
352 | package_path = d.getVar("TEST_PACKAGED_DIR") | 354 | extract_packages(d, packages) |
353 | extracted_path = d.getVar("TEST_EXTRACTED_DIR") | ||
354 | bb.utils.mkdirhier(d.getVar("TEST_LOG_DIR")) | ||
355 | bb.utils.remove(install_path, recurse=True) | ||
356 | bb.utils.remove(package_path, recurse=True) | ||
357 | bb.utils.remove(extracted_path, recurse=True) | ||
358 | bb.utils.mkdirhier(install_path) | ||
359 | bb.utils.mkdirhier(package_path) | ||
360 | bb.utils.mkdirhier(extracted_path) | ||
361 | |||
362 | 355 | ||
363 | testimage_main[vardepsexclude] += "BB_ORIGENV DATETIME" | 356 | testimage_main[vardepsexclude] += "BB_ORIGENV DATETIME" |
364 | 357 | ||
diff --git a/meta/lib/oeqa/core/utils/test.py b/meta/lib/oeqa/core/utils/test.py index 88d176552e..88d5d13981 100644 --- a/meta/lib/oeqa/core/utils/test.py +++ b/meta/lib/oeqa/core/utils/test.py | |||
@@ -10,11 +10,13 @@ def getSuiteCases(suite): | |||
10 | Returns individual test from a test suite. | 10 | Returns individual test from a test suite. |
11 | """ | 11 | """ |
12 | tests = [] | 12 | tests = [] |
13 | for item in suite: | 13 | |
14 | if isinstance(item, unittest.suite.TestSuite): | 14 | if isinstance(suite, unittest.TestCase): |
15 | tests.append(suite) | ||
16 | elif isinstance(suite, unittest.suite.TestSuite): | ||
17 | for item in suite: | ||
15 | tests.extend(getSuiteCases(item)) | 18 | tests.extend(getSuiteCases(item)) |
16 | elif isinstance(item, unittest.TestCase): | 19 | |
17 | tests.append(item) | ||
18 | return tests | 20 | return tests |
19 | 21 | ||
20 | def getSuiteModules(suite): | 22 | def getSuiteModules(suite): |
diff --git a/meta/lib/oeqa/runtime/case.py b/meta/lib/oeqa/runtime/case.py index 43f1b2f425..c1485c9860 100644 --- a/meta/lib/oeqa/runtime/case.py +++ b/meta/lib/oeqa/runtime/case.py | |||
@@ -2,7 +2,16 @@ | |||
2 | # Released under the MIT license (see COPYING.MIT) | 2 | # Released under the MIT license (see COPYING.MIT) |
3 | 3 | ||
4 | from oeqa.core.case import OETestCase | 4 | from oeqa.core.case import OETestCase |
5 | from oeqa.utils.package_manager import install_package, uninstall_package | ||
5 | 6 | ||
6 | class OERuntimeTestCase(OETestCase): | 7 | class OERuntimeTestCase(OETestCase): |
7 | # target instance set by OERuntimeTestLoader. | 8 | # target instance set by OERuntimeTestLoader. |
8 | target = None | 9 | target = None |
10 | |||
11 | def _oeSetUp(self): | ||
12 | super(OERuntimeTestCase, self)._oeSetUp() | ||
13 | install_package(self) | ||
14 | |||
15 | def _oeTearDown(self): | ||
16 | super(OERuntimeTestCase, self)._oeTearDown() | ||
17 | uninstall_package(self) | ||
diff --git a/meta/lib/oeqa/runtime/context.py b/meta/lib/oeqa/runtime/context.py index bc8abd0c4e..10b8b54809 100644 --- a/meta/lib/oeqa/runtime/context.py +++ b/meta/lib/oeqa/runtime/context.py | |||
@@ -15,12 +15,14 @@ class OERuntimeTestContext(OETestContext): | |||
15 | runtime_files_dir = os.path.join( | 15 | runtime_files_dir = os.path.join( |
16 | os.path.dirname(os.path.abspath(__file__)), "files") | 16 | os.path.dirname(os.path.abspath(__file__)), "files") |
17 | 17 | ||
18 | def __init__(self, td, logger, target, host_dumper, image_packages): | 18 | def __init__(self, td, logger, target, |
19 | host_dumper, image_packages, extract_dir): | ||
19 | super(OERuntimeTestContext, self).__init__(td, logger) | 20 | super(OERuntimeTestContext, self).__init__(td, logger) |
20 | 21 | ||
21 | self.target = target | 22 | self.target = target |
22 | self.image_packages = image_packages | 23 | self.image_packages = image_packages |
23 | self.host_dumper = host_dumper | 24 | self.host_dumper = host_dumper |
25 | self.extract_dir = extract_dir | ||
24 | self._set_target_cmds() | 26 | self._set_target_cmds() |
25 | 27 | ||
26 | def _set_target_cmds(self): | 28 | def _set_target_cmds(self): |
@@ -45,6 +47,7 @@ class OERuntimeTestContextExecutor(OETestContextExecutor): | |||
45 | default_server_ip = '192.168.7.1' | 47 | default_server_ip = '192.168.7.1' |
46 | default_target_ip = '192.168.7.2' | 48 | default_target_ip = '192.168.7.2' |
47 | default_host_dumper_dir = '/tmp/oe-saved-tests' | 49 | default_host_dumper_dir = '/tmp/oe-saved-tests' |
50 | default_extract_dir = 'extract_dir' | ||
48 | 51 | ||
49 | def register_commands(self, logger, subparsers): | 52 | def register_commands(self, logger, subparsers): |
50 | super(OERuntimeTestContextExecutor, self).register_commands(logger, subparsers) | 53 | super(OERuntimeTestContextExecutor, self).register_commands(logger, subparsers) |
@@ -72,6 +75,9 @@ class OERuntimeTestContextExecutor(OETestContextExecutor): | |||
72 | runtime_group.add_argument('--packages-manifest', action='store', | 75 | runtime_group.add_argument('--packages-manifest', action='store', |
73 | help="Package manifest of the image under test") | 76 | help="Package manifest of the image under test") |
74 | 77 | ||
78 | runtime_group.add_argument('--extract-dir', action='store', | ||
79 | help='Directory where extracted packages reside') | ||
80 | |||
75 | runtime_group.add_argument('--qemu-boot', action='store', | 81 | runtime_group.add_argument('--qemu-boot', action='store', |
76 | help="Qemu boot configuration, only needed when target_type is QEMU.") | 82 | help="Qemu boot configuration, only needed when target_type is QEMU.") |
77 | 83 | ||
@@ -126,4 +132,8 @@ class OERuntimeTestContextExecutor(OETestContextExecutor): | |||
126 | OERuntimeTestContextExecutor.readPackagesManifest( | 132 | OERuntimeTestContextExecutor.readPackagesManifest( |
127 | args.packages_manifest) | 133 | args.packages_manifest) |
128 | 134 | ||
135 | self.tc_kwargs['init']['extract_dir'] = \ | ||
136 | OERuntimeTestContextExecutor.readPackagesManifest( | ||
137 | args.extract_dir) | ||
138 | |||
129 | _executor_class = OERuntimeTestContextExecutor | 139 | _executor_class = OERuntimeTestContextExecutor |
diff --git a/meta/lib/oeqa/utils/package_manager.py b/meta/lib/oeqa/utils/package_manager.py index ab0d3e5564..92646488da 100644 --- a/meta/lib/oeqa/utils/package_manager.py +++ b/meta/lib/oeqa/utils/package_manager.py | |||
@@ -1,7 +1,8 @@ | |||
1 | import bb | 1 | import os |
2 | import json | 2 | import json |
3 | import shutil | 3 | import shutil |
4 | 4 | ||
5 | from oeqa.core.utils.test import getCaseFile, getCaseMethod | ||
5 | 6 | ||
6 | def get_package_manager(d, root_path): | 7 | def get_package_manager(d, root_path): |
7 | """ | 8 | """ |
@@ -86,6 +87,7 @@ def extract_packages(d, needed_packages): | |||
86 | Extract packages that will be needed during runtime. | 87 | Extract packages that will be needed during runtime. |
87 | """ | 88 | """ |
88 | 89 | ||
90 | import bb | ||
89 | import oe.path | 91 | import oe.path |
90 | 92 | ||
91 | extracted_path = d.getVar('TEST_EXTRACTED_DIR') | 93 | extracted_path = d.getVar('TEST_EXTRACTED_DIR') |
@@ -152,20 +154,38 @@ def _copy_package(d, pkg): | |||
152 | shutil.copy2(file_path, dst_dir) | 154 | shutil.copy2(file_path, dst_dir) |
153 | shutil.rmtree(pkg_path) | 155 | shutil.rmtree(pkg_path) |
154 | 156 | ||
155 | def install_uninstall_packages(self, test_id, pkg_dir, install): | 157 | def install_package(test_case): |
156 | """ | 158 | """ |
157 | Check if the test requires a package and Install/Unistall it in the DUT | 159 | Installs package in DUT if required. |
158 | """ | 160 | """ |
161 | needed_packages = test_needs_package(test_case) | ||
162 | if needed_packages: | ||
163 | _install_uninstall_packages(needed_packages, test_case, True) | ||
159 | 164 | ||
160 | test = test_id.split('.')[4] | 165 | def uninstall_package(test_case): |
161 | module = self.getModulefromID(test_id) | 166 | """ |
162 | json = self._getJsonFile(module) | 167 | Uninstalls package in DUT if required. |
163 | if json: | 168 | """ |
164 | needed_packages = self._getNeededPackages(json, test) | 169 | needed_packages = test_needs_package(test_case) |
170 | if needed_packages: | ||
171 | _install_uninstall_packages(needed_packages, test_case, False) | ||
172 | |||
173 | def test_needs_package(test_case): | ||
174 | """ | ||
175 | Checks if a test case requires to install/uninstall packages. | ||
176 | """ | ||
177 | test_file = getCaseFile(test_case) | ||
178 | json_file = _get_json_file(test_file) | ||
179 | |||
180 | if json_file: | ||
181 | test_method = getCaseMethod(test_case) | ||
182 | needed_packages = _get_needed_packages(json_file, test_method) | ||
165 | if needed_packages: | 183 | if needed_packages: |
166 | self._install_uninstall_packages(needed_packages, pkg_dir, install) | 184 | return needed_packages |
185 | |||
186 | return None | ||
167 | 187 | ||
168 | def _install_uninstall_packages(self, needed_packages, pkg_dir, install=True): | 188 | def _install_uninstall_packages(needed_packages, test_case, install=True): |
169 | """ | 189 | """ |
170 | Install/Unistall packages in the DUT without using a package manager | 190 | Install/Unistall packages in the DUT without using a package manager |
171 | """ | 191 | """ |
@@ -179,12 +199,12 @@ def _install_uninstall_packages(self, needed_packages, pkg_dir, install=True): | |||
179 | pkg = package['pkg'] | 199 | pkg = package['pkg'] |
180 | rm = package.get('rm', False) | 200 | rm = package.get('rm', False) |
181 | extract = package.get('extract', True) | 201 | extract = package.get('extract', True) |
182 | src_dir = os.path.join(pkg_dir, pkg) | 202 | src_dir = os.path.join(test_case.tc.extract_dir, pkg) |
183 | 203 | ||
184 | # Install package | 204 | # Install package |
185 | if install and extract: | 205 | if install and extract: |
186 | self.target.connection.copy_dir_to(src_dir, '/') | 206 | test_case.tc.target.copyDirTo(src_dir, '/') |
187 | 207 | ||
188 | # Unistall package | 208 | # Unistall package |
189 | elif not install and rm: | 209 | elif not install and rm: |
190 | self.target.connection.delete_dir_structure(src_dir, '/') | 210 | test_case.tc.target.deleteDirStructure(src_dir, '/') |