spacewalk/setup/lib/Spacewalk/Setup.pm | 123 +++++++++++++++++++++++----------
1 file changed, 88 insertions(+), 35 deletions(-)
New commits:
commit 07d1b21d5fd56635e9a47c4d553fa7fbcb71c392
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Fri Jun 18 12:05:15 2010 +0200
Port was missing in invocation of rhn-populate-database.pl for PostgreSQL.
diff --git a/spacewalk/setup/lib/Spacewalk/Setup.pm
b/spacewalk/setup/lib/Spacewalk/Setup.pm
index a14fdc3..01c8ff1 100644
--- a/spacewalk/setup/lib/Spacewalk/Setup.pm
+++ b/spacewalk/setup/lib/Spacewalk/Setup.pm
@@ -822,6 +822,7 @@ sub postgresql_populate_db {
sprintf('--password=%s', @{$answers}{'db-password'}),
sprintf('--database=%s', @{$answers}{'db-name'}),
sprintf('--host=%s', @{$answers}{'db-host'}),
+ sprintf('--port=%s', @{$answers}{'db-port'}),
sprintf("--schema-deploy-file=$sat_schema_deploy"),
sprintf("--log=$logfile"),
sprintf('--nofork'),
commit 3018b96fb6c34687bdde497f1349bd6a61be8cc9
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Fri Jun 18 12:04:27 2010 +0200
For PostgreSQL, only put in parameter to DBI connect string if they were specified.
diff --git a/spacewalk/setup/lib/Spacewalk/Setup.pm
b/spacewalk/setup/lib/Spacewalk/Setup.pm
index f1904b8..a14fdc3 100644
--- a/spacewalk/setup/lib/Spacewalk/Setup.pm
+++ b/spacewalk/setup/lib/Spacewalk/Setup.pm
@@ -1356,41 +1356,50 @@ EOQ
}
sub get_dbh {
- my $answers = shift;
+ my $answers = shift;
- my ($database, $username, $password, $sid, $host, $port) = @{$answers}{qw/db-backend
db-user db-password db-sid db-host db-port/};
+ my $dbh_attributes = {
+ RaiseError => 1,
+ PrintError => 0,
+ Taint => 0,
+ AutoCommit => 0,
+ };
- my $dbh;
- if ($database eq "oracle") {
- $dbh = DBI->connect("dbi:Oracle:$sid", $username, $password,
- {
- RaiseError => 1,
- PrintError => 0,
- Taint => 0,
- AutoCommit => 0,
- }
- );
- }
- elsif ($database eq "postgresql") {
- $dbh = DBI->connect("DBI:Pg:dbname=$sid;host=$host;port=$port",
$username, $password,
- {
- RaiseError => 1,
- PrintError => 0,
- Taint => 0,
- AutoCommit => 0,
- }
- );
- }
+ my $backend = $answers->{'db-backend'};
+ if ($backend eq 'oracle') {
+ my $dbh =
DBI->connect("dbi:Oracle:$answers->{'db-sid'}",
+ $answers->{'db-user'},
+ $answers->{'db-password'},
+ $dbh_attributes);
+
+ # Bugzilla 466747: On s390x, stty: standard input: Bad file descriptor
+ # For some reason DBI mistakenly sets FD_CLOEXEC on a stdin file
descriptor
+ # here. This made it impossible for us to succesfully call `stty -echo`
+ # later in the code. Following two lines work around the problem.
- # Bugzilla 466747: On s390x, stty: standard input: Bad file descriptor
- # For some reason DBI mistakenly sets FD_CLOEXEC on a stdin file descriptor
- # here. This made it impossible for us to succesfully call `stty -echo`
- # later in the code. Following two lines work around the problem.
+ my $flags = fcntl(STDIN, F_GETFD, 0);
+ fcntl(STDIN, F_SETFD, $flags & ~FD_CLOEXEC);
- my $flags = fcntl(STDIN, F_GETFD, 0);
- fcntl(STDIN, F_SETFD, $flags & ~FD_CLOEXEC);
+ return $dbh;
+ }
+
+ if ($backend eq 'postgresql') {
+ my $dsn = "dbi:Pg:dbname=$answers->{'db-name'}";
+ if ($answers->{'db-host'} ne '') {
+ $dsn .= ";host=$answers->{'db-host'}";
+ if ($answers->{'db-port'} ne '') {
+ $dsn .= ";port=$answers->{'db-port'}";
+ }
+ }
+ my $dbh = DBI->connect($dsn,
+ $answers->{'db-user'},
+ $answers->{'db-password'},
+ $dbh_attributes);
+
+ return $dbh;
+ }
- return $dbh;
+ die "Unknown db-backend [$backend]\n";
}
# Find the default tablespace name for the given (oracle) user.
commit 4d5f2509052893001a3505ac0cbf16895045b466
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Thu Jun 17 15:58:54 2010 +0200
For PostgreSQL, call it db-name instead of db-sid. Also use different default port.
diff --git a/spacewalk/setup/lib/Spacewalk/Setup.pm
b/spacewalk/setup/lib/Spacewalk/Setup.pm
index d3b210c..f1904b8 100644
--- a/spacewalk/setup/lib/Spacewalk/Setup.pm
+++ b/spacewalk/setup/lib/Spacewalk/Setup.pm
@@ -649,7 +649,7 @@ sub set_progress_callback {
alarm 1;
}
-sub get_database_answers {
+sub oracle_get_database_answers {
my $opts = shift;
my $answers = shift;
@@ -695,6 +695,49 @@ sub get_database_answers {
return;
}
+sub postgresql_get_database_answers {
+ my $opts = shift;
+ my $answers = shift;
+
+ ask(
+ -noninteractive => $opts->{"non-interactive"},
+ -question => "Hostname (leave empty for local)",
+ -test => sub { 1 },
+ -answer => \$answers->{'db-host'});
+
+ if ($answers->{'db-host'} ne '') {
+ ask(
+ -noninteractive => $opts->{"non-interactive"},
+ -question => "Port",
+ -test => qr/\d+/,
+ -default => 5432,
+ -answer => \$answers->{'db-port'});
+ } else {
+ $answers->{'db-port'} = '';
+ }
+
+ ask(
+ -noninteractive => $opts->{"non-interactive"},
+ -question => "Database",
+ -test => qr/\S+/,
+ -answer => \$answers->{'db-name'});
+
+ ask(
+ -noninteractive => $opts->{"non-interactive"},
+ -question => "Username",
+ -test => qr/\S+/,
+ -answer => \$answers->{'db-user'});
+
+ ask(
+ -noninteractive => $opts->{"non-interactive"},
+ -question => "Password",
+ -test => qr/\S+/,
+ -answer => \$answers->{'db-password'},
+ -password => 1);
+
+ return;
+}
+
############################
# PostgreSQL Specific Code #
@@ -709,7 +752,7 @@ sub postgresql_setup_db {
my $connected;
while (not $connected) {
- get_database_answers($opts, $answers);
+ postgresql_get_database_answers($opts, $answers);
my $dbh;
@@ -720,7 +763,7 @@ sub postgresql_setup_db {
if ($@) {
print Spacewalk::Setup::loc("Could not connect to the database. Your
connection information may be incorrect. Error: %s\n", $@);
- delete @{$answers}{qw/db-protocol db-host db-port db-user db-sid
db-password/};
+ delete @{$answers}{qw/db-host db-port db-name db-user db-password/};
}
else {
$connected = 1;
@@ -777,7 +820,7 @@ sub postgresql_populate_db {
my @opts = ('/usr/bin/rhn-populate-database.pl',
sprintf('--user=%s', @{$answers}{'db-user'}),
sprintf('--password=%s', @{$answers}{'db-password'}),
- sprintf('--database=%s', @{$answers}{'db-sid'}),
+ sprintf('--database=%s', @{$answers}{'db-name'}),
sprintf('--host=%s', @{$answers}{'db-host'}),
sprintf("--schema-deploy-file=$sat_schema_deploy"),
sprintf("--log=$logfile"),
@@ -993,7 +1036,7 @@ sub oracle_setup_db_connection {
my $connected;
while (not $connected) {
- get_database_answers($opts, $answers);
+ oracle_get_database_answers($opts, $answers);
my $address = join(",", @{$answers}{qw/db-protocol db-host db-port/});