From 82faa48a67760be8ca82cbb13bc2da08575c6fb6 Mon Sep 17 00:00:00 2001 From: rettenbe Date: Mon, 17 Mar 2008 14:29:22 +0000 Subject: [PATCH] add job entries if missing while installation git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@9899 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/gosa-si-server | 116 +++++++++------------------- gosa-si/modules/SIPackages.pm | 47 +++++++---- gosa-si/server/events/clMessages.pm | 111 +++++++------------------- 3 files changed, 93 insertions(+), 181 deletions(-) diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index ca0420dd6..8ef8e039b 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -40,8 +40,6 @@ use Sys::Syslog qw( :DEFAULT setlogsock); use Cwd; use File::Spec; use File::Basename; -use File::Find; -use File::Copy; use File::Path; use GOSA::DBsqlite; use GOSA::GosaSupportDaemon; @@ -54,7 +52,7 @@ use lib "/usr/lib/gosa-si/modules"; my (%cfg_defaults, $foreground, $verbose, $ping_timeout); my ($bus_activ, $bus, $msg_to_bus, $bus_cipher); -my ($server); +my ($server, $server_mac_address); my ($gosa_server, $job_queue_timeout, $job_queue_loop_delay); my ($known_modules); my ($pid_file, $procid, $pid, $log_file); @@ -62,9 +60,6 @@ my ($arp_activ, $arp_fifo); my ($xml); my $sources_list; my $max_clients; -my %repo_files=(); -my $repo_path; -my %repo_dirs=(); # variables declared in config file are always set to 'our' our (%cfg_defaults, $log_file, $pid_file, $server_ip, $server_port, $SIPackages_key, @@ -74,7 +69,6 @@ our (%cfg_defaults, $log_file, $pid_file, # additional variable which should be globaly accessable our $server_address; -our $server_mac_address; our $bus_address; our $gosa_address; our $no_bus; @@ -105,8 +99,16 @@ our $prg= basename($0); our $job_db; our $job_queue_tn = 'jobs'; my $job_queue_file_name; -my @job_queue_col_names = ("id INTEGER", "timestamp", "status", "result", "progress INTEGER", - "headertag", "targettag", "xmlmessage", "macaddress"); +my @job_queue_col_names = ("id INTEGER", + "timestamp", + "status DEFAULT 'none'", + "result DEFAULT 'none'", + "progress DEFAULT 'none'", + "headertag DEFAULT 'none'", + "targettag DEFAULT 'none'", + "xmlmessage DEFAULT 'none'", + "macaddress DEFAULT 'none'", + ); # holds all other gosa-sd as well as the gosa-sd-bus our $known_server_db; @@ -173,7 +175,6 @@ my $max_children = 2; "packages-list" => [\$packages_list_file_name, '/var/lib/gosa-si/packages.db'], "messaging" => [\$messaging_file_name, '/var/lib/gosa-si/messaging.db'], "source-list" => [\$sources_list, '/etc/apt/sources.list'], - "repo-path" => [\$repo_path, '/srv/www/repository'], "ldap-uri" => [\$ldap_uri, ""], "ldap-base" => [\$ldap_base, ""], "ldap-admin-dn" => [\$ldap_admin_dn, ""], @@ -945,20 +946,18 @@ sub update_jobdb_status_for_send_msgs { sub _start { my ($kernel) = $_[KERNEL]; &trigger_db_loop($kernel); - $kernel->yield('create_fai_server_db', $fai_server_tn ); + #$kernel->yield('create_fai_server_db', $fai_server_tn ); #$kernel->yield('create_fai_release_db', $fai_release_tn ); $kernel->sig(USR1 => "sig_handler"); } - sub sig_handler { - my ($kernel, $signal) = @_[KERNEL, ARG0] ; - daemon_log("0 INFO got signal '$signal'", 7); - $kernel->sig_handled(); - return; + my ($kernel, $signal) = @_[KERNEL, ARG0] ; + daemon_log("0 INFO got signal '$signal'", 1); + $kernel->sig_handled(); + return; } - sub next_task { my ($session, $heap) = @_[SESSION, HEAP]; @@ -1283,7 +1282,6 @@ sub watch_for_new_jobs { sub refresh_ldap_handle { my $mesg; - daemon_log("DEBUG: Trying to create a connection to URI $ldap_uri", 5); # Get an ldap handle, if we don't have one if( ! defined $ldap_handle ){ $ldap_handle = Net::LDAP->new( $ldap_uri ); @@ -1822,13 +1820,13 @@ sub create_sources_list { my $fh; open($fh, ">$result") or return undef; - if(defined($ldap_server_dn) and length($ldap_server_dn) > 0) { + if(defined($ldap_server_dn) && length($ldap_server_dn)>0) { my $mesg=$ldap_handle->search( - base => $ldap_server_dn, - scope => 'base', - attrs => 'FAIrepository', - filter => 'objectClass=FAIrepositoryServer' - ); + base => $ldap_server_dn, + scope => 'base', + attrs => 'FAIrepository', + ); + if($mesg->count) { foreach my $entry(@{$mesg->{'entries'}}) { my ($server, $tag, $release, $sections)= split /\|/, $entry->get_value('FAIrepository'); @@ -1880,12 +1878,10 @@ sub create_packages_list_db { } close (CONFIG); - find(\&cleanup_and_extract, keys( %repo_dirs ) ); daemon_log("INFO: create_packages_list_db: finished", 5); return; } - sub run_create_packages_list_db { my ($session, $heap) = @_[SESSION, HEAP]; my $task = POE::Wheel::Run->new( @@ -1896,13 +1892,11 @@ sub run_create_packages_list_db { ); $heap->{task}->{ $task->ID } = $task; } - sub parse_package_info { my ($baseurl, $dist, $section)= @_; my ($package); my ($path) = ($baseurl =~ m%://[^/]*(.*)$%); - $repo_dirs{ "${repo_path}/pool" } = 1; foreach $package ("Packages.gz"){ daemon_log("DEBUG: create_packages_list: fetch $baseurl, $dist, $section", 7); @@ -1910,7 +1904,6 @@ sub parse_package_info { parse_package( "$outdir/$dist/$section", $dist, $path ); } } - sub get_package { my ($url, $dest)= @_; @@ -1926,9 +1919,8 @@ sub get_package { } return 0; } - sub parse_package { - my ($path, $dist, $srv_path)= @_; + my ($path, $dist, $srv_path )= @_; my ($package, $version, $section, $description); my @sql_list; my $PACKAGES; @@ -1985,12 +1977,6 @@ sub parse_package { next; } - # Trigger for filename - if ($line =~ /^Filename:\s/){ - my ($filename) = ($line =~ /^Filename: (.*)$/); - store_fileinfo( $package, $filename, $dist, $srv_path, $version, $repo_path ); - next; - } } close( $PACKAGES ); @@ -1999,50 +1985,18 @@ sub parse_package { $packages_list_db->exec_statementlist(\@sql_list); } -sub store_fileinfo { - my( $package, $file, $dist, $path, $vers, $srvdir) = @_; - - my %fileinfo = ( - 'package' => $package, - 'dist' => $dist, - 'version' => $vers, - ); - - $repo_files{ "${srvdir}/$file" } = \%fileinfo; -} - -sub cleanup_and_extract { - - my %templates = (); - my $fileinfo = $repo_files{ $File::Find::name }; - - if( defined $fileinfo ) { - - my $dir = "$outdir/$fileinfo->{ 'dist' }/debconf.d"; - system( "mkdir -p '$dir'" ); - - system( "dpkg -e '$File::Find::name' '$dir/DEBIAN'" ); - if( -f "$dir/DEBIAN/templates" ) { - my $package = $fileinfo->{ 'package' }; - my $newver = $fileinfo->{ 'version' }; - - daemon_log("DEBUG: Found debconf templates in '$package' - $newver", 5); - if( exists $templates{ "$fileinfo->{ 'dist' }/$package" } ) { - my $oldver = $templates{ "$fileinfo->{ 'dist' }/$package" }; - my $ret = system( "dpkg --compare-versions '$oldver' gt '$newver'" ); - if( ! $ret ) { - daemon_log("DEBUG: duplicated '$package' ($newver) in $fileinfo->{ 'dist' } - keeping tmpl v'$oldver'", 5); - return; - } - else { - daemon_log("DEBUG: duplicated '$package' ($newver) in $fileinfo->{ 'dist' } - overwriting tmpl v'$oldver'", 5); - } - } - $templates{ "$fileinfo->{ 'dist' }/$package" } = $newver; - move( "$dir/DEBIAN/templates", "$dir/$package.templates" ); - } - } -} +# +#sub store_fileinfo { +# my( $package, $file, $dist, $path, $vers ) = @_; +# +# my %fileinfo = ( +# 'package' => $package, +# 'dist' => $dist, +# 'version' => $vers +# ); +# +# $repo_files{ "${srvdir}${path}/$file" } = \%fileinfo; +#} #==== MAIN = main ============================================================== diff --git a/gosa-si/modules/SIPackages.pm b/gosa-si/modules/SIPackages.pm index 832453160..7ee752072 100644 --- a/gosa-si/modules/SIPackages.pm +++ b/gosa-si/modules/SIPackages.pm @@ -23,7 +23,7 @@ use lib "/usr/lib/gosa-si/server/events"; BEGIN{} END {} -my ($server_ip, $server_port, $SIPackages_key, $max_clients, $ldap_uri, $ldap_base, $ldap_admin_dn, $ldap_admin_password, $server_interface); +my ($server_ip, $server_mac_address, $server_port, $SIPackages_key, $max_clients, $ldap_uri, $ldap_base, $ldap_admin_dn, $ldap_admin_password, $server_interface); my ($bus_activ, $bus_key, $bus_ip, $bus_port); my $server; my $event_hash; @@ -41,7 +41,7 @@ my %cfg_defaults = ( }, "server" => { "ip" => [\$server_ip, "0.0.0.0"], - "mac-address" => [\$main::server_mac_address, "00:00:00:00:00"], + "mac-address" => [\$server_mac_address, "00:00:00:00:00"], "port" => [\$server_port, "20081"], "ldap-uri" => [\$ldap_uri, ""], "ldap-base" => [\$ldap_base, ""], @@ -63,28 +63,27 @@ my %cfg_defaults = ( # if server_ip is not an ip address but a name if( inet_aton($server_ip) ){ $server_ip = inet_ntoa(inet_aton($server_ip)); } $network_interface= &get_interface_for_ip($server_ip); -$main::server_mac_address= &get_mac($network_interface); +$server_mac_address= &get_mac($network_interface); &import_events(); # Unit tag can be defined in config if((not defined($main::gosa_unit_tag)) || length($main::gosa_unit_tag) == 0) { # Read gosaUnitTag from LDAP - &main::refresh_ldap_handle(); + &main::refresh_ldap_handle(); if( defined($main::ldap_handle) ) { - &main::daemon_log("INFO: Searching for servers gosaUnitTag with mac address $main::server_mac_address",5); + &main::daemon_log("INFO: Searching for servers gosaUnitTag with mac address $server_mac_address",5); # Perform search for Unit Tag $mesg = $main::ldap_handle->search( base => $ldap_base, scope => 'sub', attrs => ['gosaUnitTag'], - filter => "(macaddress=$main::server_mac_address)" + filter => "(macaddress=$server_mac_address)" ); if ($mesg->count == 1) { my $entry= $mesg->entry(0); my $unit_tag= $entry->get_value("gosaUnitTag"); - $main::ldap_server_dn= $mesg->entry(0)->dn; if(defined($unit_tag) && length($unit_tag) > 0) { &main::daemon_log("INFO: Detected gosaUnitTag $unit_tag for creating entries", 5); $main::gosa_unit_tag= $unit_tag; @@ -103,7 +102,6 @@ if((not defined($main::gosa_unit_tag)) || length($main::gosa_unit_tag) == 0) { if ($mesg->count == 1) { my $entry= $mesg->entry(0); my $unit_tag= $entry->get_value("gosaUnitTag"); - $main::ldap_server_dn= $mesg->entry(0)->dn; if(defined($unit_tag) && length($unit_tag) > 0) { &main::daemon_log("INFO: Detected gosaUnitTag $unit_tag for creating entries", 5); $main::gosa_unit_tag= $unit_tag; @@ -122,7 +120,6 @@ if((not defined($main::gosa_unit_tag)) || length($main::gosa_unit_tag) == 0) { if ($mesg->count == 1) { my $entry= $mesg->entry(0); my $unit_tag= $entry->get_value("gosaUnitTag"); - $main::ldap_server_dn= $mesg->entry(0)->dn; if(defined($unit_tag) && length($unit_tag) > 0) { &main::daemon_log("INFO: Detected gosaUnitTag $unit_tag for creating entries", 5); $main::gosa_unit_tag= $unit_tag; @@ -306,8 +303,8 @@ sub get_mac { my $SIOCGIFHWADDR= 0x8927; # man 2 ioctl_list # A configured MAC Address should always override a guessed value - if ($main::server_mac_address and length($main::server_mac_address) > 0) { - $result= $main::server_mac_address; + if ($server_mac_address and length($server_mac_address) > 0) { + $result= $server_mac_address; } socket SOCKET, PF_INET, SOCK_DGRAM, getprotobyname('ip') @@ -416,7 +413,7 @@ sub process_incoming_msg { if ($header eq 'new_key') { @out_msg_l = &new_key($msg_hash) } elsif ($header eq 'here_i_am') { - @out_msg_l = &here_i_am($msg_hash, $session_id) + @out_msg_l = &here_i_am($msg, $msg_hash, $session_id) } else { if( exists $event_hash->{$header} ) { # a event exists with the header as name @@ -503,7 +500,7 @@ sub new_key { # DESCRIPTION: process this incoming message #=============================================================================== sub here_i_am { - my ($msg_hash, $session_id) = @_; + my ($msg, $msg_hash, $session_id) = @_; my @out_msg_l; my $out_hash; @@ -603,7 +600,7 @@ sub here_i_am { push(@out_msg_l, $new_ldap_config_out); } - my $hardware_config_out = &hardware_config($source, $gotoHardwareChecksum); + my $hardware_config_out = &hardware_config($msg, $msg_hash, $session_id); if( $hardware_config_out ) { push(@out_msg_l, $hardware_config_out); } @@ -832,7 +829,10 @@ sub new_ldap_config { # DESCRIPTION: #=============================================================================== sub hardware_config { - my ($address, $gotoHardwareChecksum) = @_ ; + my ($msg, $msg_hash, $session_id) = @_ ; + my $address = @{$msg_hash->{source}}[0]; + my $header = @{$msg_hash->{header}}[0]; + my $gotoHardwareChecksum = @{$msg_hash->{gotoHardwareChecksum}}[0]; my $sql_statement= "SELECT * FROM known_clients WHERE hostname='$address'"; my $res = $main::known_clients_db->select_dbentry( $sql_statement ); @@ -842,7 +842,6 @@ sub hardware_config { if( not $hit_counter == 1 ) { &main::daemon_log("ERROR: more or no hit found in known_clients_db by query by '$address'", 1); } - my $macaddress = $res->{1}->{macaddress}; my $hostkey = $res->{1}->{hostkey}; @@ -892,9 +891,23 @@ sub hardware_config { $data{'goto_secret'}= $goto_secret; } - &main::daemon_log("Send detect_hardware message to $address", 4); + # set status = hardware_detection at jobqueue if entry exists + my $func_dic = {table=>$main::job_queue_tn, + primkey=>['id'], + timestamp=>&get_time, + status=>'processing', + result=>'none', + progress=>'hardware-detection', + headertag=>$header, + targettag=>$address, + xmlmessage=>$msg, + macaddress=>$macaddress, + }; + my $hd_res = $main::job_db->add_dbentry($func_dic); + &main::daemon_log("$session_id INFO: add '$macaddress' to job queue as an installing job", 5); # Send information + &main::daemon_log("$session_id INFO: Send detect_hardware message to $address", 5); return &build_msg("detect_hardware", $server_address, $address, \%data); } diff --git a/gosa-si/server/events/clMessages.pm b/gosa-si/server/events/clMessages.pm index dfac67255..e197b73d5 100644 --- a/gosa-si/server/events/clMessages.pm +++ b/gosa-si/server/events/clMessages.pm @@ -14,7 +14,6 @@ my @events = ( "LOGOUT", "CURRENTLY_LOGGED_IN", "save_fai_log", - "goto_activation_start", ); @EXPORT = @events; @@ -74,21 +73,6 @@ sub read_configfile { } -sub goto_activation_start { - my ($msg, $msg_hash, $session_id) = @_; - my $header = @{$msg_hash->{'header'}}[0]; - my $macaddress = @{$msg_hash->{'macaddress'}}[0]; - - my $sql_statement = "UPDATE $main::job_queue_tn ". - "SET status='processing', progress='goto-activation' ". - "WHERE status='processing' AND macaddress LIKE '$macaddress'"; - &main::daemon_log("$session_id DEBUG: $sql_statement", 7); - my $res = $main::job_db->update_dbentry($sql_statement); - &main::daemon_log("$session_id INFO: '$header' at '$macaddress'", 5); - -} - - sub save_fai_log { my ($msg, $msg_hash, $session_id) = @_; my $header = @{$msg_hash->{'header'}}[0]; @@ -238,20 +222,14 @@ sub GOTOACTIVATION { my $macaddress = @{$msg_hash->{'macaddress'}}[0]; # test whether content is an empty hash or a string which is required -######### -# testing my $content = @{$msg_hash->{$header}}[0]; if(ref($content) eq "HASH") { $content = ""; } - #eval{ if( 0 == keys(%$content) ) { $content = ""; } }; - #if( $@ ) { $content = "$content"; } -# testing -######## # clean up header $header =~ s/CLMSG_//g; my $sql_statement = "UPDATE $main::job_queue_tn ". - "SET status='processing', result='$header"."$content' ". + "SET status='processing', progress='goto-activation' ". "WHERE status='processing' AND macaddress LIKE '$macaddress'"; &main::daemon_log("$session_id DEBUG: $sql_statement", 7); my $res = $main::job_db->update_dbentry($sql_statement); @@ -267,15 +245,8 @@ sub PROGRESS { my $macaddress = @{$msg_hash->{'macaddress'}}[0]; # test whether content is an empty hash or a string which is required -# TODO eval ändern auf if(ref($content) eq "HASH") dann ... else, dann... -######### -# testing - my $content = @{$msg_hash->{$header}}[0]; + my $content = @{$msg_hash->{$header}}[0]; if(ref($content) eq "HASH") { $content = ""; } - #eval{ if( 0 == keys(%$content) ) { $content = ""; } }; - #if( $@ ) { $content = "$content"; } -# testing -######## # clean up header $header =~ s/CLMSG_//g; @@ -298,15 +269,8 @@ sub FAIREBOOT { my $macaddress = @{$msg_hash->{'macaddress'}}[0]; # test whether content is an empty hash or a string which is required -# TODO eval ändern auf if(ref($content) eq "HASH") dann ... else, dann... -######### -# testing my $content = @{$msg_hash->{$header}}[0]; if(ref($content) eq "HASH") { $content = ""; } - #eval{ if( 0 == keys(%$content) ) { $content = ""; } }; - #if( $@ ) { $content = "$content"; } -# testing -######### # clean up header $header =~ s/CLMSG_//g; @@ -329,15 +293,8 @@ sub TASKSKIP { my $macaddress = @{$msg_hash->{'macaddress'}}[0]; # test whether content is an empty hash or a string which is required -# TODO eval ändern auf if(ref($content) eq "HASH") dann ... else, dann... -######### -# testing my $content = @{$msg_hash->{$header}}[0]; if(ref($content) eq "HASH") { $content = ""; } - #eval{ if( 0 == keys(%$content) ) { $content = ""; } }; - #if( $@ ) { $content = "$content"; } -# testing -######### # clean up header $header =~ s/CLMSG_//g; @@ -358,18 +315,10 @@ sub TASKBEGIN { my $header = @{$msg_hash->{'header'}}[0]; my $source = @{$msg_hash->{'target'}}[0]; my $macaddress = @{$msg_hash->{'macaddress'}}[0]; - my $content = @{$msg_hash->{$header}}[0]; # test whether content is an empty hash or a string which is required -# TODO eval ändern auf if(ref($content) eq "HASH") dann ... else, dann... -######### -# testing my $content = @{$msg_hash->{$header}}[0]; if(ref($content) eq "HASH") { $content = ""; } - #eval{ if( 0 == keys(%$content) ) { $content = ""; } }; - #if( $@ ) { $content = "$content"; } -# testing -######### # clean up header $header =~ s/CLMSG_//g; @@ -387,13 +336,30 @@ sub TASKBEGIN { &main::change_fai_state('localboot', \@{$msg_hash->{'macaddress'}}, $session_id); } else { - my $sql_statement = "UPDATE $main::job_queue_tn ". - "SET status='processing', result='$header "."$content' ". - "WHERE status='processing' AND macaddress LIKE '$macaddress'"; - &main::daemon_log("$session_id DEBUG: $sql_statement", 7); - my $res = $main::job_db->update_dbentry($sql_statement); - &main::daemon_log("$session_id INFO: $header at '$macaddress' - '$content'", 5); +#################### +# under construction + #my $sql_statement = "UPDATE $main::job_queue_tn ". + # "SET status='processing', result='$header "."$content' ". + # "WHERE status='processing' AND macaddress LIKE '$macaddress'"; + #&main::daemon_log("$session_id DEBUG: $sql_statement", 7); + #my $res = $main::job_db->update_dbentry($sql_statement); + #&main::daemon_log("$session_id INFO: $header at '$macaddress' - '$content'", 5); + + my %add_hash = ( table=>$main::job_queue_tn, + primkey=> ['id'], + timestamp=>&get_time, + status=>'processing', + macaddress=>'$macaddress', + ); + my ($res, $error_str) = $main::job_db->add_dbentry( \%add_hash ); + if ($res != 0) { + &main::daemon_log("$session_id ERROR: can not add entry to $main::job_queue_tn: $error_str"); + } else { + &main::daemon_log("$session_id INFO: '$header' at '$macaddress' - '$content'", 5); + } +# under construction +#################### # -----------------------> Update hier # finish @@ -413,15 +379,8 @@ sub TASKEND { my $macaddress = @{$msg_hash->{'macaddress'}}[0]; # test whether content is an empty hash or a string which is required -# TODO eval ändern auf if(ref($content) eq "HASH") dann ... else, dann... -######### -# testing - my $content = @{$msg_hash->{$header}}[0]; + my $content = @{$msg_hash->{$header}}[0]; if(ref($content) eq "HASH") { $content = ""; } - #eval{ if( 0 == keys(%$content) ) { $content = ""; } }; - #if( $@ ) { $content = "$content"; } -# testing -######### # clean up header $header =~ s/CLMSG_//g; @@ -453,15 +412,8 @@ sub TASKERROR { $header =~ s/CLMSG_//g; # test whether content is an empty hash or a string which is required -# TODO eval ändern auf if(ref($content) eq "HASH") dann ... else, dann... -######### -# testing - my $content = @{$msg_hash->{$header}}[0]; - if(ref($content) eq "HASH") { $content = ""; } - #eval{ if( 0 == keys(%$content) ) { $content = ""; } }; - #if( $@ ) { $content = "$content"; } -# testing -######### + my $content = @{$msg_hash->{$header}}[0]; + if(ref($content) eq "HASH") { $content = ""; } # set fai_state to localboot &main::change_fai_state('error', \@{$msg_hash->{'macaddress'}}, $session_id); @@ -493,15 +445,8 @@ sub HOOK { $header =~ s/CLMSG_//g; # test whether content is an empty hash or a string which is required -# TODO eval ändern auf if(ref($content) eq "HASH") dann ... else, dann... -######### -# testing my $content = @{$msg_hash->{$header}}[0]; if(ref($content) eq "HASH") { $content = ""; } - #eval{ if( 0 == keys(%$content) ) { $content = ""; } }; - #if( $@ ) { $content = "$content"; } -# testing -######### my $sql_statement = "UPDATE $main::job_queue_tn ". "SET status='processing', result='$header "."$content' ". -- 2.30.2