]>
git.proxmox.com Git - pve-storage.git/blob - test/run_bwlimit_tests.pl
10 use PVE
:: RPCEnvironment
;
14 my $datacenter_cfg = <<'EOF';
15 bwlimit: default=100,move=80,restore=60
18 my $storage_cfg = <<'EOF';
28 bwlimit default=50,move=40,restore=30
32 bwlimit default=20,move=40,restore=30
36 bwlimit default=200,move=400,restore=300
54 'user2 @test ' => { '/' => [ 'Sys.Modify' ], },
55 'user3 @test ' => { '/storage' => [ 'Datastore.Allocate' ], },
56 'user4 @test ' => { '/storage/d20m40r30' => [ 'Datastore.Allocate' ], },
59 my $pve_cluster_module ;
60 $pve_cluster_module = Test
:: MockModule-
> new ( 'PVE::Cluster' );
61 $pve_cluster_module -> mock (
65 if ( $file eq 'datacenter.cfg' ) {
66 return $datacenter_cfg ;
67 } elsif ( $file eq 'storage.cfg' ) {
70 die "TODO: mock get_config( $file ) \n " ;
75 $rpcenv_module = Test
:: MockModule-
> new ( 'PVE::RPCEnvironment' );
78 my ( $env, $user, $path, $perms, $noerr ) = @_ ;
79 return 1 if $user eq 'root @pam ' ;
80 my $userperms = $permissions ->{ $user }
81 or die "no permissions defined for user $user\n " ;
82 if ( defined ( my $pathperms = $userperms ->{ $path })) {
83 foreach my $pp ( @$pathperms ) {
84 foreach my $reqp ( @$perms ) {
85 return 1 if $pp eq $reqp ;
89 die "permission denied \n " if ! $noerr ;
94 my $rpcenv = PVE
:: RPCEnvironment-
> init ( 'pub' );
97 [ user
=> 'root @pam ' ],
98 [ [ 'unknown' , [ 'nolimit' ], undef ], undef , 'root / generic default limit' ],
99 [ [ 'move' , [ 'nolimit' ], undef ], undef , 'root / specific default limit (move)' ],
100 [ [ 'restore' , [ 'nolimit' ], undef ], undef , 'root / specific default limit (restore)' ],
101 [ [ 'unknown' , [ 'd50m40r30' ], undef ], undef , 'root / storage default limit' ],
102 [ [ 'move' , [ 'd50m40r30' ], undef ], undef , 'root / specific storage limit (move)' ],
103 [ [ 'restore' , [ 'd50m40r30' ], undef ], undef , 'root / specific storage limit (restore)' ],
105 [ user
=> 'user1 @test ' ],
106 [ [ 'unknown' , [ 'nolimit' ], undef ], 100 , 'generic default limit' ],
107 [ [ 'move' , [ 'nolimit' ], undef ], 80 , 'specific default limit (move)' ],
108 [ [ 'restore' , [ 'nolimit' ], undef ], 60 , 'specific default limit (restore)' ],
109 [ [ 'unknown' , [ 'd50m40r30' ], undef ], 50 , 'storage default limit' ],
110 [ [ 'move' , [ 'd50m40r30' ], undef ], 40 , 'specific storage limit (move)' ],
111 [ [ 'restore' , [ 'd50m40r30' ], undef ], 30 , 'specific storage limit (restore)' ],
112 [ [ 'unknown' , [ 'd200m400r300' ], undef ], 200 , 'storage default limit above datacenter limits' ],
113 [ [ 'move' , [ 'd200m400r300' ], undef ], 400 , 'specific storage limit above datacenter limits (move)' ],
114 [ [ 'restore' , [ 'd200m400r300' ], undef ], 300 , 'specific storage limit above datacenter limits (restore)' ],
115 [ [ 'unknown' , [ 'd50' ], undef ], 50 , 'storage default limit' ],
116 [ [ 'move' , [ 'd50' ], undef ], 50 , 'storage default limit (move)' ],
117 [ [ 'restore' , [ 'd50' ], undef ], 50 , 'storage default limit (restore)' ],
119 [ user
=> 'user2 @test ' ],
120 [ [ 'unknown' , [ 'nolimit' ], 0 ], 0 , 'generic default limit with Sys.Modify, passing unlimited' ],
121 [ [ 'unknown' , [ 'nolimit' ], undef ], undef , 'generic default limit with Sys.Modify' ],
122 [ [ 'restore' , [ 'nolimit' ], undef ], undef , 'specific default limit with Sys.Modify (restore)' ],
123 [ [ 'move' , [ 'nolimit' ], undef ], undef , 'specific default limit with Sys.Modify (move)' ],
124 [ [ 'unknown' , [ 'd50m40r30' ], undef ], 50 , 'storage default limit with Sys.Modify' ],
125 [ [ 'move' , [ 'd50m40r30' ], undef ], 40 , 'specific storage limit with Sys.Modify (move)' ],
126 [ [ 'restore' , [ 'd50m40r30' ], undef ], 30 , 'specific storage limit with Sys.Modify (restore)' ],
128 [ user
=> 'user3 @test ' ],
129 [ [ 'unknown' , [ 'nolimit' ], 80 ], 80 , 'generic default limit with privileges on /, passing an override value' ],
130 [ [ 'unknown' , [ 'nolimit' ], 0 ], 0 , 'generic default limit with privileges on /, passing unlimited' ],
131 [ [ 'unknown' , [ 'nolimit' ], undef ], undef , 'generic default limit with privileges on /' ],
132 [ [ 'move' , [ 'nolimit' ], undef ], undef , 'specific default limit with privileges on / (move)' ],
133 [ [ 'restore' , [ 'nolimit' ], undef ], undef , 'specific default limit with privileges on / (restore)' ],
134 [ [ 'unknown' , [ 'd50m20r20' ], 0 ], 0 , 'storage default limit with privileges on /, passing unlimited' ],
135 [ [ 'unknown' , [ 'd50m20r20' ], undef ], undef , 'storage default limit with privileges on /' ],
136 [ [ 'move' , [ 'd50m20r20' ], undef ], undef , 'specific storage limit with privileges on / (move)' ],
137 [ [ 'restore' , [ 'd50m20r20' ], undef ], undef , 'specific storage limit with privileges on / (restore)' ],
139 [ user
=> 'user4 @test ' ],
140 [ [ 'unknown' , [ 'nolimit' ], 10 ], 10 , 'generic default limit with privileges on a different storage, passing lower override' ],
141 [ [ 'unknown' , [ 'nolimit' ], undef ], 100 , 'generic default limit with privileges on a different storage' ],
142 [ [ 'unknown' , [ 'nolimit' ], 0 ], 100 , 'generic default limit with privileges on a different storage, passing unlimited' ],
143 [ [ 'move' , [ 'nolimit' ], undef ], 80 , 'specific default limit with privileges on a different storage (move)' ],
144 [ [ 'restore' , [ 'nolimit' ], undef ], 60 , 'specific default limit with privileges on a different storage (restore)' ],
145 [ [ 'unknown' , [ 'd50m40r30' ], undef ], 50 , 'storage default limit with privileges on a different storage' ],
146 [ [ 'move' , [ 'd50m40r30' ], undef ], 40 , 'specific storage limit with privileges on a different storage (move)' ],
147 [ [ 'restore' , [ 'd50m40r30' ], undef ], 30 , 'specific storage limit with privileges on a different storage (restore)' ],
148 [ [ 'unknown' , [ 'd20m40r30' ], undef ], undef , 'storage default limit with privileges on that storage' ],
149 [ [ 'unknown' , [ 'd20m40r30' ], 0 ], 0 , 'storage default limit with privileges on that storage, passing unlimited' ],
150 [ [ 'move' , [ 'd20m40r30' ], undef ], undef , 'specific storage limit with privileges on that storage (move)' ],
151 [ [ 'restore' , [ 'd20m40r30' ], undef ], undef , 'specific storage limit with privileges on that storage (restore)' ],
152 [ [ 'unknown' , [ 'd50m40r30' , 'd20m40r30' ], undef ], 50 , 'multiple storages default limit with privileges on one of them' ],
153 [ [ 'move' , [ 'd50m40r30' , 'd20m40r30' ], undef ], 40 , 'multiple storages specific limit with privileges on one of them (move)' ],
154 [ [ 'restore' , [ 'd50m40r30' , 'd20m40r30' ], undef ], 30 , 'multiple storages specific limit with privileges on one of them (restore)' ],
155 [ [ 'unknown' , [ 'd10' , 'd20m40r30' ], undef ], 10 , 'multiple storages default limit with privileges on one of them (storage limited)' ],
156 [ [ 'move' , [ 'd10' , 'd20m40r30' ], undef ], 10 , 'multiple storages specific limit with privileges on one of them (storage limited) (move)' ],
157 [ [ 'restore' , [ 'd10' , 'd20m40r30' ], undef ], 10 , 'multiple storages specific limit with privileges on one of them (storage limited) (restore)' ],
158 [ [ 'restore' , [ 'd10' , 'd20m40r30' ], 5 ], 5 , 'multiple storages specific limit (storage limited) (restore), passing lower override' ],
159 [ [ 'restore' , [ 'd200' , 'd200m400r300' ], 65 ], 65 , 'multiple storages specific limit (storage limited) (restore), passing lower override' ],
160 [ [ 'restore' , [ 'd200' , 'd200m400r300' ], 400 ], 200 , 'multiple storages specific limit (storage limited) (restore), passing higher override' ],
161 [ [ 'restore' , [ 'd200' , 'd200m400r300' ], 0 ], 200 , 'multiple storages specific limit (storage limited) (restore), passing unlimited' ],
162 [ [ 'restore' , [ 'd200' , 'd200m400r300' ], 1 ], 1 , 'multiple storages specific limit (storage limited) (restore), passing 1' ],
163 [ [ 'restore' , [ 'd10' , 'd20m40r30' ], 500 ], 10 , 'multiple storages specific limit with privileges on one of them (storage limited) (restore), passing higher override' ],
164 [ [ 'unknown' , [ 'nolimit' , 'd20m40r30' ], undef ], 100 , 'multiple storages default limit with privileges on one of them (default limited)' ],
165 [ [ 'move' , [ 'nolimit' , 'd20m40r30' ], undef ], 80 , 'multiple storages specific limit with privileges on one of them (default limited) (move)' ],
166 [ [ 'restore' , [ 'nolimit' , 'd20m40r30' ], undef ], 60 , 'multiple storages specific limit with privileges on one of them (default limited) (restore)' ],
167 [ [ 'restore' , [ 'd20m40r30' , 'm50' ], 200 ], 60 , 'multiple storages specific limit with privileges on one of them (default limited) (restore)' ],
170 foreach my $t ( @tests ) {
171 my ( $args, $expected, $description ) = @$t ;
173 if ( $args eq 'user' ) {
174 $rpcenv -> set_user ( $expected );
176 die "not a test specification \n " ;
180 is ( PVE
:: Storage
:: get_bandwidth_limit
( @$args ), $expected, $description );