Example #1
0
    def test_filesystem_udev_symlink_fsrename_poolrename(self):
        """
        Test the udev symlink creation for filesystem devices after fs and pool rename.
        """
        pool_name = p_n()
        pool_path = make_test_pool(pool_name, StratisCertify.DISKS[0:1])

        fs_name = fs_n()
        filesystem_path = make_test_filesystem(pool_path, fs_name)

        fs_name_rename = fs_n()

        self._unittest_command(
            StratisDbus.fs_rename(pool_name, fs_name, fs_name_rename),
            dbus.UInt16(0))
        # Settle after rename, to allow udev to recognize the filesystem rename
        exec_command(["udevadm", "settle"])

        pool_name_rename = p_n()

        self._unittest_command(
            StratisDbus.pool_rename(pool_name, pool_name_rename),
            dbus.UInt16(0))
        # Settle after rename, to allow udev to recognize the pool rename
        exec_command(["udevadm", "settle"])

        fsdevdest, fsdevmapperlinkdest = acquire_filesystem_symlink_targets(
            pool_name_rename, fs_name_rename, pool_path, filesystem_path)
        self.assertEqual(fsdevdest, fsdevmapperlinkdest)
Example #2
0
    def test_pool_destroy(self):
        """
        Test destroying a pool.
        """
        pool_name = p_n()
        make_test_pool(pool_name, StratisCertify.DISKS[0:1])

        self._unittest_command(StratisDbus.pool_destroy(pool_name), dbus.UInt16(0))

        self.assertEqual(StratisDbus.fs_list(), {})
Example #3
0
        def set_key():
            """
            Set up a keyfile and set the value of the key in the kernel
            keyring.
            """
            with NamedTemporaryFile(mode="w") as temp_file:
                temp_file.write("test-password")
                temp_file.flush()

                StratisDbus.set_key(key_desc, temp_file)
Example #4
0
    def test_pool_destroy(self):
        """
        Test destroying a pool.
        """
        pool_name = p_n()
        make_test_pool(pool_name, DISKS[0:1])

        (_, return_code, _) = StratisDbus.pool_destroy(pool_name)
        self.assertEqual(return_code, dbus.UInt16(0))

        self.assertEqual(StratisDbus.fs_list(), {})
Example #5
0
    def test_get_report(self):
        """
        Test getting a valid and invalid report.
        """
        (result, return_code, _) = StratisDbus.get_report("stopped_pools")
        self._inequality_test(result, dbus.String(""))
        self.assertEqual(return_code, dbus.UInt16(0))
        # Test that we have received valid JSON.
        json.loads(result)

        (result, return_code, _) = StratisDbus.get_report("invalid_report")
        self.assertEqual(result, dbus.String(""))
        self._inequality_test(return_code, dbus.UInt16(0))
Example #6
0
    def test_filesystem_destroy(self):
        """
        Test destroying a filesystem.
        """
        pool_name = p_n()
        pool_path = make_test_pool(pool_name, DISKS[0:1])

        fs_name = fs_n()
        make_test_filesystem(pool_path, fs_name)

        (_, return_code, _) = StratisDbus.fs_destroy(pool_name, fs_name)
        self.assertEqual(return_code, dbus.UInt16(0))

        self.assertEqual(StratisDbus.fs_list(), {})
Example #7
0
    def test_key_set_unset(self):
        """
        Test setting a key.
        """
        key_desc = "test-description"

        with NamedTemporaryFile(mode="w") as temp_file:
            temp_file.write("test-password")
            temp_file.flush()

            self._unittest_command(StratisDbus.set_key(key_desc, temp_file),
                                   dbus.UInt16(0))

        self._unittest_command(StratisDbus.unset_key(key_desc), dbus.UInt16(0))
Example #8
0
    def test_filesystem_destroy(self):
        """
        Test destroying a filesystem.
        """
        pool_name = p_n()
        pool_path = make_test_pool(pool_name, StratisCertify.DISKS[0:1])

        fs_name = fs_n()
        make_test_filesystem(pool_path, fs_name)

        self._unittest_command(StratisDbus.fs_destroy(pool_name, fs_name),
                               dbus.UInt16(0))

        self.assertEqual(StratisDbus.fs_list(), {})
Example #9
0
    def _test_permissions(self,
                          dbus_method,
                          args,
                          permissions,
                          *,
                          kwargs=None):
        """
        Test running dbus_method with and without root permissions.
        :param dbus_method: D-Bus method to be tested
        :type dbus_method: StratisDbus method
        :param args: the arguments to be passed to the D-Bus method
        :type args: list of objects
        :param bool permissions: True if dbus_method needs root permissions to succeed.
                                False if dbus_method should succeed without root permissions.
        :param kwargs: the keyword arguments to be passed to the D-Bus method
        :type kwargs: dict of objects or NoneType
        """
        kwargs = {} if kwargs is None else kwargs

        _permissions_flag = False

        euid = os.geteuid()
        if euid != _ROOT:
            raise RuntimeError(
                f"This process should be running as root, but the current euid is {euid}."
            )

        os.seteuid(_NON_ROOT)
        StratisDbus.reconnect()

        try:
            dbus_method(*args, **kwargs)
        except dbus.exceptions.DBusException as err:
            if err.get_dbus_name(
            ) == "org.freedesktop.DBus.Error.AccessDenied":
                _permissions_flag = True
            else:
                os.seteuid(_ROOT)
                raise err
        except Exception as err:
            os.seteuid(_ROOT)
            raise err

        os.seteuid(_ROOT)
        StratisDbus.reconnect()

        dbus_method(*args, **kwargs)

        self.assertEqual(_permissions_flag, permissions)
Example #10
0
    def test_pool_create_with_cache(self):
        """
        Test creating existing pool with device already used by cache fails
        """
        pool_name = p_n()
        pool_path = make_test_pool(pool_name, StratisCertify.DISKS[0:1])

        self._unittest_command(
            StratisDbus.pool_init_cache(pool_path, StratisCertify.DISKS[1:2]),
            dbus.UInt16(0),
        )
        self._unittest_command(
            StratisDbus.pool_create(pool_name, StratisCertify.DISKS[0:2]),
            dbus.UInt16(1),
        )
Example #11
0
    def test_pool_add_different_data_after_cache(self):
        """
        Test adding a different data device after a cache is created.
        """
        pool_name = p_n()
        pool_path = make_test_pool(pool_name, StratisCertify.DISKS[0:1])

        self._unittest_command(
            StratisDbus.pool_init_cache(pool_path, StratisCertify.DISKS[1:2]),
            dbus.UInt16(0),
        )
        self._unittest_command(
            StratisDbus.pool_add_data(pool_path, StratisCertify.DISKS[2:3]),
            dbus.UInt16(0),
        )
Example #12
0
    def test_pool_create_after_cache(self):
        """
        Test creating existing pool after cache was added
        """
        pool_name = p_n()
        pool_path = make_test_pool(pool_name, StratisCertify.DISKS[0:1])

        self._unittest_command(
            StratisDbus.pool_init_cache(pool_path, StratisCertify.DISKS[1:2]),
            dbus.UInt16(0),
        )
        self._unittest_command(
            StratisDbus.pool_create(pool_name, StratisCertify.DISKS[0:1]),
            dbus.UInt16(0),
        )
Example #13
0
    def test_pool_add_cache(self):
        """
        Test adding cache to a pool.
        """
        pool_name = p_n()
        pool_path = make_test_pool(pool_name, StratisCertify.DISKS[0:1])

        self._unittest_command(
            StratisDbus.pool_init_cache(pool_path, StratisCertify.DISKS[1:2]),
            dbus.UInt16(0),
        )
        self._unittest_command(
            StratisDbus.pool_add_cache(pool_path, StratisCertify.DISKS[2:3]),
            dbus.UInt16(0),
        )
Example #14
0
 def test_filesystem_list_empty(self):
     """
     Test listing an non-existent filesystem.
     """
     result = StratisDbus.fs_list()
     self.assertIsInstance(result, dict)
     self.assertEqual(result, {})
Example #15
0
 def test_pool_create(self):
     """
     Test creating a pool.
     """
     pool_name = p_n()
     (_, return_code, _) = StratisDbus.pool_create(pool_name, DISKS)
     self.assertEqual(return_code, dbus.UInt16(0))
Example #16
0
 def test_blockdev_list(self):
     """
     Test listing a blockdev.
     """
     result = StratisDbus.blockdev_list()
     self.assertIsInstance(result, list)
     self.assertEqual(result, [])
Example #17
0
def acquire_filesystem_symlink_targets(pool_name, filesystem_name, pool_path,
                                       filesystem_path):
    """
    Acquire the symlink targets of the "/dev/stratis" symlink,
    and the equivalent device-mapper "/dev/mapper" link, generated
    via the info from get_managed_objects().
    NOTE: This may require a preceding "udevadm settle" call, to
    ensure that up-to-date pool and filesystem information is being
    collected.
    :param str pool_name: pool name
    :param str filesystem_name: filesystem name
    :param str pool_path: pool path
    :param str filesystem_path: filesystem path
    :return: str fsdevdest, str fsdevmapperlinkdest
    """
    objects = StratisDbus.get_managed_objects()

    pool_gmodata = objects[pool_path]
    pool_uuid = pool_gmodata[StratisDbus.POOL_IFACE]["Uuid"]
    filesystem_gmodata = objects[filesystem_path]
    filesystem_uuid = filesystem_gmodata[StratisDbus.FS_IFACE]["Uuid"]

    filesystem_devnode = "/dev/stratis/" + pool_name + "/" + filesystem_name

    fs_devmapperlinkstr = ("/dev/mapper/stratis-1-" + pool_uuid + "-thin-fs-" +
                           filesystem_uuid)

    fsdevdest = resolve_symlink(filesystem_devnode)
    fsdevmapperlinkdest = resolve_symlink(fs_devmapperlinkstr)
    return fsdevdest, fsdevmapperlinkdest
Example #18
0
    def test_get_keys(self):
        """
        Test getting the Stratis keys in the kernel keyring.
        """

        (_, return_code, _) = StratisDbus.get_keys()
        self.assertEqual(return_code, dbus.UInt16(0))
Example #19
0
 def test_pool_list_empty(self):
     """
     Test listing an non-existent pool.
     """
     result = StratisDbus.pool_list()
     self.assertIsInstance(result, list)
     self.assertEqual(result, [])
Example #20
0
 def test_stratisd_version(self):
     """
     Test getting the daemon version.
     """
     result = StratisDbus.stratisd_version()
     self.assertIsInstance(result, str)
     self.assertNotEqual(result, "")
Example #21
0
    def setUp(self):
        """
        Setup for an individual test.
        * Register a cleanup action, to be run if the test fails.
        * Ensure that stratisd is running via systemd.
        * Use the running stratisd instance to destroy any existing
        Stratis filesystems, pools, etc.
        :return: None
        """
        self.addCleanup(clean_up)

        if process_exists("stratisd") is None:
            exec_command(["systemctl", "start", "stratisd"])
            time.sleep(20)

        StratisDbus.destroy_all()
        assert StratisDbus.pool_list() == []
Example #22
0
    def test_pool_list_not_empty(self):
        """
        Test listing an non-existent pool.
        """
        pool_name = p_n()
        make_test_pool(pool_name, StratisCertify.DISKS[0:1])

        self._inequality_test(StratisDbus.pool_list(), [])
Example #23
0
    def test_pool_create_same_name_different_devices(self):
        """
        Test creating a pool that already exists with different devices.
        """
        pool_name = p_n()
        make_test_pool(pool_name, DISKS[0:1])

        (_, return_code, _) = StratisDbus.pool_create(pool_name, DISKS[1:3])
        self.assertEqual(return_code, dbus.UInt16(1))
Example #24
0
    def test_pool_add_data(self):
        """
        Test adding data to a pool.
        """
        pool_name = p_n()
        pool_path = make_test_pool(pool_name, DISKS[0:2])

        (_, return_code, _) = StratisDbus.pool_add_data(pool_path, DISKS[2:3])
        self.assertEqual(return_code, dbus.UInt16(0))
Example #25
0
    def test_engine_state_report(self):
        """
        Test getting a valid engine state report
        """

        (result, return_code, _) = StratisDbus.get_engine_state_report()
        self._inequality_test(result, dbus.String(""))
        self.assertEqual(return_code, dbus.UInt16(0))
        # Test that we have received valid JSON.
        json.loads(result)
Example #26
0
    def test_pool_create(self):
        """
        Test creating a pool.
        """
        pool_name = p_n()

        self._unittest_command(
            StratisDbus.pool_create(pool_name, StratisCertify.DISKS),
            dbus.UInt16(0),
        )
Example #27
0
    def test_pool_list_not_empty(self):
        """
        Test listing an non-existent pool.
        """
        pool_name = p_n()
        make_test_pool(pool_name, DISKS[0:1])

        result = StratisDbus.pool_list()
        self.assertIsInstance(result, list)
        self.assertNotEqual(result, [])
Example #28
0
    def test_filesystem_list_not_empty(self):
        """
        Test listing an existent filesystem.
        """
        pool_name = p_n()
        pool_path = make_test_pool(pool_name, StratisCertify.DISKS[0:1])

        fs_name = fs_n()
        make_test_filesystem(pool_path, fs_name)

        self._inequality_test(StratisDbus.fs_list(), {})
Example #29
0
    def test_filesystem_create(self):
        """
        Test creating a filesystem.
        """
        pool_name = p_n()
        pool_path = make_test_pool(pool_name, StratisCertify.DISKS[0:1])

        fs_name = fs_n()

        self._unittest_command(StratisDbus.fs_create(pool_path, fs_name),
                               dbus.UInt16(0))
Example #30
0
    def test_pool_create_same_name_different_devices(self):
        """
        Test creating a pool that already exists with different devices.
        """
        pool_name = p_n()
        make_test_pool(pool_name, StratisCertify.DISKS[0:1])

        self._unittest_command(
            StratisDbus.pool_create(pool_name, StratisCertify.DISKS[1:3]),
            dbus.UInt16(1),
        )