[petitboot-test 1/2] pbtest: Support ext3, ext4, and xfs filesystems

Samuel Mendoza-Jonas sam.mj at au1.ibm.com
Mon Mar 23 17:03:32 AEDT 2015


Allow RootFS devices to support extra filesystems.
XFS does not yet support adding files from self.files as there is not an
equivalent to e2cp for XFS filesystems.

Signed-off-by: Samuel Mendoza-Jonas <sam.mj at au1.ibm.com>
---
 pbtest/rootfs.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 57 insertions(+), 1 deletion(-)

diff --git a/pbtest/rootfs.py b/pbtest/rootfs.py
index e868254..4c58437 100644
--- a/pbtest/rootfs.py
+++ b/pbtest/rootfs.py
@@ -6,7 +6,7 @@ import os
 
 class RootFS(object):
     def __init__(self, image_format = 'ext2', iface = 'virtio'):
-        self.size = 1 * 1024 * 1024
+        self.size = 16 * 1024 * 1024
         self.files = []
         self._image_file = None
         self.image_format = image_format
@@ -46,6 +46,62 @@ class RootFS(object):
             if rc != 0:
                 raise Exception("Can't add files to filesystem")
 
+    def image_create_ext3(self):
+        self._image_file = tempfile.NamedTemporaryFile(suffix = '.img')
+        self._image_file.truncate(self.size * 1024)
+        self._image_file.seek(0)
+
+        name = self._image_file.name
+
+        null = file('/dev/null', 'w')
+        rc = subprocess.call(['mkfs.ext3', '-F', '-m', '0', name],
+                                stdout = null, stderr = subprocess.STDOUT)
+        if rc != 0:
+            raise Exception("Can't create filesystem")
+
+        for (destname, data) in self.files:
+            proc = subprocess.Popen(['e2cp', '-', '%s:%s' % (name, destname)],
+                                        stdin = subprocess.PIPE)
+            proc.communicate(data)
+            if rc != 0:
+                raise Exception("Can't add files to filesystem")
+
+    def image_create_ext4(self):
+        self._image_file = tempfile.NamedTemporaryFile(suffix = '.img')
+        self._image_file.truncate(self.size)
+        self._image_file.seek(0)
+
+        name = self._image_file.name
+
+        null = file('/dev/null', 'w')
+        rc = subprocess.call(['mkfs.ext4', '-F', '-m', '0', name],
+                                stdout = null, stderr = subprocess.STDOUT)
+        if rc != 0:
+            raise Exception("Can't create filesystem")
+
+        for (destname, data) in self.files:
+            proc = subprocess.Popen(['e2cp', '-', '%s:%s' % (name, destname)],
+                                        stdin = subprocess.PIPE)
+            proc.communicate(data)
+            if rc != 0:
+                raise Exception("Can't add files to filesystem")
+
+    def image_create_xfs(self):
+        self._image_file = tempfile.NamedTemporaryFile(suffix = '.img')
+        self._image_file.truncate(self.size)
+        self._image_file.seek(0)
+
+        name = self._image_file.name
+
+        null = file('/dev/null', 'w')
+	# default 4K blocks
+        rc = subprocess.call(['mkfs.xfs',  '-f',  name],
+                                stdout = null, stderr = subprocess.STDOUT)
+        if rc != 0:
+            raise Exception("Can't create filesystem")
+
+	# self.files not added
+
     def image_create_iso9660(self):
 
         tmpdir = tempfile.mkdtemp()
-- 
2.1.0



More information about the Petitboot mailing list