當前位置: 首頁>>代碼示例>>Python>>正文


Python StoragePolicyCollection.get_object_ring方法代碼示例

本文整理匯總了Python中swift.common.storage_policy.StoragePolicyCollection.get_object_ring方法的典型用法代碼示例。如果您正苦於以下問題:Python StoragePolicyCollection.get_object_ring方法的具體用法?Python StoragePolicyCollection.get_object_ring怎麽用?Python StoragePolicyCollection.get_object_ring使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在swift.common.storage_policy.StoragePolicyCollection的用法示例。


在下文中一共展示了StoragePolicyCollection.get_object_ring方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_get_object_ring

# 需要導入模塊: from swift.common.storage_policy import StoragePolicyCollection [as 別名]
# 或者: from swift.common.storage_policy.StoragePolicyCollection import get_object_ring [as 別名]
    def test_get_object_ring(self):
        test_policies = [StoragePolicy(0, 'aay', True),
                         StoragePolicy(1, 'bee', False),
                         StoragePolicy(2, 'cee', False)]
        policies = StoragePolicyCollection(test_policies)

        class NamedFakeRing(FakeRing):

            def __init__(self, swift_dir, ring_name=None):
                self.ring_name = ring_name
                super(NamedFakeRing, self).__init__()

        with mock.patch('swift.common.storage_policy.Ring',
                        new=NamedFakeRing):
            for policy in policies:
                self.assertFalse(policy.object_ring)
                ring = policies.get_object_ring(int(policy), '/path/not/used')
                self.assertEqual(ring.ring_name, policy.ring_name)
                self.assertTrue(policy.object_ring)
                self.assertTrue(isinstance(policy.object_ring, NamedFakeRing))

        def blow_up(*args, **kwargs):
            raise Exception('kaboom!')

        with mock.patch('swift.common.storage_policy.Ring', new=blow_up):
            for policy in policies:
                policy.load_ring('/path/not/used')
                expected = policies.get_object_ring(int(policy),
                                                    '/path/not/used')
                self.assertEqual(policy.object_ring, expected)

        # bad policy index
        self.assertRaises(PolicyError, policies.get_object_ring, 99,
                          '/path/not/used')
開發者ID:aureliengoulon,項目名稱:swift,代碼行數:36,代碼來源:test_storage_policy.py


注:本文中的swift.common.storage_policy.StoragePolicyCollection.get_object_ring方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。