Ejemplo n.º 1
0
    def test_new_request(self):
        xfer = _make_xfer_request()
        xfer.srcurl = "http://someplace.com"
        xfer.dsturl = "file://path/to/no/where"

        self.mox.StubOutWithMock(config, 'get_protocol_policy')

        config.get_protocol_policy(self.conf).AndReturn(
            {
                "file": [{"module": "staccato.protocols.file.FileProtocol"}],
                "http": [{"module": "staccato.protocols.http.HttpProtocol"}]
            })

        self.db.get_new_xfer('admin',
                             xfer.srcurl,
                             xfer.dsturl,
                             "staccato.protocols.http.HttpProtocol",
                             "staccato.protocols.file.FileProtocol",
                             start_ndx=0,
                             end_ndx=None,
                             source_opts={},
                             dest_opts={}).AndReturn(xfer)
        self.mox.ReplayAll()
        res = self.controller.newtransfer(self.request, xfer.srcurl,
                                          xfer.dsturl, 'admin')
        self.mox.VerifyAll()
        self.assertEqual(res, xfer)
Ejemplo n.º 2
0
 def test_protocol_policy_retrieve(self):
     conf = config.get_config_object(args=[])
     p_file = self.get_tempfile()
     policy = {"hello": "world"}
     fptr = open(p_file, 'w')
     fptr.write(json.dumps(policy))
     fptr.close()
     conf.protocol_policy = p_file
     j = config.get_protocol_policy(conf)
     self.assertEqual(j, policy)
Ejemplo n.º 3
0
    def __call__(self, req):
        version_info = {'id': self.conf.service_id,
                        'version': self.conf.version,
                        'status': 'active',
                        }
        protocols = config.get_protocol_policy(self.conf).keys()
        version_info['protocols'] = protocols
        version_objs = {'v1': version_info}

        response = webob.Response(request=req,
                                  status=httplib.MULTIPLE_CHOICES,
                                  content_type='application/json')
        response.body = json.dumps(dict(versions=version_objs))
        return response
Ejemplo n.º 4
0
    def newtransfer(self, request, source_url, destination_url, owner,
                    source_options=None, destination_options=None,
                    start_offset=0, end_offset=None):

        srcurl_parts = urlparse.urlparse(source_url)
        dsturl_parts = urlparse.urlparse(destination_url)

        dstopts = {}
        srcopts = {}

        if source_options is not None:
            srcopts = source_options
        if destination_options is not None:
            dstopts = destination_options

        plugin_policy = config.get_protocol_policy(self.conf)
        src_module_name = utils.find_protocol_module_name(plugin_policy,
                                                          srcurl_parts)
        dst_module_name = utils.find_protocol_module_name(plugin_policy,
                                                          dsturl_parts)

        src_module = utils.load_protocol_module(src_module_name, self.conf)
        dst_module = utils.load_protocol_module(dst_module_name, self.conf)

        dstopts = dst_module.new_write(dsturl_parts, dstopts)
        srcopts = src_module.new_read(srcurl_parts, srcopts)

        xfer = self.db_con.get_new_xfer(owner,
                                        source_url,
                                        destination_url,
                                        src_module_name,
                                        dst_module_name,
                                        start_ndx=start_offset,
                                        end_ndx=end_offset,
                                        source_opts=srcopts,
                                        dest_opts=dstopts)
        return xfer
Ejemplo n.º 5
0
 def test_protocol_policy_retrieve_none(self):
     conf = config.get_config_object(args=[])
     conf.protocol_policy = None
     j = config.get_protocol_policy(conf)
     self.assertEqual(j, {})