Esempio n. 1
0
 def test_grab_sections_missing_object(self):
     open('router_connected.log', 'w').close()
     copyfile(
         os.path.join(self.location, 'Examples/Config/no_protocol.config'),
         self.config_path)
     with self.assertRaises(KeyError):
         monitor_daemon.MyConfig(self.config_path)
Esempio n. 2
0
 def test_grab_sections_multiplesections(self):
     copyfile(
         os.path.join(self.location,
                      'Examples/Config/multiple_sections.config'),
         self.config_path)
     config = monitor_daemon.MyConfig(self.config_path)
     self.assertItemsEqual(config.__dict__.keys(), ['BGP', 'ISIS'])
Esempio n. 3
0
 def test_alert_response_text(self, mock_text, mock_email):
     copyfile(
         os.path.join(self.location, 'Examples/Config/text_alert.config'),
         self.config_path)
     config = monitor_daemon.MyConfig(self.config_path)
     sec_config = config.__dict__['BGP']
     result = monitor_daemon.alert_response(sec_config, 'BGP', 'up')
     self.assertTrue(result)
     mock_email.assert_not_called()
     mock_text.assert_called_with('+14087784819',
                                  "'BGP' link is up on 'rtr1'")
Esempio n. 4
0
 def test_alert_response_miss_host(self, mock_text, mock_email,
                                   mock_logger):
     copyfile(
         os.path.join(self.location,
                      'Examples/Config/missing_hostname.config'),
         self.config_path)
     config = monitor_daemon.MyConfig(self.config_path)
     sec_config = config.__dict__['BGP']
     result = monitor_daemon.alert_response(sec_config, 'BGP', 'up')
     self.assertTrue(result)
     mock_email.assert_called_with(
         '*****@*****.**', "'BGP' link is up on '(missing hostname)'")
Esempio n. 5
0
 def setUpClass(cls):
     cls.location = os.path.dirname(os.path.realpath(__file__))
     cls.config_path = os.path.join(cls.location, '../monitor.config')
     if os.path.isfile(cls.config_path):
         move(cls.config_path,
              os.path.join(cls.location, '../monitortest.config'))
     copyfile(
         os.path.join(cls.location, 'Examples/Config/monitor_good.config'),
         cls.config_path)
     cls.config = monitor_daemon.MyConfig(cls.config_path)
     cls.grpc_client = CiscoGRPCClient('10.1.1.1', 57777, 10, 'test',
                                       'test')
     cls.sec_config = cls.config.__dict__['BGP']
Esempio n. 6
0
 def test_grab_sections_no_section(self):
     copyfile(
         os.path.join(self.location, 'Examples/Config/no_section.config'),
         self.config_path)
     with self.assertRaises(ValueError):
         monitor_daemon.MyConfig(self.config_path)
Esempio n. 7
0
 def test_grab_sections_good(self):
     copyfile(
         os.path.join(self.location, 'Examples/Config/monitor_good.config'),
         self.config_path)
     config = monitor_daemon.MyConfig(self.config_path)
     self.assertEqual(config.__dict__.keys(), ['BGP'])