Changeset 1179
- Timestamp:
- 05/22/08 00:38:26 (6 months ago)
- Files:
-
- trunk/server-plugins/MogileFS-Network/lib/MogileFS/Network.pm (modified) (3 diffs)
- trunk/server-plugins/MogileFS-Network/lib/MogileFS/ReplicationPolicy/HostsPerNetwork.pm (modified) (1 diff)
- trunk/server-plugins/MogileFS-Network/t/hosts-per-zone-replpol.t (modified) (1 diff)
- trunk/server-plugins/MogileFS-Network/t/network_zones.t (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/server-plugins/MogileFS-Network/lib/MogileFS/Network.pm
r1178 r1179 32 32 $trie = Net::Patricia->new(); 33 33 34 my @zones = split(/\s*,\s*/, MogileFS::Config->server_setting("network_zones"));34 my @zones = split(/\s*,\s*/, get_setting("network_zones")); 35 35 36 36 my @netmasks; # [ $bits, $netmask, $zone ], ... 37 37 38 38 foreach my $zone (@zones) { 39 my $zone_masks = MogileFS::Config->server_setting("zone_$zone"); 39 my $zone_masks = get_setting("zone_$zone"); 40 41 if (not $zone_masks) { 42 warn "couldn't find network_zone <<zone_$zone>> check your server settings"; 43 next; 44 } 40 45 41 46 foreach my $network_string (split /[,\s]+/, $zone_masks) { 42 if (not $network_string) {43 warn "couldn't find network_zone <<zone_$zone>> check your server settings";44 next;45 }46 47 #if ($cache{$zone}) {48 # warn "duplicate netmask <$netmask> in network zones. check your server settings";49 #}50 51 #$cache{$zone} = Net::Netmask->new2($netmask);52 47 my $netmask = Net::Netmask->new2($network_string); 53 48 … … 62 57 } 63 58 59 # Sort these by mask bit count, because Net::Patricia doesn't say in its docs whether add order 60 # or bit length is the overriding factor. 64 61 foreach my $set (sort { $a->[0] <=> $b->[0] } @netmasks) { 65 62 my ($bits, $netmask, $zone) = @$set; 63 64 if (my $other_zone = $trie->match_exact_string("$netmask")) { 65 warn "duplicate netmask <$netmask> in network zones '$zone' and '$other_zone'. check your server settings"; 66 } 66 67 67 68 $trie->add_string("$netmask", $zone); 68 69 } 69 70 70 my $interval = MogileFS::Config->server_setting("network_reload_interval") 71 || DEFAULT_RELOAD_INTERVAL; 72 73 clear_and_build_cache(); 71 my $interval = get_setting("network_reload_interval") || DEFAULT_RELOAD_INTERVAL; 74 72 75 73 $next_reload = time() + $interval; … … 78 76 } 79 77 80 sub stuff_cache { # for testing, or it'll try the db 81 my ($self, $zone, $netmask) = @_; 78 # This is a seperate subroutine so I can redefine it at test time. 79 sub get_setting { 80 my $key = shift; 81 return MogileFS::Config->server_setting($key); 82 } 82 83 83 $trie->add_string("$netmask", $zone); 84 $next_reload = time() + 120; # If the test takes more than two minutes we're gonna break 84 sub test_config { 85 my $class = shift; 86 87 my %config = @_; 88 89 no warnings 'redefine'; 90 91 *get_setting = sub { 92 my $key = shift; 93 return $config{$key}; 94 }; 95 96 $next_reload = 0; 85 97 } 86 98 trunk/server-plugins/MogileFS-Network/lib/MogileFS/ReplicationPolicy/HostsPerNetwork.pm
r1162 r1179 2 2 3 3 use strict; 4 use warnings; 5 4 6 use base 'MogileFS::ReplicationPolicy'; 5 7 trunk/server-plugins/MogileFS-Network/t/hosts-per-zone-replpol.t
r1170 r1179 114 114 my $polclass = "MogileFS::ReplicationPolicy::HostsPerNetwork"; 115 115 116 my $pol = $polclass->new(hosts_per_zone => { zone_one => $min });116 my $pol = $polclass->new(hosts_per_zone => { one => $min }); 117 117 118 MogileFS::Network->stuff_cache(zone_one => Net::Netmask->new('127.0.0.0/16')); 118 MogileFS::Network->test_config( 119 zone_one => '127.0.0.0/16', 120 network_zones => 'one', 121 ); 122 119 123 my $rr = $pol->replicate_to( 120 124 fid => 1, trunk/server-plugins/MogileFS-Network/t/network_zones.t
r1178 r1179 3 3 use strict; 4 4 use warnings; 5 use Test::More tests => 4;5 use Test::More tests => 5; 6 6 use FindBin qw($Bin); 7 7 8 8 use MogileFS::Network; 9 9 10 set(zone_one => '127.0.0.0/16'); 11 set(zone_two => '10.0.0.0/8'); 12 set(zone_three => '10.1.0.0/16'); 10 MogileFS::Network->test_config( 11 zone_one => '127.0.0.0/16', 12 zone_two => '10.0.0.0/8, 172.16.0.0/16', 13 zone_three => '10.1.0.0/16', 14 network_zones => 'one, two, three', 15 ); 13 16 14 is(lookup('127.0.0.1'), 'zone_one', "Standard match"); 15 is(lookup('10.0.0.1'), 'zone_two', "Outer netblock match"); 16 is(lookup('10.1.0.1'), 'zone_three', "Inner netblock match"); 17 18 is(lookup('127.0.0.1'), 'one', "Standard match"); 19 is(lookup('10.0.0.1'), 'two', "Outer netblock match"); 20 is(lookup('10.1.0.1'), 'three', "Inner netblock match"); 21 is(lookup('172.16.0.1'), 'two', "Zone with multiple netblocks"); 17 22 is(lookup('192.168.0.1'), undef, "Unknown zone"); 18 23 … … 20 25 return MogileFS::Network->zone_for_ip(@_); 21 26 } 22 23 sub set {24 MogileFS::Network->stuff_cache(@_);25 }
