[BACK]Return to 53-network-add_su-ap-su.t CVS log [TXT][DIR] Up to [local] / trango / Net-Telnet-Trango / t

Annotation of trango/Net-Telnet-Trango/t/53-network-add_su-ap-su.t, Revision 1.4

1.1       andrew      1: #!perl -T
1.4     ! andrew      2: # $RedRiver: 53-network-add_su-ap-su.t,v 1.3 2007/02/06 20:42:40 andrew Exp $
1.1       andrew      3:
1.2       andrew      4: use Test::More tests => 17;
1.1       andrew      5: use File::Spec;
                      6:
                      7: BEGIN {
                      8:        use_ok( 'Net::Telnet::Trango' );
                      9: }
                     10:
1.4     ! andrew     11: diag("53: AP tests when adding an SU to an AP and the SU should associate");
1.1       andrew     12:
                     13: my $cfg_file = File::Spec->catfile('t', 'tests.cfg');
                     14: my ($cir, $mir) = (128, 256);
                     15:
                     16: SKIP: {
1.2       andrew     17:     my $skipped = 16;
1.1       andrew     18:     my %cfg;
                     19:     if (-e $cfg_file) {
                     20:         if (open my $fh, $cfg_file) {
                     21:             while (<$fh>) {
                     22:                 chomp;
                     23:                 my ($key, $value) = split /\t/, $_, 2;
                     24:                 $cfg{$key} = $value;
                     25:             }
                     26:             close $fh;
                     27:         }
                     28:     }
                     29:
                     30:     my $type = 'AP';
                     31:     my ($host, $pass, $su, $su_pass, $su_id, $su_mac);
                     32:
                     33:     if ($cfg{$type} && $cfg{$type} =~ /^(\d+\.\d+\.\d+.\d+)$/) {
                     34:         $host = $1;
                     35:     }
                     36:
                     37:     skip 'No valid ' . $type . ' in config file',        $skipped unless $host;
                     38:
                     39:     if ($cfg{$type . '_PASSWD'} && $cfg{$type . '_PASSWD'} =~ /^(.*)$/) {
                     40:         $pass = $1;
                     41:     }
                     42:
                     43:     skip 'No valid ' . $type . '_PASSWD in config file', $skipped unless $pass;
                     44:
                     45:     if ($cfg{SU_ID} && $cfg{SU_ID} =~ /^(\d+)$/) {
                     46:         $su_id= $1;
                     47:     }
                     48:
                     49:     skip 'No valid SU_ID in config file', $skipped unless $su_id;
                     50:
                     51:     if ($cfg{SU_MAC} && length $cfg{SU_MAC} >= 12 && $cfg{SU_MAC} =~ /^(.*)$/) {
                     52:         $su_mac = $1;
                     53:     }
                     54:
                     55:     skip 'No valid SU_MAC in config file', $skipped unless $su_mac;
                     56:
                     57:     $type = 'SU';
                     58:     if ($cfg{$type} && $cfg{$type} =~ /^(\d+\.\d+\.\d+.\d+)$/) {
                     59:         $su = $1;
                     60:     }
                     61:
1.3       andrew     62:     skip 'No valid SU in config file',        $skipped unless $su;
1.1       andrew     63:
                     64:     if ($cfg{$type . '_PASSWD'} && $cfg{$type . '_PASSWD'} =~ /^(.*)$/) {
                     65:         $su_pass = $1;
                     66:     }
                     67:
1.3       andrew     68:     skip 'No valid SU_PASSWD in config file', $skipped unless $su_pass;
1.1       andrew     69:
                     70:     my $t;
                     71:     ok($t = Net::Telnet::Trango->new(), "Instantiating object");
                     72:
                     73:     ok($t->open($host), "Opening connection to $host");
                     74:
                     75:     ok($t->is_connected, "connected");
                     76:
                     77:     ok($t->login($pass), "Logging in");
                     78:
                     79:     ok($t->logged_in, "logged in");
                     80:
                     81:     my $sudb;
                     82:     if ((!ok($sudb = $t->sudb_view, "Getting sudb"))
                     83:       && $t->last_error ) {
                     84:         diag('ERR: ' . $t->last_error);
                     85:     }
                     86:
                     87:     my $in_sudb = 0;
                     88:     foreach my $su (@{ $sudb }) {
                     89:         if ($su_id == $su->{suid}) {
                     90:             if (lc($su_mac) eq lc($su->{mac})) {
                     91:                 $in_sudb = 1;
                     92:             } else {
                     93:                 $in_sudb = -1;
                     94:                 diag("Incorrect mac for SUID $su_id");
                     95:                 diag("  Should be $su_mac");
                     96:                 diag("  Really is $su->{mac}");
                     97:             }
                     98:             last;
                     99:         }
                    100:     }
                    101:
                    102:     is($in_sudb, 1, "Correct SU is in SUDB");
                    103:
                    104:     my $opmode;
                    105:     ok($opmode = $t->opmode, "getting current opmode");
                    106:
                    107:     SKIP: {
                    108:         skip("already opmode ap", 1) if $opmode->{Opmode} eq 'ap';
                    109:
                    110:         if ((! ok($result = $t->opmode('ap y'), "Setting opmode ap y"))
                    111:             && $t->last_error ) {
                    112:             diag('ERR: ' . $t->last_error);
                    113:         }
                    114:     }
                    115:
                    116:     $opmode = {};
                    117:     if ((! ok($opmode = $t->opmode, "getting current opmode"))
                    118:         && $t->last_error) {
                    119:         diag('ERR: ' . $t->last_error);
                    120:     }
                    121:
                    122:     is($opmode->{Opmode}, 'ap', "current Opmode ap");
                    123:
                    124:     if (! ok($result = $t->save_ss, "Saving systemsetting")
                    125:         && $t->last_error ) {
                    126:         diag('ERR: ' . $t->last_error);
                    127:     }
                    128:
                    129:     my $sysinfo;
                    130:     if ((!ok($sysinfo = $t->sysinfo, "Getting sysinfo"))
                    131:       && $t->last_error ) {
                    132:         diag('ERR: ' . $t->last_error);
                    133:     }
                    134:
                    135:     # XXX This is probably the wrong way to do this, but it should work
                    136:     # XXX most of the time.
                    137:     my $su_subnet  = $sysinfo->{'Subnet Mask'};
                    138:     my $su_gateway = $sysinfo->{'Gateway'};
                    139:
                    140:     if ( (! ok($t->su_password($su_pass, $su_id), "set SU password"))
                    141:       && $t->last_error ) {
                    142:         diag('ERR: ' . $t->last_error);
                    143:     }
                    144:
                    145:     if ( (! ok($t->su_ipconfig($su_id, $su, $su_subnet, $su_gateway),
                    146:                 "set SU IP"))
                    147:       && $t->last_error ) {
                    148:         diag('ERR: ' . $t->last_error);
                    149:     }
                    150:
                    151:     ok($t->bye, "Goodbye");
1.3       andrew    152:
                    153:     if ($su && $su_pass) {
                    154:         diag("Waiting 30 seconds for SU to associate");
                    155:         sleep 30;
                    156:     }
                    157:
1.1       andrew    158: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>