[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [OSSTEST PATCH 05/11] ResourceCondition: Break out PropCompareBase
Make a base class so we can easily invent other kinds of resource property condition. The child is responsible only for stringification and the actual comparison. These classes does not need Exporter, so drop all that. Use `use parent' to import the base class. Signed-off-by: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx> --- Osstest/ResourceCondition/PropCompareBase.pm | 66 ++++++++++++++++++++++++++++ Osstest/ResourceCondition/PropMinVer.pm | 45 +++---------------- 2 files changed, 73 insertions(+), 38 deletions(-) create mode 100644 Osstest/ResourceCondition/PropCompareBase.pm diff --git a/Osstest/ResourceCondition/PropCompareBase.pm b/Osstest/ResourceCondition/PropCompareBase.pm new file mode 100644 index 0000000..5306bb8 --- /dev/null +++ b/Osstest/ResourceCondition/PropCompareBase.pm @@ -0,0 +1,66 @@ +# 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::PropCompareBase; + +use strict; +use warnings; + +use Osstest; +use Osstest::TestSupport; + +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) = @_; + + die "propname: $prop?" unless propname_check($prop); + + return bless { + Prop => $prop, + Val => $val + }, $class; +} + +sub check { + my ($pc, $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, $pc->{Prop}); + + my $row= $hpropq->fetchrow_arrayref(); + $hpropq->finish(); + + my $propval = $row->[0]; + + return $pc->_check($propval); +} + +1; diff --git a/Osstest/ResourceCondition/PropMinVer.pm b/Osstest/ResourceCondition/PropMinVer.pm index 155aefb..1880d7c 100644 --- a/Osstest/ResourceCondition/PropMinVer.pm +++ b/Osstest/ResourceCondition/PropMinVer.pm @@ -19,6 +19,8 @@ package Osstest::ResourceCondition::PropMinVer; use strict; use warnings; +use parent 'Osstest::ResourceCondition::PropCompareBase'; + use Osstest; use Osstest::TestSupport; @@ -26,52 +28,19 @@ 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) = @_; - - die "propname: $prop?" unless propname_check($prop); - - return bless { - Prop => $prop, - MinVal => $val - }, $class; -} - sub stringify { my ($pmv) = @_; - return "$pmv->{MinVal} >=(v) property $pmv->{Prop}"; + return "$pmv->{Val} >=(v) 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(); +sub _check { + my ($pmv, $propval) = @_; - return 1 unless $row; # No prop == no restriction. + return 1 unless defined $propval; # No prop == no restriction. # If the maximum minimum is >= to the resource's minimum then the # resource meets the requirement. - return versioncmp($pmv->{MinVal}, $row->[0]) >= 0; + return versioncmp($pmv->{Val}, $propval) >= 0; } 1; -- 2.1.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |