lintian doesn't like orphan packages with uploaders...
[debian/amanda] / installcheck / Amanda_Changer.pl
index 910d459cdea9ed0b54faf4438083e4c72feee8b6..22b099d8c33ca4b55bcba22e4fb8a3f3e402bb36 100644 (file)
@@ -1,8 +1,9 @@
-# Copyright (c) 2007, 2008, 2009, 2010 Zmanda, Inc.  All Rights Reserved.
+# Copyright (c) 2007-2012 Zmanda, Inc.  All Rights Reserved.
 #
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 as published
-# by the Free Software Foundation.
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
 #
 # This program is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
@@ -16,7 +17,7 @@
 # Contact information: Zmanda Inc, 465 S. Mathilda Ave., Suite 300
 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
 
-use Test::More tests => 47;
+use Test::More tests => 54;
 use File::Path;
 use Data::Dumper;
 use strict;
@@ -25,11 +26,12 @@ use warnings;
 use lib "@amperldir@";
 use Installcheck::Config;
 use Amanda::Paths;
-use Amanda::Device;
+use Amanda::Device qw( :constants );;
 use Amanda::Debug;
 use Amanda::MainLoop;
 use Amanda::Config qw( :init :getconf config_dir_relative );
 use Amanda::Changer;
+use Amanda::Tapelist;
 
 # set up debugging so debug output doesn't interfere with test results
 Amanda::Debug::dbopen("installcheck");
@@ -249,9 +251,33 @@ if ($cfg_result != $CFGERR_OK) {
 }
 
 # check out the relevant changer properties
-my $chg = Amanda::Changer->new("mychanger");
+my $tlf = Amanda::Config::config_dir_relative(getconf($CNF_TAPELIST));
+my $tl = Amanda::Tapelist->new($tlf);
+my $chg = Amanda::Changer->new("mychanger", tapelist => $tl);
 is($chg->{'config'}->get_property("testprop"), "testval",
     "changer properties are correctly represented");
+is($chg->have_inventory(), 1, "changer have inventory");
+my @new_tape_label = $chg->make_new_tape_label();
+is_deeply(\@new_tape_label, [undef, "template is not set, you must set autolabel"], "no make_new_tape_label");
+is($chg->make_new_meta_label(), undef, "no make_new_meta_label");
+
+$chg = Amanda::Changer->new("mychanger", tapelist => $tl,
+                           labelstr => "TESTCONF-[0-9][0-9][0-9]-[a-z][a-z][a-z]-[0-9][0-9][0-9]",
+                           autolabel => { template => '$c-$m-$b-%%%',
+                                          other_config => 1,
+                                          non_amanda => 1,
+                                          volume_error => 0,
+                                          empty => 1 },
+                           meta_autolabel => "%%%");
+my $meta = $chg->make_new_meta_label();
+is($meta, "001", "meta 001");
+my $label = $chg->make_new_tape_label(meta => $meta, barcode => 'aaa');
+is($label, 'TESTCONF-001-aaa-001', "label TESTCONF-001-aaa-001");
+
+is($chg->volume_is_labelable($DEVICE_STATUS_VOLUME_UNLABELED, $Amanda::Header::F_EMPTY),
+   1, "empty volume is labelable");
+is($chg->volume_is_labelable($DEVICE_STATUS_VOLUME_ERROR, undef),
+   0, "empty volume is labelable");
 
 # test loading by label
 {
@@ -522,6 +548,7 @@ Amanda::MainLoop::run();
     $do_info->();
     Amanda::MainLoop::run();
 }
+$chg->quit();
 
 # Test the various permutations of configuration setup, with a patched
 # _new_from_uri so we can monitor the result
@@ -676,7 +703,8 @@ sub test_locked_state {
     my $num_outstanding = 0;
 
     my $steps = define_steps
-       cb_ref => \$finished_cb;
+       cb_ref => \$finished_cb,
+       finalize => sub { $chg->quit() if defined $chg };
 
     step start => sub {
        $chg = Amanda::Changer->new("chg-null:");