+ st = os.stat(file_name)
+ actual_mode = stat.S_IMODE(st.st_mode)
+ self.assertEqual(actual_mode, expected_mode)
+
+ def assertEqualValues(self, first, second, msg=None):
+ """Compares two values whether they're equal.
+
+ Tuples are automatically converted to lists before comparing.
+
+ """
+ return self.assertEqual(UnifyValueType(first),
+ UnifyValueType(second),
+ msg=msg)
+
+ @staticmethod
+ def _TestDataFilename(name):
+ """Returns the filename of a given test data file.
+
+ @type name: str
+ @param name: the 'base' of the file name, as present in
+ the test/data directory
+ @rtype: str
+ @return: the full path to the filename, such that it can
+ be used in 'make distcheck' rules
+
+ """
+ return "%s/test/data/%s" % (GetSourceDir(), name)
+
+ @classmethod
+ def _ReadTestData(cls, name):
+ """Returns the contents of a test data file.
+
+ This is just a very simple wrapper over utils.ReadFile with the
+ proper test file name.
+
+ """
+ return utils.ReadFile(cls._TestDataFilename(name))
+
+ def _CreateTempFile(self):
+ """Creates a temporary file and adds it to the internal cleanup list.
+
+ This method simplifies the creation and cleanup of temporary files
+ during tests.
+
+ """
+ fh, fname = tempfile.mkstemp(prefix="ganeti-test", suffix=".tmp")
+ os.close(fh)
+ self._temp_files.append(fname)
+ return fname
+
+
+def UnifyValueType(data):
+ """Converts all tuples into lists.
+
+ This is useful for unittests where an external library doesn't keep types.
+
+ """
+ if isinstance(data, (tuple, list)):
+ return [UnifyValueType(i) for i in data]
+
+ elif isinstance(data, dict):
+ return dict([(UnifyValueType(key), UnifyValueType(value))
+ for (key, value) in data.iteritems()])
+
+ return data