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 /meta/lib/oeqa | |
| 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>
Diffstat (limited to 'meta/lib/oeqa')
| -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 |
4 files changed, 59 insertions, 18 deletions
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, '/') |
