Ejemplo n.º 1
0
    def test_storage_device(self):
        # Check that / and NUL are rejected along with . and ..
        good_names = ['sda1', '1sda', 'good-name', 'cciss/c0d0']
        bad_names = ['sda/1', 'sda\x00', '.', '..', 'cciss/..']

        sd = StorageDevice("tester")

        for name in good_names:
            self.assertTrue(sd.is_name_valid(name))

        for name in bad_names:
            self.assertFalse(sd.is_name_valid(name))
Ejemplo n.º 2
0
    def test_storage_device(self):
        # Check that / and NUL are rejected along with . and ..
        good_names = ['sda1', '1sda', 'good-name', 'cciss/c0d0']
        bad_names = ['sda/1', 'sda\x00', '.', '..', 'cciss/..']

        sd = StorageDevice("tester")

        for name in good_names:
            self.assertTrue(sd.is_name_valid(name))

        for name in bad_names:
            self.assertFalse(sd.is_name_valid(name))
Ejemplo n.º 3
0
    def test_storage_device(self, *patches):  # pylint: disable=unused-argument
        # Check that / and NUL are rejected along with . and ..
        good_names = ['sda1', '1sda', 'good-name', 'cciss/c0d0']
        bad_names = ['sda/1', 'sda\x00', '.', '..', 'cciss/..']

        sd = StorageDevice("tester")

        for name in good_names:
            self.assertTrue(sd.is_name_valid(name))

        for name in bad_names:
            self.assertFalse(sd.is_name_valid(name))

        # Check that name validity check is omitted (only) when
        # device already exists
        # This test was added to prevent regression (see #1379145)
        for name in good_names:
            try:
                StorageDevice(name, exists=True)
            except ValueError:
                self.fail("Name check should not be performed nor failing")

            try:
                StorageDevice(name, exists=False)
            except ValueError:
                self.fail("Device name check failed when it shouldn't")

        for name in bad_names:
            try:
                StorageDevice(name, exists=True)
            except ValueError as e:
                if ' is not a valid name for this device' in str(e):
                    self.fail("Device name checked on already existing device")

            with six.assertRaisesRegex(self, ValueError,
                                       ' is not a valid name for this device'):
                StorageDevice(name, exists=False)
Ejemplo n.º 4
0
    def test_storage_device(self, *patches):  # pylint: disable=unused-argument
        # Check that / and NUL are rejected along with . and ..
        good_names = ['sda1', '1sda', 'good-name', 'cciss/c0d0']
        bad_names = ['sda/1', 'sda\x00', '.', '..', 'cciss/..']

        sd = StorageDevice("tester")

        for name in good_names:
            self.assertTrue(sd.is_name_valid(name))

        for name in bad_names:
            self.assertFalse(sd.is_name_valid(name))

        # Check that name validity check is omitted (only) when
        # device already exists
        # This test was added to prevent regression (see #1379145)
        for name in good_names:
            try:
                StorageDevice(name, exists=True)
            except ValueError:
                self.fail("Name check should not be performed nor failing")

            try:
                StorageDevice(name, exists=False)
            except ValueError:
                self.fail("Device name check failed when it shouldn't")

        for name in bad_names:
            try:
                StorageDevice(name, exists=True)
            except ValueError as e:
                if ' is not a valid name for this device' in str(e):
                    self.fail("Device name checked on already existing device")

            with six.assertRaisesRegex(self, ValueError, ' is not a valid name for this device'):
                StorageDevice(name, exists=False)