Begin to fill in pt-agent. Use new, experimental Percona::Toolkit. Remove Versions resource; add as optional attrib to Agent resource.

This commit is contained in:
Daniel Nichter
2012-12-24 13:17:48 -07:00
parent 93416d4cb6
commit 593e64e6ec
5 changed files with 282 additions and 1273 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -19,7 +19,45 @@
# ###########################################################################
{
package Percona::Toolkit;
our $VERSION = '2.1.7';
our $VERSION = '3.0.0';
use Carp qw(carp cluck);
use Data::Dumper qw();
$Data::Dumper::Indent = 1;
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Quotekeys = 0;
use Exporter 'import';
our @EXPORT = qw(
have_required_args
Dumper
_d
);
sub have_required_args {
my ($args, @required_args) = @_;
my $have_required_args = 1;
foreach my $arg ( @required_args ) {
if ( !defined $args->{$arg} ) {
$have_required_args = 0;
carp "Argument $arg is not defined";
}
}
cluck unless $have_required_args; # print backtrace
return $have_required_args;
}
sub Dumper {
Data::Dumper::Dumper(@_);
}
sub _d {
my ($package, undef, $line) = caller 0;
@_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
map { defined $_ ? $_ : 'undef' }
@_;
print STDERR "# $package:$line $PID ", join(' ', @_), "\n";
}
1;
}

View File

@@ -15,12 +15,11 @@ has 'hostname' => (
is => 'ro',
isa => 'Str',
required => 1,
default => sub { return `hostname 2>/dev/null` },
);
has 'versions' => (
is => 'ro',
isa => 'Maybe[Percona::WebAPI::Resource::Versions]',
isa => 'Maybe[HashRef]',
required => 0,
default => undef,
);

View File

@@ -1,14 +0,0 @@
package Percona::WebAPI::Resource::Versions;
use Mo;
with 'Percona::WebAPI::Representation::JSON';
with 'Percona::WebAPI::Representation::HashRef';
has 'versions' => (
is => 'ro',
isa => 'HashRef',
required => 1,
);
1;

View File

@@ -8,76 +8,13 @@ BEGIN {
use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);
use Test::More;
use IPC::Cmd qw(run can_run);
use PerconaTest;
use Percona::Toolkit;
use Percona::Test;
my $version = $Percona::Toolkit::VERSION;
my $perl = $^X;
use File::Basename qw(basename);
my @vc_tools = grep { chomp; basename($_) =~ /\A[a-z-]+\z/ } glob("$trunk/bin/*");
foreach my $tool ( @vc_tools ) {
my $output = `$tool --version 2>/dev/null`;
my ($tool_version) = $output =~ /(\b[0-9]\.[0-9]\.[0-9]\b)/;
next unless $tool_version; # Some tools don't have --version implemented
my $base = basename($tool);
is(
$tool_version,
$version,
"$base --version and Percona::Toolkit::VERSION agree"
);
# Now let's check that lib/Percona/Toolkit.pm and each tool's
# $Percona::Toolkit::VERSION agree, sow e can avoid the 2.1.4 pt-table-sync
# debacle
open my $tmp_fh, q{<}, $tool or die "$!";
my $is_perl = scalar(<$tmp_fh>) =~ /perl/;
close $tmp_fh;
next unless $is_perl;
my ($success, undef, $full_buf) =
run(
command => [ $perl, '-le', "require q{$tool}; print \$Percona::Toolkit::VERSION"]
);
if ( !$success ) {
fail("Failed to get \$Percona::Toolkit::VERSION from $base: $full_buf")
}
else {
chomp(@$full_buf);
my $out = join "", @$full_buf;
if ($out) {
is(
"@$full_buf",
$version,
"$base and lib/Percona/Toolkit.pm agree"
);
}
}
}
my $bzr = can_run('bzr');
SKIP: {
skip "Can't run bzr, skipping tag checking", 1 unless $bzr;
chomp(my $root = `$bzr root 2>/dev/null`);
skip '$trunk and bzr root differ, skipping tag checking'
unless $root eq $trunk;
my @tags = split /\n/, `$bzr tags`;
my ($current_tag) = $tags[-1] =~ /^(\S+)/;
is(
$current_tag,
$version,
"bzr tags and Percona::Toolkit::VERSION agree"
);
}
# #############################################################################
# Done.
# #############################################################################
done_testing;