All of lore.kernel.org
 help / color / mirror / Atom feed
From: Randy Witt <randy.e.witt@linux.intel.com>
To: openembedded-core@lists.openembedded.org
Subject: [PATCH] selftest/containerimage.py: Add container IMAGE_FSTYPES test
Date: Thu, 19 Jan 2017 13:52:36 -0800	[thread overview]
Message-ID: <20170119215236.11012-1-randy.e.witt@linux.intel.com> (raw)
In-Reply-To: <cc6a7fcca781a3a153ba5cfbfe7a45282a55f917.1484764234.git.randy.e.witt@linux.intel.com>

This test checks to make sure only the files expected exist in a
container image. Currently only ROOTFS_BOOTSTRAP_INSTALL, gets added to
all images without the user specifying it.

But this test should help if a developer in the future ever silently
adds more than just ROOTFS_BOOTSTRAP_INSTALL, and that the developer can
make sure it also gets removed from a container image.

[YOCTO #9502]

Signed-off-by: Randy Witt <randy.e.witt@linux.intel.com>
---
 .../container-image/container-image-testpkg.bb     |  8 +++
 .../container-image/container-test-image.bb        |  8 +++
 meta/lib/oeqa/selftest/containerimage.py           | 82 ++++++++++++++++++++++
 3 files changed, 98 insertions(+)
 create mode 100644 meta-selftest/recipes-test/container-image/container-image-testpkg.bb
 create mode 100644 meta-selftest/recipes-test/container-image/container-test-image.bb
 create mode 100644 meta/lib/oeqa/selftest/containerimage.py

diff --git a/meta-selftest/recipes-test/container-image/container-image-testpkg.bb b/meta-selftest/recipes-test/container-image/container-image-testpkg.bb
new file mode 100644
index 0000000..f8dd229
--- /dev/null
+++ b/meta-selftest/recipes-test/container-image/container-image-testpkg.bb
@@ -0,0 +1,8 @@
+LICENSE = "MIT"
+
+INHIBIT_DEFAULT_DEPS = "1"
+
+do_install_append() {
+    install -d ${D}${bindir}
+    touch ${D}${bindir}/theapp
+}
diff --git a/meta-selftest/recipes-test/container-image/container-test-image.bb b/meta-selftest/recipes-test/container-image/container-test-image.bb
new file mode 100644
index 0000000..d5f939c
--- /dev/null
+++ b/meta-selftest/recipes-test/container-image/container-test-image.bb
@@ -0,0 +1,8 @@
+IMAGE_INSTALL += "container-image-testpkg"
+
+LICENSE = "MIT"
+
+IMAGE_FSTYPES = "container"
+IMAGE_LINGUAS = ""
+
+inherit core-image
diff --git a/meta/lib/oeqa/selftest/containerimage.py b/meta/lib/oeqa/selftest/containerimage.py
new file mode 100644
index 0000000..6a85222
--- /dev/null
+++ b/meta/lib/oeqa/selftest/containerimage.py
@@ -0,0 +1,82 @@
+import os
+
+from oeqa.selftest.base import oeSelfTest
+from oeqa.utils.commands import bitbake, get_bb_vars, runCmd
+
+# This test builds an image with using the "container" IMAGE_FSTYPE, and
+# ensures that then files in the image are only the ones expected.
+#
+# The only package added to the image is container_image_testpkg, which
+# contains one file. However, due to some other things not cleaning up during
+# rootfs creation, there is some cruft. Ideally bugs will be filed and the
+# cruft removed, but for now we whitelist some known set.
+#
+# Also for performance reasons we're only checking the cruft when using ipk.
+# When using deb, and rpm it is a bit different and we could test all
+# of them, but this test is more to catch if other packages get added by
+# default other than what is in ROOTFS_BOOTSTRAP_INSTALL.
+#
+class ContainerImageTests(oeSelfTest):
+
+    # Verify that when specifying a IMAGE_TYPEDEP_ of the form "foo.bar" that
+    # the conversion type bar gets added as a dep as well
+    def test_expected_files(self):
+
+        def get_each_path_part(path):
+            if path:
+                part = [ '.' + path + '/' ]
+                result = get_each_path_part(path.rsplit('/', 1)[0])
+                if result:
+                    return part + result
+                else:
+                    return part
+            else:
+                return None
+
+        bbvars = get_bb_vars(['bindir', 'sysconfdir', 'localstatedir',
+                              'DEPLOY_DIR_IMAGE'])
+        expected_files = [
+                    './',
+                    '.{bindir}/theapp',
+                    '.{sysconfdir}/default/',
+                    '.{sysconfdir}/default/postinst',
+                    '.{sysconfdir}/ld.so.cache',
+                    '.{sysconfdir}/timestamp',
+                    '.{sysconfdir}/version',
+                    './run/',
+                    '.{localstatedir}/cache/',
+                    '.{localstatedir}/cache/ldconfig/',
+                    '.{localstatedir}/cache/ldconfig/aux-cache',
+                    '.{localstatedir}/cache/opkg/',
+                    '.{localstatedir}/lib/',
+                    '.{localstatedir}/lib/opkg/'
+                ]
+
+        expected_files = [ x.format(bindir=bbvars['bindir'],
+                                    sysconfdir=bbvars['sysconfdir'],
+                                    localstatedir=bbvars['localstatedir'])
+                                    for x in expected_files ]
+
+        # Since tar lists all directories individually, make sure each element
+        # from bindir, sysconfdir, etc is added
+        expected_files += get_each_path_part(bbvars['bindir'])
+        expected_files += get_each_path_part(bbvars['sysconfdir'])
+        expected_files += get_each_path_part(bbvars['localstatedir'])
+
+        expected_files = sorted(expected_files)
+
+
+        self.write_config('PREFERRED_PROVIDER_virtual/kernel = "linux-dummy"')
+        self.append_config('MACHINE = "qemux86"')
+        self.append_config('IMAGE_FSTYPES = "container"')
+        self.append_config('PACKAGE_CLASSES = "package_ipk"')
+
+        # Build the image of course
+        bitbake('container-test-image')
+
+        image = os.path.join(bbvars['DEPLOY_DIR_IMAGE'],
+                             'container-test-image-qemux86.tar.bz2')
+
+        # Ensure the files in the image are what we expect
+        result = runCmd("tar tf {} | sort".format(image), shell=True)
+        self.assertEqual(result.output.split('\n'), expected_files)
-- 
2.9.3



      parent reply	other threads:[~2017-01-19 21:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-18 18:31 [PATCH 0/3] Add initial container IMAGE_FSTYPES support Randy Witt
2017-01-18 18:31 ` [PATCH 1/3] image-container.bbclass: Add the "container" IMAGE_FSTYPES Randy Witt
2017-01-18 18:31 ` [PATCH 2/3] image-container.bbclass: Error if not using linux-dummy Randy Witt
2017-01-18 18:31 ` [PATCH 3/3] selftest/containerimage.py: Add container IMAGE_FSTYPES test Randy Witt
2017-01-19 12:01   ` Burton, Ross
2017-01-19 22:50     ` Randy Witt
2017-01-19 21:52   ` Randy Witt [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170119215236.11012-1-randy.e.witt@linux.intel.com \
    --to=randy.e.witt@linux.intel.com \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.