From: Ian Campbell <ian.campbell@citrix.com>
To: ian.jackson@eu.citrix.com, xen-devel@lists.xen.org
Cc: Ian Campbell <ian.campbell@citrix.com>
Subject: [PATCH OSSTEST 3/4] Add support for selecting resources based on their properties.
Date: Tue, 15 Sep 2015 17:05:17 +0100 [thread overview]
Message-ID: <1442333118-843-3-git-send-email-ian.campbell@citrix.com> (raw)
In-Reply-To: <1442333100.18856.16.camel@citrix.com>
In particular for allocating hosts based on host properties.
To do this we extend the hostflags syntax with "condition:arg1:arg2".
This specifies that the candidate host must pass the condition given
the arguments.
Each "condition" is a new module in the Osstest::ResourceCondition
namespace. For each condition an object is constructed using the given
arguments (split on ':') and stored in $hid.
When allocating for each candidate host the object's ->check method is
called giving $restype and $resname and will return true or false
depending on whether the given host meets the condition.
Only a single condition is implemented here "PropMinVer" which
requires that a given property on the resource has at least the given
value when compared as a version string. The actual database name of
the property must be in the new CamelCase style (as output by
propname_massage) since it is looked up by precisely that name and
possible legacy aliases are not considered. Lack of the property being
compared is taken a "no restriction" and hence is allowed.
Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
---
Osstest/ResourceCondition/PropMinVer.pm | 74 +++++++++++++++++++++++++++++++++
ts-hosts-allocate-Executive | 25 +++++++++--
2 files changed, 96 insertions(+), 3 deletions(-)
create mode 100644 Osstest/ResourceCondition/PropMinVer.pm
diff --git a/Osstest/ResourceCondition/PropMinVer.pm b/Osstest/ResourceCondition/PropMinVer.pm
new file mode 100644
index 0000000..d842fe7
--- /dev/null
+++ b/Osstest/ResourceCondition/PropMinVer.pm
@@ -0,0 +1,74 @@
+# This is part of "osstest", an automated testing framework for Xen.
+# Copyright (C) 2015 Citrix Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+package Osstest::ResourceCondition::PropMinVer;
+
+use strict;
+use warnings;
+
+use Osstest;
+use Osstest::TestSupport;
+
+use Sort::Versions;
+
+use overload '""' => 'stringify';
+
+BEGIN {
+ use Exporter ();
+ our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
+ $VERSION = 1.00;
+ @ISA = qw(Exporter);
+ @EXPORT = qw();
+ %EXPORT_TAGS = ( );
+
+ @EXPORT_OK = qw();
+}
+
+sub new {
+ my ($class, $name, $prop, $val) = @_;
+ return bless {
+ Prop => propname_massage($prop),
+ MinVal => $val
+ }, $class;
+}
+
+sub stringify {
+ my ($pmv) = @_;
+ return "$pmv->{MinVal} >= property $pmv->{Prop}";
+}
+
+sub check {
+ my ($pmv, $restype, $resname) = @_;
+
+ # Using _cached avoids needing to worry about $dbh_tests being
+ # closed/reopened between invocations
+ my $hpropq = $dbh_tests->prepare_cached(<<END);
+ SELECT val FROM resource_properties
+ WHERE restype = ? AND resname = ? AND name = ?
+END
+ $hpropq->execute($restype, $resname, $pmv->{Prop});
+
+ my $row= $hpropq->fetchrow_arrayref();
+ $hpropq->finish();
+
+ return 1 unless $row; # No prop == no restriction.
+
+ # If the required minimum is >= to the resource's minimum then the
+ # resource meets the requirement.
+ return versioncmp($pmv->{MinVal}, $row->[0]) >= 0;
+}
+
+1;
diff --git a/ts-hosts-allocate-Executive b/ts-hosts-allocate-Executive
index 294395d..345ffeb 100755
--- a/ts-hosts-allocate-Executive
+++ b/ts-hosts-allocate-Executive
@@ -213,7 +213,7 @@ sub compute_hids () {
our %equivs;
foreach my $ident (@ARGV) {
- my $hid= { };
+ my $hid= { Conds => { host => [] } };
my $override_use;
if ($ident =~ m/\=/) {
$hid->{OverrideUse}= $'; #'
@@ -251,11 +251,23 @@ sub compute_hids () {
my $equiv= $hid->{Equiv}= $equivs{$formalclass};
print DEBUG "HID $ident FLAG $flag EQUIV $equiv->{Wanted}\n";
next;
- }
+ } elsif ($flag =~ m/:/) {
+ my (@c) = split /:/, $flag;
+ my $o;
+ eval ("use Osstest::ResourceCondition::$c[0];".
+ "\$o = Osstest::ResourceCondition::$c[0]->new(\@c);")
+ or die "get ResourceCondition $@";
+
+ push @{$hid->{Conds}{host}}, $o;
+
+ print DEBUG "HID $ident FLAG $flag HCOND $o\n";
+ next;
+ }
$flags{$flag}= 1;
}
$hid->{Flags}= \%flags;
- print DEBUG "HID $ident FLAGS ".(join ',', sort keys %flags)."\n";
+ print DEBUG "HID $ident FLAGS ".(join ',', sort keys %flags).
+ " + ".scalar @{$hid->{Conds}{host}}." host conditions(s)\n";
push @hids, $hid;
}
}
@@ -363,6 +375,13 @@ END
push @{ $candrow->{Warnings} },
"specified host lacks flags @missingflags";
}
+
+ foreach my $c (@{$hid->{Conds}{$candrow->{restype}}}) {
+ if (!$c->check($candrow->{restype}, $candrow->{resname})) {
+ print DEBUG "$dbg failed $c condition\n";
+ next CANDIDATE unless defined $use;
+ }
+ }
$any++;
print DEBUG "$dbg GOOD\n";
--
2.5.1
next prev parent reply other threads:[~2015-09-15 16:05 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-15 16:05 [PATCH OSSTEST 0/4] Avoid running Linux on hosts for the given version lacks drivers Ian Campbell
2015-09-15 16:05 ` [PATCH OSSTEST 1/4] ts-hosts-allocate-Executive: Allow dry-run Ian Campbell
2015-09-15 17:04 ` Ian Jackson
2015-09-15 16:05 ` [PATCH OSSTEST 2/4] ts-hosts-allocate-Executive: add a label to loop over candidates Ian Campbell
2015-09-15 17:04 ` Ian Jackson
2015-09-16 8:51 ` Ian Campbell
2015-09-15 16:05 ` Ian Campbell [this message]
2015-09-15 17:18 ` [PATCH OSSTEST 3/4] Add support for selecting resources based on their properties Ian Jackson
2015-09-16 8:57 ` Ian Campbell
2015-09-15 16:05 ` [PATCH OSSTEST 4/4] make-flight: Add a minimum linux version requirement to all linux-* branches Ian Campbell
2015-09-15 17:19 ` Ian Jackson
2015-09-15 17:21 ` [PATCH OSSTEST 0/4] Avoid running Linux on hosts for the given version lacks drivers Ian Jackson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1442333118-843-3-git-send-email-ian.campbell@citrix.com \
--to=ian.campbell@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).