#NEWLINE# @ skip_if_disabled #NEWLINE# def test_get_head_simple_post( self ) : #NEWLINE# #INDENT# '\n        We test the following sequential series of actions:\n\n        0. GET /images\n        - Verify no public images\n        1. GET /images/detail\n        - Verify no public images\n        2. POST /images with public image named Image1\n        and no custom properties\n        - Verify 201 returned\n        3. HEAD image\n        - Verify HTTP headers have correct information we just added\n        4. GET image\n        - Verify all information on image we just added is correct\n        5. GET /images\n        - Verify the image we just added is returned\n        6. GET /images/detail\n        - Verify the image we just added is returned\n        7. PUT image with custom properties of "distro" and "arch"\n        - Verify 200 returned\n        8. GET image\n        - Verify updated information about image was stored\n        9. PUT image\n        - Remove a previously existing property.\n        10. PUT image\n        - Add a previously deleted property.\n        ' #NEWLINE# self . cleanup ( ) #NEWLINE# self . start_servers ( ** self . __dict__ . copy ( ) ) #NEWLINE# path = ( 'https://%s:%d/v1/images' % ( '0.0.0.0' , self . api_port ) ) #NEWLINE# https = httplib2 . Http ( disable_ssl_certificate_validation = True ) #NEWLINE# ( response , content ) = https . request ( path , 'GET' ) #NEWLINE# self . assertEqual ( response . status , 200 ) #NEWLINE# self . assertEqual ( content , '{"images": []}' ) #NEWLINE# path = ( 'https://%s:%d/v1/images/detail' % ( '0.0.0.0' , self . api_port ) ) #NEWLINE# https = httplib2 . Http ( disable_ssl_certificate_validation = True ) #NEWLINE# ( response , content ) = https . request ( path , 'GET' ) #NEWLINE# self . assertEqual ( response . status , 200 ) #NEWLINE# self . assertEqual ( content , '{"images": []}' ) #NEWLINE# image_data = ( '*' * FIVE_KB ) #NEWLINE# headers = { #NEWLINE# #INDENT# 'Content-Type' : 'application/octet-stream' , #NEWLINE# 'X-Image-Meta-Name' : 'Image1' , #NEWLINE# 'X-Image-Meta-Is-Public' : 'True' , #NEWLINE# #UNINDENT# } #NEWLINE# path = ( 'https://%s:%d/v1/images' % ( '0.0.0.0' , self . api_port ) ) #NEWLINE# https = httplib2 . Http ( disable_ssl_certificate_validation = True ) #NEWLINE# ( response , content ) = https . request ( path , 'POST' , headers = headers , body = image_data ) #NEWLINE# self . assertEqual ( response . status , 201 ) #NEWLINE# data = json . loads ( content ) #NEWLINE# self . assertEqual ( data [ 'image' ] [ 'checksum' ] , hashlib . md5 ( image_data ) . hexdigest ( ) ) #NEWLINE# self . assertEqual ( data [ 'image' ] [ 'size' ] , FIVE_KB ) #NEWLINE# self . assertEqual ( data [ 'image' ] [ 'name' ] , 'Image1' ) #NEWLINE# self . assertEqual ( data [ 'image' ] [ 'is_public' ] , True ) #NEWLINE# image_id = data [ 'image' ] [ 'id' ] #NEWLINE# path = ( 'https://%s:%d/v1/images/%s' % ( '0.0.0.0' , self . api_port , image_id ) ) #NEWLINE# https = httplib2 . Http ( disable_ssl_certificate_validation = True ) #NEWLINE# ( response , content ) = https . request ( path , 'HEAD' ) #NEWLINE# self . assertEqual ( response . status , 200 ) #NEWLINE# self . assertEqual ( response [ 'x-image-meta-name' ] , 'Image1' ) #NEWLINE# path = ( 'https://%s:%d/v1/images/%s' % ( '0.0.0.0' , self . api_port , image_id ) ) #NEWLINE# https = httplib2 . Http ( disable_ssl_certificate_validation = True ) #NEWLINE# ( response , content ) = https . request ( path , 'GET' ) #NEWLINE# self . assertEqual ( response . status , 200 ) #NEWLINE# expected_image_headers = { #NEWLINE# #INDENT# 'x-image-meta-id' : image_id , #NEWLINE# 'x-image-meta-name' : 'Image1' , #NEWLINE# 'x-image-meta-is_public' : 'True' , #NEWLINE# 'x-image-meta-status' : 'active' , #NEWLINE# 'x-image-meta-disk_format' : '' , #NEWLINE# 'x-image-meta-container_format' : '' , #NEWLINE# 'x-image-meta-size' : str ( FIVE_KB ) , #NEWLINE# #UNINDENT# } #NEWLINE# expected_std_headers = { #NEWLINE# #INDENT# 'content-length' : str ( FIVE_KB ) , #NEWLINE# 'content-type' : 'application/octet-stream' , #NEWLINE# #UNINDENT# } #NEWLINE# for ( expected_key , expected_value ) in expected_image_headers . items ( ) : #NEWLINE# #INDENT# self . assertEqual ( response [ expected_key ] , expected_value , ( "For key '%s' expected header value '%s'. Got '%s'" % ( expected_key , expected_value , response [ expected_key ] ) ) ) #NEWLINE# #UNINDENT# for ( expected_key , expected_value ) in expected_std_headers . items ( ) : #NEWLINE# #INDENT# self . assertEqual ( response [ expected_key ] , expected_value , ( "For key '%s' expected header value '%s'. Got '%s'" % ( expected_key , expected_value , response [ expected_key ] ) ) ) #NEWLINE# #UNINDENT# self . assertEqual ( content , ( '*' * FIVE_KB ) ) #NEWLINE# self . assertEqual ( hashlib . md5 ( content ) . hexdigest ( ) , hashlib . md5 ( ( '*' * FIVE_KB ) ) . hexdigest ( ) ) #NEWLINE# path = ( 'https://%s:%d/v1/images' % ( '0.0.0.0' , self . api_port ) ) #NEWLINE# https = httplib2 . Http ( disable_ssl_certificate_validation = True ) #NEWLINE# ( response , content ) = https . request ( path , 'GET' ) #NEWLINE# self . assertEqual ( response . status , 200 ) #NEWLINE# expected_result = { #NEWLINE# #INDENT# 'images' : [ { #NEWLINE# #INDENT# 'container_format' : None , #NEWLINE# 'disk_format' : None , #NEWLINE# 'id' : image_id , #NEWLINE# 'name' : 'Image1' , #NEWLINE# 'checksum' : 'c2e5db72bd7fd153f53ede5da5a06de3' , #NEWLINE# 'size' : 5120 , #NEWLINE# #UNINDENT# } ] , #NEWLINE# #UNINDENT# } #NEWLINE# self . assertEqual ( json . loads ( content ) , expected_result ) #NEWLINE# path = ( 'https://%s:%d/v1/images/detail' % ( '0.0.0.0' , self . api_port ) ) #NEWLINE# https = httplib2 . Http ( disable_ssl_certificate_validation = True ) #NEWLINE# ( response , content ) = https . request ( path , 'GET' ) #NEWLINE# self . assertEqual ( response . status , 200 ) #NEWLINE# expected_image = { #NEWLINE# #INDENT# 'status' : 'active' , #NEWLINE# 'name' : 'Image1' , #NEWLINE# 'deleted' : False , #NEWLINE# 'container_format' : None , #NEWLINE# 'disk_format' : None , #NEWLINE# 'id' : image_id , #NEWLINE# 'is_public' : True , #NEWLINE# 'deleted_at' : None , #NEWLINE# 'properties' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# 'size' : 5120 , #NEWLINE# #UNINDENT# } #NEWLINE# image = json . loads ( content ) #NEWLINE# for ( expected_key , expected_value ) in expected_image . items ( ) : #NEWLINE# #INDENT# self . assertEqual ( expected_value , image [ 'images' ] [ 0 ] [ expected_key ] , ( "For key '%s' expected header value '%s'. Got '%s'" % ( expected_key , expected_value , image [ 'images' ] [ 0 ] [ expected_key ] ) ) ) #NEWLINE# #UNINDENT# headers = { #NEWLINE# #INDENT# 'X-Image-Meta-Property-Distro' : 'Ubuntu' , #NEWLINE# 'X-Image-Meta-Property-Arch' : 'x86_64' , #NEWLINE# #UNINDENT# } #NEWLINE# path = ( 'https://%s:%d/v1/images/%s' % ( '0.0.0.0' , self . api_port , image_id ) ) #NEWLINE# https = httplib2 . Http ( disable_ssl_certificate_validation = True ) #NEWLINE# ( response , content ) = https . request ( path , 'PUT' , headers = headers ) #NEWLINE# self . assertEqual ( response . status , 200 ) #NEWLINE# data = json . loads ( content ) #NEWLINE# self . assertEqual ( data [ 'image' ] [ 'properties' ] [ 'arch' ] , 'x86_64' ) #NEWLINE# self . assertEqual ( data [ 'image' ] [ 'properties' ] [ 'distro' ] , 'Ubuntu' ) #NEWLINE# path = ( 'https://%s:%d/v1/images/detail' % ( '0.0.0.0' , self . api_port ) ) #NEWLINE# https = httplib2 . Http ( disable_ssl_certificate_validation = True ) #NEWLINE# ( response , content ) = https . request ( path , 'GET' ) #NEWLINE# self . assertEqual ( response . status , 200 ) #NEWLINE# expected_image = { #NEWLINE# #INDENT# 'status' : 'active' , #NEWLINE# 'name' : 'Image1' , #NEWLINE# 'deleted' : False , #NEWLINE# 'container_format' : None , #NEWLINE# 'disk_format' : None , #NEWLINE# 'id' : image_id , #NEWLINE# 'is_public' : True , #NEWLINE# 'deleted_at' : None , #NEWLINE# 'properties' : { #NEWLINE# #INDENT# 'distro' : 'Ubuntu' , #NEWLINE# 'arch' : 'x86_64' , #NEWLINE# #UNINDENT# } , #NEWLINE# 'size' : 5120 , #NEWLINE# #UNINDENT# } #NEWLINE# image = json . loads ( content ) #NEWLINE# for ( expected_key , expected_value ) in expected_image . items ( ) : #NEWLINE# #INDENT# self . assertEqual ( expected_value , image [ 'images' ] [ 0 ] [ expected_key ] , ( "For key '%s' expected header value '%s'. Got '%s'" % ( expected_key , expected_value , image [ 'images' ] [ 0 ] [ expected_key ] ) ) ) #NEWLINE# #UNINDENT# headers = { #NEWLINE# #INDENT# 'X-Image-Meta-Property-Arch' : 'x86_64' , #NEWLINE# #UNINDENT# } #NEWLINE# path = ( 'https://%s:%d/v1/images/%s' % ( '0.0.0.0' , self . api_port , image_id ) ) #NEWLINE# https = httplib2 . Http ( disable_ssl_certificate_validation = True ) #NEWLINE# ( response , content ) = https . request ( path , 'PUT' , headers = headers ) #NEWLINE# self . assertEqual ( response . status , 200 ) #NEWLINE# path = ( 'https://%s:%d/v1/images/detail' % ( '0.0.0.0' , self . api_port ) ) #NEWLINE# ( response , content ) = https . request ( path , 'GET' ) #NEWLINE# self . assertEqual ( https . status , 200 ) #NEWLINE# data = json . loads ( content ) [ 'images' ] [ 0 ] #NEWLINE# self . assertEqual ( len ( data [ 'properties' ] ) , 1 ) #NEWLINE# self . assertEqual ( data [ 'properties' ] [ 'arch' ] , 'x86_64' ) #NEWLINE# headers = { #NEWLINE# #INDENT# 'X-Image-Meta-Property-Distro' : 'Ubuntu' , #NEWLINE# 'X-Image-Meta-Property-Arch' : 'x86_64' , #NEWLINE# #UNINDENT# } #NEWLINE# path = ( 'https://%s:%d/v1/images/%s' % ( '0.0.0.0' , self . api_port , image_id ) ) #NEWLINE# https = httplib2 . Http ( disable_ssl_certificate_validation = True ) #NEWLINE# ( response , content ) = https . request ( path , 'PUT' , headers = headers ) #NEWLINE# self . assertEqual ( response . status , 200 ) #NEWLINE# data = json . loads ( content ) #NEWLINE# path = ( 'https://%s:%d/v1/images/detail' % ( '0.0.0.0' , self . api_port ) ) #NEWLINE# ( response , content ) = https . request ( path , 'GET' ) #NEWLINE# self . assertEqual ( response . status , 200 ) #NEWLINE# data = json . loads ( content ) [ 'images' ] [ 0 ] #NEWLINE# self . assertEqual ( len ( data [ 'properties' ] ) , 2 ) #NEWLINE# self . assertEqual ( data [ 'properties' ] [ 'arch' ] , 'x86_64' ) #NEWLINE# self . assertEqual ( data [ 'properties' ] [ 'distro' ] , 'Ubuntu' ) #NEWLINE# self . stop_servers ( )