Revision ef8002fd src/Tests/cloud_test.c
src/Tests/cloud_test.c | ||
---|---|---|
5 | 5 |
* |
6 | 6 |
* This is a small test program for the cloud interface |
7 | 7 |
* To try the simple test: run it with |
8 |
* ./cloud_test -c "provider=<cloud_provider>,<provider_opts>" [-g key | -p key=value] |
|
8 |
* ./cloud_test -c "provider=<cloud_provider>,<provider_opts>" [-g key | -p key=value | -n | -e ip:port]
|
|
9 | 9 |
* |
10 |
* the "-g" and "-p" parameters select the GET or PUT operation |
|
10 |
* -g GET key from cloud |
|
11 |
* -p PUT key=value on cloud |
|
12 |
* -n print the cloud node |
|
13 |
* -e check if ip:port references the cloud |
|
14 |
* -c set the configuration of the cloud provider |
|
11 | 15 |
* |
12 | 16 |
* For example, run |
13 | 17 |
* ./cloud_test -c "provider=delegate,delegate_lib=libfilecloud.so" -p hello=world |
... | ... | |
26 | 30 |
|
27 | 31 |
#define GET 0 |
28 | 32 |
#define PUT 1 |
33 |
#define GET_CLOUD_NODE 2 |
|
34 |
#define EQ_CLOUD_NODE 3 |
|
29 | 35 |
|
30 | 36 |
static const char *config; |
31 | 37 |
static int operation; |
... | ... | |
40 | 46 |
int o; |
41 | 47 |
char *temp; |
42 | 48 |
|
43 |
while ((o = getopt(argc, argv, "c:g:p:")) != -1) { |
|
49 |
while ((o = getopt(argc, argv, "c:g:p:ne:")) != -1) {
|
|
44 | 50 |
switch(o) { |
45 | 51 |
case 'c': |
46 | 52 |
config = strdup(optarg); |
... | ... | |
61 | 67 |
case 'g': |
62 | 68 |
key = strdup(optarg); |
63 | 69 |
break; |
64 |
default: |
|
70 |
case 'n': |
|
71 |
operation = GET_CLOUD_NODE; |
|
72 |
break; |
|
73 |
case 'e': |
|
74 |
operation = EQ_CLOUD_NODE; |
|
75 |
temp = strdup(optarg); |
|
76 |
|
|
77 |
key = strsep(&optarg, ":"); |
|
78 |
value = optarg; |
|
79 |
|
|
80 |
|
|
81 |
if (!value || !key){ |
|
82 |
printf("Expected ip:port for option -e"); |
|
83 |
free(temp); |
|
84 |
exit(-1); |
|
85 |
} |
|
86 |
break; |
|
87 |
default: |
|
65 | 88 |
fprintf(stderr, "Error: unknown option %c\n", o); |
66 | 89 |
|
67 | 90 |
exit(-1); |
... | ... | |
96 | 119 |
struct cloud_helper_context *cloud; |
97 | 120 |
char buffer[100]; |
98 | 121 |
int err; |
122 |
struct nodeID *t; |
|
99 | 123 |
struct timeval tout = {10, 0}; |
100 | 124 |
|
101 | 125 |
cmdline_parse(argc, argv); |
... | ... | |
142 | 166 |
printf("No value for the specified key. Received: %s\n", buffer); |
143 | 167 |
return 1; |
144 | 168 |
} |
169 |
break; |
|
170 |
case GET_CLOUD_NODE: |
|
171 |
printf("Cloud node: %s\n", node_addr(get_cloud_node(cloud))); |
|
172 |
break; |
|
173 |
case EQ_CLOUD_NODE: |
|
174 |
t = create_node(key, atoi(value)); |
|
175 |
printf("Node %s references cloud? %d\n", node_addr(get_cloud_node(cloud)), |
|
176 |
is_cloud_node(cloud, t)); |
|
177 |
break; |
|
145 | 178 |
} |
146 | 179 |
|
147 | 180 |
|
Also available in: Unified diff