Exemplo n.º 1
0
 def __init__(self, host, cluster_name, capabilities, pool_name):
     new_host = vol_utils.append_host(host, pool_name)
     new_cluster = vol_utils.append_host(cluster_name, pool_name)
     super(PoolState, self).__init__(new_host, new_cluster, capabilities)
     self.pool_name = pool_name
     # No pools in pool
     self.pools = None
Exemplo n.º 2
0
 def __init__(self, host, cluster_name, capabilities, pool_name):
     new_host = vol_utils.append_host(host, pool_name)
     new_cluster = vol_utils.append_host(cluster_name, pool_name)
     super(PoolState, self).__init__(new_host, new_cluster, capabilities)
     self.pool_name = pool_name
     # No pools in pool
     self.pools = None
Exemplo n.º 3
0
 def __init__(self, host, capabilities, pool_name):
     new_host = vol_utils.append_host(host, pool_name)
     super(PoolState, self).__init__(new_host, capabilities)
     self.pool_name = pool_name
     # No pools in pool
     self.pools = None
     self.num_io_ops = 0
Exemplo n.º 4
0
 def __init__(self, host, capabilities, pool_name):
     new_host = vol_utils.append_host(host, pool_name)
     super(PoolState, self).__init__(new_host, capabilities)
     self.pool_name = pool_name
     # No pools in pool
     self.pools = None
     self.num_io_ops = 0
Exemplo n.º 5
0
    def get_pools(self, context, filters=None):
        """Returns a dict of all pools on all hosts HostManager knows about."""

        self._update_backend_state_map(context)

        all_pools = []
        name = None
        if filters:
            name = filters.pop('name', None)

        for backend_key, state in self.backend_state_map.items():
            for key in state.pools:
                filtered = False
                pool = state.pools[key]
                # use backend_key.pool_name to make sure key is unique
                pool_key = vol_utils.append_host(backend_key, pool.pool_name)
                new_pool = dict(name=pool_key)
                new_pool.update(dict(capabilities=pool.capabilities))

                if name and new_pool.get('name') != name:
                    continue

                if filters:
                    # filter all other items in capabilities
                    for (attr, value) in filters.items():
                        cap = new_pool.get('capabilities').get(attr)
                        if not self._equal_after_convert(cap, value):
                            filtered = True
                            break

                if not filtered:
                    all_pools.append(new_pool)

        return all_pools
Exemplo n.º 6
0
    def test_init_host_count_allocated_capacity(self, init_host_mock,
                                                mock_listdir):
        mock_listdir.return_value = []
        vol0 = tests_utils.create_volume(self.context,
                                         size=100,
                                         host=CONF.host)
        vol1 = tests_utils.create_volume(self.context,
                                         size=128,
                                         host=volutils.append_host(
                                             CONF.host, 'pool0'))
        vol2 = tests_utils.create_volume(self.context,
                                         size=256,
                                         host=volutils.append_host(
                                             CONF.host, 'pool0'))
        vol3 = tests_utils.create_volume(self.context,
                                         size=512,
                                         host=volutils.append_host(
                                             CONF.host, 'pool1'))
        vol4 = tests_utils.create_volume(self.context,
                                         size=1024,
                                         host=volutils.append_host(
                                             CONF.host, 'pool2'))
        self.volume.init_host(service_id=self.service_id)
        init_host_mock.assert_called_once_with(service_id=self.service_id,
                                               added_to_cluster=None)
        stats = self.volume.stats
        self.assertEqual(2020, stats['allocated_capacity_gb'])
        self.assertEqual(384, stats['pools']['pool0']['allocated_capacity_gb'])
        self.assertEqual(512, stats['pools']['pool1']['allocated_capacity_gb'])
        self.assertEqual(1024,
                         stats['pools']['pool2']['allocated_capacity_gb'])

        # NOTE(jdg): On the create we have host='xyz', BUT
        # here we do a db.volume_get, and now the host has
        # been updated to xyz#pool-name.  Note this is
        # done via the managers init, which calls the drivers
        # get_pool method, which in the legacy case is going
        # to be volume_backend_name or None

        vol0.refresh()
        expected_host = volutils.append_host(CONF.host, 'fake')
        self.assertEqual(expected_host, vol0.host)
        self.volume.delete_volume(self.context, vol0)
        self.volume.delete_volume(self.context, vol1)
        self.volume.delete_volume(self.context, vol2)
        self.volume.delete_volume(self.context, vol3)
        self.volume.delete_volume(self.context, vol4)
Exemplo n.º 7
0
    def test_append_host(self):
        host = 'Host'
        pool = 'Pool'
        expected = 'Host#Pool'
        self.assertEqual(expected, volume_utils.append_host(host, pool))

        pool = None
        expected = 'Host'
        self.assertEqual(expected, volume_utils.append_host(host, pool))

        host = None
        pool = 'pool'
        expected = None
        self.assertEqual(expected, volume_utils.append_host(host, pool))

        host = None
        pool = None
        expected = None
        self.assertEqual(expected, volume_utils.append_host(host, pool))
Exemplo n.º 8
0
    def test_append_host(self):
        host = "Host"
        pool = "Pool"
        expected = "Host#Pool"
        self.assertEqual(expected, volume_utils.append_host(host, pool))

        pool = None
        expected = "Host"
        self.assertEqual(expected, volume_utils.append_host(host, pool))

        host = None
        pool = "pool"
        expected = None
        self.assertEqual(expected, volume_utils.append_host(host, pool))

        host = None
        pool = None
        expected = None
        self.assertEqual(expected, volume_utils.append_host(host, pool))
Exemplo n.º 9
0
    def test_init_host_count_allocated_capacity(self, init_host_mock):
        vol0 = tests_utils.create_volume(
            self.context, size=100, host=CONF.host)
        vol1 = tests_utils.create_volume(
            self.context, size=128,
            host=volutils.append_host(CONF.host, 'pool0'))
        vol2 = tests_utils.create_volume(
            self.context, size=256,
            host=volutils.append_host(CONF.host, 'pool0'))
        vol3 = tests_utils.create_volume(
            self.context, size=512,
            host=volutils.append_host(CONF.host, 'pool1'))
        vol4 = tests_utils.create_volume(
            self.context, size=1024,
            host=volutils.append_host(CONF.host, 'pool2'))
        self.volume.init_host(service_id=self.service_id)
        init_host_mock.assert_called_once_with(
            service_id=self.service_id, added_to_cluster=None)
        stats = self.volume.stats
        self.assertEqual(2020, stats['allocated_capacity_gb'])
        self.assertEqual(
            384, stats['pools']['pool0']['allocated_capacity_gb'])
        self.assertEqual(
            512, stats['pools']['pool1']['allocated_capacity_gb'])
        self.assertEqual(
            1024, stats['pools']['pool2']['allocated_capacity_gb'])

        # NOTE(jdg): On the create we have host='xyz', BUT
        # here we do a db.volume_get, and now the host has
        # been updated to xyz#pool-name.  Note this is
        # done via the managers init, which calls the drivers
        # get_pool method, which in the legacy case is going
        # to be volume_backend_name or None

        vol0.refresh()
        expected_host = volutils.append_host(CONF.host, 'fake')
        self.assertEqual(expected_host, vol0.host)
        self.volume.delete_volume(self.context, vol0)
        self.volume.delete_volume(self.context, vol1)
        self.volume.delete_volume(self.context, vol2)
        self.volume.delete_volume(self.context, vol3)
        self.volume.delete_volume(self.context, vol4)
Exemplo n.º 10
0
    def test_append_host(self):
        host = 'Host'
        pool = 'Pool'
        expected = 'Host#Pool'
        self.assertEqual(expected,
                         volume_utils.append_host(host, pool))

        pool = None
        expected = 'Host'
        self.assertEqual(expected,
                         volume_utils.append_host(host, pool))

        host = None
        pool = 'pool'
        expected = None
        self.assertEqual(expected,
                         volume_utils.append_host(host, pool))

        host = None
        pool = None
        expected = None
        self.assertEqual(expected,
                         volume_utils.append_host(host, pool))
Exemplo n.º 11
0
    def get_pools(self, context):
        """Returns a dict of all pools on all hosts HostManager knows about."""

        all_pools = []
        for host, state in self.host_state_map.items():
            for key in state.pools:
                pool = state.pools[key]
                # use host.pool_name to make sure key is unique
                pool_key = vol_utils.append_host(host, pool.pool_name)
                new_pool = dict(name=pool_key)
                new_pool.update(dict(capabilities=pool.capabilities))
                all_pools.append(new_pool)

        return all_pools
Exemplo n.º 12
0
    def get_pools(self, context):
        """Returns a dict of all pools on all hosts HostManager knows about."""

        all_pools = []
        for host, state in self.host_state_map.items():
            for key in state.pools:
                pool = state.pools[key]
                # use host.pool_name to make sure key is unique
                pool_key = vol_utils.append_host(host, pool.pool_name)
                new_pool = dict(name=pool_key)
                new_pool.update(dict(capabilities=pool.capabilities))
                all_pools.append(new_pool)

        return all_pools
Exemplo n.º 13
0
    def get_pools(self, context, filters=None):
        """Returns a dict of all pools on all hosts HostManager knows about."""

        self._update_backend_state_map(context)

        all_pools = {}
        name = volume_type = None
        if filters:
            name = filters.pop('name', None)
            volume_type = filters.pop('volume_type', None)

        for backend_key, state in self.backend_state_map.items():
            for key in state.pools:
                filtered = False
                pool = state.pools[key]
                # use backend_key.pool_name to make sure key is unique
                pool_key = vol_utils.append_host(backend_key, pool.pool_name)
                new_pool = dict(name=pool_key)
                new_pool.update(dict(capabilities=pool.capabilities))

                if name and new_pool.get('name') != name:
                    continue

                if filters:
                    # filter all other items in capabilities
                    for (attr, value) in filters.items():
                        cap = new_pool.get('capabilities').get(attr)
                        if not self._equal_after_convert(cap, value):
                            filtered = True
                            break

                if not filtered:
                    all_pools[pool_key] = pool

        # filter pools by volume type
        if volume_type:
            volume_type = volume_types.get_by_name_or_id(
                context, volume_type)
            all_pools = (
                self._filter_pools_by_volume_type(context,
                                                  volume_type,
                                                  all_pools))

        # encapsulate pools in format:{name: XXX, capabilities: XXX}
        return [dict(name=key, capabilities=value.capabilities)
                for key, value in all_pools.items()]
Exemplo n.º 14
0
    def get_pools(self, context, filters=None):
        """Returns a dict of all pools on all hosts HostManager knows about."""

        self._update_backend_state_map(context)

        all_pools = {}
        name = volume_type = None
        if filters:
            name = filters.pop('name', None)
            volume_type = filters.pop('volume_type', None)

        for backend_key, state in self.backend_state_map.items():
            for key in state.pools:
                filtered = False
                pool = state.pools[key]
                # use backend_key.pool_name to make sure key is unique
                pool_key = vol_utils.append_host(backend_key, pool.pool_name)
                new_pool = dict(name=pool_key)
                new_pool.update(dict(capabilities=pool.capabilities))

                if name and new_pool.get('name') != name:
                    continue

                if filters:
                    # filter all other items in capabilities
                    for (attr, value) in filters.items():
                        cap = new_pool.get('capabilities').get(attr)
                        if not self._equal_after_convert(cap, value):
                            filtered = True
                            break

                if not filtered:
                    all_pools[pool_key] = pool

        # filter pools by volume type
        if volume_type:
            volume_type = volume_types.get_by_name_or_id(
                context, volume_type)
            all_pools = (
                self._filter_pools_by_volume_type(context,
                                                  volume_type,
                                                  all_pools))

        # encapsulate pools in format:{name: XXX, capabilities: XXX}
        return [dict(name=key, capabilities=value.capabilities)
                for key, value in all_pools.items()]
Exemplo n.º 15
0
    def test_init_host_count_allocated_capacity_cluster(self, init_host_mock):
        cluster_name = 'mycluster'
        self.volume.cluster = cluster_name
        # All these volumes belong to the same cluster, so we will calculate
        # the capacity of them all because we query the DB by cluster_name.
        tests_utils.create_volume(self.context,
                                  size=100,
                                  host=CONF.host,
                                  cluster_name=cluster_name)
        tests_utils.create_volume(self.context,
                                  size=128,
                                  cluster_name=cluster_name,
                                  host=volutils.append_host(
                                      CONF.host, 'pool0'))
        tests_utils.create_volume(self.context,
                                  size=256,
                                  cluster_name=cluster_name,
                                  host=volutils.append_host(
                                      CONF.host + '2', 'pool0'))
        tests_utils.create_volume(self.context,
                                  size=512,
                                  cluster_name=cluster_name,
                                  host=volutils.append_host(
                                      CONF.host + '2', 'pool1'))
        tests_utils.create_volume(self.context,
                                  size=1024,
                                  cluster_name=cluster_name,
                                  host=volutils.append_host(
                                      CONF.host + '3', 'pool2'))

        # These don't belong to the cluster so they will be ignored
        tests_utils.create_volume(self.context,
                                  size=1024,
                                  host=volutils.append_host(
                                      CONF.host, 'pool2'))
        tests_utils.create_volume(self.context,
                                  size=1024,
                                  cluster_name=cluster_name + '1',
                                  host=volutils.append_host(
                                      CONF.host + '3', 'pool2'))

        self.volume.init_host(service_id=self.service_id)
        init_host_mock.assert_called_once_with(service_id=self.service_id,
                                               added_to_cluster=None)
        stats = self.volume.stats
        self.assertEqual(2020, stats['allocated_capacity_gb'])
        self.assertEqual(384, stats['pools']['pool0']['allocated_capacity_gb'])
        self.assertEqual(512, stats['pools']['pool1']['allocated_capacity_gb'])
        self.assertEqual(1024,
                         stats['pools']['pool2']['allocated_capacity_gb'])
Exemplo n.º 16
0
    def test_init_host_count_allocated_capacity_cluster(self, init_host_mock):
        cluster_name = 'mycluster'
        self.volume.cluster = cluster_name
        # All these volumes belong to the same cluster, so we will calculate
        # the capacity of them all because we query the DB by cluster_name.
        tests_utils.create_volume(self.context, size=100, host=CONF.host,
                                  cluster_name=cluster_name)
        tests_utils.create_volume(
            self.context, size=128, cluster_name=cluster_name,
            host=volutils.append_host(CONF.host, 'pool0'))
        tests_utils.create_volume(
            self.context, size=256, cluster_name=cluster_name,
            host=volutils.append_host(CONF.host + '2', 'pool0'))
        tests_utils.create_volume(
            self.context, size=512, cluster_name=cluster_name,
            host=volutils.append_host(CONF.host + '2', 'pool1'))
        tests_utils.create_volume(
            self.context, size=1024, cluster_name=cluster_name,
            host=volutils.append_host(CONF.host + '3', 'pool2'))

        # These don't belong to the cluster so they will be ignored
        tests_utils.create_volume(
            self.context, size=1024,
            host=volutils.append_host(CONF.host, 'pool2'))
        tests_utils.create_volume(
            self.context, size=1024, cluster_name=cluster_name + '1',
            host=volutils.append_host(CONF.host + '3', 'pool2'))

        self.volume.init_host(service_id=self.service_id)
        init_host_mock.assert_called_once_with(
            service_id=self.service_id, added_to_cluster=None)
        stats = self.volume.stats
        self.assertEqual(2020, stats['allocated_capacity_gb'])
        self.assertEqual(
            384, stats['pools']['pool0']['allocated_capacity_gb'])
        self.assertEqual(
            512, stats['pools']['pool1']['allocated_capacity_gb'])
        self.assertEqual(
            1024, stats['pools']['pool2']['allocated_capacity_gb'])