specinfra 2.0.0.beta8 → 2.0.0.beta9

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: 50a10980f138ec879c1ac3a5c120188071418ad9
4
- data.tar.gz: d993a25a4be1bea047667287d3d35dd39dc32a9e
3
+ metadata.gz: 572f8250ba4ca99acbaa3740b61bb646103cd041
4
+ data.tar.gz: d8cec18e50e69cd12c3186dbcbc7835e8896df93
5
5
  SHA512:
6
- metadata.gz: b2338c5dc61527407961299803bbdb2779e0d39fe878afce5eadf65914166727af1250cb748fd984d90e3e3339f82d171b7c684c91fe42ff4119c22e9ce6e035
7
- data.tar.gz: 09cf549373c2c63725169e4fa0de1e7fa2ad00ed1772602a53af34fcb9c1390d8b4f1e864377402b269bcc8ed98f0a33a0f3a2406e6ae805d82bce8395aae79f
6
+ metadata.gz: 7250feadcc58c2e9672a5e5580674b2283cbb2c5109ee8e3c7b3ec330e83985d3494d39c332c8ea1825ebd211f82e7a1ddafae6c7468a2c43dc94cdfa3a84518
7
+ data.tar.gz: a8e345e42bb720faa2d8001e17513d2b76ccc0c3135884aa0beff203f9681d04542f169b5101fbc7ff0a96925d855092f0f7f70c51cf9562713da17b6f6910ab
@@ -1,5 +1,6 @@
1
1
  require 'singleton'
2
2
  require 'specinfra/command_result'
3
+ require 'specinfra/command/processor'
3
4
 
4
5
  module Specinfra
5
6
  module Backend
@@ -22,12 +23,15 @@ module Specinfra
22
23
  run_command(commands.send(cmd, *args)).success?
23
24
  end
24
25
 
25
- # Default action is to call check_zero with args
26
26
  def method_missing(meth, *args, &block)
27
- if meth.to_s =~ /^check/
28
- check_zero(meth, *args)
27
+ if os[:family] == 'windows'
28
+ if meth.to_s =~ /^check/
29
+ backend.check_zero(meth, *args)
30
+ else
31
+ backend.run_command(commands.send(meth, *args))
32
+ end
29
33
  else
30
- run_command(commands.send(meth, *args))
34
+ Specinfra::Command::Processor.send(meth, *args)
31
35
  end
32
36
  end
33
37
  end
@@ -55,134 +55,6 @@ module Specinfra
55
55
  end
56
56
  end
57
57
 
58
- def check_service_is_running(service)
59
- ret = run_command(commands.check_service_is_running(service))
60
-
61
- # In Ubuntu, some services are under upstart and "service foo status" returns
62
- # exit status 0 even though they are stopped.
63
- # So return false if stdout contains "stopped/waiting".
64
- return false if ret.stdout =~ /stopped\/waiting/
65
-
66
- # If the service is not registered, check by ps command
67
- if ret.exit_status == 1
68
- ret = run_command(commands.check_process_is_running(service))
69
- end
70
-
71
- ret.success?
72
- end
73
-
74
- def check_service_is_monitored_by_monit(process)
75
- ret = run_command(commands.check_service_is_monitored_by_monit(process))
76
- return false unless ret.stdout != nil && ret.success?
77
-
78
- retlines = ret.stdout.split(/[\r\n]+/).map(&:strip)
79
- proc_index = retlines.index("Process '#{process}'")
80
- return false unless proc_index
81
-
82
- retlines[proc_index+2].match(/\Amonitoring status\s+monitored\Z/i) != nil
83
- end
84
-
85
- def check_file_is_readable(file, by_whom)
86
- mode = sprintf('%04s',run_command(commands.get_file_mode(file)).stdout.strip)
87
- mode = mode.split('')
88
- mode_octal = mode[0].to_i * 512 + mode[1].to_i * 64 + mode[2].to_i * 8 + mode[3].to_i * 1
89
- case by_whom
90
- when nil
91
- mode_octal & 0444 != 0
92
- when 'owner'
93
- mode_octal & 0400 != 0
94
- when 'group'
95
- mode_octal & 0040 != 0
96
- when 'others'
97
- mode_octal & 0004 != 0
98
- end
99
- end
100
-
101
- def check_file_is_writable(file, by_whom)
102
- mode = sprintf('%04s',run_command(commands.get_file_mode(file)).stdout.strip)
103
- mode = mode.split('')
104
- mode_octal = mode[0].to_i * 512 + mode[1].to_i * 64 + mode[2].to_i * 8 + mode[3].to_i * 1
105
- case by_whom
106
- when nil
107
- mode_octal & 0222 != 0
108
- when 'owner'
109
- mode_octal & 0200 != 0
110
- when 'group'
111
- mode_octal & 0020 != 0
112
- when 'others'
113
- mode_octal & 0002 != 0
114
- end
115
- end
116
-
117
- def check_file_is_executable(file, by_whom)
118
- mode = sprintf('%04s',run_command(commands.get_file_mode(file)).stdout.strip)
119
- mode = mode.split('')
120
- mode_octal = mode[0].to_i * 512 + mode[1].to_i * 64 + mode[2].to_i * 8 + mode[3].to_i * 1
121
- case by_whom
122
- when nil
123
- mode_octal & 0111 != 0
124
- when 'owner'
125
- mode_octal & 0100 != 0
126
- when 'group'
127
- mode_octal & 0010 != 0
128
- when 'others'
129
- mode_octal & 0001 != 0
130
- end
131
- end
132
-
133
- def check_file_is_mounted(path, expected_attr, only_with)
134
- ret = run_command(commands.check_file_is_mounted(path))
135
- if expected_attr.nil? || ret.failure?
136
- return ret.success?
137
- end
138
-
139
- mount = ret.stdout.scan(/\S+/)
140
- actual_attr = { :device => mount[0], :type => mount[4] }
141
- mount[5].gsub(/\(|\)/, '').split(',').each do |option|
142
- name, val = option.split('=')
143
- if val.nil?
144
- actual_attr[name.to_sym] = true
145
- else
146
- val = val.to_i if val.match(/^\d+$/)
147
- actual_attr[name.to_sym] = val
148
- end
149
- end
150
-
151
- if ! expected_attr[:options].nil?
152
- expected_attr.merge!(expected_attr[:options])
153
- expected_attr.delete(:options)
154
- end
155
-
156
- if only_with
157
- actual_attr == expected_attr
158
- else
159
- expected_attr.each do |key, val|
160
- return false if actual_attr[key] != val
161
- end
162
- true
163
- end
164
- end
165
-
166
- def check_routing_table_has_entry(expected_attr)
167
- return false if ! expected_attr[:destination]
168
- ret = run_command(commands.check_routing_table_has_entry(expected_attr[:destination]))
169
- return false if ret.failure?
170
-
171
- ret.stdout.gsub!(/\r\n/, "\n")
172
-
173
- ret.stdout =~ /^(\S+)(?: via (\S+))? dev (\S+).+\n(?:default via (\S+))?/
174
- actual_attr = {
175
- :destination => $1,
176
- :gateway => $2 ? $2 : $4,
177
- :interface => expected_attr[:interface] ? $3 : nil
178
- }
179
-
180
- expected_attr.each do |key, val|
181
- return false if actual_attr[key] != val
182
- end
183
- true
184
- end
185
-
186
58
  def copy_file(from, to)
187
59
  begin
188
60
  FileUtils.cp(from, to)
@@ -0,0 +1,139 @@
1
+ module Specinfra::Command
2
+ class Processor
3
+ def self.method_missing(meth, *args, &block)
4
+ if meth.to_s =~ /^check/
5
+ backend.check_zero(meth, *args)
6
+ else
7
+ backend.run_command(commands.send(meth, *args))
8
+ end
9
+ end
10
+
11
+ def self.check_service_is_running(service)
12
+ ret = backend.run_command(commands.check_service_is_running(service))
13
+
14
+ # In Ubuntu, some services are under upstart and "service foo status" returns
15
+ # exit status 0 even though they are stopped.
16
+ # So return false if stdout contains "stopped/waiting".
17
+ return false if ret.stdout =~ /stopped\/waiting/
18
+
19
+ # If the service is not registered, check by ps command
20
+ if ret.exit_status == 1
21
+ ret = backend.run_command(commands.check_process_is_running(service))
22
+ end
23
+
24
+ ret.success?
25
+ end
26
+
27
+ def self.check_service_is_monitored_by_monit(process)
28
+ ret = backend.run_command(commands.check_service_is_monitored_by_monit(process))
29
+ return false unless ret.stdout != nil && ret.success?
30
+
31
+ retlines = ret.stdout.split(/[\r\n]+/).map(&:strip)
32
+ proc_index = retlines.index("Process '#{process}'")
33
+ return false unless proc_index
34
+
35
+ retlines[proc_index+2].match(/\Amonitoring status\s+monitored\Z/i) != nil
36
+ end
37
+
38
+ def self.check_file_is_readable(file, by_whom)
39
+ mode = sprintf('%04s',backend.run_command(commands.get_file_mode(file)).stdout.strip)
40
+ mode = mode.split('')
41
+ mode_octal = mode[0].to_i * 512 + mode[1].to_i * 64 + mode[2].to_i * 8 + mode[3].to_i * 1
42
+ case by_whom
43
+ when nil
44
+ mode_octal & 0444 != 0
45
+ when 'owner'
46
+ mode_octal & 0400 != 0
47
+ when 'group'
48
+ mode_octal & 0040 != 0
49
+ when 'others'
50
+ mode_octal & 0004 != 0
51
+ end
52
+ end
53
+
54
+ def self.check_file_is_writable(file, by_whom)
55
+ mode = sprintf('%04s',backend.run_command(commands.get_file_mode(file)).stdout.strip)
56
+ mode = mode.split('')
57
+ mode_octal = mode[0].to_i * 512 + mode[1].to_i * 64 + mode[2].to_i * 8 + mode[3].to_i * 1
58
+ case by_whom
59
+ when nil
60
+ mode_octal & 0222 != 0
61
+ when 'owner'
62
+ mode_octal & 0200 != 0
63
+ when 'group'
64
+ mode_octal & 0020 != 0
65
+ when 'others'
66
+ mode_octal & 0002 != 0
67
+ end
68
+ end
69
+
70
+ def self.check_file_is_executable(file, by_whom)
71
+ mode = sprintf('%04s',backend.run_command(commands.get_file_mode(file)).stdout.strip)
72
+ mode = mode.split('')
73
+ mode_octal = mode[0].to_i * 512 + mode[1].to_i * 64 + mode[2].to_i * 8 + mode[3].to_i * 1
74
+ case by_whom
75
+ when nil
76
+ mode_octal & 0111 != 0
77
+ when 'owner'
78
+ mode_octal & 0100 != 0
79
+ when 'group'
80
+ mode_octal & 0010 != 0
81
+ when 'others'
82
+ mode_octal & 0001 != 0
83
+ end
84
+ end
85
+
86
+ def self.check_file_is_mounted(path, expected_attr, only_with)
87
+ ret = backend.run_command(commands.check_file_is_mounted(path))
88
+ if expected_attr.nil? || ret.failure?
89
+ return ret.success?
90
+ end
91
+
92
+ mount = ret.stdout.scan(/\S+/)
93
+ actual_attr = { :device => mount[0], :type => mount[4] }
94
+ mount[5].gsub(/\(|\)/, '').split(',').each do |option|
95
+ name, val = option.split('=')
96
+ if val.nil?
97
+ actual_attr[name.to_sym] = true
98
+ else
99
+ val = val.to_i if val.match(/^\d+$/)
100
+ actual_attr[name.to_sym] = val
101
+ end
102
+ end
103
+
104
+ if ! expected_attr[:options].nil?
105
+ expected_attr.merge!(expected_attr[:options])
106
+ expected_attr.delete(:options)
107
+ end
108
+
109
+ if only_with
110
+ actual_attr == expected_attr
111
+ else
112
+ expected_attr.each do |key, val|
113
+ return false if actual_attr[key] != val
114
+ end
115
+ true
116
+ end
117
+ end
118
+
119
+ def self.check_routing_table_has_entry(expected_attr)
120
+ return false if ! expected_attr[:destination]
121
+ ret = backend.run_command(commands.check_routing_table_has_entry(expected_attr[:destination]))
122
+ return false if ret.failure?
123
+
124
+ ret.stdout.gsub!(/\r\n/, "\n")
125
+
126
+ ret.stdout =~ /^(\S+)(?: via (\S+))? dev (\S+).+\n(?:default via (\S+))?/
127
+ actual_attr = {
128
+ :destination => $1,
129
+ :gateway => $2 ? $2 : $4,
130
+ :interface => expected_attr[:interface] ? $3 : nil
131
+ }
132
+
133
+ expected_attr.each do |key, val|
134
+ return false if actual_attr[key] != val
135
+ end
136
+ true
137
+ end
138
+ end
139
+ end
@@ -1,3 +1,3 @@
1
1
  module Specinfra
2
- VERSION = "2.0.0.beta8"
2
+ VERSION = "2.0.0.beta9"
3
3
  end
@@ -34,18 +34,6 @@ build:
34
34
  name: Run rake spec:centos65
35
35
  code: rake spec:centos65
36
36
  cwd: $WORKING_DIR
37
- - script:
38
- name: Run vagrant up centos70
39
- code: vagrant up centos70 --provider=digital_ocean
40
- cwd: $WORKING_DIR
41
- - script:
42
- name: Run vagrant reload centos70
43
- code: vagrant reload centos70
44
- cwd: $WORKING_DIR
45
- - script:
46
- name: Run rake spec:centos70
47
- code: rake spec:centos70
48
- cwd: $WORKING_DIR
49
37
  - script:
50
38
  name: Run vagrant up ubuntu1404
51
39
  code: vagrant up ubuntu1404 --provider=digital_ocean
@@ -64,10 +52,6 @@ build:
64
52
  name: Run vagrant destroy centos65
65
53
  code: vagrant destroy centos65 --force
66
54
  cwd: $WORKING_DIR
67
- - script:
68
- name: Run vagrant destroy centos70
69
- code: vagrant destroy centos70 --force
70
- cwd: $WORKING_DIR
71
55
  - script:
72
56
  name: Run vagrant destroy ubuntu1404
73
57
  code: vagrant destroy ubuntu1404 --force
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: specinfra
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta8
4
+ version: 2.0.0.beta9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gosuke Miyashita
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-23 00:00:00.000000000 Z
11
+ date: 2014-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh
@@ -206,6 +206,7 @@ files:
206
206
  - lib/specinfra/command/plamo/base.rb
207
207
  - lib/specinfra/command/plamo/base/package.rb
208
208
  - lib/specinfra/command/plamo/base/service.rb
209
+ - lib/specinfra/command/processor.rb
209
210
  - lib/specinfra/command/redhat.rb
210
211
  - lib/specinfra/command/redhat/base.rb
211
212
  - lib/specinfra/command/redhat/base/file.rb