<s> from neutron import context <EOL> from neutron . db import agents_db <EOL> from neutron . db import db_base_plugin_v2 <EOL> from neutron . extensions import agent <EOL> from neutron . extensions import availability_zone as az_ext <EOL> from neutron . tests . common import helpers <EOL> from neutron . tests . unit . db import test_db_base_plugin_v2 <EOL> class AZExtensionManager ( object ) : <EOL> def get_resources ( self ) : <EOL> agent . RESOURCE_ATTRIBUTE_MAP [ '<STR_LIT>' ] . update ( <EOL> az_ext . EXTENDED_ATTRIBUTES_2_0 [ '<STR_LIT>' ] ) <EOL> return ( az_ext . Availability_zone . get_resources ( ) + <EOL> agent . Agent . get_resources ( ) ) <EOL> def get_actions ( self ) : <EOL> return [ ] <EOL> def get_request_extensions ( self ) : <EOL> return [ ] <EOL> class AZTestPlugin ( db_base_plugin_v2 . NeutronDbPluginV2 , <EOL> agents_db . AgentDbMixin ) : <EOL> supported_extension_aliases = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> class AZTestCommon ( test_db_base_plugin_v2 . NeutronDbPluginV2TestCase ) : <EOL> def _register_azs ( self ) : <EOL> self . agent1 = helpers . register_dhcp_agent ( host = '<STR_LIT>' , az = '<STR_LIT>' ) <EOL> self . agent2 = helpers . register_dhcp_agent ( host = '<STR_LIT>' , az = '<STR_LIT>' ) <EOL> self . agent3 = helpers . register_l3_agent ( host = '<STR_LIT>' , az = '<STR_LIT>' ) <EOL> self . agent4 = helpers . register_l3_agent ( host = '<STR_LIT>' , az = '<STR_LIT>' ) <EOL> self . agent5 = helpers . register_l3_agent ( host = '<STR_LIT>' , az = '<STR_LIT>' ) <EOL> class TestAZAgentCase ( AZTestCommon ) : <EOL> def setUp ( self ) : <EOL> plugin = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> ext_mgr = AZExtensionManager ( ) <EOL> super ( TestAZAgentCase , self ) . setUp ( plugin = plugin , ext_mgr = ext_mgr ) <EOL> def test_list_availability_zones ( self ) : <EOL> self . _register_azs ( ) <EOL> helpers . set_agent_admin_state ( self . agent3 [ '<STR_LIT:id>' ] , admin_state_up = False ) <EOL> helpers . set_agent_admin_state ( self . agent4 [ '<STR_LIT:id>' ] , admin_state_up = False ) <EOL> expected = [ <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:state>' : '<STR_LIT>' } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:state>' : '<STR_LIT>' } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:state>' : '<STR_LIT>' } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:state>' : '<STR_LIT>' } ] <EOL> res = self . _list ( '<STR_LIT>' ) <EOL> azs = res [ '<STR_LIT>' ] <EOL> self . assertItemsEqual ( expected , azs ) <EOL> ctx = context . Context ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> res = self . _list ( '<STR_LIT>' , neutron_context = ctx ) <EOL> azs = res [ '<STR_LIT>' ] <EOL> self . assertItemsEqual ( expected , azs ) <EOL> def test_list_agent_with_az ( self ) : <EOL> helpers . register_dhcp_agent ( host = '<STR_LIT>' , az = '<STR_LIT>' ) <EOL> res = self . _list ( '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> res [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> def test_validate_availability_zones ( self ) : <EOL> self . _register_azs ( ) <EOL> ctx = context . Context ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . plugin . validate_availability_zones ( ctx , '<STR_LIT>' , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . plugin . validate_availability_zones ( ctx , '<STR_LIT>' , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertRaises ( az_ext . AvailabilityZoneNotFound , <EOL> self . plugin . validate_availability_zones , <EOL> ctx , '<STR_LIT>' , [ '<STR_LIT>' ] ) <EOL> class TestAZNetworkCase ( AZTestCommon ) : <EOL> def setUp ( self ) : <EOL> plugin = '<STR_LIT>' <EOL> ext_mgr = AZExtensionManager ( ) <EOL> super ( TestAZNetworkCase , self ) . setUp ( plugin = plugin , ext_mgr = ext_mgr ) <EOL> def test_availability_zones_in_create_response ( self ) : <EOL> with self . network ( ) as net : <EOL> self . assertIn ( '<STR_LIT>' , net [ '<STR_LIT>' ] ) <EOL> self . assertIn ( '<STR_LIT>' , net [ '<STR_LIT>' ] ) <EOL> def test_create_network_with_az ( self ) : <EOL> self . _register_azs ( ) <EOL> az_hints = [ '<STR_LIT>' ] <EOL> with self . network ( availability_zone_hints = az_hints ) as net : <EOL> res = self . _show ( '<STR_LIT>' , net [ '<STR_LIT>' ] [ '<STR_LIT:id>' ] ) <EOL> self . assertItemsEqual ( az_hints , <EOL> res [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> def test_create_network_with_azs ( self ) : <EOL> self . _register_azs ( ) <EOL> az_hints = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> with self . network ( availability_zone_hints = az_hints ) as net : <EOL> res = self . _show ( '<STR_LIT>' , net [ '<STR_LIT>' ] [ '<STR_LIT:id>' ] ) <EOL> self . assertItemsEqual ( az_hints , <EOL> res [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> def test_create_network_without_az ( self ) : <EOL> with self . network ( ) as net : <EOL> res = self . _show ( '<STR_LIT>' , net [ '<STR_LIT>' ] [ '<STR_LIT:id>' ] ) <EOL> self . assertEqual ( [ ] , res [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> def test_create_network_with_empty_az ( self ) : <EOL> with self . network ( availability_zone_hints = [ ] ) as net : <EOL> res = self . _show ( '<STR_LIT>' , net [ '<STR_LIT>' ] [ '<STR_LIT:id>' ] ) <EOL> self . assertEqual ( [ ] , res [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> def test_create_network_with_not_exist_az ( self ) : <EOL> res = self . _create_network ( self . fmt , '<STR_LIT>' , True , <EOL> availability_zone_hints = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <NUM_LIT> , res . status_int ) </s>
