houcho 0.0.12 → 0.0.13
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 +4 -4
- data/lib/houcho/cli/spec.rb +4 -2
- data/lib/houcho/outerrole.rb +16 -0
- data/lib/houcho/outerrole/yabitz.rb +5 -16
- data/lib/houcho/role.rb +1 -1
- data/lib/houcho/spec/runner.rb +21 -13
- data/lib/houcho/version.rb +1 -1
- data/spec/houcho_spec.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: faf0bd15776ab9a902d2770798e258d20c7cc4e0
|
4
|
+
data.tar.gz: 862315e86a7307b23f0cde6f2b2ae349fe95be06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf01e0af237e984edc44bec9ffa7559e6395725f965a46217db8ed87878827ce569d6b8a9e145234791c830acc7799f062f4a7e9cb8c99b5121068bd1e634606
|
7
|
+
data.tar.gz: 2d6c8f6fc7f1d066c465dd8a2b08bba8c4d8240b9ca741d82846b814a9c43eb935c5e6818739c5864ec1b877ee676ad3ff407507eca4253420a709697090ce93
|
data/lib/houcho/cli/spec.rb
CHANGED
@@ -82,6 +82,7 @@ module Houcho
|
|
82
82
|
desc 'exec [spec1 spec2..]', 'run spec'
|
83
83
|
option :hosts, :type => :array, :desc => '--hosts host1 host2 host3...', :required => true
|
84
84
|
option :dry_run, :type => :boolean, :default => false, :desc => 'show commands that may exexute'
|
85
|
+
option :attr, :type => :hash, :default => false, :desc => 'set attribute'
|
85
86
|
def exec(*args)
|
86
87
|
Houcho::CLI::Main.empty_args(self, shell, __method__) if args.empty?
|
87
88
|
runner = Houcho::Spec::Runner.new
|
@@ -90,8 +91,9 @@ module Houcho
|
|
90
91
|
exit! unless runner.execute_manually(
|
91
92
|
options[:hosts],
|
92
93
|
args,
|
93
|
-
options[:dry_run],
|
94
|
-
true
|
94
|
+
dryrun: options[:dry_run],
|
95
|
+
console_output: true,
|
96
|
+
attr: options[:attr]
|
95
97
|
)
|
96
98
|
rescue Houcho::SpecFileException => e
|
97
99
|
puts e.message
|
data/lib/houcho/outerrole.rb
CHANGED
@@ -12,6 +12,21 @@ module Houcho
|
|
12
12
|
@type_id = 1
|
13
13
|
end
|
14
14
|
|
15
|
+
|
16
|
+
def list(opt = {})
|
17
|
+
sql = "SELECT T1.name FROM outerrole T1, role_outerrole T2"
|
18
|
+
sql += " WHERE T1.data_source LIKE ?"
|
19
|
+
ds = opt[:data_source]
|
20
|
+
|
21
|
+
if opt[:role_id]
|
22
|
+
sql += " AND T1.id = T2.outerrole_id AND T2.role_id = ?"
|
23
|
+
return @db.execute(sql, ds ? ds : "%", opt[:role_id]).flatten
|
24
|
+
else
|
25
|
+
return @db.execute(sql, ds ? ds : "%").flatten
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
15
30
|
def details(outer_role)
|
16
31
|
outer_role = outer_role.is_a?(Array) ? outer_role : [outer_role]
|
17
32
|
result = {}
|
@@ -26,6 +41,7 @@ module Houcho
|
|
26
41
|
result
|
27
42
|
end
|
28
43
|
|
44
|
+
|
29
45
|
def hostlist(outer_role)
|
30
46
|
outer_role = outer_role.is_a?(Array) ? outer_role : [outer_role]
|
31
47
|
hosts = []
|
@@ -25,7 +25,7 @@ class OuterRole
|
|
25
25
|
|
26
26
|
|
27
27
|
private
|
28
|
-
def http_get(host, port, path, params)
|
28
|
+
def http_get(host, port, path, params = {})
|
29
29
|
Net::HTTP.get(
|
30
30
|
host,
|
31
31
|
"#{path}?".concat(
|
@@ -38,22 +38,11 @@ class OuterRole
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def download_json(host, port)
|
41
|
-
JSON.load(
|
42
|
-
http_get(
|
43
|
-
host, port, "/ybz/search.json",
|
44
|
-
{
|
45
|
-
andor: "AND",
|
46
|
-
cond0: 0,
|
47
|
-
field0: "os",
|
48
|
-
value0: " ",
|
49
|
-
status: "IN_SERVICE",
|
50
|
-
ex_andor: "AND",
|
51
|
-
ex_cond0: 0,
|
52
|
-
ex_field0: "not_selected",
|
53
|
-
ex_value0: nil,
|
54
|
-
},
|
55
|
-
)
|
41
|
+
metadata = JSON.load(
|
42
|
+
http_get( host, port, "/ybz/hosts/all.json" )
|
56
43
|
)
|
44
|
+
|
45
|
+
metadata.select { |md| md["content"]["status"] == "IN_SERVICE" }
|
57
46
|
end
|
58
47
|
|
59
48
|
def create_yabitz_role(host, port)
|
data/lib/houcho/role.rb
CHANGED
data/lib/houcho/spec/runner.rb
CHANGED
@@ -22,7 +22,7 @@ class Spec
|
|
22
22
|
end
|
23
23
|
|
24
24
|
|
25
|
-
def check(spec, host_count,
|
25
|
+
def check(spec, host_count, opt = {})
|
26
26
|
spec = spec.is_a?(Array) ? spec : [spec]
|
27
27
|
role = spec.map { |s| @spec.details(s)[s]["role"] }.flatten
|
28
28
|
host = []
|
@@ -37,24 +37,28 @@ class Spec
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
execute_manually(
|
40
|
+
execute_manually(
|
41
|
+
host.sample(host_count), spec,
|
42
|
+
dryrun: opt[:dryrun], console_output: opt[:console_output])
|
43
|
+
# dry run for test
|
41
44
|
end
|
42
45
|
|
43
46
|
|
44
|
-
def execute_manually(host, spec,
|
47
|
+
def execute_manually(host, spec, opt = {})
|
45
48
|
host = host.is_a?(Array) ? host : [host]
|
46
49
|
spec = spec.is_a?(Array) ? spec : [spec]
|
47
50
|
|
48
51
|
run(
|
49
52
|
{ rand(36**50).to_s(36) => { "host" => host, "spec" => spec } },
|
50
|
-
dryrun,
|
51
|
-
false,
|
52
|
-
console_output
|
53
|
+
opt[:dryrun],
|
54
|
+
false, # ci
|
55
|
+
opt[:console_output],
|
56
|
+
opt[:attr]
|
53
57
|
)
|
54
58
|
end
|
55
59
|
|
56
60
|
|
57
|
-
def execute_role(role, ex_host = [], dryrun = false, console_output = false)
|
61
|
+
def execute_role(role, ex_host = [], dryrun = false, console_output = false, attr = nil)
|
58
62
|
role = role.is_a?(Array) ? role : [role]
|
59
63
|
ex_host = ex_host.is_a?(Array) ? ex_host : [ex_host]
|
60
64
|
|
@@ -80,12 +84,12 @@ class Spec
|
|
80
84
|
role_valiables[rolename] = rv
|
81
85
|
end
|
82
86
|
|
83
|
-
run(role_valiables, dryrun, true, console_output)
|
87
|
+
run(role_valiables, dryrun, true, console_output, attr)
|
84
88
|
end
|
85
89
|
|
86
90
|
|
87
91
|
private
|
88
|
-
def run(target, dryrun, ci = false, console_output = false)
|
92
|
+
def run(target, dryrun, ci = false, console_output = false, manually_attr = nil)
|
89
93
|
messages = []
|
90
94
|
failure = false
|
91
95
|
|
@@ -105,9 +109,13 @@ class Spec
|
|
105
109
|
end
|
106
110
|
|
107
111
|
Parallel.each(v["host"], :in_threads => Parallel.processor_count) do |host|
|
108
|
-
if
|
109
|
-
attr =
|
110
|
-
|
112
|
+
if manually_attr.is_a?(Hash)
|
113
|
+
attr = manually_attr
|
114
|
+
else
|
115
|
+
if !defined_spec_attr.empty?
|
116
|
+
attr = generate_attr(role, host)
|
117
|
+
attr.delete_if { |name, value| !defined_spec_attr.include?(name.to_s) }
|
118
|
+
end
|
111
119
|
end
|
112
120
|
|
113
121
|
result = systemu(
|
@@ -119,7 +127,7 @@ class Spec
|
|
119
127
|
:cwd => File.join(@specdir, "..")
|
120
128
|
)
|
121
129
|
|
122
|
-
logmsg = attr
|
130
|
+
logmsg = attr ? "" : "attribute that has been set: #{attr}"
|
123
131
|
if !result[1].empty?
|
124
132
|
@logger.info(host) { logmsg } unless result[1].empty?
|
125
133
|
@logger.info(host) { result[1] }
|
data/lib/houcho/version.rb
CHANGED
data/spec/houcho_spec.rb
CHANGED
@@ -381,7 +381,7 @@ YAML
|
|
381
381
|
expect(@specrunner.execute_manually(
|
382
382
|
["test3.studio3104.com", "test4.studio3104.com"],
|
383
383
|
"specA",
|
384
|
-
true
|
384
|
+
dryrun: true
|
385
385
|
)).to eq([
|
386
386
|
"TARGET_HOST=test3.studio3104.com rspec --format documentation #{Houcho::Config::SPECDIR}/specA_spec.rb",
|
387
387
|
"TARGET_HOST=test4.studio3104.com rspec --format documentation #{Houcho::Config::SPECDIR}/specA_spec.rb"
|
@@ -389,14 +389,14 @@ YAML
|
|
389
389
|
end
|
390
390
|
|
391
391
|
it "case of spec not exist" do
|
392
|
-
expect { @specrunner.execute_manually("test5.studio3104.com", ["specA", "specX"], true) }.to(
|
392
|
+
expect { @specrunner.execute_manually("test5.studio3104.com", ["specA", "specX"], dryrun: true) }.to(
|
393
393
|
raise_error Houcho::SpecFileException, "No such spec file - specX"
|
394
394
|
)
|
395
395
|
end
|
396
396
|
end
|
397
397
|
|
398
398
|
context "check spec" do
|
399
|
-
it { expect(@specrunner.check("specA", 2, true).size).to be(2) }
|
399
|
+
it { expect(@specrunner.check("specA", 2, dryrun: true).size).to be(2) }
|
400
400
|
|
401
401
|
it "case of spec not exist" do
|
402
402
|
expect { @specrunner.check("specX", 2) }.to(
|
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.
|
4
|
+
version: 0.0.13
|
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-
|
11
|
+
date: 2013-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|