Merge tag 'upstream/3.3.3'
[debian/amanda] / installcheck / Amanda_Changer_ndmp.pl
index a04ac2b181041c7fae14719be64544ce6ca74159..a5943bfd67d039f9d09e8c12a39b850c92464317 100644 (file)
@@ -1,8 +1,9 @@
-# Copyright (c) 2009, 2010 Zmanda Inc.  All Rights Reserved.
+# Copyright (c) 2009-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 => 165;
+use Test::More tests => 171;
 use File::Path;
 use Data::Dumper;
 use strict;
@@ -74,7 +75,8 @@ sub test_interface {
     my ($interface, $chg);
 
     my $steps = define_steps
-       cb_ref => \$finished_cb;
+       cb_ref => \$finished_cb,
+       finalize => sub { $chg->quit() if defined $chg};
 
     step start => sub {
        my $testconf = Installcheck::Config->new();
@@ -95,6 +97,7 @@ sub test_interface {
 
        $chg = Amanda::Changer->new("robo");
        die "$chg" if $chg->isa("Amanda::Changer::Error");
+       is($chg->have_inventory(), '1', "changer have inventory");
 
        $interface = $chg->{'interface'};
        $interface->inquiry($steps->{'inquiry_cb'});
@@ -290,12 +293,12 @@ sub test_changer {
     my $pfx = "BC=$mtx_config->{barcodes}; TORIG=$mtx_config->{track_orig}";
 
     my $steps = define_steps
-       cb_ref => \$finished_cb;
+       cb_ref => \$finished_cb,
+       finalize => sub { $chg->quit() if defined $chg};
 
     # clean up
     step setup => sub {
        unlink($chg_state_file) if -f $chg_state_file;
-       %Amanda::Changer::changers_by_uri_cc = ();
 
        my @ignore_barcodes = ( property => "\"ignore-barcodes\" \"y\"")
            if ($mtx_config->{'barcodes'} == -1);
@@ -335,6 +338,7 @@ sub test_changer {
            "$pfx: Create working chg-robot instance: $chg")
            or die("no sense going on");
 
+       is($chg->have_inventory(), '1', "changer have inventory");
        $chg->info(info => [qw(vendor_string num_slots fast_search)],
                    info_cb => $steps->{'info_cb'});
     };
@@ -356,19 +360,24 @@ sub test_changer {
        check_inventory($chg, $mtx_config->{'barcodes'} > 0, $steps->{'load_slot_1'}, [
            { slot => 1, state => Amanda::Changer::SLOT_EMPTY,
              import_export => 1,
-             device_status => undef, f_type => undef, label => undef },
+             device_status => undef, device_error => undef,
+             f_type => undef, label => undef },
            { slot => 2, state => Amanda::Changer::SLOT_EMPTY,
              import_export => 1,
-             device_status => undef, f_type => undef, label => undef },
+             device_status => undef, device_error => undef,
+             f_type => undef, label => undef },
            { slot => 3, state => Amanda::Changer::SLOT_FULL,
              barcode => 'PTAG00XX', current => 1,
-             device_status => undef, f_type => undef, label => undef },
+             device_status => undef, device_error => undef,
+             f_type => undef, label => undef },
            { slot => 4, state => Amanda::Changer::SLOT_FULL,
              barcode => 'PTAG01XX',
-             device_status => undef, f_type => undef, label => undef },
+             device_status => undef, device_error => undef,
+             f_type => undef, label => undef },
            { slot => 5, state => Amanda::Changer::SLOT_FULL,
              barcode => 'PTAG02XX',
-             device_status => undef, f_type => undef, label => undef },
+             device_status => undef, device_error => undef,
+             f_type => undef, label => undef },
        ], "$pfx: inventory is correct on start-up");
     };
 
@@ -447,20 +456,27 @@ sub test_changer {
        check_inventory($chg, $mtx_config->{'barcodes'} > 0, $steps->{'load_slot_3'}, [
            { slot => 1, state => Amanda::Changer::SLOT_EMPTY,
              import_export => 1,
-             device_status => undef, f_type => undef, label => undef },
+             device_status => undef, device_error => undef,
+             f_type => undef, label => undef },
            { slot => 2, state => Amanda::Changer::SLOT_EMPTY,
              import_export => 1,
-             device_status => undef, f_type => undef, label => undef },
+             device_status => undef, device_error => undef,
+             f_type => undef, label => undef },
            { slot => 3, state => Amanda::Changer::SLOT_FULL,
              barcode => 'PTAG00XX', reserved => 1, loaded_in => 0,
              current => 1,
-             device_status => undef, f_type => undef, label => undef },
+             device_status => $DEVICE_STATUS_VOLUME_UNLABELED,
+             device_error => 'no tape label found',
+             f_type => $Amanda::Header::F_EMPTY, label => undef },
            { slot => 4, state => Amanda::Changer::SLOT_FULL,
              barcode => 'PTAG01XX', reserved => 1, loaded_in => 1,
-             device_status => undef, f_type => undef, label => undef },
+             device_status => $DEVICE_STATUS_VOLUME_UNLABELED,
+             device_error => 'no tape label found',
+             f_type => $Amanda::Header::F_EMPTY, label => undef },
            { slot => 5, state => Amanda::Changer::SLOT_FULL,
              barcode => 'PTAG02XX',
-             device_status => undef, f_type => undef, label => undef },
+             device_status => undef, device_error => undef,
+             f_type => undef, label => undef },
        ], "$pfx: inventory is updated when slots are loaded");
     };
 
@@ -549,22 +565,25 @@ sub test_changer {
        check_inventory($chg, $mtx_config->{'barcodes'} > 0, $steps->{'check_state_after_release1'}, [
            { slot => 1, state => Amanda::Changer::SLOT_EMPTY,
              import_export => 1,
-             device_status => undef, f_type => undef, label => undef },
+             device_status => undef, device_error => undef,
+             f_type => undef, label => undef },
            { slot => 2, state => Amanda::Changer::SLOT_EMPTY,
              import_export => 1,
-             device_status => undef, f_type => undef, label => undef },
+             device_status => undef, device_error => undef,
+             f_type => undef, label => undef },
            { slot => 3, state => Amanda::Changer::SLOT_FULL,
              barcode => 'PTAG00XX', reserved => 1, loaded_in => 0,
              current => 1,
-             device_status => $DEVICE_STATUS_SUCCESS,
+             device_status => $DEVICE_STATUS_SUCCESS, device_error => undef,
              f_type => $Amanda::Header::F_TAPESTART, label => 'TAPE-1' },
            { slot => 4, state => Amanda::Changer::SLOT_FULL,
              barcode => 'PTAG01XX', loaded_in => 1,
-             device_status => $DEVICE_STATUS_SUCCESS,
+             device_status => $DEVICE_STATUS_SUCCESS, device_error => undef,
              f_type => $Amanda::Header::F_TAPESTART, label => 'TAPE-2' },
            { slot => 5, state => Amanda::Changer::SLOT_FULL,
              barcode => 'PTAG02XX',
-             device_status => undef, f_type => undef, label => undef },
+             device_status => undef, device_error => undef,
+             f_type => undef, label => undef },
        ], "$pfx: inventory is still up to date");
     };
 
@@ -647,22 +666,24 @@ sub test_changer {
        check_inventory($chg, $mtx_config->{'barcodes'} > 0, $steps->{'release2'}, [
            { slot => 1, state => Amanda::Changer::SLOT_EMPTY,
              import_export => 1,
-             device_status => undef, f_type => undef, label => undef },
+             device_status => undef, device_error => undef,
+             f_type => undef, label => undef },
            { slot => 2, state => Amanda::Changer::SLOT_EMPTY,
              import_export => 1,
-             device_status => undef, f_type => undef, label => undef },
+             device_status => undef, device_error => undef,
+             f_type => undef, label => undef },
            { slot => 3, state => Amanda::Changer::SLOT_FULL,
              barcode => 'PTAG00XX', reserved => 1, loaded_in => 0,
-             device_status => $DEVICE_STATUS_SUCCESS,
+             device_status => $DEVICE_STATUS_SUCCESS, device_error => undef,
              f_type => $Amanda::Header::F_TAPESTART, label => 'TAPE-1' },
            { slot => 4, state => Amanda::Changer::SLOT_FULL,
              barcode => 'PTAG01XX',
-             device_status => $DEVICE_STATUS_SUCCESS,
+             device_status => $DEVICE_STATUS_SUCCESS, device_error => undef,
              f_type => $Amanda::Header::F_TAPESTART, label => 'TAPE-2' },
            { slot => 5, state => Amanda::Changer::SLOT_FULL,
              barcode => 'PTAG02XX', reserved => 1, loaded_in => 1,
              current => 1,
-             device_status => $DEVICE_STATUS_SUCCESS,
+             device_status => $DEVICE_STATUS_SUCCESS, device_error => undef,
              f_type => $Amanda::Header::F_TAPESTART, label => 'TAPE-4' },
        ], "$pfx: inventory is up to date after more labelings");
     };