test scripts for the rest api

This commit is contained in:
Bruce Potter 2014-01-31 08:26:55 -05:00
parent a3d6555515
commit 466d5f0a9f
2 changed files with 128 additions and 0 deletions

View File

@ -0,0 +1,103 @@
#!/usr/bin/env perl
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
# This is a command which can be used to access the rest api of xCAT
use strict;
use Getopt::Long;
use LWP;
use JSON;
require HTTP::Request;
# set the usage message
my $usage_string = "Usage:
restapi -u url -m GET|PUT|POST|DELETE [-f html|json|xml] [-V]
-u The url of the action. .e.g to get the power status of node \'nodename\' https://httpserver/xcatws/nodes/nodename/power
-m The method of the request
-h The hostname of the xCAT web server
-o Target object
-f The output format of the requested action
-V Display the verbose message\n";
# Parse the argument
$Getopt::Long::ignorecase = 0;
Getopt::Long::Configure( "bundling" );
if (!GetOptions( 'u=s' => \$::URL,
'f=s' => \$::FORMAT,
'h=s' => \$::HOST,
'o=s' => \$::OBJ,
'm=s' => \$::METHOD,
'V' => \$::VERBOSE )) {
print $usage_string;
exit 1;
}
if (defined($::FORMAT)) {
if ($::FORMAT eq "") {
$::FORMAT = "html";
} elsif ($::FORMAT !~ /^(html|json|xml)$/) {
print $usage_string;
exit 1;
}
}
else{
$::FORMAT = "html";
}
if (defined($::METHOD)){
if ($::METHOD !~/^(GET|PUT|POST|DELETE)$/){
print $usage_string;
exit 1;
}
}
else{
print $usage_string;
exit 1;
}
if (!$::URL) {
if ($::HOST && $::OBJ) {
$::URL = "https://$::HOST/xcatws/$::OBJ?format=$::FORMAT";
} else {
print $usage_string;
exit 1;
}
} else {
if ($::URL =~ /\?/){
$::URL .= "&format=$::FORMAT";
}
else{
$::URL .= "?format=$::FORMAT";
}
}
my @updatearray;
my $fieldname;
my $fieldvalue;
if (scalar(@ARGV) > 0){
foreach my $tempstr (@ARGV){
push @updatearray, $tempstr;
}
}
my $request;
my $ua = LWP::UserAgent->new();
my $response;
if (($::METHOD eq 'PUT') || ($::METHOD eq 'POST')){
my $tempstr = encode_json \@updatearray;
$request = HTTP::Request->new($::METHOD => $::URL);
$request->header('content-type' => 'text/plain');
$request->header('content-length' => length($tempstr));
$request->content($tempstr);
}
elsif(($::METHOD eq 'GET'|| ($::METHOD eq 'DELETE'))){
$request = HTTP::Request->new($::METHOD=>$::URL);
}
my $response = $ua->request($request);
print $response->content . "\n";
print $response->code . "\n";
print $response->message . "\n";

View File

@ -0,0 +1,25 @@
#!/usr/bin/perl
# test & doc all current calls
# finish test driver (including calling it natively from perl)
# restructure & comment code
# add debugging and fix bugs:
# - all put and post calls
# - and allow put data in url args too
# change structure of json and add Returns lines to doc
# add missing functionality
# - nodeset stat
# - osimage create and change and delete and copycds
# do perf test and optimize code
curl -X GET -k 'http://127.0.0.1/xcatws/nodes?userName=bp&password=and9ew88&format=xml'
curl -X GET -k 'https://9.114.34.210/xcatws/nodes?userName=bp&password=bryan1&format=xml'
curl -X GET -k 'https://9.114.34.210/xcatws/nodes?userName=bp&password=bryan1&format=xml&field=mac'
curl -X GET -k 'https://9.114.34.210/xcatws/nodes/test001-test006?userName=bp&password=bryan1&format=xml'
curl -X GET -k 'https://9.114.34.210/xcatws/nodes/test001-test006?userName=bp&password=bryan1&format=xml&field=mac'
#curl -X PUT -k --data '{"room":"foo"}' 'https://127.0.0.1/xcatws/nodes/test001?userName=bp&password=bryan1'
#curl -X POST -k --data '{"groups":"compute,all"}' 'https://127.0.0.1/xcatws/nodes/test001?userName=bp&password=bryan1'
curl -X DELETE -k 'http://127.0.0.1/xcatws/nodes/test001?userName=bp&password=and9ew88'
./restapi -u "https://127.0.0.1/xcatws/nodes/test001?userName=bp&password=bryan1" -m GET
./restapi -u "https://10.1.0.210/xcatws/nodes/test001?userName=bp&password=bryan1" -m PUT "nodepos.room=foo"