diff options
author | Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com> | 2020-04-19 08:35:34 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2021-02-10 23:55:53 +0000 |
commit | 6c7a7d371fc44f5b6bec6a8769a422fece88ec76 (patch) | |
tree | 9ab361d0abc2e29332bacee22b2652e7edddf451 /meta/lib/oeqa/selftest/cases | |
parent | af11b386facccae152f4455dc4f9f6f329d4df06 (diff) | |
download | poky-6c7a7d371fc44f5b6bec6a8769a422fece88ec76.tar.gz |
oeqa: wic: Add tests for permissions and change-directory
Make sure that the permissions and username are respected when using all
the rootfs modifiers.
Add tests for change-directory command
Cc: Paul Barker <pbarker@konsulko.com>
(From OE-Core rev: 5a3ce870ff54e73543caba5899aabd6c872691b0)
Signed-off-by: Ricardo Ribalda Delgado <ricardo@ribalda.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
(cherry picked from commit 4aad9531df44d1b0637bd559161702ad86861b46)
Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/selftest/cases')
-rw-r--r-- | meta/lib/oeqa/selftest/cases/wic.py | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/meta/lib/oeqa/selftest/cases/wic.py b/meta/lib/oeqa/selftest/cases/wic.py index 13b6a0cc72..d4c0db8bda 100644 --- a/meta/lib/oeqa/selftest/cases/wic.py +++ b/meta/lib/oeqa/selftest/cases/wic.py | |||
@@ -62,6 +62,12 @@ def extract_files(debugfs_output): | |||
62 | return [line.split('/')[5].strip() for line in \ | 62 | return [line.split('/')[5].strip() for line in \ |
63 | debugfs_output.strip().split('/\n')] | 63 | debugfs_output.strip().split('/\n')] |
64 | 64 | ||
65 | def files_own_by_root(debugfs_output): | ||
66 | for line in debugfs_output.strip().split('/\n'): | ||
67 | if line.split('/')[3:5] != ['0', '0']: | ||
68 | print(debugfs_output) | ||
69 | return False | ||
70 | return True | ||
65 | 71 | ||
66 | class WicTestCase(OESelftestTestCase): | 72 | class WicTestCase(OESelftestTestCase): |
67 | """Wic test class.""" | 73 | """Wic test class.""" |
@@ -84,6 +90,7 @@ class WicTestCase(OESelftestTestCase): | |||
84 | self.skipTest('wic-tools cannot be built due its (intltool|gettext)-native dependency and NLS disable') | 90 | self.skipTest('wic-tools cannot be built due its (intltool|gettext)-native dependency and NLS disable') |
85 | 91 | ||
86 | bitbake('core-image-minimal') | 92 | bitbake('core-image-minimal') |
93 | bitbake('core-image-minimal-mtdutils') | ||
87 | WicTestCase.image_is_ready = True | 94 | WicTestCase.image_is_ready = True |
88 | 95 | ||
89 | rmtree(self.resultdir, ignore_errors=True) | 96 | rmtree(self.resultdir, ignore_errors=True) |
@@ -506,6 +513,89 @@ part /part2 --source rootfs --ondisk mmcblk0 --fstype=ext4 --include-path %s""" | |||
506 | % (wks_file, self.resultdir), ignore_status=True).status) | 513 | % (wks_file, self.resultdir), ignore_status=True).status) |
507 | os.remove(wks_file) | 514 | os.remove(wks_file) |
508 | 515 | ||
516 | def test_permissions(self): | ||
517 | """Test permissions are respected""" | ||
518 | |||
519 | oldpath = os.environ['PATH'] | ||
520 | os.environ['PATH'] = get_bb_var("PATH", "wic-tools") | ||
521 | |||
522 | t_normal = """ | ||
523 | part / --source rootfs --fstype=ext4 | ||
524 | """ | ||
525 | t_exclude = """ | ||
526 | part / --source rootfs --fstype=ext4 --exclude-path=home | ||
527 | """ | ||
528 | t_multi = """ | ||
529 | part / --source rootfs --ondisk sda --fstype=ext4 | ||
530 | part /export --source rootfs --rootfs=core-image-minimal-mtdutils --fstype=ext4 | ||
531 | """ | ||
532 | t_change = """ | ||
533 | part / --source rootfs --ondisk sda --fstype=ext4 --exclude-path=etc/ | ||
534 | part /etc --source rootfs --fstype=ext4 --change-directory=etc | ||
535 | """ | ||
536 | tests = [t_normal, t_exclude, t_multi, t_change] | ||
537 | |||
538 | try: | ||
539 | for test in tests: | ||
540 | include_path = os.path.join(self.resultdir, 'test-include') | ||
541 | os.makedirs(include_path) | ||
542 | wks_file = os.path.join(include_path, 'temp.wks') | ||
543 | with open(wks_file, 'w') as wks: | ||
544 | wks.write(test) | ||
545 | runCmd("wic create %s -e core-image-minimal -o %s" \ | ||
546 | % (wks_file, self.resultdir)) | ||
547 | |||
548 | for part in glob(os.path.join(self.resultdir, 'temp-*.direct.p*')): | ||
549 | res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % (part)) | ||
550 | self.assertEqual(True, files_own_by_root(res.output)) | ||
551 | |||
552 | rmtree(self.resultdir, ignore_errors=True) | ||
553 | |||
554 | finally: | ||
555 | os.environ['PATH'] = oldpath | ||
556 | |||
557 | def test_change_directory(self): | ||
558 | """Test --change-directory wks option.""" | ||
559 | |||
560 | oldpath = os.environ['PATH'] | ||
561 | os.environ['PATH'] = get_bb_var("PATH", "wic-tools") | ||
562 | |||
563 | try: | ||
564 | include_path = os.path.join(self.resultdir, 'test-include') | ||
565 | os.makedirs(include_path) | ||
566 | wks_file = os.path.join(include_path, 'temp.wks') | ||
567 | with open(wks_file, 'w') as wks: | ||
568 | wks.write("part /etc --source rootfs --fstype=ext4 --change-directory=etc") | ||
569 | runCmd("wic create %s -e core-image-minimal -o %s" \ | ||
570 | % (wks_file, self.resultdir)) | ||
571 | |||
572 | part1 = glob(os.path.join(self.resultdir, 'temp-*.direct.p1'))[0] | ||
573 | |||
574 | res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % (part1)) | ||
575 | files = extract_files(res.output) | ||
576 | self.assertIn('passwd', files) | ||
577 | |||
578 | finally: | ||
579 | os.environ['PATH'] = oldpath | ||
580 | |||
581 | def test_change_directory_errors(self): | ||
582 | """Test --change-directory wks option error handling.""" | ||
583 | wks_file = 'temp.wks' | ||
584 | |||
585 | # Absolute argument. | ||
586 | with open(wks_file, 'w') as wks: | ||
587 | wks.write("part / --source rootfs --fstype=ext4 --change-directory /usr") | ||
588 | self.assertNotEqual(0, runCmd("wic create %s -e core-image-minimal -o %s" \ | ||
589 | % (wks_file, self.resultdir), ignore_status=True).status) | ||
590 | os.remove(wks_file) | ||
591 | |||
592 | # Argument pointing to parent directory. | ||
593 | with open(wks_file, 'w') as wks: | ||
594 | wks.write("part / --source rootfs --fstype=ext4 --change-directory ././..") | ||
595 | self.assertNotEqual(0, runCmd("wic create %s -e core-image-minimal -o %s" \ | ||
596 | % (wks_file, self.resultdir), ignore_status=True).status) | ||
597 | os.remove(wks_file) | ||
598 | |||
509 | class Wic2(WicTestCase): | 599 | class Wic2(WicTestCase): |
510 | 600 | ||
511 | def test_bmap_short(self): | 601 | def test_bmap_short(self): |