]>
git.proxmox.com Git - ceph.git/blob - ceph/qa/workunits/rgw/common.py
235c36c9521f88d3bef0cb22d7a2a64ccf2ce48a
7 import botocore
. exceptions
9 log
. basicConfig ( format
= ' %(message)s ' , level
= log
. DEBUG
)
10 log
. getLogger ( 'botocore' ). setLevel ( log
. CRITICAL
)
11 log
. getLogger ( 'boto3' ). setLevel ( log
. CRITICAL
)
12 log
. getLogger ( 'urllib3' ). setLevel ( log
. CRITICAL
)
14 def exec_cmd ( cmd
, wait
= True , ** kwargs
):
15 check_retcode
= kwargs
. pop ( 'check_retcode' , True )
16 kwargs
[ 'shell' ] = True
17 kwargs
[ 'stdout' ] = subprocess
. PIPE
18 proc
= subprocess
. Popen ( cmd
, ** kwargs
)
21 out
, _
= proc
. communicate ()
23 assert ( proc
. returncode
== 0 )
25 return ( out
, proc
. returncode
)
28 def create_user ( uid
, display_name
, access_key
, secret_key
):
29 _
, ret
= exec_cmd ( f
'radosgw-admin user create --uid {uid} --display-name " {display_name} " --access-key {access_key} --secret {secret_key} ' , check_retcode
= False )
30 assert ( ret
== 0 or errno
. EEXIST
)
32 def boto_connect ( access_key
, secret_key
, config
= None ):
33 def try_connect ( portnum
, ssl
, proto
):
34 endpoint
= proto
+ '://localhost:' + portnum
35 conn
= boto3
. resource ( 's3' ,
36 aws_access_key_id
= access_key
,
37 aws_secret_access_key
= secret_key
,
39 endpoint_url
= endpoint
,
44 list ( conn
. buckets
. limit ( 1 )) # just verify we can list buckets
45 except botocore
. exceptions
. ConnectionError
as e
:
48 print ( 'connected to' , endpoint
)
51 return try_connect ( '80' , False , 'http' )
52 except botocore
. exceptions
. ConnectionError
:
53 try : # retry on non-privileged http port
54 return try_connect ( '8000' , False , 'http' )
55 except botocore
. exceptions
. ConnectionError
:
57 return try_connect ( '443' , True , 'https' )