Skip to content

Commit 08a3fd8

Browse files
committed
Change MinioAdmin to terminal commands, PEP8 fmt.
1 parent 09f5e46 commit 08a3fd8

File tree

3 files changed

+51
-49
lines changed

3 files changed

+51
-49
lines changed

LNX-docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ services:
3232
interval: 1s
3333
fakeservices.datajoint.io:
3434
<<: *net
35-
image: datajoint/nginx:v0.0.17
35+
image: datajoint/nginx:v0.0.18
3636
environment:
3737
- ADD_db_TYPE=DATABASE
3838
- ADD_db_ENDPOINT=db:3306

local-docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ services:
3434
interval: 1s
3535
fakeservices.datajoint.io:
3636
<<: *net
37-
image: datajoint/nginx:v0.0.17
37+
image: datajoint/nginx:v0.0.18
3838
environment:
3939
- ADD_db_TYPE=DATABASE
4040
- ADD_db_ENDPOINT=db:3306

tests/test_s3.py

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
from . import S3_CONN_INFO
22
from minio import Minio
3-
import minio
43
import json
54
import urllib3
65
import certifi
76
from nose.tools import assert_true, raises
87
from .schema_external import schema, SimpleRemote
98
from datajoint.errors import DataJointError
9+
import os
10+
1011

1112
class TestS3:
1213

@@ -31,7 +32,7 @@ def test_connection():
3132
http_client=http_client)
3233

3334
assert_true(minio_client.bucket_exists(S3_CONN_INFO['bucket']))
34-
35+
3536
@staticmethod
3637
def test_connection_secure():
3738

@@ -53,66 +54,64 @@ def test_connection_secure():
5354
http_client=http_client)
5455

5556
assert_true(minio_client.bucket_exists(S3_CONN_INFO['bucket']))
57+
5658
@staticmethod
5759
@raises(DataJointError)
5860
def test_remove_object_exception():
5961
# https://github.com/datajoint/datajoint-python/issues/952
60-
62+
6163
# Initialize minioClient with an endpoint and access/secret keys.
6264
minio_client = Minio(
6365
'minio:9000',
64-
access_key= 'jeffjeff',
65-
secret_key= 'jeffjeff',
66+
access_key='jeffjeff',
67+
secret_key='jeffjeff',
6668
secure=False)
6769

68-
minio_admin = minio.MinioAdmin(target = 'myminio')
69-
7070
# 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')
7372
# json for test policy for permissionless user
7473
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+
]
102103
}
103-
]
104-
}
105104

106105
# Write test json to tmp directory so we can use it to create a new user policy
107106
with open('/tmp/policy.json', 'w') as f:
108107
f.write(json.dumps(testpolicy))
109-
108+
110109
# 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')
113112

114113
# 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]]
116115
SimpleRemote.insert1(test)
117116
SimpleRemote.delete()
118117

@@ -121,14 +120,17 @@ def test_remove_object_exception():
121120

122121
# Apply our new minio client to the external table that has permissions restrictions
123122
schema.external['share'].s3.client = minio_client
124-
123+
125124
# 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)
127126

128127
# 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')
131133
schema.external['share'].s3.client = old_client
132134

133135
# Raise the error we want
134-
raise error_list[0][2]
136+
raise error_list[0][2]

0 commit comments

Comments
 (0)