示例#1
0
 /*
 * initiate a gfal's context with default parameters for use
 */
gfal2_context_t gfal_initG (GError** err)
{
	GError* tmp_err=NULL;
	gfal2_context_t handle = g_new0(struct gfal_handle_,1);// clear allocation of the struct and set defautl options
	if(handle == NULL){
		errno= ENOMEM;
        g_set_error(err, gfal2_get_plugins_quark(), ENOMEM, "[gfal_initG] bad allocation, no more memory free");
		return NULL;
	}
	handle->plugin_opt.plugin_number= 0;

    if((handle->conf = gfal_conf_new(&tmp_err)) && !tmp_err){
        // load and instanciate all the plugins
        gfal_plugins_instance(handle, &tmp_err);
        // cancel logic init
        handle->cancel = FALSE;
        handle->running_ops = 0;
        handle->mux_cancel = g_mutex_new();
        g_hook_list_init(&handle->cancel_hooks, sizeof(GHook));
    }


    if(tmp_err){
        if (handle && handle->conf)
            gfal_conf_delete(handle->conf);
        g_free(handle);
        handle = NULL;
    }
    G_RETURN_ERR(handle, tmp_err, err);
}
示例#2
0
void gfal2_test_gfal_select_best_protocol_and_endpointG()
{
	char endpoint[2048];
	memset(endpoint, '\0', sizeof(char)*2048);
	enum gfal_srm_proto srm_type;
	GError * err= NULL;
	gfal_handle handle  = gfal_initG(&err);
	assert_true_with_message(handle != NULL, " handle is not properly allocated");
	if(handle==NULL)
		return;
	gfal_plugins_instance(handle, NULL);
	gfal_srmv2_opt opts;
	gfal_srm_opt_initG(&opts, handle);
	gfal_set_default_storageG(&opts, PROTO_SRMv2);
	char* endpoint_list[] = { "everest", "montblanc", NULL};
	char* se_type_list[] = { "srm_v1", "srm_v2", NULL };
	int ret = gfal_select_best_protocol_and_endpointG(&opts, se_type_list, endpoint_list, endpoint, 2048, &srm_type, &err);
	assert_true_with_message(ret ==0 && err == NULL, " must be a succefull call to the best select");
	gfal_check_GError(&err);

	assert_true_with_message(strings_are_equal(endpoint,"montblanc"), " reponse not match correctly");
	// try with another version by default
	gfal_set_default_storageG(&opts, PROTO_SRM);
	ret = gfal_select_best_protocol_and_endpointG(&opts, se_type_list, endpoint_list, endpoint, 2048, &srm_type, &err);
	assert_true_with_message(ret ==0 && err == NULL, " must be a succefull call to the best select");
	gfal_check_GError(&err);
	assert_true_with_message(strings_are_equal(endpoint,"everest") , "must be a valid check");	
	gfal_handle_freeG(handle);
}
示例#3
0
void gfal2_test_gfal_auto_get_srm_endpoint_full_endpoint_with_no_bdiiG()
{
#if USE_MOCK
	setup_mock_bdii();

#endif
	GError* err = NULL;
	char buff_endpoint[2048];
	enum gfal_srm_proto proto;
	gfal_handle handle = gfal_initG(&err);
	assert_true_with_message(handle != NULL, " handle is not properly allocated");
	if(handle==NULL)
		return;
	gfal_plugins_instance(handle, NULL);
	gfal_srmv2_opt opts;
	gfal_srm_opt_initG(&opts, handle);
	gfal_set_nobdiiG(handle, TRUE);
	int ret =-1;
	ret = gfal_srm_determine_endpoint(&opts, TEST_SRM_DPM_FULLENDPOINT_PREFIX, buff_endpoint, 2048, &proto, &err);
	assert_true_with_message( ret ==0 && err == NULL && strings_are_equal(buff_endpoint, TEST_SRM_DPM_FULLENDPOINT_URL), " must be a succesfull endpoint determination %d %ld %s", ret, err, buff_endpoint);
	gfal_check_GError(&err);	
	
	ret = gfal_srm_determine_endpoint(&opts, "srm://srm-pps:8443/srm/managerv2?SFN=/castor/cern.ch/grid/dteam/castordev/test-srm-pps_8443-srm2_d0t1-ed6b7013-5329-4f5b", buff_endpoint, 2048, &proto, &err);
	assert_true_with_message( ret ==0 && err == NULL && strings_are_equal(buff_endpoint, "httpg://srm-pps:8443/srm/managerv2"), " must be a succesfull endpoint determination 2 %d %ld %s", ret, err, buff_endpoint);
	gfal_check_GError(&err);
	memset(buff_endpoint,0, sizeof(char)*2048);
	ret = gfal_srm_determine_endpoint(&opts, TEST_SRM_VALID_SURL_EXAMPLE1, buff_endpoint, 2048, &proto, &err);
	assert_true_with_message( ret !=0 && err != NULL && err->code== EINVAL && *buff_endpoint=='\0', " must be a reported error, bdii is disable");
	g_clear_error(&err);
	gfal_handle_freeG(handle);	
}
示例#4
0
void gfal2_test_plugin_access_file()
{
	GError* tmp_err=NULL;
	gfal_handle handle = gfal_initG(&tmp_err);
	assert_true_with_message(handle != NULL, " must init properly");
	if(handle == NULL)	
		return;
	gfal_plugins_instance(handle, &tmp_err);
	assert_true_with_message(tmp_err== NULL, " must be instance properly");
	if(tmp_err)
		return;
	test_mock_lfc(handle, &tmp_err);
	assert_true_with_message(tmp_err== NULL, " must be mocked properly");
	if(tmp_err)
			return;
#if USE_MOCK
	will_respond(lfc_mock_access, 0, want_string(path, TEST_LFC_VALID_ACCESS+4), want(mode, F_OK));
	will_respond(lfc_mock_access, ENOENT, want_string(path, TEST_LFC_NOEXIST_ACCESS+4), want(mode, F_OK));
	always_return(lfc_mock_access, EINVAL);
#endif
	int ret = gfal_plugins_accessG(handle, TEST_LFC_VALID_ACCESS, F_OK, &tmp_err);
	assert_true_with_message(ret == 0, " must be a valid access");

	
	ret = gfal_plugins_accessG(handle, TEST_LFC_NOEXIST_ACCESS, F_OK, &tmp_err);	
	assert_true_with_message(ret!=0 && tmp_err!=NULL && tmp_err->code == ENOENT, " must be a non-existing file %d %ld %d", (int)ret, (long)tmp_err, (int) (tmp_err)?(tmp_err->code):0);
	
	g_clear_error(&tmp_err);
	gfal_handle_freeG(handle);
}
示例#5
0
void test_mock_guid_open_invalid(const char * guid1){
#if USE_MOCK
	gfal_handle handle = gfal_posix_instance();
	gfal_plugins_instance(handle,NULL);
		
	will_respond(lfc_mock_getlinks, ENOENT, want_string(guid, ((char*)guid1)+5), want(path, NULL), want_non_null(nbentries), want_non_null(linkinfos));	
#endif	
}
示例#6
0
void mock_srm_access_right_response(char* surl){
#if USE_MOCK
	GError* mock_err=NULL;
	gfal_handle handle = gfal_posix_instance();
	gfal_plugins_instance(handle,NULL);
	test_mock_lfc(handle, &mock_err);
	setup_mock_srm();
	if( gfal_check_GError(&mock_err))
		return;
	gfal_plugins_instance(handle, NULL);
	char* surls[] = { surl, NULL };
	char* turls[] = { "nawak", NULL };
	int status[] = { 0, 0 };

	define_mock_srmv2_filestatus(1, surls, NULL,  turls, status);
	define_mock_endpoints(TEST_SRM_DPM_FULLENDPOINT_URL);
	will_respond(srm_mock_srm_context_init, 0, want_non_null(context), want_string(srm_endpoint, TEST_SRM_DPM_FULLENDPOINT_URL));
	will_respond(srm_mock_srm_check_permission, 1, want_non_null(context), want_non_null(statuses), want_non_null(input));		
#endif
}
示例#7
0
void test_srm_mock_chmod(char* url, int retcode){
#if USE_MOCK
	gfal_handle handle = gfal_posix_instance();
	gfal_plugins_instance(handle,NULL);
	
	setup_mock_srm();
	define_mock_endpoints(TEST_SRM_DPM_FULLENDPOINT_URL);

	will_respond(srm_mock_srm_context_init, 0, want_non_null(context), want_string(srm_endpoint, TEST_SRM_DPM_FULLENDPOINT_URL));
	will_respond(srm_mock_srm_setpermission, retcode, want_non_null(context), want_non_null(input));		
#endif	
	
}
示例#8
0
void test_mock_lfc_open_eacces(const char* lfc_url){
#if USE_MOCK
	GError* mock_err=NULL;
	gfal_handle handle = gfal_posix_instance();
	gfal_plugins_instance(handle,NULL);
	test_mock_lfc(handle, &mock_err);
	setup_mock_srm();
	if( gfal_check_GError(&mock_err))
		return;	
	will_respond(lfc_mock_getreplica, EACCES, want_string(path, ((char*)lfc_url)+4), want_non_null(nbentries), want_non_null(rep_entries));	
	
#endif	
}
示例#9
0
void gfal2_test__plugin_lstat()
{
	struct stat resu;
	memset(&resu, 0, sizeof(struct stat));
	GError* tmp_err=NULL;
	
	gfal_handle handle = gfal_initG(&tmp_err);
	assert_true_with_message(handle != NULL, " must init properly");
	if(handle == NULL)
		return;

	gfal_plugins_instance(handle, &tmp_err);
	assert_true_with_message(tmp_err==NULL, " must be a valid instance call");
	if(tmp_err)
		return;
	test_mock_lfc(handle, &tmp_err);
	assert_true_with_message(tmp_err==NULL, " must be a valid mock call");
	if(tmp_err)
		return;	
	
#if USE_MOCK
	struct lfc_filestat f;
	f.filemode = TEST_GFAL_LFC_FILE_STAT_MODE_VALUE;
	f.uid = TEST_GFAL_LFC_FILE_STAT_UID_VALUE ;
	f.gid=TEST_GFAL_LFC_FILE_STAT_GID_VALUE ;
	will_respond(lfc_mock_lstatg, 0, want_string(lfn, TEST_GFAL_LFC_FILE_STAT_OK+4));
	defined_filestat = &f;
	will_respond(lfc_mock_lstatg, 0, want_string(lfn, TEST_GFAL_LFC_LINK_STAT_OK+4));
	defined_filestat = &f;
	will_respond(lfc_mock_lstatg, ENOENT, want_string(lfn, TEST_GFAL_LFC_FILE_STAT_NONEXIST+4));
	always_return(lfc_mock_lstatg, EINVAL);
#endif	
	

	int ret = gfal_plugin_lstatG(handle, TEST_GFAL_LFC_FILE_STAT_OK, &resu, &tmp_err);
	assert_true_with_message(ret==0 && tmp_err==NULL, " must be a success convertion");


	ret = gfal_plugin_lstatG(handle, TEST_GFAL_LFC_LINK_STAT_OK, &resu, &tmp_err);
	assert_true_with_message(ret==0 && tmp_err==NULL, " must be a success convertion");

	
	//g_printerr(" extract from the stat struct : right : %o, owner : %d, group : %d, size : %lu", resu.st_mode, resu.st_uid, resu.st_gid, resu.st_size);	
	ret = gfal_plugin_lstatG(handle, TEST_GFAL_LFC_FILE_STAT_NONEXIST, &resu, &tmp_err);
	assert_true_with_message(ret != 0 && tmp_err!=NULL && tmp_err->code == ENOENT, " must be a failure");
	
	
	g_clear_error(&tmp_err);
	gfal_handle_freeG(handle);
	
}
示例#10
0
void test_mock_srm_open_invalid(char** tab, char** tab_exp, int* res){
#if USE_MOCK
	test_rfio_mock_all();
	setup_mock_srm();
	gfal_handle handle = gfal_posix_instance();
	gfal_plugins_instance(handle,NULL);
	
	define_mock_endpoints(TEST_SRM_DPM_FULLENDPOINT_URL); // mock the mds for the srm endpoitn resolution


	will_respond(srm_mock_srm_context_init, 0, want_non_null(context), want_string(srm_endpoint, TEST_SRM_DPM_FULLENDPOINT_URL));
	define_mock_srmv2_pinfilestatus(1, tab, tab_exp, NULL , res);
	will_respond(srm_mock_srm_prepare_to_get, 1, want_non_null(context), want_non_null(input), want_non_null(output));
#endif
}
示例#11
0
void gfal2_test_gfal_srm_getTURLS_pipeline_success()
{
	setup_mock_srm();
	setup_mock_bdii();
	int i1;
#if USE_MOCK
	define_se_endpoints = calloc(sizeof(char*), 4); // set the response of the MDS layer for endpoint
	for(i1=0;i1 <3; ++i1)
		define_se_endpoints[i1]= strdup(TEST_SRM_DPM_FULLENDPOINT_URL);
	define_se_types= calloc(sizeof(char*), 4);
	char* types[] = { "srm_v1", "srm_v2", "srm_v1"};
	for(i1=0;i1 <3; ++i1)
		define_se_types[i1]= strdup(types[i1]);	


	will_respond(srm_mock_srm_context_init, 0, want_non_null(context), want_string(srm_endpoint, TEST_SRM_DPM_FULLENDPOINT_URL));
	defined_get_output = calloc(sizeof(struct srmv2_pinfilestatus),3);
	defined_get_output[0].turl= strdup(TEST_SRM_TURL_EXAMPLE1);
	defined_get_output[1].status= ENOENT;
	defined_get_output[1].explanation = strdup("err msg");
	defined_get_output[2].turl = strdup(TEST_SRM_TURL_EXAMPLE1);
	will_respond(srm_mock_srm_prepare_to_get, 3, want_non_null(context), want_non_null(input), want_non_null(output));
	always_return(srm_mock_srm_srmv2_filestatus_delete,0);
	always_return(srm_mock_srm_srmv2_pinfilestatus_delete,0);
#endif
	GError* tmp_err=NULL;
	gfal_handle handle  = gfal_initG(&tmp_err);
	assert_true_with_message(handle != NULL, " handle is not properly allocated");
	if(handle==NULL)
		return;
	gfal_srmv2_opt opts;
	gfal_srm_opt_initG(&opts, handle);
	gfal_plugins_instance(handle, NULL);
	gfal_srm_result* resu=NULL;
	char* surls[] = {TEST_SRM_VALID_SURL_EXAMPLE1, TEST_SRM_INVALID_SURL_EXAMPLE2, TEST_SRM_VALID_SURL_EXAMPLE1, NULL};
	int ret = gfal_srm_getTURLS(&opts, surls, &resu, &tmp_err);
	assert_true_with_message(ret ==g_strv_length(surls) && resu != NULL && tmp_err == NULL, " must be a successfull request");
	gfal_check_GError(&tmp_err);
	assert_true_with_message(resu[0].err_code == 0 && *(resu[0].err_str)== '\0' && strings_are_equal(resu[0].turl, TEST_SRM_TURL_EXAMPLE1), 
				" must be a valid turl, maybe the turl has changed %d %ld %s",resu[0].err_code, resu[0].err_str, resu[0].turl);	

	assert_true_with_message(resu[1].err_code == ENOENT && *(resu[1].err_str)!= '\0' && *(resu[1].turl) == '\0', 
				" must be a invalid turl 2 ");	
	assert_true_with_message(resu[2].err_code == 0 && *(resu[2].err_str)== '\0' && strings_are_equal(resu[2].turl, TEST_SRM_TURL_EXAMPLE1), 
				" must be a valid turl 3, maybe the turl has changed ");	
	free(resu);
	gfal_handle_freeG(handle);
}
示例#12
0
void test_mock_lfc_open_valid(const char* lfc_url){ 
#if USE_MOCK
	char* tab[]= { TEST_SRM_VALID_SURL_EXAMPLE1, NULL };	
	char* tab_turl[] = { TEST_SRM_TURL_EXAMPLE1, NULL };
	int res[] = { 0, 0 };
	test_mock_srm_open_valid(tab, tab_turl, res);
	GError* mock_err=NULL;
	gfal_handle handle = gfal_posix_instance();
	gfal_plugins_instance(handle,NULL);
	test_mock_lfc(handle, &mock_err);

	if( gfal_check_GError(&mock_err))
		return;	

	define_mock_filereplica(1, tab);
	will_respond(lfc_mock_getreplica, 0, want_string(path, ((char*)lfc_url)+4), want_non_null(nbentries), want_non_null(rep_entries));	

#endif
}
示例#13
0
void gfal2_test_gfal_srm_determine_endpoint_not_fullG()
{
	
#if USE_MOCK
	int i1;
	setup_mock_bdii();
	char buff_tmp[2048];
	char* p = TEST_SRM_DPM_ENDPOINT_PREFIX+ strlen(GFAL_PREFIX_SRM);
	g_strlcpy(buff_tmp, p, strchr(p, '/')-p+1);
	define_se_endpoints = calloc(sizeof(char*), 4);
	for(i1=0;i1 <3; ++i1)
		define_se_endpoints[i1]= strdup(TEST_SRM_DPM_FULLENDPOINT_URL);
	define_se_types= calloc(sizeof(char*), 4);
	char* types[] = { "srm_v1", "srm_v2", "srm_v1"};
	for(i1=0;i1 <3; ++i1)
		define_se_types[i1]= strdup(types[i1]);	



#endif
	GError* err = NULL;
	char buff_endpoint[2048];
	enum gfal_srm_proto proto;
	gfal_handle handle = gfal_initG(&err);
	assert_true_with_message(handle != NULL, " handle is not properly allocated");
	if(handle==NULL)
		return;
	gfal_srmv2_opt opts;
	gfal_srm_opt_initG(&opts, handle);
	gfal_plugins_instance(handle, NULL);
	int ret =-1;
	ret = gfal_srm_determine_endpoint(&opts, TEST_SRM_DPM_ENDPOINT_PREFIX, buff_endpoint, 2048, &proto, &err);
	assert_true_with_message( ret ==0 && err == NULL && strings_are_equal(buff_endpoint, TEST_SRM_DPM_FULLENDPOINT_URL), " must be a succesfull endpoint determination %d %ld %s", ret, err, buff_endpoint);
	gfal_check_GError(&err);	
	
	ret = gfal_srm_determine_endpoint(&opts, "http://google.com", buff_endpoint, 2048, &proto, &err);
	assert_true_with_message( ret !=0 && err != NULL, "error must be reported %d %s", ret, ((err)?err->message:""));
	g_clear_error(&err);
	gfal_handle_freeG(handle);	
}
示例#14
0
void test_mock_srm_open_write_valid(char** tab, char** tab_turl, int* res){
#if USE_MOCK
	test_rfio_mock_all();
	setup_mock_srm();
	gfal_handle handle = gfal_posix_instance();
	gfal_plugins_instance(handle,NULL);
	int status[] = { 0,0 };
	char* turls[] = { "rfio://mockedturl", NULL };
	char* surls[] = { "srm://mockedsurl", NULL };
	
	define_mock_endpoints(TEST_SRM_DPM_FULLENDPOINT_URL); // mock the mds for the srm endpoitn resolution


	will_respond(srm_mock_srm_context_init, 0, want_non_null(context), want_string(srm_endpoint, TEST_SRM_DPM_FULLENDPOINT_URL));
	define_mock_srmv2_putoutput(1, tab, NULL, tab_turl, res);
	will_respond(srm_mock_srm_prepare_to_put, 1, want_non_null(context), want_non_null(input), want_non_null(output));

	will_respond(rfio_mock_open, 15, want_non_null(path));

	define_put_done(1, surls, NULL, turls, status);
	will_respond(srm_mock_srm_put_done,1, want_non_null(context));
	will_respond(rfio_mock_close, 0, want(fd, 15));
#endif
}