示例#1
0
    def test_valid_config(self, mock_requests, mock_report_to_site):
        mo = mock_open(read_data='my_version')
        mock_requests.get.return_value = self.cool_response

        with patch('ona_service.ona.open', mo, create=True):
            ona = ONA(data_type='ona', poll_seconds=1, update_only=True)
            ona.config_mode = 'auto'
            # The configuration update should cause the service to exit
            # with a special return code
            with self.assertRaises(SystemExit):
                ona.execute()

        mock_report_to_site.assert_called_once_with(ona)

        expected_config = '\n'.join([
            'OBSRVBL_IPFIX_PROBE_4_PORT="9996"',
            'OBSRVBL_IPFIX_PROBE_4_TYPE="netflow-v9"',
            'OBSRVBL_NETWORKS="10.0.0.0/8 172.16.0.0/12 192.168.0.0/16"',
            'OBSRVBL_PDNS_PPS_LIMIT="102"',
            'OBSRVBL_SNMP_ENABLED="true"',
            'OBSRVBL_SNMP_OBJECTID="1.3.6.1.4.1.3375.2.100"',
            'OBSRVBL_SNMP_SERVER="127.0.0.1"',
            'OBSRVBL_SNMP_SERVER_PORT="162"',
            'OBSRVBL_SNMP_USER="******"',
            'OBSRVBL_SNMP_VERSION="2"',
            'OBSRVBL_SYSLOG_ENABLED="true"',
            'OBSRVBL_SYSLOG_FACILITY="user"',
            'OBSRVBL_SYSLOG_SERVER_PORT="51"',
        ])
        mo().write.assert_called_once_with(expected_config)
示例#2
0
文件: test_ona.py 项目: obsrvbl/ona
    def test_valid_config(self, mock_requests, mock_report_to_site):
        mo = mock_open(read_data='my_version')
        mock_requests.get.return_value = self.cool_response

        with patch('ona_service.ona.open', mo, create=True):
            ona = ONA(data_type='ona', poll_seconds=1, update_only=True)
            ona.config_mode = 'auto'
            # The configuration update should cause the service to exit
            # with a special return code
            with self.assertRaises(SystemExit):
                ona.execute()

        mock_report_to_site.assert_called_once_with(ona)

        expected_config = '\n'.join([
            'OBSRVBL_NETWORKS="10.0.0.0/8 172.16.0.0/12 192.168.0.0/16"',
            'OBSRVBL_PDNS_PPS_LIMIT="102"',
            'OBSRVBL_SNMP_ENABLED="true"',
            'OBSRVBL_SNMP_OBJECTID="1.3.6.1.4.1.3375.2.100"',
            'OBSRVBL_SNMP_SERVER="127.0.0.1"',
            'OBSRVBL_SNMP_SERVER_PORT="162"',
            'OBSRVBL_SNMP_USER="******"',
            'OBSRVBL_SNMP_VERSION="2"',
            'OBSRVBL_SYSLOG_ENABLED="true"',
            'OBSRVBL_SYSLOG_FACILITY="user"',
            'OBSRVBL_SYSLOG_SERVER_PORT="51"',
        ])
        mo().write.assert_called_once_with(expected_config)
示例#3
0
    def test_valid_no_config(self, mock_requests, mock_write_config):
        mock_requests.get.return_value = self.my_response
        ona = ONA(data_type='ona', poll_seconds=1, update_only=True)
        ona.config_mode = 'auto'

        with patch('ona_service.ona.open', mock_open(), create=True):
            ona.execute()

        self.assertEqual(mock_write_config.call_count, 0)
示例#4
0
文件: test_ona.py 项目: obsrvbl/ona
    def test_valid_no_config(self, mock_requests, mock_write_config):
        mock_requests.get.return_value = self.my_response
        ona = ONA(data_type='ona', poll_seconds=1, update_only=True)
        ona.config_mode = 'auto'

        with patch('ona_service.ona.open', mock_open(), create=True):
            ona.execute()

        self.assertEqual(mock_write_config.call_count, 0)
示例#5
0
    def test_check_config(self, mock_requests, mock_exit):
        ona = ONA(data_type='ona', poll_seconds=1)
        ona.config_mode = 'auto'

        # first execution, nothing has changed - don't exit
        mock_requests.get.return_value = self.my_response
        with patch('ona_service.ona.open', mock_open(), create=True):
            ona.execute()

        self.assertEqual(mock_exit.call_count, 0)

        # second execution, config has changed - exit
        mock_requests.get.return_value = self.cool_response
        with patch('ona_service.ona.open', mock_open(), create=True):
            ona.execute()

        mock_exit.assert_called_once_with(EAGAIN)
示例#6
0
文件: test_ona.py 项目: obsrvbl/ona
    def test_check_config(self, mock_requests, mock_exit):
        ona = ONA(data_type='ona', poll_seconds=1)
        ona.config_mode = 'auto'

        # first execution, nothing has changed - don't exit
        mock_requests.get.return_value = self.my_response
        with patch('ona_service.ona.open', mock_open(), create=True):
            ona.execute()

        self.assertEqual(mock_exit.call_count, 0)

        # second execution, config has changed - exit
        mock_requests.get.return_value = self.cool_response
        with patch('ona_service.ona.open', mock_open(), create=True):
            ona.execute()

        mock_exit.assert_called_once_with(EAGAIN)