def test_report_state_attribute_error(self, agent_registration):
     cfg.CONF.set_override('report_interval', 1, 'AGENT')
     self.plugin_reportstate_api.report_state.side_effect = AttributeError
     agent = cfg_agent.CiscoCfgAgentWithStateReport(HOSTNAME, self.conf)
     agent.heartbeat = mock.Mock()
     agent.send_agent_report(None, None)
     self.assertTrue(agent.heartbeat.stop.called)
 def test_agent_registration_fail_always(self):
     self.devmgr_plugin_api.register_for_duty = mock.Mock(
         return_value=False)
     cfg_agent.REGISTRATION_RETRY_DELAY = 0.01
     cfg_agent.MAX_REGISTRATION_ATTEMPTS = 3
     with testtools.ExpectedException(SystemExit):
         cfg_agent.CiscoCfgAgentWithStateReport(HOSTNAME, self.conf)
示例#3
0
 def test_report_state_report_iteration_check_partial_report(self):
     agent = cfg_agent.CiscoCfgAgentWithStateReport(HOSTNAME, self.conf)
     # Retain original keepalive iteration
     agent.keepalive_iteration = self.conf.cfg_agent.report_iteration
     agent._report_state()
     self.assertNotIn('configurations', agent.agent_state)
     self.assertEqual((self.conf.cfg_agent.report_iteration + 1),
                      agent.keepalive_iteration)
示例#4
0
 def test_initialize_service_helpers_error(self):
     self.conf.set_override('fw_svc_helper_class',
                            'wrong.path.FakeFirewallSvcHelper', 'cfg_agent')
     agent = cfg_agent.CiscoCfgAgentWithStateReport(HOSTNAME, self.conf)
     # In this error scenario the exception ImportError has been caught
     # and fw_service_helper is set to None. So we only need to evaluate
     # if fw_service_helper is None.
     self.assertEqual(None, agent.fw_service_helper)
示例#5
0
 def test_report_state(self):
     agent = cfg_agent.CiscoCfgAgentWithStateReport(HOSTNAME, self.conf)
     # Set keepalive iteration to just before the reporting iteration
     agent.keepalive_iteration = self.conf.cfg_agent.report_iteration - 1
     agent._report_state()
     self.assertIn('total routers', agent.agent_state['configurations'])
     self.assertEqual(0,
                      agent.agent_state['configurations']['total routers'])
示例#6
0
 def test_no_hosting_devices_monitored_from_start_if_rpc_fail(self):
     agent = cfg_agent.CiscoCfgAgentWithStateReport(HOSTNAME, self.conf)
     with mock.patch.object(agent.devmgr_rpc,
                            'get_hosting_devices_for_agent',
                            side_effect=exceptions.MessagingException), \
             mock.patch.object(agent, '_dev_status') as ds_mock:
         agent.after_start()
         ds_mock.backlog_hosting_devices.assert_not_called()
示例#7
0
 def test_assigned_hosting_devices_monitored_from_start(self):
     agent = cfg_agent.CiscoCfgAgentWithStateReport(HOSTNAME, self.conf)
     fake_hds = [{'id': 'fake_id1'}, {'id': 'fake_id2'}]
     with mock.patch.object(agent.devmgr_rpc,
                            'get_hosting_devices_for_agent',
                            return_value=fake_hds), \
             mock.patch.object(agent, '_dev_status') as ds_mock:
         agent.after_start()
         ds_mock.backlog_hosting_devices.assert_called_once_with(fake_hds)
示例#8
0
 def test_assigned_hosting_devices_monitored_from_start_retry(self):
     agent = cfg_agent.CiscoCfgAgentWithStateReport(HOSTNAME, self.conf)
     fake_hds = [{'id': 'fake_id1'}, {'id': 'fake_id2'}]
     results = [exceptions.MessagingException(),
                exceptions.MessagingException(), fake_hds]
     with mock.patch.object(agent.devmgr_rpc,
                            'get_hosting_devices_for_agent',
                            side_effect=results), \
             mock.patch.object(agent, '_dev_status') as ds_mock:
         agent.after_start()
         ds_mock.backlog_hosting_devices.assert_called_once_with(fake_hds)
 def test_get_hosting_device_configuration_no_svc_helper(self):
     routing_service_helper_mock = mock.MagicMock()
     routing_service_helper_mock.driver_manager = mock.MagicMock()
     drv_mgr = routing_service_helper_mock.driver_manager
     drv = drv_mgr.get_driver_for_hosting_device.return_value
     fake_running_config = 'a fake running config'
     drv.get_configuration = mock.MagicMock(
         return_value=fake_running_config)
     hd_id = 'a_hd_id'
     payload = {'hosting_device_id': hd_id}
     agent = cfg_agent.CiscoCfgAgentWithStateReport(HOSTNAME, self.conf)
     agent.routing_service_helper = None
     res = agent.get_hosting_device_configuration(mock.MagicMock(), payload)
     self.assertIsNone(res)
     drv.get_configuration.assert_not_called()
示例#10
0
 def test_plugin_not_notified_about_revived_hosting_devices_heartbeat_off(
         self):
     self.conf.set_override('enable_heartbeat', False, 'cfg_agent')
     agent = cfg_agent.CiscoCfgAgentWithStateReport(HOSTNAME, self.conf)
     _dev_status_mock = mock.MagicMock()
     ids_revived_hds = ['fake_hd_id1', 'fake_hd_id2']
     _dev_status_mock.check_backlogged_hosting_devices.return_value = {
         'reachable': [], 'dead': [], 'revived': ids_revived_hds}
     with mock.patch.object(agent, '_dev_status', _dev_status_mock),\
             mock.patch.object(agent, 'process_services') as p_s_mock,\
             mock.patch.object(agent, 'devmgr_rpc') as d_r_mock:
         ctx = mock.MagicMock()
         agent._process_backlogged_hosting_devices(ctx)
     self.assertEqual(0, p_s_mock.call_count)
     self.assertEqual(0, d_r_mock.report_revived_hosting_devices.call_count)
示例#11
0
 def test_report_state(self):
     agent = cfg_agent.CiscoCfgAgentWithStateReport(HOSTNAME, self.conf)
     agent._report_state()
     self.assertIn('total routers', agent.agent_state['configurations'])
     self.assertEqual(0,
                      agent.agent_state['configurations']['total routers'])
示例#12
0
 def test_agent_registration_success_after_2_tries(self):
     self.devmgr_plugin_api.register_for_duty = mock.Mock(
         side_effect=[False, False, True])
     cfg_agent.REGISTRATION_RETRY_DELAY = 0.01
     agent = cfg_agent.CiscoCfgAgentWithStateReport(HOSTNAME, self.conf)
     self.assertEqual(agent.devmgr_rpc.register_for_duty.call_count, 3)
示例#13
0
 def test_agent_registration_success(self):
     agent = cfg_agent.CiscoCfgAgentWithStateReport(HOSTNAME, self.conf)
     self.assertTrue(agent.devmgr_rpc.register_for_duty(agent.context))