From 3f9341f18399991ea1f30c49076e40c5c98cc40e Mon Sep 17 00:00:00 2001 From: rettenbe Date: Tue, 18 Mar 2008 15:43:42 +0000 Subject: [PATCH] updates from buildserv git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@9929 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/gosa-si-client | 80 +++++++++-------- gosa-si/gosa-si-server | 57 +++++------- gosa-si/modules/GosaPackages.pm | 2 +- gosa-si/modules/SIPackages.pm | 6 +- gosa-si/server/events/clMessages.pm | 117 ++++++++++++++----------- gosa-si/server/events/databases.pm | 12 +-- gosa-si/server/events/gosaTriggered.pm | 2 +- gosa-si/server/events/siTriggered.pm | 2 +- 8 files changed, 141 insertions(+), 137 deletions(-) diff --git a/gosa-si/gosa-si-client b/gosa-si/gosa-si-client index fa4b86047..1aae6effd 100755 --- a/gosa-si/gosa-si-client +++ b/gosa-si/gosa-si-client @@ -691,35 +691,38 @@ sub open_socket { sub register_at_gosa_si_server { my ($kernel) = $_[KERNEL]; my $try_to_register = 0; + + # if client is already registered, stop registration process + if ($REGISTERED) { + $kernel->delay('register_at_gosa_si_server'); - if( not $REGISTERED ) { - # clear all other triggered events and wait till registration was successful - $kernel->delay('trigger_new_key'); + # client is not registered, start registration process + } else { + # clear all other triggered events and wait till registration was successful + $kernel->delay('trigger_new_key'); - # create new passwd and ciphering object for client-server communication - $server_key = &create_passwd(); + # create new passwd and ciphering object for client-server communication + $server_key = &create_passwd(); - my $events = join( ",", keys %{$event_hash} ); - while(1) { + my $events = join( ",", keys %{$event_hash} ); + while(1) { - if( $try_to_register >= @servers ) { - last; - } + if( $try_to_register >= @servers ) { last; } - # fetch first gosa-si-server from @servers - my $server = shift(@servers); + # fetch first gosa-si-server from @servers + my $server = shift(@servers); - # append shifted gosa-si-server at the end of @servers, so looking for servers never stop if - # a registration never occured - push( @servers, $server ); + # append shifted gosa-si-server at the end of @servers, so looking for servers never stop if + # a registration never occured + push( @servers, $server ); - # Check if our ip is resolvable - if not: don't try to register - my $ip= &get_local_ip_for_remote_ip(sprintf("%s", $server =~ /^([0-9\.]*?):.*$/)); - my $dnsname= gethostbyaddr(inet_aton($ip), AF_INET); - if(!defined($dnsname)) { - &write_to_file("goto-error-dns:$ip", $fai_logpath); - exit(1); - } + # Check if our ip is resolvable - if not: don't try to register + my $ip= &get_local_ip_for_remote_ip(sprintf("%s", $server =~ /^([0-9\.]*?):.*$/)); + my $dnsname= gethostbyaddr(inet_aton($ip), AF_INET); + if(!defined($dnsname)) { + &write_to_file("goto-error-dns:$ip", $fai_logpath); + exit(1); + } # create registration msg my $local_ip = &get_local_ip_for_remote_ip(sprintf("%s", $server =~ /^([0-9\.]*?):.*$/)); @@ -743,6 +746,8 @@ sub register_at_gosa_si_server { # send xml hash to server with general server passwd my $res = &send_msg_hash_to_target($register_hash, $server, $default_server_key); + + # if delivery of registration msg succeed if($res == 0) { # reset try_to_register $try_to_register = 0; @@ -754,28 +759,31 @@ sub register_at_gosa_si_server { $client_dnsname = $dnsname; last; + + # delivery of registration msg failed } else { $try_to_register++; - # wait 1 sec until trying to register again sleep(1); next; } - } - if( $try_to_register >= @servers ) { - &write_to_file("gosa-si-no-server-available", $fai_logpath); - $kernel->delay_set('register_at_gosa_si_server', $delay_set_time); - } - else { - daemon_log("INFO: waiting for msg 'register_at_gosa_si_server'",5); - $kernel->delay_set('register_at_gosa_si_server', $delay_set_time); - # clear old settings and set it again - $kernel->delay_set('trigger_new_key', $server_key_lifetime); - } + } # end of while + + # one circle through all servers finished and no registration succeed + if ( $try_to_register >= @servers ) { + &write_to_file("gosa-si-no-server-available", $fai_logpath); + $kernel->delay_set('register_at_gosa_si_server', $delay_set_time); + + # delivery of registraion msg succeed, waiting for server response + } else { + daemon_log("INFO: waiting for msg 'register_at_gosa_si_server'",5); + $kernel->delay_set('register_at_gosa_si_server', $delay_set_time); + # clear old settings and set it again + $kernel->delay('trigger_new_key'); + $kernel->delay_set('trigger_new_key', $server_key_lifetime); + } - } else { - $kernel->delay('register_at_gosa_si_server'); } return; } diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index 238fcd6fc..7653c67f4 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; @@ -181,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, ""], @@ -953,8 +946,8 @@ 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_release_db', $fai_release_tn ); + #$kernel->yield('create_fai_server_db', $fai_server_tn ); + #$kernel->yield('create_fai_release_db', $fai_release_tn ); $kernel->sig(USR1 => "sig_handler"); } @@ -1289,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 ); @@ -1334,6 +1326,7 @@ sub change_fai_state { wake => '', memcheck => 'memcheck', sysinfo => 'sysinfo', + install => 'install', ); # Return if this is unknown @@ -1828,13 +1821,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'); @@ -1890,7 +1883,6 @@ sub create_packages_list_db { 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( @@ -1901,22 +1893,18 @@ 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); get_package( "$baseurl/dists/$dist/$section/binary-$arch/$package", "$outdir/$dist/$section" ); parse_package( "$outdir/$dist/$section", $dist, $path ); } - find(\&cleanup_and_extract, keys( %repo_dirs ) ); } - sub get_package { my ($url, $dest)= @_; @@ -1932,9 +1920,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; @@ -1991,12 +1978,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 ); @@ -2005,18 +1986,20 @@ sub parse_package { $packages_list_db->exec_statementlist(\@sql_list); } + sub store_fileinfo { - my( $package, $file, $dist, $path, $vers, $srvdir) = @_; + my( $package, $file, $dist, $path, $vers, $srvdir) = @_; - my %fileinfo = ( - 'package' => $package, - 'dist' => $dist, - 'version' => $vers, - ); + my %fileinfo = ( + 'package' => $package, + 'dist' => $dist, + 'version' => $vers, + ); - $repo_files{ "${srvdir}/$file" } = \%fileinfo; + $repo_files{ "${srvdir}/$file" } = \%fileinfo; } + sub cleanup_and_extract { my $fileinfo = $repo_files{ $File::Find::name }; diff --git a/gosa-si/modules/GosaPackages.pm b/gosa-si/modules/GosaPackages.pm index 1e6ad1457..7c396167d 100644 --- a/gosa-si/modules/GosaPackages.pm +++ b/gosa-si/modules/GosaPackages.pm @@ -246,7 +246,7 @@ sub import_events { $event_hash->{$event_name} = $event_module; } my $events_string = join( ", ", @{$events_l}); - &main::daemon_log("G INFO: GosaPackages imported events $events_string", 5); + &main::daemon_log("G DEBUG: GosaPackages imported events $events_string", 8); } } diff --git a/gosa-si/modules/SIPackages.pm b/gosa-si/modules/SIPackages.pm index c8078499a..0bebf286d 100644 --- a/gosa-si/modules/SIPackages.pm +++ b/gosa-si/modules/SIPackages.pm @@ -354,7 +354,7 @@ sub register_at_bus { sub import_events { if (not -e $event_dir) { - &main::daemon_log("ERROR: cannot find directory or directory is not readable: $event_dir", 1); + &main::daemon_log("S ERROR: cannot find directory or directory is not readable: $event_dir", 1); } opendir (DIR, $event_dir) or die "ERROR while loading gosa-si-events from directory $event_dir : $!\n"; @@ -376,7 +376,7 @@ sub import_events { $event_hash->{$event_name} = $event_module; } my $events_string = join( ", ", @{$events_l}); - &main::daemon_log("INFO: SIPackages imported events $events_string", 5); + &main::daemon_log("S DEBUG: SIPackages imported events $events_string", 8); } } @@ -854,7 +854,7 @@ sub hardware_config { } # Build LDAP connection - &main::refresh_ldap_handle(); + &main::refresh_ldap_handle(); if( not defined $main::ldap_handle ) { &main::daemon_log("ERROR: cannot connect to ldap: $ldap_uri", 1); return; diff --git a/gosa-si/server/events/clMessages.pm b/gosa-si/server/events/clMessages.pm index 5fdcd06ea..23b302282 100644 --- a/gosa-si/server/events/clMessages.pm +++ b/gosa-si/server/events/clMessages.pm @@ -323,63 +323,76 @@ sub TASKBEGIN { # clean up header $header =~ s/CLMSG_//g; - # check if installation finished + # TASKBEGIN eq finish or faiend if (($content eq 'finish') || ($content eq 'faiend')){ - my $sql_statement = "UPDATE $main::job_queue_tn ". - "SET status='done', 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'", -# result=>"'$header $content'", -# progress=>"'none'", -# headertag=>"'trigger_action_reinstall'", -# targettag=>"'none'", -# xmlmessage=>"'none'", -# macaddress=>"'$macaddress'", -# }; -# my ($res, $error_str) = $main::job_db->add_dbentry( $add_hash ); -# if ($res != 0) { -# &main::daemon_log("$session_id ERROR: $res - can not add entry to $main::job_queue_tn: $error_str"); -# } else { -# &main::daemon_log("$session_id INFO: '$header' at '$macaddress' - '$content'", 5); -# } -# + my $sql_statement = "UPDATE $main::job_queue_tn ". + "SET status='done', 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); + # set fai_state to localboot &main::change_fai_state('localboot', \@{$msg_hash->{'macaddress'}}, $session_id); + # other TASKBEGIN msgs } 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); - -# -# my $add_hash = { table=>$main::job_queue_tn, -# primkey=> ['id'], -# timestamp=>&get_time, -# status=>"'processing'", -# result=>"'$header $content'", -# progress=>"'none'", -# headertag=>"'trigger_action_reinstall'", -# targettag=>"'none'", -# xmlmessage=>"'none'", -# macaddress=>"'$macaddress'", -# }; -# my ($res, $error_str) = $main::job_db->add_dbentry( $add_hash ); -# if ($res != 0) { -# &main::daemon_log("$session_id ERROR: $res - can not add entry to $main::job_queue_tn: $error_str"); -# } else { -# &main::daemon_log("$session_id INFO: '$header' at '$macaddress' - '$content'", 5); -# } -# + # select processing jobs for host + my $sql_statement = "SELECT * FROM $main::job_queue_tn WHERE status='processing' AND macaddress LIKE '$macaddress'"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->select_dbentry($sql_statement); + + # there is exactly one job entry in queue for this host + if (keys(%$res) == 1) { + &main::daemon_log("$session_id DEBUG: there is already one processing job in queue for host '$macaddress', run an update for this entry", 7); + my $sql_statement = "UPDATE $main::job_queue_tn SET result='$header $content' WHERE status='processing' AND macaddress LIKE '$macaddress'"; + my $err = $main::job_db->update_dbentry($sql_statement); + if (not defined $err) { + &main::daemon_log("$session_id ERROR: cannot update job_db entry: ".Dumper($err), 1); + } + + # there is no entry or more than one enties + } else { + # in case of more than one running jobs in queue, delete all jobs + if (keys(%$res) > 1) { + &main::daemon_log("$session_id DEBUG: there are more than one processing job in queue for host '$macaddress', ". + "delete entries", 7); + + my $sql_statement = "DELETE FROM $main::job_queue_tn WHERE status='processing' AND macaddress LIKE '$macaddress'"; + my ($err) = $main::job_db->del_dbentry($sql_statement); + if (not defined $err) { + &main::daemon_log("$session_id ERROR: can not delete multiple processing queue entries for host '$macaddress': ".Dumper($err), 1); + } + } + + # in case of no and more than one running jobs in queue, add on single job + &main::daemon_log("$session_id DEBUG: add job to queue for host '$macaddress'", 7); + my $func_dic = {table=>$main::job_queue_tn, + primkey=>['id'], + timestamp=>&get_time, + status=>'processing', + result=>"$header $content", + progress=>'none', + headertag=>'trigger_action_reinstall', + targettag=>$source, + xmlmessage=>'none', + macaddress=>$macaddress, + }; + my ($err, $error_str) = $main::job_db->add_dbentry($func_dic); + if ($err != 0) { + &main::daemon_log("$session_id ERROR: cannot add entry to job_db: $error_str", 1); + } + + } + + #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); + + # -----------------------> Update hier # finish #
CLMSG_TASKBEGIN
diff --git a/gosa-si/server/events/databases.pm b/gosa-si/server/events/databases.pm index e50915fc3..2bb2e487d 100644 --- a/gosa-si/server/events/databases.pm +++ b/gosa-si/server/events/databases.pm @@ -34,8 +34,8 @@ sub get_events { return \@events; } -sub query_fai_release { return &query_db( @_ ); } -sub query_fai_server { return &query_db( @_ ) ; } +sub query_fai_releases{ return &query_db( @_ ); } +sub query_fai_server{ return &query_db( @_ ) ; } sub query_packages_list { return &query_db( @_ ) ; } sub query_jobdb { return &query_db( @_ ) ; } sub query_db { @@ -54,7 +54,7 @@ sub query_db { } elsif( $header =~ /query_fai_server/ ) { $table = $main::fai_server_tn; $db = $main::fai_server_db; - } elsif( $header =~ /query_fai_release/ ) { + } elsif( $header =~ /count_fai_release/ ) { $table = $main::fai_release_tn; $db = $main::fai_server_db; } @@ -74,9 +74,9 @@ sub query_db { return @out_msg_l; } -sub count_fai_release { return &count_db( @_ ); } -sub count_fai_server { return &count_db( @_ ); } -sub count_packages_list { return &count_db( @_ ); } +sub count_fai_releas{ return &count_db( @_ ); } +sub count_fai_server{ return &count_db( @_ ); } +sub count_packages_list{ return &count_db( @_ ); } sub count_jobdb{ return &count_db( @_ ); } sub count_db { my ($msg, $msg_hash, $session_id) = @_; diff --git a/gosa-si/server/events/gosaTriggered.pm b/gosa-si/server/events/gosaTriggered.pm index f069da1d4..7c15ab22b 100644 --- a/gosa-si/server/events/gosaTriggered.pm +++ b/gosa-si/server/events/gosaTriggered.pm @@ -353,7 +353,7 @@ sub trigger_action_faireboot { push(@out_msg_l, $msg); &main::change_goto_state('locked', \@{$msg_hash->{target}}, $session_id); - &main::change_fai_state('localboot', \@{$msg_hash->{target}}, $session_id); + &main::change_fai_state('install', \@{$msg_hash->{target}}, $session_id); # delete all jobs from jobqueue which correspond to fai my $sql_statement = "DELETE FROM $main::job_queue_tn WHERE (macaddress='$macaddress' AND ". diff --git a/gosa-si/server/events/siTriggered.pm b/gosa-si/server/events/siTriggered.pm index 55e3be017..53ae3d58f 100644 --- a/gosa-si/server/events/siTriggered.pm +++ b/gosa-si/server/events/siTriggered.pm @@ -70,7 +70,7 @@ sub reload_ldap_config { my $header = @{$msg_hash->{header}}[0]; my $target = @{$msg_hash->{$header}}[0]; - my $out_msg = &SIPackages::new_ldap_config($target); + my $out_msg = &SIPackages::new_ldap_config($target, $session_id); my @out_msg_l = ( $out_msg ); return @out_msg_l; } -- 2.30.2