linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: ckulkarnilinux@gmail.com (Chaitanya Kulkarni)
Subject: [PATCH V2 06/46] nvmftests-utils: add fs package
Date: Tue, 24 Oct 2017 18:30:23 -0700	[thread overview]
Message-ID: <1508895063-6280-7-git-send-email-ckulkarnilinux@gmail.com> (raw)
In-Reply-To: <1508895063-6280-1-git-send-email-ckulkarnilinux@gmail.com>

From: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>

This adds wrapper classes for handling different
file system related operations. In current implementation
it has a support for ext4 file system.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni at wdc.com>
---
 .../selftests/nvmftests/utils/fs/__init__.py       |  21 ++++
 .../testing/selftests/nvmftests/utils/fs/ext4fs.py | 108 ++++++++++++++++++
 .../selftests/nvmftests/utils/fs/filesystem.py     | 122 +++++++++++++++++++++
 3 files changed, 251 insertions(+)
 create mode 100644 tools/testing/selftests/nvmftests/utils/fs/__init__.py
 create mode 100644 tools/testing/selftests/nvmftests/utils/fs/ext4fs.py
 create mode 100644 tools/testing/selftests/nvmftests/utils/fs/filesystem.py

diff --git a/tools/testing/selftests/nvmftests/utils/fs/__init__.py b/tools/testing/selftests/nvmftests/utils/fs/__init__.py
new file mode 100644
index 0000000..e83f580
--- /dev/null
+++ b/tools/testing/selftests/nvmftests/utils/fs/__init__.py
@@ -0,0 +1,21 @@
+# Copyright (c) 2016-2017 Western Digital Corporation or its affiliates.
+#
+# 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; either version 2
+# of the License, or (at your option) any later version.
+#
+# 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., 51 Franklin Street, Fifth Floor, Boston,
+# MA  02110-1301, USA.
+#
+#   Author: Chaitanya Kulkarni <chaitanya.kulkarni at wdc.com>
+#
+from .filesystem import FileSystem
+from .ext4fs import Ext4FS
diff --git a/tools/testing/selftests/nvmftests/utils/fs/ext4fs.py b/tools/testing/selftests/nvmftests/utils/fs/ext4fs.py
new file mode 100644
index 0000000..e0a5146
--- /dev/null
+++ b/tools/testing/selftests/nvmftests/utils/fs/ext4fs.py
@@ -0,0 +1,108 @@
+# Copyright (c) 2016-2017 Western Digital Corporation or its affiliates.
+#
+# 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; either version 2
+# of the License, or (at your option) any later version.
+#
+# 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., 51 Franklin Street, Fifth Floor, Boston,
+# MA  02110-1301, USA.
+#
+#   Author: Chaitanya Kulkarni <chaitanya.kulkarni at wdc.com>
+#
+""" Represents Ext4 File system.
+"""
+import os
+import logging
+
+from .filesystem import FileSystem
+from utils.shell import Cmd
+
+
+class Ext4FS(FileSystem):
+    """
+    Represents Ext4 File System management interface.
+
+        - Attributes :
+    """
+    def __init__(self, dev_path, mount_path=None):
+        super(Ext4FS, self).__init__("ext4", dev_path, mount_path)
+        self.logger = logging.getLogger(__name__)
+        self.log_format = '%(asctime)s %(name)-12s %(levelname)-8s %(message)s'
+        self.log_format += '%(filename)20s %(funcName)20s %(lineno)4d'
+        self.log_format += '%(pathname)s'
+        self.formatter = logging.Formatter(self.log_format)
+        self.logger.setLevel(logging.WARNING)
+
+    def get_mount_path(self):
+        """ Accessor for file system mountpath.
+            - Args :
+                - None.
+            - Returns :
+                - File system mountpath.
+        """
+        return super(Ext4FS, self).get_mount_path()
+
+    def mkfs(self):
+        """ Execute mkfs on target deivce.
+            - Args :
+                - None.
+            - Returns :
+                - True on success, False on failure.
+        """
+        if super(Ext4FS, self).mkfs() is False:
+            return False
+
+        if Cmd.exec_cmd("mkfs.ext4 " + self.dev_path) is False:
+            self.logger.error("mkfs failed")
+            return False
+
+        self.logger.info("mkfs successful!!!")
+        return True
+
+    def mount(self):
+        """ Mount Target device on the mount path.
+            - Args :
+                - None.
+            - Returns :
+                - True on success, False on failure.
+        """
+        if super(Ext4FS, self).mount() is False:
+            return False
+        return Cmd.exec_cmd("mount " + self.dev_path + " " + self.mount_path)
+
+    def is_mounted(self):
+        """ Check if mount_path is mounted.
+            - Args :
+                - None.
+            - Returns :
+                - True on success, False on failure.
+        """
+        return Cmd.exec_cmd("mountpoint -q " + self.mount_path)
+
+    def umount(self):
+        """ Unmount target device from mount path.
+            - Args :
+                - None.
+            - Returns :
+                - True on success, False on failure.
+        """
+        if super(Ext4FS, self).umount() is False:
+            return False
+
+        ret = True
+        Cmd.exec_cmd("umount " + self.mount_path)
+        try:
+            os.rmdir(self.mount_path)
+        except Exception as err:
+            self.logger.info(str(err))
+            ret = False
+
+        return ret
diff --git a/tools/testing/selftests/nvmftests/utils/fs/filesystem.py b/tools/testing/selftests/nvmftests/utils/fs/filesystem.py
new file mode 100644
index 0000000..cedb9e9
--- /dev/null
+++ b/tools/testing/selftests/nvmftests/utils/fs/filesystem.py
@@ -0,0 +1,122 @@
+# Copyright (c) 2016-2017 Western Digital Corporation or its affiliates.
+#
+# 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; either version 2
+# of the License, or (at your option) any later version.
+#
+# 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., 51 Franklin Street, Fifth Floor, Boston,
+# MA  02110-1301, USA.
+#
+#   Author: Chaitanya Kulkarni <chaitanya.kulkarni at wdc.com>
+#
+""" Represents File System Base class.
+"""
+import os
+import stat
+import logging
+
+
+from utils.shell import Cmd
+
+
+class FileSystem(object):
+    """
+    Represents file system management interface.
+
+        - Attributes :
+            - fs_name : file system name.
+            - dev_path : target device.
+            - mount_path : path to mount target device.
+    """
+    def __init__(self, fs_name, dev_path, mount_path=None):
+        self.fs_name = fs_name
+        self.dev_path = dev_path
+        self.mount_path = mount_path
+        if self.mount_path is None:
+            self.mount_path = "/mnt/" + self.dev_path.split('/')[-1]
+
+        self.logger = logging.getLogger(__name__)
+        self.log_format = '%(asctime)s %(name)-12s %(levelname)-8s %(message)s'
+        self.log_format += '%(filename)20s %(funcName)20s %(lineno)4d'
+        self.log_format += '%(pathname)s'
+        self.formatter = logging.Formatter(self.log_format)
+        self.logger.setLevel(logging.WARNING)
+
+    def mkfs(self):
+        """ Check preconditions for the mkfs operation, subclass should
+            implement actual mkfs.
+            - Args :
+                - None.
+            - Returns :
+                - True on success, False on failure.
+        """
+        if not os.path.exists(self.dev_path):
+            self.logger.info("ERROR : device path %s is not present.",
+                             self.dev_path)
+            return False
+
+        if not stat.S_ISBLK(os.stat(self.dev_path).st_mode):
+            self.logger.info("ERRO : block device expected for mkfs.")
+            return False
+
+        if self.is_mounted() is True:
+            self.logger.info("ERROR : device is already mounted.")
+            return False
+
+        return True
+
+    def mount(self):
+        """ Check preconditions for the mount operation.
+            - Args :
+                - None.
+            - Returns :
+                - True on success, False on failure.
+        """
+        if not os.path.exists(self.mount_path):
+            try:
+                os.makedirs(self.mount_path)
+            except Exception as err:
+                self.logger.info(str(err))
+                return False
+
+        return True
+
+    def get_mount_path(self):
+        """ Accessor for file system mountpath.
+            - Args :
+                - None.
+            - Returns :
+                - File system mountpath.
+        """
+        # TODO : add mount check here
+        return self.mount_path
+
+    def umount(self):
+        """ Check preconditions for the umount operation.
+            - Args :
+                - None.
+            - Returns :
+                - True on success, False on failure.
+        """
+        if not self.is_mounted():
+            self.logger.info("fs is not mounted")
+            return False
+
+        return True
+
+    def is_mounted(self):
+        """ Check if mount_path is mounted.
+            - Args :
+                - None.
+            - Returns :
+                - True on success, False on failure.
+        """
+        return Cmd.exec_cmd("mountpoint -q " + self.mount_path)
-- 
1.8.3.1

  parent reply	other threads:[~2017-10-25  1:30 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-25  1:30 [PATCH V2 00/46] nvmftests: NVMe Over Fabrics Unit Test Framework Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 01/46] nvmftests: add nvmftests README file Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 02/46] nvmftests-utils: add utility class to define constants Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 03/46] nvmftests-utils: add shell command package Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 04/46] nvmftests-utils: add log package Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 05/46] nvmftests-utils: add diskio package Chaitanya Kulkarni
2017-10-25  1:30 ` Chaitanya Kulkarni [this message]
2017-10-25  1:30 ` [PATCH V2 07/46] nvmftests-utils: add misc package Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 08/46] nvmftests: add utils package Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 09/46] nvmftests-nvmf: add target config generator Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 10/46] nvmftests-nvmf: add support for target ns Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 11/46] nvmftests-nvmf: add support for target port Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 12/46] nvmftests-nvmf: add support for target subsystem Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 13/46] nvmftests-nvmf: add support for target Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 14/46] nvmftests-nvmf: add target package Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 15/46] nvmftests-nvmf: add support for host ns Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 16/46] nvmftests-nvmf: add support for host subsystem Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 17/46] nvmftests-nvmf: add support for host Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 18/46] nvmftests-nvmf: add host package Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 19/46] nvmftests-nvmf: add nvmf core package Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 20/46] nvmftests-tests: add user config file Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 21/46] nvmftests-tests: add support for test logger Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 22/46] nvmftests-tests: add a parent class for tests Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 23/46] nvmftests-tests: add a test for generic block device Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 24/46] nvmftests-tests: add a test for ns-descs Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 25/46] nvmftests-tests: add a test for create/delete host Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 26/46] nvmftests-tests: add a test for NVMe PCIe target ns Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 27/46] nvmftests-tests: add a test to create and delete target Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 28/46] nvmftests-tests: add a test for controller rescan Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 29/46] nvmftests-tests: add a test for controller reset Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 30/46] nvmftests-tests: add a test for get-ns-id Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 31/46] nvmftests-tests: add a test for identify controller Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 32/46] nvmftests-tests: add a test for identify namespace Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 33/46] nvmftests-tests: add a test for smart-log Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 34/46] nvmftests-tests: add a test to run IOs with dd Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 35/46] nvmftests-tests: add a test to run IOs parallely " Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 36/46] nvmftests-tests: add a test to run mkfs and fio Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 37/46] nvmftests-tests: add a test to enable/disable target ns Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 38/46] nvmftests-tests: add a test to run IOs with dd randomly Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 39/46] nvmftests-tests: add a test to scan host ctrls and ns Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 40/46] nvmftests-tests: add a test to scan target subsys/ns Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 41/46] nvmftests-tests: add a target template Chaitanya Kulkarni
2017-10-25  1:30 ` [PATCH V2 42/46] nvmftests-tests: add a host template Chaitanya Kulkarni
2017-10-25  1:31 ` [PATCH V2 43/46] nvmftests-tests: add a test to run traffic and disable ns Chaitanya Kulkarni
2017-10-25  1:31 ` [PATCH V2 44/46] nvmftests-tests: add a test to measure perf with fio Chaitanya Kulkarni
2017-10-25  1:31 ` [PATCH V2 45/46] nvmftests: add class documentation and sequence diagram Chaitanya Kulkarni
2017-10-25  1:31 ` [PATCH V2 46/46] nvmftests: add Makefile Chaitanya Kulkarni
2017-10-25  7:30 ` [PATCH V2 00/46] nvmftests: NVMe Over Fabrics Unit Test Framework Johannes Thumshirn
2018-02-21 13:00 ` Michael Moese

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=1508895063-6280-7-git-send-email-ckulkarnilinux@gmail.com \
    --to=ckulkarnilinux@gmail.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).