예제 #1
0
    def testCreate(self):
        """
        Type of result should always be correct.

        If rc is OK, then pool must exist.
        """
        devs = _DEVICE_STRATEGY()
        ((poolpath, devnodes), rc,
         _) = Manager.Methods.CreatePool(self._proxy, {
             'name': self._POOLNAME,
             'redundancy': (True, 0),
             'devices': devs
         })

        managed_objects = \
           ObjectManager.Methods.GetManagedObjects(self._proxy, {})
        all_pools = [x for x in pools().search(managed_objects)]
        result = next(
            pools(props={
                'Name': self._POOLNAME
            }).search(managed_objects), None)

        if rc == StratisdErrors.OK:
            self.assertIsNotNone(result)
            (pool, table) = result
            self.assertEqual(pool, poolpath)
            self.assertEqual(len(all_pools), 1)
            self.assertLessEqual(len(devnodes), len(devs))

            pool_info = MOPool(table)
            self.assertLessEqual(int(pool_info.TotalPhysicalUsed()),
                                 int(pool_info.TotalPhysicalSize()))
        else:
            self.assertIsNone(result)
            self.assertEqual(len(all_pools), 0)
예제 #2
0
    def _test_cap_size(self, pool_name, prediction):
        """
        Helper function to verify that the cap device is the correct size.

        :param str pool_name: the name of the pool to test
        :param prediction: JSON output from script
        """
        proxy = get_object(TOP_OBJECT)
        managed_objects = ObjectManager.Methods.GetManagedObjects(proxy, {})

        _pool_object_path, pool = next(
            pools(props={
                "Name": pool_name
            }).require_unique_match(True).search(managed_objects))

        pool_uuid = MOPool(pool).Uuid()

        cap_name = self._CAP_DEVICE_STR % pool_uuid

        with subprocess.Popen(
            ["blockdev", "--getsize64",
             "/dev/mapper/%s" % cap_name],
                stdout=subprocess.PIPE,
                universal_newlines=True,
        ) as command:
            cap_device_size, _ = command.communicate()
            self.assertEqual(cap_device_size.rstrip("\n"), prediction["free"])
예제 #3
0
    def _test_prediction(self, pool_name, *, fs_specs=None, overprovision=True):
        """
        Helper function to verify that the prediction matches the reality to
        an acceptable degree.

        :param str pool_name: the name of the pool to test
        :param fs_specs: filesystems to create and test
        :type fs_specs: list of of str * Range or NoneType
        :param bool overprovision: True if overprovisioning is allowed
        """
        proxy = get_object(TOP_OBJECT)

        managed_objects = ObjectManager.Methods.GetManagedObjects(proxy, {})

        pool_object_path, pool = next(
            pools(props={"Name": pool_name})
            .require_unique_match(True)
            .search(managed_objects)
        )

        mopool = MOPool(pool)

        physical_sizes = _get_block_device_sizes(pool_object_path, managed_objects)
        pre_prediction = _call_predict_usage(
            mopool.Encrypted(), physical_sizes, overprovision=overprovision
        )

        self._check_prediction(pre_prediction, mopool)

        change = _possibly_add_filesystems(pool_object_path, fs_specs=fs_specs)

        post_prediction = _call_predict_usage(
            mopool.Encrypted(),
            physical_sizes,
            fs_specs=fs_specs,
            overprovision=overprovision,
        )

        self._check_fs_prediction(
            pre_prediction, post_prediction, change, overprovision=overprovision
        )
예제 #4
0
def get_pools(name=None):
    """
    Returns a list of all pools found by GetManagedObjects, or a list
    of pools with names matching the specified name, if passed.
    :param name: filter for pool name
    :type name: str or NoneType
    :return: list of pool information found
    :rtype: list of (str * MOPool)
    """
    managed_objects = ObjectManager.Methods.GetManagedObjects(
        get_object(TOP_OBJECT), {})

    return [(op, MOPool(info))
            for op, info in pools(props={} if name is None else {
                "Name": name
            }).search(managed_objects)]