def test_dump_diags_process(self): process_results = [ ('Execution time in user mode (seconds)', 'ru_utime', 1), ('Execution time in kernel mode (seconds)', 'ru_stime', 2), ('Maximum Resident Set Size (KB)', 'ru_maxrss', 3), ('Soft page faults', 'ru_minflt', 4), ('Hard page faults', 'ru_majflt', 5), ('Input events', 'ru_inblock', 6), ('Output events', 'ru_oublock', 7), ('Voluntary context switches', 'ru_nvcsw', 8), ('Involuntary context switches', 'ru_nivcsw', 9), ] with mock.patch('calico.felix.futils.stat_log') as m_log: with mock.patch('calico.felix.futils.resource') as m_resource: res = m_resource.getrusage.return_value for _, field, val in process_results: setattr(res, field, val) calls = [ mock.call.info('=== DIAGNOSTICS ==='), mock.call.info("--- %s ---", "foo"), mock.call.info('--- %s ---', 'Process Statistics'), mock.call.info('=== END OF DIAGNOSTICS ==='), ] calls.extend( mock.call.info('%s: %s', name, value) for name, _, value in process_results ) futils.register_process_statistics() futils.dump_diags() m_log.assert_has_calls(calls, any_order=True)
def test_dump_diags_process(self): process_results = [ ("Execution time in user mode (seconds)", "ru_utime", 1), ("Execution time in kernel mode (seconds)", "ru_stime", 2), ("Maximum Resident Set Size (KB)", "ru_maxrss", 3), ("Soft page faults", "ru_minflt", 4), ("Hard page faults", "ru_majflt", 5), ("Input events", "ru_inblock", 6), ("Output events", "ru_oublock", 7), ("Voluntary context switches", "ru_nvcsw", 8), ("Involuntary context switches", "ru_nivcsw", 9), ] with mock.patch("calico.felix.futils.stat_log") as m_log: with mock.patch("calico.felix.futils.resource") as m_resource: res = m_resource.getrusage.return_value for _, field, val in process_results: setattr(res, field, val) calls = [ mock.call.info("=== DIAGNOSTICS ==="), mock.call.info("--- %s ---", "foo"), mock.call.info("--- %s ---", "Process Statistics"), mock.call.info("=== END OF DIAGNOSTICS ==="), ] calls.extend(mock.call.info("%s: %s", name, value) for name, _, value in process_results) futils.register_process_statistics() futils.dump_diags() m_log.assert_has_calls(calls, any_order=True)
def test_dump_diags(self): with mock.patch("calico.felix.futils.stat_log") as m_log: self.sc.increment("bar") futils.dump_diags() m_log.assert_has_calls([ mock.call.info("=== DIAGNOSTICS ==="), mock.call.info("--- %s ---", "foo"), mock.call.info("%s: %s", "bar", 1), mock.call.info("=== END OF DIAGNOSTICS ==="), ], any_order=True)
def test_dump_diags(self): with mock.patch("calico.felix.futils.stat_log") as m_log: self.sc.increment("bar") futils.dump_diags() self.assertEqual(m_log.info.mock_calls, [ mock.call("=== DIAGNOSTICS ==="), mock.call("--- %s ---", "foo"), mock.call("%s: %s", "bar", 1), mock.call("=== END OF DIAGNOSTICS ==="), ])
def test_main_greenlet_no_ipv6(self, m_iwait, m_MasqueradeManager, m_IptablesUpdater, m_UpdateSplitter, m_host_chains, m_wl_chains, m_start, m_load, m_ipset_4, m_check_output, m_check_call, m_popen, m_configure_global_kernel_config, m_list_interface_ips, m_path_exists, m_install_globals, m_conntrack): m_popen.return_value.communicate.return_value = "", "" m_IptablesUpdater.return_value.greenlet = mock.Mock() m_MasqueradeManager.return_value.greenlet = mock.Mock() m_UpdateSplitter.return_value.greenlet = mock.Mock() m_host_chains.return_value.greenlet = mock.Mock() m_wl_chains.return_value.greenlet = mock.Mock() m_list_interface_ips.return_value = set() env_dict = { "FELIX_ETCDADDR": "localhost:4001", "FELIX_ETCDSCHEME": "http", "FELIX_ETCDKEYFILE": "none", "FELIX_ETCDCERTFILE": "none", "FELIX_ETCDCAFILE": "none", "FELIX_FELIXHOSTNAME": "myhost", "FELIX_INTERFACEPREFIX": "tap", "FELIX_METADATAIP": "10.0.0.1", "FELIX_METADATAPORT": "1234", "FELIX_IPINIPENABLED": "True", "FELIX_IPINIPMTU": "1480", "FELIX_DEFAULTINPUTCHAINACTION": "RETURN" } config = load_config("felix_missing.cfg", env_dict=env_dict) with gevent.Timeout(5): self.assertRaises(TestException, felix._main_greenlet, config) m_load.assert_called_once_with(async=False) m_configure_global_kernel_config.assert_called_once_with() m_install_globals.assert_called_once_with(mock.ANY, mock.ANY, mock.ANY, ip_version=4) m_conntrack.assert_called_once_with() # Cover the diags dump function. futils.dump_diags()
def test_dump_diags_cover(self): with mock.patch("calico.felix.futils.stat_log") as m_log: m_log.info.side_effect = Exception() m_log.exception.side_effect = Exception() futils.dump_diags()