From 3f6059e75fef02ae8a2588d221f6c8b1c6e32769 Mon Sep 17 00:00:00 2001 From: Kevin Scott Adams Date: Tue, 31 Jul 2018 22:38:59 -0400 Subject: [PATCH] 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 --- perl5/PVE/Storage/LunCmd/FreeNAS.pm | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/perl5/PVE/Storage/LunCmd/FreeNAS.pm b/perl5/PVE/Storage/LunCmd/FreeNAS.pm index aaea53e..befefde 100644 --- a/perl5/PVE/Storage/LunCmd/FreeNAS.pm +++ b/perl5/PVE/Storage/LunCmd/FreeNAS.pm @@ -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); }