Skip to content

Commit

Permalink
tests/fsuuid: Implement checking invalid UUIDs
Browse files Browse the repository at this point in the history
So far we only have tested valid UUIDs properly, while we had a test
using invalid UUIDs the test was more or less a no-op, because during
creation no error is thrown if we use an invalid UUID.

Rather than throwing an error the create() method logs a warning, which
we now verify using assertLogs test_set_invalid_uuid().

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
  • Loading branch information
aszlig committed Jan 28, 2017
1 parent 64ce958 commit e357807
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions tests/formats_test/fsuuid.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import sys
import abc
from six import add_metaclass
from unittest import skipIf

from tests import loopbackedtestcase
from blivet.devicetree import DeviceTree
from blivet.errors import FSError, FSWriteUUIDError
from blivet.size import Size


Expand Down Expand Up @@ -37,13 +40,21 @@ class SetUUIDWithMkFs(SetUUID):
native mkfs tool can set the UUID.
"""

def test_set_uuid(self):
@skipIf(sys.version_info < (3, 4), "assertLogs is not supported")
def test_set_invalid_uuid(self):
"""Create the filesystem with an invalid UUID."""
an_fs = self._fs_class(device=self.loop_devices[0],
uuid=self._invalid_uuid)
self.assertIsNone(an_fs.create())
if self._fs_class._type == "swap":
with self.assertRaisesRegex(FSWriteUUIDError, "bad UUID format"):
an_fs.create()
else:
with self.assertLogs('blivet', 'WARNING') as logs:
an_fs.create()
self.assertTrue(len(logs.output) >= 1)
self.assertRegex(logs.output[0], "UUID format.*unacceptable")

def test_creating(self):
def test_set_uuid(self):
"""Create the filesystem with a valid UUID."""
an_fs = self._fs_class(device=self.loop_devices[0],
uuid=self._valid_uuid)
Expand Down Expand Up @@ -87,3 +98,14 @@ def test_set_uuid_later(self):
dt.populate()
device = dt.get_device_by_path(self.loop_devices[0])
self.assertEqual(device.format.uuid, self._valid_uuid)

def test_set_invalid_uuid_later(self):
"""Create the filesystem and try to reassign an invalid UUID later."""
an_fs = self._fs_class(device=self.loop_devices[0])
if an_fs._writeuuid.availability_errors:
self.skipTest("can not write UUID for filesystem %s" % an_fs.name)
self.assertIsNone(an_fs.create())

an_fs.uuid = self._invalid_uuid
with self.assertRaisesRegex(FSError, "bad UUID format"):
an_fs.write_uuid()

0 comments on commit e357807

Please sign in to comment.