hosttag 0.12
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.
- data/.gitignore +2 -0
- data/ChangeLog +44 -0
- data/EXCLUDE +3 -0
- data/LICENCE +674 -0
- data/README +92 -0
- data/Rakefile +30 -0
- data/TODO +4 -0
- data/bin/hosttag +168 -0
- data/bin/ht +168 -0
- data/bin/htdel +164 -0
- data/bin/htdump +70 -0
- data/bin/htexport +99 -0
- data/bin/htimport +81 -0
- data/bin/htremap +93 -0
- data/bin/htset +164 -0
- data/etc/Makefile +16 -0
- data/etc/README +10 -0
- data/hosttag.gemspec +23 -0
- data/hosttag.spec +179 -0
- data/lib/hosttag.rb +402 -0
- data/lib/hosttag/server.rb +35 -0
- data/test/data_hosttag/a/centos +0 -0
- data/test/data_hosttag/a/centos5 +0 -0
- data/test/data_hosttag/a/centos5-x86_64 +0 -0
- data/test/data_hosttag/a/public +0 -0
- data/test/data_hosttag/g/SKIP +0 -0
- data/test/data_hosttag/g/centos +0 -0
- data/test/data_hosttag/g/centos4 +0 -0
- data/test/data_hosttag/g/centos4-i386 +0 -0
- data/test/data_hosttag/h/SKIP +0 -0
- data/test/data_hosttag/h/centos +0 -0
- data/test/data_hosttag/h/centos4 +0 -0
- data/test/data_hosttag/h/centos4-x86_64 +0 -0
- data/test/data_hosttag/h/public +0 -0
- data/test/data_hosttag/m/centos +0 -0
- data/test/data_hosttag/m/centos4 +0 -0
- data/test/data_hosttag/m/centos4-x86_64 +0 -0
- data/test/data_hosttag/m/public +0 -0
- data/test/data_hosttag/m/vps +0 -0
- data/test/data_hosttag/n/centos +0 -0
- data/test/data_hosttag/n/centos5 +0 -0
- data/test/data_hosttag/n/centos5-i386 +0 -0
- data/test/data_hosttag/n/laptop +0 -0
- data/test/test_hosttag_bin.rb +70 -0
- data/test/test_hosttag_lib.rb +119 -0
- data/test/test_htset_bin.rb +174 -0
- data/test/test_htset_lib.rb +183 -0
- data/test/ts_all.rb +4 -0
- metadata +132 -0
@@ -0,0 +1,35 @@
|
|
1
|
+
# Hosttag::Server class, extending Redis
|
2
|
+
|
3
|
+
# Blech - shouldn't need to require rubygems here, but fails on 1.8.x otherwise
|
4
|
+
require 'rubygems'
|
5
|
+
require 'redis'
|
6
|
+
require 'resolv'
|
7
|
+
|
8
|
+
module Hosttag
|
9
|
+
class Server < Redis
|
10
|
+
def initialize(options)
|
11
|
+
@defaults = {
|
12
|
+
:server => ENV['HOSTTAG_SERVER'] || 'hosttag',
|
13
|
+
:port => ENV['HOSTTAG_PORT'] || 6379,
|
14
|
+
:namespace => ENV['HOSTTAG_NAMESPACE'] || 'hosttag',
|
15
|
+
}
|
16
|
+
@defaults.merge!(options)
|
17
|
+
|
18
|
+
# Check :server name resolves
|
19
|
+
begin
|
20
|
+
Resolv.getaddress( @defaults[:server] )
|
21
|
+
rescue Resolv::ResolvError
|
22
|
+
raise Resolv::ResolvError,
|
23
|
+
"Host '#{@defaults[:server]}' does not resolve (try --server <hostname>?)", caller
|
24
|
+
end
|
25
|
+
|
26
|
+
# Connect to redis
|
27
|
+
super( :host => @defaults[:server], :port => @defaults[:port] )
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_key(*elt)
|
31
|
+
"#{@defaults[:namespace]}::#{elt.join(':')}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
require 'hosttag'
|
7
|
+
include Hosttag
|
8
|
+
|
9
|
+
class TestHosttagBin < Test::Unit::TestCase
|
10
|
+
def setup
|
11
|
+
@test_args = '--server localhost --ns hosttag_testing'
|
12
|
+
@test_opts = { :server => 'localhost', :namespace => 'hosttag_testing',
|
13
|
+
:delete => true, :autoconfirm => true, :debug => false }
|
14
|
+
@bindir = File.join(File.dirname(__FILE__), '..', 'bin')
|
15
|
+
datadir = "#{File.dirname(__FILE__)}/data_hosttag"
|
16
|
+
File.directory?(datadir) or throw "missing datadir #{datadir}"
|
17
|
+
hosttag_import_from_directory(datadir, @test_opts)
|
18
|
+
end
|
19
|
+
|
20
|
+
# format: args (string) => expected (either string or regex)
|
21
|
+
TESTS = [
|
22
|
+
[ 'centos', 'a m n' ],
|
23
|
+
[ 'laptop', 'n' ],
|
24
|
+
[ 'vps', 'm' ],
|
25
|
+
[ 'laptop vps', '' ],
|
26
|
+
[ '-a laptop vps', '' ],
|
27
|
+
[ '-o laptop vps', 'm n' ],
|
28
|
+
[ '-t n', 'centos centos5 centos5-i386 laptop' ],
|
29
|
+
[ '-t a', 'centos centos5 centos5-x86_64 public' ],
|
30
|
+
[ '-t m', 'centos centos4 centos4-x86_64 public vps' ],
|
31
|
+
[ '-t a n', 'centos centos5 centos5-i386 centos5-x86_64 laptop public' ],
|
32
|
+
[ '-to a n', 'centos centos5 centos5-i386 centos5-x86_64 laptop public' ],
|
33
|
+
[ '-t -o a n', 'centos centos5 centos5-i386 centos5-x86_64 laptop public' ],
|
34
|
+
[ '-ta a n', 'centos centos5' ],
|
35
|
+
[ '-t -a a n', 'centos centos5' ],
|
36
|
+
[ '-t -a a n m', 'centos' ],
|
37
|
+
[ '-1 centos', "a\nm\nn" ],
|
38
|
+
[ '-o -1 laptop vps', "m\nn" ],
|
39
|
+
# List mode
|
40
|
+
[ '-l centos5', 'centos5: a n' ],
|
41
|
+
# All cases
|
42
|
+
[ '-A', 'a m n' ],
|
43
|
+
[ '-A -A', 'a g h m n' ],
|
44
|
+
[ '-T', 'centos centos4 centos4-x86_64 centos5 centos5-i386 centos5-x86_64 laptop public vps' ],
|
45
|
+
[ '-A -1', "a\nm\nn" ],
|
46
|
+
[ '-A -1 -A', "a\ng\nh\nm\nn" ],
|
47
|
+
[ '-1 -T', "centos\ncentos4\ncentos4-x86_64\ncentos5\ncentos5-i386\ncentos5-x86_64\nlaptop\npublic\nvps" ],
|
48
|
+
# Try unrecognised tags as hosts
|
49
|
+
[ 'n', 'centos centos5 centos5-i386 laptop' ],
|
50
|
+
[ 'a n', 'centos centos5 centos5-i386 centos5-x86_64 laptop public' ],
|
51
|
+
# Invalid data
|
52
|
+
[ 'foo', %r{ \btag\b .* not\sfound }x ],
|
53
|
+
[ 'centos foo', %r{ \btag\b .* not\sfound }x ],
|
54
|
+
[ '-t foo', %r{ \bhost\b .* not\sfound }x ],
|
55
|
+
[ '-t n foo', %r{ \bhost\b .* not\sfound }x ],
|
56
|
+
]
|
57
|
+
|
58
|
+
def test_hosttag
|
59
|
+
TESTS.each do |args, expected|
|
60
|
+
got = `#{@bindir}/hosttag #{@test_args} #{args} 2>&1`.chomp
|
61
|
+
if expected.is_a?(String)
|
62
|
+
assert_equal(expected, got, "args: #{args}")
|
63
|
+
elsif expected.is_a?(Regexp)
|
64
|
+
assert_match(expected, got, "args: #{args}")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
@@ -0,0 +1,119 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
require 'hosttag'
|
7
|
+
include Hosttag
|
8
|
+
|
9
|
+
class TestHosttagLib < Test::Unit::TestCase
|
10
|
+
def setup
|
11
|
+
@test_args = '--server localhost --ns hosttag_testing'
|
12
|
+
@test_opts = { :server => 'localhost', :namespace => 'hosttag_testing',
|
13
|
+
:delete => true, :autoconfirm => true, :debug => false }
|
14
|
+
datadir = "#{File.dirname(__FILE__)}/data_hosttag"
|
15
|
+
bindir = File.join(File.dirname(__FILE__), '..', 'bin')
|
16
|
+
File.directory?(datadir) or throw "missing datadir #{datadir}"
|
17
|
+
hosttag_import_from_directory(datadir, @test_opts)
|
18
|
+
end
|
19
|
+
|
20
|
+
# format: args (array), options (hash) => expected (array)
|
21
|
+
TAGSET = [
|
22
|
+
[ %w{centos}, {}, %w{a m n} ],
|
23
|
+
[ %w{laptop}, {}, %w{n} ],
|
24
|
+
[ %w{vps}, {}, %w{m} ],
|
25
|
+
[ %w{laptop vps}, {}, %w{} ],
|
26
|
+
[ %w{laptop vps}, { :rel => :and }, %w{} ],
|
27
|
+
[ %w{laptop vps}, { :rel => :or }, %w{m n} ],
|
28
|
+
]
|
29
|
+
HOSTSET = [
|
30
|
+
[ %w{n}, {}, %w{centos centos5 centos5-i386 laptop} ],
|
31
|
+
[ %w{a}, {}, %w{centos centos5 centos5-x86_64 public} ],
|
32
|
+
[ %w{m}, {}, %w{centos centos4 centos4-x86_64 public vps} ],
|
33
|
+
[ %w{a n}, {}, %w{centos centos5 centos5-i386 centos5-x86_64 laptop public} ],
|
34
|
+
[ %w{a n}, { :rel => :or }, %w{centos centos5 centos5-i386 centos5-x86_64 laptop public} ],
|
35
|
+
[ %w{a n}, { :rel => :and }, %w{centos centos5} ],
|
36
|
+
[ %w{a n m}, { :rel => :and }, %w{centos} ],
|
37
|
+
]
|
38
|
+
|
39
|
+
def test_hosttag_lookup
|
40
|
+
TAGSET.each do |args, opts, expected|
|
41
|
+
opts.merge!(@test_opts)
|
42
|
+
got = hosttag_lookup(args, opts)
|
43
|
+
assert_equal(expected, got, "args: #{args}")
|
44
|
+
end
|
45
|
+
HOSTSET.each do |args, opts, expected|
|
46
|
+
opts.merge!(@test_opts)
|
47
|
+
got = hosttag_lookup(args, opts)
|
48
|
+
assert_equal(expected, got, "args: #{args}")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_hosttag_lookup_tags
|
53
|
+
TAGSET.each do |args, opts, expected|
|
54
|
+
opts.merge!(@test_opts)
|
55
|
+
got = hosttag_lookup_tags(args, opts)
|
56
|
+
assert_equal(expected, got, "args: #{args}")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_hosttag_lookup_hosts
|
61
|
+
HOSTSET.each do |args, opts, expected|
|
62
|
+
opts.merge!(@test_opts)
|
63
|
+
got = hosttag_lookup_hosts(args, opts)
|
64
|
+
assert_equal(expected, got, "args: #{args}")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# format: options (hash) => expected (array)
|
69
|
+
TAGSET_ALL = [
|
70
|
+
[ {}, %w{centos centos4 centos4-x86_64 centos5 centos5-i386 centos5-x86_64 laptop public vps} ],
|
71
|
+
[ { :include_skip? => true }, %w{SKIP centos centos4 centos4-i386 centos4-x86_64 centos5 centos5-i386 centos5-x86_64 laptop public vps} ],
|
72
|
+
]
|
73
|
+
def test_hosttag_all_tags
|
74
|
+
TAGSET_ALL.each do |opts, expected|
|
75
|
+
mopts = opts.merge(@test_opts)
|
76
|
+
got = hosttag_all_tags(mopts)
|
77
|
+
assert_equal(expected, got, "opts: #{opts}")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# format: options (hash) => expected (array)
|
82
|
+
HOSTSET_ALL = [
|
83
|
+
[ {}, %w{a m n} ],
|
84
|
+
[ { :include_skip? => true }, %w{a g h m n} ],
|
85
|
+
]
|
86
|
+
def test_hosttag_all_hosts
|
87
|
+
HOSTSET_ALL.each do |opts, expected|
|
88
|
+
mopts = opts.merge(@test_opts)
|
89
|
+
got = hosttag_all_hosts(mopts)
|
90
|
+
assert_equal(expected, got, "opts: #{opts}")
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# Invalid data
|
95
|
+
INVALID_TAGS = [
|
96
|
+
[ %w{foo}, %r{ \btag\b .* not\sfound }x ],
|
97
|
+
[ %w{centos foo}, %r{ \btag\b .* not\sfound }x ],
|
98
|
+
]
|
99
|
+
INVALID_HOSTS = [
|
100
|
+
[ %w{foo}, %r{ \bhost\b .* not\sfound }x ],
|
101
|
+
[ %w{n foo}, %r{ \bhost\b .* not\sfound }x ],
|
102
|
+
]
|
103
|
+
|
104
|
+
def test_invalid_data
|
105
|
+
INVALID_TAGS.each do |args, expected|
|
106
|
+
exception = assert_raise RuntimeError do
|
107
|
+
hosttag_lookup_tags(args)
|
108
|
+
end
|
109
|
+
assert_match expected, exception.message, "args: #{args}"
|
110
|
+
end
|
111
|
+
INVALID_HOSTS.each do |args, expected|
|
112
|
+
exception = assert_raise RuntimeError do
|
113
|
+
hosttag_lookup_hosts(args)
|
114
|
+
end
|
115
|
+
assert_match expected, exception.message, "args: #{args}"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
@@ -0,0 +1,174 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
require 'hosttag'
|
7
|
+
include Hosttag
|
8
|
+
|
9
|
+
class TestHtsetBin < Test::Unit::TestCase
|
10
|
+
|
11
|
+
def setup
|
12
|
+
@test_args = '--server localhost --ns hosttag_testing'
|
13
|
+
@test_opts = { :server => 'localhost', :namespace => 'hosttag_testing',
|
14
|
+
:delete => true, :autoconfirm => true, :debug => false }
|
15
|
+
datadir = "#{File.dirname(__FILE__)}/data_reset"
|
16
|
+
@bindir = File.join(File.dirname(__FILE__), '..', 'bin')
|
17
|
+
File.directory?(datadir) or throw "missing datadir #{datadir}"
|
18
|
+
hosttag_import_from_directory(datadir, @test_opts)
|
19
|
+
end
|
20
|
+
|
21
|
+
TESTS = [
|
22
|
+
[
|
23
|
+
%w{htset foo centos}, # operation
|
24
|
+
%w{foo}, # ht -A output
|
25
|
+
%w{foo}, # ht -A -A output
|
26
|
+
%w{centos}, # ht -T output
|
27
|
+
%w{centos}, # ht -T -T output
|
28
|
+
],
|
29
|
+
[
|
30
|
+
%w{htset foo centos5},
|
31
|
+
%w{foo},
|
32
|
+
%w{foo},
|
33
|
+
%w{centos centos5},
|
34
|
+
%w{centos centos5},
|
35
|
+
],
|
36
|
+
[
|
37
|
+
%w{htset bar centos},
|
38
|
+
%w{bar foo},
|
39
|
+
%w{bar foo},
|
40
|
+
%w{centos centos5},
|
41
|
+
%w{centos centos5},
|
42
|
+
],
|
43
|
+
[
|
44
|
+
%w{htset bar centos4},
|
45
|
+
%w{bar foo},
|
46
|
+
%w{bar foo},
|
47
|
+
%w{centos centos4 centos5},
|
48
|
+
%w{centos centos4 centos5},
|
49
|
+
],
|
50
|
+
[
|
51
|
+
%w{htset bar SKIP},
|
52
|
+
%w{foo},
|
53
|
+
%w{bar foo},
|
54
|
+
%w{centos centos5},
|
55
|
+
%w{SKIP centos centos4 centos5},
|
56
|
+
],
|
57
|
+
[
|
58
|
+
%w{htset bar centos4-i386},
|
59
|
+
%w{foo},
|
60
|
+
%w{bar foo},
|
61
|
+
%w{centos centos5},
|
62
|
+
%w{SKIP centos centos4 centos4-i386 centos5},
|
63
|
+
],
|
64
|
+
[
|
65
|
+
%w{htdel bar centos4},
|
66
|
+
%w{foo},
|
67
|
+
%w{bar foo},
|
68
|
+
%w{centos centos5},
|
69
|
+
%w{SKIP centos centos4-i386 centos5},
|
70
|
+
],
|
71
|
+
[
|
72
|
+
%w{htdel bar SKIP},
|
73
|
+
%w{bar foo},
|
74
|
+
%w{bar foo},
|
75
|
+
%w{centos centos4-i386 centos5},
|
76
|
+
%w{centos centos4-i386 centos5},
|
77
|
+
],
|
78
|
+
[
|
79
|
+
%w{htdel foo centos5},
|
80
|
+
%w{bar foo},
|
81
|
+
%w{bar foo},
|
82
|
+
%w{centos centos4-i386},
|
83
|
+
%w{centos centos4-i386},
|
84
|
+
],
|
85
|
+
[
|
86
|
+
%w{htdel foo centos},
|
87
|
+
%w{bar},
|
88
|
+
%w{bar},
|
89
|
+
%w{centos centos4-i386},
|
90
|
+
%w{centos centos4-i386},
|
91
|
+
],
|
92
|
+
[
|
93
|
+
%w{htdel bar centos},
|
94
|
+
%w{bar},
|
95
|
+
%w{bar},
|
96
|
+
%w{centos4-i386},
|
97
|
+
%w{centos4-i386},
|
98
|
+
],
|
99
|
+
[
|
100
|
+
%w{htdel bar centos4-i386},
|
101
|
+
[],
|
102
|
+
[],
|
103
|
+
[],
|
104
|
+
[],
|
105
|
+
],
|
106
|
+
]
|
107
|
+
|
108
|
+
def test_htset
|
109
|
+
TESTS.each do |op, all_hosts, all_hosts_full, all_tags, all_tags_full|
|
110
|
+
cmd = op.join(' ')
|
111
|
+
bin = op.shift()
|
112
|
+
error = %x{#{@bindir}/#{bin} #{@test_args} #{op.join(' ')}}
|
113
|
+
|
114
|
+
# Check results
|
115
|
+
assert_equal("", error, "Error output found: #{error}")
|
116
|
+
assert_equal(all_hosts, hosttag_all_hosts(@test_opts), "all_hosts, #{cmd}")
|
117
|
+
assert_equal(all_hosts_full, hosttag_all_hosts(@test_opts.merge({ :include_skip? => true })),
|
118
|
+
"all_hosts include_skip, #{cmd}")
|
119
|
+
assert_equal(all_tags, hosttag_all_tags(@test_opts), "all_tags, #{cmd}")
|
120
|
+
assert_equal(all_tags_full, hosttag_all_tags(@test_opts.merge({ :include_skip? => true })),
|
121
|
+
"all_tags_full, #{cmd}")
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# Test argument classification
|
126
|
+
# Format: operation, error, all_hosts, all_tags
|
127
|
+
CLASSIFY_TESTS = [
|
128
|
+
[
|
129
|
+
%w{htset foo centos},
|
130
|
+
'',
|
131
|
+
%w{foo},
|
132
|
+
%w{centos},
|
133
|
+
],
|
134
|
+
[
|
135
|
+
%w{htset cat foo dog centos5}, # unclassifiable host (dog) should give gives error
|
136
|
+
"Error: can't auto-classify 'dog' - aborting\n",
|
137
|
+
%w{foo},
|
138
|
+
%w{centos},
|
139
|
+
],
|
140
|
+
[
|
141
|
+
%w{htset cat dell centos centos5-x86_64}, # unclassifiable tag (dell) should give error
|
142
|
+
"Error: can't auto-classify 'dell' - aborting\n",
|
143
|
+
%w{foo},
|
144
|
+
%w{centos},
|
145
|
+
],
|
146
|
+
[
|
147
|
+
%w{htset cat dog foo centos5}, # known host allows classification of former args as hosts
|
148
|
+
'',
|
149
|
+
%w{cat dog foo},
|
150
|
+
%w{centos centos5},
|
151
|
+
],
|
152
|
+
[
|
153
|
+
%w{htset cat centos dell centos5-x86_64}, # known tag allows classification of later args as tags
|
154
|
+
'',
|
155
|
+
%w{cat dog foo},
|
156
|
+
%w{centos centos5 centos5-x86_64 dell},
|
157
|
+
],
|
158
|
+
]
|
159
|
+
|
160
|
+
def test_htset_argument_classification
|
161
|
+
CLASSIFY_TESTS.each do |op, error, all_hosts, all_tags|
|
162
|
+
cmd = op.join(' ')
|
163
|
+
bin = op.shift()
|
164
|
+
output = %x{#{@bindir}/#{bin} #{@test_args} #{op.join(' ')}}
|
165
|
+
|
166
|
+
# Check results
|
167
|
+
assert_equal(error, output, "Error output mismatch")
|
168
|
+
assert_equal(all_hosts, hosttag_all_hosts(@test_opts), "all_hosts, #{cmd}")
|
169
|
+
assert_equal(all_tags, hosttag_all_tags(@test_opts), "all_tags, #{cmd}")
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
|
@@ -0,0 +1,183 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
require 'hosttag'
|
7
|
+
include Hosttag
|
8
|
+
|
9
|
+
class TestHtsetLib < Test::Unit::TestCase
|
10
|
+
|
11
|
+
def setup
|
12
|
+
@test_args = '--server localhost --ns hosttag_testing'
|
13
|
+
@test_opts = { :server => 'localhost', :namespace => 'hosttag_testing',
|
14
|
+
:delete => true, :autoconfirm => true, :debug => false }
|
15
|
+
datadir = "#{File.dirname(__FILE__)}/data_reset"
|
16
|
+
@bindir = File.join(File.dirname(__FILE__), '..', 'bin')
|
17
|
+
File.directory?(datadir) or throw "missing datadir #{datadir}"
|
18
|
+
hosttag_import_from_directory(datadir, @test_opts)
|
19
|
+
end
|
20
|
+
|
21
|
+
# -----------------------------------------------------------------------
|
22
|
+
# Testing hosttag_add_tags and hosttag_delete_tags
|
23
|
+
# -----------------------------------------------------------------------
|
24
|
+
|
25
|
+
TESTS = [
|
26
|
+
[
|
27
|
+
%w{htset foo centos}, # operation
|
28
|
+
%w{foo}, # ht -A output
|
29
|
+
%w{foo}, # ht -A -A output
|
30
|
+
%w{centos}, # ht -T output
|
31
|
+
%w{centos}, # ht -T -T output
|
32
|
+
],
|
33
|
+
[
|
34
|
+
%w{htset foo centos5},
|
35
|
+
%w{foo},
|
36
|
+
%w{foo},
|
37
|
+
%w{centos centos5},
|
38
|
+
%w{centos centos5},
|
39
|
+
],
|
40
|
+
[
|
41
|
+
%w{htset bar centos},
|
42
|
+
%w{bar foo},
|
43
|
+
%w{bar foo},
|
44
|
+
%w{centos centos5},
|
45
|
+
%w{centos centos5},
|
46
|
+
],
|
47
|
+
[
|
48
|
+
%w{htset bar centos4},
|
49
|
+
%w{bar foo},
|
50
|
+
%w{bar foo},
|
51
|
+
%w{centos centos4 centos5},
|
52
|
+
%w{centos centos4 centos5},
|
53
|
+
],
|
54
|
+
[
|
55
|
+
%w{htset bar SKIP},
|
56
|
+
%w{foo},
|
57
|
+
%w{bar foo},
|
58
|
+
%w{centos centos5},
|
59
|
+
%w{SKIP centos centos4 centos5},
|
60
|
+
],
|
61
|
+
[
|
62
|
+
%w{htset bar centos4-i386},
|
63
|
+
%w{foo},
|
64
|
+
%w{bar foo},
|
65
|
+
%w{centos centos5},
|
66
|
+
%w{SKIP centos centos4 centos4-i386 centos5},
|
67
|
+
],
|
68
|
+
[
|
69
|
+
%w{htdel bar centos4},
|
70
|
+
%w{foo},
|
71
|
+
%w{bar foo},
|
72
|
+
%w{centos centos5},
|
73
|
+
%w{SKIP centos centos4-i386 centos5},
|
74
|
+
],
|
75
|
+
[
|
76
|
+
%w{htdel bar SKIP},
|
77
|
+
%w{bar foo},
|
78
|
+
%w{bar foo},
|
79
|
+
%w{centos centos4-i386 centos5},
|
80
|
+
%w{centos centos4-i386 centos5},
|
81
|
+
],
|
82
|
+
[
|
83
|
+
%w{htdel foo centos5},
|
84
|
+
%w{bar foo},
|
85
|
+
%w{bar foo},
|
86
|
+
%w{centos centos4-i386},
|
87
|
+
%w{centos centos4-i386},
|
88
|
+
],
|
89
|
+
[
|
90
|
+
%w{htdel foo centos},
|
91
|
+
%w{bar},
|
92
|
+
%w{bar},
|
93
|
+
%w{centos centos4-i386},
|
94
|
+
%w{centos centos4-i386},
|
95
|
+
],
|
96
|
+
[
|
97
|
+
%w{htdel bar centos},
|
98
|
+
%w{bar},
|
99
|
+
%w{bar},
|
100
|
+
%w{centos4-i386},
|
101
|
+
%w{centos4-i386},
|
102
|
+
],
|
103
|
+
[
|
104
|
+
%w{htdel bar centos4-i386},
|
105
|
+
[],
|
106
|
+
[],
|
107
|
+
[],
|
108
|
+
[],
|
109
|
+
],
|
110
|
+
]
|
111
|
+
|
112
|
+
def test_hosttag_add_delete_tags
|
113
|
+
TESTS.each do |op, all_hosts, all_hosts_full, all_tags, all_tags_full|
|
114
|
+
cmd = op.join(' ')
|
115
|
+
bin = op.shift()
|
116
|
+
if bin == 'htset'
|
117
|
+
hosttag_add_tags([ op[0] ], [ op[1] ], @test_opts)
|
118
|
+
else
|
119
|
+
hosttag_delete_tags([ op[0] ], [ op[1] ], @test_opts)
|
120
|
+
end
|
121
|
+
|
122
|
+
# Check results
|
123
|
+
assert_equal(all_hosts, hosttag_all_hosts(@test_opts), "all_hosts, #{cmd}")
|
124
|
+
assert_equal(all_hosts_full, hosttag_all_hosts(@test_opts.merge({ :include_skip? => true })),
|
125
|
+
"all_hosts_full, #{cmd}")
|
126
|
+
assert_equal(all_tags, hosttag_all_tags(@test_opts), "all_tags, #{cmd}")
|
127
|
+
assert_equal(all_tags_full, hosttag_all_tags(@test_opts.merge({ :include_skip? => true })),
|
128
|
+
"all_tags_full, #{cmd}")
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
# -----------------------------------------------------------------------
|
133
|
+
# Testing hosttag_delete_all_tags
|
134
|
+
# -----------------------------------------------------------------------
|
135
|
+
|
136
|
+
# Format: host => tags
|
137
|
+
SETUP2 = [
|
138
|
+
%w{foo centos centos5 centos5-x86_64 dell},
|
139
|
+
%w{bar ubuntu ubuntu-lucid hp},
|
140
|
+
%w{cat debian debian4 dell},
|
141
|
+
%w{dog fedora fedora14 supermicro},
|
142
|
+
]
|
143
|
+
TESTS2 = [
|
144
|
+
# Format: hosts to delete, ht -A output, ht -T output
|
145
|
+
[
|
146
|
+
%w{},
|
147
|
+
%w{bar cat dog foo},
|
148
|
+
%w{centos centos5 centos5-x86_64 debian debian4 dell fedora fedora14 hp supermicro ubuntu ubuntu-lucid},
|
149
|
+
],
|
150
|
+
[
|
151
|
+
%w{foo},
|
152
|
+
%w{bar cat dog},
|
153
|
+
%w{debian debian4 dell fedora fedora14 hp supermicro ubuntu ubuntu-lucid},
|
154
|
+
],
|
155
|
+
[
|
156
|
+
%w{cat dog},
|
157
|
+
%w{bar},
|
158
|
+
%w{hp ubuntu ubuntu-lucid},
|
159
|
+
],
|
160
|
+
[
|
161
|
+
%w{bar},
|
162
|
+
%w{},
|
163
|
+
%w{},
|
164
|
+
],
|
165
|
+
]
|
166
|
+
|
167
|
+
def test_hosttag_delete_all_tags
|
168
|
+
SETUP2.each do |host, *tags|
|
169
|
+
hosttag_add_tags([ host ], tags, @test_opts)
|
170
|
+
end
|
171
|
+
TESTS2.each do |hosts, all_hosts, all_tags|
|
172
|
+
if hosts.length > 0
|
173
|
+
hosttag_delete_all_tags(hosts, @test_opts)
|
174
|
+
end
|
175
|
+
|
176
|
+
# Check results
|
177
|
+
assert_equal(all_hosts, hosttag_all_hosts(@test_opts), "all_hosts after deleting #{hosts}")
|
178
|
+
assert_equal(all_tags, hosttag_all_tags(@test_opts), "all_tags after deleting #{hosts}")
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
end
|
183
|
+
|