1
1
from . import S3_CONN_INFO
2
2
from minio import Minio
3
- import minio
4
3
import json
5
4
import urllib3
6
5
import certifi
7
6
from nose .tools import assert_true , raises
8
7
from .schema_external import schema , SimpleRemote
9
8
from datajoint .errors import DataJointError
9
+ import os
10
+
10
11
11
12
class TestS3 :
12
13
@@ -31,7 +32,7 @@ def test_connection():
31
32
http_client = http_client )
32
33
33
34
assert_true (minio_client .bucket_exists (S3_CONN_INFO ['bucket' ]))
34
-
35
+
35
36
@staticmethod
36
37
def test_connection_secure ():
37
38
@@ -53,66 +54,64 @@ def test_connection_secure():
53
54
http_client = http_client )
54
55
55
56
assert_true (minio_client .bucket_exists (S3_CONN_INFO ['bucket' ]))
57
+
56
58
@staticmethod
57
59
@raises (DataJointError )
58
60
def test_remove_object_exception ():
59
61
# https://github.com/datajoint/datajoint-python/issues/952
60
-
62
+
61
63
# Initialize minioClient with an endpoint and access/secret keys.
62
64
minio_client = Minio (
63
65
'minio:9000' ,
64
- access_key = 'jeffjeff' ,
65
- secret_key = 'jeffjeff' ,
66
+ access_key = 'jeffjeff' ,
67
+ secret_key = 'jeffjeff' ,
66
68
secure = False )
67
69
68
- minio_admin = minio .MinioAdmin (target = 'myminio' )
69
-
70
70
# Create new user
71
- minio_admin .user_add (access_key = 'jeffjeff' , secret_key = 'jeffjeff' )
72
-
71
+ os .system ('mc admin user add myminio jeffjeff jeffjeff' )
73
72
# json for test policy for permissionless user
74
73
testpolicy = {
75
- "Version" : "2012-10-17" ,
76
- "Statement" : [
77
- {
78
- "Action" : [
79
- "s3:GetBucketLocation" ,
80
- "s3:ListBucket" ,
81
- "s3:ListBucketMultipartUploads" ,
82
- "s3:ListAllMyBuckets"
83
- ],
84
- "Effect" : "Allow" ,
85
- "Resource" : [
86
- "arn:aws:s3:::datajoint.test" ,
87
- "arn:aws:s3:::datajoint.migrate"
88
- ],
89
- "Sid" : ""
90
- },
91
- {
92
- "Action" : [
93
- "s3:GetObject" ,
94
- "s3:ListMultipartUploadParts"
95
- ],
96
- "Effect" : "Allow" ,
97
- "Resource" : [
98
- "arn:aws:s3:::datajoint.test/*" ,
99
- "arn:aws:s3:::datajoint.migrate/*"
100
- ],
101
- "Sid" : ""
74
+ "Version" : "2012-10-17" ,
75
+ "Statement" : [
76
+ {
77
+ "Action" : [
78
+ "s3:GetBucketLocation" ,
79
+ "s3:ListBucket" ,
80
+ "s3:ListBucketMultipartUploads" ,
81
+ "s3:ListAllMyBuckets"
82
+ ],
83
+ "Effect" : "Allow" ,
84
+ "Resource" : [
85
+ "arn:aws:s3:::datajoint.test" ,
86
+ "arn:aws:s3:::datajoint.migrate"
87
+ ],
88
+ "Sid" : ""
89
+ },
90
+ {
91
+ "Action" : [
92
+ "s3:GetObject" ,
93
+ "s3:ListMultipartUploadParts"
94
+ ],
95
+ "Effect" : "Allow" ,
96
+ "Resource" : [
97
+ "arn:aws:s3:::datajoint.test/*" ,
98
+ "arn:aws:s3:::datajoint.migrate/*"
99
+ ],
100
+ "Sid" : ""
101
+ }
102
+ ]
102
103
}
103
- ]
104
- }
105
104
106
105
# Write test json to tmp directory so we can use it to create a new user policy
107
106
with open ('/tmp/policy.json' , 'w' ) as f :
108
107
f .write (json .dumps (testpolicy ))
109
-
108
+
110
109
# Add the policy and apply it to the user
111
- minio_admin . policy_add ( policy_name = 'test' , policy_file = ' /tmp/policy.json' )
112
- minio_admin . policy_set ( policy_name = ' test' , user = ' jeffjeff' )
110
+ os . system ( 'mc admin policy add myminio test /tmp/policy.json' )
111
+ os . system ( 'mc admin policy set myminio test user= jeffjeff' )
113
112
114
113
# Insert some test data and remove it so that the external table is populated
115
- test = [1 ,[1 ,2 , 3 ]]
114
+ test = [1 , [1 , 2 , 3 ]]
116
115
SimpleRemote .insert1 (test )
117
116
SimpleRemote .delete ()
118
117
@@ -121,14 +120,17 @@ def test_remove_object_exception():
121
120
122
121
# Apply our new minio client to the external table that has permissions restrictions
123
122
schema .external ['share' ].s3 .client = minio_client
124
-
123
+
125
124
# This method returns a list of errors
126
- error_list = schema .external ['share' ].delete (delete_external_files = True , errors_as_string = False )
125
+ error_list = schema .external ['share' ].delete (delete_external_files = True , errors_as_string = False )
127
126
128
127
# Teardown
129
- minio_admin .user_remove (access_key = 'jeffjeff' )
130
- minio_admin .policy_remove ('test' )
128
+ os .system ('mc admin policy remove myminio test' )
129
+ os .system ('mc admin user remove myminio jeffjeff' )
130
+
131
+ # minio_admin.user_remove(access_key = 'jeffjeff')
132
+ # minio_admin.policy_remove('test')
131
133
schema .external ['share' ].s3 .client = old_client
132
134
133
135
# Raise the error we want
134
- raise error_list [0 ][2 ]
136
+ raise error_list [0 ][2 ]
0 commit comments