Skip to contentSkip to conversation

Fix for #10783 wic should not be writing out to /var/tmp/wic

PATCH New Ed Bartosh 1 participant 9 messages Jan 24, 2017

lore
Share & tools
lore

Ed Bartosh

author
#0 lore raw

cover Fix for #10783 wic should not be writing out to /var/tmp/wic

Hi,

This patchset changes default output location for wic images from /var/tmp/wic/build to the current directory. It also includes a bit of refactoring of DirectImageCreator class.

The following changes since commit 62d7d4130202d8ede16abf9e7d779361ca70847e:

build-appliance-image: Update to master head revision (2017-01-23 23:32:23 +0000)

are available in the git repository at:

git://git.yoctoproject.org/poky-contrib ed/wic/default-output-dir-10783
http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=ed/wic/default-output-dir-10783

Ed Bartosh (8):
wic: change default output directory
wic: get rid of baseimager inheritance
wic: make workdir a temporary directory
wic: remove unused API DirectImageCreator.get_disk_names
wic: direct.py: get rid of names with two underscores
image_types: use correct output directory
selftest: wic: explicitly specify output directory
selftest: wic: test default output directory

 meta/classes/image_types.bbclass     |   2 +-
 meta/lib/oeqa/selftest/wic.py        |  94 ++++++++---------
 scripts/lib/wic/imager/baseimager.py | 191 -----------------------------------
 scripts/lib/wic/imager/direct.py     | 108 +++++++++-----------
 scripts/wic                          |   2 +-
 5 files changed, 96 insertions(+), 301 deletions(-)
 delete mode 100644 scripts/lib/wic/imager/baseimager.py

--
Regards,
Ed

author
#1 lore raw

PATCH 1/8 wic: change default output directory

Set default output directory to current dir.

[YOCTO #10783]

---
 scripts/wic | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/wic +1 -1
index 8918cb4..54cbe96 100755
@@ -88,7 +88,7 @@ def wic_create_subcommand(args, usage_str):
     """
     parser = optparse.OptionParser(usage=usage_str)
 
-    parser.add_option("-o", "--outdir", dest="outdir",
+    parser.add_option("-o", "--outdir", dest="outdir", default='.',
                       help="name of directory to create image in")
     parser.add_option("-e", "--image-name", dest="image_name",
                       help="name of the image to use the artifacts from "
Signature · 1 line
2.1.4
author
#2 lore raw

PATCH 2/8 wic: get rid of baseimager inheritance

In reply to Ed Bartosh

Simplified DirectImageCreator code by removing inheritance from BaseImageCreator. This inheritance doesn't make much sense as DirectImageCreator is the only class that was inherited from BaseImageCreator.

---
 scripts/lib/wic/imager/baseimager.py | 191 -----------------------------------
 scripts/lib/wic/imager/direct.py     |  19 ++--
 2 files changed, 13 insertions(+), 197 deletions(-)
 delete mode 100644 scripts/lib/wic/imager/baseimager.py
scripts/lib/wic/imager/baseimager.py deleted +0 -191
deleted file mode 100644
index 1a52dd8..0000000
@@ -1,191 +0,0 @@
-#!/usr/bin/env python -tt
-#
-# Copyright (c) 2007 Red Hat  Inc.
-# Copyright (c) 2009, 2010, 2011 Intel, Inc.
-#
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by the Free
-# Software Foundation; version 2 of the License
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program; if not, write to the Free Software Foundation, Inc., 59
-# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-import os
-import tempfile
-import shutil
-
-from wic import msger
-from wic.utils.errors import CreatorError
-from wic.utils import runner
-
-class BaseImageCreator():
-    """Base class for image creation.
-
-    BaseImageCreator is the simplest creator class available; it will
-    create a system image according to the supplied kickstart file.
-
-    e.g.
-
-      import wic.imgcreate as imgcreate
-      ks = imgcreate.read_kickstart("foo.ks")
-      imgcreate.ImageCreator(ks, "foo").create()
-    """
-
-    def __del__(self):
-        self.cleanup()
-
-    def __init__(self, createopts=None):
-        """Initialize an ImageCreator instance.
-
-        ks -- a pykickstart.KickstartParser instance; this instance will be
-              used to drive the install by e.g. providing the list of packages
-              to be installed, the system configuration and %post scripts
-
-        name -- a name for the image; used for e.g. image filenames or
-                filesystem labels
-        """
-
-        self.__builddir = None
-
-        self.ks = None
-        self.name = "target"
-        self.tmpdir = "/var/tmp/wic"
-        self.workdir = "/var/tmp/wic/build"
-
-        # setup tmpfs tmpdir when enabletmpfs is True
-        self.enabletmpfs = False
-
-        if createopts:
-            # Mapping table for variables that have different names.
-            optmap = {"outdir" : "destdir",
-                     }
-
-            # update setting from createopts
-            for key in createopts:
-                if key in optmap:
-                    option = optmap[key]
-                else:
-                    option = key
-                setattr(self, option, createopts[key])
-
-            self.destdir = os.path.abspath(os.path.expanduser(self.destdir))
-
-        self._dep_checks = ["ls", "bash", "cp", "echo"]
-
-        # Output image file names
-        self.outimage = []
-
-        # No ks provided when called by convertor, so skip the dependency check
-        if self.ks:
-            # If we have btrfs partition we need to check necessary tools
-            for part in self.ks.partitions:
-                if part.fstype and part.fstype == "btrfs":
-                    self._dep_checks.append("mkfs.btrfs")
-                    break
-
-        # make sure the specified tmpdir and cachedir exist
-        if not os.path.exists(self.tmpdir):
-            os.makedirs(self.tmpdir)
-
-
-    #
-    # Hooks for subclasses
-    #
-    def _create(self):
-        """Create partitions for the disk image(s)
-
-        This is the hook where subclasses may create the partitions
-        that will be assembled into disk image(s).
-
-        There is no default implementation.
-        """
-        pass
-
-    def _cleanup(self):
-        """Undo anything performed in _create().
-
-        This is the hook where subclasses must undo anything which was
-        done in _create().
-
-        There is no default implementation.
-
-        """
-        pass
-
-    #
-    # Actual implementation
-    #
-    def __ensure_builddir(self):
-        if not self.__builddir is None:
-            return
-
-        try:
-            self.workdir = os.path.join(self.tmpdir, "build")
-            if not os.path.exists(self.workdir):
-                os.makedirs(self.workdir)
-            self.__builddir = tempfile.mkdtemp(dir=self.workdir,
-                                               prefix="imgcreate-")
-        except OSError as err:
-            raise CreatorError("Failed create build directory in %s: %s" %
-                               (self.tmpdir, err))
-
-    def __setup_tmpdir(self):
-        if not self.enabletmpfs:
-            return
-
-        runner.show('mount -t tmpfs -o size=4G tmpfs %s' % self.workdir)
-
-    def __clean_tmpdir(self):
-        if not self.enabletmpfs:
-            return
-
-        runner.show('umount -l %s' % self.workdir)
-
-    def create(self):
-        """Create partitions for the disk image(s)
-
-        Create the partitions that will be assembled into disk
-        image(s).
-        """
-        self.__setup_tmpdir()
-        self.__ensure_builddir()
-
-        self._create()
-
-    def cleanup(self):
-        """Undo anything performed in create().
-
-        Note, make sure to call this method once finished with the creator
-        instance in order to ensure no stale files are left on the host e.g.:
-
-          creator = ImageCreator(ks, name)
-          try:
-              creator.create()
-          finally:
-              creator.cleanup()
-
-        """
-        if not self.__builddir:
-            return
-
-        self._cleanup()
-
-        shutil.rmtree(self.__builddir, ignore_errors=True)
-        self.__builddir = None
-
-        self.__clean_tmpdir()
-
-
-    def print_outimage_info(self):
-        msg = "The new image can be found here:\n"
-        self.outimage.sort()
-        for path in self.outimage:
-            msg += '  %s\n' % os.path.abspath(path)
-
-        msger.info(msg)
scripts/lib/wic/imager/direct.py +13 -6
index 52828c1..825c9d7 100644
@@ -32,7 +32,6 @@ from wic import msger
 from wic.utils.oe.misc import get_bitbake_var
 from wic.utils.partitionedfs import Image
 from wic.utils.errors import CreatorError, ImageError
-from wic.imager.baseimager import BaseImageCreator
 from wic.plugin import pluginmgr
 from wic.utils.oe.misc import exec_cmd, exec_native_cmd
 
@@ -61,7 +60,7 @@ class DiskImage():
 
         self.created = True
 
-class DirectImageCreator(BaseImageCreator):
+class DirectImageCreator:
     """
     Installs a system into a file containing a partitioned disk image.
 
@@ -72,15 +71,23 @@ class DirectImageCreator(BaseImageCreator):
     media and used on actual hardware.
     """
 
-    def __init__(self, oe_builddir, image_output_dir, rootfs_dir, bootimg_dir,
-                 kernel_dir, native_sysroot, compressor, creatoropts=None,
-                 bmap=False):
+    def __init__(self, oe_builddir, image_output_dir, rootfs_dir,
+                 bootimg_dir, kernel_dir, native_sysroot, compressor,
+                 creatoropts, bmap=False):
         """
         Initialize a DirectImageCreator instance.
 
         This method takes the same arguments as ImageCreator.__init__()
         """
-        BaseImageCreator.__init__(self, creatoropts)
+
+        self.name = creatoropts['name']
+        self.ks = creatoropts['ks']
+
+        self.tmpdir = "/var/tmp/wic"
+        self.workdir = "/var/tmp/wic/build"
+
+        if not os.path.exists(self.tmpdir):
+            os.makedirs(self.tmpdir)
 
         self.__image = None
         self.__disks = {}
Signature · 1 line
2.1.4
author
#3 lore raw

PATCH 3/8 wic: make workdir a temporary directory

In reply to Ed Bartosh

Wic used hardcoded path /var/tmp/wic/ as a work directory, which caused conflicts if two wic instances run in parallel.

Made work directory unique and temporary. Moved results from work directory to output directory when they're ready.

[YOCTO #10783]

---
 scripts/lib/wic/imager/direct.py | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)
scripts/lib/wic/imager/direct.py +15 -12
index 825c9d7..63f1fa1 100644
@@ -27,6 +27,7 @@
 import os
 import shutil
 import uuid
+import tempfile
 
 from wic import msger
 from wic.utils.oe.misc import get_bitbake_var
@@ -79,16 +80,11 @@ class DirectImageCreator:
 
         This method takes the same arguments as ImageCreator.__init__()
         """
-
         self.name = creatoropts['name']
+        self.outdir = image_output_dir
+        self.workdir = tempfile.mktemp(prefix='wic')
         self.ks = creatoropts['ks']
 
-        self.tmpdir = "/var/tmp/wic"
-        self.workdir = "/var/tmp/wic/build"
-
-        if not os.path.exists(self.tmpdir):
-            os.makedirs(self.tmpdir)
-
         self.__image = None
         self.__disks = {}
         self.__disk_format = "direct"
@@ -96,8 +92,6 @@ class DirectImageCreator:
         self.ptable_format = self.ks.bootloader.ptable
 
         self.oe_builddir = oe_builddir
-        if image_output_dir:
-            self.tmpdir = image_output_dir
         self.rootfs_dir = rootfs_dir
         self.bootimg_dir = bootimg_dir
         self.kernel_dir = kernel_dir
@@ -270,9 +264,6 @@ class DirectImageCreator:
 
         fstab_path = self._write_fstab(self.rootfs_dir.get("ROOTFS_DIR"))
 
-        shutil.rmtree(self.workdir)
-        os.mkdir(self.workdir)
-
         for part in parts:
             # get rootfs size from bitbake variable if it's not set in .ks file
             if not part.size:
@@ -425,3 +416,15 @@ class DirectImageCreator:
             except ImageError as err:
                 msger.warning("%s" % err)
 
+        # Move results to the output dir
+        if not os.path.exists(self.outdir):
+            os.makedirs(self.outdir)
+
+        for fname in os.listdir(self.workdir):
+            path = os.path.join(self.workdir, fname)
+            if os.path.isfile(path):
+                shutil.move(path, os.path.join(self.outdir, fname))
+
+        # remove work directory
+        shutil.rmtree(self.workdir, ignore_errors=True)
+
Signature · 1 line
2.1.4
author
#4 lore raw

PATCH 4/8 wic: remove unused API DirectImageCreator.get_disk_names

In reply to Ed Bartosh
---
 scripts/lib/wic/imager/direct.py | 26 --------------------------
 1 file changed, 26 deletions(-)
scripts/lib/wic/imager/direct.py +0 -26
index 63f1fa1..6340a59 100644
@@ -185,32 +185,6 @@ class DirectImageCreator:
         # partitions list from kickstart file
         return self.ks.partitions
 
-    def get_disk_names(self):
-        """ Returns a list of physical target disk names (e.g., 'sdb') which
-        will be created. """
-
-        if self._disk_names:
-            return self._disk_names
-
-        #get partition info from ks handler
-        parts = self._get_parts()
-
-        for i in range(len(parts)):
-            if parts[i].disk:
-                disk_name = parts[i].disk
-            else:
-                raise CreatorError("Failed to create disks, no --ondisk "
-                                   "specified in partition line of ks file")
-
-            if parts[i].mountpoint and not parts[i].fstype:
-                raise CreatorError("Failed to create disks, no --fstype "
-                                   "specified for partition with mountpoint "
-                                   "'%s' in the ks file")
-
-            self._disk_names.append(disk_name)
-
-        return self._disk_names
-
     def _full_name(self, name, extention):
         """ Construct full file name for a file we generate. """
         return "%s-%s.%s" % (self.name, name, extention)
Signature · 1 line
2.1.4
author
#5 lore raw

PATCH 5/8 wic: direct.py: get rid of names with two underscores

In reply to Ed Bartosh

Attributes with two leading underscores are mangled in Python and used mainly for avoiding name clashes with names from subclasses. They're not needed in most of wic classes.

---
 scripts/lib/wic/imager/direct.py | 50 +++++++++++++++++++---------------------
 1 file changed, 24 insertions(+), 26 deletions(-)
scripts/lib/wic/imager/direct.py +24 -26
index 6340a59..575fd95 100644
@@ -99,7 +99,7 @@ class DirectImageCreator:
         self.compressor = compressor
         self.bmap = bmap
 
-    def __get_part_num(self, num, parts):
+    def _get_part_num(self, num, parts):
         """calculate the real partition number, accounting for partitions not
         in the partition table and logical partitions
         """
@@ -142,7 +142,7 @@ class DirectImageCreator:
         """Assume partition order same as in wks"""
         updated = False
         for num, part in enumerate(parts, 1):
-            pnum = self.__get_part_num(num, parts)
+            pnum = self._get_part_num(num, parts)
             if not pnum or not part.mountpoint \
                or part.mountpoint in ("/", "/boot"):
                 continue
@@ -209,7 +209,7 @@ class DirectImageCreator:
     #
     # Actual implemention
     #
-    def _create(self):
+    def create(self):
         """
         For 'wic', we already have our build artifacts - we just create
         filesystems from the artifacts directly and combine them into
@@ -217,7 +217,7 @@ class DirectImageCreator:
         """
         parts = self._get_parts()
 
-        self.__image = Image(self.native_sysroot)
+        self._image = Image(self.native_sysroot)
 
         disk_ids = {}
         for num, part in enumerate(parts, 1):
@@ -234,7 +234,7 @@ class DirectImageCreator:
                     if part.disk not in disk_ids:
                         disk_ids[part.disk] = int.from_bytes(os.urandom(4), 'little')
                     disk_id = disk_ids[part.disk]
-                    part.uuid = '%0x-%02d' % (disk_id, self.__get_part_num(num, parts))
+                    part.uuid = '%0x-%02d' % (disk_id, self._get_part_num(num, parts))
 
         fstab_path = self._write_fstab(self.rootfs_dir.get("ROOTFS_DIR"))
 
@@ -262,7 +262,7 @@ class DirectImageCreator:
                          self.bootimg_dir, self.kernel_dir, self.native_sysroot)
 
 
-            self.__image.add_partition(part.disk_size,
+            self._image.add_partition(part.disk_size,
                                        part.disk,
                                        part.mountpoint,
                                        part.source_file,
@@ -279,28 +279,27 @@ class DirectImageCreator:
         if fstab_path:
             shutil.move(fstab_path + ".orig", fstab_path)
 
-        self.__image.layout_partitions(self.ptable_format)
+        self._image.layout_partitions(self.ptable_format)
 
-        self.__imgdir = self.workdir
-        for disk_name, disk in self.__image.disks.items():
-            full_path = self._full_path(self.__imgdir, disk_name, "direct")
+        for disk_name, disk in self._image.disks.items():
+            full_path = self._full_path(self.workdir, disk_name, "direct")
             msger.debug("Adding disk %s as %s with size %s bytes" \
                         % (disk_name, full_path, disk['min_size']))
             disk_obj = DiskImage(full_path, disk['min_size'])
-            self.__disks[disk_name] = disk_obj
-            self.__image.add_disk(disk_name, disk_obj, disk_ids.get(disk_name))
+            #self._disks[disk_name] = disk_obj
+            self._image.add_disk(disk_name, disk_obj, disk_ids.get(disk_name))
 
-        self.__image.create()
+        self._image.create()
 
     def assemble(self):
         """
         Assemble partitions into disk image(s)
         """
-        for disk_name, disk in self.__image.disks.items():
-            full_path = self._full_path(self.__imgdir, disk_name, "direct")
+        for disk_name, disk in self._image.disks.items():
+            full_path = self._full_path(self.workdir, disk_name, "direct")
             msger.debug("Assembling disk %s as %s with size %s bytes" \
                         % (disk_name, full_path, disk['min_size']))
-            self.__image.assemble(full_path)
+            self._image.assemble(full_path)
 
     def finalize(self):
         """
@@ -308,12 +307,11 @@ class DirectImageCreator:
 
         For example, prepare the image to be bootable by e.g.
         creating and installing a bootloader configuration.
-
         """
         source_plugin = self.get_default_source_plugin()
         if source_plugin:
             self._source_methods = pluginmgr.get_source_plugin_methods(source_plugin, disk_methods)
-            for disk_name, disk in self.__image.disks.items():
+            for disk_name, disk in self._image.disks.items():
                 self._source_methods["do_install_disk"](disk, disk_name, self,
                                                         self.workdir,
                                                         self.oe_builddir,
@@ -321,8 +319,8 @@ class DirectImageCreator:
                                                         self.kernel_dir,
                                                         self.native_sysroot)
 
-        for disk_name, disk in self.__image.disks.items():
-            full_path = self._full_path(self.__imgdir, disk_name, "direct")
+        for disk_name, disk in self._image.disks.items():
+            full_path = self._full_path(self.workdir, disk_name, "direct")
             # Generate .bmap
             if self.bmap:
                 msger.debug("Generating bmap file for %s" % disk_name)
@@ -341,12 +339,12 @@ class DirectImageCreator:
 
         parts = self._get_parts()
 
-        for disk_name in self.__image.disks:
+        for disk_name in self._image.disks:
             extension = "direct" + {"gzip": ".gz",
                                     "bzip2": ".bz2",
                                     "xz": ".xz",
                                     "": ""}.get(self.compressor)
-            full_path = self._full_path(self.__imgdir, disk_name, extension)
+            full_path = self._full_path(self.outdir, disk_name, extension)
             msg += '  %s\n\n' % full_path
 
         msg += 'The following build artifacts were used to create the image(s):\n'
@@ -380,13 +378,13 @@ class DirectImageCreator:
                     return "PARTUUID=%s" % part.uuid
                 else:
                     suffix = 'p' if part.disk.startswith('mmcblk') else ''
-                    pnum = self.__get_part_num(num, parts)
+                    pnum = self._get_part_num(num, parts)
                     return "/dev/%s%s%-d" % (part.disk, suffix, pnum)
 
-    def _cleanup(self):
-        if not self.__image is None:
+    def cleanup(self):
+        if self._image:
             try:
-                self.__image.cleanup()
+                self._image.cleanup()
             except ImageError as err:
                 msger.warning("%s" % err)
 
Signature · 1 line
2.1.4
author
#6 lore raw

PATCH 6/8 image_types: use correct output directory

In reply to Ed Bartosh

Wic put result images into <output dir>/build, which was confusing. Now it's fixed in wic code and images are put into output directory. Changed code in image_types to reflect this.

[YOCTO #10783]

---
 meta/classes/image_types.bbclass | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
meta/classes/image_types.bbclass +1 -1
index 5b1746a..c457f38 100644
@@ -217,7 +217,7 @@ IMAGE_CMD_wic () {
 	fi
 
 	BUILDDIR="${TOPDIR}" wic create "$wks" --vars "${STAGING_DIR}/imgdata/" -e "${IMAGE_BASENAME}" -o "$out/" ${WIC_CREATE_EXTRA_ARGS}
-	mv "$out/build/$(basename "${wks%.wks}")"*.direct "$out${IMAGE_NAME_SUFFIX}.wic"
+	mv "$out/$(basename "${wks%.wks}")"*.direct "$out${IMAGE_NAME_SUFFIX}.wic"
 	rm -rf "$out/"
 }
 IMAGE_CMD_wic[vardepsexclude] = "WKS_FULL_PATH WKS_FILES"
Signature · 1 line
2.1.4
author
#7 lore raw

PATCH 7/8 selftest: wic: explicitly specify output directory

In reply to Ed Bartosh

wic started to use current directory as a default output dir. Specified output directory in wic command line to make tests more predictable and easier to maintain.

---
 meta/lib/oeqa/selftest/wic.py | 72 +++++++++++++++++++++++++------------------
 1 file changed, 42 insertions(+), 30 deletions(-)
meta/lib/oeqa/selftest/wic.py +42 -30
index 11dc744..7916071 100644
@@ -36,8 +36,8 @@ from oeqa.utils.decorators import testcase
 class Wic(oeSelfTest):
     """Wic test class."""
 
-    resultdir = "/var/tmp/wic/build/"
     alternate_resultdir = "/var/tmp/wic/build/alt/"
+    resultdir = "/var/tmp/wic.oe-selftest/"
     image_is_ready = False
     wicenv_cache = {}
 
@@ -56,6 +56,10 @@ class Wic(oeSelfTest):
 
         rmtree(self.resultdir, ignore_errors=True)
 
+    def tearDownLocal(self):
+        """Remove resultdir as it may contain images."""
+        rmtree(self.resultdir, ignore_errors=True)
+
     @testcase(1552)
     def test_version(self):
         """Test wic --version"""
@@ -134,14 +138,14 @@ class Wic(oeSelfTest):
     @testcase(1211)
     def test_build_image_name(self):
         """Test wic create directdisk --image-name=core-image-minimal"""
-        cmd = "wic create directdisk --image-name=core-image-minimal"
+        cmd = "wic create directdisk --image-name=core-image-minimal -o %s" % self.resultdir
         self.assertEqual(0, runCmd(cmd).status)
         self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct")))
 
     @testcase(1157)
     def test_gpt_image(self):
         """Test creation of core-image-minimal with gpt table and UUID boot"""
-        cmd = "wic create directdisk-gpt --image-name core-image-minimal"
+        cmd = "wic create directdisk-gpt --image-name core-image-minimal -o %s" % self.resultdir
         self.assertEqual(0, runCmd(cmd).status)
         self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct")))
 
@@ -152,7 +156,7 @@ class Wic(oeSelfTest):
         self.append_config(config)
         bitbake('core-image-minimal')
         self.remove_config(config)
-        cmd = "wic create mkhybridiso --image-name core-image-minimal"
+        cmd = "wic create mkhybridiso --image-name core-image-minimal -o %s" % self.resultdir
         self.assertEqual(0, runCmd(cmd).status)
         self.assertEqual(1, len(glob(self.resultdir + "HYBRID_ISO_IMG-*.direct")))
         self.assertEqual(1, len(glob(self.resultdir + "HYBRID_ISO_IMG-*.iso")))
@@ -160,21 +164,21 @@ class Wic(oeSelfTest):
     @testcase(1348)
     def test_qemux86_directdisk(self):
         """Test creation of qemux-86-directdisk image"""
-        cmd = "wic create qemux86-directdisk -e core-image-minimal"
+        cmd = "wic create qemux86-directdisk -e core-image-minimal -o %s" % self.resultdir
         self.assertEqual(0, runCmd(cmd).status)
         self.assertEqual(1, len(glob(self.resultdir + "qemux86-directdisk-*direct")))
 
     @testcase(1350)
     def test_mkefidisk(self):
         """Test creation of mkefidisk image"""
-        cmd = "wic create mkefidisk -e core-image-minimal"
+        cmd = "wic create mkefidisk -e core-image-minimal -o %s" % self.resultdir
         self.assertEqual(0, runCmd(cmd).status)
         self.assertEqual(1, len(glob(self.resultdir + "mkefidisk-*direct")))
 
     @testcase(1385)
     def test_directdisk_bootloader_config(self):
         """Test creation of directdisk-bootloader-config image"""
-        cmd = "wic create directdisk-bootloader-config -e core-image-minimal"
+        cmd = "wic create directdisk-bootloader-config -e core-image-minimal -o %s" % self.resultdir
         self.assertEqual(0, runCmd(cmd).status)
         self.assertEqual(1, len(glob(self.resultdir + "directdisk-bootloader-config-*direct")))
 
@@ -185,14 +189,14 @@ class Wic(oeSelfTest):
         self.append_config(config)
         bitbake('core-image-minimal')
         self.remove_config(config)
-        cmd = "wic create systemd-bootdisk -e core-image-minimal"
+        cmd = "wic create systemd-bootdisk -e core-image-minimal -o %s" % self.resultdir
         self.assertEqual(0, runCmd(cmd).status)
         self.assertEqual(1, len(glob(self.resultdir + "systemd-bootdisk-*direct")))
 
     @testcase(1561)
     def test_sdimage_bootpart(self):
         """Test creation of sdimage-bootpart image"""
-        cmd = "wic create sdimage-bootpart -e core-image-minimal"
+        cmd = "wic create sdimage-bootpart -e core-image-minimal -o %s" % self.resultdir
         self.write_config('IMAGE_BOOT_FILES = "bzImage"\n')
         self.assertEqual(0, runCmd(cmd).status)
         self.assertEqual(1, len(glob(self.resultdir + "sdimage-bootpart-*direct")))
@@ -219,11 +223,13 @@ class Wic(oeSelfTest):
         bbvars = dict((var.lower(), get_bb_var(var, 'core-image-minimal'))
                       for var in ('STAGING_DATADIR', 'DEPLOY_DIR_IMAGE', 'IMAGE_ROOTFS'))
         bbvars['recipe_sysroot_native'] = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools')
+        bbvars['resultdir'] = self.resultdir
         status = runCmd("wic create directdisk "
                         "-b %(staging_datadir)s "
                         "-k %(deploy_dir_image)s "
                         "-n %(recipe_sysroot_native)s "
-                        "-r %(image_rootfs)s" % bbvars).status
+                        "-r %(image_rootfs)s "
+                        "-o %(resultdir)s" % bbvars).status
         self.assertEqual(0, status)
         self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct")))
 
@@ -232,7 +238,7 @@ class Wic(oeSelfTest):
         """Test compressing an image with gzip"""
         self.assertEqual(0, runCmd("wic create directdisk "
                                    "--image-name core-image-minimal "
-                                   "-c gzip").status)
+                                   "-c gzip -o %s" % self.resultdir).status)
         self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct.gz")))
 
     @testcase(1265)
@@ -240,7 +246,7 @@ class Wic(oeSelfTest):
         """Test compressing an image with bzip2"""
         self.assertEqual(0, runCmd("wic create directdisk "
                                    "--image-name=core-image-minimal "
-                                   "-c bzip2").status)
+                                   "-c bzip2 -o %s" % self.resultdir).status)
         self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct.bz2")))
 
     @testcase(1266)
@@ -248,7 +254,7 @@ class Wic(oeSelfTest):
         """Test compressing an image with xz"""
         self.assertEqual(0, runCmd("wic create directdisk "
                                    "--image-name=core-image-minimal "
-                                   "--compress-with=xz").status)
+                                   "--compress-with=xz -o %s" % self.resultdir).status)
         self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct.xz")))
 
     @testcase(1267)
@@ -256,18 +262,19 @@ class Wic(oeSelfTest):
         """Test how wic breaks if wrong compressor is provided"""
         self.assertEqual(2, runCmd("wic create directdisk "
                                    "--image-name=core-image-minimal "
-                                   "-c wrong", ignore_status=True).status)
+                                   "-c wrong -o %s" % self.resultdir,
+                                   ignore_status=True).status)
 
     @testcase(1558)
     def test_debug(self):
         """Test debug"""
         self.assertEqual(0, runCmd("wic create directdisk "
                                    "--image-name=core-image-minimal "
-                                   "-D").status)
+                                   "-D -o %s" % self.resultdir).status)
         self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct")))
         self.assertEqual(0, runCmd("wic create directdisk "
                                    "--image-name=core-image-minimal "
-                                   "--debug").status)
+                                   "--debug -o %s" % self.resultdir).status)
         self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct")))
 
     @testcase(1563)
@@ -275,11 +282,12 @@ class Wic(oeSelfTest):
         """Test skip build check"""
         self.assertEqual(0, runCmd("wic create directdisk "
                                    "--image-name=core-image-minimal "
-                                   "-s").status)
+                                   "-s -o %s" % self.resultdir).status)
         self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct")))
         self.assertEqual(0, runCmd("wic create directdisk "
                                    "--image-name=core-image-minimal "
-                                   "--skip-build-check").status)
+                                   "--skip-build-check "
+                                   "--outdir %s" % self.resultdir).status)
         self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct")))
 
     @testcase(1564)
@@ -287,11 +295,12 @@ class Wic(oeSelfTest):
         """Test build rootfs"""
         self.assertEqual(0, runCmd("wic create directdisk "
                                    "--image-name=core-image-minimal "
-                                   "-f").status)
+                                   "-f -o %s" % self.resultdir).status)
         self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct")))
         self.assertEqual(0, runCmd("wic create directdisk "
                                    "--image-name=core-image-minimal "
-                                   "--build-rootfs").status)
+                                   "--build-rootfs "
+                                   "--outdir %s" % self.resultdir).status)
         self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct")))
 
     @testcase(1268)
@@ -300,7 +309,8 @@ class Wic(oeSelfTest):
         status = runCmd("wic create directdisk-multi-rootfs "
                         "--image-name=core-image-minimal "
                         "--rootfs rootfs1=core-image-minimal "
-                        "--rootfs rootfs2=core-image-minimal").status
+                        "--rootfs rootfs2=core-image-minimal "
+                        "--outdir %s" % self.resultdir).status
         self.assertEqual(0, status)
         self.assertEqual(1, len(glob(self.resultdir + "directdisk-multi-rootfs*.direct")))
 
@@ -311,25 +321,27 @@ class Wic(oeSelfTest):
                       for var in ('STAGING_DATADIR', 'DEPLOY_DIR_IMAGE', 'IMAGE_ROOTFS'))
         bbvars['recipe_sysroot_native'] = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools')
         bbvars['wks'] = "directdisk-multi-rootfs"
+        bbvars['resultdir'] = self.resultdir
         status = runCmd("wic create %(wks)s "
                         "--bootimg-dir=%(staging_datadir)s "
                         "--kernel-dir=%(deploy_dir_image)s "
                         "--native-sysroot=%(recipe_sysroot_native)s "
                         "--rootfs-dir rootfs1=%(image_rootfs)s "
-                        "--rootfs-dir rootfs2=%(image_rootfs)s"
-                        % bbvars).status
+                        "--rootfs-dir rootfs2=%(image_rootfs)s "
+                        "--outdir %(resultdir)s" % bbvars).status
         self.assertEqual(0, status)
         self.assertEqual(1, len(glob(self.resultdir + "%(wks)s-*.direct" % bbvars)))
 
     @testcase(1496)
     def test_bmap(self):
         """Test generation of .bmap file"""
-        cmd = "wic create directdisk -e core-image-minimal -m"
+        cmd = "wic create directdisk -e core-image-minimal -m -o %s" % self.resultdir
         status = runCmd(cmd).status
         self.assertEqual(0, status)
         self.assertEqual(1, len(glob(self.resultdir + "directdisk-*direct")))
         self.assertEqual(1, len(glob(self.resultdir + "directdisk-*direct.bmap")))
-        cmd = "wic create directdisk -e core-image-minimal --bmap"
+        rmtree(self.resultdir)
+        cmd = "wic create directdisk -e core-image-minimal --bmap -o %s" % self.resultdir
         status = runCmd(cmd).status
         self.assertEqual(0, status)
         self.assertEqual(1, len(glob(self.resultdir + "directdisk-*direct")))
@@ -372,13 +384,13 @@ class Wic(oeSelfTest):
         imgenvdir = self._get_image_env_path(image)
 
         self.assertEqual(0, runCmd("wic create directdisk "
-                                   "--image-name=%s "
-                                   "-v %s"
-                                   % (image, imgenvdir)).status)
+                                   "--image-name=%s -v %s -o %s"
+                                   % (image, imgenvdir, self.resultdir)).status)
         self.assertEqual(0, runCmd("wic create directdisk "
                                    "--image-name=%s "
-                                   "--vars %s"
-                                   % (image, imgenvdir)).status)
+                                   "--vars %s "
+                                   "--outdir %s"
+                                   % (image, imgenvdir, self.resultdir)).status)
 
     @testcase(1351)
     def test_wic_image_type(self):
Signature · 1 line
2.1.4
author
#8 lore raw

PATCH 8/8 selftest: wic: test default output directory

In reply to Ed Bartosh

As tests now explicitly specify output directory we don't need test_alternate_output_dir test case. However, we need to test wic output to default output location.

Removed test_alternate_output_dir test case.
Added test_default_output_dir test case.

---
 meta/lib/oeqa/selftest/wic.py | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)
meta/lib/oeqa/selftest/wic.py +7 -15
index 7916071..8295b40 100644
@@ -36,7 +36,6 @@ from oeqa.utils.decorators import testcase
 class Wic(oeSelfTest):
     """Wic test class."""
 
-    alternate_resultdir = "/var/tmp/wic/build/alt/"
     resultdir = "/var/tmp/wic.oe-selftest/"
     image_is_ready = False
     wicenv_cache = {}
@@ -202,20 +201,13 @@ class Wic(oeSelfTest):
         self.assertEqual(1, len(glob(self.resultdir + "sdimage-bootpart-*direct")))
 
     @testcase(1562)
-    def test_alternate_output_dir(self):
-        """Test alternate output directory"""
-        self.assertEqual(0, runCmd("wic create directdisk "
-                                   "-e core-image-minimal "
-                                   "-o %s"
-                                   % self.alternate_resultdir).status)
-        self.assertEqual(1, len(glob(self.alternate_resultdir +
-                                     "build/directdisk-*.direct")))
-        self.assertEqual(0, runCmd("wic create mkefidisk -e "
-                                   "core-image-minimal "
-                                   "--outdir=%s"
-                                   % self.alternate_resultdir).status)
-        self.assertEqual(1, len(glob(self.alternate_resultdir +
-                                     "build/mkefidisk-*direct")))
+    def test_default_output_dir(self):
+        """Test default output location"""
+        for fname in glob("directdisk-*.direct"):
+            os.remove(fname)
+        cmd = "wic create directdisk -e core-image-minimal"
+        self.assertEqual(0, runCmd(cmd).status)
+        self.assertEqual(1, len(glob("directdisk-*.direct")))
 
     @testcase(1212)
     def test_build_artifacts(self):
Signature · 1 line
2.1.4