def test_channel_stopped(self): plugin = NginxPlugin() locations_dirname = self.make_temp_dir() plugin.start_plugin( { 'server_name': 'http//www.example.org', 'vhost_file': self.make_temp_file(), 'locations_dir': locations_dirname }, JunebugConfig({})) properties = self.create_channel_properties(config={ 'web_path': '/foo/bar', 'web_port': 2323, }) channel = yield self.create_channel(self.service, self.redis, id='chan4', properties=properties) plugin.channel_started(channel) self.assertTrue(path.exists(path.join(locations_dirname, 'chan4.conf'))) plugin.channel_stopped(channel) self.assertFalse( path.exists(path.join(locations_dirname, 'chan4.conf')))
def test_channel_started_custom_template(self): plugin = NginxPlugin() locations_dirname = self.make_temp_dir() location_template_filename = self.make_temp_file() write(location_template_filename, '%(external_path)s') plugin.start_plugin( { 'server_name': 'http//www.example.org', 'vhost_file': self.make_temp_file(), 'locations_dir': locations_dirname, 'location_template': location_template_filename }, JunebugConfig({})) properties = self.create_channel_properties(config={ 'web_path': '/foo/bar', 'web_port': 2323, }) channel = yield self.create_channel(self.service, self.redis, id='chan4', properties=properties) plugin.channel_started(channel) self.assertEqual(read(path.join(locations_dirname, 'chan4.conf')), '/foo/bar')
def test_channel_stopped_irrelevant_channel_nginx_reload(self): plugin = NginxPlugin() plugin.start_plugin( { 'server_name': 'http//www.example.org', 'vhost_file': self.make_temp_file(), 'locations_dir': self.make_temp_dir() }, JunebugConfig({})) properties = self.create_channel_properties(web_path='/foo/bar', web_port=2323) chan4 = yield self.create_channel(self.service, self.redis, id='chan4', properties=properties) chan5 = yield self.create_channel(self.service, self.redis, id='chan5', properties=properties) plugin.channel_started(chan4) calls = self.patch_subprocess_call(((['which', 'nginx'], 0), )) plugin.channel_stopped(chan4) plugin.channel_stopped(chan5) self.assertEqual(calls.count(['nginx', '-s', 'reload']), 1)
def test_channel_stopped_irrelevant_channel_nginx_reload(self): plugin = NginxPlugin() plugin.start_plugin( { 'server_name': 'http//www.example.org', 'vhost_file': self.make_temp_file(), 'locations_dir': self.make_temp_dir() }, JunebugConfig({})) properties = self.create_channel_properties(config={ 'web_path': '/foo/bar', 'web_port': 2323, }) chan4 = yield self.create_channel(self.service, self.redis, id='chan4', properties=properties) chan5 = yield self.create_channel(self.service, self.redis, id='chan5', properties=properties) plugin.channel_started(chan4) self.nginx_reloads() # flush reloads plugin.channel_stopped(chan4) plugin.channel_stopped(chan5) self.assertEqual(self.nginx_reloads(), 1)
def test_channel_started(self): plugin = NginxPlugin() locations_dirname = self.make_temp_dir() plugin.start_plugin( { 'server_name': 'http//www.example.org', 'vhost_file': self.make_temp_file(), 'locations_dir': locations_dirname }, JunebugConfig({})) properties = self.create_channel_properties(web_path='/foo/bar', web_port=2323) channel = yield self.create_channel(self.service, self.redis, id='chan4', properties=properties) plugin.channel_started(channel) self.assertEqual( read(path.join(locations_dirname, 'chan4.conf')), read(plugin.config.location_template) % { 'external_path': '/foo/bar', 'internal_url': 'http://localhost:2323/foo/bar' })
def test_channel_started_no_nginx_found(self): self.patch_logger() calls = self.patch_subprocess_call(((['which', 'nginx'], 1), )) plugin = NginxPlugin() plugin.start_plugin( { 'server_name': 'http//www.example.org', 'vhost_file': self.make_temp_file(), 'locations_dir': self.make_temp_dir() }, JunebugConfig({})) properties = self.create_channel_properties(web_path='/foo/bar', web_port=2323) channel = yield self.create_channel(self.service, self.redis, properties=properties) self.assertEqual(calls.count(['nginx', '-s', 'reload']), 0) plugin.channel_started(channel) self.assertEqual(calls.count(['nginx', '-s', 'reload']), 0) self.assert_was_logged('Cannot reload nginx, nginx not found in path')
def create_channel_config(self, **kw): self.persistencehelper = PersistenceHelper() yield self.persistencehelper.setup() self.addCleanup(self.persistencehelper.cleanup) config = deepcopy(self.default_channel_config) config.update(kw) channel_config = self.persistencehelper.mk_config(config) channel_config['redis'] = channel_config['redis_manager'] returnValue(JunebugConfig(channel_config))
def test_start_service(self): service = JunebugService( JunebugConfig({ 'host': '127.0.0.1', 'port': 0, })) yield service.startService() server = service._port self.assertTrue(server.connected) yield service.stopService() self.assertFalse(server.connected)
def test_start_plugin_nginx_reload(self): plugin = NginxPlugin() self.assertEqual(self.nginx_reloads(), 0) plugin.start_plugin( { 'server_name': 'http//www.example.org', 'vhost_file': self.make_temp_file(), 'locations_dir': self.make_temp_dir() }, JunebugConfig({})) self.assertEqual(self.nginx_reloads(), 1)
def test_stop_plugin_remove_vhost_config(self): plugin = NginxPlugin() vhost_filename = self.make_temp_file() plugin.start_plugin( { 'server_name': 'http//www.example.org', 'vhost_file': vhost_filename, 'locations_dir': self.make_temp_dir() }, JunebugConfig({})) self.assertTrue(path.exists(vhost_filename)) plugin.stop_plugin() self.assertFalse(path.exists(vhost_filename))
def config_from_args(args): args = omit_nones(args) config = load_config(args.pop('config_filename', None)) config['redis'] = parse_redis(config.get('redis', {}), args) config['amqp'] = parse_amqp(config.get('amqp', {}), args) parse_channels(args) args['plugins'] = parse_plugins(config.get('plugins', []), args) combined = conjoin(config, args) # max_log_files == 0 means that no limit should be set, so we need to set # it to `None` for that case combined['max_log_files'] = combined.get('max_log_files') or None return JunebugConfig(combined)
def test_start_plugin_create_vhost_config_custom_template(self): plugin = NginxPlugin() vhost_filename = self.make_temp_file() vhost_template_filename = self.make_temp_file() write(vhost_template_filename, '%(server_name)s') plugin.start_plugin( { 'server_name': 'http//www.example.org', 'vhost_file': vhost_filename, 'locations_dir': self.make_temp_dir(), 'vhost_template': vhost_template_filename, }, JunebugConfig({})) self.assertEqual(read(vhost_filename), 'http//www.example.org')
def test_start_server(self): '''Starting the server should listen on the specified interface and port''' redis = yield self.get_redis() config = JunebugConfig({ 'port': 0, 'interface': 'localhost', 'redis': redis._config, }) service = yield start_server(config) port = service._port host = port.getHost() self.assertEqual(host.host, '127.0.0.1') self.assertEqual(host.type, 'TCP') self.assertTrue(host.port > 0) yield service.stopService()
def test_start_plugin_create_vhost_config(self): plugin = NginxPlugin() locations_dirname = self.make_temp_dir() vhost_filename = self.make_temp_file() plugin.start_plugin( { 'server_name': 'http//www.example.org', 'vhost_file': vhost_filename, 'locations_dir': locations_dirname }, JunebugConfig({})) self.assertEqual( read(vhost_filename), read(plugin.config.vhost_template) % { 'server_name': 'http//www.example.org', 'includes': path.join(locations_dirname, '*.conf') })
def test_channel_started_non_http(self): plugin = NginxPlugin() locations_dirname = self.make_temp_dir() plugin.start_plugin( { 'server_name': 'http//www.example.org', 'vhost_file': self.make_temp_file(), 'locations_dir': locations_dirname }, JunebugConfig({})) channel = yield self.create_channel(self.service, self.redis, id='chan4') plugin.channel_started(channel) self.assertFalse( path.exists(path.join(locations_dirname, 'chan4.conf')))
def test_channel_stopped_irrelevant_channels(self): plugin = NginxPlugin() locations_dirname = self.make_temp_dir() plugin.start_plugin( { 'server_name': 'http//www.example.org', 'vhost_file': self.make_temp_file(), 'locations_dir': locations_dirname }, JunebugConfig({})) properties = self.create_channel_properties(web_path='/foo/bar', web_port=2323) chan4 = yield self.create_channel(self.service, self.redis, id='chan4', properties=properties) chan5 = yield self.create_channel(self.service, self.redis, id='chan5', properties=properties) write(path.join(locations_dirname, 'chan5.conf'), 'foo') plugin.channel_started(chan4) self.assertTrue(path.exists(path.join(locations_dirname, 'chan4.conf'))) self.assertTrue(path.exists(path.join(locations_dirname, 'chan5.conf'))) plugin.channel_stopped(chan4) plugin.channel_stopped(chan5) self.assertFalse( path.exists(path.join(locations_dirname, 'chan4.conf'))) self.assertTrue(path.exists(path.join(locations_dirname, 'chan5.conf')))
def test_channel_started_ensure_dir(self): plugin = NginxPlugin() locations_dirname = path.join(self.make_temp_dir(), 'a/b/c') plugin.start_plugin( { 'server_name': 'http//www.example.org', 'vhost_file': self.make_temp_file(), 'locations_dir': locations_dirname }, JunebugConfig({})) properties = self.create_channel_properties(web_path='/foo/bar', web_port=2323) channel = yield self.create_channel(self.service, self.redis, id='chan4', properties=properties) plugin.channel_started(channel) self.assertTrue(path.exists(locations_dirname))