Hi,

This patch fixes many database bootstrapping problems.

Unfortunately, even though it seems to work fine, some more work is required 
for bootstrapping as the database is reset after this command (db 
inithialization ran twice), and the Nics table get erased.
Then, the /usr/bin/set_node_nics is called, but fails

I'll work on this now, otherwise, bootstrapping will lead to a failure at stage 
6 (setup_pxe fails)

-- 
        Olivier LAHAYE
        CEA Saclay
        DRT-LIST-DETECS-SSTM
--- /root/oscar/scripts/create_and_populate_basic_node_info	2009-12-02 10:46:21.000000000 +0100
+++ /usr/bin/create_and_populate_basic_node_info	2009-12-02 10:49:04.000000000 +0100
@@ -38,6 +38,7 @@
 use OSCAR::Package;
 use OSCAR::oda;
 use OSCAR::Logger;
+use OSCAR::MAC;
 
 my %options = ();
 my %field_value_hash = ();
@@ -47,6 +48,25 @@
 $options{debug} = 1 if $ENV{OSCAR_DB_DEBUG}; 
 $options{verbose} = 1 if $ENV{OSCAR_DB_VERBOSE}; 
 
+# Compute network base ip adress from an ip adress and its netmask.
+sub get_network_base_ip ($$) {
+    my ($ip , $netmask) = @_;
+
+    # Compute network from broadcast and netmask, then check the Network table.
+    my @addrarr=split(/\./,$ip);
+    my ( $ipaddress ) = unpack( "N", pack( "C4",@addrarr ) );
+
+    my @maskarr=split(/\./,$netmask);
+    my ( $netmask ) = unpack( "N", pack( "C4",@maskarr ) );
+
+    # Calculate network address by logical AND operation of addr & netmask
+    # and convert network address to IP address format
+    my $netadd = ( $ipaddress & $netmask );
+    my @netarr=unpack( "C4", pack( "N",$netadd ) );
+    my $netaddress=join(".",@netarr);
+    return $netaddress;
+}
+
 # see if there is already a node named oscar_server,
 # and make it if it doesn't already exist, this will also
 # make a special associated node group named oscar_server
@@ -67,7 +87,7 @@
 my @errors = ();
 #locking("write", \%options, \...@tables, \...@errors);
 
-# Populate "Nodes" table
+# Populate "Nodes" table (the head is a node)
 my $msg = "in create_and_populate_basic_node_info Populating Nodes records for oscar_server ...\n";
 print "DB_DEBUG>$0:====>\n$msg" if $options{debug};
 @errors = ("cannot read nodes database table");
@@ -78,36 +98,134 @@
     die "ERROR: Impossible to set headnode information in the database";
 }
 
+# Get headnode_iface config so we can populate Nics table.
+my %head_nic ;
+my %head_network ;
+my $private_netif_name = OSCAR::Database::get_headnode_iface(undef, undef);
+my @private_netif_config = `LC_ALL=C  ifconfig $private_netif_name` ;
+for ( @private_netif_config ) {
+	%head_nic->{ip} = $1 if ( /\s*inet addr:([\d.]+)/ ) ;
+	%head_nic->{mac} = $1 if ( /HWaddr\s+([[:xdigit:]:]+)\s+/ ) ;
+	%head_network->{broadcast} = $1 if ( /\s*Bcast:([\d.]+)/ ) ;
+	%head_network->{netmask} = $1 if ( /\s*Mask:([\d.]+)/ ) ;
+}
+
+# Get the network base ip on the private iface so we can populate the network table.
+my $netaddress = get_network_base_ip(%head_network->{broadcast}, %head_network->{netmask}) ;
+
+# Get the gateway adress associated with this network.
+my $cmd = "route -n |grep -E '".$netaddress."[[:space:]]+.*".$private_netif_name."'";
+my $output = `$cmd`;
+my ($net, $gw, $nm, $flgs, $metric, $ref, $use, $iface) = split (/\s+/, $output);
+
+die "create_and_populate_basic_node_info: No route defined for network $netaddress"
+    if! defined($gw);
+# Check if network already registered.
+my @networks ;
+...@errors = ("cannot read Networks database table");
+die "DB_DEBUG>$0:\n====>Failed to query Networks table"
+    if! get_networks(\...@networks, \%options, \...@errors);
+
+# Scan Networks from ODA. If found update, else create.
+my $found=0;
+for my $network (@networks ) {
+    $found=1 if ($network->{base_ip} eq $netaddress);
+}
+
+my $sql ;
+if($found) {
+    $sql = "UPDATE Networks SET broadcast='".%head_network->{broadcast}.
+                             "',gateway='".$gw."',".
+                               "netmask='".%head_network->{netmask}."'".
+                         " WHERE base_ip='".$netaddress."'";
+    print "DB_DEBUG>$0:\n===> in create_and_populate_basic_node_info SQL:  $sql\n";
+    @errors = ("cannot update Networks database table");
+    die "DB_DEBUG>$0:\n====>Failed to update values via << $sql >>"
+        if !&do_update($sql,
+                       "Networks",
+                       \%options,
+                       \...@errors);
+} else {
+    $sql = "INSERT INTO Networks (base_ip,broadcast,cluster_id,gateway,name,netmask) VALUES ('".
+                           $netaddress."','".
+                           %head_network->{broadcast}."','".
+                           "1"."','". # BUG: Hard codded: this is BAD
+                           $gw."','".
+                           "oscarnetwork"."','".
+                           %head_network->{netmask}."')";
+    print "DB_DEBUG>$0:\n====> in create_and_populate_basic_node_info SQL : $sql\n";
+    @errors = ("cannot insert into Networks database table");
+    die "DB_DEBUG>$0:\n====>Failed to insert values via << $sql >>"
+        if !&do_insert($sql,
+            "Image_Package_Status",
+            \%options,
+            \...@errors);
+}
+
+# Populate the "Nics" table (the head iface dedicated to nodes)
+# 1st, Get the id of the network for our nic in the Networks table
+undef @networks;
+...@errors = ("cannot read Networks database table");
+die "DB_DEBUG>$0:\n====>Failed to query again Networks table"
+    if! get_networks(\...@networks, \%options, \...@errors);
+for my $network (@networks ) {
+    if ($network->{base_ip} eq $netaddress) {
+        %head_nic->{network_id} = $network->{n_id};
+	last;
+    }
+}
+
+# 2nd, using previous informations, populate the nic table.
+my $msg = "in create_and_populate_basic_node_info Populating Nics records for oscar_server ...\n";
+print "DB_DEBUG>$0:====>\n$msg" if $options{debug};
+...@errors = ("cannot read Nics database table");
+if (set_nics_with_node($private_netif_name,
+                       $OSCAR_SERVER_NODE,
+                       \%head_nic,
+                       \%options,
+                       \...@errors) !=1) {
+    die "ERROR: Impossible to set headnode nic information in the database";
+}
+
 # update some of the fields in the node record for oscar_server
 
 my $hostname = `hostname`;
 chomp $hostname;
-%field_value_hash = ( "hostname" => $hostname );
-my $where = " WHERE name='oscar_server' ";
-print "Updating the hostname field in the oscar_server node to <$hostname> ...\n";
-update_table( \%options, "Nodes", \%field_value_hash, $where, \...@errors );
 my $dns_domain = `dnsdomainname`;
 chomp $dns_domain;
+my $fqdn = $hostname;
+
 if ( defined $dns_domain && $dns_domain ne "" ) {
     print "Updating the dns_domain field in the oscar_server node to ".
           "<$dns_domain>\n";
     %field_value_hash = ( "dns_domain" => $dns_domain );
     my $where = "WHERE name='oscar_server'";
     update_table( \%options, "Nodes", \%field_value_hash, $where, \...@errors );
+    # Get the non fqdn hostname.
+    $hostname =~ s/\.$dns_domain//g
 }
 
+%field_value_hash = ( "hostname" => $hostname , "fqdn" => $fqdn );
+my $where = " WHERE name='oscar_server' ";
+print "Updating the hostname and fields in the oscar_server node to <$hostname> and <$hostname\.$dns_domain>...\n";
+...@errors = ("cannot update table Nodes");
+update_table( \%options, "Nodes", \%field_value_hash, $where, \...@errors );
+
+
 # make sure that certain node groups exist
 
 foreach my $node_group_name ( "oscar_clients", "all", "Default_node" ) {
     oscar_log_subsection ("Checking for existence of node group ".
                           "$node_group_name ...");
     my @node_groups = ();
+    @errors = ("cannot read Groups table");
     my $group = OSCAR::Database::get_groups(\...@node_groups,
                                             \%options,
                                             \...@errors,
                                             $node_group_name);
     if ( ! $group ) {
         oscar_log_section ("Creating node group $node_group_name ...");
+        @errors = ("cannot insert into Groups table");
         if (OSCAR::Database::set_groups($node_group_name,
                                         \%options,
                                         \...@errors,
@@ -117,6 +235,12 @@
     }
 }
 
+# Set the default install mode to systemimager-rsync that correspond to the default at step 6
+...@errors = ("cannot update table clusters (install_mode field)");
+OSCAR::Database::set_install_mode('systemimager-rsync',
+				  \%options,
+				  \...@errors);
+OSCAR::MAC::__enable_install_mode();
 
 # UNLOCKING FOR NEST.
 #unlock(\%options, \...@errors);
------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing. 
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
Oscar-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/oscar-devel

Reply via email to