中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

lifecycle功能測試方法是什么

發布時間:2021-12-30 16:38:46 來源:億速云 閱讀:128 作者:iii 欄目:云計算

本篇內容主要講解“lifecycle功能測試方法是什么”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“lifecycle功能測試方法是什么”吧!

lifecycle功能測試

功能描述:
1.目前從k版本開始支持lifecycle,且僅支持Expired,既過期對象刪除。
2.AWS4認證下無法進行lifecycle的修改操作,HTTP層面會出現501錯誤。
3.boto和boto3可以支持AWS2認證下的get和put操作,測試功能可用。
4.測試發現先對bucket進行get_lifecycle操作,如果返回404,則對應的response的內容不完整,之后的一次request請求中的response會被污染。

get_bucket_lifecycle 測試用例
boto3用例
import boto3
from botocore.client import Config

aws_access_key_id = ''
aws_secret_access_key = ''
bucket_name = 'test1'

# aws4
s3 = boto3.client('s3', region_name='CN',
                  use_ssl=False,
                  endpoint_url='http://ceph.work',
                  aws_access_key_id=aws_access_key_id,
                  aws_secret_access_key=aws_secret_access_key,
                  config=Config(signature_version='s3v4',
                                s3={'addressing_style': 'virtual'}))

# aws2
s3 = boto3.client('s3', region_name=None,
                  use_ssl=False,
                  endpoint_url='http://ceph.work',
                  aws_access_key_id=aws_access_key_id,
                  aws_secret_access_key=aws_secret_access_key,
                  config=Config(s3={'addressing_style': 'virtual'}))


print s3.get_bucket_lifecycle(Bucket=bucket_name)
print s3.get_bucket_lifecycle_configuration(Bucket=bucket_name)
boto用例
from boto.s3.connection import S3Connection
import boto

# import os
# os.environ['S3_USE_SIGV4'] = 'True' #use aws4


access_key = ''
secret_key = ''
host = 'ceph.work'
bucket_name = 'test1'

conn = boto.connect_s3(
    aws_access_key_id=access_key,
    aws_secret_access_key=secret_key,
    host=host,
    is_secure=False,
    calling_format=boto.s3.connection.SubdomainCallingFormat(),
    validate_certs=True,
)

bucket = conn.get_bucket(bucket_name)
config = bucket.get_lifecycle_config()
for i in config:
    print i.endElement
    print i.expiration
    print i.id
    print i.startElement
    print i.to_xml()
put_bucket_lifecycle 測試用例
boto3用例
import boto3
from botocore.client import Config
import datetime

aws_access_key_id = ''
aws_secret_access_key = ''
bucket_name = 'test1'

#aws2 可用
s3 = boto3.client('s3', region_name=None,
                  use_ssl=False,
                  endpoint_url='http://ceph.work',
                  aws_access_key_id=aws_access_key_id,
                  aws_secret_access_key=aws_secret_access_key,
                  config=Config(s3={'addressing_style': 'virtual'}))


#aws4 錯誤,返回501
s3 = boto3.client('s3', region_name='CN',
                  use_ssl=False,
                  endpoint_url='http://ceph.work',
                  aws_access_key_id=aws_access_key_id,
                  aws_secret_access_key=aws_secret_access_key,
                  config=Config(signature_version='s3v4',
                                s3={'addressing_style': 'virtual'}))

print s3.put_bucket_lifecycle(
    Bucket=bucket_name,
    LifecycleConfiguration={
        'Rules': [
            {
                'Expiration': {
                    'Date': datetime.datetime(2015, 3, 15),
                    'Days': 123,
                    'ExpiredObjectDeleteMarker': True|False
                },
                'ID': 'demo1',
                'Prefix': '/abc',
                'Status': 'Enabled',
                'Transition': {
                    'Date': datetime.datetime(2017, 3, 15),
                    'Days': 123,
                    'StorageClass': 'STANDARD_IA'
                },
                'NoncurrentVersionTransition': {
                    'NoncurrentDays': 123,
                    'StorageClass': 'STANDARD_IA'
                },
                'NoncurrentVersionExpiration': {
                    'NoncurrentDays': 123
                },
                'AbortIncompleteMultipartUpload': {
                    'DaysAfterInitiation': 123
                }
            },
        ]
    }
)

501錯誤提示,應該是官方還沒完成該部分特性。

<?xml version="1.0" encoding="UTF-8"?><Error><Code>NotImplemented</Code><RequestId>tx000000000000000000056-0058d0d70b-10b2-default</RequestId><HostId>10b2-default-default</HostId></Error>
boto用例
from boto.s3.connection import S3Connection
import boto
import boto.s3.lifecycle
import os
# os.environ['S3_USE_SIGV4'] = 'True' #use aws4

from boto.s3.lifecycle import (
    Lifecycle,
    Expiration,
)

access_key = ''
secret_key = ''
host = 'ceph.work'
bucket_name = 'test1'

conn = boto.connect_s3(
    aws_access_key_id=access_key,
    aws_secret_access_key=secret_key,
    host=host,
    is_secure=False,
    calling_format=boto.s3.connection.SubdomainCallingFormat(),
    validate_certs=True,
)
bucket = conn.get_bucket(bucket_name)

#type 1
lifecycle_config = boto.s3.lifecycle.Lifecycle()
lifecycle_config.add_rule('lc_rule_1', 'del/', 'Enabled', 1)
lifecycle_config.add_rule('lc_rule_2', '/abc', 'Enabled', 10)
bucket.configure_lifecycle(lifecycle_config)


#type 2
lifecycle = Lifecycle()
lifecycle.add_rule('lc_rule_1', prefix='del/', status='Enable', expiration=Expiration(days=1))
lifecycle.add_rule('lc_rule_2', prefix='data/', status='Enabled', expiration=Expiration(days=10))
bucket.configure_lifecycle(lifecycle)

get_bucket_lifecycled的bug

from boto.s3.connection import S3Connection
import boto

access_key = ''
secret_key = ''
host = 'ceph.work'
bucket_name = 'test1'

conn = boto.connect_s3(
    aws_access_key_id=access_key,
    aws_secret_access_key=secret_key,
    host=host,
    is_secure=False,
    calling_format=boto.s3.connection.SubdomainCallingFormat(),
    validate_certs=True,
)

bucket = conn.get_bucket(bucket_name)
print bucket.get_lifecycle_config() #未設置bucket的lifecycle,返回404,報以下錯誤

錯誤提示

Traceback (most recent call last):
  File "/Users/Diluga/SourceCode/PycharmProjects/kv_server/boto_demo/demo1.py", line 56, in <module>
    print bucket.get_lifecycle_config()
  File "/Users/Diluga/lwc/lib/python2.7/site-packages/boto/s3/bucket.py", line 1387, in get_lifecycle_config
    response.status, response.reason, body)
boto.exception.S3ResponseError: S3ResponseError: 404 Not Found
<?xml version="1.0" encoding="UTF-8"?><Error><Code>NoSuchLifecycleConfiguration</Code><BucketName>snappy-test</BucketName><RequestId>tx00000000000000000008f-0058d0dc3b-10b2-default</RequestId><HostId>10b2-default-default</HostId></Error>
#xml未結束,下一個request請求所返回的response會被污染

s3cmd同樣報錯

DEBUG: signature-v4 headers: {'x-amz-content-sha256': 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 'Authorization': 'AWS4-HMAC-SHA256 Credential=W7L3YC842AGADI1T8BV9/20170321/CN/s3/aws4_request,SignedHeaders=host;x-amz-content-sha256;x-amz-date,Signature=d0a6ca337af207d00d170f5bb999782f49928b01395494c96d3dd31f88d987c7', 'x-amz-date': '20170321T075840Z'}
DEBUG: Processing request, please wait...
DEBUG: get_hostname(snappy-test): snappy-test.ceph.work
DEBUG: ConnMan.get(): re-using connection: http://snappy-test.ceph.work#2
DEBUG: format_uri(): /?lifecycle
DEBUG: Sending request method_string='GET', uri='/?lifecycle', headers={'x-amz-content-sha256': 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 'Authorization': 'AWS4-HMAC-SHA256 Credential=W7L3YC842AGADI1T8BV9/20170321/CN/s3/aws4_request,SignedHeaders=host;x-amz-content-sha256;x-amz-date,Signature=d0a6ca337af207d00d170f5bb999782f49928b01395494c96d3dd31f88d987c7', 'x-amz-date': '20170321T075840Z'}, body=(0 bytes)
DEBUG: Response: {'status': 404, 'headers': {'date': 'Tue, 21 Mar 2017 07:58:40 GMT', 'content-length': '237', 'x-amz-request-id': 'tx000000000000000000092-0058d0dd30-10b2-default', 'content-type': 'application/xml', 'accept-ranges': 'bytes'}, 'reason': 'Not Found', 'data': '<?xml version="1.0" encoding="UTF-8"?><Error><Code>NoSuchLifecycleConfiguration</Code><BucketName>snappy-test</BucketName><RequestId>tx000000000000000000092-0058d0dd30-10b2-default</RequestId><HostId>10b2-default-default</HostId></Error>'}
DEBUG: ConnMan.put(): connection put back to pool (http://snappy-test.ceph.work#3)
DEBUG: S3Error: 404 (Not Found)
DEBUG: HttpHeader: date: Tue, 21 Mar 2017 07:58:40 GMT
DEBUG: HttpHeader: content-length: 237
DEBUG: HttpHeader: x-amz-request-id: tx000000000000000000092-0058d0dd30-10b2-default
DEBUG: HttpHeader: content-type: application/xml
DEBUG: HttpHeader: accept-ranges: bytes
DEBUG: ErrorXML: Code: 'NoSuchLifecycleConfiguration'
DEBUG: ErrorXML: BucketName: 'snappy-test'
DEBUG: ErrorXML: RequestId: 'tx000000000000000000092-0058d0dd30-10b2-default'
DEBUG: ErrorXML: HostId: '10b2-default-default'
DEBUG: Could not get /?lifecycle - lifecycle probably not configured for this bucket
   Expiration Rule: none
DEBUG: CreateRequest: resource[uri]=/?acl
DEBUG: Using signature v4
DEBUG: get_hostname(snappy-test): snappy-test.ceph.work
DEBUG: canonical_headers = host:snappy-test.ceph.work
x-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
x-amz-date:20170321T075840Z

DEBUG: Canonical Request:
GET
/
acl=
host:snappy-test.ceph.work
x-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
x-amz-date:20170321T075840Z

host;x-amz-content-sha256;x-amz-date
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
----------------------
DEBUG: signature-v4 headers: {'x-amz-content-sha256': 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 'Authorization': 'AWS4-HMAC-SHA256 Credential=W7L3YC842AGADI1T8BV9/20170321/CN/s3/aws4_request,SignedHeaders=host;x-amz-content-sha256;x-amz-date,Signature=03386b844b8600b0cdd28d38d8a6e528fa75385cab056771f9148266905a33dd', 'x-amz-date': '20170321T075840Z'}
DEBUG: Processing request, please wait...
DEBUG: get_hostname(snappy-test): snappy-test.ceph.work
DEBUG: ConnMan.get(): re-using connection: http://snappy-test.ceph.work#3
DEBUG: format_uri(): /?acl
DEBUG: Sending request method_string='GET', uri='/?acl', headers={'x-amz-content-sha256': 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 'Authorization': 'AWS4-HMAC-SHA256 Credential=W7L3YC842AGADI1T8BV9/20170321/CN/s3/aws4_request,SignedHeaders=host;x-amz-content-sha256;x-amz-date,Signature=03386b844b8600b0cdd28d38d8a6e528fa75385cab056771f9148266905a33dd', 'x-amz-date': '20170321T075840Z'}, body=(0 bytes)
DEBUG: Response: {'status': 200, 'headers': {}, 'reason': '', 'data': '<LifecycleConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"></LifecycleConfiguration>HTTP/1.1 200 OK\r\nx-amz-request-id: tx000000000000000000093-0058d0dd30-10b2-default\r\nContent-Type: application/xml\r\nContent-Length: 441\r\nDate: Tue, 21 Mar 2017 07:58:40 GMT\r\n\r\n<?xml version="1.0" encoding="UTF-8"?><AccessControlPolicy xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Owner><ID>u-gfn2636</ID><DisplayName>u-gfn2636</DisplayName></Owner><AccessControlList><Grant><Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser"><ID>u-gfn2636</ID><DisplayName>u-gfn2636</DisplayName></Grantee><Permission>FULL_CONTROL</Permission></Grant></AccessControlList></AccessControlPolicy>'}
DEBUG: ConnMan.put(): connection put back to pool (http://snappy-test.ceph.work#4)
ERROR: Error parsing xml: not well-formed (invalid token): line 1, column 101
ERROR: <LifecycleConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"></LifecycleConfiguration>HTTP/1.1 200 OK
x-amz-request-id: tx000000000000000000093-0058d0dd30-10b2-default
Content-Type: application/xml
Content-Length: 441
Date: Tue, 21 Mar 2017 07:58:40 GMT

<?xml version="1.0" encoding="UTF-8"?><AccessControlPolicy xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Owner><ID>u-gfn2636</ID><DisplayName>u-gfn2636</DisplayName></Owner><AccessControlList><Grant><Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser"><ID>u-gfn2636</ID><DisplayName>u-gfn2636</DisplayName></Grantee><Permission>FULL_CONTROL</Permission></Grant></AccessControlList></AccessControlPolicy>

到此,相信大家對“lifecycle功能測試方法是什么”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

威远县| 资讯| 偃师市| 江津市| 根河市| 绥棱县| 和平县| 确山县| 偃师市| 舟山市| 宜黄县| 平湖市| 遵化市| 天水市| 乐至县| 泽州县| 沐川县| 万全县| 灌阳县| 太仆寺旗| 常德市| 霍州市| 久治县| 黎川县| 昭苏县| 陈巴尔虎旗| 镇雄县| 石泉县| 新营市| 循化| 家居| 平湖市| 长治县| 芮城县| 西和县| 侯马市| 聂荣县| 安阳县| 海门市| 五家渠市| 阳朔县|