def test_find_module_default(self): url = "file://host.com:90//path/to/file" url_parts = urlparse.urlparse(url) module_path = "just.some.thing" lookup_dict = { 'file': [{'module': module_path}] } res = utils.find_protocol_module_name(lookup_dict, url_parts) self.assertEqual(res, module_path)
def test_find_module_wildcards_middle(self): url = "file://host.com:90//path/to/file" url_parts = urlparse.urlparse(url) module_path = "just.some.thing" lookup_dict = { 'file': [{'module': module_path, 'netloc': '.*host.com.*', 'path': '.*'}] } res = utils.find_protocol_module_name(lookup_dict, url_parts) self.assertEqual(res, module_path)
def test_find_module_multiple_wildcards(self): url = "file://host.com:90//path/to/file" url_parts = urlparse.urlparse(url) bad_module_path = "just.some.bad.thing" good_module_path = "just.some.bad.thing" lookup_dict = { 'file': [{'module': bad_module_path, 'netloc': '.*', 'path': '/sorry/.*'}, {'module': good_module_path}] } res = utils.find_protocol_module_name(lookup_dict, url_parts) self.assertEqual(res, good_module_path)
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