houcho 0.0.10 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b59ced5d69133f301f1a65871fcb2cd8378ceaca
4
- data.tar.gz: 8ac6a107ea045d6353df58264fee06e99d527848
3
+ metadata.gz: c7c23a4ef5cf93e240094423d9ac76d943403b3f
4
+ data.tar.gz: 9194233d1018017bcdcdee212947f957c1b1c7c6
5
5
  SHA512:
6
- metadata.gz: fd397c0f4a66a9ad8327b83691cf2b0b77298c9611281c65835fcb9eab166fda6905c5c8de338d1b2ee10538f435c63460e1e2937011cc5740b2f39f265dc8c6
7
- data.tar.gz: 9ea002fe75a457d41f320a9eb38d9a53fb875a0bb4b6c0c645f877e1e374a600546c685bd1db0c6fd8b64d412975e579ae7bb5a11d574b58ef2a91b7eda6ab82
6
+ metadata.gz: 34ec4bece0fdbd4a3c67d4841c2d9351449b2d090065f992c9c7ce91ad88d263fd83f38ab2c8ca42b23c6d6dac90a581b323eb48a65b0a2ff796e9b105572a81
7
+ data.tar.gz: f78039031014a62a8f0afc7248c2fd4b249b9681e2f7f713cce724b4603d6c60e7a68157844c29cc1e2b0bdb2f6181bc07020c23652528515deac0edc0d541a3
@@ -84,6 +84,7 @@ class Spec
84
84
  end
85
85
 
86
86
 
87
+ private
87
88
  def run(target, dryrun, ci = false, console_output = false)
88
89
  messages = []
89
90
  failure = false
@@ -92,6 +93,7 @@ class Spec
92
93
  @spec.check_existence(v["spec"])
93
94
  spec = v["spec"].map { |spec| "#{@specdir}/#{spec}_spec.rb" }
94
95
  command = "rspec --format documentation #{spec.sort.uniq.join(" ")}"
96
+ defined_spec_attr = grep_spec_attr(spec)
95
97
 
96
98
  if dryrun
97
99
  v["host"].each do |host|
@@ -103,50 +105,40 @@ class Spec
103
105
  end
104
106
 
105
107
  Parallel.each(v["host"], :in_threads => Parallel.processor_count) do |host|
106
- attr_role = @role.get_attr(role)
107
- attr_host = @host.get_attr(host)
108
- attr_outerrole = {}
109
- outerrole = []
110
-
111
- @host.details(host).each do |h, v|
112
- outerrole = outerrole.concat((v["outer role"] || [])).uniq
113
- end
114
-
115
- outerrole.each do |o|
116
- attr_outerrole.merge!(@outerrole.get_attr(o))
117
- end
118
-
119
- attr = attr_role.merge(attr_outerrole)
120
- attr = attr.merge(attr_host)
121
-
122
- logmesg = ""
123
- if attr != {} && attr_host == {} && outerrole.size > 1
124
- logmsg = "might not be given the appropriate attribute value, because #{host} have no attributes and belongs to more than one outer role - #{outerrole.join(", ")}"
125
- @logger.warn(host) { logmsg }
126
- logmsg += "\n"
108
+ if !defined_spec_attr.empty?
109
+ attr = generate_attr(role, host)
110
+ attr.delete_if { |name, value| !defined_spec_attr.include?(name.to_s) }
127
111
  end
128
112
 
129
113
  result = systemu(
130
114
  command,
131
115
  :env => {
132
116
  "TARGET_HOST" => host,
133
- "TARGET_HOST_ATTR" => JSON.generate(attr)
117
+ "TARGET_HOST_ATTR" => attr ? JSON.generate(attr) : "{}"
134
118
  },
135
119
  :cwd => File.join(@specdir, "..")
136
120
  )
137
121
 
138
- @logger.info(host) { "#{result[1]}\n#{result[2]}" }
122
+ logmsg = attr.empty? ? "" : "attribute that has been set: #{attr}"
123
+ if !result[1].empty?
124
+ @logger.info(host) { logmsg } unless result[1].empty?
125
+ @logger.info(host) { result[1] }
126
+ end
127
+ @logger.warn(host) { result[2] } unless result[2].empty?
128
+
139
129
  failure = true if result[0] != 0
140
130
 
141
- msg = result[1].scan(/\d* examples?, \d* failures?\n/).first
142
- msg = msg ? msg.chomp : "error"
143
- msg += "\t#{host} => #{v["spec"].join(", ")}\n"
144
- puts msg if console_output
131
+ if console_output
132
+ msg = result[1].scan(/\d* examples?, \d* failures?\n/).first
133
+ msg = msg ? msg.chomp : "error"
134
+ msg += "\t#{host} => #{v["spec"].join(", ")}\n"
135
+ puts msg
136
+ end
145
137
 
146
138
  if ci
147
139
  begin
148
140
  post_result(result, role, host, v["spec"], command, logmsg)
149
- rescue
141
+ rescue => e
150
142
  ci = false
151
143
  end
152
144
  end
@@ -157,10 +149,51 @@ class Spec
157
149
  end
158
150
 
159
151
 
160
- private
152
+ def grep_spec_attr(spec)
153
+ attr = []
154
+
155
+ spec.each do |s|
156
+ File.open(s).each_line do |l|
157
+ /attr\[\:(?<name>.+)\]/ =~ l
158
+ attr << name
159
+ end
160
+ end
161
+
162
+ attr.compact.uniq
163
+ end
164
+
165
+
166
+ def generate_attr(role, host)
167
+ attr_role = @role.get_attr(role)
168
+ attr_host = @host.get_attr(host)
169
+ attr_outerrole = {}
170
+ outerrole = []
171
+
172
+ @host.details(host).each do |h, v|
173
+ outerrole = outerrole.concat((v["outer role"] || [])).uniq
174
+ end
175
+
176
+ outerrole.each do |o|
177
+ attr_outerrole.merge!(@outerrole.get_attr(o))
178
+ end
179
+
180
+ attr = attr_role.merge(attr_outerrole)
181
+ attr = attr.merge(attr_host)
182
+
183
+ if attr != {} && attr_host == {} && outerrole.size > 1
184
+ log = "might not be given the appropriate attribute value, because #{host} have no attributes and belongs to more than one outer role - #{outerrole.join(", ")}"
185
+ @logger.warn(host) { log }
186
+ end
187
+
188
+ return attr
189
+ end
190
+
191
+
161
192
  def post_result(result, role, host, spec, command, message)
162
193
  result_status = result[0] == 0 ? 1 : 2
194
+ result_status = result[2].empty? ? result_status : 3
163
195
 
196
+ # willing to mv to constractor
164
197
  conf = YAML.load_file(Houcho::Config::FILE)
165
198
  ukigumo = conf["ukigumo"]
166
199
  ikachan = conf["ikachan"]
@@ -169,12 +202,12 @@ class Spec
169
202
  u = CI::UkigumoClient.new(ukigumo["host"], ukigumo["port"])
170
203
  ukigumo_report = u.post({
171
204
  :status => result_status,
172
- :project => host.gsub(/\./, "-"),
205
+ :project => "This is test " + host.gsub(/\./, "-"),
173
206
  :branch => role,
174
207
  :repo => "_",
175
208
  :revision => spec.join(", "),
176
209
  :vc_log => command,
177
- :body => ( message || "" ) + result[1],
210
+ :body => [message, result[1], result[2]].join("\n\n")
178
211
  })
179
212
  end
180
213
 
@@ -1,3 +1,3 @@
1
1
  module Houcho
2
- VERSION = '0.0.10'
2
+ VERSION = '0.0.11'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: houcho
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Satoshi SUZUKI
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-15 00:00:00.000000000 Z
11
+ date: 2013-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor