예제 #1
0
    def test_chunk(self):
        dev1 = Mock()
        attrs = {"req_grow": True, "id": 1, "name": "req1"}
        dev1.configure_mock(**attrs)

        req1 = Request(dev1)
        req1.base = 10

        dev2 = Mock()
        attrs = {"req_grow": False, "id": 2, "name": "req2"}
        dev2.configure_mock(**attrs)

        req2 = Request(dev2)
        req2.base = 20

        chunk = Chunk(110, requests=[req1, req2])
        self.assertEqual(chunk.pool, 80)
        self.assertEqual(chunk.base, 10)

        dev3 = Mock()
        attrs = {"req_grow": True, "id": 3, "name": "req3"}
        dev3.configure_mock(**attrs)

        req3 = Request(dev3)
        req3.base = 20
        req3.max_growth = 35

        chunk.add_request(req3)
        self.assertEqual(chunk.pool, 60)
        self.assertEqual(chunk.base, 30)

        self.assertEqual(chunk.length_to_size(30), 30)
        self.assertEqual(chunk.size_to_length(40), 40)
        self.assertEqual(chunk.has_growable, True)

        chunk.grow_requests()

        # the chunk is done growing since its pool has been exhausted
        self.assertEqual(chunk.done, True)

        # there is still one request remaining since req1 has no maximum growth
        self.assertEqual(chunk.remaining, 1)

        # req1 is 10 units and growable with no limit
        # req2 is 20 units and not growable
        # req3 is 20 units and growable with a limits of 35 units of growth
        #
        # Requests are grown at rates proportional to their share of the
        # combined base size of all growable requests. If req3 had no max growth
        # it would get 40 units and req1 would get 20. Since req3 has a limit,
        # it will get 35 and req1 will get its 20 plus the leftovers from req3,
        # which comes out to 25.
        self.assertEqual(req1.growth, 25)
        self.assertEqual(req2.growth, 0)
        self.assertEqual(req3.growth, 35)
예제 #2
0
    def test_chunk(self):
        dev1 = Mock()
        attrs = {"req_grow": True,
                 "id": 1,
                 "name": "req1"}
        dev1.configure_mock(**attrs)

        req1 = Request(dev1)
        req1.base = 10

        dev2 = Mock()
        attrs = {"req_grow": False,
                 "id": 2,
                 "name": "req2"}
        dev2.configure_mock(**attrs)

        req2 = Request(dev2)
        req2.base = 20

        chunk = Chunk(110, requests=[req1, req2])
        self.assertEqual(chunk.pool, 80)
        self.assertEqual(chunk.base, 10)

        dev3 = Mock()
        attrs = {"req_grow": True,
                 "id": 3,
                 "name": "req3"}
        dev3.configure_mock(**attrs)

        req3 = Request(dev3)
        req3.base = 20
        req3.max_growth = 35

        chunk.add_request(req3)
        self.assertEqual(chunk.pool, 60)
        self.assertEqual(chunk.base, 30)

        self.assertEqual(chunk.length_to_size(30), 30)
        self.assertEqual(chunk.size_to_length(40), 40)
        self.assertEqual(chunk.has_growable, True)

        chunk.grow_requests()

        # the chunk is done growing since its pool has been exhausted
        self.assertEqual(chunk.done, True)

        # there is still one request remaining since req1 has no maximum growth
        self.assertEqual(chunk.remaining, 1)

        # req1 is 10 units and growable with no limit
        # req2 is 20 units and not growable
        # req3 is 20 units and growable with a limits of 35 units of growth
        #
        # Requests are grown at rates proportional to their share of the
        # combined base size of all growable requests. If req3 had no max growth
        # it would get 40 units and req1 would get 20. Since req3 has a limit,
        # it will get 35 and req1 will get its 20 plus the leftovers from req3,
        # which comes out to 25.
        self.assertEqual(req1.growth, 25)
        self.assertEqual(req2.growth, 0)
        self.assertEqual(req3.growth, 35)
예제 #3
0
 def client_capabilities(system):
     caps = Mock(name="Client.capabilities(%s)" % system.name)
     caps.configure_mock(**{"supported.return_value": system.raid})
     return caps
예제 #4
0
    def test_update_volume_list(self):
        """Validate conversion of lsm data."""
        _client_systems = [Mock(), Mock(), Mock()]
        _client_systems[0].configure_mock(name="Smart Array P840 in Slot 1",
                                          raid=True)
        _client_systems[1].configure_mock(name="LSI MegaRAID SAS", raid=True)
        _client_systems[2].configure_mock(name="Supermicro Superchassis",
                                          raid=False)

        _client_volumes = [
            Mock(system_id=_client_systems[0].id,
                 nodes=["/dev/sda"],
                 vpd83=0,
                 raid_type=sentinel.RAID_TYPE_RAID0,
                 stripe_size=262144,
                 drives=4,
                 min_io=262144,
                 opt_io=1048576),
            Mock(system_id=_client_systems[1].id,
                 nodes=["/dev/sdb"],
                 vpd83=1,
                 raid_type=sentinel.RAID_TYPE_OTHER,
                 stripe_size=524288,
                 drives=2,
                 min_io=524288,
                 opt_io=1048576),
            Mock(system_id=_client_systems[2].id,
                 nodes=["/dev/sdc"],
                 vpd83=2,
                 raid_type=None,
                 strip_size=None,
                 drives=None,
                 min_io=None,
                 opt_io=None)
        ]

        def client_capabilities(system):
            caps = Mock(name="Client.capabilities(%s)" % system.name)
            caps.configure_mock(**{"supported.return_value": system.raid})
            return caps

        def client_volume_raid_info(volume):
            return (volume.raid_type, volume.stripe_size, volume.drives,
                    volume.min_io, volume.opt_io)

        def vpd83_search(vpd83):
            return six.next(
                (vol.nodes for vol in _client_volumes if vol.vpd83 == vpd83),
                None)

        def system_by_id(sys_id):
            return six.next(
                (sys for sys in _client_systems if sys.id == sys_id), None)

        with patch("blivet.devicelibs.disk._lsm_required._check_avail",
                   return_value=True):
            with patch("blivet.devicelibs.disk.lsm") as _lsm:
                _lsm.Volume.RAID_TYPE_RAID0 = sentinel.RAID_TYPE_RAID0
                _lsm.Volume.RAID_TYPE_OTHER = sentinel.RAID_TYPE_OTHER
                _lsm.Capabilities.VOLUME_RAID_INFO = sentinel.VOLUME_RAID_INFO
                _lsm.LocalDisk.vpd83_search.side_effect = vpd83_search
                client_mock = Mock(name="lsm.Client")
                client_mock.configure_mock(
                    **{
                        "return_value": client_mock,
                        "volumes.return_value": _client_volumes,
                        "systems.return_value": _client_systems,
                        "capabilities.side_effect": client_capabilities,
                        "volume_raid_info.side_effect": client_volume_raid_info
                    })
                _lsm.Client = client_mock
                disklib.update_volume_info()
                for (i, lvol) in enumerate(_client_volumes):
                    bvol = disklib.volumes[lvol.nodes[0]]
                    system = system_by_id(lvol.system_id)
                    self.assertEqual(bvol.system, system.name)
                    if client_mock.capabilities(system).supported(
                            sentinel.VOLUME_RAID_INFO):
                        self.assertEqual(
                            bvol.raid_type,
                            disklib._get_lsm_raid_level(lvol.raid_type))
                        self.assertEqual(bvol.raid_stripe_size,
                                         Size(lvol.stripe_size))
                        self.assertEqual(bvol.raid_disk_count, lvol.drives)
                    else:
                        self.assertIsNone(bvol.raid_type)
                        self.assertIsNone(bvol.raid_stripe_size)
                        self.assertIsNone(bvol.raid_disk_count)
예제 #5
0
 def client_capabilities(system):
     caps = Mock(name="Client.capabilities(%s)" % system.name)
     caps.configure_mock(**{"supported.return_value": system.raid})
     return caps
예제 #6
0
    def test_update_volume_list(self):
        """Validate conversion of lsm data."""
        _client_systems = [Mock(), Mock(), Mock()]
        _client_systems[0].configure_mock(name="Smart Array P840 in Slot 1", raid=True)
        _client_systems[1].configure_mock(name="LSI MegaRAID SAS", raid=True)
        _client_systems[2].configure_mock(name="Supermicro Superchassis", raid=False)

        _client_volumes = [Mock(system_id=_client_systems[0].id,
                                nodes=["/dev/sda"],
                                vpd83=0,
                                raid_type=sentinel.RAID_TYPE_RAID0,
                                stripe_size=262144,
                                drives=4,
                                min_io=262144,
                                opt_io=1048576),
                           Mock(system_id=_client_systems[1].id,
                                nodes=["/dev/sdb"],
                                vpd83=1,
                                raid_type=sentinel.RAID_TYPE_OTHER,
                                stripe_size=524288,
                                drives=2,
                                min_io=524288,
                                opt_io=1048576),
                           Mock(system_id=_client_systems[2].id,
                                nodes=["/dev/sdc"],
                                vpd83=2,
                                raid_type=None,
                                strip_size=None,
                                drives=None,
                                min_io=None,
                                opt_io=None)]

        def client_capabilities(system):
            caps = Mock(name="Client.capabilities(%s)" % system.name)
            caps.configure_mock(**{"supported.return_value": system.raid})
            return caps

        def client_volume_raid_info(volume):
            return (volume.raid_type, volume.stripe_size, volume.drives, volume.min_io, volume.opt_io)

        def vpd83_search(vpd83):
            return six.next((vol.nodes for vol in _client_volumes if vol.vpd83 == vpd83), None)

        def system_by_id(sys_id):
            return six.next((sys for sys in _client_systems if sys.id == sys_id), None)

        with patch("blivet.devicelibs.disk._lsm_required._check_avail", return_value=True):
            with patch("blivet.devicelibs.disk.lsm") as _lsm:
                _lsm.Volume.RAID_TYPE_RAID0 = sentinel.RAID_TYPE_RAID0
                _lsm.Volume.RAID_TYPE_OTHER = sentinel.RAID_TYPE_OTHER
                _lsm.Capabilities.VOLUME_RAID_INFO = sentinel.VOLUME_RAID_INFO
                _lsm.LocalDisk.vpd83_search.side_effect = vpd83_search
                client_mock = Mock(name="lsm.Client")
                client_mock.configure_mock(**{"return_value": client_mock,
                                              "volumes.return_value": _client_volumes,
                                              "systems.return_value": _client_systems,
                                              "capabilities.side_effect": client_capabilities,
                                              "volume_raid_info.side_effect": client_volume_raid_info})
                _lsm.Client = client_mock
                disklib.update_volume_info()
                for (i, lvol) in enumerate(_client_volumes):
                    bvol = disklib.volumes[lvol.nodes[0]]
                    system = system_by_id(lvol.system_id)
                    self.assertEqual(bvol.system, system.name)
                    if client_mock.capabilities(system).supported(sentinel.VOLUME_RAID_INFO):
                        self.assertEqual(bvol.raid_type, disklib._get_lsm_raid_level(lvol.raid_type))
                        self.assertEqual(bvol.raid_stripe_size, Size(lvol.stripe_size))
                        self.assertEqual(bvol.raid_disk_count, lvol.drives)
                    else:
                        self.assertIsNone(bvol.raid_type)
                        self.assertIsNone(bvol.raid_stripe_size)
                        self.assertIsNone(bvol.raid_disk_count)