<s> from django . test import TestCase <EOL> import mock <EOL> from netaddr import IPNetwork <EOL> from devops . models import Environment <EOL> class TestLibvirtL2NetworkDevice ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . env = Environment . create ( '<STR_LIT>' ) <EOL> self . group = self . env . add_group ( <EOL> group_name = '<STR_LIT>' , <EOL> driver_name = '<STR_LIT>' , <EOL> connection_string = '<STR_LIT>' ) <EOL> self . ap = self . env . add_address_pool ( <EOL> name = '<STR_LIT>' , <EOL> net = '<STR_LIT>' , <EOL> tag = <NUM_LIT:0> , <EOL> ip_reserved = dict ( l2_network_device = '<STR_LIT>' ) , <EOL> ) <EOL> self . net_pool = self . group . add_network_pool ( <EOL> name = '<STR_LIT>' , <EOL> address_pool_name = '<STR_LIT>' , <EOL> ) <EOL> self . l2_net_dev = self . group . add_l2_network_device ( <EOL> name = '<STR_LIT>' , <EOL> forward = dict ( mode = '<STR_LIT>' ) , <EOL> address_pool = '<STR_LIT>' , <EOL> ) <EOL> self . d = self . group . driver <EOL> def tearDown ( self ) : <EOL> for network_name in self . d . conn . listDefinedNetworks ( ) : <EOL> self . d . conn . networkLookupByName ( network_name ) . undefine ( ) <EOL> def test_define ( self ) : <EOL> assert self . l2_net_dev . forward . mode == '<STR_LIT>' <EOL> self . l2_net_dev . define ( ) <EOL> assert isinstance ( self . l2_net_dev . uuid , str ) <EOL> assert len ( self . l2_net_dev . uuid ) == <NUM_LIT> <EOL> assert self . l2_net_dev . network_name ( ) == '<STR_LIT>' <EOL> assert self . l2_net_dev . exists ( ) is True <EOL> assert self . l2_net_dev . is_active ( ) == <NUM_LIT:0> <EOL> assert self . l2_net_dev . bridge_name ( ) == '<STR_LIT>' <EOL> assert self . l2_net_dev . _libvirt_network . autostart ( ) == <NUM_LIT:1> <EOL> xml = self . l2_net_dev . _libvirt_network . XMLDesc ( <NUM_LIT:0> ) <EOL> assert xml == ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" . format ( self . l2_net_dev . uuid ) ) <EOL> def test_start_destroy ( self ) : <EOL> self . l2_net_dev . define ( ) <EOL> assert self . l2_net_dev . is_active ( ) == <NUM_LIT:0> <EOL> self . l2_net_dev . start ( ) <EOL> assert self . l2_net_dev . is_active ( ) == <NUM_LIT:1> <EOL> self . l2_net_dev . destroy ( ) <EOL> assert self . l2_net_dev . is_active ( ) == <NUM_LIT:0> <EOL> def test_exists ( self ) : <EOL> self . l2_net_dev . define ( ) <EOL> assert self . l2_net_dev . exists ( ) is True <EOL> self . l2_net_dev . remove ( ) <EOL> assert self . l2_net_dev . exists ( ) is False <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_remove_active ( self , sleep_mock ) : <EOL> self . l2_net_dev . define ( ) <EOL> self . l2_net_dev . start ( ) <EOL> assert self . l2_net_dev . exists ( ) is True <EOL> assert self . l2_net_dev . is_active ( ) == <NUM_LIT:1> <EOL> self . l2_net_dev . remove ( ) <EOL> assert self . l2_net_dev . exists ( ) is False <EOL> def test_driver_get_allocated_networks ( self ) : <EOL> self . l2_net_dev . define ( ) <EOL> ret = self . d . get_allocated_networks ( ) <EOL> assert len ( ret ) == <NUM_LIT:1> <EOL> assert ret [ <NUM_LIT:0> ] == IPNetwork ( '<STR_LIT>' ) </s>
