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