1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+ #
18
+ import os
19
+
20
+ import nuvolaris.config as cfg
21
+ import nuvolaris.minio_deploy as minio
22
+ import nuvolaris.minio_util as mutil
23
+ import nuvolaris.testutil as tu
24
+ import nuvolaris.util as util
25
+ import json
26
+
27
+ tu.run_proc("kubectl -n nuvolaris delete all --all")
28
+ tu.run_proc("kubectl -n nuvolaris delete pvc --all")
29
+
30
+ # test
31
+ assert(cfg.configure(tu.load_sample_config()))
32
+ assert(cfg.detect_storage()["nuvolaris.storageclass"])
33
+
34
+ os.environ['MINIO_API_HOST']='localhost'
35
+ assert(minio.create())
36
+
37
+ pod_name = util.get_pod_name("{.items[?(@.metadata.labels.app == 'minio')].metadata.name}")
38
+ assert(pod_name)
39
+
40
+ minioClient = mutil.MinioClient()
41
+ assert(minioClient.make_bucket("ftt-data"))
42
+ assert(minioClient.make_public_bucket("ftt-web"))
43
+ assert(minioClient.add_user("ftt","jgfkjsgcasgfjgdsafgsdkfgkaj"))
44
+ assert(minioClient.assign_rw_bucket_policy_to_user("ftt",["ftt-web/*","ftt-data/*"]))
45
+
46
+ assert(minioClient.assign_quota_to_bucket("ftt-data",10))
47
+
48
+ # upload 7M
49
+ tu.run_proc(f"dd if=/dev/urandom of=/tmp/__minio_test_file1 bs=1M count=7")
50
+ minioClient.mc("cp", f"/tmp/__minio_test_file1", f"local_ftt/ftt-data/file1")
51
+ os.remove(f"/tmp/__minio_test_file1")
52
+
53
+ # check quota is 7M
54
+ assert(minioClient.mc("du", "local/ftt-data", "--json"))
55
+ last_output = minioClient.get_last_output()
56
+ quota_info = json.loads(last_output)
57
+ size = quota_info.get('size', 0)
58
+ assert(size == 7340032)
59
+
60
+
61
+ tu.run_proc(f"dd if=/dev/urandom of=/tmp/__minio_test_file2 bs=1M count=15")
62
+ res = minioClient.mc("cp", f"/tmp/__minio_test_file2", f"local_ftt/ftt-data/file2")
63
+ assert (res is False)
64
+ last_output = minioClient.get_last_output()
65
+ os.remove(f"/tmp/__minio_test_file2")
66
+ assert(last_output.index("Bucket quota exceeded") >= 0)
67
+
68
+
69
+ assert(minio.delete())
0 commit comments