Add test for the FreeNAS API

- Add a simple API test using the FreeNAS API call to get its version
number, which could prove useful in future versions. Closes #17
- Whitespace cleanup
This commit is contained in:
Kevin Scott Adams 2018-07-31 22:38:59 -04:00
parent 42edb8614e
commit 3f6059e75f
1 changed files with 9 additions and 2 deletions

View File

@ -198,8 +198,8 @@ sub run_delete_lu {
my $target2extents = freenas_iscsi_get_target_to_extent($scfg);
foreach my $item (@$target2extents) {
if($item->{'iscsi_target'} == $target_id &&
$item->{'iscsi_lunid'} == $lun->{'iscsi_lunid'} &&
if($item->{'iscsi_target'} == $target_id &&
$item->{'iscsi_lunid'} == $lun->{'iscsi_lunid'} &&
$item->{'iscsi_extent'} == $lun->{'id'}) {
$link = $item;
@ -230,6 +230,7 @@ sub freenas_api_call {
my ($scfg, $method, $path, $data) = @_;
my $client = undef;
my $scheme = $scfg->{freenas_use_ssl} ? "https" : "http";
my $apiping = '/api/v1.0/system/version/';
$client = REST::Client->new();
$client->setHost($scheme . '://' . $scfg->{portal});
@ -240,6 +241,12 @@ sub freenas_api_call {
$client->getUseragent()->ssl_opts(verify_hostname => 0);
$client->getUseragent()->ssl_opts(SSL_verify_mode => SSL_VERIFY_NONE);
}
# Check if the API is working via the selected scheme
my $code = $client->request('GET', $apiping)->responseCode();
if ($code != 200) {
freenas_api_log_error($client, "freenas_api_call");
die "Unable to connect to the FreeNAS API service at '" . $scfg->{portal} . "' using '" . $scheme . "' protocol";
}
if ($method eq 'GET') {
$client->GET($path);
}