<s> from rally . common . i18n import _ <EOL> from rally . common import log as logging <EOL> from rally . common import utils as rutils <EOL> from rally import consts <EOL> from rally import osclients <EOL> from rally . task import context <EOL> from ec2api . tests . functional import botocoreclient <EOL> LOG = logging . getLogger ( __name__ ) <EOL> @ context . configure ( name = "<STR_LIT>" , order = <NUM_LIT> ) <EOL> class FakeImageGenerator ( context . Context ) : <EOL> """<STR_LIT>""" <EOL> CONFIG_SCHEMA = { <EOL> "<STR_LIT:type>" : "<STR_LIT:object>" , <EOL> "<STR_LIT>" : consts . JSON_SCHEMA , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ] , <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT:string>" , <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:1> <EOL> } , <EOL> } , <EOL> "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> "<STR_LIT>" : False <EOL> } <EOL> @ logging . log_task_wrapper ( LOG . info , _ ( "<STR_LIT>" ) ) <EOL> def setup ( self ) : <EOL> disk_format = self . config [ "<STR_LIT>" ] <EOL> container_format = self . config [ "<STR_LIT>" ] <EOL> images_per_tenant = self . config [ "<STR_LIT>" ] <EOL> for user , tenant_id in rutils . iterate_per_tenants ( <EOL> self . context [ "<STR_LIT>" ] ) : <EOL> glance = osclients . Clients ( user [ "<STR_LIT>" ] ) . glance ( ) . images <EOL> current_images = [ ] <EOL> for i in range ( images_per_tenant ) : <EOL> kw = { <EOL> "<STR_LIT:name>" : "<STR_LIT>" + tenant_id [ <NUM_LIT:0> : <NUM_LIT:8> ] + "<STR_LIT:->" + str ( i ) , <EOL> "<STR_LIT>" : container_format , <EOL> "<STR_LIT>" : disk_format , <EOL> "<STR_LIT:size>" : <NUM_LIT> , <EOL> } <EOL> image = glance . create ( ** kw ) <EOL> current_images . append ( image . id ) <EOL> self . context [ "<STR_LIT>" ] [ tenant_id ] [ "<STR_LIT>" ] = current_images <EOL> args = user [ '<STR_LIT>' ] <EOL> client = botocoreclient . get_ec2_client ( <EOL> args [ '<STR_LIT:url>' ] , args [ '<STR_LIT>' ] , args [ '<STR_LIT>' ] , args [ '<STR_LIT>' ] ) <EOL> data = client . describe_images ( ) <EOL> @ logging . log_task_wrapper ( LOG . info , _ ( "<STR_LIT>" ) ) <EOL> def cleanup ( self ) : <EOL> for user , tenant_id in rutils . iterate_per_tenants ( <EOL> self . context [ "<STR_LIT>" ] ) : <EOL> glance = osclients . Clients ( user [ "<STR_LIT>" ] ) . glance ( ) . images <EOL> for image in self . context [ "<STR_LIT>" ] [ tenant_id ] . get ( "<STR_LIT>" , [ ] ) : <EOL> with logging . ExceptionLogger ( <EOL> LOG , <EOL> _ ( "<STR_LIT>" ) <EOL> % tenant_id ) : <EOL> glance . delete ( image ) </s>
