diff mbox

[Xen-devel,OSSTEST,v2,10/20] standalone: Introduce "HostGroups" for use in OSSTEST_CONFIG

Message ID 1414579302-6692-10-git-send-email-ian.campbell@citrix.com
State New
Headers show

Commit Message

Ian Campbell Oct. 29, 2014, 10:41 a.m. UTC
This saves repeating identical HostProp and HostFlags for sets of identical
machines. e.g.

    HostGroupProp_cubietruck_LinuxSerialConsole ttyS0
    HostGroupProp_cubietruck_Build_Make_Flags -j12
    HostGroupProp_cubietruck_XenSerialConsole dtuart
    HostGroupProp_cubietruck_XenDTUARTPath /soc@01c00000/serial@01c28000
    HostGroupFlags_cubietruck suite-wheezy,equiv-cubietruck,need-kernel-deb-armmp,no-di-kernel,need-uboot-bootscr

    HostGroup_braque cubietruck
    HostProp_braque_Fqdn braque.uk.xensource.com

    HostGroup_picaso cubietruck
    HostProp_picaso_Fqdn picaso.uk.xensource.com

    HostGroup_metzinger cubietruck
    HostProp_metzinger metzinger.uk.xensource.com

    HostGroup_gleizes cubietruck
    HostProp_gleizes_Fqdn gleizes.uk.xensource.com

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
---
v2: Set HostGroup props after DB
    Clarify docs
---
 Osstest/HostDB/Static.pm |  2 ++
 Osstest/TestSupport.pm   | 19 ++++++++++++++++++-
 README                   | 22 ++++++++++++++++++++++
 3 files changed, 42 insertions(+), 1 deletion(-)

Comments

Ian Jackson Oct. 29, 2014, 4:22 p.m. UTC | #1
Ian Campbell writes ("[PATCH OSSTEST v2 10/20] standalone: Introduce "HostGroups" for use in OSSTEST_CONFIG"):
> This saves repeating identical HostProp and HostFlags for sets of identical
> machines. e.g.

Thanks.

> -    # First, we use the config file's general properites as defaults
> +    # First, set the prop group if any.
> +    foreach my $k (keys %c) {
> +	next unless $k =~ m/^HostGroup_([-a-z0-9]+)$/;
> +	next unless $1 eq $name;

Am I being dim or could this loop be replaced with a single lookup of
$c{"HostGroup_${name}"} ?

Apart from that this looks fine to me.

Thanks,
Ian.
Ian Campbell Oct. 29, 2014, 4:34 p.m. UTC | #2
On Wed, 2014-10-29 at 16:22 +0000, Ian Jackson wrote:
> Ian Campbell writes ("[PATCH OSSTEST v2 10/20] standalone: Introduce "HostGroups" for use in OSSTEST_CONFIG"):
> > This saves repeating identical HostProp and HostFlags for sets of identical
> > machines. e.g.
> 
> Thanks.
> 
> > -    # First, we use the config file's general properites as defaults
> > +    # First, set the prop group if any.
> > +    foreach my $k (keys %c) {
> > +	next unless $k =~ m/^HostGroup_([-a-z0-9]+)$/;
> > +	next unless $1 eq $name;
> 
> Am I being dim or could this loop be replaced with a single lookup of
> $c{"HostGroup_${name}"} ?

Uh, no, I think it was me who was being dim.

> Apart from that this looks fine to me.

Thanks.

Ian.
diff mbox

Patch

diff --git a/Osstest/HostDB/Static.pm b/Osstest/HostDB/Static.pm
index e786761..076da62 100644
--- a/Osstest/HostDB/Static.pm
+++ b/Osstest/HostDB/Static.pm
@@ -58,6 +58,8 @@  sub get_flags ($$) { #method
     };
 
     $process->('HostFlags');
+    $process->("HostGroupFlags_$ho->{Properties}{HostGroup}")
+	if $ho->{Properties}{HostGroup};
     $process->("HostFlags_$ho->{Name}");
 
     return $flags;
diff --git a/Osstest/TestSupport.pm b/Osstest/TestSupport.pm
index d66708e..a1c2947 100644
--- a/Osstest/TestSupport.pm
+++ b/Osstest/TestSupport.pm
@@ -766,7 +766,15 @@  sub selecthost ($) {
 	$ho->{Properties}{$pn} = $val;
     };
 
-    # First, we use the config file's general properites as defaults
+    # First, set the prop group if any.
+    foreach my $k (keys %c) {
+	next unless $k =~ m/^HostGroup_([-a-z0-9]+)$/;
+	next unless $1 eq $name;
+	$setprop->("HostGroup", $c{$k});
+	logm("Host $name is in HostGroup $ho->{Properties}{HostGroup}");
+    }
+
+    # Next, 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});
@@ -775,6 +783,15 @@  sub selecthost ($) {
     # Then we read in the HostDB's properties
     $mhostdb->get_properties($name, $ho->{Properties});
 
+    # Next, we set any HostGroup based properties
+    if ( $ho->{Properties}{HostGroup} ) {
+	foreach my $k (keys %c) {
+	    next unless $k =~ m/^HostGroupProp_([-a-z0-9]+)_(.*)$/;
+	    next unless $1 eq $ho->{Properties}{HostGroup};
+	    $setprop->($2, $c{$k});
+	}
+    }
+
     # Finally, we override any host-specific properties from the config
     foreach my $k (keys %c) {
 	next unless $k =~ m/^HostProp_([-a-z0-9]+)_(.*)$/;
diff --git a/README b/README
index 5c5f347..5ba695d 100644
--- a/README
+++ b/README
@@ -333,6 +333,28 @@  HostProp_<testbox>_TftpScope
    Defines the Tftp scope (i.e. subnet) where this host resides. See
    "TftpFoo_<scope> and TftpFoo" below.
 
+HostFlags_<testbox>
+   Defines a set of flags for the host. Flags is a list separated by
+   whitespace, comma or semi-colon. A flag can be unset by prepending
+   a !. Only used in standalone mode.
+
+HostGroup_<testbox> <group>
+   Defines a group of similar hosts of which <testbox> is a
+   member. This can then be used with HostGroupProp and HostGroupFlags
+
+HostGroupProps_<group>_<prop>
+   Equivalent to writing HostProp_<testbox>_<prop> for every testbox
+   which declares HostGroup_<testbox>_<group>. Allows setting a set of
+   common properties for a group of similar machines. These settings
+   take precedence over the database provided settings, but are
+   themselves overridden by host-specific properties.
+
+HostGroupFlags_<group>
+   Equivalent to writing HostFlags_<testbox> for every testbox which
+   declares HostGroup_<testbox>_<group>. Allows setting a set of
+   common flags for a group of similar machines. These flags are
+   merged with the host specific flags. Only used in standalone mode.
+
 DebianPreseed
    Text to add to the debian-installer preseed file.  Optional
    but you will need to set some NTP servers here if your firewall