mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-11-27 07:30:33 +08:00
f3e711e2b8
re: https://github.com/Unidata/netcdf-c/issues/2177 re: https://github.com/Unidata/netcdf-c/pull/2178 Provide get/set functions to store global data alignment information and apply it when a file is created. The api is as follows: ```` int nc_set_alignment(int threshold, int alignment); int nc_get_alignment(int* thresholdp, int* alignmentp); ```` If defined, then for every file created opened after the call to nc_set_alignment, for every new variable added to the file, the most recently set threshold and alignment values will be applied to that variable. The nc_get_alignment function return the last values set by nc_set_alignment. If nc_set_alignment has not been called, then it returns the value 0 for both threshold and alignment. The alignment parameters are stored in the NCglobalstate object (see below) for use as needed. Repeated calls to nc_set_alignment will overwrite any existing values in NCglobalstate. The alignment parameters are applied in libhdf5/hdf5create.c and libhdf5/hdf5open.c The set/get alignment functions are defined in libsrc4/nc4internal.c. A test program was added as nc_test4/tst_alignment.c. ## Misc. Changes Unrelated to Alignment * The NCRCglobalstate type was renamed to NCglobalstate to indicate that it represented more general global state than just .rc data. It was also moved to nc4internal.h. This led to a large number of small changes: mostly renaming. The global state management functions were moved to nc4internal.c. * The global chunk cache variables have been moved into NCglobalstate. As warranted, other global state will be moved as well. * Some misc. problems with the nczarr performance tests were corrected.
178 lines
4.8 KiB
C
178 lines
4.8 KiB
C
/*********************************************************************
|
|
* Copyright 2018, UCAR/Unidata
|
|
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
|
|
*********************************************************************/
|
|
|
|
/**
|
|
Test the handling of aws profiles and regions.
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <assert.h>
|
|
#include "netcdf.h"
|
|
#include "ncrc.h"
|
|
#include "ncpathmgr.h"
|
|
|
|
#undef DEBUG
|
|
|
|
typedef struct ProfileTest {
|
|
const char* profile;
|
|
const char* access_key;
|
|
const char* secret_key;
|
|
const char* region;
|
|
} ProfileTest;
|
|
|
|
typedef struct URLTest {
|
|
const char* url;
|
|
const char* newurl;
|
|
const char* profile;
|
|
const char* region;
|
|
const char* bucket;
|
|
} URLTest;
|
|
|
|
static ProfileTest PROFILETESTS[] = {
|
|
{"default", "ACCESSKEYDEFAULTXXXX", "DEFAULT/ef0ghijklmnopqr/defaultxxxxxxxxx",""},
|
|
{"ncar", "ACCESSKEYNCARXXXXXXX", "NCAR/ef0ghijklmnopqr/ncarxxxxxxxxxxxxxxx",""},
|
|
{"unidata", "ACCESSKEYUNIDATAXXXX", "UNIDATA/ef0ghijklmnopqr/unidataxxxxxxxxx", "us-west-1"},
|
|
{NULL, NULL,NULL,NULL}
|
|
};
|
|
|
|
static URLTest URLTESTS[] = {
|
|
{"s3://simplebucket#mode=nczarr,s3&aws.region=us-west-1",
|
|
"https://s3.us-west-1.amazonaws.com/simplebucket#mode=nczarr,s3&aws.region=us-west-1","default","us-west-1","simplebucket"},
|
|
#if 0
|
|
{"s3://simplebucket#mode=nczarr,s3&aws.profile=unidata",
|
|
"https://s3.us-west-1.amazonaws.com/simplebucket#mode=nczarr,s3&aws.profile=unidata","unidata","us-west-1","simplebucket"},
|
|
{"https://s3.eu-east-1.amazonaws.com/simplebucket#mode=nczarr,s3&aws.profile=none",
|
|
"https://s3.eu-east-1.amazonaws.com/simplebucket#mode=nczarr,s3&aws.profile=none","none","eu-east-1","simplebucket"},
|
|
{"https://s3.eu-west-1.amazonaws.com/bucket2#mode=nczarr,s3",
|
|
"https://s3.eu-west-1.amazonaws.com/bucket2#mode=nczarr,s3","default","eu-west-1","bucket2"},
|
|
#endif
|
|
{NULL, NULL,NULL,NULL,NULL}
|
|
};
|
|
|
|
static char* awstestdir0 = NULL;
|
|
|
|
void
|
|
failurltest(URLTest* test)
|
|
{
|
|
fprintf(stderr,"***FAIL: urL=%s\n",test->url);
|
|
#ifdef DEBUG
|
|
abort();
|
|
#endif
|
|
exit(1);
|
|
}
|
|
|
|
void
|
|
failprofiletest(ProfileTest* test)
|
|
{
|
|
fprintf(stderr,"***FAIL: profile=%s\n",test->profile);
|
|
#ifdef DEBUG
|
|
abort();
|
|
#endif
|
|
exit(1);
|
|
}
|
|
|
|
static int
|
|
testprofiles(void)
|
|
{
|
|
int stat = NC_NOERR;
|
|
ProfileTest* test;
|
|
int index;
|
|
|
|
for(index=0,test=PROFILETESTS;test->profile;test++,index++) {
|
|
const char* accesskey = NULL;
|
|
const char* region = NULL;
|
|
|
|
if((stat = NC_s3profilelookup(test->profile, "aws_access_key_id", &accesskey))) goto done;
|
|
if((stat = NC_s3profilelookup(test->profile, "aws_region", ®ion))) goto done;
|
|
if(region == NULL) region = "";
|
|
#ifdef DEBUG
|
|
printf("profile=%s aws_access_key_id=%s region=%s\n",
|
|
test->profile,
|
|
(accesskey?accesskey:""),
|
|
(region?region:""));
|
|
#endif
|
|
if(accesskey == NULL || strcasecmp(accesskey,test->access_key)!=0) failprofiletest(test);
|
|
if(region == NULL || strcasecmp(region,test->region)!=0) failprofiletest(test);
|
|
}
|
|
done:
|
|
return stat;
|
|
}
|
|
|
|
static int
|
|
testurls(void)
|
|
{
|
|
int stat = NC_NOERR;
|
|
URLTest* test;
|
|
int index;
|
|
NCURI* url = NULL;
|
|
NCURI* url2 = NULL;
|
|
const char* profile = NULL;
|
|
char* region = NULL;
|
|
char* bucket = NULL;
|
|
char* newurl = NULL;
|
|
|
|
for(index=0,test=URLTESTS;test->url;test++,index++) {
|
|
ncuriparse(test->url,&url);
|
|
if(url == NULL) {
|
|
fprintf(stderr,"URI parse fail: %s\n",test->url);
|
|
goto done;
|
|
}
|
|
if((stat = NC_getactives3profile(url, &profile))) {
|
|
fprintf(stderr,"active profile fail: %s\n",test->url);
|
|
goto done;
|
|
}
|
|
if((stat = NC_s3urlrebuild(url, &url2, &bucket, ®ion))) {
|
|
fprintf(stderr,"url rebuild failed: %s\n",test->url);
|
|
goto done;
|
|
}
|
|
newurl = ncuribuild(url2,NULL,NULL,NCURIALL);
|
|
#ifdef DEBUG
|
|
printf("url=%s {url=%s bucket=%s region=%s profile=%s}\n",
|
|
test->url,newurl,bucket,region,profile);
|
|
#endif
|
|
if(strcasecmp(newurl,test->newurl)!=0) failurltest(test);
|
|
if(strcasecmp(profile,test->profile)!=0) failurltest(test);
|
|
if(strcasecmp(region,test->region)!=0) failurltest(test);
|
|
if(strcasecmp(bucket,test->bucket)!=0) failurltest(test);
|
|
ncurifree(url); url = NULL;
|
|
ncurifree(url2); url2 = NULL;
|
|
nullfree(newurl); newurl = NULL;
|
|
nullfree(bucket); bucket = NULL;
|
|
nullfree(region); region = NULL;
|
|
}
|
|
done:
|
|
return stat;
|
|
}
|
|
|
|
|
|
int
|
|
main(int argc, char** argv)
|
|
{
|
|
int stat = NC_NOERR;
|
|
|
|
awstestdir0 = getenv("NC_TEST_AWS_DIR");
|
|
if(awstestdir0 == NULL) {
|
|
fprintf(stderr,"NC_TEST_AWS_DIR environment variable is undefined\n");
|
|
goto done;
|
|
}
|
|
|
|
/* Load RC and .aws/config */
|
|
if((stat = nc_initialize())) goto done;
|
|
|
|
printf("testprofiles:\n-------------\n");
|
|
stat = testprofiles();
|
|
|
|
printf("testurls:\n--------\n");
|
|
stat = testurls();
|
|
|
|
printf("***PASS test_aws\n");
|
|
|
|
done:
|
|
if(stat) printf("*** FAIL: %s(%d)\n",nc_strerror(stat),stat);
|
|
exit(stat?1:0);
|
|
}
|