<s> """<STR_LIT>""" <EOL> from cloudcafe . common . tools . datagen import rand_name <EOL> from cloudcafe . glance . common . constants import Messages <EOL> from cloudcafe . glance . common . types import ImageMemberStatus , ImageType <EOL> from cloudroast . glance . fixtures import ImagesIntegrationFixture <EOL> class ImageSharing ( ImagesIntegrationFixture ) : <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> super ( ImageSharing , cls ) . setUpClass ( ) <EOL> cls . alt_one_member_id = cls . images_alt_one . auth . tenant_id <EOL> cls . alt_two_member_id = cls . images_alt_two . auth . tenant_id <EOL> created_images = cls . images . behaviors . create_images_via_task ( <EOL> image_properties = { '<STR_LIT:name>' : rand_name ( '<STR_LIT>' ) } , count = <NUM_LIT:6> ) <EOL> cls . single_member_image = created_images . pop ( ) <EOL> cls . multiple_members_image = created_images . pop ( ) <EOL> cls . delete_access_image = created_images . pop ( ) <EOL> cls . images . client . create_image_member ( <EOL> cls . delete_access_image . id_ , cls . alt_one_member_id ) <EOL> cls . shared_image = created_images . pop ( ) <EOL> cls . images . client . create_image_member ( <EOL> cls . shared_image . id_ , cls . alt_one_member_id ) <EOL> cls . images_alt_one . client . update_image_member ( <EOL> cls . shared_image . id_ , cls . alt_one_member_id , <EOL> ImageMemberStatus . ACCEPTED ) <EOL> image = created_images . pop ( ) <EOL> cls . images . client . create_image_member ( image . id_ , cls . alt_one_member_id ) <EOL> cls . images_alt_one . client . update_image_member ( <EOL> image . id_ , cls . alt_one_member_id , ImageMemberStatus . ACCEPTED ) <EOL> cls . images_admin . client . deactivate_image ( image . id_ ) <EOL> cls . shared_deactivated_image = ( <EOL> cls . images . client . get_image_details ( image . id_ ) . entity ) <EOL> alt_image = created_images . pop ( ) <EOL> cls . images . client . create_image_member ( <EOL> alt_image . id_ , cls . alt_one_member_id ) <EOL> cls . images_alt_one . client . update_image_member ( <EOL> alt_image . id_ , cls . alt_one_member_id , ImageMemberStatus . ACCEPTED ) <EOL> cls . images_admin . client . deactivate_image ( alt_image . id_ ) <EOL> cls . images_admin . client . reactivate_image ( alt_image . id_ ) <EOL> cls . shared_reactivated_image = ( <EOL> cls . images . client . get_image_details ( alt_image . id_ ) . entity ) <EOL> cls . imported_image = cls . images . behaviors . create_image_via_task ( <EOL> image_properties = { '<STR_LIT:name>' : rand_name ( '<STR_LIT>' ) } , <EOL> import_from = cls . images . config . import_from_bootable ) <EOL> cls . images . client . create_image_member ( <EOL> cls . imported_image . id_ , cls . alt_one_member_id ) <EOL> cls . snapshot_image = cls . images . behaviors . create_image_via_task ( <EOL> image_properties = { '<STR_LIT:name>' : rand_name ( '<STR_LIT>' ) } , <EOL> import_from = cls . images . config . import_from_bootable ) <EOL> cls . images . client . create_image_member ( <EOL> cls . snapshot_image . id_ , cls . alt_one_member_id ) <EOL> cls . snapshot_server = ( <EOL> cls . compute_alt_one_servers_behaviors . create_active_server ( <EOL> name = rand_name ( '<STR_LIT>' ) , <EOL> image_ref = cls . snapshot_image . id_ ) ) . entity <EOL> cls . resources . add ( <EOL> cls . snapshot_server . id , <EOL> cls . compute_alt_one_servers_client . delete_server ) <EOL> @ classmethod <EOL> def tearDownClass ( cls ) : <EOL> cls . images . behaviors . resources . release ( ) <EOL> cls . resources . release ( ) <EOL> super ( ImageSharing , cls ) . tearDownClass ( ) <EOL> def test_delete_shared_image_accessibility ( self ) : <EOL> """<STR_LIT>""" <EOL> resp = self . images . client . get_image_member ( <EOL> self . delete_access_image . id_ , self . alt_one_member_id ) <EOL> self . assertTrue ( resp . ok , Messages . OK_RESP_MSG . format ( resp . status_code ) ) <EOL> get_member = resp . entity <EOL> self . assertEqual ( get_member . status , ImageMemberStatus . PENDING ) <EOL> resp = self . images_alt_one . client . delete_image ( <EOL> self . delete_access_image . id_ ) <EOL> self . assertEqual ( <EOL> resp . status_code , <NUM_LIT> , <EOL> Messages . STATUS_CODE_MSG . format ( <NUM_LIT> , resp . status_code ) ) <EOL> resp = self . images_alt_one . client . update_image_member ( <EOL> self . delete_access_image . id_ , self . alt_one_member_id , <EOL> ImageMemberStatus . ACCEPTED ) <EOL> updated_member = resp . entity <EOL> self . assertEqual ( updated_member . status , ImageMemberStatus . ACCEPTED ) <EOL> resp = self . images_alt_one . client . delete_image ( <EOL> self . delete_access_image . id_ ) <EOL> self . assertEqual ( <EOL> resp . status_code , <NUM_LIT> , <EOL> Messages . STATUS_CODE_MSG . format ( <NUM_LIT> , resp . status_code ) ) <EOL> resp = self . images . client . delete_image ( <EOL> self . delete_access_image . id_ ) <EOL> self . assertTrue ( resp . ok , Messages . OK_RESP_MSG . format ( resp . status_code ) ) <EOL> resp = self . images_alt_one . client . get_image_details ( <EOL> self . delete_access_image . id_ ) <EOL> self . assertEqual ( <EOL> resp . status_code , <NUM_LIT> , <EOL> Messages . STATUS_CODE_MSG . format ( <NUM_LIT> , resp . status_code ) ) <EOL> def test_share_image_with_single_member ( self ) : <EOL> """<STR_LIT>""" <EOL> image_member_ids = [ ] <EOL> resp = self . images . client . get_image_details ( <EOL> self . single_member_image . id_ ) <EOL> self . assertTrue ( resp . ok , Messages . OK_RESP_MSG . format ( resp . status_code ) ) <EOL> get_image_as_owner = resp . entity <EOL> errors = self . images . behaviors . validate_image ( get_image_as_owner ) <EOL> self . assertEqual ( <EOL> errors , [ ] , <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( errors ) ) <EOL> resp = self . images_alt_one . client . get_image_details ( <EOL> self . single_member_image . id_ ) <EOL> self . assertEqual ( <EOL> resp . status_code , <NUM_LIT> , <EOL> Messages . STATUS_CODE_MSG . format ( <NUM_LIT> , resp . status_code ) ) <EOL> listed_images = self . images_alt_one . behaviors . list_all_images ( ) <EOL> self . assertNotIn ( <EOL> self . single_member_image , listed_images , <EOL> msg = '<STR_LIT>' <EOL> '<STR_LIT>' . format ( self . single_member_image ) ) <EOL> resp = self . images . client . create_image_member ( <EOL> self . single_member_image . id_ , self . alt_one_member_id ) <EOL> self . assertTrue ( resp . ok , Messages . OK_RESP_MSG . format ( resp . status_code ) ) <EOL> member = resp . entity <EOL> self . assertEqual ( member . status , ImageMemberStatus . PENDING ) <EOL> resp = self . images_alt_one . client . get_image_details ( <EOL> self . single_member_image . id_ ) <EOL> self . assertTrue ( resp . ok , Messages . OK_RESP_MSG . format ( resp . status_code ) ) <EOL> get_image_as_member = resp . entity <EOL> self . assertEqual ( <EOL> get_image_as_member , get_image_as_owner , <EOL> msg = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( get_image_as_member , <EOL> get_image_as_owner ) ) <EOL> listed_images = self . images_alt_one . behaviors . list_all_images ( ) <EOL> self . assertNotIn ( <EOL> self . single_member_image , listed_images , <EOL> msg = '<STR_LIT>' <EOL> '<STR_LIT>' . format ( self . single_member_image ) ) <EOL> resp = self . images_alt_one . client . update_image_member ( <EOL> self . single_member_image . id_ , self . alt_one_member_id , <EOL> ImageMemberStatus . ACCEPTED ) <EOL> updated_member = resp . entity <EOL> self . assertEqual ( updated_member . status , ImageMemberStatus . ACCEPTED ) <EOL> resp = self . images_alt_one . client . get_image_details ( <EOL> self . single_member_image . id_ ) <EOL> self . assertTrue ( resp . ok , Messages . OK_RESP_MSG . format ( resp . status_code ) ) <EOL> get_image_as_member_updated = resp . entity <EOL> self . assertEqual ( <EOL> get_image_as_member_updated , get_image_as_member , <EOL> msg = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( get_image_as_member_updated , <EOL> get_image_as_member ) ) <EOL> listed_images = self . images_alt_one . behaviors . list_all_images ( ) <EOL> self . assertIn ( <EOL> self . single_member_image , listed_images , <EOL> msg = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( self . single_member_image ) ) <EOL> resp = self . images . client . list_image_members ( <EOL> self . single_member_image . id_ ) <EOL> self . assertTrue ( resp . ok , Messages . OK_RESP_MSG . format ( resp . status_code ) ) <EOL> listed_image_members = resp . entity <EOL> self . assertEqual ( <EOL> len ( listed_image_members ) , <NUM_LIT:1> , <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( len ( listed_image_members ) ) ) <EOL> [ image_member_ids . append ( image_member . member_id ) <EOL> for image_member in listed_image_members ] <EOL> self . assertIn ( <EOL> self . alt_one_member_id , image_member_ids , <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( self . alt_one_member_id , <EOL> image_member_ids ) ) <EOL> def test_share_image_with_multiple_members ( self ) : <EOL> """<STR_LIT>""" <EOL> image_member_ids = [ ] <EOL> resp = self . images_alt_one . client . get_image_details ( <EOL> self . multiple_members_image . id_ ) <EOL> self . assertEqual ( <EOL> resp . status_code , <NUM_LIT> , <EOL> Messages . STATUS_CODE_MSG . format ( <NUM_LIT> , resp . status_code ) ) <EOL> listed_images = self . images_alt_one . behaviors . list_all_images ( ) <EOL> self . assertNotIn ( <EOL> self . multiple_members_image , listed_images , <EOL> msg = '<STR_LIT>' <EOL> '<STR_LIT>' . format ( self . multiple_members_image ) ) <EOL> resp = self . images_alt_two . client . get_image_details ( <EOL> self . multiple_members_image . id_ ) <EOL> self . assertEqual ( <EOL> resp . status_code , <NUM_LIT> , <EOL> Messages . STATUS_CODE_MSG . format ( <NUM_LIT> , resp . status_code ) ) <EOL> listed_images = self . images_alt_two . behaviors . list_all_images ( ) <EOL> self . assertNotIn ( <EOL> self . multiple_members_image , listed_images , <EOL> msg = '<STR_LIT>' <EOL> '<STR_LIT>' . format ( self . multiple_members_image ) ) <EOL> resp = self . images . client . create_image_member ( <EOL> self . multiple_members_image . id_ , self . alt_one_member_id ) <EOL> self . assertTrue ( resp . ok , Messages . OK_RESP_MSG . format ( resp . status_code ) ) <EOL> member = resp . entity <EOL> self . assertEqual ( member . status , ImageMemberStatus . PENDING ) <EOL> resp = self . images_alt_one . client . get_image_details ( <EOL> self . multiple_members_image . id_ ) <EOL> self . assertTrue ( resp . ok , Messages . OK_RESP_MSG . format ( resp . status_code ) ) <EOL> listed_images = self . images_alt_one . behaviors . list_all_images ( ) <EOL> self . assertNotIn ( <EOL> self . multiple_members_image , listed_images , <EOL> msg = '<STR_LIT>' <EOL> '<STR_LIT>' . format ( self . multiple_members_image ) ) <EOL> resp = self . images . client . create_image_member ( <EOL> self . multiple_members_image . id_ , self . alt_two_member_id ) <EOL> self . assertTrue ( resp . ok , Messages . OK_RESP_MSG . format ( resp . status_code ) ) <EOL> member = resp . entity <EOL> self . assertEqual ( member . status , ImageMemberStatus . PENDING ) <EOL> resp = self . images_alt_two . client . get_image_details ( <EOL> self . multiple_members_image . id_ ) <EOL> self . assertTrue ( resp . ok , Messages . OK_RESP_MSG . format ( resp . status_code ) ) <EOL> listed_images = self . images_alt_two . behaviors . list_all_images ( ) <EOL> self . assertNotIn ( <EOL> self . multiple_members_image , listed_images , <EOL> msg = '<STR_LIT>' <EOL> '<STR_LIT>' . format ( self . multiple_members_image ) ) <EOL> resp = self . images_alt_one . client . update_image_member ( <EOL> self . multiple_members_image . id_ , self . alt_one_member_id , <EOL> ImageMemberStatus . ACCEPTED ) <EOL> updated_member = resp . entity <EOL> self . assertEqual ( updated_member . status , ImageMemberStatus . ACCEPTED ) <EOL> resp = self . images_alt_one . client . get_image_details ( <EOL> self . multiple_members_image . id_ ) <EOL> self . assertTrue ( resp . ok , Messages . OK_RESP_MSG . format ( resp . status_code ) ) <EOL> listed_images = self . images_alt_one . behaviors . list_all_images ( ) <EOL> self . assertIn ( <EOL> self . multiple_members_image , listed_images , <EOL> msg = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( self . multiple_members_image ) ) <EOL> resp = self . images_alt_two . client . update_image_member ( <EOL> self . multiple_members_image . id_ , self . alt_two_member_id , <EOL> ImageMemberStatus . ACCEPTED ) <EOL> updated_member = resp . entity <EOL> self . assertEqual ( updated_member . status , ImageMemberStatus . ACCEPTED ) <EOL> resp = self . images_alt_two . client . get_image_details ( <EOL> self . multiple_members_image . id_ ) <EOL> self . assertTrue ( resp . ok , Messages . OK_RESP_MSG . format ( resp . status_code ) ) <EOL> listed_images = self . images_alt_two . behaviors . list_all_images ( ) <EOL> self . assertIn ( <EOL> self . multiple_members_image , listed_images , <EOL> msg = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( self . multiple_members_image ) ) <EOL> resp = self . images . client . list_image_members ( <EOL> self . multiple_members_image . id_ ) <EOL> self . assertTrue ( resp . ok , Messages . OK_RESP_MSG . format ( resp . status_code ) ) <EOL> listed_image_members = resp . entity <EOL> self . assertEqual ( <EOL> len ( listed_image_members ) , <NUM_LIT:2> , <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( len ( listed_image_members ) ) ) <EOL> [ image_member_ids . append ( image_member . member_id ) <EOL> for image_member in listed_image_members ] <EOL> self . assertIn ( <EOL> self . alt_one_member_id , image_member_ids , <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( self . alt_one_member_id , <EOL> image_member_ids ) ) <EOL> self . assertIn ( <EOL> self . alt_two_member_id , image_member_ids , <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( self . alt_two_member_id , <EOL> image_member_ids ) ) <EOL> def test_create_server_from_shared_image ( self ) : <EOL> """<STR_LIT>""" <EOL> resp = self . compute_alt_one_servers_behaviors . create_active_server ( <EOL> name = rand_name ( '<STR_LIT>' ) , <EOL> image_ref = self . imported_image . id_ ) <EOL> self . assertTrue ( resp . ok , Messages . OK_RESP_MSG . format ( resp . status_code ) ) <EOL> server = resp . entity <EOL> self . resources . add ( <EOL> server . id , self . compute_alt_one_servers_client . delete_server ) <EOL> self . assertEqual ( <EOL> server . status . lower ( ) , '<STR_LIT>' , <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( server . status . lower ( ) ) ) <EOL> remote_client = ( <EOL> self . compute_alt_one_servers_behaviors . get_remote_instance_client ( <EOL> server , self . compute . servers . config ) ) <EOL> self . assertTrue ( remote_client . can_authenticate ( ) , <EOL> msg = "<STR_LIT>" ) <EOL> def test_create_snapshot_of_server_created_from_shared_image ( self ) : <EOL> """<STR_LIT>""" <EOL> created_snapshot = ( <EOL> self . compute_alt_one_images_behaviors . create_active_image ( <EOL> server_id = self . snapshot_server . id , <EOL> name = rand_name ( '<STR_LIT>' ) ) . entity ) <EOL> self . resources . add ( <EOL> created_snapshot . id , self . images_alt_one . client . delete_image ) <EOL> resp = self . images_alt_one . client . get_image_details ( <EOL> created_snapshot . id ) <EOL> self . assertTrue ( resp . ok , Messages . OK_RESP_MSG . format ( resp . status_code ) ) <EOL> get_image = resp . entity <EOL> errors = self . images_alt_one . behaviors . validate_image ( get_image ) <EOL> if get_image . image_type != ImageType . SNAPSHOT : <EOL> errors . append ( Messages . PROPERTY_MSG . format ( <EOL> '<STR_LIT>' , ImageType . SNAPSHOT , get_image . image_type ) ) <EOL> self . assertEqual ( <EOL> errors , [ ] , <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( errors ) ) <EOL> def test_share_image_as_member_of_image_forbidden ( self ) : <EOL> """<STR_LIT>""" <EOL> resp = self . images_alt_one . client . create_image_member ( <EOL> self . shared_image . id_ , self . alt_two_member_id ) <EOL> self . assertEqual ( <EOL> resp . status_code , <NUM_LIT> , <EOL> Messages . STATUS_CODE_MSG . format ( <NUM_LIT> , resp . status_code ) ) <EOL> resp = self . images_alt_two . client . get_image_details ( <EOL> self . shared_image . id_ ) <EOL> self . assertEqual ( <EOL> resp . status_code , <NUM_LIT> , <EOL> Messages . STATUS_CODE_MSG . format ( <NUM_LIT> , resp . status_code ) ) <EOL> def test_shared_deactivated_image_accessibility ( self ) : <EOL> """<STR_LIT>""" <EOL> resp = self . images_alt_one . client . get_image_details ( <EOL> self . shared_deactivated_image . id_ ) <EOL> self . assertTrue ( resp . ok , Messages . OK_RESP_MSG . format ( resp . status_code ) ) <EOL> listed_images = self . images_alt_one . behaviors . list_all_images ( ) <EOL> self . assertIn ( <EOL> self . shared_deactivated_image , listed_images , <EOL> msg = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( self . shared_deactivated_image ) ) <EOL> def test_shared_reactivated_image_accessibility ( self ) : <EOL> """<STR_LIT>""" <EOL> resp = self . images_alt_one . client . get_image_details ( <EOL> self . shared_reactivated_image . id_ ) <EOL> self . assertTrue ( resp . ok , Messages . OK_RESP_MSG . format ( resp . status_code ) ) <EOL> listed_images = self . images_alt_one . behaviors . list_all_images ( ) <EOL> self . assertIn ( <EOL> self . shared_reactivated_image , listed_images , <EOL> msg = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( self . shared_reactivated_image ) ) </s>
