예제 #1
0
    def setUp(self):

        self.logger = debug_logger('proxy-server')
        self.storage = FakeStorageAPI(namespace='NS',
                                      timeouts={},
                                      logger=self.logger)

        self.app = PatchedObjControllerApp({'sds_namespace': "NS"},
                                           account_ring=FakeRing(),
                                           container_ring=FakeRing(),
                                           storage=self.storage,
                                           logger=self.logger)
        self.app.container_info = dict(self.container_info)
        self.storage.account.account_show = Mock(
            return_value={
                'ctime': 0,
                'mtime': 0,
                'containers': 1,
                'objects': 1,
                'bytes': 2,
                'metadata': {}
            })
        self.storage.container.container_get_properties = Mock(return_value={
            'properties': {},
            'system': {}
        })
예제 #2
0
    def setUp(self):
        self.logger = debug_logger('proxy-server')
        self.storage = FakeStorageAPI(logger=self.logger)

        self.app = proxy_server.Application(
            {'sds_namespace': "TEST"}, FakeMemcache(),
            account_ring=FakeRing(), container_ring=FakeRing(),
            storage=self.storage, logger=self.logger)
예제 #3
0
def app_factory(global_conf, **local_conf):
    conf = global_conf.copy()
    conf.update(local_conf)
    account_ring = FakeRing()
    container_ring = FakeRing()
    app = Application(conf,
                      account_ring=account_ring,
                      container_ring=container_ring)
    app.check_config()
    return app
예제 #4
0
    def setUp(self):

        self.logger = debug_logger('proxy-server')
        self.storage = FakeStorageAPI(logger=self.logger)
        self.storage.account.account_show = Mock(return_value={
            'containers': 0,
            'objects': 0,
            'bytes': 0,
            'ctime': 0,
            'metadata': {}
        })

        self.account_info = {
            'status': 200,
            'container_count': '10',
            'total_object_count': '100',
            'bytes': '1000',
            'meta': {},
            'sysmeta': {}
        }

        self.app = proxy_server.Application({'sds_namespace': 'NS'},
                                            FakeMemcache(),
                                            account_ring=FakeRing(),
                                            container_ring=FakeRing(),
                                            storage=self.storage,
                                            logger=self.logger)

        class FakeAccountInfoContainerController(
                proxy_server.ContainerController):
            def account_info(controller, *args, **kwargs):
                patch_path = 'swift.proxy.controllers.base.get_info'
                with patch(patch_path) as mock_get_info:
                    mock_get_info.return_value = dict(self.account_info)
                    return super(FakeAccountInfoContainerController,
                                 controller).account_info(*args, **kwargs)

        _orig_get_controller = self.app.get_controller

        def wrapped_get_controller(*args, **kwargs):
            with patch('swift.proxy.server.ContainerController',
                       new=FakeAccountInfoContainerController):
                return _orig_get_controller(*args, **kwargs)

        self.app.get_controller = wrapped_get_controller
예제 #5
0
    def __init__(self,
                 conf,
                 memcache=None,
                 logger=None,
                 account_ring=None,
                 container_ring=None,
                 storage=None):
        for policy, ring_arg in zip(POLICIES, ring_args):
            if ring_arg is not None:
                policy.object_ring = FakeRing(**ring_arg)

        SwiftApplication.__init__(self,
                                  conf,
                                  memcache=memcache,
                                  logger=logger,
                                  account_ring=account_ring,
                                  container_ring=container_ring)
        if conf is None:
            conf = dict()
        sds_conf = {
            k[4:]: v
            for k, v in conf.iteritems() if k.startswith("sds_")
        }

        self.oio_stgpol = []
        if 'auto_storage_policies' in conf:
            for elem in conf['auto_storage_policies'].split(','):
                if ':' in elem:
                    name, offset = elem.split(':')
                    self.oio_stgpol.append((name, int(offset)))
                else:
                    self.oio_stgpol.append((elem, 0))
            self.oio_stgpol.sort(key=lambda x: x[1])

        policies = []
        if 'oio_storage_policies' in conf:
            for i, pol in enumerate(conf['oio_storage_policies'].split(',')):
                policies.append(
                    storage_policy.StoragePolicy(i, pol, is_default=i == 0))
        else:
            policies.append(storage_policy.StoragePolicy(0, 'SINGLE', True))

        self.POLICIES = storage_policy.StoragePolicyCollection(policies)

        # Mandatory, raises KeyError
        sds_namespace = sds_conf['namespace']
        sds_conf.pop('namespace')  # removed to avoid unpacking conflict
        # Loaded by ObjectStorageApi if None
        sds_proxy_url = sds_conf.pop('proxy_url', None)
        self.storage = storage or \
            ObjectStorageApi(sds_namespace, endpoint=sds_proxy_url, **sds_conf)
예제 #6
0
    def __init__(self,
                 conf,
                 memcache=None,
                 logger=None,
                 account_ring=None,
                 container_ring=None,
                 storage=None):
        for policy, ring_arg in zip(POLICIES, ring_args):
            if ring_arg is not None:
                policy.object_ring = FakeRing(**ring_arg)

        SwiftApplication.__init__(self,
                                  conf,
                                  memcache=memcache,
                                  logger=logger,
                                  account_ring=account_ring,
                                  container_ring=container_ring)
        if conf is None:
            conf = dict()
        sds_conf = {
            k[4:]: v
            for k, v in conf.iteritems() if k.startswith("sds_")
        }

        self.oio_stgpol = []
        if 'auto_storage_policies' in conf:
            for elem in conf['auto_storage_policies'].split(','):
                if ':' in elem:
                    name, offset = elem.split(':')
                    self.oio_stgpol.append((name, int(offset)))
                else:
                    self.oio_stgpol.append((elem, 0))
            self.oio_stgpol.sort(key=lambda x: x[1])

        policies = []
        if 'oio_storage_policies' in conf:
            for i, pol in enumerate(conf['oio_storage_policies'].split(',')):
                policies.append(
                    storage_policy.StoragePolicy(i, pol, is_default=i == 0))
        else:
            policies.append(storage_policy.StoragePolicy(0, 'SINGLE', True))

        self.POLICIES = storage_policy.StoragePolicyCollection(policies)

        # Mandatory, raises KeyError
        sds_namespace = sds_conf['namespace']
        sds_conf.pop('namespace')  # removed to avoid unpacking conflict
        # Loaded by ObjectStorageApi if None
        sds_proxy_url = sds_conf.pop('proxy_url', None)
        # Fix boolean parameter
        if 'autocreate' in sds_conf and not (
                hasattr(ObjectStorageApi, 'EXTRA_KEYWORDS')
                or 'autocreate' in ObjectStorageApi.EXTRA_KEYWORDS):
            logger.warn("'autocreate' parameter is ignored by current version"
                        " of OpenIO SDS. Please update to oio>=4.1.23.")
        else:
            sds_conf['autocreate'] = config_true_value(
                sds_conf.get('autocreate', 'true'))

        self.storage = storage or \
            ObjectStorageApi(sds_namespace, endpoint=sds_proxy_url, **sds_conf)