def testIpForwardingDaemonError(
     self, mock_lock, mock_logger, mock_watcher, mock_network_utils,
     mock_ip_forwarding_utils):
   mock_logger_instance = mock.Mock()
   mock_logger.Logger.return_value = mock_logger_instance
   mocks = mock.Mock()
   mocks.attach_mock(mock_lock, 'lock')
   mocks.attach_mock(mock_logger, 'logger')
   mocks.attach_mock(mock_network_utils, 'network')
   mocks.attach_mock(mock_ip_forwarding_utils, 'forwarding')
   mocks.attach_mock(mock_watcher, 'watcher')
   mock_lock.LockFile.side_effect = IOError('Test Error')
   with mock.patch.object(
       ip_forwarding_daemon.IpForwardingDaemon, 'HandleNetworkInterfaces'):
     ip_forwarding_daemon.IpForwardingDaemon()
     expected_calls = [
         mock.call.logger.Logger(
             name=mock.ANY, debug=False, facility=mock.ANY),
         mock.call.watcher.MetadataWatcher(logger=mock_logger_instance),
         mock.call.network.NetworkUtils(logger=mock_logger_instance),
         mock.call.forwarding.IpForwardingUtils(
             logger=mock_logger_instance, proto_id=None),
         mock.call.lock.LockFile(ip_forwarding_daemon.LOCKFILE),
         mock.call.logger.Logger().warning('Test Error'),
     ]
     self.assertEqual(mocks.mock_calls, expected_calls)
 def testIpForwardingDaemon(
     self, mock_lock, mock_logger, mock_watcher, mock_network_utils,
     mock_ip_forwarding_utils):
   mock_logger_instance = mock.Mock()
   mock_logger.Logger.return_value = mock_logger_instance
   mocks = mock.Mock()
   mocks.attach_mock(mock_lock, 'lock')
   mocks.attach_mock(mock_logger, 'logger')
   mocks.attach_mock(mock_network_utils, 'network')
   mocks.attach_mock(mock_ip_forwarding_utils, 'forwarding')
   mocks.attach_mock(mock_watcher, 'watcher')
   metadata_key = ip_forwarding_daemon.IpForwardingDaemon.network_interfaces
   with mock.patch.object(
       ip_forwarding_daemon.IpForwardingDaemon,
       'HandleNetworkInterfaces') as mock_handle:
     ip_forwarding_daemon.IpForwardingDaemon(proto_id='66', debug=True)
     expected_calls = [
         mock.call.logger.Logger(name=mock.ANY, debug=True, facility=mock.ANY),
         mock.call.watcher.MetadataWatcher(logger=mock_logger_instance),
         mock.call.network.NetworkUtils(logger=mock_logger_instance),
         mock.call.forwarding.IpForwardingUtils(
             logger=mock_logger_instance, proto_id='66'),
         mock.call.lock.LockFile(ip_forwarding_daemon.LOCKFILE),
         mock.call.lock.LockFile().__enter__(),
         mock.call.logger.Logger().info(mock.ANY),
         mock.call.watcher.MetadataWatcher().WatchMetadata(
             mock_handle, metadata_key=metadata_key, recursive=True,
             timeout=mock.ANY),
         mock.call.lock.LockFile().__exit__(None, None, None),
     ]
     self.assertEqual(mocks.mock_calls, expected_calls)