# The splat passes the correct (we hope) number of arguments to the
# appropriate runner. The Rm(Dummy)Runner have splats on their
# *target arguments as well, to turn ARGV back into an array.
- runner.run(plugin, *args)
+ runner.run(cfg, plugin, *args)
end
end
end
module Runner
- def run(plugin, targets)
+ def run(cfg, plugin, targets)
raise NotImplementedError
end
class MvDummyRunner
include Runner
- def run(plugin, src, dst)
+ def run(cfg, plugin, src, dst)
if src.is_a?(Domain) or dst.is_a?(Domain) then
msg = 'only users can be moved'
class MvRunner
include Runner
- def run(plugin, src, dst)
+ def run(cfg, plugin, src, dst)
if src.is_a?(Domain) or dst.is_a?(Domain) then
msg = 'only users can be moved'
class PruneDummyRunner
include Runner
- def run(plugin)
+ def run(cfg, plugin)
# We don't want to check the PostfixAdmin database against itself.
return if plugin.class == PostfixadminPrune
- cfg = Configuration.new()
pfa = PostfixadminPrune.new(cfg)
db_users = pfa.list_users()
leftovers += plugin.get_leftover_domains(db_domains)
rm_dummy_runner = RmDummyRunner.new()
- rm_dummy_runner.run(plugin, *leftovers)
+ rm_dummy_runner.run(cfg, plugin, *leftovers)
end
end
class PruneRunner
include Runner
- def run(plugin)
+ def run(cfg, plugin)
# We don't want to check the PostfixAdmin database against itself.
return if plugin.class == PostfixadminPrune
- cfg = Configuration.new()
pfa = PostfixadminPrune.new(cfg)
db_users = pfa.list_users()
leftovers += plugin.get_leftover_domains(db_domains)
rm_runner = RmRunner.new()
- rm_runner.run(plugin, *leftovers)
+ rm_runner.run(cfg, plugin, *leftovers)
end
end
class RmDummyRunner
include Runner
- def run(plugin, *targets)
+ def run(cfg, plugin, *targets)
targets.each do |target|
target_description = plugin.describe(target)
msg = "Would remove #{target.class.to_s().downcase()} #{target}"
class RmRunner
include Runner
- def run(plugin, *targets)
+ def run(cfg, plugin, *targets)
targets.each do |target|
remove_target(plugin, target)
end
db_user = 'postgres'
db_pass = nil
- connection = PGconn.connect(db_host,
- db_port,
- db_opts,
- db_tty,
- db_name,
- db_user,
- db_pass)
+ connection = PGconn.connect(db_host, db_port, db_opts, db_tty,
+ db_name, db_user, db_pass)
return connection
end
# | 3 | adam@example.net |
# +---------+--------------------+
+ # First make sure we get rid of everything so we don't get random
+ # failures from databases and directories that already exist.
+ teardown()
+
cfg = configuration()
# First create the "mail directories".
plugin_dbuser = cfg.send("#{plugin}_dbuser")
plugin_dbpass = cfg.send("#{plugin}_dbpass")
- plugin_conn = PGconn.connect(plugin_dbhost,
- plugin_dbport,
- plugin_dbopts,
- plugin_dbtty,
- plugin_dbname,
- plugin_dbuser,
+ plugin_conn = PGconn.connect(plugin_dbhost, plugin_dbport, plugin_dbopts,
+ plugin_dbtty, plugin_dbname, plugin_dbuser,
plugin_dbpass)
sql = File.open("test/sql/#{plugin}.sql").read()
cfg = configuration()
connection = connect_superuser()
+ # Don't emit notices about missing tables. Why this happens when I
+ # explicitly say IF EXISTS is beyond me.
+ connection.set_notice_processor{}
+
cfg.plugins.each do |plugin|
plugin_dbname = cfg.send("#{plugin}_dbname")
next if plugin_dbname.nil? # Skip the dovecot plugin
- query = "DROP DATABASE #{plugin_dbname};"
+ query = "DROP DATABASE IF EXISTS #{plugin_dbname};"
connection.query(query)
end
connection.close()
# Get rid of the maildirs.
- FileUtils.rm_r(cfg.dovecot_mail_root())
+ FileUtils.rm_rf(cfg.dovecot_mail_root())
end
end