From: rettenbe Date: Wed, 6 Aug 2008 13:33:34 +0000 (+0000) Subject: * bugfix: opsi_add_client X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=525cc7737005e3d408e5612d3cef918ea3e920f5;p=gosa.git * bugfix: opsi_add_client * bugfix: check_opsi_res git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@12162 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index a2eaf89a1..dcf3b063f 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -1468,21 +1468,6 @@ sub session_start { } -sub check_opsi_res { - my $res= shift; - if($res) { - if ($res->is_error) { - &main::daemon_log("ERROR: opsi configed communication failed: ".$res->error_message, 1); - } else { - return 1; - } - } else { - &main::daemon_log("ERROR: opsi configed communication failed: ".$opsi_client->status_line, 1); - } - return 0; -} - - sub watch_for_done_jobs { #CHECK: $heap for what? my ($kernel,$heap) = @_[KERNEL, HEAP]; @@ -1526,6 +1511,7 @@ sub watch_for_opsi_jobs { }; my $hres = $opsi_client->call($opsi_url, $callobj); + my ($hres_err, $hres_err_string) = &check_opsi_res($hres); if (&check_opsi_res($hres)) { my $htmp= $hres->result->{$hostId}; diff --git a/gosa-si/modules/GosaSupportDaemon.pm b/gosa-si/modules/GosaSupportDaemon.pm index f0998cfe3..c10a0e46f 100644 --- a/gosa-si/modules/GosaSupportDaemon.pm +++ b/gosa-si/modules/GosaSupportDaemon.pm @@ -30,6 +30,7 @@ my @functions = ( "run_as", "inform_all_other_si_server", "read_configfile", + "check_opsi_res", ); @EXPORT = @functions; use strict; @@ -732,4 +733,24 @@ sub read_configfile { } +sub check_opsi_res { + my $res= shift; + + if($res) { + if ($res->is_error) { + my $error_string; + if (ref $res->error_message eq "HASH") { + $error_string = $res->error_message->{'message'}; + } else { + $error_string = $res->error_message; + } + return 1, $error_string; + } + } else { + return 1, $main::opsi_client->status_line; + } + return 0; +} + + 1; diff --git a/gosa-si/server/events/opsi_com.pm b/gosa-si/server/events/opsi_com.pm index e38f7c495..d0acd00cd 100644 --- a/gosa-si/server/events/opsi_com.pm +++ b/gosa-si/server/events/opsi_com.pm @@ -54,7 +54,7 @@ sub opsi_add_product_to_client { # TODO: check dependencies later on? # build return message with twisted target and source - my $out_hash = &main::create_xml_hash("answer_$header", $target, $source); + my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source); if (defined $forward_to_gosa) { &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa); } @@ -73,10 +73,12 @@ sub opsi_add_product_to_client { params => [ $productId, $hostId, "setup" ], id => 1, }; + my $sres = $main::opsi_client->call($main::opsi_url, $callobj); - if (&main::check_opsi_res($sres)){ - &main::daemon_log("ERROR: cannot add product: ".$sres->error_message, 1); - &add_content2xml_hash($out_hash, "error", $sres->error_message); + my ($sres_err, $sres_err_string) = &check_opsi_res($sres); + if ($sres_err){ + &main::daemon_log("$session_id ERROR: cannot add product: ".$sres_err_string, 1); + &add_content2xml_hash($out_hash, "error", $sres_err_string); } # return message @@ -93,7 +95,7 @@ sub opsi_del_product_from_client { my ($hostId, $productId); # build return message with twisted target and source - my $out_hash = &main::create_xml_hash("answer_$header", $target, $source); + my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source); if (defined $forward_to_gosa) { &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa); } @@ -114,9 +116,10 @@ sub opsi_del_product_from_client { # id => 1, }; # #my $sres = $main::opsi_client->call($main::opsi_url, $callobj); - #if (&main::check_opsi_res($sres)){ - # &main::daemon_log("ERROR: cannot perform dependency check: ".$res->error_message, 1); - # &add_content2xml_hash($out_hash, "error", $res->error_message); + #my ($sres_err, $sres_err_string) = &check_opsi_res($sres); + #if ($sres_err){ + # &main::daemon_log("ERROR: cannot perform dependency check: ".$sres_err_string, 1); + # &add_content2xml_hash($out_hash, "error", $sres_err_string); # return ( &create_xml_string($out_hash) ); #} @@ -128,9 +131,10 @@ sub opsi_del_product_from_client { id => 1, }; my $sres = $main::opsi_client->call($main::opsi_url, $callobj); - if (&main::check_opsi_res($sres)){ - &main::daemon_log("ERROR: cannot get product action list: ".$sres->error_message, 1); - &add_content2xml_hash($out_hash, "error", $sres->error_message); + my ($sres_err, $sres_err_string) = &check_opsi_res($sres); + if ($sres_err){ + &main::daemon_log("$session_id ERROR: cannot get product action list: ".$sres_err_string, 1); + &add_content2xml_hash($out_hash, "error", $sres_err_string); return ( &create_xml_string($out_hash) ); } my $uninst_possible= 0; @@ -140,7 +144,7 @@ sub opsi_del_product_from_client { } } if (!$uninst_possible){ - &main::daemon_log("ERROR: cannot uninstall product", 1); + &main::daemon_log("$session_id ERROR: cannot uninstall product", 1); &add_content2xml_hash($out_hash, "error", "product is not uninstallable"); return ( &create_xml_string($out_hash) ); } @@ -153,9 +157,10 @@ sub opsi_del_product_from_client { id => 1, }; $sres = $main::opsi_client->call($main::opsi_url, $callobj); - if (&main::check_opsi_res($sres)){ - &main::daemon_log("ERROR: cannot delete product: ".$sres->error_message, 1); - &add_content2xml_hash($out_hash, "error", $sres->error_message); + my ($sres_err, $sres_err_string) = &check_opsi_res($sres); + if ($sres_err){ + &main::daemon_log("$session_id ERROR: cannot delete product: ".$sres_err_string, 1); + &add_content2xml_hash($out_hash, "error", $sres_err_string); return ( &create_xml_string($out_hash) ); } @@ -173,7 +178,7 @@ sub opsi_add_client { my $hostId; # build return message with twisted target and source - my $out_hash = &main::create_xml_hash("answer_$header", $target, $source); + my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source); if (defined $forward_to_gosa) { &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa); } @@ -196,21 +201,22 @@ sub opsi_add_client { if (defined @{$msg_hash->{'ip'}}[0]){ $ip = @{$msg_hash->{'ip'}}[0]; } - if (defined @{$msg_hash->{'mac'}}[0]){ - $mac = @{$msg_hash->{'mac'}}[0]; + if (defined @{$msg_hash->{'macaddress'}}[0]){ + $mac = @{$msg_hash->{'macaddress'}}[0]; } my $callobj; $callobj = { - method => 'createclient', + method => 'createClient', params => [ $name, $domain, $description, $notes, $ip, $mac ], id => 1, }; my $sres = $main::opsi_client->call($main::opsi_url, $callobj); - if (&main::check_opsi_res($sres)){ - &main::daemon_log("ERROR: cannot create client: ".$sres->error_message, 1); - &add_content2xml_hash($out_hash, "error", $sres->error_message); + my ($sres_err, $sres_err_string) = &check_opsi_res($sres); + if ($sres_err){ + &main::daemon_log("$session_id ERROR: cannot create client: ".$sres_err_string, 1); + &add_content2xml_hash($out_hash, "error", $sres_err_string); } # return message @@ -227,7 +233,7 @@ sub opsi_modify_client { my $hostId; # build return message with twisted target and source - my $out_hash = &main::create_xml_hash("answer_$header", $target, $source); + my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source); if (defined $forward_to_gosa) { &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa); } @@ -251,9 +257,10 @@ sub opsi_modify_client { id => 1, }; my $sres = $main::opsi_client->call($main::opsi_url, $callobj); - if (&main::check_opsi_res($sres)){ - &main::daemon_log("ERROR: cannot set description: ".$sres->error_message, 1); - &add_content2xml_hash($out_hash, "error", $sres->error_message); + my ($sres_err, $sres_err_string) = &check_opsi_res($sres); + if ($sres_err){ + &main::daemon_log("ERROR: cannot set description: ".$sres_err_string, 1); + &add_content2xml_hash($out_hash, "error", $sres_err_string); return ( &create_xml_string($out_hash) ); } } @@ -265,9 +272,10 @@ sub opsi_modify_client { id => 1, }; my $sres = $main::opsi_client->call($main::opsi_url, $callobj); - if (&main::check_opsi_res($sres)){ - &main::daemon_log("ERROR: cannot set notes: ".$sres->error_message, 1); - &add_content2xml_hash($out_hash, "error", $sres->error_message); + my ($sres_err, $sres_err_string) = &check_opsi_res($sres); + if ($sres_err){ + &main::daemon_log("ERROR: cannot set notes: ".$sres_err_string, 1); + &add_content2xml_hash($out_hash, "error", $sres_err_string); return ( &create_xml_string($out_hash) ); } } @@ -279,9 +287,10 @@ sub opsi_modify_client { id => 1, }; my $sres = $main::opsi_client->call($main::opsi_url, $callobj); - if (&main::check_opsi_res($sres)){ - &main::daemon_log("ERROR: cannot set mac address: ".$sres->error_message, 1); - &add_content2xml_hash($out_hash, "error", $sres->error_message); + my ($sres_err, $sres_err_string) = &check_opsi_res($sres); + if ($sres_err){ + &main::daemon_log("ERROR: cannot set mac address: ".$sres_err_string, 1); + &add_content2xml_hash($out_hash, "error", $sres_err_string); return ( &create_xml_string($out_hash) ); } } @@ -305,7 +314,7 @@ sub opsi_get_netboot_products { my $hostId; # build return message with twisted target and source - my $out_hash = &main::create_xml_hash("answer_$header", $target, $source); + my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source); if (defined $forward_to_gosa) { &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa); } @@ -331,7 +340,7 @@ sub opsi_get_netboot_products { my %r = (); for (@{$res->result}) { $r{$_} = 1 } - if (&main::check_opsi_res($res)){ + if (&check_opsi_res($res)){ if (defined $hostId){ $callobj = { @@ -341,7 +350,7 @@ sub opsi_get_netboot_products { }; my $hres = $main::opsi_client->call($main::opsi_url, $callobj); - if (&main::check_opsi_res($hres)){ + if (&check_opsi_res($hres)){ my $htmp= $hres->result->{$hostId}; # check state != not_installed or action == setup -> load and add @@ -363,7 +372,7 @@ sub opsi_get_netboot_products { }; my $sres = $main::opsi_client->call($main::opsi_url, $callobj); - if (&main::check_opsi_res($sres)){ + if (&check_opsi_res($sres)){ my $tres= $sres->result; my $name= xml_quote($tres->{'name'}); @@ -388,7 +397,7 @@ sub opsi_get_netboot_products { }; my $sres = $main::opsi_client->call($main::opsi_url, $callobj); - if (&main::check_opsi_res($sres)){ + if (&check_opsi_res($sres)){ my $tres= $sres->result; my $name= xml_quote($tres->{'name'}); @@ -424,7 +433,7 @@ sub opsi_get_product_properties { my $hostId; # build return message with twisted target and source - my $out_hash = &main::create_xml_hash("answer_$header", $target, $source); + my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source); # Get hostID if defined if (defined @{$msg_hash->{'hostId'}}[0]){ @@ -444,7 +453,7 @@ sub opsi_get_product_properties { id => 1, }; my $res = $main::opsi_client->call($main::opsi_url, $callobj); - if (&main::check_opsi_res($res)){ + if (&check_opsi_res($res)){ foreach my $action (@{$res->result}){ &add_content2xml_hash($out_hash, "action", $action); } @@ -465,7 +474,7 @@ sub opsi_get_product_properties { $res = $main::opsi_client->call($main::opsi_url, $callobj); - if (&main::check_opsi_res($res)){ + if (&check_opsi_res($res)){ my $r= $res->result; foreach my $key (keys %{$r}) { my $item= ""; @@ -504,7 +513,7 @@ sub opsi_set_product_properties { my $hostId; # build return message with twisted target and source - my $out_hash = &main::create_xml_hash("answer_$header", $target, $source); + my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source); &add_content2xml_hash($out_hash, "ProductId", $productId); # Get hostID if defined @@ -545,10 +554,11 @@ sub opsi_set_product_properties { } my $res = $main::opsi_client->call($main::opsi_url, $callobj); - - if (!&main::check_opsi_res($res)){ - &main::daemon_log("ERROR: no communication failed while setting '".$item->{'name'}[0]."': ".$res->error_message, 1); - &add_content2xml_hash($out_hash, "error", $res->error_message); + my ($res_err, $res_err_string) = &check_opsi_res($res); +# TODO : This error message sounds strange + if ($res_err){ + &man::daemon_log("$session_id ERROR: no communication failed while setting '".$item->{'name'}[0]."': ".$res_err_string, 1); + &add_content2xml_hash($out_hash, "error", $res_err_string); } } @@ -572,7 +582,7 @@ sub opsi_get_client_hardware { my $hostId = @{$msg_hash->{'hostId'}}[0]; # build return message with twisted target and source - my $out_hash = &main::create_xml_hash("answer_$header", $target, $source); + my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source); if (defined $forward_to_gosa) { &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa); @@ -589,7 +599,7 @@ sub opsi_get_client_hardware { }; my $res = $main::opsi_client->call($main::opsi_url, $callobj); - if (&main::check_opsi_res($res)){ + if (&check_opsi_res($res)){ my $result= $res->result; foreach my $r (keys %{$result}){ my $item= "".xml_quote($r).""; @@ -628,7 +638,7 @@ sub opsi_list_clients { my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0]; # build return message with twisted target and source - my $out_hash = &main::create_xml_hash("answer_$header", $target, $source); + my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source); if (defined $forward_to_gosa) { &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa); @@ -645,7 +655,7 @@ sub opsi_list_clients { }; my $res = $main::opsi_client->call($main::opsi_url, $callobj); - if (&main::check_opsi_res($res)){ + if (&check_opsi_res($res)){ foreach my $host (@{$res->result}){ my $item= "".$host->{'hostId'}.""; @@ -677,7 +687,7 @@ sub opsi_get_client_software { my $hostId = @{$msg_hash->{'hostId'}}[0]; # build return message with twisted target and source - my $out_hash = &main::create_xml_hash("answer_$header", $target, $source); + my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source); if (defined $forward_to_gosa) { &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa); @@ -694,7 +704,7 @@ sub opsi_get_client_software { }; my $res = $main::opsi_client->call($main::opsi_url, $callobj); - if (&main::check_opsi_res($res)){ + if (&check_opsi_res($res)){ my $result= $res->result; } @@ -718,7 +728,7 @@ sub opsi_get_local_products { my $hostId; # build return message with twisted target and source - my $out_hash = &main::create_xml_hash("answer_$header", $target, $source); + my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source); # Get hostID if defined if (defined @{$msg_hash->{'hostId'}}[0]){ @@ -744,7 +754,7 @@ sub opsi_get_local_products { my %r = (); for (@{$res->result}) { $r{$_} = 1 } - if (&main::check_opsi_res($res)){ + if (&check_opsi_res($res)){ if (defined $hostId){ $callobj = { @@ -754,7 +764,7 @@ sub opsi_get_local_products { }; my $hres = $main::opsi_client->call($main::opsi_url, $callobj); - if (&main::check_opsi_res($hres)){ + if (&check_opsi_res($hres)){ my $htmp= $hres->result->{$hostId}; # check state != not_installed or action == setup -> load and add @@ -776,7 +786,7 @@ sub opsi_get_local_products { }; my $sres = $main::opsi_client->call($main::opsi_url, $callobj); - if (&main::check_opsi_res($sres)){ + if (&check_opsi_res($sres)){ my $tres= $sres->result; my $name= xml_quote($tres->{'name'}); @@ -801,7 +811,7 @@ sub opsi_get_local_products { }; my $sres = $main::opsi_client->call($main::opsi_url, $callobj); - if (&main::check_opsi_res($sres)){ + if (&check_opsi_res($sres)){ my $tres= $sres->result; my $name= xml_quote($tres->{'name'}); @@ -836,7 +846,7 @@ sub opsi_del_client { my $hostId = @{$msg_hash->{'hostId'}}[0]; # build return message with twisted target and source - my $out_hash = &main::create_xml_hash("answer_$header", $target, $source); + my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source); if (defined $forward_to_gosa) { &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa); @@ -892,7 +902,7 @@ sub opsi_install_client { # Set parameters in opsi if (not $error) { # build return message with twisted target and source - my $out_hash = &main::create_xml_hash("answer_$header", $target, $source); + my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source); if (defined $forward_to_gosa) { &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa); @@ -908,7 +918,7 @@ sub opsi_install_client { }; my $hres = $main::opsi_client->call($main::opsi_url, $callobj); - if (&main::check_opsi_res($hres)){ + if (&check_opsi_res($hres)){ my $htmp= $hres->result->{$hostId}; # check state != not_installed or action == setup -> load and add @@ -924,7 +934,7 @@ sub opsi_install_client { id => 1, }; my $res = $main::opsi_client->call($main::opsi_url, $callobj); - if (!&main::check_opsi_res($res)){ + if (!&check_opsi_res($res)){ &main::daemon_log("ERROR: cannot set product action request for $hostId!", 1); } else { &main::daemon_log("INFO: requesting 'setup' for '".$product->{'productId'}."' on $hostId", 1); diff --git a/gosa-si/tests/client.php b/gosa-si/tests/client.php index 62b0a6648..11368f7a8 100755 --- a/gosa-si/tests/client.php +++ b/gosa-si/tests/client.php @@ -156,6 +156,12 @@ for($count = 1; $count <= $zahl; $count++) # Install Opsi client $data = "
job_opsi_install_client
GOSA 00:01:6c:9d:b9:fa limux-cl-2.intranet.gonicus.de 00:11:25:4b:8c:e5
"; + # Add Opsi client + $data = "
gosa_opsi_add_client
GOSA 00:01:6c:9d:b9:fa limux-cl-1.intranet.gonicus.de 00:11:25:4b:8c:e6 Test halt
"; + + # Add product to Opsi client + + # Delete product from Opsi client ######################### # Mailqueue communication