1
# Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved.
2
# Use is subject to license terms.
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; version 2 of the License.
8
# This program is distributed in the hope that it will be useful, but
9
# WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
# General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
18
package GenTest::XML::Transporter;
23
#@EXPORT = ('XMLTRANSPORT_TYPE_SCP', 'XMLTRANSPORT_TYPE_MYSQL');
27
use GenTest::Constants;
28
use GenTest::Properties;
31
use constant XMLTRANSPORT_TYPE => 0; # which transport type to use
32
use constant XMLTRANSPORT_TYPE_MYSQL => 1; # db connections
33
use constant XMLTRANSPORT_TYPE_SCP => 2; # secure copy
34
use constant XMLTRANSPORT_TYPES => 3; # collection of types
37
use constant XML_DEFAULT_TRANSPORT_TYPE => XMLTRANSPORT_TYPE_SCP;
38
use constant XML_MYSQL_DEFAULT_DSN =>
39
'dbi:mysql:host=myhost:port=3306:user=xmldrop:password=test;database=test';
40
use constant XML_SCP_DEFAULT_USER => undef;
41
use constant XML_SCP_DEFAULT_HOST => 'regin.norway.sun.com';
42
use constant XML_SCP_DEFAULT_DEST_PATH => '/raid/xml_results/TestTool/xml/';
44
1; # so the require or use succeeds
47
# Use this class for transporting XML reports to a given destination.
49
# Usage example (using default settings):
51
# use GenTest::XML::Transporter;
52
# my $xml_transporter = GenTest::XML::Transporter->new(
55
# my $result = $xml_transporter->sendXML($xmlFileName);
56
# if ($result != STATUS_OK) {
57
# croak("Error from XML Transporter: $result");
64
my $self = $class->SUPER::new({
65
type => XMLTRANSPORT_TYPE
68
# Figure out transport type, which may be set as string value on
69
# command-line, or elsewhere. Use default if not set.
70
if (not defined $self->[XMLTRANSPORT_TYPE]) {
71
$self->[XMLTRANSPORT_TYPE] = XML_DEFAULT_TRANSPORT_TYPE;
72
say('XML Transport: Using default settings');
73
} elsif ($self->[XMLTRANSPORT_TYPE] =~ m{scp}io) {
74
# string match for "scp" (case insensitive)
75
$self->[XMLTRANSPORT_TYPE] = XMLTRANSPORT_TYPE_SCP;
76
} elsif ($self->[XMLTRANSPORT_TYPE] =~ m{mysql}io) {
77
# string match for "mysql" (case insensitive)
78
$self->[XMLTRANSPORT_TYPE] = XMLTRANSPORT_TYPE_MYSQL;
81
#${$self}[XMLTRANSPORT_TYPES] = ();
88
# Returns the type of transport mechanism this object represents.
92
if (defined $self->[XMLTRANSPORT_TYPE]) {
93
return $self->[XMLTRANSPORT_TYPE];
95
return XML_DEFAULT_TRANSPORT_TYPE;
100
# Constructs a default destination for the SCP transport type.
101
# Suitable for use in an scp command-line such as:
102
# scp myfile <defaultScpDestination>
103
# where <defaultScpDestination> is <user>@<host>:<path>.
105
sub defaultScpDestination {
107
my $dest = XML_SCP_DEFAULT_HOST.':'.XML_SCP_DEFAULT_DEST_PATH;
108
$dest = XML_SCP_DEFAULT_USER.'@'.$dest if defined XML_SCP_DEFAULT_USER;
114
# Sends XML data to a destination.
115
# The transport mechanism to use (e.g. file copy, database insert, ftp, etc.)
116
# and destination is determined by the "type" argument to the object's
120
# arg1: xml - The xml data file name. TODO: Support XML as string?
121
# arg2: dest - Destination for xml report. Defaults are used if omitted.
124
my ($self, $xml, $dest) = @_;
126
if ($self->type == XMLTRANSPORT_TYPE_MYSQL) {
127
say("XML Transport type: MySQL database connection");
128
$dest = XML_MYSQL_DEFAULT_DSN if not defined $dest;
129
return $self->mysql($xml, $dest);
130
} elsif ($self->type == XMLTRANSPORT_TYPE_SCP) {
131
say("XML Transport type: SCP");
132
$dest = $self->defaultScpDestination if not defined $dest;
133
return $self->scp($xml, $dest);
135
say("[ERROR] XML transport type '".$self->type."' not supported.");
136
return STATUS_ENVIRONMENT_FAILURE;
144
# Sends the XML contents of file $xml to $dest.
145
# If $dest is not defined, a default MySQL dsn will be used.
147
# TODO: - Support argument as string (real XML contents) instead of file name.
148
# - Support non-default destination.
151
my ($self, $xml, $dest) = @_;
154
# 1. Establish dbh / connect
156
# 3. Check for errors
157
# 4. Return appropriate status.
158
say("MySQL XML transport not implemented yet");
159
return STATUS_WONT_HANDLE;
163
# Sends the file $xml by SCP (secure file copy) to $dest.
166
my ($self, $xml, $dest) = @_;
168
# For now, we assume $xml is a file name
169
# TODO: Support XML as string as well? Create temporary file?
174
# We currently support only pscp.exe from Putty on native Windows.
176
# NOTE: Using pscp without specifying private key (-i <keyfile>)
177
# requires that Putty's pageant tool is running and set up with
178
# the correct ssh key on the test host.
179
# If support for options is needed, add it below.
180
$cmd = 'pscp.exe -q '.$xmlfile.' '.$dest;
182
$cmd = 'scp '.$xmlfile.' '.$dest;
185
say("SCP command is: ".$cmd);
187
# TODO: The scp command is interactive if keys and hosts are not set up.
188
# This may cause hangs in automated environments. Find a way to
189
# always run non-interactively, or kill the command after a timeout.
190
my $result == system($cmd);
191
if ($result != STATUS_OK) {
192
warn('XML Transport: scp failed. Command was: '.$cmd);
1
# Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved.
2
# Use is subject to license terms.
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; version 2 of the License.
8
# This program is distributed in the hope that it will be useful, but
9
# WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
# General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
18
package GenTest::XML::Transporter;
23
#@EXPORT = ('XMLTRANSPORT_TYPE_SCP', 'XMLTRANSPORT_TYPE_MYSQL');
27
use GenTest::Constants;
28
use GenTest::Properties;
31
use constant XMLTRANSPORT_TYPE => 0; # which transport type to use
32
use constant XMLTRANSPORT_TYPE_MYSQL => 1; # db connections
33
use constant XMLTRANSPORT_TYPE_SCP => 2; # secure copy
34
use constant XMLTRANSPORT_TYPES => 3; # collection of types
37
use constant XML_DEFAULT_TRANSPORT_TYPE => XMLTRANSPORT_TYPE_SCP;
38
use constant XML_MYSQL_DEFAULT_DSN =>
39
'dbi:mysql:host=myhost:port=3306:user=xmldrop:password=test;database=test';
40
use constant XML_SCP_DEFAULT_USER => undef;
41
use constant XML_SCP_DEFAULT_HOST => 'regin.norway.sun.com';
42
use constant XML_SCP_DEFAULT_DEST_PATH => '/raid/xml_results/TestTool/xml/';
44
1; # so the require or use succeeds
47
# Use this class for transporting XML reports to a given destination.
49
# Usage example (using default settings):
51
# use GenTest::XML::Transporter;
52
# my $xml_transporter = GenTest::XML::Transporter->new(
55
# my $result = $xml_transporter->sendXML($xmlFileName);
56
# if ($result != STATUS_OK) {
57
# croak("Error from XML Transporter: $result");
64
my $self = $class->SUPER::new({
65
type => XMLTRANSPORT_TYPE
68
# Figure out transport type, which may be set as string value on
69
# command-line, or elsewhere. Use default if not set.
70
if (not defined $self->[XMLTRANSPORT_TYPE]) {
71
$self->[XMLTRANSPORT_TYPE] = XML_DEFAULT_TRANSPORT_TYPE;
72
say('XML Transport: Using default settings');
73
} elsif ($self->[XMLTRANSPORT_TYPE] =~ m{scp}io) {
74
# string match for "scp" (case insensitive)
75
$self->[XMLTRANSPORT_TYPE] = XMLTRANSPORT_TYPE_SCP;
76
} elsif ($self->[XMLTRANSPORT_TYPE] =~ m{mysql}io) {
77
# string match for "mysql" (case insensitive)
78
$self->[XMLTRANSPORT_TYPE] = XMLTRANSPORT_TYPE_MYSQL;
81
#${$self}[XMLTRANSPORT_TYPES] = ();
88
# Returns the type of transport mechanism this object represents.
92
if (defined $self->[XMLTRANSPORT_TYPE]) {
93
return $self->[XMLTRANSPORT_TYPE];
95
return XML_DEFAULT_TRANSPORT_TYPE;
100
# Constructs a default destination for the SCP transport type.
101
# Suitable for use in an scp command-line such as:
102
# scp myfile <defaultScpDestination>
103
# where <defaultScpDestination> is <user>@<host>:<path>.
105
sub defaultScpDestination {
107
my $dest = XML_SCP_DEFAULT_HOST.':'.XML_SCP_DEFAULT_DEST_PATH;
108
$dest = XML_SCP_DEFAULT_USER.'@'.$dest if defined XML_SCP_DEFAULT_USER;
114
# Sends XML data to a destination.
115
# The transport mechanism to use (e.g. file copy, database insert, ftp, etc.)
116
# and destination is determined by the "type" argument to the object's
120
# arg1: xml - The xml data file name. TODO: Support XML as string?
121
# arg2: dest - Destination for xml report. Defaults are used if omitted.
124
my ($self, $xml, $dest) = @_;
126
if ($self->type == XMLTRANSPORT_TYPE_MYSQL) {
127
say("XML Transport type: MySQL database connection");
128
$dest = XML_MYSQL_DEFAULT_DSN if not defined $dest;
129
return $self->mysql($xml, $dest);
130
} elsif ($self->type == XMLTRANSPORT_TYPE_SCP) {
131
say("XML Transport type: SCP");
132
$dest = $self->defaultScpDestination if not defined $dest;
133
return $self->scp($xml, $dest);
135
say("[ERROR] XML transport type '".$self->type."' not supported.");
136
return STATUS_ENVIRONMENT_FAILURE;
144
# Sends the XML contents of file $xml to $dest.
145
# If $dest is not defined, a default MySQL dsn will be used.
147
# TODO: - Support argument as string (real XML contents) instead of file name.
148
# - Support non-default destination.
151
my ($self, $xml, $dest) = @_;
154
# 1. Establish dbh / connect
156
# 3. Check for errors
157
# 4. Return appropriate status.
158
say("MySQL XML transport not implemented yet");
159
return STATUS_WONT_HANDLE;
163
# Sends the file $xml by SCP (secure file copy) to $dest.
166
my ($self, $xml, $dest) = @_;
168
# For now, we assume $xml is a file name
169
# TODO: Support XML as string as well? Create temporary file?
174
# We currently support only pscp.exe from Putty on native Windows.
176
# NOTE: Using pscp without specifying private key (-i <keyfile>)
177
# requires that Putty's pageant tool is running and set up with
178
# the correct ssh key on the test host.
179
# If support for options is needed, add it below.
180
$cmd = 'pscp.exe -q '.$xmlfile.' '.$dest;
182
$cmd = 'scp '.$xmlfile.' '.$dest;
185
say("SCP command is: ".$cmd);
187
# TODO: The scp command is interactive if keys and hosts are not set up.
188
# This may cause hangs in automated environments. Find a way to
189
# always run non-interactively, or kill the command after a timeout.
190
my $result == system($cmd);
191
if ($result != STATUS_OK) {
192
warn('XML Transport: scp failed. Command was: '.$cmd);