示例#1
0
    def test_should_load_file_if_config_file_present(self):
        with patch('data.options._parse_args') as args_mock:
            args_mock.return_value = {'config_file': 'dummy_file.ini'}
            with patch('data.options._parse_ini_file') as ini_mock:
                ini_mock.return_value = {
                    'failure':
                    False,
                    'successful_read':
                    True,
                    'server_configs': [{
                        'host': '192.168.1.23',
                        'password': '******',
                        'user': '******'
                    }, {
                        'host': '10.0.0.1',
                        'password': '******',
                        'user': '******'
                    }]
                }
                config = get_config()

        expectations = {
            'servers': [{
                'host': '192.168.1.23',
                'password': '******',
                'user': '******'
            }, {
                'host': '10.0.0.1',
                'password': '******',
                'user': '******'
            }]
        }

        self.assertEquals(expectations, config)
示例#2
0
    def test_should_exit_if_cannot_parse_config_file(self):
        with patch('data.options._parse_args') as args_mock:
            args_mock.return_value = {'config_file': 'dummy_file.ini'}
            with patch('data.options._parse_ini_file') as ini_mock:
                ini_mock.return_value = {'failure': True, 'successful_read': False, 
                                 'server_configs': []}

                old_stderr = sys.stderr
                sys.stderr = StringIO()
                try:
                    with self.assertRaises(SystemExit):
                        config = get_config()
                    
                    self.assertEquals("Could not parse 'dummy_file.ini'\n", sys.stderr.getvalue())
                finally:
                    sys.stderr = old_stderr
示例#3
0
    def test_should_exit_if_cannot_parse_config_file(self):
        with patch('data.options._parse_args') as args_mock:
            args_mock.return_value = {'config_file': 'dummy_file.ini'}
            with patch('data.options._parse_ini_file') as ini_mock:
                ini_mock.return_value = {
                    'failure': True,
                    'successful_read': False,
                    'server_configs': []
                }

                old_stderr = sys.stderr
                sys.stderr = StringIO()
                try:
                    with self.assertRaises(SystemExit):
                        config = get_config()

                    self.assertEquals("Could not parse 'dummy_file.ini'\n",
                                      sys.stderr.getvalue())
                finally:
                    sys.stderr = old_stderr
示例#4
0
 def test_should_load_file_if_config_file_present(self):
     with patch('data.options._parse_args') as args_mock:
         args_mock.return_value = {'config_file': 'dummy_file.ini'}
         with patch('data.options._parse_ini_file') as ini_mock:
             ini_mock.return_value = {'failure': False, 'successful_read': True, 
                              'server_configs': [{'host': '192.168.1.23', 
                              'password': '******', 'user': '******'}, 
                              {'host': '10.0.0.1', 'password': '******', 
                               'user': '******'}]
                             }
             config = get_config()
             
     
     expectations = {'servers': [
                     {'host': '192.168.1.23', 'password': '******', 
                      'user': '******'}, 
                     {'host': '10.0.0.1', 'password': '******', 
                      'user': '******'}]}
     
     
     self.assertEquals(expectations, config)
示例#5
0
    def test_should_remove_config_file_parameter(self, _parse_args_mock):
        _parse_args_mock.return_value = {'config_file': ''}

        config = get_config()

        self.assertEquals({}, config)
示例#6
0
 def test_should_remove_config_file_parameter(self, _parse_args_mock):
     _parse_args_mock.return_value = {'config_file': ''}
     
     config = get_config()
     
     self.assertEquals({}, config)
示例#7
0
def main(config, static_path):
    hostname = 'testing'
    monitor = WorkerMonitor()
    server_state = ServerState()
    if not config['test']:
        for server_config in config['servers']:
            add_server(monitor, server_config, server_state,
                       config['stat_window'])
        print('Started gathering varnish data')

    else:
        from tests.data_generator import DummyDataGenerator
        dummydata = DummyDataGenerator(server_state)
        worker = Worker('Testing', dummydata)
        monitor.add_worker(worker)

    Worker('WorkerMonitor', monitor).start()
    http_server.start(server_state, static_path, config['port'],
                      config['wsgi_server'])

    print('Simverest stopping...')
    monitor.stop()


if __name__ == "__main__":
    static_path = os.path.join(os.path.dirname(__file__), 'web', 'static')
    try:
        main(get_config(), static_path)
    except:
        pass
示例#8
0
    health = VarnishHealth(host, user, password, hostname, server_state)
    monitor.add_worker(Worker(health_name, health))

def main(config, static_path):
    hostname = 'testing'
    monitor = WorkerMonitor()
    server_state = ServerState()
    if not config['test']:
        for server_config in config['servers']:
            add_server(monitor, server_config, server_state, config['stat_window'])
        print('Started gathering varnish data')

    else:
        from tests.data_generator import DummyDataGenerator
        dummydata = DummyDataGenerator(server_state)
        worker = Worker('Testing', dummydata)
        monitor.add_worker(worker)

    Worker('WorkerMonitor', monitor).start()
    http_server.start(server_state, static_path, config['port'], config['wsgi_server'])

    print('Simverest stopping...')
    monitor.stop()

if __name__ == "__main__":
    static_path = os.path.join(os.path.dirname(__file__), 'web', 'static')
    try:
        main(get_config(), static_path)
    except:
        pass