File Coverage

blib/lib/PITA/Image/Test.pm
Criterion Covered Total %
statement 20 58 34.4
branch 0 18 0.0
condition n/a
subroutine 7 18 38.8
pod 0 10 0.0
total 27 104 25.9


line stmt bran cond sub pod time code
1             package PITA::Image::Test;
2              
3 1     1   2576 use 5.006;
  1         4  
  1         30  
4 1     1   5 use strict;
  1         2  
  1         34  
5 1     1   763 use Data::GUID ();
  1         13150  
  1         27  
6 1     1   12 use Params::Util ();
  1         2  
  1         13  
7 1     1   6 use PITA::Image::Task ();
  1         2  
  1         16  
8              
9 1     1   5 use vars qw{$VERSION @ISA};
  1         1  
  1         73  
10             BEGIN {
11 1     1   2 $VERSION = '0.60';
12 1         555 @ISA = 'PITA::Image::Task';
13             }
14              
15             sub new {
16 0     0 0   my $class = shift;
17 0           my $self = bless { @_ }, $class;
18              
19             # Got somewhere to report this to?
20 0 0         unless ( $self->job_id ) {
21 0           Carp::croak("Task does not have a job_id");
22             }
23              
24             # Resolve the specific schema class for this test run
25 0           my $scheme = $self->scheme; # A convenience
26 0 0         unless ( $scheme ) {
27 0           Carp::croak("Missing option 'task.scheme' in image.conf");
28             }
29 0           my $driver = join( '::', 'PITA', 'Scheme', map { ucfirst $_ } split /\./, lc $scheme );
  0            
30 0 0         unless ( Params::Util::_CLASS($driver) ) {
31 0           Carp::croak("Invalid scheme '$scheme' for task.scheme in in image.conf");
32             }
33              
34             # Load the scheme class
35 0           eval "require $driver;";
36 0 0         if ( $@ =~ /^Can\'t locate PITA/ ) {
    0          
37 0           Carp::croak("Scheme '$scheme' is unsupported on this Guest");
38             } elsif ( $@ ) {
39 0           Carp::croak("Error loading scheme '$scheme' driver $driver: $@");
40             }
41              
42             # Did we get a path
43 0 0         unless ( defined $self->path ) {
44 0           Carp::croak("Missing option task.path in image.conf");
45             }
46              
47             # Did we get a config file
48 0 0         unless ( $self->config ) {
49 0           Carp::croak("Missing option task.config in image.conf");
50             }
51              
52             # Did we get a job_id?
53 0 0         unless ( _GUID($self->job_id) ) {
54 0           Carp::croak("Missing option task.job_id in image.conf");
55             }
56              
57             # Did we get a request?
58             # Create the task object from it
59 0           $self->{driver} = $driver->new(
60             injector => $self->{injector},
61             workarea => $self->{workarea},
62             scheme => $self->scheme,
63             path => $self->path,
64             request_xml => $self->config,
65             request_id => $self->job_id,
66             );
67              
68 0           $self;
69             }
70              
71             sub job_id {
72 0     0 0   $_[0]->{job_id};
73             }
74              
75             sub scheme {
76 0     0 0   $_[0]->{scheme};
77             }
78              
79             sub path {
80 0     0 0   $_[0]->{path};
81             }
82              
83             sub config {
84 0     0 0   $_[0]->{config};
85             }
86              
87             sub driver {
88 0     0 0   $_[0]->{driver};
89             }
90              
91              
92              
93              
94              
95             #####################################################################
96             # Run the test
97              
98             sub run {
99 0     0 0   my $self = shift;
100 0           $self->driver->prepare_all;
101 0           $self->driver->execute_all;
102 0           1;
103             }
104              
105             sub result {
106 0     0 0   $_[0]->report;
107             }
108              
109              
110              
111              
112              
113             #####################################################################
114             # Return the resulting data
115              
116             sub report {
117 0     0 0   $_[0]->driver->report;
118             }
119              
120             sub install {
121 0     0 0   $_[0]->driver->install;
122             }
123              
124              
125              
126              
127              
128             #####################################################################
129             # Support Methods
130              
131             sub _GUID {
132 0     0     my $guid = eval {
133 0           Data::GUID->from_any_string(shift);
134             };
135 0 0         $@ ? undef : $guid;
136             }
137              
138             #sub DESTROY {
139             # # Clean up our driver early
140             # if ( $_[0]->{driver} ) {
141             # undef $_[0]->{driver};
142             # }
143             #}
144              
145             1;