is_master 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 95addbb0d7882dea2b0c89407e2eafcaac273db9
4
- data.tar.gz: 29930f30a84441d6dd17b07c535c1c3e3fd69b8f
3
+ metadata.gz: f8d446a1bbdb34413d0769717d31ba5be21f829b
4
+ data.tar.gz: 829cc0ec8b33b49ded5dc833922726fbc4fc77c2
5
5
  SHA512:
6
- metadata.gz: 613d77a498bbaaec34a570cdce9e1c0a7c1962599cf8d13d78c50d7088e09f5fc991d53f9227f5860120b0f90075ffd590519cd962742c758b9238300ba3f468
7
- data.tar.gz: 7ceb81a73cd6aca6df41351f0fc5be554d24b33d04b5cd2f44c9c22c845e60fcf9a43d9df06f60e5b17c3fd3a85de6dfb7f153364370ade53eb55f9e4401c60c
6
+ metadata.gz: 79fb48be507c41b7913d37ffbd74adb26ae3b0d857e6381091e9a6801f4d51bdd24074818c3cfccbb15a51c63db16ab1f92163ea95a9370a40ba5a0d7c8160d0
7
+ data.tar.gz: 1460fc60be1aa17ec7a8a35055d1a2add71f140c9e8af0e771002c7011742e54eade8fde2dd99f3713ed0a8aaa7c55e7dc1b300e31a13eb1855c20c79862b5b4
@@ -21,4 +21,5 @@ gem build is_master.gemspec
21
21
  gem install "is_master-$(cat VERSION).gem"
22
22
 
23
23
  rubocop
24
- ruby ./test/test_cli.rb
24
+ ruby ./test/test_cli_master.rb
25
+ ruby ./test/test_cli_slave.rb
@@ -6,10 +6,13 @@ AllCops:
6
6
  - Vagrantfile
7
7
  TargetRubyVersion: 2.3
8
8
 
9
+ Gemspec/RequiredRubyVersion:
10
+ Enabled: false
11
+
9
12
  Naming/AccessorMethodName:
10
13
  Enabled: false
11
14
 
12
- Lint/RescueWithoutErrorClass:
15
+ Style/RescueStandardError:
13
16
  Enabled: false
14
17
 
15
18
  Metrics/LineLength:
@@ -1,9 +1,10 @@
1
1
  language: ruby
2
2
  dist: precise
3
3
  rvm:
4
- - 2.4.2
5
- - 2.3.5
6
- - 2.2.8
4
+ - 2.5.0
5
+ - 2.4.3
6
+ - 2.3.6
7
+ - 2.2.9
7
8
  - 2.1.10
8
9
  install:
9
10
  - bundle install
@@ -11,4 +12,5 @@ install:
11
12
  - gem install is_master-$(cat VERSION).gem
12
13
  script:
13
14
  - rubocop
14
- - ruby ./test/test_cli.rb
15
+ - ruby ./test/test_cli_master.rb
16
+ - ruby ./test/test_cli_slave.rb
@@ -1,4 +1,8 @@
1
1
  # CHANGELOG
2
+ ## 1.2.0 (2018-02-24)
3
+
4
+ * add is_slave binary
5
+
2
6
  ## 1.1.0 (2017-12-15)
3
7
 
4
8
  * add expected file option
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  group :development do
4
- gem 'rubocop', '0.50.0'
4
+ gem 'rubocop', '0.52.1'
5
5
  gem 'test-unit'
6
6
  end
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # is_master
2
- [![Version](https://img.shields.io/badge/latest_version-1.1.0-green.svg)](https://github.com/nishiki/is_master/releases)
2
+ [![Gem Version](https://badge.fury.io/rb/is_master.svg)](https://badge.fury.io/rb/is_master)
3
3
  [![Build Status](https://travis-ci.org/nishiki/is_master.svg?branch=master)](https://travis-ci.org/nishiki/is_master)
4
4
  [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://github.com/nishiki/is_master/blob/master/LICENSE)
5
5
 
@@ -18,10 +18,14 @@ gem install is_master
18
18
  It's simple:
19
19
  ```
20
20
  is_master 10.0.254.2 ls -l
21
+ is_master /path/to/file ls -l
22
+ is_slave 10.0.254.2 ls -l
23
+ is_slave /path/to/file ls -l
21
24
  ```
22
- or
25
+
26
+ Output is `ls -l` result or:
23
27
  ```
24
- is_master /path/to/file ls -l
28
+ OK - I am slave, i going to sleep
25
29
  ```
26
30
 
27
31
  ## Development
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.2.0
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+
19
+ require 'socket'
20
+
21
+ if ARGV.length < 2
22
+ puts 'is_slave execute a command when it determine that server is slave'
23
+ puts "Usage: #{$PROGRAM_NAME} [VIP|FILE] COMMAND"
24
+ puts ' VIP - IP address expected to be master'
25
+ puts ' FILE - File expected to be master'
26
+ puts ' COMMAND - Command to execute if host is slave'
27
+ exit 2
28
+ end
29
+
30
+ expected = ARGV[0]
31
+ command = ARGV[1..-1].join(' ')
32
+
33
+ if !Socket.ip_address_list.map(&:ip_address).include?(expected) && !File.exist?(expected)
34
+ Kernel.exec(command)
35
+ else
36
+ puts 'OK - I am master, i going to sleep'
37
+ end
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.license = 'Apache-2.0'
12
12
 
13
13
  spec.files = %x(git ls-files -z).split("\x0")
14
- spec.executables = ['is_master']
14
+ spec.executables = %w[is_master is_slave]
15
15
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
16
  spec.require_paths = ['lib']
17
17
 
@@ -1,6 +1,6 @@
1
1
  require 'test/unit'
2
2
 
3
- class TestCli < Test::Unit::TestCase
3
+ class TestCliMaster < Test::Unit::TestCase
4
4
  def test_missing_arg
5
5
  output = %x(is_master 127.0.0.1)
6
6
  assert_match('Usage: ', output)
@@ -0,0 +1,33 @@
1
+ require 'test/unit'
2
+
3
+ class TestCliSlave < Test::Unit::TestCase
4
+ def test_missing_arg
5
+ output = %x(is_slave 127.0.0.1)
6
+ assert_match('Usage: ', output)
7
+
8
+ output = %x(is_slave)
9
+ assert_match('Usage: ', output)
10
+ end
11
+
12
+ def test_slave_mode
13
+ output = %x(is_slave 10.255.255.0 echo 'GOOD!')
14
+ assert_match('GOOD!', output)
15
+ end
16
+
17
+ def test_master_mode
18
+ output = %x(is_slave 127.0.0.1 echo 'GOOD!')
19
+ assert_match('I am master', output)
20
+ end
21
+
22
+ def test_file_slave_mode
23
+ output = %x(is_slave /tmp/test.txt echo 'GOOD!')
24
+ assert_match('GOOD!', output)
25
+ end
26
+
27
+ def test_file_master_mode
28
+ File.write('/tmp/test.txt', '')
29
+ output = %x(is_slave /tmp/test.txt echo 'GOOD!')
30
+ assert_match('I am master', output)
31
+ File.unlink('/tmp/test.txt')
32
+ end
33
+ end
metadata CHANGED
@@ -1,20 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: is_master
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrien Waksberg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-15 00:00:00.000000000 Z
11
+ date: 2018-02-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
15
15
  - is_master@yae.im
16
16
  executables:
17
17
  - is_master
18
+ - is_slave
18
19
  extensions: []
19
20
  extra_rdoc_files: []
20
21
  files:
@@ -29,8 +30,10 @@ files:
29
30
  - README.md
30
31
  - VERSION
31
32
  - bin/is_master
33
+ - bin/is_slave
32
34
  - is_master.gemspec
33
- - test/test_cli.rb
35
+ - test/test_cli_master.rb
36
+ - test/test_cli_slave.rb
34
37
  homepage: https://github.com/nishiki/is_master
35
38
  licenses:
36
39
  - Apache-2.0
@@ -51,9 +54,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
54
  version: '0'
52
55
  requirements: []
53
56
  rubyforge_project:
54
- rubygems_version: 2.6.11
57
+ rubygems_version: 2.6.14
55
58
  signing_key:
56
59
  specification_version: 4
57
60
  summary: is_master execute a command when it determine that server is master
58
61
  test_files:
59
- - test/test_cli.rb
62
+ - test/test_cli_master.rb
63
+ - test/test_cli_slave.rb