]>
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 ], 100 , 'root / generic default limit, requesting default' ],
99 [ [ 'move' , [ 'nolimit' ], undef ], 80 , 'root / specific default limit, requesting default (move)' ],
100 [ [ 'restore' , [ 'nolimit' ], undef ], 60 , 'root / specific default limit, requesting default (restore)' ],
101 [ [ 'unknown' , [ 'd50m40r30' ], undef ], 50 , 'root / storage default limit' ],
102 [ [ 'move' , [ 'd50m40r30' ], undef ], 40 , 'root / specific storage limit (move)' ],
103 [ [ 'restore' , [ 'd50m40r30' ], undef ], 30 , 'root / specific storage limit (restore)' ],
104 [ [ 'unknown' , [ 'nolimit' ], 0 ], 0 , 'root / generic default limit' ],
105 [ [ 'move' , [ 'nolimit' ], 0 ], 0 , 'root / specific default limit (move)' ],
106 [ [ 'restore' , [ 'nolimit' ], 0 ], 0 , 'root / specific default limit (restore)' ],
107 [ [ 'unknown' , [ 'd50m40r30' ], 0 ], 0 , 'root / storage default limit' ],
108 [ [ 'move' , [ 'd50m40r30' ], 0 ], 0 , 'root / specific storage limit (move)' ],
109 [ [ 'restore' , [ 'd50m40r30' ], 0 ], 0 , 'root / specific storage limit (restore)' ],
111 [ user
=> 'user1 @test ' ],
112 [ [ 'unknown' , [ 'nolimit' ], undef ], 100 , 'generic default limit' ],
113 [ [ 'move' , [ 'nolimit' ], undef ], 80 , 'specific default limit (move)' ],
114 [ [ 'restore' , [ 'nolimit' ], undef ], 60 , 'specific default limit (restore)' ],
115 [ [ 'unknown' , [ 'd50m40r30' ], undef ], 50 , 'storage default limit' ],
116 [ [ 'move' , [ 'd50m40r30' ], undef ], 40 , 'specific storage limit (move)' ],
117 [ [ 'restore' , [ 'd50m40r30' ], undef ], 30 , 'specific storage limit (restore)' ],
118 [ [ 'unknown' , [ 'd200m400r300' ], undef ], 200 , 'storage default limit above datacenter limits' ],
119 [ [ 'move' , [ 'd200m400r300' ], undef ], 400 , 'specific storage limit above datacenter limits (move)' ],
120 [ [ 'restore' , [ 'd200m400r300' ], undef ], 300 , 'specific storage limit above datacenter limits (restore)' ],
121 [ [ 'unknown' , [ 'd50' ], undef ], 50 , 'storage default limit' ],
122 [ [ 'move' , [ 'd50' ], undef ], 50 , 'storage default limit (move)' ],
123 [ [ 'restore' , [ 'd50' ], undef ], 50 , 'storage default limit (restore)' ],
125 [ user
=> 'user2 @test ' ],
126 [ [ 'unknown' , [ 'nolimit' ], 0 ], 0 , 'generic default limit with Sys.Modify, passing unlimited' ],
127 [ [ 'unknown' , [ 'nolimit' ], undef ], 100 , 'generic default limit with Sys.Modify' ],
128 [ [ 'move' , [ 'nolimit' ], undef ], 80 , 'specific default limit with Sys.Modify (move)' ],
129 [ [ 'restore' , [ 'nolimit' ], undef ], 60 , 'specific default limit with Sys.Modify (restore)' ],
130 [ [ 'restore' , [ 'nolimit' ], 0 ], 0 , 'specific default limit with Sys.Modify, passing unlimited (restore)' ],
131 [ [ 'move' , [ 'nolimit' ], 0 ], 0 , 'specific default limit with Sys.Modify, passing unlimited (move)' ],
132 [ [ 'unknown' , [ 'd50m40r30' ], undef ], 50 , 'storage default limit with Sys.Modify' ],
133 [ [ 'restore' , [ 'd50m40r30' ], undef ], 30 , 'specific storage limit with Sys.Modify (restore)' ],
134 [ [ 'move' , [ 'd50m40r30' ], undef ], 40 , 'specific storage limit with Sys.Modify (move)' ],
136 [ user
=> 'user3 @test ' ],
137 [ [ 'unknown' , [ 'nolimit' ], undef ], 100 , 'generic default limit with privileges on /' ],
138 [ [ 'unknown' , [ 'nolimit' ], 80 ], 80 , 'generic default limit with privileges on /, passing an override value' ],
139 [ [ 'unknown' , [ 'nolimit' ], 0 ], 0 , 'generic default limit with privileges on /, passing unlimited' ],
140 [ [ 'move' , [ 'nolimit' ], undef ], 80 , 'specific default limit with privileges on / (move)' ],
141 [ [ 'move' , [ 'nolimit' ], 0 ], 0 , 'specific default limit with privileges on /, passing unlimited (move)' ],
142 [ [ 'restore' , [ 'nolimit' ], undef ], 60 , 'specific default limit with privileges on / (restore)' ],
143 [ [ 'restore' , [ 'nolimit' ], 0 ], 0 , 'specific default limit with privileges on /, passing unlimited (restore)' ],
144 [ [ 'unknown' , [ 'd50m40r30' ], 0 ], 0 , 'storage default limit with privileges on /, passing unlimited' ],
145 [ [ 'unknown' , [ 'd50m40r30' ], undef ], 50 , 'storage default limit with privileges on /' ],
146 [ [ 'unknown' , [ 'd50m40r30' ], 0 ], 0 , 'storage default limit with privileges on, passing unlimited /' ],
147 [ [ 'move' , [ 'd50m40r30' ], undef ], 40 , 'specific storage limit with privileges on / (move)' ],
148 [ [ 'move' , [ 'd50m40r30' ], 0 ], 0 , 'specific storage limit with privileges on, passing unlimited / (move)' ],
149 [ [ 'restore' , [ 'd50m40r30' ], undef ], 30 , 'specific storage limit with privileges on / (restore)' ],
150 [ [ 'restore' , [ 'd50m40r30' ], 0 ], 0 , 'specific storage limit with privileges on /, passing unlimited (restore)' ],
152 [ user
=> 'user4 @test ' ],
153 [ [ 'unknown' , [ 'nolimit' ], 10 ], 10 , 'generic default limit with privileges on a different storage, passing lower override' ],
154 [ [ 'unknown' , [ 'nolimit' ], undef ], 100 , 'generic default limit with privileges on a different storage' ],
155 [ [ 'unknown' , [ 'nolimit' ], 0 ], 100 , 'generic default limit with privileges on a different storage, passing unlimited' ],
156 [ [ 'move' , [ 'nolimit' ], undef ], 80 , 'specific default limit with privileges on a different storage (move)' ],
157 [ [ 'restore' , [ 'nolimit' ], undef ], 60 , 'specific default limit with privileges on a different storage (restore)' ],
158 [ [ 'unknown' , [ 'd50m40r30' ], undef ], 50 , 'storage default limit with privileges on a different storage' ],
159 [ [ 'move' , [ 'd50m40r30' ], undef ], 40 , 'specific storage limit with privileges on a different storage (move)' ],
160 [ [ 'restore' , [ 'd50m40r30' ], undef ], 30 , 'specific storage limit with privileges on a different storage (restore)' ],
161 [ [ 'unknown' , [ 'd20m40r30' ], undef ], 20 , 'storage default limit with privileges on that storage' ],
162 [ [ 'unknown' , [ 'd20m40r30' ], 0 ], 0 , 'storage default limit with privileges on that storage, passing unlimited' ],
163 [ [ 'move' , [ 'd20m40r30' ], undef ], 40 , 'specific storage limit with privileges on that storage (move)' ],
164 [ [ 'move' , [ 'd20m40r30' ], 0 ], 0 , 'specific storage limit with privileges on that storage, passing unlimited (move)' ],
165 [ [ 'move' , [ 'd20m40r30' ], 10 ], 10 , 'specific storage limit with privileges on that storage, passing low override (move)' ],
166 [ [ 'move' , [ 'd20m40r30' ], 300 ], 300 , 'specific storage limit with privileges on that storage, passing high override (move)' ],
167 [ [ 'restore' , [ 'd20m40r30' ], undef ], 30 , 'specific storage limit with privileges on that storage (restore)' ],
168 [ [ 'restore' , [ 'd20m40r30' ], 0 ], 0 , 'specific storage limit with privileges on that storage, passing unlimited (restore)' ],
169 [ [ 'unknown' , [ 'd50m40r30' , 'd20m40r30' ], 0 ], 50 , 'multiple storages default limit with privileges on one of them, passing unlimited' ],
170 [ [ 'move' , [ 'd50m40r30' , 'd20m40r30' ], 0 ], 40 , 'multiple storages specific limit with privileges on one of them, passing unlimited (move)' ],
171 [ [ 'restore' , [ 'd50m40r30' , 'd20m40r30' ], 0 ], 30 , 'multiple storages specific limit with privileges on one of them, passing unlimited (restore)' ],
172 [ [ 'unknown' , [ 'd50m40r30' , 'd20m40r30' ], undef ], 20 , 'multiple storages default limit with privileges on one of them' ],
173 [ [ 'unknown' , [ 'd10' , 'd20m40r30' ], undef ], 10 , 'multiple storages default limit with privileges on one of them (storage limited)' ],
174 [ [ 'move' , [ 'd10' , 'd20m40r30' ], undef ], 10 , 'multiple storages specific limit with privileges on one of them (storage limited) (move)' ],
175 [ [ 'restore' , [ 'd10' , 'd20m40r30' ], undef ], 10 , 'multiple storages specific limit with privileges on one of them (storage limited) (restore)' ],
176 [ [ 'restore' , [ 'd10' , 'd20m40r30' ], 5 ], 5 , 'multiple storages specific limit (storage limited) (restore), passing lower override' ],
177 [ [ 'restore' , [ 'd200' , 'd200m400r300' ], 65 ], 65 , 'multiple storages specific limit (storage limited) (restore), passing lower override' ],
178 [ [ 'restore' , [ 'd200' , 'd200m400r300' ], 400 ], 200 , 'multiple storages specific limit (storage limited) (restore), passing higher override' ],
179 [ [ 'restore' , [ 'd200' , 'd200m400r300' ], 0 ], 200 , 'multiple storages specific limit (storage limited) (restore), passing unlimited' ],
180 [ [ 'restore' , [ 'd200' , 'd200m400r300' ], 1 ], 1 , 'multiple storages specific limit (storage limited) (restore), passing 1' ],
181 [ [ 'restore' , [ 'd10' , 'd20m40r30' ], 500 ], 10 , 'multiple storages specific limit with privileges on one of them (storage limited) (restore), passing higher override' ],
182 [ [ 'unknown' , [ 'nolimit' , 'd20m40r30' ], 0 ], 100 , 'multiple storages default limit with privileges on one of them, passing unlimited (default limited)' ],
183 [ [ 'move' , [ 'nolimit' , 'd20m40r30' ], 0 ], 80 , 'multiple storages specific limit with privileges on one of them, passing unlimited (default limited) (move)' ],
184 [ [ 'restore' , [ 'nolimit' , 'd20m40r30' ], 0 ], 60 , 'multiple storages specific limit with privileges on one of them, passing unlimited (default limited) (restore)' ],
185 [ [ 'unknown' , [ 'nolimit' , 'd20m40r30' ], undef ], 20 , 'multiple storages default limit with privileges on one of them (default limited)' ],
186 [ [ 'move' , [ 'nolimit' , 'd20m40r30' ], undef ], 40 , 'multiple storages specific limit with privileges on one of them (default limited) (move)' ],
187 [ [ 'restore' , [ 'nolimit' , 'd20m40r30' ], undef ], 30 , 'multiple storages specific limit with privileges on one of them (default limited) (restore)' ],
188 [ [ 'restore' , [ 'd20m40r30' , 'm50' ], 200 ], 60 , 'multiple storages specific limit with privileges on one of them (global default limited) (restore)' ],
191 foreach my $t ( @tests ) {
192 my ( $args, $expected, $description ) = @$t ;
194 if ( $args eq 'user' ) {
195 $rpcenv -> set_user ( $expected );
197 die "not a test specification \n " ;
201 is ( PVE
:: Storage
:: get_bandwidth_limit
( @$args ), $expected, $description );