summaryrefslogtreecommitdiffstats
path: root/test/test-nvme_options.py
diff options
context:
space:
mode:
authorBenjamin Drung <bdrung@debian.org>2023-06-10 08:55:33 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-06-10 09:21:49 +0000
commit88837172f69eabc408ae3945d82e0270b8e07440 (patch)
treed6b7fa06694f45d25f54f6ea9ded93c981e51f6f /test/test-nvme_options.py
parentInitial commit. (diff)
downloadnvme-stas-88837172f69eabc408ae3945d82e0270b8e07440.tar.xz
nvme-stas-88837172f69eabc408ae3945d82e0270b8e07440.zip
Adding upstream version 2.2.1.upstream/2.2.1
Signed-off-by: Benjamin Drung <bdrung@debian.org>
Diffstat (limited to 'test/test-nvme_options.py')
-rwxr-xr-xtest/test-nvme_options.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/test/test-nvme_options.py b/test/test-nvme_options.py
new file mode 100755
index 0000000..428f22a
--- /dev/null
+++ b/test/test-nvme_options.py
@@ -0,0 +1,61 @@
+#!/usr/bin/python3
+import os
+import logging
+import unittest
+from staslib import conf, log
+from pyfakefs.fake_filesystem_unittest import TestCase
+
+
+class Test(TestCase):
+ """Unit tests for class NvmeOptions"""
+
+ def setUp(self):
+ self.setUpPyfakefs()
+ log.init(syslog=False)
+ self.logger = logging.getLogger()
+ self.logger.setLevel(logging.INFO)
+
+ def tearDown(self):
+ # No longer need self.tearDownPyfakefs()
+ pass
+
+ def test_fabrics_empty_file(self):
+ self.assertFalse(os.path.exists("/dev/nvme-fabrics"))
+ # TODO: this is a bug
+ self.fs.create_file("/dev/nvme-fabrics")
+ self.assertTrue(os.path.exists('/dev/nvme-fabrics'))
+ nvme_options = conf.NvmeOptions()
+ self.assertIsInstance(nvme_options.discovery_supp, bool)
+ self.assertIsInstance(nvme_options.host_iface_supp, bool)
+ del nvme_options
+
+ def test_fabrics_wrong_file(self):
+ self.assertFalse(os.path.exists("/dev/nvme-fabrics"))
+ self.fs.create_file("/dev/nvme-fabrics", contents="blah")
+ self.assertTrue(os.path.exists('/dev/nvme-fabrics'))
+ nvme_options = conf.NvmeOptions()
+ self.assertIsInstance(nvme_options.discovery_supp, bool)
+ self.assertIsInstance(nvme_options.host_iface_supp, bool)
+ del nvme_options
+
+ def test_fabrics_correct_file(self):
+ self.assertFalse(os.path.exists("/dev/nvme-fabrics"))
+ self.fs.create_file(
+ '/dev/nvme-fabrics', contents='host_iface=%s,discovery,dhchap_secret=%s,dhchap_ctrl_secret=%s\n'
+ )
+ self.assertTrue(os.path.exists('/dev/nvme-fabrics'))
+ nvme_options = conf.NvmeOptions()
+ self.assertTrue(nvme_options.discovery_supp)
+ self.assertTrue(nvme_options.host_iface_supp)
+ self.assertTrue(nvme_options.dhchap_hostkey_supp)
+ self.assertTrue(nvme_options.dhchap_ctrlkey_supp)
+ self.assertEqual(
+ nvme_options.get(),
+ {'discovery': True, 'host_iface': True, 'dhchap_secret': True, 'dhchap_ctrl_secret': True},
+ )
+ self.assertTrue(str(nvme_options).startswith("supported options:"))
+ del nvme_options
+
+
+if __name__ == "__main__":
+ unittest.main()