From 6634816b0954389cd54e1010f2eef1db0401ee40 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Mon, 7 Jan 2008 16:34:19 +0000
Subject: [PATCH] =?UTF-8?q?Fix=20=E2=80=98make=20distcheck=E2=80=99=20brea?=
 =?UTF-8?q?kage=20introduced=20in=20r455?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This patch fixes the β€˜make distcheck’ breakage caused by missing test data in
the archive and missing handling of builddir!=srcdir case.

Reviewed-by: schreiberal
---
 test/Makefile.am             |  2 +-
 test/ganeti.bdev_unittest.py | 22 +++++++++++++++++++---
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/test/Makefile.am b/test/Makefile.am
index bd221006c..7f9196626 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -11,5 +11,5 @@ check-am: do-pre-check
 do-pre-check:
 	$(MAKE) -C $(top_builddir) pre-check
 
-EXTRA_DIST = $(TESTS) mocks.py
+EXTRA_DIST = $(TESTS) mocks.py data
 CLEANFILES = *.py[co]
diff --git a/test/ganeti.bdev_unittest.py b/test/ganeti.bdev_unittest.py
index 5a775c796..7876f3d54 100755
--- a/test/ganeti.bdev_unittest.py
+++ b/test/ganeti.bdev_unittest.py
@@ -22,6 +22,7 @@
 """Script for unittesting the bdev module"""
 
 
+import os
 import unittest
 
 from ganeti import bdev
@@ -43,6 +44,21 @@ class TestDRBD8Runner(unittest.TestCase):
       )
     return retval
 
+  @staticmethod
+  def _get_contents(name):
+    """Returns the contents of a file"""
+
+    prefix = os.environ.get("srcdir", None)
+    if prefix:
+      name = prefix + "/" + name
+    fh = open(name, "r")
+    try:
+      data = fh.read()
+    finally:
+      fh.close()
+    return data
+
+
   @staticmethod
   def _has_net(data, local, remote):
     """Check network connection parameters"""
@@ -60,7 +76,7 @@ class TestDRBD8Runner(unittest.TestCase):
 
   def testParserBoth(self):
     """Test drbdsetup show parser for disk and network"""
-    data = open("data/bdev-both.txt").read()
+    data = self._get_contents("data/bdev-both.txt")
     result = bdev.DRBD8._GetDevInfo(data)
     self.failUnless(self._has_disk(result, "/dev/xenvg/test.data",
                                    "/dev/xenvg/test.meta"),
@@ -71,7 +87,7 @@ class TestDRBD8Runner(unittest.TestCase):
 
   def testParserNet(self):
     """Test drbdsetup show parser for disk and network"""
-    data = open("data/bdev-net.txt").read()
+    data = self._get_contents("data/bdev-net.txt")
     result = bdev.DRBD8._GetDevInfo(data)
     self.failUnless(("local_dev" not in result and
                      "meta_dev" not in result and
@@ -83,7 +99,7 @@ class TestDRBD8Runner(unittest.TestCase):
 
   def testParserDisk(self):
     """Test drbdsetup show parser for disk and network"""
-    data = open("data/bdev-disk.txt").read()
+    data = self._get_contents("data/bdev-disk.txt")
     result = bdev.DRBD8._GetDevInfo(data)
     self.failUnless(self._has_disk(result, "/dev/xenvg/test.data",
                                    "/dev/xenvg/test.meta"),
-- 
GitLab