Beispiel #1
0
class SupervisorConfigTestCase(TestCase):
    def setUp(self):
        self.infile_path = NamedTemporaryFile(delete=False).name
        self.outfile_path = NamedTemporaryFile(delete=False).name

        with io.open(self.infile_path, mode='wt') as f:
            f.write(INFILE_CONTENTS)

        self.inst = SupervisorConfig(infile_path=self.infile_path,
                                     outfile_path=self.outfile_path)

    def tearDown(self):
        remove(self.infile_path)
        remove(self.outfile_path)

    @patch('ona_service.supervisor_config.getenv', mock_getenv)
    def test_sections(self):
        self.inst.update()
        actual = self.inst.config.sections()
        expected = [
            'supervisord',
            'program:ona-pna-monitor_eth0',
            'program:ona-pna-monitor_eth1',
            'program:ona-pna-pusher',
            'program:ona-netflow-monitor',
            'program:ona-netflow-pusher',
        ]
        self.assertItemsEqual(actual, expected)

    @patch('ona_service.supervisor_config.getenv', mock_getenv)
    def test_standard_program(self):
        self.inst.update()

        actual = dict(self.inst.config.items('program:ona-netflow-pusher'))

        expected = DEFAULT_PARAMETERS.copy()
        expected['command'] = ' '.join(PROGRAM_COMMANDS['ona-netflow-pusher'])
        expected['stdout_logfile'] = LOG_PATH.format('ona-netflow-pusher')

        self.assertEqual(actual, expected)

    @patch('ona_service.supervisor_config.getenv', mock_getenv)
    def test_custom_program(self):
        self.inst.update()

        actual = dict(self.inst.config.items('program:ona-pna-monitor_eth1'))

        expected = PROGRAM_PARAMETERS['ona-pna-monitor'].copy()
        expected['command'] = ' '.join(PROGRAM_COMMANDS['ona-pna-monitor'] +
                                       ['eth1'])

        self.assertEqual(actual, expected)

    @patch('ona_service.supervisor_config.getenv', mock_getenv)
    def test_write(self):
        self.inst.update()
        self.inst.write()

        new_config = RawConfigParser()
        new_config.read(self.outfile_path)

        actual = new_config.sections()
        expected = self.inst.config.sections()
        self.assertItemsEqual(actual, expected)

        for section in new_config.sections():
            actual = dict(new_config.items(section))
            expected = dict(self.inst.config.items(section))
            self.assertEqual(actual, expected)
Beispiel #2
0
class SupervisorConfigTestCase(TestCase):
    def setUp(self):
        self.infile_path = NamedTemporaryFile(delete=False).name
        self.outfile_path = NamedTemporaryFile(delete=False).name

        with io.open(self.infile_path, mode='wt') as f:
            f.write(INFILE_CONTENTS)

        self.inst = SupervisorConfig(
            infile_path=self.infile_path, outfile_path=self.outfile_path
        )

    def tearDown(self):
        remove(self.infile_path)
        remove(self.outfile_path)

    @patch('ona_service.supervisor_config.getenv', mock_getenv)
    def test_sections(self):
        self.inst.update()
        actual = self.inst.config.sections()
        expected = [
            'supervisord',
            'program:ona-pna-monitor_eth0',
            'program:ona-pna-monitor_eth1',
            'program:ona-pna-pusher',
            'program:ona-netflow-monitor',
            'program:ona-netflow-pusher',
        ]
        self.assertItemsEqual(actual, expected)

    @patch('ona_service.supervisor_config.getenv', mock_getenv)
    def test_standard_program(self):
        self.inst.update()

        actual = dict(self.inst.config.items('program:ona-netflow-pusher'))

        expected = DEFAULT_PARAMETERS.copy()
        expected['command'] = ' '.join(PROGRAM_COMMANDS['ona-netflow-pusher'])
        expected['stdout_logfile'] = LOG_PATH.format('ona-netflow-pusher')

        self.assertEqual(actual, expected)

    @patch('ona_service.supervisor_config.getenv', mock_getenv)
    def test_custom_program(self):
        self.inst.update()

        actual = dict(self.inst.config.items('program:ona-pna-monitor_eth1'))

        expected = PROGRAM_PARAMETERS['ona-pna-monitor'].copy()
        expected['command'] = ' '.join(
            PROGRAM_COMMANDS['ona-pna-monitor'] + ['eth1']
        )

        self.assertEqual(actual, expected)

    @patch('ona_service.supervisor_config.getenv', mock_getenv)
    def test_write(self):
        self.inst.update()
        self.inst.write()

        new_config = RawConfigParser()
        new_config.read(self.outfile_path)

        actual = new_config.sections()
        expected = self.inst.config.sections()
        self.assertItemsEqual(actual, expected)

        for section in new_config.sections():
            actual = dict(new_config.items(section))
            expected = dict(self.inst.config.items(section))
            self.assertEqual(actual, expected)
Beispiel #3
0
class SupervisorConfigTestCase(TestCase):
    def setUp(self):
        self.infile_path = NamedTemporaryFile(delete=False).name
        self.outfile_path = NamedTemporaryFile(delete=False).name

        with io.open(self.infile_path, mode='wt') as f:
            f.write(INFILE_CONTENTS)

        self.inst = SupervisorConfig(infile_path=self.infile_path,
                                     outfile_path=self.outfile_path)

    def tearDown(self):
        remove(self.infile_path)
        remove(self.outfile_path)

    def test_module(self):
        # Ensure that Supervisor is import-able
        import supervisor.supervisord
        self.assertEqual(supervisor.supervisord.__name__,
                         'supervisor.supervisord')

    @patch('ona_service.supervisor_config.getenv', mock_getenv)
    def test_sections(self):
        self.inst.update()
        actual = self.inst.config.sections()
        expected = [
            'supervisord',
            'program:ona-pna-monitor_eth0',
            'program:ona-pna-monitor_eth1',
            'program:ona-pna-pusher',
            'program:ona-ipfix-monitor',
            'program:ona-yaf-monitor_eth0-4739',
            'program:ona-yaf-monitor_eth1-4740',
            'program:ona-ipfix-pusher',
            'program:ona-notification-publisher',
            'program:ona-pdns-monitor',
            'program:ona-pdns-pusher',
        ]
        self.assertItemsEqual(actual, expected)

    @patch('ona_service.supervisor_config.getenv', mock_getenv)
    def test_standard_program(self):
        self.inst.update()

        actual = dict(
            self.inst.config.items('program:ona-notification-publisher'))

        expected = DEFAULT_PARAMETERS.copy()
        args = PROGRAM_COMMANDS['ona-notification-publisher']
        expected['command'] = ' '.join('"{}"'.format(x) for x in args)
        expected['stdout_logfile'] = LOG_PATH.format(
            'ona-notification-publisher')

        self.assertEqual(actual, expected)

    @patch('ona_service.supervisor_config.getenv', mock_getenv)
    def test_pna(self):
        self.inst.update()

        actual = dict(self.inst.config.items('program:ona-pna-monitor_eth1'))

        expected = PROGRAM_PARAMETERS['ona-pna-monitor'].copy()
        args = PROGRAM_COMMANDS['ona-pna-monitor'] + ['eth1']
        expected['command'] = ' '.join('"{}"'.format(x) for x in args)

        self.assertEqual(actual, expected)

    @patch('ona_service.supervisor_config.getenv', mock_getenv)
    def test_yaf(self):
        self.inst.update()

        actual = dict(
            self.inst.config.items('program:ona-yaf-monitor_eth1-4740'))

        expected = DEFAULT_PARAMETERS.copy()
        args = PROGRAM_COMMANDS['ona-yaf-monitor'] + ['eth1', '4740']
        expected['command'] = ' '.join('"{}"'.format(x) for x in args)
        expected['stdout_logfile'] = LOG_PATH.format('ona-yaf-monitor')

        self.assertEqual(actual, expected)

    @patch('ona_service.supervisor_config.getenv', mock_getenv)
    def test_write(self):
        self.inst.update()
        self.inst.write()

        new_config = RawConfigParser()
        new_config.read(self.outfile_path)

        actual = new_config.sections()
        expected = self.inst.config.sections()
        self.assertItemsEqual(actual, expected)

        for section in new_config.sections():
            actual = dict(new_config.items(section))
            expected = dict(self.inst.config.items(section))
            self.assertEqual(actual, expected)