<s> import os <EOL> import mock <EOL> from oslo_config import cfg <EOL> from oslo_config import fixture as fixture_config <EOL> from oslo_utils import uuidutils <EOL> from neutron . _i18n import _ <EOL> from neutron . agent . l3 import keepalived_state_change <EOL> from neutron . tests . functional import base <EOL> class TestKeepalivedStateChange ( base . BaseSudoTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestKeepalivedStateChange , self ) . setUp ( ) <EOL> self . conf_fixture = self . useFixture ( fixture_config . Config ( ) ) <EOL> self . conf_fixture . register_opt ( <EOL> cfg . StrOpt ( '<STR_LIT>' , <EOL> default = '<STR_LIT>' , <EOL> help = _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) ) ) <EOL> self . router_id = uuidutils . generate_uuid ( ) <EOL> self . conf_dir = self . get_default_temp_dir ( ) . path <EOL> self . cidr = '<STR_LIT>' <EOL> self . interface_name = '<STR_LIT>' <EOL> self . monitor = keepalived_state_change . MonitorDaemon ( <EOL> self . get_temp_file_path ( '<STR_LIT>' ) , <EOL> self . router_id , <EOL> <NUM_LIT:1> , <EOL> <NUM_LIT:2> , <EOL> '<STR_LIT>' , <EOL> self . conf_dir , <EOL> self . interface_name , <EOL> self . cidr ) <EOL> mock . patch . object ( self . monitor , '<STR_LIT>' ) . start ( ) <EOL> self . line = '<STR_LIT>' % ( self . interface_name , self . cidr ) <EOL> def test_parse_and_handle_event_wrong_device_completes_without_error ( self ) : <EOL> self . monitor . parse_and_handle_event ( <EOL> '<STR_LIT>' ) <EOL> def _get_state ( self ) : <EOL> with open ( os . path . join ( self . monitor . conf_dir , '<STR_LIT:state>' ) ) as state_file : <EOL> return state_file . read ( ) <EOL> def test_parse_and_handle_event_writes_to_file ( self ) : <EOL> self . monitor . parse_and_handle_event ( '<STR_LIT>' % self . line ) <EOL> self . assertEqual ( '<STR_LIT>' , self . _get_state ( ) ) <EOL> self . monitor . parse_and_handle_event ( self . line ) <EOL> self . assertEqual ( '<STR_LIT>' , self . _get_state ( ) ) <EOL> def test_parse_and_handle_event_fails_writing_state ( self ) : <EOL> with mock . patch . object ( <EOL> self . monitor , '<STR_LIT>' , side_effect = OSError ) : <EOL> self . monitor . parse_and_handle_event ( self . line ) <EOL> def test_parse_and_handle_event_fails_notifying_agent ( self ) : <EOL> with mock . patch . object ( <EOL> self . monitor , '<STR_LIT>' , side_effect = Exception ) : <EOL> self . monitor . parse_and_handle_event ( self . line ) </s>
