automateit 0.71101.1 → 0.71101.2

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.tar.gz.sig CHANGED
Binary file
data/CHANGES.txt CHANGED
@@ -1,3 +1,12 @@
1
+ 0.71101.2:
2
+ Date: Thu, 01 Nov 2007 22:37:44 -0700
3
+ Desc:
4
+ - (%) Fixed bug in TagParser, it couldn't parse hostnames with non-letter characters. Added tests. Thanks for the report, David Brewer.
5
+ - (%) Fixed bug in TagManager, adding a run-time tag caused it to not parse tags.yml. Added tests.
6
+ - (+) Improved TagManager, it now makes run-time tags available to the interpreter when parsing tags.yml, which provides greater flexibility in defining tags. Added tests. Thanks for the suggestion, David Brewer.
7
+
8
+ Thanks for the report, David Brewer.
9
+
1
10
  0.71101.1:
2
11
  Date: Thu, 01 Nov 2007 18:52:01 -0700
3
12
  Desc:
@@ -2,12 +2,6 @@ rails_servers:
2
2
  - localhost
3
3
  - kagami
4
4
  - tsukasa
5
- - michiru
6
- - rheya
7
- - satori
8
5
  myapp_servers:
9
6
  - localhost
10
7
  - kagami
11
- - michiru
12
- - rheya
13
- - satori
@@ -176,6 +176,7 @@ module AutomateIt
176
176
  # Instantiate core plugins so they're available to the project
177
177
  _instantiate_plugins
178
178
 
179
+ # Add optional run-time tags
179
180
  tags.merge(opts[:tags]) if opts[:tags]
180
181
 
181
182
  if project_path = opts[:project] || ENV["AUTOMATEIT_PROJECT"] || ENV["AIP"]
@@ -190,7 +191,7 @@ module AutomateIt
190
191
  log.debug(PNOTE+"Loading project library: #{lib}")
191
192
  invoke(lib)
192
193
  end
193
-
194
+
194
195
  tag_file = File.join(@project, "config", "tags.yml")
195
196
  if File.exists?(tag_file)
196
197
  log.debug(PNOTE+"Loading project tags: #{tag_file}")
@@ -1,7 +1,7 @@
1
1
  # See AutomateIt::Interpreter for usage information.
2
2
  module AutomateIt # :nodoc:
3
3
  # AutomateIt version
4
- VERSION=Gem::Version.new("0.71101.1")
4
+ VERSION=Gem::Version.new("0.71101.2")
5
5
 
6
6
  # Instantiates a new Interpreter. See documentation for
7
7
  # Interpreter#setup.
@@ -13,33 +13,49 @@ class AutomateIt::TagManager::Struct < AutomateIt::TagManager::BaseDriver
13
13
  # * :struct -- Hash to use for queries.
14
14
  def setup(opts={})
15
15
  super(opts)
16
-
17
16
  @struct ||= {}
18
17
  @tags ||= Set.new
18
+ @struct_updated = false
19
+ @our_hostname_tags ||= Set.new
20
+ @our_platform_tags ||= Set.new
19
21
 
20
22
  if opts[:struct]
23
+ @struct_updated = true
21
24
  @struct.merge!(AutomateIt::TagManager::TagParser.expand(opts[:struct]))
22
25
  end
23
26
  end
24
27
 
25
28
  # Return tags, populate them if necessary.
26
29
  def tags
27
- if @tags.empty?
30
+ if @our_hostname_tags.empty?
31
+ @struct_updated = true
32
+
28
33
  begin
29
- hostnames = interpreter.address_manager.hostnames # SLOW 0.4s
30
- @tags.merge(hostnames)
31
- @tags.merge(tags_for(hostnames))
32
- @tags.merge(interpreter.address_manager.addresses)
34
+ @our_hostname_tags.merge(interpreter.address_manager.hostnames) # SLOW 0.4s
35
+ @our_hostname_tags.merge(interpreter.address_manager.addresses)
33
36
  rescue NotImplementedError => e
34
37
  log.debug("Can't find AddressManager for this platform: #{e}")
35
38
  end
36
39
 
40
+ @tags.merge(@our_hostname_tags)
41
+ end
42
+
43
+ if @our_platform_tags.empty?
44
+ @struct_updated = true
45
+
37
46
  begin
38
- @tags.merge(interpreter.platform_manager.tags)
47
+ @our_platform_tags = interpreter.platform_manager.tags
48
+ @tags.merge(@our_platform_tags)
39
49
  rescue NotImplementedError => e
40
50
  log.debug("Can't find PlatformManager for this platform: #{e}")
41
51
  end
42
52
  end
53
+
54
+ if @struct_updated
55
+ @tags.merge(tags_for(@our_hostname_tags))
56
+ @struct_updated = false
57
+ end
58
+
43
59
  @tags
44
60
  end
45
61
 
@@ -3,7 +3,7 @@
3
3
  # Helper class for parsing tags. Not useful for users -- for internal use only.
4
4
  class AutomateIt::TagManager::TagParser
5
5
  attr_accessor :struct
6
- attr_accessor :is_trace
6
+ attr_accessor :is_trace # FIXME replace is_trace with nitpick
7
7
 
8
8
  # Create a parser for the +struct+, a hash of tag keys to values with arrays of items.
9
9
  def initialize(struct, is_trace=false)
@@ -38,6 +38,11 @@ class AutomateIt::TagManager::TagParser
38
38
  puts msg if is_trace
39
39
  end
40
40
 
41
+ HOSTS_FOR_VALUE = /(.+?)/
42
+ HOSTS_FOR_INCLUDE_TAG_RE = /^INCLUDE_TAG #{HOSTS_FOR_VALUE}$/
43
+ HOSTS_FOR_EXCLUDE_TAG_RE = /^EXCLUDE_TAG #{HOSTS_FOR_VALUE}$/
44
+ HOSTS_FOR_EXCLUDE_HOST_RE = /^EXCLUDE_HOST #{HOSTS_FOR_VALUE}$/
45
+
41
46
  # Return array of hosts for the +tag+.
42
47
  def hosts_for(tag)
43
48
  raise IndexError.new("Unknown tag - #{tag}") unless struct[tag]
@@ -45,13 +50,13 @@ class AutomateIt::TagManager::TagParser
45
50
  hosts = Set.new
46
51
  for item in struct[tag]
47
52
  case item
48
- when /^INCLUDE_TAG (\w+)$/
53
+ when HOSTS_FOR_INCLUDE_TAG_RE
49
54
  trace "+g %s" % $1
50
55
  hosts.merge(hosts_for($1))
51
- when /^EXCLUDE_TAG (\w+)$/
56
+ when HOSTS_FOR_EXCLUDE_TAG_RE
52
57
  trace "-g %s" % $1
53
58
  hosts.subtract(hosts_for($1))
54
- when /^EXCLUDE_HOST (\w+)$/
59
+ when HOSTS_FOR_EXCLUDE_HOST_RE
55
60
  trace "-h %s" % $1
56
61
  hosts.delete($1)
57
62
  else
@@ -141,6 +141,18 @@ describe AutomateIt::CLI, " with a project" do# {{{
141
141
  end
142
142
 
143
143
  it "should add run-time tags to a project" do
144
+ with_project do
145
+ recipe = "recipes/recipe.rb"
146
+
147
+ write_to(recipe, <<-HERE)
148
+ tagged?("added")
149
+ HERE
150
+
151
+ AutomateIt::CLI.run(:recipe => recipe, :tags => %w(added)).should be_true
152
+ end
153
+ end
154
+
155
+ it "should add run-time tags to a project without masking existing tags" do
144
156
  with_project do
145
157
  recipe = "recipes/recipe.rb"
146
158
  tags_yml = "config/tags.yml"
@@ -151,10 +163,10 @@ describe AutomateIt::CLI, " with a project" do# {{{
151
163
  HERE
152
164
 
153
165
  write_to(recipe, <<-HERE)
154
- tagged?("tsukai")
166
+ tagged?("added && all_servers")
155
167
  HERE
156
168
 
157
- AutomateIt::CLI.run(:recipe => recipe, :tags => %w(tsukai)).should be_true
169
+ AutomateIt::CLI.run(:recipe => recipe, :tags => %w(added)).should be_true
158
170
  end
159
171
  end
160
172
 
@@ -138,6 +138,14 @@ describe "AutomateIt::TagManager", :shared => true do
138
138
  it "should exclude groups from groups" do
139
139
  @a.hosts_tagged_with("all_servers_except_proxy_servers").sort.should == ["kurou", "shirou"].sort
140
140
  end
141
+
142
+ it "should match tags with dashes" do
143
+ @a.tagged?("apache-servers-using-dashes").should be_true
144
+ end
145
+
146
+ it "should include groups with dashes" do
147
+ @a.tagged?("apache-servers-using-dashes-include").should be_true
148
+ end
141
149
  end
142
150
 
143
151
  describe "AutomateIt::TagManager::Struct" do
@@ -166,6 +174,12 @@ describe "AutomateIt::TagManager::Struct" do
166
174
  "@all_servers",
167
175
  "!@proxy_servers",
168
176
  ],
177
+ "apache-servers-using-dashes" => [
178
+ "@apache_servers",
179
+ ],
180
+ "apache-servers-using-dashes-include" => [
181
+ "@apache-servers-using-dashes",
182
+ ]
169
183
  }
170
184
  )
171
185
  end
@@ -190,6 +204,10 @@ describe "AutomateIt::TagManager::YAML" do
190
204
  all_servers_except_proxy_servers:
191
205
  - @all_servers
192
206
  - !@proxy_servers
207
+ apache-servers-using-dashes:
208
+ - @apache_servers
209
+ apache-servers-using-dashes-include:
210
+ - @apache-servers-using-dashes
193
211
  EOB
194
212
  @m.setup(
195
213
  :default => :yaml,
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: automateit
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.71101.1
6
+ version: 0.71101.2
7
7
  date: 2007-11-01 00:00:00 -07:00
8
8
  summary: AutomateIt is an open source tool for automating the setup and maintenance of servers, applications and their dependencies.
9
9
  require_paths:
@@ -168,7 +168,6 @@ files:
168
168
  - spec/unit/interpreter_spec.rb
169
169
  - spec/unit/platform_manager_spec.rb
170
170
  - spec/unit/edit_manager_spec.rb
171
- - spec/unit/tag_manager_spec.rb.orig
172
171
  - spec/integration/service_manager_sysv_spec.rb
173
172
  - spec/integration/template_manager_erb_spec.rb
174
173
  - spec/integration/package_manager_spec.rb
@@ -200,7 +199,6 @@ test_files:
200
199
  - spec/unit/interpreter_spec.rb
201
200
  - spec/unit/platform_manager_spec.rb
202
201
  - spec/unit/edit_manager_spec.rb
203
- - spec/unit/tag_manager_spec.rb.orig
204
202
  - spec/integration/service_manager_sysv_spec.rb
205
203
  - spec/integration/template_manager_erb_spec.rb
206
204
  - spec/integration/package_manager_spec.rb
metadata.gz.sig CHANGED
Binary file
@@ -1,215 +0,0 @@
1
- require File.join(File.dirname(File.expand_path(__FILE__)), "/../spec_helper.rb")
2
-
3
- describe "AutomateIt::TagManager", :shared => true do
4
- before(:all) do
5
- @a = AutomateIt.new
6
- @a.platform_manager.setup(
7
- :default => :struct,
8
- :struct => {
9
- :os => "mizrahi",
10
- :arch => "realian",
11
- :distro => "momo",
12
- :version => "s100",
13
- }
14
- )
15
- @a.address_manager.should_receive(:hostnames).any_number_of_times.and_return(["kurou", "kurou.foo"])
16
-
17
- @m = @a.tag_manager
18
- end
19
-
20
- it "should have tags" do
21
- @a.tags.should be_a_kind_of(Enumerable)
22
- end
23
-
24
- it "should have tags that include tag for hostname" do
25
- @a.tags.should include("kurou")
26
- end
27
-
28
- it "should have tag for short hostname" do
29
- @a.tagged?("kurou").should be_true
30
- end
31
-
32
- it "should have tag for long hostname" do
33
- @a.tagged?("kurou.foo").should be_true
34
- end
35
-
36
- it "should have tag for OS" do
37
- @a.tagged?("mizrahi").should be_true
38
- end
39
-
40
- it "should have tag for OS/arch" do
41
- @a.tagged?("mizrahi_realian").should be_true
42
- end
43
-
44
- it "should have tag for distro/release" do
45
- @a.tagged?("momo_s100").should be_true
46
- end
47
-
48
- it "should have tag for a role" do
49
- @a.tagged?("apache_servers").should be_true
50
- end
51
-
52
- it "should match a symbol query" do
53
- @a.tagged?(:apache_servers).should be_true
54
- end
55
-
56
- it "should match a string query" do
57
- @a.tagged?("apache_servers").should be_true
58
- end
59
-
60
- it "should not match unknown symbol keys" do
61
- @a.tagged?(:foo).should be_false
62
- end
63
-
64
- it "should not match unknown string keys" do
65
- @a.tagged?("foo").should be_false
66
- end
67
-
68
- it "should match an AND query" do
69
- @a.tagged?("kurou && apache_servers").should be_true
70
- end
71
-
72
- it "should match an OR query" do
73
- @a.tagged?("kurou || apache_servers").should be_true
74
- end
75
-
76
- it "should match a grouped AND and OR query" do
77
- @a.tagged?("(kurou || apache_servers) && momo_s100").should be_true
78
- end
79
-
80
- it "should not match AND with unknown keys" do
81
- @a.tagged?("kurou && foo").should be_false
82
- end
83
-
84
- it "should not match OR with unknown keys" do
85
- @a.tagged?("foo && bar").should be_false
86
- end
87
-
88
- it "should query tags for a specific host" do
89
- @a.tagged?("proxy_servers", "kurou").should be_false
90
- @a.tagged?("proxy_servers", "akane.foo").should be_true
91
- @a.tagged?("proxy_servers", "akane").should be_true
92
- end
93
-
94
- it "should append tags" do
95
- @a.tagged?("magic").should be_false
96
- @a.tags << "magic"
97
- @a.tagged?("magic").should be_true
98
- end
99
-
100
- it "should find tags with dashes in the name" do
101
- tag_with_dash = "pawafuru-mirakuru"
102
- tag_without_dash = "wandafuru"
103
-
104
- @a.tags << tag_with_dash << tag_without_dash
105
-
106
- @a.tagged?(tag_with_dash).should be_true
107
- @a.tagged?(tag_without_dash).should be_true
108
- end
109
-
110
- it "should find tags for a host" do
111
- @a.tags_for("akane.foo.bar").should include("proxy_servers")
112
- end
113
-
114
- it "should find tags for an array of hosts" do
115
- @a.tags_for(["kurou"]).should include("apache_servers")
116
- end
117
-
118
- it "should find hosts with a tag" do
119
- hosts = @a.hosts_tagged_with("apache_servers")
120
- hosts.should include("kurou")
121
- hosts.should include("shirou")
122
- hosts.should_not include("akane")
123
- end
124
-
125
- it "should find matching negative queries" do
126
- @a.tagged?("akane").should be_false
127
- @a.tagged?("!akane").should be_true
128
- @a.tagged?("!akane && !proxy_servers").should be_true
129
- end
130
-
131
- it "should include group aliases" do
132
- @a.hosts_tagged_with("all_servers").sort.should == ["kurou", "shirou", "akane.foo"].sort
133
- end
134
-
135
- it "should exclude hosts from groups" do
136
- @a.hosts_tagged_with("apache_servers_except_kurou").should == ["shirou"]
137
- end
138
-
139
- it "should exclude groups from groups" do
140
- @a.hosts_tagged_with("all_servers_except_proxy_servers").sort.should == ["kurou", "shirou"].sort
141
- end
142
- end
143
-
144
- describe "AutomateIt::TagManager::Struct" do
145
- it_should_behave_like "AutomateIt::TagManager"
146
-
147
- before(:all) do
148
- @m.setup(
149
- :default => :struct,
150
- :struct => {
151
- "apache_servers" => [
152
- "kurou",
153
- "shirou",
154
- ],
155
- "proxy_servers" => [
156
- "akane.foo",
157
- ],
158
- "all_servers" => [
159
- "@apache_servers",
160
- "@proxy_servers",
161
- ],
162
- "apache_servers_except_kurou" => [
163
- "@apache_servers",
164
- "!kurou",
165
- ],
166
- "all_servers_except_proxy_servers" => [
167
- "@all_servers",
168
- "!@proxy_servers",
169
- ],
170
- }
171
- )
172
- end
173
- end
174
-
175
- describe "AutomateIt::TagManager::YAML" do
176
- it_should_behave_like "AutomateIt::TagManager"
177
-
178
- def setup_yaml_tags
179
- @m[:yaml].should_receive(:_read).any_number_of_times.with("demo.yml").and_return(<<-EOB)
180
- <%="apache_servers"%>:
181
- - kurou
182
- - shirou
183
- proxy_servers:
184
- - akane.foo
185
- all_servers:
186
- - @apache_servers
187
- - @proxy_servers
188
- apache_servers_except_kurou:
189
- - @apache_servers
190
- - !kurou
191
- all_servers_except_proxy_servers:
192
- - @all_servers
193
- - !@proxy_servers
194
- EOB
195
- @m.setup(
196
- :default => :yaml,
197
- :file => "demo.yml"
198
- )
199
- end
200
-
201
- before(:all) do
202
- setup_yaml_tags
203
- end
204
-
205
- it "should not clear tags if re-loaded" do
206
- setup_yaml_tags
207
- tag = "ivemell"
208
-
209
- @a.tags << tag
210
- @a.should be_tagged(tag)
211
-
212
- setup_yaml_tags
213
- @a.should be_tagged(tag)
214
- end
215
- end