]> xenbits.xensource.com Git - people/iwj/osstest.git/commitdiff
wip reorg refactor Properties
authorIan Jackson <ian.jackson@eu.citrix.com>
Thu, 18 Oct 2012 15:13:45 +0000 (16:13 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Thu, 18 Oct 2012 15:13:45 +0000 (16:13 +0100)
Osstest/Debian.pm
Osstest/HostDB/Executive.pm
Osstest/HostDB/Static.pm
Osstest/TestSupport.pm

index a5ea1e6e1b0375567e5d137d8a39f1531f2993ec..556a20f654397a6f77a52bd61e9a47e3c81f7ede 100644 (file)
@@ -522,9 +522,9 @@ END
 
     $preseed_file .= "$c{DebianPreseed}\n";
 
-    foreach my $prop (values %{ $xopts{Properties} }) {
-        next unless $prop->{name} =~ m/^preseed $suite /;
-        $preseed_file .= "$' $prop->{val}\n";
+    foreach my $name (keys %{ $xopts{Properties} }) {
+        next unless $name =~ m/^preseed $suite /;
+        $preseed_file .= "$' $xopts{Properties}{$name}\n";
     }
 
     return create_webfile($ho, "preseed$sfx", $preseed_file);
index e7d942870d887e91c5c0be314b0bc196cedf5783..687e02df6ba0ec9dc1c3b3ed7a1ee09fa18c7b19 100644 (file)
@@ -20,13 +20,18 @@ BEGIN {
 
 sub new { return bless {}, $_[0]; }
 
-sub get_properties ($$) {
-    my ($hd, $name) = @_;
+sub get_properties ($$$) {
+    my ($hd, $name, $hp) = @_;
     
-    return $dbh_tests->selectall_hashref(<<END, 'name', {}, $name);
+    my $q = $dbh_tests->prepare(<<END);
         SELECT * FROM resource_properties
             WHERE restype='host' AND resname=?
 END
+    $q->execute($name);
+    foreach my ($row = $q->fetchrow_hashref()) {
+       my $name = $row->{name};
+       $hp{propname_massage($name)} = $row->{val};
+    }
 }
 
 sub get_flags ($$) {
@@ -45,13 +50,6 @@ END
     return $flags;
 }
 
-sub get_property ($$$;$) {
-    my ($hd, $ho, $prop, $defval) = @_;
-    my $row= $ho->{Properties}{$prop};
-    return $defval unless $row && defined $row->{val};
-    return $row->{val};
-}
-
 sub default_methods ($$) {
     my ($hd, $ho) = @_;
 
index ef563559858a6f277d7cdcee4e20f13b3c9c8665..ae333f08f54825bfe7ac8a25e270940e6df260f0 100644 (file)
@@ -20,40 +20,8 @@ BEGIN {
 
 sub new { return bless {}, $_[0]; }
 
-sub get_properties ($$) { #method
-    my ($hd, $name) = @_;
-    my $hp = { };
-    my $k;
-    my $sp = sub {
-       my ($pn,$v) = @_;
-       $hp->{$pn} = {
-           name => $pn,
-           val => $v,
-       };
-    };
-    foreach $k (keys %c) {
-       next unless $k =~ m/^HostProp_([A-Z].*)$/;
-       $sp->($1, $c{$k});
-    }
-    foreach $k (keys %c) {
-       next unless $k =~ m/^HostProp_([a-z0-9]+)_(.*)$/;
-       next unless $1 eq $name;
-       $sp->($2, $c{$k});
-    }
-    return $hp;
-}
-
-sub get_property ($$$;$) { #method
-    my ($hd, $ho, $prop, $defval) = @_;
-
-    $prop = ucfirst $prop;
-    while ($prop =~ m/-/) {
-       $prop = $`.ucfirst $'; #';
-    }
-
-    my $row = $ho->{Properties}{$prop};
-    return $defval unless $row && defined $row->{val};
-    return $row->{val};
+sub get_properties ($$$) { #method
+    my ($hd, $name, $hp) = @_;
 }
 
 sub get_flags ($$) { #method
index 30b1fb82f7cbe038723837e2d8937c186509652e..a269a308001259ec0e96db8dc03deb0e8655f483 100644 (file)
@@ -44,6 +44,7 @@ BEGIN {
 
                       selecthost get_hostflags get_host_property
                       power_state power_cycle power_cycle_time
+                      propname_massage
          
                       get_stashed open_unique_stashfile
                       dir_identify_vcs build_clone built_stash 
@@ -655,7 +656,35 @@ sub selecthost ($) {
         Suite => get_runvar_default("${ident}_suite",$job,$c{DebianSuite}),
     };
 
-    $ho->{Properties} = $mhostdb->get_properties($name);
+    #----- calculation of the host's properties -----
+
+    $ho->{Properties} = { };
+    my $setprop = sub {
+       my ($pn,$val) = @_;
+       $ho->{Properties}{$pn} = $val;
+    };
+
+    # First, we use the config file's general properites as defaults
+    foreach my $k (keys %c) {
+       next unless $k =~ m/^HostProp_([A-Z].*)$/;
+       $setprop->($1, $c{$k});
+    }
+
+    # Then we read in the HostDB's properties
+    $mhostdb->get_properties($name, $ho->{Properties});
+
+    # Finally, we override any host-specific properties from the config
+    foreach my $k (keys %c) {
+       next unless $k =~ m/^HostProp_([a-z0-9]+)_(.*)$/;
+       next unless $1 eq $name;
+       $setprop->($2, $c{$k});
+    }
+
+    #----- calculation of the host's flags -----
+
+    $ho->{Flags} = $mhostdb->get_flags($ho);
+
+
 
     $ho->{Ether}= get_host_property($ho,'ether');
     $ho->{DiskDevice}= get_host_property($ho,'disk-device');
@@ -674,8 +703,6 @@ sub selecthost ($) {
     $ho->{Ip}= inet_ntoa($ip_packed);
     die "$ho->{Fqdn} ?" unless defined $ho->{Ip};
 
-    $ho->{Flags} = $mhostdb->get_flags($ho);
-
     $mjobdb->host_check_allocated($ho);
 
     logm("host: selected $ho->{Name} $ho->{Ether} $ho->{Ip}".
@@ -686,8 +713,22 @@ sub selecthost ($) {
     return $ho;
 }
 
+sub propname_massage ($) {
+    # property names used to be in the form word-word-word
+    # and are moving to WordWordWord
+    my ($prop) = @_;
+
+    $prop = ucfirst $prop;
+    while ($prop =~ m/-/) {
+       $prop = $`.ucfirst $'; #';
+    }
+    return $prop;
+}
+
 sub get_host_property ($$;$) {
-    return $mhostdb->get_property(@_);
+    my ($ho, $prop, $defval) = @_;
+    my $val = $ho->{Properties}{propname_massage($prop)};
+    return defined($val) ? $val : $defval;
 }
 
 sub get_host_method_object ($$$) {
@@ -965,12 +1006,13 @@ sub host_involves_pcipassthrough ($) {
 sub host_get_pcipassthrough_devs ($) {
     my ($ho) = @_;
     my @devs;
-    foreach my $prop (values %{ $ho->{Properties} }) {
-        next unless $prop->{name} =~ m/^pcipassthrough (\w+)$/;
+    foreach my $name (keys %{ $ho->{Properties} }) {
+        next unless $name =~ m/^pcipassthrough (\w+)$/;
         my $devtype= $1;
         next unless grep { m/^pcipassthrough-$devtype$/ } get_hostflags($ho);
-        $prop->{val} =~ m,^([0-9a-f]+\:[0-9a-f]+\.\d+)/, or
-            die "$ho->{Ident} $prop->{val} ?";
+       my $val = $ho->{Properties}{$name};
+        $val =~ m,^([0-9a-f]+\:[0-9a-f]+\.\d+)/, or
+            die "$ho->{Ident} $val ?";
         push @devs, {
             DevType => $devtype,
             Bdf => $1,