# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-
use FindBind($RealBin);
use hostdb;
print "Add Machine to build farm: add\n";
print "Remove Machine from build farm: remove\n";
-print "Modify build farm account: modify\n";
+print "Modify build farm account: modify\n";
print "Select Operation: [add]";
my lc($op) = chomp(<>);
-if ($op == "") {
+if ($op eq "") {
$op = "add";
}
-if ($op == "add") {
+if ($op eq "remove") {
+ print "Please enter hostname to delete: \n";
+ my $hostname = chomp(<>);
+ $ok = $db->deletehost($hostname);
+ assert($ok);
+} elif ($op eq "add") {
print "Machine hostname: ";
my $hostname = chomp(<>);
print "Machine platform (eg Fedora 9 x86_64): "
}
print "Enter password (press enter for random)";
my $password = chomp(<>);
- if ($password == "") {
+ if ($password eq "") {
$password = chomp(`pwgen 16 1`);
print "Password will be: $password\n"
}
print "Enter permission e-mail, finish with a ."
my $permission;
while (<>) {
- last if $_ = ".\n";
+ last if $_ eq ".\n";
$permission = $_;
}
print "Subject: $subject\n";
open(MAIL,"|cat");
} else {
- open(MAIL,"|Mail -s \"Your new build farm host $hostname\" \"$owner\" \<$owner_email\>");
+ open(MAIL,"|Mail -s \"Your new build farm host $hostname\" \"$owner <$owner_email\>");
}
my $body = << "__EOF__";
__EOF__
-print MAIL $body;
+ print MAIL $body;
-close(MAIL);
+ close(MAIL);
+} else {
+ die("Unknown command $op");
}
-
return $self->{dbh}->selectall_arrayref("SELECT * FROM host", { Slice => {} });
}
+sub host($$)
+{
+ my ($self, $name) = @_;
+
+ my $hosts = $self->hosts();
+
+ foreach (@$hosts) {
+ return $_ if ($_->{name} eq $name);
+ }
+
+ return undef;
+}
+
+sub update_platform($$$)
+{
+ my ($self, $name, $new_platform) = @_;
+
+ my $changed = $self->{dbh}->do("UPDATE host SET platform = ? WHERE name = ?", undef,
+ ($new_platform, $name));
+
+ die("Inconsistent database: More than one entry with name $name") if ($changed > 1);
+
+ return ($changed == 1);
+}
+
+sub update_owner($$$$)
+{
+ my ($self, $name, $new_owner, $new_owner_email) = @_;
+
+ my $changed = $self->{dbh}->do("UPDATE host SET owner = ?, owner_email = ? WHERE name = ?",
+ undef, ($new_owner, $new_owner_email, $name));
+
+ die("Inconsistent database: More than one entry with name $name") if ($changed > 1);
+
+ return ($changed == 1);
+}
+
# Write out the rsyncd.secrets
sub create_rsync_secrets($)
{
foreach (@$hosts) {
$res .= "# $_->{name}, owner: $_->{owner} <$_->{owner_email}>\n";
- $res .= "$_->{name} $_->{password}\n\n";
+ $res .= "$_->{name}:$_->{password}\n\n";
}
return $res;
use lib "$RealBin/..";
use lib "$RealBin/../web";
-use Test::More tests => 9;
+use Test::More tests => 15;
use strict;
use hostdb;
is_deeply([["gwalcmai"]], $db->{dbh}->selectall_arrayref("SELECT name FROM host"));
-is_deeply([{ name => "gwalcmai", owner => "jelmer", owner_email => "jelmer\@example.com",
+my $expected_host = { name => "gwalcmai", owner => "jelmer", owner_email => "jelmer\@example.com",
platform => "vax", permission => 'Yo! Please put me on the buildfarm', fqdn => undef,
- password => "geheim", ssh_access => undef }], $db->hosts());
+ password => "geheim", ssh_access => undef };
+
+is_deeply([$expected_host], $db->hosts());
+
+is_deeply($expected_host, $db->host("gwalcmai"));
+
+is(undef, $db->host("foo"));
is("gwalcmai: vax\n", $db->create_hosts_list());
is("# rsyncd.secrets file\n" .
"# automatically generated by textfiles.pl. DO NOT EDIT!\n\n" .
- "# gwalcmai, jelmer <jelmer\@example.com>\n" .
- "gwalcmai: geheim\n\n", $db->create_rsync_secrets());
+ "# gwalcmai, owner: jelmer <jelmer\@example.com>\n" .
+ "gwalcmai:geheim\n\n", $db->create_rsync_secrets());
+
+ok($db->update_platform("gwalcmai", "s390"));
+
+$expected_host->{platform} = "s390";
+
+is_deeply($expected_host, $db->host("gwalcmai"));
+
+ok($db->update_owner("gwalcmai", "Andrew", "abartlet\@example.com"));
+
+$expected_host->{owner} = "Andrew";
+$expected_host->{owner_email} = "abartlet\@example.com";
+
+is_deeply($expected_host, $db->host("gwalcmai"));
ok($db->deletehost("gwalcmai"));
is_deeply([], $db->{dbh}->selectall_arrayref("SELECT name FROM host"));