Skip to content

Commit

Permalink
adding chroot options
Browse files Browse the repository at this point in the history
  • Loading branch information
Keisuke Kawahara committed Jun 25, 2012
1 parent a85d36e commit 7ea3ff9
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/redis_failover/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ def self.parse(source)
options[:config_file] = file
end

opts.on('--with-chroot ROOT', 'Path to ZooKeepers chroot') do |chroot|
options[:chroot] = chroot
end

opts.on('-E', '--environment ENV', 'Config environment to use') do |config_env|
options[:config_environment] = config_env
end
Expand Down
2 changes: 1 addition & 1 deletion lib/redis_failover/node_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def shutdown
# Configures the ZooKeeper client.
def setup_zk
@zk.close! if @zk
@zk = ZK.new(@options[:zkservers])
@zk = ZK.new("#{@options[:zkservers]}#{@options[:chroot] || ''}")

@zk.register(@manual_znode) do |event|
@mutex.synchronize do
Expand Down
24 changes: 24 additions & 0 deletions spec/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ module RedisFailover
opts[:max_failures].should == 1
end

it 'properly parses a chroot' do
opts = CLI.parse(['-n host:port', '-z localhost:1111', '--with-chroot', '/with/chroot/from/command/line'])
opts[:nodes].should == [{
:host => 'host',
:port => 'port',
}]

opts[:chroot].should == '/with/chroot/from/command/line'
end

it 'properly parses the config file' do
opts = CLI.parse(['-C', "#{File.dirname(__FILE__)}/support/config/single_environment.yml"])
opts[:zkservers].should == 'zk01:2181,zk02:2181,zk03:2181'
Expand All @@ -46,6 +56,20 @@ module RedisFailover
opts = CLI.parse(['-C', "#{File.dirname(__FILE__)}/support/config/multiple_environments.yml", '-E', 'staging'])
opts[:zkservers].should == 'zk01:2181,zk02:2181,zk03:2181'
end

it 'properly parses the config file that include chroot' do
opts = CLI.parse(['-C', "#{File.dirname(__FILE__)}/support/config/single_environment_with_chroot.yml"])
opts[:zkservers].should == 'zk01:2181,zk02:2181,zk03:2181'
opts[:chroot].should == '/with/chroot'

opts = CLI.parse(['-C', "#{File.dirname(__FILE__)}/support/config/multiple_environments_with_chroot.yml", '-E', 'development'])
opts[:zkservers].should == 'localhost:2181'
opts[:chroot].should == '/with/chroot_development'

opts = CLI.parse(['-C', "#{File.dirname(__FILE__)}/support/config/multiple_environments_with_chroot.yml", '-E', 'staging'])
opts[:zkservers].should == 'zk01:2181,zk02:2181,zk03:2181'
opts[:chroot].should == '/with/chroot_staging'
end
end
end
end
17 changes: 17 additions & 0 deletions spec/support/config/multiple_environments_with_chroot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
:development:
:nodes:
- localhost:6379
- localhost:6389
:zkservers:
- localhost:2181
:chroot: /with/chroot_development

:staging:
:nodes:
- redis01:6379
- redis02:6379
:zkservers:
- zk01:2181
- zk02:2181
- zk03:2181
:chroot: /with/chroot_staging
8 changes: 8 additions & 0 deletions spec/support/config/single_environment_with_chroot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
:nodes:
- redis01:6379
- redis02:6379
:zkservers:
- zk01:2181
- zk02:2181
- zk03:2181
:chroot: /with/chroot

0 comments on commit 7ea3ff9

Please sign in to comment.