Nir Soffer has uploaded a new change for review.
Change subject: tests: Add storage mailbox tests
......................................................................
tests: Add storage mailbox tests
Use fake repository for testing the content of the storage mailbox
without using real block devices.
Change-Id: If02ed99b95dfd0d6bc5cc9694e60c3808d0974aa
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
M tests/Makefile.am
A tests/mailboxTests.py
2 files changed, 91 insertions(+), 0 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/71/29371/1
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6507165..a1fd385 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -46,6 +46,7 @@
libvirtconnectionTests.py \
lsblkTests.py \
lvmTests.py \
+ mailboxTests.py \
main.py \
md_utils_tests.py \
miscTests.py \
diff --git a/tests/mailboxTests.py b/tests/mailboxTests.py
new file mode 100644
index 0000000..ec6854c
--- /dev/null
+++ b/tests/mailboxTests.py
@@ -0,0 +1,90 @@
+import ConfigParser
+import errno
+import os
+import time
+
+from storage import sd
+from storage import storage_mailbox
+from vdsm import config
+
+from testrunner import VdsmTestCase as TestCaseBase
+import monkeypatch
+
+# Don't use /tmp, as O_DIRECT does not work with tempfs file system. Keeping
+# the test files in the source is ugly but make it very easy to debug the
+# mailbox content.
+REPO_DIR = 'mailboxTests.tmp'
+
+HOST_ID = 1
+POOL_ID = 'pool'
+MD_DIR = os.path.join(REPO_DIR, POOL_ID, "mastersd", sd.DOMAIN_META_DATA)
+INBOX = os.path.join(MD_DIR, "inbox")
+OUTBOX = os.path.join(MD_DIR, "outbox")
+MAX_HOSTS = 2000
+
+# U (0x55) is a nice initial value
+DIRTY_MAILBOX = 'U' * storage_mailbox.MAILBOX_SIZE
+
+fake_config = ConfigParser.ConfigParser()
+config.set_defaults(fake_config)
+fake_config.set('irs', 'repository', REPO_DIR)
+
+
+class HSMMailboxTests(TestCaseBase):
+
+ def setUp(self):
+ # Note: we don't remove the inbox and outbox when test ends to make it
+ # eaiser to debug by checking inbox and outbox content after a test
+ # fails.
+ create_repository()
+ init_mailbox(INBOX)
+ init_mailbox(OUTBOX)
+
+ @monkeypatch.MonkeyPatch(storage_mailbox, 'config', fake_config)
+ def test_init_inbox(self):
+ mailer = storage_mailbox.HSM_Mailbox(HOST_ID, POOL_ID)
+ try:
+ time.sleep(0.5)
+ with open(INBOX) as f:
+ # First mailbox is not used
+ data = f.read(storage_mailbox.MAILBOX_SIZE)
+ self.assertEquals(data, DIRTY_MAILBOX)
+ # When mailbox is started, it clears the host inbox
+ data = f.read(storage_mailbox.MAILBOX_SIZE)
+ self.assertEquals(data, storage_mailbox.EMPTYMAILBOX)
+ # This mailbox belong to another host, and should not change
+ data = f.read(storage_mailbox.MAILBOX_SIZE)
+ self.assertEquals(data, DIRTY_MAILBOX)
+ finally:
+ mailer.stop()
+
+ @monkeypatch.MonkeyPatch(storage_mailbox, 'config', fake_config)
+ def test_keep_outbox(self):
+ mailer = storage_mailbox.HSM_Mailbox(HOST_ID, POOL_ID)
+ try:
+ time.sleep(0.5)
+ with open(OUTBOX) as f:
+ # First mailbox is not used
+ data = f.read(storage_mailbox.MAILBOX_SIZE)
+ self.assertEquals(data, DIRTY_MAILBOX)
+ # Outbox is not touched
+ data = f.read(storage_mailbox.MAILBOX_SIZE)
+ self.assertEquals(data, DIRTY_MAILBOX)
+ # This mailbox belong to another host, and should not change
+ data = f.read(storage_mailbox.MAILBOX_SIZE)
+ self.assertEquals(data, DIRTY_MAILBOX)
+ finally:
+ mailer.stop()
+
+
+def init_mailbox(path):
+ with open(path, 'w') as f:
+ f.write(DIRTY_MAILBOX * MAX_HOSTS)
+
+
+def create_repository():
+ try:
+ os.makedirs(MD_DIR)
+ except OSError as e:
+ if e.errno != errno.EEXIST:
+ raise
--
To view, visit
http://gerrit.ovirt.org/29371
To unsubscribe, visit
http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If02ed99b95dfd0d6bc5cc9694e60c3808d0974aa
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer(a)redhat.com>