<s> """<STR_LIT>""" <EOL> from nova import test <EOL> from nova import context <EOL> from nova import db <EOL> from nova import flags <EOL> FLAGS = flags . FLAGS <EOL> def _setup_networking ( instance_id , ip = '<STR_LIT>' , flo_addr = '<STR_LIT>' ) : <EOL> ctxt = context . get_admin_context ( ) <EOL> network_ref = db . project_get_networks ( ctxt , <EOL> '<STR_LIT>' , <EOL> associate = True ) [ <NUM_LIT:0> ] <EOL> vif = { '<STR_LIT:address>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : network_ref [ '<STR_LIT:id>' ] , <EOL> '<STR_LIT>' : instance_id } <EOL> vif_ref = db . virtual_interface_create ( ctxt , vif ) <EOL> fixed_ip = { '<STR_LIT:address>' : ip , <EOL> '<STR_LIT>' : network_ref [ '<STR_LIT:id>' ] , <EOL> '<STR_LIT>' : vif_ref [ '<STR_LIT:id>' ] , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : instance_id } <EOL> db . fixed_ip_create ( ctxt , fixed_ip ) <EOL> fix_ref = db . fixed_ip_get_by_address ( ctxt , ip ) <EOL> db . floating_ip_create ( ctxt , { '<STR_LIT:address>' : flo_addr , <EOL> '<STR_LIT>' : fix_ref [ '<STR_LIT:id>' ] } ) <EOL> class DbApiTestCase ( test . TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( DbApiTestCase , self ) . setUp ( ) <EOL> self . user_id = '<STR_LIT>' <EOL> self . project_id = '<STR_LIT>' <EOL> self . context = context . RequestContext ( self . user_id , self . project_id ) <EOL> def test_instance_get_project_vpn ( self ) : <EOL> values = { '<STR_LIT>' : FLAGS . default_instance_type , <EOL> '<STR_LIT>' : FLAGS . vpn_image_id , <EOL> '<STR_LIT>' : self . project_id , <EOL> } <EOL> instance = db . instance_create ( self . context , values ) <EOL> result = db . instance_get_project_vpn ( self . context . elevated ( ) , <EOL> self . project_id ) <EOL> self . assertEqual ( instance [ '<STR_LIT:id>' ] , result [ '<STR_LIT:id>' ] ) <EOL> def test_instance_get_project_vpn_joins ( self ) : <EOL> values = { '<STR_LIT>' : FLAGS . default_instance_type , <EOL> '<STR_LIT>' : FLAGS . vpn_image_id , <EOL> '<STR_LIT>' : self . project_id , <EOL> } <EOL> instance = db . instance_create ( self . context , values ) <EOL> _setup_networking ( instance [ '<STR_LIT:id>' ] ) <EOL> result = db . instance_get_project_vpn ( self . context . elevated ( ) , <EOL> self . project_id ) <EOL> self . assertEqual ( instance [ '<STR_LIT:id>' ] , result [ '<STR_LIT:id>' ] ) <EOL> self . assertEqual ( result [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] . address , <EOL> '<STR_LIT>' ) <EOL> def test_instance_get_all_by_filters ( self ) : <EOL> args = { '<STR_LIT>' : '<STR_LIT:a>' , '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT:host>' : '<STR_LIT>' } <EOL> inst1 = db . instance_create ( self . context , args ) <EOL> inst2 = db . instance_create ( self . context , args ) <EOL> result = db . instance_get_all_by_filters ( self . context , { } ) <EOL> self . assertTrue ( <NUM_LIT:2> , len ( result ) ) <EOL> def test_instance_get_all_by_filters_deleted ( self ) : <EOL> args1 = { '<STR_LIT>' : '<STR_LIT:a>' , '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT:host>' : '<STR_LIT>' } <EOL> inst1 = db . instance_create ( self . context , args1 ) <EOL> args2 = { '<STR_LIT>' : '<STR_LIT:b>' , '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT:host>' : '<STR_LIT>' } <EOL> inst2 = db . instance_create ( self . context , args2 ) <EOL> db . instance_destroy ( self . context , inst1 . id ) <EOL> result = db . instance_get_all_by_filters ( self . context . elevated ( ) , { } ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( result ) ) <EOL> self . assertEqual ( result [ <NUM_LIT:0> ] . id , inst2 . id ) <EOL> self . assertEqual ( result [ <NUM_LIT:1> ] . id , inst1 . id ) <EOL> self . assertTrue ( result [ <NUM_LIT:1> ] . deleted ) </s>
