From: ckulkarnilinux@gmail.com (Chaitanya Kulkarni)
Subject: [PATCH V2 11/46] nvmftests-nvmf: add support for target port
Date: Tue, 24 Oct 2017 18:30:28 -0700 [thread overview]
Message-ID: <1508895063-6280-12-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 a new class to handle the target port operations.
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni at wdc.com>
---
.../selftests/nvmftests/nvmf/target/port.py | 122 +++++++++++++++++++++
1 file changed, 122 insertions(+)
create mode 100644 tools/testing/selftests/nvmftests/nvmf/target/port.py
diff --git a/tools/testing/selftests/nvmftests/nvmf/target/port.py b/tools/testing/selftests/nvmftests/nvmf/target/port.py
new file mode 100644
index 0000000..a622ea2
--- /dev/null
+++ b/tools/testing/selftests/nvmftests/nvmf/target/port.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 NVMe Over Fabric Target Port.
+"""
+
+import os
+import shutil
+
+from utils.shell import Cmd
+from utils.const import Const
+from utils.log import Log
+
+
+class NVMFTargetPort(object):
+ """
+ Represents a target port.
+
+ - Attributes :
+ - cfgfs : configfs mountpoint.
+ - port_id : port identification number.
+ - port_path : port path in configfs.
+ - port_conf : dictionary to hold the port attributes.
+ """
+ def __init__(self, cfgfs, port_id, **port_conf):
+ self.cfgfs = cfgfs
+ self.port_id = port_id
+ self.port_path = self.cfgfs + "/nvmet/ports/" + port_id + "/"
+ self.port_conf = {}
+ self.port_conf['addr_treq'] = port_conf['addr_treq']
+ self.port_conf['addr_traddr'] = port_conf['addr_traddr']
+ self.port_conf['addr_trtype'] = port_conf['addr_trtype']
+ self.port_conf['addr_adrfam'] = port_conf['addr_adrfam']
+ self.port_conf['addr_trsvcid'] = port_conf['addr_trsvcid']
+ self.port_conf['referrals'] = Const.XXX
+ self.port_conf['subsystems'] = port_conf['subsystems']
+ self.logger = Log.get_logger(__name__, 'port')
+
+ def init(self):
+ """ Create and initialize port.
+ - Args :
+ - None.
+ - Returns :
+ - True on success, False on failure.
+ """
+ if self.port_conf['addr_trtype'] != "loop":
+ self.logger.error("only loop transport type is supported.")
+ return False
+
+ ret = Cmd.exec_cmd("mkdir -p " + self.port_path)
+ if ret is False:
+ self.logger.error("failed to create " + self.port_path + ".")
+ return False
+
+ # initialize transport type
+ self.logger.info("Port " + self.port_path + " created successfully.")
+
+ ret = Cmd.exec_cmd("echo -n \"" + self.port_conf['addr_trtype'] +
+ "\" > " + self.port_path + "/addr_trtype")
+ if ret is False:
+ status = "trtype " + self.port_path + " failed."
+ self.logger.error(status)
+ else:
+ status = "Port " + self.port_path + " initialized successfully."
+ self.logger.info(status)
+ return ret
+
+ def add_subsys(self, subsys_name):
+ """ Link Subsystem to this port.
+ - Args :
+ - subsys_name : subsystem nqn to be linked.
+ - Returns :
+ - True on success, False on failure.
+ """
+ src = self.cfgfs + "/nvmet/subsystems/" + subsys_name
+ if not os.path.exists(src):
+ self.logger.error("subsystem '" + src + "' not present.")
+ return False
+ dest = self.port_path + "/subsystems/"
+ cmd = "ln -s " + src + " " + dest
+ self.logger.info(cmd)
+ return Cmd.exec_cmd(cmd)
+
+ def delete(self):
+ """ Delete this port.
+ - Args :
+ - None.
+ -Returns :
+ - True on success, False on failure.
+ """
+ self.logger.info("Deleting port " + self.port_id + ".")
+ subsys_symlink = self.port_path + "/subsystem/"
+ try:
+
+ if os.path.isdir(subsys_symlink):
+ shutil.rmtree(subsys_symlink, ignore_errors=True)
+ self.logger.info("Unlink subsystem fromn port successfully.")
+
+ if os.path.isdir(self.port_path):
+ shutil.rmtree(self.port_path, ignore_errors=True)
+
+ except Exception, err:
+ self.logger.error(str(err) + ".")
+ return False
+ self.logger.info("Removed port " + self.port_path + " successfully.")
+ return True
--
1.8.3.1
next prev 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 ` [PATCH V2 06/46] nvmftests-utils: add fs package Chaitanya Kulkarni
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 ` Chaitanya Kulkarni [this message]
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-12-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).