@@ -116,9 +116,11 @@ func (s *apiQuotaSuite) TestCreateQuotaValues(c *check.C) {
116
116
CPUs : []int {0 , 1 },
117
117
})
118
118
c .Check (quotaValues .Journal , check .DeepEquals , & client.QuotaJournalValues {
119
- Size : quantity .SizeMiB ,
120
- RateCount : 150 ,
121
- RatePeriod : time .Second ,
119
+ Size : quantity .SizeMiB ,
120
+ QuotaJournalRate : & client.QuotaJournalRate {
121
+ RateCount : 150 ,
122
+ RatePeriod : time .Second ,
123
+ },
122
124
})
123
125
}
124
126
@@ -259,6 +261,43 @@ func (s *apiQuotaSuite) TestPostEnsureQuotaCreateQuotaConflicts(c *check.C) {
259
261
c .Assert (createCalled , check .Equals , 2 )
260
262
}
261
263
264
+ func (s * apiQuotaSuite ) TestPostEnsureQuotaCreateJournalRateZeroHappy (c * check.C ) {
265
+ var createCalled int
266
+ r := daemon .MockServicestateCreateQuota (func (st * state.State , name string , parentName string , snaps []string , resourceLimits quota.Resources ) (* state.TaskSet , error ) {
267
+ createCalled ++
268
+ c .Check (name , check .Equals , "booze" )
269
+ c .Check (parentName , check .Equals , "foo" )
270
+ c .Check (snaps , check .DeepEquals , []string {"some-snap" })
271
+ c .Check (resourceLimits , check .DeepEquals , quota .NewResourcesBuilder ().WithJournalRate (0 , 0 ).Build ())
272
+ ts := state .NewTaskSet (st .NewTask ("foo-quota" , "..." ))
273
+ return ts , nil
274
+ })
275
+ defer r ()
276
+
277
+ data , err := json .Marshal (daemon.PostQuotaGroupData {
278
+ Action : "ensure" ,
279
+ GroupName : "booze" ,
280
+ Parent : "foo" ,
281
+ Snaps : []string {"some-snap" },
282
+ Constraints : client.QuotaValues {
283
+ Journal : & client.QuotaJournalValues {
284
+ QuotaJournalRate : & client.QuotaJournalRate {
285
+ RateCount : 0 ,
286
+ RatePeriod : 0 ,
287
+ },
288
+ },
289
+ },
290
+ })
291
+ c .Assert (err , check .IsNil )
292
+
293
+ req , err := http .NewRequest ("POST" , "/v2/quotas" , bytes .NewBuffer (data ))
294
+ c .Assert (err , check .IsNil )
295
+ rsp := s .asyncReq (c , req , nil )
296
+ c .Assert (rsp .Status , check .Equals , 202 )
297
+ c .Assert (createCalled , check .Equals , 1 )
298
+ c .Assert (s .ensureSoonCalled , check .Equals , 1 )
299
+ }
300
+
262
301
func (s * apiQuotaSuite ) TestPostEnsureQuotaUpdateCpuHappy (c * check.C ) {
263
302
st := s .d .Overlord ().State ()
264
303
st .Lock ()
@@ -677,6 +716,68 @@ func (s *apiQuotaSuite) TestListQuotas(c *check.C) {
677
716
c .Check (s .ensureSoonCalled , check .Equals , 0 )
678
717
}
679
718
719
+ func (s * apiQuotaSuite ) TestListJournalQuotas (c * check.C ) {
720
+ st := s .d .Overlord ().State ()
721
+ st .Lock ()
722
+ err := servicestatetest .MockQuotaInState (st , "foo" , "" , nil , quota .NewResourcesBuilder ().WithJournalSize (64 * quantity .SizeMiB ).Build ())
723
+ c .Assert (err , check .IsNil )
724
+ err = servicestatetest .MockQuotaInState (st , "bar" , "foo" , nil , quota .NewResourcesBuilder ().WithJournalRate (100 , time .Hour ).Build ())
725
+ c .Assert (err , check .IsNil )
726
+ err = servicestatetest .MockQuotaInState (st , "baz" , "foo" , nil , quota .NewResourcesBuilder ().WithJournalRate (0 , 0 ).Build ())
727
+ c .Assert (err , check .IsNil )
728
+ st .Unlock ()
729
+
730
+ calls := 0
731
+ r := daemon .MockGetQuotaUsage (func (grp * quota.Group ) (* client.QuotaValues , error ) {
732
+ calls ++
733
+ return & client.QuotaValues {}, nil
734
+ })
735
+ defer r ()
736
+ defer func () {
737
+ c .Assert (calls , check .Equals , 3 )
738
+ }()
739
+
740
+ req , err := http .NewRequest ("GET" , "/v2/quotas" , nil )
741
+ c .Assert (err , check .IsNil )
742
+ rsp := s .syncReq (c , req , nil )
743
+ c .Assert (rsp .Status , check .Equals , 200 )
744
+ c .Assert (rsp .Result , check .FitsTypeOf , []client.QuotaGroupResult {})
745
+ res := rsp .Result .([]client.QuotaGroupResult )
746
+ c .Check (res , check .DeepEquals , []client.QuotaGroupResult {
747
+ {
748
+ GroupName : "bar" ,
749
+ Parent : "foo" ,
750
+ Constraints : & client.QuotaValues {Journal : & client.QuotaJournalValues {
751
+ QuotaJournalRate : & client.QuotaJournalRate {
752
+ RateCount : 100 ,
753
+ RatePeriod : time .Hour ,
754
+ },
755
+ }},
756
+ Current : & client.QuotaValues {},
757
+ },
758
+ {
759
+ GroupName : "baz" ,
760
+ Parent : "foo" ,
761
+ Constraints : & client.QuotaValues {Journal : & client.QuotaJournalValues {
762
+ QuotaJournalRate : & client.QuotaJournalRate {
763
+ RateCount : 0 ,
764
+ RatePeriod : 0 ,
765
+ },
766
+ }},
767
+ Current : & client.QuotaValues {},
768
+ },
769
+ {
770
+ GroupName : "foo" ,
771
+ Subgroups : []string {"bar" , "baz" },
772
+ Constraints : & client.QuotaValues {Journal : & client.QuotaJournalValues {
773
+ Size : 64 * quantity .SizeMiB ,
774
+ }},
775
+ Current : & client.QuotaValues {},
776
+ },
777
+ })
778
+ c .Check (s .ensureSoonCalled , check .Equals , 0 )
779
+ }
780
+
680
781
func (s * apiQuotaSuite ) TestGetQuota (c * check.C ) {
681
782
st := s .d .Overlord ().State ()
682
783
st .Lock ()
0 commit comments