コード例 #1
0
ファイル: test_utils.py プロジェクト: therve/zaqar
    def test_can_connect_fails_if_bad_uri_mongodb(self):
        self.config(unreliable=True)

        uri = 'mongodb://localhost:8080?connectTimeoutMS=100'
        self.assertFalse(utils.can_connect(uri, conf=self.conf))

        uri = 'mongodb://example.com:27017?connectTimeoutMS=100'
        self.assertFalse(utils.can_connect(uri, conf=self.conf))
コード例 #2
0
ファイル: test_utils.py プロジェクト: rose/zaqar
    def test_can_connect_fails_if_bad_uri_mongodb(self):
        self.config(unreliable=True)

        uri = 'mongodb://localhost:8080?connectTimeoutMS=100'
        self.assertFalse(utils.can_connect(uri, conf=self.conf))

        uri = 'mongodb://example.com:27017?connectTimeoutMS=100'
        self.assertFalse(utils.can_connect(uri, conf=self.conf))
コード例 #3
0
ファイル: pools.py プロジェクト: AvnishPal/zaqar
    def on_put(self, request, response, project_id, pool):
        """Registers a new pool. Expects the following input:

        ::

            {"weight": 100, "uri": ""}

        An options object may also be provided.

        :returns: HTTP | [201, 204]
        """

        LOG.debug(u'PUT pool - name: %s', pool)

        conf = self._ctrl.driver.conf
        data = wsgi_utils.load(request)
        wsgi_utils.validate(self._validators['create'], data)
        if not storage_utils.can_connect(data['uri'], conf=conf):
            raise wsgi_errors.HTTPBadRequestBody(
                'cannot connect to %s' % data['uri']
            )
        try:
            self._ctrl.create(pool, weight=data['weight'],
                              uri=data['uri'],
                              group=data.get('group'),
                              options=data.get('options', {}))
            response.status = falcon.HTTP_201
            response.location = request.path
        except errors.PoolCapabilitiesMismatch as e:
            LOG.exception(e)
            title = _(u'Unable to create pool')
            raise falcon.HTTPBadRequest(title, six.text_type(e))
        except errors.PoolAlreadyExists as e:
            LOG.exception(e)
            raise wsgi_errors.HTTPConflict(six.text_type(e))
コード例 #4
0
ファイル: pools.py プロジェクト: yiyezhiqiu1228/zaqar
    def on_put(self, request, response, project_id, pool):
        """Registers a new pool. Expects the following input:

        ::

            {"weight": 100, "uri": ""}

        An options object may also be provided.

        :returns: HTTP | [201, 204]
        """

        LOG.debug(u'PUT pool - name: %s', pool)

        conf = self._ctrl.driver.conf
        data = wsgi_utils.load(request)
        wsgi_utils.validate(self._validators['create'], data)
        if not storage_utils.can_connect(data['uri'], conf=conf):
            raise wsgi_errors.HTTPBadRequestBody(
                'cannot connect to %s' % data['uri']
            )
        try:
            self._ctrl.create(pool, weight=data['weight'],
                              uri=data['uri'],
                              group=data.get('group'),
                              options=data.get('options', {}))
            response.status = falcon.HTTP_201
            response.location = request.path
        except errors.PoolCapabilitiesMismatch as e:
            LOG.exception(e)
            title = _(u'Unable to create pool')
            raise falcon.HTTPBadRequest(title, six.text_type(e))
        except errors.PoolAlreadyExists as e:
            LOG.exception(e)
            raise wsgi_errors.HTTPConflict(six.text_type(e))
コード例 #5
0
ファイル: pools.py プロジェクト: neerja28/zaqar
    def on_put(self, request, response, project_id, pool):
        """Registers a new pool. Expects the following input:

        ::

            {"weight": 100, "uri": ""}

        An options object may also be provided.

        :returns: HTTP | [201, 204]
        """

        LOG.debug(u'PUT pool - name: %s', pool)

        conf = self._ctrl.driver.conf
        data = wsgi_utils.load(request)
        wsgi_utils.validate(self._validators['create'], data)
        if not storage_utils.can_connect(data['uri'], conf=conf):
            raise wsgi_errors.HTTPBadRequestBody(
                'cannot connect to %s' % data['uri']
            )
        self._ctrl.create(pool, weight=data['weight'],
                          uri=data['uri'],
                          options=data.get('options', {}))
        response.status = falcon.HTTP_201
        response.location = request.path
コード例 #6
0
ファイル: pools.py プロジェクト: wenchma/zaqar
    def on_put(self, request, response, project_id, pool):
        """Registers a new pool. Expects the following input:

        ::

            {"weight": 100, "uri": ""}

        An options object may also be provided.

        :returns: HTTP | [201, 204]
        """

        LOG.debug(u'PUT pool - name: %s', pool)

        conf = self._ctrl.driver.conf
        data = wsgi_utils.load(request)
        wsgi_utils.validate(self._validators['create'], data)
        if not storage_utils.can_connect(data['uri'], conf=conf):
            raise wsgi_errors.HTTPBadRequestBody('cannot connect to %s' %
                                                 data['uri'])
        self._ctrl.create(pool,
                          weight=data['weight'],
                          uri=data['uri'],
                          options=data.get('options', {}))
        response.status = falcon.HTTP_201
        response.location = request.path
コード例 #7
0
    def on_patch(self, request, response, project_id, pool):
        """Allows one to update a pool's weight, uri, and/or options.

        This method expects the user to submit a JSON object
        containing at least one of: 'uri', 'weight', 'flavor',
        'options'.If none are found, the request is flagged as bad.
        There is also strict format checking through the use of
        jsonschema. Appropriate errors are returned in each case for
        badly formatted input.

        :returns: HTTP | 200,400
        """

        LOG.debug(u'PATCH pool - name: %s', pool)
        data = wsgi_utils.load(request)

        EXPECT = ('weight', 'uri', 'flavor', 'options')
        if not any([(field in data) for field in EXPECT]):
            LOG.debug(u'PATCH pool, bad params')
            raise wsgi_errors.HTTPBadRequestBody(
                'One of `uri`, `weight`, `flavor`,'
                ' or `options` needs '
                'to be specified'
            )

        for field in EXPECT:
            wsgi_utils.validate(self._validators[field], data)

        conf = self._ctrl.driver.conf
        if 'uri' in data and not storage_utils.can_connect(data['uri'],
                                                           conf=conf):
            raise wsgi_errors.HTTPBadRequestBody(
                'cannot connect to %s' % data['uri']
            )
        fields = common_utils.fields(data, EXPECT,
                                     pred=lambda v: v is not None)
        resp_data = None
        try:
            self._ctrl.update(pool, **fields)
            resp_data = self._ctrl.get(pool, False)
        except errors.PoolDoesNotExist as ex:
            LOG.exception('Pool "%s" does not exist', pool)
            raise wsgi_errors.HTTPNotFound(six.text_type(ex))

        resp_data['href'] = request.path
        response.body = transport_utils.to_json(resp_data)
コード例 #8
0
ファイル: pools.py プロジェクト: ISCAS-VDI/zaqar
    def on_patch(self, request, response, project_id, pool):
        """Allows one to update a pool's weight, uri, and/or options.

        This method expects the user to submit a JSON object
        containing at least one of: 'uri', 'weight', 'group', 'options'. If
        none are found, the request is flagged as bad. There is also
        strict format checking through the use of
        jsonschema. Appropriate errors are returned in each case for
        badly formatted input.

        :returns: HTTP | 200,400
        """

        LOG.debug(u'PATCH pool - name: %s', pool)
        data = wsgi_utils.load(request)

        EXPECT = ('weight', 'uri', 'group', 'options')
        if not any([(field in data) for field in EXPECT]):
            LOG.debug(u'PATCH pool, bad params')
            raise wsgi_errors.HTTPBadRequestBody(
                'One of `uri`, `weight`, `group`, or `options` needs '
                'to be specified'
            )

        for field in EXPECT:
            wsgi_utils.validate(self._validators[field], data)

        conf = self._ctrl.driver.conf
        if 'uri' in data and not storage_utils.can_connect(data['uri'],
                                                           conf=conf):
            raise wsgi_errors.HTTPBadRequestBody(
                'cannot connect to %s' % data['uri']
            )
        fields = common_utils.fields(data, EXPECT,
                                     pred=lambda v: v is not None)
        resp_data = None
        try:
            self._ctrl.update(pool, **fields)
            resp_data = self._ctrl.get(pool, False)
        except errors.PoolDoesNotExist as ex:
            LOG.exception(ex)
            raise wsgi_errors.HTTPNotFound(six.text_type(ex))

        resp_data['href'] = request.path
        response.body = transport_utils.to_json(resp_data)
コード例 #9
0
ファイル: pools.py プロジェクト: wenchma/zaqar
    def on_patch(self, request, response, project_id, pool):
        """Allows one to update a pool's weight, uri, and/or options.

        This method expects the user to submit a JSON object
        containing at least one of: 'uri', 'weight', 'group', 'options'. If
        none are found, the request is flagged as bad. There is also
        strict format checking through the use of
        jsonschema. Appropriate errors are returned in each case for
        badly formatted input.

        :returns: HTTP | 200,400
        """

        LOG.debug(u"PATCH pool - name: %s", pool)
        data = wsgi_utils.load(request)

        EXPECT = ("weight", "uri", "group", "options")
        if not any([(field in data) for field in EXPECT]):
            LOG.debug(u"PATCH pool, bad params")
            raise wsgi_errors.HTTPBadRequestBody(
                "One of `uri`, `weight`, `group`, or `options` needs " "to be specified"
            )

        for field in EXPECT:
            wsgi_utils.validate(self._validators[field], data)

        conf = self._ctrl.driver.conf
        if "uri" in data and not storage_utils.can_connect(data["uri"], conf=conf):
            raise wsgi_errors.HTTPBadRequestBody("cannot connect to %s" % data["uri"])
        fields = common_utils.fields(data, EXPECT, pred=lambda v: v is not None)

        try:
            self._ctrl.update(pool, **fields)
        except errors.PoolDoesNotExist as ex:
            LOG.exception(ex)
            raise falcon.HTTPNotFound()
コード例 #10
0
 def test_can_connect(self):
     swift_uri = "swift://*****:*****@/service"
     is_alive_path = 'zaqar.storage.swift.driver.DataDriver.is_alive'
     with mock.patch(is_alive_path) as is_alive:
         is_alive.return_value = True
         self.assertTrue(utils.can_connect(swift_uri, self.conf))
コード例 #11
0
ファイル: test_utils.py プロジェクト: rose/zaqar
 def test_can_connect_suceeds_if_good_uri_sqlite(self):
     self.assertTrue(utils.can_connect('sqlite://:memory:'))
コード例 #12
0
ファイル: test_utils.py プロジェクト: therve/zaqar
 def test_can_connect_succeeds_if_good_uri_redis(self):
     self.assertTrue(utils.can_connect('redis://localhost'))
     self.assertTrue(utils.can_connect('redis://localhost:6379'))
コード例 #13
0
ファイル: test_utils.py プロジェクト: therve/zaqar
 def test_can_connect_succeeds_if_good_uri_mongo(self):
     self.config(unreliable=True)
     self.assertTrue(utils.can_connect(self.mongodb_url,
                                       conf=self.conf))
コード例 #14
0
ファイル: test_utils.py プロジェクト: rose/zaqar
 def test_can_connect_suceeds_if_good_uri_sqlite(self):
     self.assertTrue(utils.can_connect('sqlite://:memory:'))
コード例 #15
0
ファイル: test_utils.py プロジェクト: rose/zaqar
 def test_can_connect_suceeds_if_good_uri_mongo(self):
     self.config(unreliable=True)
     self.assertTrue(
         utils.can_connect('mongodb://localhost:27017', conf=self.conf))
コード例 #16
0
ファイル: test_utils.py プロジェクト: rose/zaqar
 def test_can_connect_suceeds_if_good_uri_mongo(self):
     self.config(unreliable=True)
     self.assertTrue(utils.can_connect('mongodb://localhost:27017',
                                       conf=self.conf))
コード例 #17
0
ファイル: test_utils.py プロジェクト: rose/zaqar
 def test_can_connect_suceeds_if_good_uri_redis(self):
     self.assertTrue(utils.can_connect('redis://localhost'))
     self.assertTrue(utils.can_connect('redis://localhost:6379'))
コード例 #18
0
ファイル: test_utils.py プロジェクト: therve/zaqar
 def test_can_connect_fails_if_bad_uri_missing_schema(self):
     self.assertFalse(utils.can_connect('localhost:27017'))
コード例 #19
0
ファイル: test_utils.py プロジェクト: rose/zaqar
 def test_can_connect_fails_if_bad_uri_missing_schema(self):
     self.assertFalse(utils.can_connect('localhost:27017'))
コード例 #20
0
ファイル: test_utils.py プロジェクト: therve/zaqar
 def test_can_connect_fails_if_bad_uri_redis(self):
     self.assertFalse(utils.can_connect('redis://localhost:8080'))
     self.assertFalse(utils.can_connect('redis://example.com:6379'))
コード例 #21
0
ファイル: test_utils.py プロジェクト: rose/zaqar
 def test_can_connect_fails_if_bad_uri_redis(self):
     self.assertFalse(utils.can_connect('redis://localhost:8080'))
     self.assertFalse(utils.can_connect('redis://example.com:6379'))
コード例 #22
0
ファイル: test_utils.py プロジェクト: openstack/zaqar
 def test_can_connect(self):
     swift_uri = "swift://*****:*****@/service"
     is_alive_path = 'zaqar.storage.swift.driver.DataDriver.is_alive'
     with mock.patch(is_alive_path) as is_alive:
         is_alive.return_value = True
         self.assertTrue(utils.can_connect(swift_uri, self.conf))