Signed-off-by: Luke Kanies <lu...@reductivelabs.com>
---
lib/puppet/defaults.rb | 5 -----
1 files changed, 0 insertions(+), 5 deletions(-)
diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb
index ca4b9b8..fe68ce7 100644
--- a/lib/puppet/defaults.rb
+++ b/lib/puppet/defaults.rb
@@ -700,11 +700,6 @@ module Puppet
]
)
- setdefaults(:parser,
- :typecheck => [true, "Whether to validate types during parsing."],
- :paramcheck => [true, "Whether to validate parameters during parsing."]
- )
-
setdefaults(:main,
:casesensitive => [false,
"Whether matching in case statements and selectors
--
1.6.1
diff --git a/lib/puppet.rb b/lib/puppet.rb
index 03cb5ed..dc5c123 100644
--- a/lib/puppet.rb
+++ b/lib/puppet.rb
@@ -167,6 +167,8 @@ end
require 'puppet/type'
require 'puppet/parser'
+require 'puppet/resource'
+require 'puppet/resource/reference'
require 'puppet/network'
require 'puppet/ssl'
require 'puppet/module'
diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb
index 828b1b3..3941762 100644
--- a/lib/puppet/util/settings.rb
+++ b/lib/puppet/util/settings.rb
@@ -4,6 +4,8 @@ require 'getoptlong'
require 'puppet/external/event-loop'
require 'puppet/util/cacher'
require 'puppet/util/loadedfile'
+require 'puppet/resource'
+require 'puppet/resource/reference'
# The class for handling configuration files.
class Puppet::Util::Settings
--
1.6.1
Signed-off-by: Luke Kanies <lu...@reductivelabs.com>
---
lib/puppet/parser/grammar.ra | 9 +-
lib/puppet/parser/parser.rb | 1148 ++++++++++++++++++++++--------------------
spec/unit/parser/parser.rb | 41 ++
3 files changed, 637 insertions(+), 561 deletions(-)
diff --git a/lib/puppet/parser/grammar.ra b/lib/puppet/parser/grammar.ra
index 519e4f6..5dbf6f4 100644
--- a/lib/puppet/parser/grammar.ra
+++ b/lib/puppet/parser/grammar.ra
@@ -653,17 +653,17 @@ definition: DEFINE classname argumentlist LBRACE statements RBRACE {
}
#hostclass: CLASS NAME argumentlist parent LBRACE statements RBRACE {
-hostclass: CLASS classname classparent LBRACE statements RBRACE {
+hostclass: CLASS classname argumentlist classparent LBRACE statements RBRACE {
@lexer.commentpop
# Our class gets defined in the parent namespace, not our own.
@lexer.namepop
- newclass classname(val[1]), :code => val[4], :parent => val[2], :line => val[0][:line]
+ newclass classname(val[1]), :arguments => val[2], :code => val[5], :parent => val[3], :line => val[0][:line]
result = nil
-} | CLASS classname classparent LBRACE RBRACE {
+} | CLASS classname argumentlist classparent LBRACE RBRACE {
@lexer.commentpop
# Our class gets defined in the parent namespace, not our own.
@lexer.namepop
- newclass classname(val[1]), :parent => val[2], :line => val[0][:line]
+ newclass classname(val[1]), :arguments => val[2], :parent => val[3], :line => val[0][:line]
result = nil
}
@@ -681,6 +681,7 @@ classref: CLASSREF { result = val[0][:value] }
classname: NAME { result = val[0][:value] }
| CLASSNAME { result = val[0][:value] }
+ | CLASS { result = "class" }
# Multiple hostnames, as used for node names. These are all literal
# strings, not AST objects.
diff --git a/lib/puppet/parser/parser.rb b/lib/puppet/parser/parser.rb
index b962efa..2f7d754 100644
--- a/lib/puppet/parser/parser.rb
+++ b/lib/puppet/parser/parser.rb
@@ -24,7 +24,7 @@ module Puppet
module Parser
class Parser < Racc::Parser
-module_eval(<<'...end grammar.ra/module_eval...', 'grammar.ra', 801)
+module_eval(<<'...end grammar.ra/module_eval...', 'grammar.ra', 802)
# It got too annoying having code in a file that needs to be compiled.
require 'puppet/parser/parser_support'
@@ -39,147 +39,158 @@ require 'puppet/parser/parser_support'
##### State transition tables begin ###
racc_action_table = [
- 77, 56, 59, 56, 59, 54, 285, 187, 165, 126,
- 158, 159, 160, 144, 284, 56, 59, 152, 156, 48,
- 73, 77, 56, 59, 170, 138, 90, 77, 56, 59,
- 91, 48, 249, 48, 123, 58, 61, 58, 201, 68,
- 248, 68, 312, 92, 55, 78, 111, 73, 63, 194,
- 63, 84, 48, 77, 56, 59, 58, 61, 48, 41,
- 68, 41, 58, 61, 187, 55, 68, 93, 261, 63,
- 247, 55, 78, 38, 39, 63, -146, 138, 84, -151,
- 41, 287, 38, 39, 48, 253, 41, 301, 58, 201,
- 257, 264, 68, 77, 56, 59, 137, 111, 245, 246,
- 300, 63, 165, 77, 56, 59, 245, 246, 40, 277,
- 253, 44, 41, 48, 36, 257, 163, 40, 170, 165,
- 44, 4, 8, 73, 48, 54, 56, 59, 58, 61,
- 48, 41, 68, 165, 48, 170, 36, 55, 58, 61,
- 41, 63, 68, 4, 48, 51, 36, 55, 78, 170,
- 207, 63, 41, 4, 84, 163, 48, 77, 56, 59,
- 58, 61, 41, 206, 68, 38, 39, 36, 52, 55,
- 183, 208, -148, 63, 4, 210, 211, 73, 77, 56,
- 59, 160, 144, -145, 41, 270, 152, 156, 48, 160,
- 144, 130, 58, 61, 152, 156, 68, 77, 56, 59,
- 40, 55, 78, 44, 272, 63, 250, 138, 84, 48,
- 245, 246, -147, 58, 61, -149, 41, 68, 77, 56,
- 59, -150, 55, 41, 161, 217, 63, 278, 48, 210,
- 218, 258, 58, 61, 163, 241, 68, 41, 73, 210,
- 211, 55, 33, 34, 41, 63, 56, 59, 175, 48,
- 77, 56, 59, 58, 61, -146, 41, 68, 210, 311,
- 152, 156, 55, 78, 152, 156, 63, -148, 90, 84,
- -145, 77, 56, 59, 176, 137, 177, 41, 280, -163,
- 41, 48, 178, -149, -147, 58, 61, 91, 286, 68,
- 184, -147, 132, 130, 55, 196, 298, 299, 63, 186,
- 302, 189, 48, 77, 56, 59, 58, 61, 105, 41,
- 68, 189, -145, -148, 189, 55, -150, 280, 314, 63,
- 99, -147, -145, 73, 77, 56, 59, -148, -146, -150,
- 41, 316, 190, -146, 48, 97, 130, 47, 58, 61,
- 322, -198, 68, 37, 196, 187, 192, 55, 78, nil,
- nil, 63, nil, nil, 84, 48, 77, 56, 59, 58,
- 61, nil, 41, 68, nil, nil, nil, nil, 55, nil,
- nil, nil, 63, nil, nil, nil, 73, 77, 56, 59,
- nil, nil, nil, 41, nil, nil, nil, 48, nil, nil,
- nil, 58, 61, nil, nil, 68, nil, 73, nil, nil,
- 55, 78, nil, nil, 63, nil, nil, 84, 48, 77,
- 56, 59, 58, 61, nil, 41, 68, nil, nil, nil,
- nil, 55, 78, nil, nil, 63, nil, nil, 84, 73,
- 77, 56, 59, nil, nil, nil, 41, nil, nil, nil,
- 48, nil, nil, nil, 58, 61, nil, nil, 68, nil,
- 73, nil, nil, 55, 78, nil, nil, 63, nil, nil,
- 84, 48, 77, 56, 59, 58, 61, nil, 41, 68,
- nil, nil, nil, nil, 55, 78, nil, nil, 63, nil,
- nil, 84, nil, 77, 56, 59, nil, nil, nil, 41,
- nil, nil, nil, 48, nil, nil, nil, 58, 113, nil,
- nil, 68, nil, 73, nil, nil, 111, nil, nil, nil,
- 63, nil, 155, nil, 48, nil, nil, nil, 58, 61,
- 146, 41, 68, 77, 56, 59, 141, 55, 78, nil,
- nil, 63, nil, nil, 84, nil, nil, 77, 56, 59,
- nil, nil, 41, nil, 77, 56, 59, nil, 158, 159,
- 160, 144, 145, 147, 48, 152, 156, nil, 58, 61,
- nil, nil, 68, nil, 73, nil, nil, 55, 48, 155,
- nil, 63, 58, 61, nil, 48, 68, 146, nil, 58,
- 61, 55, 41, 68, nil, 63, nil, nil, 55, 78,
- nil, nil, 63, nil, nil, 84, 41, 77, 56, 59,
- 56, 59, nil, 41, nil, 158, 159, 160, 144, 145,
- 147, nil, 152, 156, nil, nil, nil, 73, 77, 56,
- 59, nil, nil, nil, 77, 56, 59, nil, 48, nil,
- 48, nil, 58, 61, 58, 201, 68, nil, 68, nil,
- nil, 55, 78, 111, 73, 63, nil, 63, 84, 48,
- 77, 56, 59, 58, 61, 48, 41, 68, 41, 58,
- 61, nil, 55, 68, nil, nil, 63, nil, 55, 78,
- 73, nil, 63, nil, nil, 84, nil, 41, nil, 155,
- nil, 48, nil, 41, nil, 58, 61, 146, nil, 68,
- 77, 56, 59, nil, 55, 78, nil, nil, 63, nil,
- nil, 84, nil, nil, nil, nil, nil, nil, nil, 41,
- 73, 77, 56, 59, nil, 158, 159, 160, 144, 145,
- 147, 48, 152, 156, nil, 58, 61, nil, nil, 68,
- nil, 73, nil, nil, 55, 78, nil, nil, 63, nil,
- nil, 84, 48, 77, 56, 59, 58, 61, nil, 41,
- 68, nil, nil, nil, nil, 55, 78, nil, nil, 63,
- nil, nil, 84, 73, 77, 56, 59, nil, nil, nil,
- 41, nil, nil, nil, 48, nil, nil, nil, 58, 61,
- nil, nil, 68, nil, 73, nil, nil, 55, 78, nil,
- nil, 63, nil, nil, 84, 48, 77, 56, 59, 58,
- 61, nil, 41, 68, nil, nil, nil, nil, 55, 78,
- nil, nil, 63, nil, nil, 84, 73, nil, 56, 59,
- nil, nil, nil, 41, 56, 59, nil, 48, nil, nil,
- nil, 58, 61, nil, nil, 68, nil, nil, 133, nil,
- 55, 78, nil, nil, 63, nil, nil, 84, 48, 56,
- 59, nil, 58, 61, 48, 41, 68, nil, 58, 201,
- 52, 55, 68, 56, 59, 63, nil, 111, nil, 275,
- nil, 63, nil, nil, nil, nil, 41, nil, nil, 48,
- nil, nil, 41, 58, 61, 56, 59, 68, nil, nil,
- nil, 52, 55, 48, nil, nil, 63, 58, 201, 56,
- 59, 68, nil, nil, nil, 214, 111, 41, nil, nil,
- 63, nil, nil, nil, nil, 48, nil, 56, 59, 58,
- 61, 41, nil, 68, nil, nil, nil, 52, 55, 48,
- nil, nil, 63, 58, 201, 56, 59, 68, 203, nil,
- nil, nil, 111, 41, nil, nil, 63, 48, nil, 56,
- 59, 58, 61, nil, nil, 68, nil, 41, nil, 52,
- 55, nil, nil, nil, 63, 48, nil, 56, 59, 58,
- 201, 282, nil, 68, nil, 41, nil, nil, 111, 48,
- nil, nil, 63, 58, 201, nil, nil, 68, nil, nil,
- nil, nil, 111, 41, nil, nil, 63, 48, nil, 157,
- nil, 58, 201, nil, nil, 68, nil, 41, 150, 155,
- 111, nil, nil, nil, 63, nil, nil, 146, 148, 151,
- 154, 150, 155, nil, nil, 41, nil, nil, nil, nil,
- 146, 148, 151, 154, nil, nil, 158, 159, 160, 144,
- nil, 149, 153, 152, 156, 158, 159, 160, 144, 145,
- 147, nil, 152, 156, nil, nil, nil, nil, 158, 159,
- 160, 144, 145, 147, nil, 152, 156, 150, 155, nil,
- nil, nil, nil, nil, nil, nil, 146, 148, 151, 154,
- 150, 155, nil, nil, nil, nil, nil, nil, nil, 146,
- 148, 151, 154, nil, nil, nil, nil, nil, nil, nil,
- 149, 153, nil, nil, 158, 159, 160, 144, 145, 147,
- nil, 152, 156, 149, 153, nil, nil, 158, 159, 160,
- 144, 145, 147, nil, 152, 156, 150, 155, nil, nil,
- nil, nil, nil, nil, 216, 146, 148, 151, 154, 150,
- 155, nil, nil, nil, nil, nil, nil, nil, 146, 148,
- 151, 154, nil, 155, nil, nil, nil, nil, nil, 149,
- 153, 146, nil, 158, 159, 160, 144, 145, 147, nil,
- 152, 156, nil, 153, nil, nil, 158, 159, 160, 144,
- 145, 147, 281, 152, 156, nil, nil, nil, nil, 158,
- 159, 160, 144, 145, 147, nil, 152, 156, nil, nil,
+ 78, 57, 60, 127, 190, 39, 40, 292, 166, 250,
+ 252, 180, 39, 40, 55, 131, 184, 290, 251, 49,
+ 74, 78, 57, 60, 171, 289, 153, 157, 124, 39,
+ 40, 49, 248, 249, 139, 59, 62, 248, 249, 69,
+ 41, 74, 257, 45, 56, 79, 197, 41, 64, 210,
+ 45, 85, 49, 78, 57, 60, 59, 62, 138, 42,
+ 69, 261, 209, 42, 41, 56, 79, 45, 190, 64,
+ 42, 282, 85, 74, 78, 57, 60, 260, 256, 91,
+ 42, 139, 35, 92, 49, 265, 37, 42, 59, 62,
+ 259, 35, 69, 4, 74, 37, 93, 56, 79, 266,
+ 166, 64, 4, 8, 85, 49, 78, 57, 60, 59,
+ 62, 49, 42, 69, 153, 157, 171, -150, 56, 79,
+ 94, -146, 64, 166, 166, 85, 74, 78, 57, 60,
+ 33, 34, 35, 42, 49, 49, 37, 49, 269, 171,
+ 171, 59, 62, 4, 244, 69, 164, 74, 213, 214,
+ 56, 79, 57, 60, 64, 213, 315, 85, 49, 55,
+ 57, 60, 59, 62, 164, 42, 69, -151, 161, 145,
+ -148, 56, 79, 153, 157, 64, 57, 60, 85, 52,
+ 78, 57, 60, 180, 275, 35, 42, 131, 184, 37,
+ 49, 277, 264, 139, 59, 62, 4, -145, 69, -147,
+ 74, -149, 53, 56, 161, 145, 131, 64, 283, 153,
+ 157, 49, 78, 57, 60, 59, 62, 253, 42, 69,
+ 192, 248, 249, 190, 56, 79, -149, 162, 64, -150,
+ -146, 85, 211, 78, 57, 60, 213, 214, -148, 42,
+ 220, 91, -145, 49, 213, 221, 164, 59, 62, 42,
+ 285, 69, 138, 176, 177, 178, 56, -163, 42, 291,
+ 64, 106, 92, -147, 49, 78, 57, 60, 59, 62,
+ 133, 42, 69, 199, 258, 185, -147, 56, 106, 189,
+ 192, 64, 192, 100, -145, 74, 78, 57, 60, 316,
+ 285, 318, 42, -148, -147, -145, 49, -148, -146, -150,
+ 59, 62, 320, 98, 69, 193, 74, 48, 324, 56,
+ 79, -199, 38, 64, -146, 199, 85, 49, 78, 57,
+ 60, 59, 62, 195, 42, 69, nil, nil, nil, nil,
+ 56, 79, nil, nil, 64, nil, nil, 85, nil, 78,
+ 57, 60, nil, nil, nil, 42, nil, nil, nil, 49,
+ nil, nil, nil, 59, 204, nil, nil, 69, nil, nil,
+ nil, nil, 112, nil, nil, nil, 64, nil, nil, nil,
+ 49, 78, 57, 60, 59, 62, nil, 42, 69, nil,
+ nil, nil, nil, 56, nil, nil, nil, 64, nil, nil,
+ nil, 74, 78, 57, 60, nil, nil, nil, 42, nil,
+ nil, nil, 49, nil, nil, nil, 59, 62, nil, nil,
+ 69, nil, 74, nil, nil, 56, 79, nil, nil, 64,
+ nil, nil, 85, 49, 78, 57, 60, 59, 62, nil,
+ 42, 69, nil, nil, nil, nil, 56, 79, nil, nil,
+ 64, nil, nil, 85, 74, 78, 57, 60, nil, nil,
+ nil, 42, nil, nil, nil, 49, nil, nil, nil, 59,
+ 62, nil, nil, 69, nil, 74, nil, nil, 56, 79,
+ nil, nil, 64, nil, nil, 85, 49, 78, 57, 60,
+ 59, 62, nil, 42, 69, nil, nil, nil, nil, 56,
+ 79, nil, nil, 64, nil, nil, 85, nil, 78, 57,
+ 60, nil, nil, nil, 42, nil, nil, nil, 49, nil,
+ nil, nil, 59, 62, nil, nil, 69, 78, 57, 60,
+ nil, 56, nil, nil, nil, 64, nil, nil, nil, 49,
+ nil, nil, nil, 59, 114, nil, 42, 69, 78, 57,
+ 60, nil, 112, nil, nil, nil, 64, nil, 49, nil,
+ nil, nil, 59, 62, nil, nil, 69, 42, 74, nil,
+ nil, 56, nil, nil, nil, 64, nil, nil, nil, 49,
+ 78, 57, 60, 59, 62, nil, 42, 69, nil, nil,
+ nil, nil, 56, 79, nil, nil, 64, nil, nil, 85,
+ 74, 78, 57, 60, nil, nil, nil, 42, nil, nil,
+ nil, 49, nil, nil, nil, 59, 62, nil, nil, 69,
+ nil, nil, nil, nil, 56, 79, nil, nil, 64, nil,
+ nil, 85, 49, 78, 57, 60, 59, 62, nil, 42,
+ 69, nil, nil, nil, nil, 56, nil, nil, nil, 64,
+ nil, nil, nil, 74, 78, 57, 60, nil, nil, nil,
+ 42, nil, nil, nil, 49, nil, nil, nil, 59, 62,
+ nil, nil, 69, 78, 57, 60, nil, 56, 79, nil,
+ nil, 64, nil, nil, 85, 49, nil, nil, nil, 59,
+ 62, nil, 42, 69, 78, 57, 60, nil, 56, nil,
+ nil, nil, 64, nil, 49, nil, nil, nil, 59, 62,
+ nil, nil, 69, 42, nil, nil, nil, 56, nil, nil,
+ nil, 64, nil, nil, nil, 49, 78, 57, 60, 59,
+ 62, nil, 42, 69, nil, nil, nil, nil, 56, nil,
+ nil, nil, 64, nil, nil, nil, 74, 78, 57, 60,
+ nil, nil, nil, 42, nil, nil, nil, 49, nil, nil,
+ nil, 59, 62, nil, nil, 69, nil, 74, nil, nil,
+ 56, 79, nil, nil, 64, nil, 156, 85, 49, nil,
+ nil, nil, 59, 62, 147, 42, 69, 78, 57, 60,
+ 142, 56, 79, nil, nil, 64, nil, nil, 85, nil,
+ nil, nil, nil, nil, nil, nil, 42, nil, 78, 57,
+ 60, nil, 159, 160, 161, 145, 146, 148, 49, 153,
+ 157, nil, 59, 62, nil, nil, 69, nil, 74, nil,
+ nil, 56, nil, nil, nil, 64, nil, nil, nil, 49,
+ 78, 57, 60, 59, 62, nil, 42, 69, nil, nil,
+ nil, nil, 56, 79, nil, nil, 64, nil, nil, 85,
+ 74, nil, 57, 60, nil, 206, nil, 42, nil, nil,
+ nil, 49, nil, nil, nil, 59, 62, nil, nil, 69,
+ nil, 57, 60, nil, 56, 79, nil, nil, 64, nil,
+ nil, 85, 49, nil, nil, nil, 59, 204, nil, 42,
+ 69, 280, 57, 60, nil, 112, nil, nil, nil, 64,
+ nil, 49, 57, 60, nil, 59, 62, nil, nil, 69,
+ 42, nil, nil, 53, 56, nil, nil, nil, 64, nil,
+ nil, nil, 49, nil, 57, 60, 59, 62, 287, 42,
+ 69, nil, 49, nil, 53, 56, 59, 204, nil, 64,
+ 69, nil, 57, 60, nil, 112, nil, nil, nil, 64,
+ 42, nil, nil, nil, 49, nil, nil, nil, 59, 204,
+ 42, nil, 69, 57, 60, nil, nil, 112, nil, 57,
+ 60, 64, 49, nil, nil, nil, 59, 204, nil, nil,
+ 69, nil, 42, 134, nil, 112, nil, nil, nil, 64,
+ nil, nil, nil, 49, 57, 60, nil, 59, 62, 49,
+ 42, 69, nil, 59, 204, 53, 56, 69, 57, 60,
+ 64, nil, 112, nil, 217, nil, 64, nil, nil, nil,
+ nil, 42, nil, nil, 49, nil, nil, 42, 59, 62,
+ 57, 60, 69, nil, nil, nil, 53, 56, 49, nil,
+ nil, 64, 59, 204, 57, 60, 69, nil, nil, nil,
+ nil, 112, 42, nil, nil, 64, nil, nil, nil, nil,
+ 49, nil, nil, nil, 59, 204, 42, nil, 69, nil,
+ nil, nil, nil, 112, 49, 158, nil, 64, 59, 204,
+ nil, nil, 69, nil, 151, 156, nil, 112, 42, nil,
+ nil, 64, nil, 147, 149, 152, 155, 151, 156, nil,
+ nil, nil, 42, nil, nil, nil, 147, 149, 152, 155,
+ nil, nil, 159, 160, 161, 145, nil, 150, 154, 153,
+ 157, 159, 160, 161, 145, 146, 148, nil, 153, 157,
+ 150, 154, nil, nil, 159, 160, 161, 145, 146, 148,
+ nil, 153, 157, 151, 156, nil, nil, nil, nil, nil,
+ nil, nil, 147, 149, 152, 155, 151, 156, nil, nil,
+ nil, nil, nil, nil, 219, 147, 149, 152, 155, 159,
+ 160, 161, 145, 146, 148, nil, 153, 157, nil, nil,
+ 159, 160, 161, 145, 146, 148, nil, 153, 157, 150,
+ 154, nil, nil, 159, 160, 161, 145, 146, 148, nil,
+ 153, 157, 151, 156, nil, nil, nil, nil, nil, nil,
+ nil, 147, 149, 152, 155, 151, 156, nil, nil, nil,
+ nil, nil, nil, nil, 147, 149, 152, 155, nil, 156,
+ nil, nil, nil, nil, nil, nil, 154, 147, nil, 159,
+ 160, 161, 145, 146, 148, nil, 153, 157, 150, 154,
+ 156, nil, 159, 160, 161, 145, 146, 148, 147, 153,
+ 157, nil, nil, 156, nil, 159, 160, 161, 145, 146,
+ 148, 147, 153, 157, 159, 160, 161, 145, 146, 148,
+ nil, 153, 157, nil, nil, nil, 159, 160, 161, 145,
+ 146, 148, 311, 153, 157, nil, nil, nil, nil, 159,
+ 160, 161, 145, 146, 148, nil, 153, 157, nil, nil,
nil, 303, nil, 18, nil, 23, 26, nil, 1, 5,
nil, 12, nil, 16, nil, 20, nil, 27, nil, nil,
- 4, 8, 18, 305, 23, 26, nil, 1, 5, nil,
+ 4, 8, 18, 308, 23, 26, nil, 1, 5, nil,
12, nil, 16, nil, 20, nil, 27, nil, nil, 4,
- 8, nil, 307, nil, 18, nil, 23, 26, nil, 1,
+ 8, nil, 286, nil, 18, nil, 23, 26, nil, 1,
5, nil, 12, nil, 16, nil, 20, nil, 27, nil,
- nil, 4, 8, 18, 320, 23, 26, nil, 1, 5,
+ nil, 4, 8, 18, 321, 23, 26, nil, 1, 5,
nil, 12, nil, 16, nil, 20, nil, 27, nil, nil,
- 4, 8, nil, 259, nil, 18, nil, 23, 26, nil,
+ 4, 8, nil, 322, nil, 18, nil, 23, 26, nil,
1, 5, nil, 12, nil, 16, nil, 20, nil, 27,
- nil, nil, 4, 8, 18, 232, 23, 26, nil, 1,
+ nil, nil, 4, 8, 18, 272, 23, 26, nil, 1,
5, nil, 12, nil, 16, nil, 20, nil, 27, nil,
- nil, 4, 8, nil, 323, nil, 18, nil, 23, 26,
+ nil, 4, 8, nil, 325, nil, 18, nil, 23, 26,
nil, 1, 5, nil, 12, nil, 16, nil, 20, nil,
- 27, nil, nil, 4, 8, 18, 325, 23, 26, nil,
+ 27, nil, nil, 4, 8, 18, 327, 23, 26, nil,
1, 5, nil, 12, nil, 16, nil, 20, nil, 27,
- nil, nil, 4, 8, nil, 327, nil, 18, nil, 23,
+ nil, nil, 4, 8, nil, 329, nil, 18, nil, 23,
26, nil, 1, 5, nil, 12, nil, 16, nil, 20,
- nil, 27, nil, nil, 4, 8, 18, 267, 23, 26,
+ nil, 27, nil, nil, 4, 8, 18, 235, 23, 26,
nil, 1, 5, nil, 12, nil, 16, nil, 20, nil,
- 27, nil, nil, 4, 8, nil, 328, nil, 18, nil,
+ 27, nil, nil, 4, 8, nil, 330, nil, 18, nil,
23, 26, nil, 1, 5, nil, 12, nil, 16, nil,
20, nil, 27, nil, nil, 4, 8, 18, nil, 23,
26, nil, 1, 5, nil, 12, nil, 16, nil, 20,
@@ -187,369 +198,384 @@ racc_action_table = [
nil, 1, 5, nil, 12, nil, 16, nil, 20, nil,
27, nil, nil, 4, 8, 18, nil, 23, 26, nil,
1, 5, nil, 12, nil, 16, nil, 20, nil, 27,
- nil, nil, 4, 8, 158, 159, 160, 144, 145, 147,
- nil, 152, 156, 158, 159, 160, 144, 145, 147, nil,
- 152, 156 ]
+ nil, nil, 4, 8, 159, 160, 161, 145, nil, nil,
+ nil, 153, 157 ]
racc_action_check = [
- 155, 155, 155, 248, 248, 61, 240, 130, 93, 43,
- 222, 222, 222, 222, 240, 176, 176, 222, 222, 93,
- 155, 90, 90, 90, 93, 61, 21, 84, 84, 84,
- 21, 155, 169, 248, 43, 155, 155, 248, 248, 155,
- 169, 248, 280, 21, 155, 155, 248, 84, 155, 130,
- 248, 155, 90, 186, 186, 186, 90, 90, 84, 155,
- 90, 248, 84, 84, 113, 90, 84, 21, 185, 90,
- 166, 84, 84, 12, 12, 84, 83, 113, 84, 82,
- 90, 243, 123, 123, 186, 178, 84, 255, 186, 186,
- 178, 188, 186, 187, 187, 187, 215, 186, 166, 166,
- 255, 186, 92, 159, 159, 159, 243, 243, 12, 215,
- 301, 12, 186, 92, 28, 301, 189, 123, 92, 244,
- 123, 28, 28, 159, 187, 16, 16, 16, 187, 187,
- 244, 12, 187, 165, 159, 244, 5, 187, 159, 159,
- 123, 187, 159, 5, 165, 16, 26, 159, 159, 165,
- 134, 159, 187, 26, 159, 190, 16, 18, 18, 18,
- 16, 16, 159, 134, 16, 126, 126, 105, 16, 16,
- 105, 136, 81, 16, 105, 136, 136, 18, 20, 20,
- 20, 234, 234, 80, 16, 195, 234, 234, 18, 235,
- 235, 196, 18, 18, 235, 235, 18, 194, 194, 194,
- 126, 18, 18, 126, 197, 18, 174, 201, 18, 20,
- 174, 174, 76, 20, 20, 72, 18, 20, 144, 144,
- 144, 71, 20, 126, 89, 140, 20, 218, 194, 140,
- 140, 179, 194, 194, 91, 162, 194, 20, 144, 162,
- 162, 194, 1, 1, 156, 194, 23, 23, 94, 144,
- 302, 302, 302, 144, 144, 70, 194, 144, 274, 274,
- 236, 236, 144, 144, 219, 219, 144, 67, 66, 144,
- 64, 298, 298, 298, 96, 57, 97, 144, 232, 55,
- 152, 302, 98, 88, 53, 302, 302, 101, 242, 302,
- 106, 110, 49, 47, 302, 251, 253, 254, 302, 112,
- 257, 114, 298, 78, 78, 78, 298, 298, 35, 302,
- 298, 266, 115, 117, 164, 298, 86, 281, 284, 298,
- 27, 290, 292, 78, 272, 272, 272, 293, 294, 295,
- 298, 297, 118, 119, 78, 25, 175, 15, 78, 78,
- 310, 311, 78, 9, 131, 163, 124, 78, 78, nil,
- nil, 78, nil, nil, 78, 272, 145, 145, 145, 272,
- 272, nil, 78, 272, nil, nil, nil, nil, 272, nil,
- nil, nil, 272, nil, nil, nil, 145, 33, 33, 33,
- nil, nil, nil, 272, nil, nil, nil, 145, nil, nil,
- nil, 145, 145, nil, nil, 145, nil, 33, nil, nil,
- 145, 145, nil, nil, 145, nil, nil, 145, 33, 34,
- 34, 34, 33, 33, nil, 145, 33, nil, nil, nil,
- nil, 33, 33, nil, nil, 33, nil, nil, 33, 34,
- 146, 146, 146, nil, nil, nil, 33, nil, nil, nil,
- 34, nil, nil, nil, 34, 34, nil, nil, 34, nil,
- 146, nil, nil, 34, 34, nil, nil, 34, nil, nil,
- 34, 146, 37, 37, 37, 146, 146, nil, 34, 146,
- nil, nil, nil, nil, 146, 146, nil, nil, 146, nil,
- nil, 146, nil, 147, 147, 147, nil, nil, nil, 146,
- nil, nil, nil, 37, nil, nil, nil, 37, 37, nil,
- nil, 37, nil, 147, nil, nil, 37, nil, nil, nil,
- 37, nil, 223, nil, 147, nil, nil, nil, 147, 147,
- 223, 37, 147, 77, 77, 77, 77, 147, 147, nil,
- nil, 147, nil, nil, 147, nil, nil, 209, 209, 209,
- nil, nil, 147, nil, 73, 73, 73, nil, 223, 223,
- 223, 223, 223, 223, 77, 223, 223, nil, 77, 77,
- nil, nil, 77, nil, 73, nil, nil, 77, 209, 226,
- nil, 77, 209, 209, nil, 73, 209, 226, nil, 73,
- 73, 209, 77, 73, nil, 209, nil, nil, 73, 73,
- nil, nil, 73, nil, nil, 73, 209, 158, 158, 158,
- 203, 203, nil, 73, nil, 226, 226, 226, 226, 226,
- 226, nil, 226, 226, nil, nil, nil, 158, 54, 54,
- 54, nil, nil, nil, 148, 148, 148, nil, 158, nil,
- 203, nil, 158, 158, 203, 203, 158, nil, 203, nil,
- nil, 158, 158, 203, 148, 158, nil, 203, 158, 54,
- 149, 149, 149, 54, 54, 148, 158, 54, 203, 148,
- 148, nil, 54, 148, nil, nil, 54, nil, 148, 148,
- 149, nil, 148, nil, nil, 148, nil, 54, nil, 229,
- nil, 149, nil, 148, nil, 149, 149, 229, nil, 149,
- 150, 150, 150, nil, 149, 149, nil, nil, 149, nil,
- nil, 149, nil, nil, nil, nil, nil, nil, nil, 149,
- 150, 151, 151, 151, nil, 229, 229, 229, 229, 229,
- 229, 150, 229, 229, nil, 150, 150, nil, nil, 150,
- nil, 151, nil, nil, 150, 150, nil, nil, 150, nil,
- nil, 150, 151, 153, 153, 153, 151, 151, nil, 150,
- 151, nil, nil, nil, nil, 151, 151, nil, nil, 151,
- nil, nil, 151, 153, 154, 154, 154, nil, nil, nil,
- 151, nil, nil, nil, 153, nil, nil, nil, 153, 153,
- nil, nil, 153, nil, 154, nil, nil, 153, 153, nil,
- nil, 153, nil, nil, 153, 154, 160, 160, 160, 154,
- 154, nil, 153, 154, nil, nil, nil, nil, 154, 154,
- nil, nil, 154, nil, nil, 154, 160, nil, 51, 51,
- nil, nil, nil, 154, 249, 249, nil, 160, nil, nil,
- nil, 160, 160, nil, nil, 160, nil, nil, 51, nil,
- 160, 160, nil, nil, 160, nil, nil, 160, 51, 207,
- 207, nil, 51, 51, 249, 160, 51, nil, 249, 249,
- 51, 51, 249, 285, 285, 51, nil, 249, nil, 207,
- nil, 249, nil, nil, nil, nil, 51, nil, nil, 207,
- nil, nil, 249, 207, 207, 138, 138, 207, nil, nil,
- nil, 207, 207, 285, nil, nil, 207, 285, 285, 309,
- 309, 285, nil, nil, nil, 138, 285, 207, nil, nil,
- 285, nil, nil, nil, nil, 138, nil, 137, 137, 138,
- 138, 285, nil, 138, nil, nil, nil, 138, 138, 309,
- nil, nil, 138, 309, 309, 132, 132, 309, 132, nil,
- nil, nil, 309, 138, nil, nil, 309, 137, nil, 161,
- 161, 137, 137, nil, nil, 137, nil, 309, nil, 137,
- 137, nil, nil, nil, 137, 132, nil, 238, 238, 132,
- 132, 238, nil, 132, nil, 137, nil, nil, 132, 161,
- nil, nil, 132, 161, 161, nil, nil, 161, nil, nil,
- nil, nil, 161, 132, nil, nil, 161, 238, nil, 87,
- nil, 238, 238, nil, nil, 238, nil, 161, 87, 87,
- 238, nil, nil, nil, 238, nil, nil, 87, 87, 87,
- 87, 228, 228, nil, nil, 238, nil, nil, nil, nil,
- 228, 228, 228, 228, nil, nil, 220, 220, 220, 220,
- nil, 87, 87, 220, 220, 87, 87, 87, 87, 87,
- 87, nil, 87, 87, nil, nil, nil, nil, 228, 228,
- 228, 228, 228, 228, nil, 228, 228, 103, 103, nil,
- nil, nil, nil, nil, nil, nil, 103, 103, 103, 103,
- 104, 104, nil, nil, nil, nil, nil, nil, nil, 104,
- 104, 104, 104, nil, nil, nil, nil, nil, nil, nil,
- 103, 103, nil, nil, 103, 103, 103, 103, 103, 103,
- nil, 103, 103, 104, 104, nil, nil, 104, 104, 104,
- 104, 104, 104, nil, 104, 104, 139, 139, nil, nil,
- nil, nil, nil, nil, 139, 139, 139, 139, 139, 224,
- 224, nil, nil, nil, nil, nil, nil, nil, 224, 224,
- 224, 224, nil, 225, nil, nil, nil, nil, nil, 139,
- 139, 225, nil, 139, 139, 139, 139, 139, 139, nil,
- 139, 139, nil, 224, nil, nil, 224, 224, 224, 224,
- 224, 224, 233, 224, 224, nil, nil, nil, nil, 225,
- 225, 225, 225, 225, 225, nil, 225, 225, nil, nil,
- nil, 258, nil, 233, nil, 233, 233, nil, 233, 233,
- nil, 233, nil, 233, nil, 233, nil, 233, nil, nil,
- 233, 233, 258, 260, 258, 258, nil, 258, 258, nil,
- 258, nil, 258, nil, 258, nil, 258, nil, nil, 258,
- 258, nil, 268, nil, 260, nil, 260, 260, nil, 260,
- 260, nil, 260, nil, 260, nil, 260, nil, 260, nil,
- nil, 260, 260, 268, 304, 268, 268, nil, 268, 268,
- nil, 268, nil, 268, nil, 268, nil, 268, nil, nil,
- 268, 268, nil, 184, nil, 304, nil, 304, 304, nil,
+ 156, 156, 156, 44, 131, 124, 124, 246, 93, 167,
+ 170, 106, 127, 127, 62, 48, 106, 243, 170, 93,
+ 156, 155, 155, 155, 93, 243, 239, 239, 44, 12,
+ 12, 156, 246, 246, 62, 156, 156, 167, 167, 156,
+ 124, 155, 180, 124, 156, 156, 131, 127, 156, 135,
+ 127, 156, 155, 154, 154, 154, 155, 155, 218, 156,
+ 155, 184, 135, 124, 12, 155, 155, 12, 114, 155,
+ 127, 218, 155, 154, 152, 152, 152, 182, 179, 21,
+ 155, 114, 5, 21, 154, 186, 5, 12, 154, 154,
+ 182, 28, 154, 5, 152, 28, 21, 154, 154, 188,
+ 94, 154, 28, 28, 154, 152, 159, 159, 159, 152,
+ 152, 94, 154, 152, 222, 222, 94, 87, 152, 152,
+ 21, 84, 152, 166, 247, 152, 159, 160, 160, 160,
+ 1, 1, 26, 152, 166, 247, 26, 159, 191, 166,
+ 247, 159, 159, 26, 163, 159, 192, 160, 163, 163,
+ 159, 159, 177, 177, 159, 279, 279, 159, 160, 16,
+ 16, 16, 160, 160, 193, 159, 160, 83, 237, 237,
+ 82, 160, 160, 237, 237, 160, 23, 23, 160, 16,
+ 18, 18, 18, 260, 198, 185, 160, 199, 260, 185,
+ 16, 200, 185, 204, 16, 16, 185, 81, 16, 77,
+ 18, 73, 16, 16, 238, 238, 176, 16, 221, 238,
+ 238, 18, 20, 20, 20, 18, 18, 175, 16, 18,
+ 165, 175, 175, 164, 18, 18, 89, 90, 18, 72,
+ 71, 18, 137, 91, 91, 91, 137, 137, 68, 18,
+ 141, 67, 65, 20, 141, 141, 92, 20, 20, 157,
+ 235, 20, 58, 95, 97, 98, 20, 56, 153, 245,
+ 20, 99, 102, 54, 91, 161, 161, 161, 91, 91,
+ 50, 20, 91, 254, 181, 107, 111, 91, 36, 113,
+ 271, 91, 115, 27, 116, 161, 145, 145, 145, 285,
+ 286, 289, 91, 118, 295, 297, 161, 298, 299, 300,
+ 161, 161, 302, 25, 161, 119, 145, 15, 314, 161,
+ 161, 315, 9, 161, 120, 132, 161, 145, 189, 189,
+ 189, 145, 145, 125, 161, 145, nil, nil, nil, nil,
+ 145, 145, nil, nil, 145, nil, nil, 145, nil, 277,
+ 277, 277, nil, nil, nil, 145, nil, nil, nil, 189,
+ nil, nil, nil, 189, 189, nil, nil, 189, nil, nil,
+ nil, nil, 189, nil, nil, nil, 189, nil, nil, nil,
+ 277, 146, 146, 146, 277, 277, nil, 189, 277, nil,
+ nil, nil, nil, 277, nil, nil, nil, 277, nil, nil,
+ nil, 146, 147, 147, 147, nil, nil, nil, 277, nil,
+ nil, nil, 146, nil, nil, nil, 146, 146, nil, nil,
+ 146, nil, 147, nil, nil, 146, 146, nil, nil, 146,
+ nil, nil, 146, 147, 33, 33, 33, 147, 147, nil,
+ 146, 147, nil, nil, nil, nil, 147, 147, nil, nil,
+ 147, nil, nil, 147, 33, 34, 34, 34, nil, nil,
+ nil, 147, nil, nil, nil, 33, nil, nil, nil, 33,
+ 33, nil, nil, 33, nil, 34, nil, nil, 33, 33,
+ nil, nil, 33, nil, nil, 33, 34, 261, 261, 261,
+ 34, 34, nil, 33, 34, nil, nil, nil, nil, 34,
+ 34, nil, nil, 34, nil, nil, 34, nil, 38, 38,
+ 38, nil, nil, nil, 34, nil, nil, nil, 261, nil,
+ nil, nil, 261, 261, nil, nil, 261, 257, 257, 257,
+ nil, 261, nil, nil, nil, 261, nil, nil, nil, 38,
+ nil, nil, nil, 38, 38, nil, 261, 38, 148, 148,
+ 148, nil, 38, nil, nil, nil, 38, nil, 257, nil,
+ nil, nil, 257, 257, nil, nil, 257, 38, 148, nil,
+ nil, 257, nil, nil, nil, 257, nil, nil, nil, 148,
+ 85, 85, 85, 148, 148, nil, 257, 148, nil, nil,
+ nil, nil, 148, 148, nil, nil, 148, nil, nil, 148,
+ 85, 190, 190, 190, nil, nil, nil, 148, nil, nil,
+ nil, 85, nil, nil, nil, 85, 85, nil, nil, 85,
+ nil, nil, nil, nil, 85, 85, nil, nil, 85, nil,
+ nil, 85, 190, 151, 151, 151, 190, 190, nil, 85,
+ 190, nil, nil, nil, nil, 190, nil, nil, nil, 190,
+ nil, nil, nil, 151, 55, 55, 55, nil, nil, nil,
+ 190, nil, nil, nil, 151, nil, nil, nil, 151, 151,
+ nil, nil, 151, 197, 197, 197, nil, 151, 151, nil,
+ nil, 151, nil, nil, 151, 55, nil, nil, nil, 55,
+ 55, nil, 151, 55, 212, 212, 212, nil, 55, nil,
+ nil, nil, 55, nil, 197, nil, nil, nil, 197, 197,
+ nil, nil, 197, 55, nil, nil, nil, 197, nil, nil,
+ nil, 197, nil, nil, nil, 212, 150, 150, 150, 212,
+ 212, nil, 197, 212, nil, nil, nil, nil, 212, nil,
+ nil, nil, 212, nil, nil, nil, 150, 79, 79, 79,
+ nil, nil, nil, 212, nil, nil, nil, 150, nil, nil,
+ nil, 150, 150, nil, nil, 150, nil, 79, nil, nil,
+ 150, 150, nil, nil, 150, nil, 228, 150, 79, nil,
+ nil, nil, 79, 79, 228, 150, 79, 78, 78, 78,
+ 78, 79, 79, nil, nil, 79, nil, nil, 79, nil,
+ nil, nil, nil, nil, nil, nil, 79, nil, 74, 74,
+ 74, nil, 228, 228, 228, 228, 228, 228, 78, 228,
+ 228, nil, 78, 78, nil, nil, 78, nil, 74, nil,
+ nil, 78, nil, nil, nil, 78, nil, nil, nil, 74,
+ 149, 149, 149, 74, 74, nil, 78, 74, nil, nil,
+ nil, nil, 74, 74, nil, nil, 74, nil, nil, 74,
+ 149, nil, 133, 133, nil, 133, nil, 74, nil, nil,
+ nil, 149, nil, nil, nil, 149, 149, nil, nil, 149,
+ nil, 210, 210, nil, 149, 149, nil, nil, 149, nil,
+ nil, 149, 133, nil, nil, nil, 133, 133, nil, 149,
+ 133, 210, 138, 138, nil, 133, nil, nil, nil, 133,
+ nil, 210, 206, 206, nil, 210, 210, nil, nil, 210,
+ 133, nil, nil, 210, 210, nil, nil, nil, 210, nil,
+ nil, nil, 138, nil, 241, 241, 138, 138, 241, 210,
+ 138, nil, 206, nil, 138, 138, 206, 206, nil, 138,
+ 206, nil, 251, 251, nil, 206, nil, nil, nil, 206,
+ 138, nil, nil, nil, 241, nil, nil, nil, 241, 241,
+ 206, nil, 241, 52, 52, nil, nil, 241, nil, 290,
+ 290, 241, 251, nil, nil, nil, 251, 251, nil, nil,
+ 251, nil, 241, 52, nil, 251, nil, nil, nil, 251,
+ nil, nil, nil, 52, 139, 139, nil, 52, 52, 290,
+ 251, 52, nil, 290, 290, 52, 52, 290, 313, 313,
+ 52, nil, 290, nil, 139, nil, 290, nil, nil, nil,
+ nil, 52, nil, nil, 139, nil, nil, 290, 139, 139,
+ 162, 162, 139, nil, nil, nil, 139, 139, 313, nil,
+ nil, 139, 313, 313, 252, 252, 313, nil, nil, nil,
+ nil, 313, 139, nil, nil, 313, nil, nil, nil, nil,
+ 162, nil, nil, nil, 162, 162, 313, nil, 162, nil,
+ nil, nil, nil, 162, 252, 88, nil, 162, 252, 252,
+ nil, nil, 252, nil, 88, 88, nil, 252, 162, nil,
+ nil, 252, nil, 88, 88, 88, 88, 105, 105, nil,
+ nil, nil, 252, nil, nil, nil, 105, 105, 105, 105,
+ nil, nil, 225, 225, 225, 225, nil, 88, 88, 225,
+ 225, 88, 88, 88, 88, 88, 88, nil, 88, 88,
+ 105, 105, nil, nil, 105, 105, 105, 105, 105, 105,
+ nil, 105, 105, 231, 231, nil, nil, nil, nil, nil,
+ nil, nil, 231, 231, 231, 231, 140, 140, nil, nil,
+ nil, nil, nil, nil, 140, 140, 140, 140, 140, 224,
+ 224, 224, 224, 224, 224, nil, 224, 224, nil, nil,
+ 231, 231, 231, 231, 231, 231, nil, 231, 231, 140,
+ 140, nil, nil, 140, 140, 140, 140, 140, 140, nil,
+ 140, 140, 227, 227, nil, nil, nil, nil, nil, nil,
+ nil, 227, 227, 227, 227, 104, 104, nil, nil, nil,
+ nil, nil, nil, nil, 104, 104, 104, 104, nil, 232,
+ nil, nil, nil, nil, nil, nil, 227, 232, nil, 227,
+ 227, 227, 227, 227, 227, nil, 227, 227, 104, 104,
+ 229, nil, 104, 104, 104, 104, 104, 104, 229, 104,
+ 104, nil, nil, 226, nil, 232, 232, 232, 232, 232,
+ 232, 226, 232, 232, 233, 233, 233, 233, 233, 233,
+ nil, 233, 233, nil, nil, nil, 229, 229, 229, 229,
+ 229, 229, 273, 229, 229, nil, nil, nil, nil, 226,
+ 226, 226, 226, 226, 226, nil, 226, 226, nil, nil,
+ nil, 256, nil, 273, nil, 273, 273, nil, 273, 273,
+ nil, 273, nil, 273, nil, 273, nil, 273, nil, nil,
+ 273, 273, 256, 265, 256, 256, nil, 256, 256, nil,
+ 256, nil, 256, nil, 256, nil, 256, nil, nil, 256,
+ 256, nil, 236, nil, 265, nil, 265, 265, nil, 265,
+ 265, nil, 265, nil, 265, nil, 265, nil, 265, nil,
+ nil, 265, 265, 236, 304, 236, 236, nil, 236, 236,
+ nil, 236, nil, 236, nil, 236, nil, 236, nil, nil,
+ 236, 236, nil, 309, nil, 304, nil, 304, 304, nil,
304, 304, nil, 304, nil, 304, nil, 304, nil, 304,
- nil, nil, 304, 304, 184, 157, 184, 184, nil, 184,
- 184, nil, 184, nil, 184, nil, 184, nil, 184, nil,
- nil, 184, 184, nil, 312, nil, 157, nil, 157, 157,
- nil, 157, 157, nil, 157, nil, 157, nil, 157, nil,
- 157, nil, nil, 157, 157, 312, 314, 312, 312, nil,
- 312, 312, nil, 312, nil, 312, nil, 312, nil, 312,
- nil, nil, 312, 312, nil, 324, nil, 314, nil, 314,
- 314, nil, 314, 314, nil, 314, nil, 314, nil, 314,
- nil, 314, nil, nil, 314, 314, 324, 192, 324, 324,
- nil, 324, 324, nil, 324, nil, 324, nil, 324, nil,
- 324, nil, nil, 324, 324, nil, 326, nil, 192, nil,
- 192, 192, nil, 192, 192, nil, 192, nil, 192, nil,
- 192, nil, 192, nil, nil, 192, 192, 326, nil, 326,
- 326, nil, 326, 326, nil, 326, nil, 326, nil, 326,
- nil, 326, nil, nil, 326, 326, 0, nil, 0, 0,
- nil, 0, 0, nil, 0, nil, 0, nil, 0, nil,
- 0, nil, nil, 0, 0, 30, nil, 30, 30, nil,
- 30, 30, nil, 30, nil, 30, nil, 30, nil, 30,
- nil, nil, 30, 30, 230, 230, 230, 230, 230, 230,
- nil, 230, 230, 221, 221, 221, 221, 221, 221, nil,
- 221, 221 ]
+ nil, nil, 304, 304, 309, 195, 309, 309, nil, 309,
+ 309, nil, 309, nil, 309, nil, 309, nil, 309, nil,
+ nil, 309, 309, nil, 316, nil, 195, nil, 195, 195,
+ nil, 195, 195, nil, 195, nil, 195, nil, 195, nil,
+ 195, nil, nil, 195, 195, 316, 318, 316, 316, nil,
+ 316, 316, nil, 316, nil, 316, nil, 316, nil, 316,
+ nil, nil, 316, 316, nil, 326, nil, 318, nil, 318,
+ 318, nil, 318, 318, nil, 318, nil, 318, nil, 318,
+ nil, 318, nil, nil, 318, 318, 326, 158, 326, 326,
+ nil, 326, 326, nil, 326, nil, 326, nil, 326, nil,
+ 326, nil, nil, 326, 326, nil, 328, nil, 158, nil,
+ 158, 158, nil, 158, 158, nil, 158, nil, 158, nil,
+ 158, nil, 158, nil, nil, 158, 158, 328, nil, 328,
+ 328, nil, 328, 328, nil, 328, nil, 328, nil, 328,
+ nil, 328, nil, nil, 328, 328, 30, nil, 30, 30,
+ nil, 30, 30, nil, 30, nil, 30, nil, 30, nil,
+ 30, nil, nil, 30, 30, 0, nil, 0, 0, nil,
+ 0, 0, nil, 0, nil, 0, nil, 0, nil, 0,
+ nil, nil, 0, 0, 223, 223, 223, 223, nil, nil,
+ nil, 223, 223 ]
racc_action_pointer = [
- 1418, 229, nil, nil, nil, 98, nil, nil, nil, 337,
- nil, nil, 70, nil, nil, 331, 123, nil, 155, nil,
- 176, 24, nil, 243, nil, 335, 108, 278, 76, nil,
- 1437, nil, nil, 375, 407, 273, nil, 460, nil, nil,
- nil, nil, nil, -1, nil, nil, nil, 255, nil, 271,
- nil, 815, nil, 263, 616, 277, nil, 265, nil, nil,
- nil, 3, nil, nil, 249, nil, 266, 246, nil, nil,
- 234, 200, 194, 542, nil, nil, 191, 521, 301, nil,
- 162, 151, 58, 55, 25, nil, 295, 993, 262, 218,
- 19, 196, 80, -14, 242, nil, 264, 276, 260, nil,
- nil, 281, nil, 1052, 1065, 129, 284, nil, nil, nil,
- 270, nil, 260, 55, 291, 291, nil, 292, 314, 312,
- nil, nil, nil, 79, 340, nil, 162, nil, nil, nil,
- -2, 334, 932, nil, 140, nil, 166, 914, 882, 1111,
- 220, nil, nil, nil, 216, 354, 428, 481, 622, 648,
- 688, 709, 219, 741, 762, -2, 183, 1298, 595, 101,
- 794, 946, 230, 336, 304, 111, 50, nil, nil, 16,
- nil, nil, nil, nil, 162, 298, 12, nil, 52, 225,
- nil, nil, nil, nil, 1276, 61, 51, 91, 84, 78,
- 117, nil, 1380, nil, 195, 178, 153, 195, nil, nil,
- nil, 185, nil, 597, nil, nil, nil, 846, nil, 535,
- nil, nil, nil, nil, nil, 86, nil, nil, 222, 205,
- 984, 1441, -42, 496, 1124, 1137, 553, nil, 1006, 663,
- 1432, nil, 249, 1175, 127, 135, 201, nil, 964, nil,
- -4, nil, 281, 58, 97, nil, nil, nil, 0, 821,
- nil, 285, nil, 283, 274, 77, nil, 287, 1194, nil,
- 1216, nil, nil, nil, nil, nil, 301, nil, 1235, nil,
- nil, nil, 322, nil, 249, nil, nil, nil, nil, nil,
- 36, 288, nil, nil, 312, 860, nil, nil, nil, nil,
- 300, nil, 301, 306, 307, 308, nil, 324, 269, nil,
- nil, 77, 248, nil, 1257, nil, nil, nil, nil, 896,
- 333, 334, 1317, nil, 1339, nil, nil, nil, nil, nil,
- nil, nil, nil, nil, 1358, nil, 1399, nil, nil ]
+ 1547, 117, nil, nil, nil, 48, nil, nil, nil, 306,
+ nil, nil, 26, nil, nil, 301, 157, nil, 178, nil,
+ 210, 77, nil, 173, nil, 303, 98, 241, 57, nil,
+ 1528, nil, nil, 422, 443, nil, 256, nil, 496, nil,
+ nil, nil, nil, nil, -7, nil, nil, nil, -23, nil,
+ 249, nil, 960, nil, 242, 642, 255, nil, 242, nil,
+ nil, nil, 12, nil, nil, 221, nil, 239, 217, nil,
+ nil, 209, 208, 180, 796, nil, nil, 178, 775, 735,
+ nil, 176, 149, 146, 100, 568, nil, 96, 1069, 205,
+ 221, 231, 208, -14, 78, 247, nil, 244, 255, 239,
+ nil, nil, 256, nil, 1200, 1082, -22, 240, nil, nil,
+ nil, 255, nil, 240, 59, 272, 263, nil, 272, 287,
+ 293, nil, nil, nil, 2, 317, nil, 9, nil, nil,
+ nil, -5, 305, 849, nil, 39, nil, 227, 889, 991,
+ 1141, 235, nil, nil, nil, 284, 369, 390, 536, 828,
+ 714, 621, 72, 197, 51, 19, -2, 188, 1490, 104,
+ 125, 263, 1027, 139, 214, 210, 101, -11, nil, nil,
+ -6, nil, nil, nil, nil, 173, 168, 149, nil, 72,
+ 29, 251, 67, nil, 48, 151, 79, nil, 92, 316,
+ 589, 131, 108, 126, nil, 1408, nil, 661, 177, 149,
+ 182, nil, nil, nil, 171, nil, 899, nil, nil, nil,
+ 868, nil, 682, nil, nil, nil, nil, nil, 48, nil,
+ nil, 203, 55, 1542, 1117, 1060, 1247, 1187, 750, 1234,
+ nil, 1128, 1213, 1222, nil, 221, 1345, 114, 150, -33,
+ nil, 921, nil, 7, nil, 252, -16, 102, nil, nil,
+ nil, 939, 1041, nil, 263, nil, 1304, 515, nil, nil,
+ 150, 475, nil, nil, nil, 1326, nil, nil, nil, nil,
+ nil, 270, nil, 1285, nil, nil, nil, 337, nil, 146,
+ nil, nil, nil, nil, nil, 283, 261, nil, nil, 285,
+ 966, nil, nil, nil, nil, 273, nil, 274, 276, 277,
+ 278, nil, 295, nil, 1367, nil, nil, nil, nil, 1386,
+ nil, nil, nil, 1005, 301, 304, 1427, nil, 1449, nil,
+ nil, nil, nil, nil, nil, nil, 1468, nil, 1509, nil,
+ nil ]
racc_action_default = [
- -174, -200, -15, -3, -165, -200, -16, -5, -163, -200,
- -17, -6, -200, -7, -8, -200, -164, -9, -200, -10,
- -200, -200, -11, -200, -12, -200, -200, -39, -200, -13,
- -1, -14, -2, -200, -200, -174, -164, -72, -171, -170,
- -169, -199, -173, -174, -172, -166, -168, -79, -191, -200,
- -31, -200, -33, -32, -200, -63, -102, -21, -104, -103,
- -22, -62, -23, -61, -26, -153, -200, -27, -152, -151,
- -28, -29, -30, -200, -94, -112, -90, -200, -200, -97,
- -91, -95, -99, -92, -200, -96, -93, -200, -98, -200,
- -200, -72, -174, -174, -42, -154, -156, -200, -174, -40,
- -38, -200, -4, -70, -71, -200, -200, -187, -73, -67,
- -64, -63, -59, -62, -197, -65, -57, -68, -200, -66,
- -150, -69, -149, -200, -200, -185, -200, -77, -78, -80,
- -200, -197, -200, -20, -200, -82, -200, -200, -200, -200,
- -200, -194, -128, -121, -200, -200, -200, -200, -200, -200,
- -200, -200, -200, -200, -200, -200, -200, -200, -200, -200,
- -200, -200, -200, -200, -197, -174, -200, -46, -48, -200,
- -62, -55, -54, -45, -200, -79, -200, 329, -175, -200,
- -176, -189, -188, -190, -200, -200, -60, -200, -200, -198,
- -72, -186, -200, -167, -200, -200, -198, -200, -147, -139,
- -140, -62, -145, -200, -148, -146, -18, -200, -105, -200,
- -195, -196, -24, -25, -101, -200, -131, -192, -196, -117,
- -119, -123, -120, -125, -130, -127, -124, -113, -129, -126,
- -122, -114, -109, -200, -115, -116, -118, -137, -200, -133,
- -200, -106, -200, -200, -200, -51, -50, -44, -200, -200,
- -43, -197, -155, -184, -200, -200, -179, -182, -200, -160,
- -200, -34, -58, -75, -35, -74, -197, -162, -200, -76,
- -37, -81, -200, -142, -197, -19, -83, -100, -193, -108,
- -200, -109, -132, -134, -200, -200, -36, -49, -47, -88,
- -84, -52, -85, -89, -86, -87, -53, -200, -200, -177,
- -178, -200, -200, -158, -200, -159, -56, -161, -144, -200,
- -200, -196, -200, -107, -200, -138, -41, -183, -180, -181,
- -157, -143, -141, -111, -200, -136, -200, -110, -135 ]
+ -175, -201, -15, -3, -165, -166, -16, -5, -163, -201,
+ -17, -6, -201, -7, -8, -201, -164, -9, -201, -10,
+ -201, -201, -11, -201, -12, -201, -201, -39, -201, -13,
+ -1, -14, -2, -201, -201, -166, -175, -164, -72, -172,
+ -171, -170, -200, -174, -175, -173, -167, -169, -79, -192,
+ -201, -31, -201, -33, -32, -201, -63, -102, -21, -104,
+ -103, -22, -62, -23, -61, -26, -153, -201, -27, -152,
+ -151, -28, -29, -30, -201, -94, -112, -90, -201, -201,
+ -97, -91, -95, -99, -92, -201, -96, -93, -201, -98,
+ -201, -201, -72, -175, -175, -42, -154, -156, -201, -175,
+ -40, -38, -201, -4, -70, -71, -176, -175, -177, -73,
+ -67, -64, -63, -59, -62, -198, -65, -57, -68, -201,
+ -66, -150, -69, -149, -201, -201, -186, -201, -77, -78,
+ -80, -201, -198, -201, -20, -201, -82, -201, -201, -201,
+ -201, -201, -195, -128, -121, -201, -201, -201, -201, -201,
+ -201, -201, -201, -201, -201, -201, -201, -201, -201, -201,
+ -201, -201, -201, -201, -201, -198, -175, -201, -46, -48,
+ -201, -62, -55, -54, -45, -201, -79, -201, 331, -201,
+ -185, -201, -201, -180, -183, -201, -201, -188, -201, -60,
+ -201, -201, -199, -72, -187, -201, -168, -201, -201, -199,
+ -201, -147, -139, -140, -62, -145, -201, -148, -146, -18,
+ -201, -105, -201, -196, -197, -24, -25, -101, -201, -131,
+ -193, -197, -117, -119, -123, -120, -125, -130, -127, -124,
+ -113, -129, -126, -122, -114, -109, -201, -115, -116, -118,
+ -137, -201, -133, -201, -106, -201, -201, -201, -51, -50,
+ -44, -201, -201, -43, -198, -155, -201, -201, -178, -179,
+ -201, -201, -190, -189, -191, -201, -34, -58, -75, -35,
+ -74, -198, -162, -201, -76, -37, -81, -201, -142, -198,
+ -19, -83, -100, -194, -108, -201, -109, -132, -134, -201,
+ -201, -36, -49, -47, -88, -84, -52, -85, -89, -86,
+ -87, -53, -201, -158, -201, -184, -181, -182, -160, -201,
+ -56, -161, -144, -201, -201, -197, -201, -107, -201, -138,
+ -41, -157, -159, -143, -141, -111, -201, -136, -201, -110,
+ -135 ]
racc_goto_table = [
- 15, 21, 102, 197, 30, 116, 200, 114, 42, 256,
- 188, 131, 50, 57, 121, 45, 62, 35, 239, 212,
- 32, 166, 174, 279, 69, 25, 136, 195, 271, 101,
- 15, 21, 237, 109, 291, 296, 309, 127, 98, 238,
- 288, 94, 199, 185, 274, 69, 96, 50, 134, 140,
- 67, 62, 72, 179, 106, 107, 43, 124, 112, 69,
- 242, 164, 162, 125, 191, 254, 255, 100, 182, nil,
- nil, 117, 313, 122, 197, nil, nil, 273, nil, nil,
- nil, nil, nil, nil, nil, 67, nil, 72, nil, 212,
- nil, nil, nil, nil, 243, 283, nil, nil, nil, nil,
- nil, nil, nil, nil, nil, nil, nil, nil, nil, 237,
- nil, nil, nil, nil, nil, nil, nil, 181, 180, 42,
- nil, 89, 42, nil, nil, nil, 172, 172, nil, 193,
- nil, nil, 318, 50, 50, 215, nil, 213, 62, 251,
- 69, nil, nil, nil, nil, 69, 69, 297, 227, nil,
- nil, nil, 231, nil, 262, 135, 315, 15, 21, nil,
- 266, 233, 306, 121, nil, 127, 204, nil, 122, 69,
- 310, 67, 67, 72, 72, nil, nil, nil, 135, 265,
- 197, nil, 109, 321, 15, 21, 127, nil, 260, nil,
- nil, 135, 15, 21, 69, 204, 268, 122, nil, 172,
- nil, nil, nil, 50, nil, 102, nil, 213, nil, nil,
- nil, 69, nil, nil, 53, 69, nil, 71, nil, nil,
- 117, 95, 122, nil, nil, nil, nil, nil, nil, nil,
- 64, nil, 102, 15, 21, 110, nil, 204, 120, 122,
- 102, 67, nil, 72, 289, 289, 69, nil, nil, 53,
- nil, 115, 71, nil, nil, nil, 69, 69, 15, 21,
- 15, 21, 304, nil, nil, 64, nil, nil, 15, 21,
- nil, nil, 204, 70, 122, nil, 102, nil, 172, nil,
- nil, nil, 293, 293, 122, 122, nil, nil, 263, nil,
- nil, nil, nil, 69, 119, 269, 102, nil, 102, nil,
- nil, nil, nil, nil, 15, 21, 171, 171, 70, nil,
- 276, nil, 15, 21, 15, 21, 324, 69, 326, 204,
- nil, 122, nil, nil, 15, 21, 15, 21, nil, nil,
- 198, nil, nil, 120, nil, 53, 53, nil, 71, 71,
- nil, nil, nil, 204, nil, 122, 202, nil, nil, nil,
- nil, 64, 64, nil, nil, nil, nil, nil, nil, 198,
- nil, nil, 120, nil, nil, nil, nil, nil, nil, nil,
- nil, nil, nil, 308, 252, 202, nil, nil, nil, 171,
- nil, nil, nil, nil, 110, nil, nil, 120, nil, 205,
- nil, nil, nil, nil, 70, 70, nil, nil, nil, 317,
- 115, 198, nil, 319, 120, 53, nil, nil, 71, nil,
- nil, nil, nil, nil, nil, nil, nil, 202, 205, 87,
- nil, 64, nil, nil, nil, nil, nil, nil, nil, nil,
- nil, nil, nil, nil, 103, 104, 198, nil, nil, 120,
- nil, nil, nil, 119, nil, nil, 290, 290, nil, 295,
- 295, nil, 202, nil, nil, nil, nil, nil, 171, nil,
- 205, nil, 292, 292, 70, nil, nil, nil, nil, nil,
- nil, nil, nil, nil, 139, nil, nil, nil, nil, 142,
- nil, nil, nil, 198, nil, 143, 120, nil, nil, nil,
- nil, nil, nil, nil, nil, 205, nil, nil, nil, 202,
- nil, nil, nil, nil, nil, 294, 294, 198, nil, nil,
- 120, nil, nil, nil, nil, nil, nil, nil, nil, nil,
- nil, nil, nil, 202, nil, nil, nil, nil, nil, nil,
+ 15, 21, 103, 203, 30, 36, 183, 200, 115, 132,
+ 43, 46, 58, 242, 122, 117, 63, 32, 167, 175,
+ 107, 25, 191, 284, 128, 215, 99, 70, 276, 102,
+ 15, 21, 137, 296, 301, 241, 240, 313, 293, 198,
+ 202, 95, 279, 97, 188, 186, 44, 125, 135, 70,
+ 113, 194, 63, 108, 181, 141, 182, 54, 101, 73,
+ 263, 126, 165, 70, 96, nil, nil, nil, 163, nil,
+ nil, nil, 245, nil, 317, nil, 278, nil, nil, 111,
+ 200, 123, nil, 179, nil, nil, nil, nil, nil, nil,
+ nil, 246, 288, 54, nil, 73, nil, 215, nil, nil,
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
- nil, nil, 205, nil, nil, 219, 220, 221, 222, 223,
- 224, 225, 226, nil, 228, 229, 230, nil, nil, 234,
- 235, 236, nil, nil, nil, nil, 205 ]
+ nil, nil, 72, nil, nil, 240, 108, nil, nil, nil,
+ nil, nil, 43, nil, 187, 43, 196, nil, nil, nil,
+ nil, nil, nil, nil, 121, 218, nil, 254, 216, 63,
+ nil, nil, nil, nil, 70, nil, nil, nil, 72, 70,
+ 70, 230, 128, 90, nil, 234, nil, nil, 15, 21,
+ 306, 302, 236, 271, 319, 122, 267, nil, 270, nil,
+ nil, nil, nil, 70, 201, 128, 123, nil, 310, 54,
+ 54, 73, 73, 323, nil, 262, 314, 200, 136, nil,
+ 65, nil, nil, nil, nil, 15, 21, nil, nil, 273,
+ 70, nil, nil, 201, nil, 123, nil, nil, 103, nil,
+ 216, 136, 116, nil, nil, nil, nil, 70, 255, nil,
+ nil, 70, nil, nil, 136, nil, 65, nil, nil, 121,
+ 111, nil, 123, nil, 72, 72, 15, 21, nil, nil,
+ nil, nil, nil, nil, nil, 103, nil, 201, nil, 123,
+ nil, 54, 70, 73, nil, 71, 15, 21, 121, nil,
+ 304, nil, 70, 70, nil, 15, 21, 172, 172, 309,
+ nil, nil, nil, 15, 21, nil, 103, 120, nil, nil,
+ nil, 103, 201, nil, 123, 121, nil, nil, nil, 68,
+ nil, 71, 295, 295, 123, 123, nil, nil, 103, nil,
+ 103, 70, 121, nil, 15, 21, 72, 205, nil, 15,
+ 21, 118, 65, 65, nil, nil, 15, 21, 15, 21,
+ 326, 51, 328, 268, 70, 68, 15, 21, 15, 21,
+ 274, 201, nil, 123, nil, nil, 205, 121, nil, nil,
+ 172, nil, nil, 110, nil, 281, nil, 300, 300, nil,
+ nil, nil, nil, nil, 201, nil, 123, 51, nil, nil,
+ nil, nil, nil, 116, nil, nil, 173, 173, nil, nil,
+ nil, nil, 208, nil, nil, nil, nil, 71, 71, nil,
+ 205, nil, nil, nil, 65, nil, 121, nil, nil, nil,
+ 305, nil, nil, nil, 307, nil, nil, nil, nil, nil,
+ nil, 208, nil, nil, 88, nil, 207, nil, nil, 121,
+ 312, 68, 68, nil, nil, 205, nil, nil, nil, 104,
+ 105, 172, nil, nil, nil, 297, 297, nil, 120, nil,
+ nil, nil, nil, nil, nil, 207, nil, nil, nil, 173,
+ nil, nil, nil, 51, 51, 208, nil, nil, nil, 71,
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
+ 140, nil, 118, nil, 205, 143, nil, nil, nil, nil,
+ nil, 144, nil, nil, nil, nil, nil, nil, nil, 207,
+ 208, nil, nil, 68, nil, nil, nil, 205, nil, nil,
+ 299, 299, nil, nil, 110, nil, nil, nil, nil, nil,
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
+ nil, nil, nil, nil, 207, 51, nil, nil, nil, nil,
+ 173, nil, nil, nil, 298, 298, nil, nil, nil, 208,
+ nil, 222, 223, 224, 225, 226, 227, 228, 229, nil,
+ 231, 232, 233, nil, nil, 237, 238, 239, nil, nil,
+ nil, nil, 208, nil, nil, nil, 294, 294, nil, nil,
+ nil, nil, nil, 207, nil, nil, nil, nil, nil, nil,
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
+ nil, nil, nil, nil, nil, nil, 207 ]
racc_goto_check = [
- 20, 33, 4, 59, 2, 43, 61, 31, 55, 72,
- 32, 34, 26, 18, 46, 68, 20, 28, 57, 19,
- 3, 37, 37, 54, 45, 1, 52, 32, 51, 33,
- 20, 33, 59, 26, 42, 42, 53, 48, 28, 56,
- 38, 36, 60, 30, 62, 45, 63, 26, 18, 52,
- 22, 20, 25, 64, 65, 3, 66, 67, 29, 45,
- 32, 31, 52, 3, 69, 70, 71, 5, 73, nil,
- nil, 22, 54, 25, 59, nil, nil, 61, nil, nil,
- nil, nil, nil, nil, nil, 22, nil, 25, nil, 19,
- nil, nil, nil, nil, 37, 57, nil, nil, nil, nil,
- nil, nil, nil, nil, nil, nil, nil, nil, nil, 59,
- nil, nil, nil, nil, nil, nil, nil, 28, 3, 55,
- nil, 49, 55, nil, nil, nil, 22, 22, nil, 68,
- nil, nil, 72, 26, 26, 18, nil, 20, 20, 34,
- 45, nil, nil, nil, nil, 45, 45, 32, 55, nil,
- nil, nil, 55, nil, 43, 49, 59, 20, 33, nil,
- 31, 2, 32, 46, nil, 48, 22, nil, 25, 45,
- 32, 22, 22, 25, 25, nil, nil, nil, 49, 48,
- 59, nil, 26, 61, 20, 33, 48, nil, 2, nil,
- nil, 49, 20, 33, 45, 22, 2, 25, nil, 22,
- nil, nil, nil, 26, nil, 4, nil, 20, nil, nil,
- nil, 45, nil, nil, 27, 45, nil, 24, nil, nil,
- 22, 27, 25, nil, nil, nil, nil, nil, nil, nil,
- 21, nil, 4, 20, 33, 27, nil, 22, 24, 25,
- 4, 22, nil, 25, 26, 26, 45, nil, nil, 27,
- nil, 21, 24, nil, nil, nil, 45, 45, 20, 33,
- 20, 33, 2, nil, nil, 21, nil, nil, 20, 33,
- nil, nil, 22, 23, 25, nil, 4, nil, 22, nil,
- nil, nil, 22, 22, 25, 25, nil, nil, 49, nil,
- nil, nil, nil, 45, 23, 49, 4, nil, 4, nil,
- nil, nil, nil, nil, 20, 33, 21, 21, 23, nil,
- 49, nil, 20, 33, 20, 33, 2, 45, 2, 22,
- nil, 25, nil, nil, 20, 33, 20, 33, nil, nil,
- 27, nil, nil, 24, nil, 27, 27, nil, 24, 24,
- nil, nil, nil, 22, nil, 25, 21, nil, nil, nil,
- nil, 21, 21, nil, nil, nil, nil, nil, nil, 27,
- nil, nil, 24, nil, nil, nil, nil, nil, nil, nil,
- nil, nil, nil, 49, 27, 21, nil, nil, nil, 21,
- nil, nil, nil, nil, 27, nil, nil, 24, nil, 23,
- nil, nil, nil, nil, 23, 23, nil, nil, nil, 49,
- 21, 27, nil, 49, 24, 27, nil, nil, 24, nil,
- nil, nil, nil, nil, nil, nil, nil, 21, 23, 47,
- nil, 21, nil, nil, nil, nil, nil, nil, nil, nil,
- nil, nil, nil, nil, 47, 47, 27, nil, nil, 24,
- nil, nil, nil, 23, nil, nil, 27, 27, nil, 24,
- 24, nil, 21, nil, nil, nil, nil, nil, 21, nil,
- 23, nil, 21, 21, 23, nil, nil, nil, nil, nil,
- nil, nil, nil, nil, 47, nil, nil, nil, nil, 47,
- nil, nil, nil, 27, nil, 47, 24, nil, nil, nil,
- nil, nil, nil, nil, nil, 23, nil, nil, nil, 21,
- nil, nil, nil, nil, nil, 23, 23, 27, nil, nil,
- 24, nil, nil, nil, nil, nil, nil, nil, nil, nil,
- nil, nil, nil, 21, nil, nil, nil, nil, nil, nil,
+ 20, 33, 4, 61, 2, 28, 72, 59, 31, 34,
+ 55, 68, 18, 57, 46, 43, 20, 3, 37, 37,
+ 64, 1, 32, 54, 48, 19, 28, 45, 51, 33,
+ 20, 33, 52, 42, 42, 56, 59, 53, 38, 32,
+ 60, 36, 62, 63, 30, 65, 66, 67, 18, 45,
+ 29, 69, 20, 3, 70, 52, 71, 27, 5, 25,
+ 73, 3, 31, 45, 27, nil, nil, nil, 52, nil,
+ nil, nil, 32, nil, 54, nil, 61, nil, nil, 27,
+ 59, 25, nil, 64, nil, nil, nil, nil, nil, nil,
+ nil, 37, 57, 27, nil, 25, nil, 19, nil, nil,
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
+ nil, nil, 24, nil, nil, 59, 3, nil, nil, nil,
+ nil, nil, 55, nil, 3, 55, 68, nil, nil, nil,
+ nil, nil, nil, nil, 24, 18, nil, 34, 20, 20,
+ nil, nil, nil, nil, 45, nil, nil, nil, 24, 45,
+ 45, 55, 48, 49, nil, 55, nil, nil, 20, 33,
+ 72, 32, 2, 31, 59, 46, 43, nil, 48, nil,
+ nil, nil, nil, 45, 27, 48, 25, nil, 32, 27,
+ 27, 25, 25, 61, nil, 28, 32, 59, 49, nil,
+ 21, nil, nil, nil, nil, 20, 33, nil, nil, 2,
+ 45, nil, nil, 27, nil, 25, nil, nil, 4, nil,
+ 20, 49, 21, nil, nil, nil, nil, 45, 27, nil,
+ nil, 45, nil, nil, 49, nil, 21, nil, nil, 24,
+ 27, nil, 25, nil, 24, 24, 20, 33, nil, nil,
+ nil, nil, nil, nil, nil, 4, nil, 27, nil, 25,
+ nil, 27, 45, 25, nil, 23, 20, 33, 24, nil,
+ 2, nil, 45, 45, nil, 20, 33, 21, 21, 2,
+ nil, nil, nil, 20, 33, nil, 4, 23, nil, nil,
+ nil, 4, 27, nil, 25, 24, nil, nil, nil, 22,
+ nil, 23, 27, 27, 25, 25, nil, nil, 4, nil,
+ 4, 45, 24, nil, 20, 33, 24, 21, nil, 20,
+ 33, 22, 21, 21, nil, nil, 20, 33, 20, 33,
+ 2, 26, 2, 49, 45, 22, 20, 33, 20, 33,
+ 49, 27, nil, 25, nil, nil, 21, 24, nil, nil,
+ 21, nil, nil, 26, nil, 49, nil, 24, 24, nil,
+ nil, nil, nil, nil, 27, nil, 25, 26, nil, nil,
+ nil, nil, nil, 21, nil, nil, 22, 22, nil, nil,
+ nil, nil, 23, nil, nil, nil, nil, 23, 23, nil,
+ 21, nil, nil, nil, 21, nil, 24, nil, nil, nil,
+ 49, nil, nil, nil, 49, nil, nil, nil, nil, nil,
+ nil, 23, nil, nil, 47, nil, 22, nil, nil, 24,
+ 49, 22, 22, nil, nil, 21, nil, nil, nil, 47,
+ 47, 21, nil, nil, nil, 21, 21, nil, 23, nil,
+ nil, nil, nil, nil, nil, 22, nil, nil, nil, 22,
+ nil, nil, nil, 26, 26, 23, nil, nil, nil, 23,
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
+ 47, nil, 22, nil, 21, 47, nil, nil, nil, nil,
+ nil, 47, nil, nil, nil, nil, nil, nil, nil, 22,
+ 23, nil, nil, 22, nil, nil, nil, 21, nil, nil,
+ 23, 23, nil, nil, 26, nil, nil, nil, nil, nil,
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
+ nil, nil, nil, nil, 22, 26, nil, nil, nil, nil,
+ 22, nil, nil, nil, 22, 22, nil, nil, nil, 23,
+ nil, 47, 47, 47, 47, 47, 47, 47, 47, nil,
+ 47, 47, 47, nil, nil, 47, 47, 47, nil, nil,
+ nil, nil, 23, nil, nil, nil, 26, 26, nil, nil,
+ nil, nil, nil, 22, nil, nil, nil, nil, nil, nil,
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
- nil, nil, 23, nil, nil, 47, 47, 47, 47, 47,
- 47, 47, 47, nil, 47, 47, 47, nil, nil, 47,
- 47, 47, nil, nil, nil, nil, 23 ]
+ nil, nil, nil, nil, nil, nil, 22 ]
racc_goto_pointer = [
- nil, 25, 4, 20, -28, 39, nil, nil, nil, nil,
- nil, nil, nil, nil, nil, nil, nil, nil, -3, -118,
- 0, 214, 34, 257, 201, 36, -4, 198, 12, 21,
- -69, -30, -104, 1, -36, nil, 20, -71, -204, nil,
- nil, nil, -214, -32, nil, 8, -23, 401, -10, 101,
- nil, -168, -28, -238, -209, -4, -122, -143, nil, -129,
- -90, -126, -159, 23, -45, 19, 44, 14, 3, -59,
- -113, -112, -169, -37 ]
+ nil, 21, 4, 17, -28, 30, nil, nil, nil, nil,
+ nil, nil, nil, nil, nil, nil, nil, nil, -4, -113,
+ 0, 174, 273, 239, 96, 43, 305, 41, 0, 12,
+ -69, -30, -93, 1, -39, nil, 20, -75, -209, nil,
+ nil, nil, -218, -23, nil, 11, -24, 386, -24, 133,
+ nil, -171, -23, -242, -212, -2, -127, -149, nil, -126,
+ -93, -130, -164, 20, -16, -62, 34, 3, -1, -73,
+ -52, -50, -100, -125 ]
racc_goto_default = [
- nil, nil, nil, 173, 3, 7, 11, 13, 14, 17,
- 19, 22, 24, 29, 31, 2, 6, 10, nil, 60,
- 79, 80, 81, 83, 86, 88, 74, 76, 9, nil,
- nil, nil, nil, 66, nil, 28, nil, nil, 167, 244,
- 168, 169, nil, nil, 118, 82, 85, nil, 108, 75,
- 128, 129, nil, 209, nil, 65, nil, nil, 240, 49,
- nil, nil, nil, nil, nil, nil, nil, nil, nil, 46,
+ nil, nil, nil, 174, 3, 7, 11, 13, 14, 17,
+ 19, 22, 24, 29, 31, 2, 6, 10, nil, 61,
+ 80, 81, 82, 84, 87, 89, 75, 77, 9, nil,
+ nil, nil, nil, 67, nil, 28, nil, nil, 168, 247,
+ 169, 170, nil, nil, 119, 83, 86, nil, 109, 76,
+ 129, 130, nil, 212, nil, 66, nil, nil, 243, 50,
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, 47,
nil, nil, nil, nil ]
racc_reduce_table = [
@@ -712,51 +738,52 @@ racc_reduce_table = [
2, 73, :_reduce_156,
6, 75, :_reduce_157,
5, 75, :_reduce_158,
- 6, 76, :_reduce_159,
- 5, 76, :_reduce_160,
+ 7, 76, :_reduce_159,
+ 6, 76, :_reduce_160,
6, 77, :_reduce_161,
5, 77, :_reduce_162,
1, 95, :_reduce_163,
1, 90, :_reduce_164,
1, 90, :_reduce_165,
+ 1, 90, :_reduce_166,
1, 128, :_reduce_none,
- 3, 128, :_reduce_167,
- 1, 130, :_reduce_168,
- 1, 131, :_reduce_169,
+ 3, 128, :_reduce_168,
+ 1, 130, :_reduce_169,
1, 131, :_reduce_170,
1, 131, :_reduce_171,
1, 131, :_reduce_172,
+ 1, 131, :_reduce_173,
1, 131, :_reduce_none,
- 0, 65, :_reduce_174,
- 0, 132, :_reduce_175,
+ 0, 65, :_reduce_175,
+ 0, 132, :_reduce_176,
1, 126, :_reduce_none,
- 3, 126, :_reduce_177,
3, 126, :_reduce_178,
+ 3, 126, :_reduce_179,
1, 133, :_reduce_none,
- 3, 133, :_reduce_180,
- 3, 134, :_reduce_181,
- 1, 134, :_reduce_182,
- 3, 134, :_reduce_183,
- 1, 134, :_reduce_184,
+ 3, 133, :_reduce_181,
+ 3, 134, :_reduce_182,
+ 1, 134, :_reduce_183,
+ 3, 134, :_reduce_184,
+ 1, 134, :_reduce_185,
1, 129, :_reduce_none,
- 2, 129, :_reduce_186,
+ 2, 129, :_reduce_187,
1, 127, :_reduce_none,
- 2, 127, :_reduce_188,
+ 2, 127, :_reduce_189,
1, 135, :_reduce_none,
1, 135, :_reduce_none,
- 1, 84, :_reduce_191,
- 3, 108, :_reduce_192,
- 4, 108, :_reduce_193,
- 2, 108, :_reduce_194,
+ 1, 84, :_reduce_192,
+ 3, 108, :_reduce_193,
+ 4, 108, :_reduce_194,
+ 2, 108, :_reduce_195,
1, 115, :_reduce_none,
1, 115, :_reduce_none,
0, 94, :_reduce_none,
- 1, 94, :_reduce_198,
- 1, 117, :_reduce_199 ]
+ 1, 94, :_reduce_199,
+ 1, 117, :_reduce_200 ]
-racc_reduce_n = 200
+racc_reduce_n = 201
-racc_shift_n = 329
+racc_shift_n = 331
racc_token_table = {
false => 0,
@@ -2056,7 +2083,7 @@ module_eval(<<'.,.,', 'grammar.ra', 656)
@lexer.commentpop
# Our class gets defined in the parent namespace, not our own.
@lexer.namepop
- newclass classname(val[1]), :code => val[4], :parent => val[2], :line => val[0][:line]
+ newclass classname(val[1]), :arguments => val[2], :code => val[5], :parent => val[3], :line => val[0][:line]
result = nil
result
@@ -2068,7 +2095,7 @@ module_eval(<<'.,.,', 'grammar.ra', 662)
@lexer.commentpop
# Our class gets defined in the parent namespace, not our own.
@lexer.namepop
- newclass classname(val[1]), :parent => val[2], :line => val[0][:line]
+ newclass classname(val[1]), :arguments => val[2], :parent => val[3], :line => val[0][:line]
result = nil
result
@@ -2116,29 +2143,29 @@ module_eval(<<'.,.,', 'grammar.ra', 682)
end
.,.,
-# reduce 166 omitted
-
-module_eval(<<'.,.,', 'grammar.ra', 688)
- def _reduce_167(val, _values, result)
- result = val[0]
- result = [result] unless result.is_a?(Array)
- result << val[2]
-
+module_eval(<<'.,.,', 'grammar.ra', 683)
+ def _reduce_166(val, _values, result)
+ result = "class"
result
end
.,.,
-module_eval(<<'.,.,', 'grammar.ra', 694)
+# reduce 167 omitted
+
+module_eval(<<'.,.,', 'grammar.ra', 689)
def _reduce_168(val, _values, result)
- result = ast AST::HostName, :value => val[0]
+ result = val[0]
+ result = [result] unless result.is_a?(Array)
+ result << val[2]
result
end
.,.,
-module_eval(<<'.,.,', 'grammar.ra', 697)
+module_eval(<<'.,.,', 'grammar.ra', 695)
def _reduce_169(val, _values, result)
- result = val[0][:value]
+ result = ast AST::HostName, :value => val[0]
+
result
end
.,.,
@@ -2164,36 +2191,43 @@ module_eval(<<'.,.,', 'grammar.ra', 700)
end
.,.,
-# reduce 173 omitted
+module_eval(<<'.,.,', 'grammar.ra', 701)
+ def _reduce_173(val, _values, result)
+ result = val[0][:value]
+ result
+ end
+.,.,
+
+# reduce 174 omitted
-module_eval(<<'.,.,', 'grammar.ra', 704)
- def _reduce_174(val, _values, result)
+module_eval(<<'.,.,', 'grammar.ra', 705)
+ def _reduce_175(val, _values, result)
result = nil
result
end
.,.,
-module_eval(<<'.,.,', 'grammar.ra', 708)
- def _reduce_175(val, _values, result)
+module_eval(<<'.,.,', 'grammar.ra', 709)
+ def _reduce_176(val, _values, result)
result = ast AST::ASTArray, :children => []
result
end
.,.,
-# reduce 176 omitted
+# reduce 177 omitted
-module_eval(<<'.,.,', 'grammar.ra', 713)
- def _reduce_177(val, _values, result)
+module_eval(<<'.,.,', 'grammar.ra', 714)
+ def _reduce_178(val, _values, result)
result = nil
result
end
.,.,
-module_eval(<<'.,.,', 'grammar.ra', 716)
- def _reduce_178(val, _values, result)
+module_eval(<<'.,.,', 'grammar.ra', 717)
+ def _reduce_179(val, _values, result)
result = val[1]
result = [result] unless result[0].is_a?(Array)
@@ -2201,10 +2235,10 @@ module_eval(<<'.,.,', 'grammar.ra', 716)
end
.,.,
-# reduce 179 omitted
+# reduce 180 omitted
-module_eval(<<'.,.,', 'grammar.ra', 722)
- def _reduce_180(val, _values, result)
+module_eval(<<'.,.,', 'grammar.ra', 723)
+ def _reduce_181(val, _values, result)
result = val[0]
result = [result] unless result[0].is_a?(Array)
result << val[2]
@@ -2213,8 +2247,8 @@ module_eval(<<'.,.,', 'grammar.ra', 722)
end
.,.,
-module_eval(<<'.,.,', 'grammar.ra', 728)
- def _reduce_181(val, _values, result)
+module_eval(<<'.,.,', 'grammar.ra', 729)
+ def _reduce_182(val, _values, result)
Puppet.warning addcontext("Deprecation notice: must now include '$' in prototype")
result = [val[0][:value], val[2]]
@@ -2222,8 +2256,8 @@ module_eval(<<'.,.,', 'grammar.ra', 728)
end
.,.,
-module_eval(<<'.,.,', 'grammar.ra', 732)
- def _reduce_182(val, _values, result)
+module_eval(<<'.,.,', 'grammar.ra', 733)
+ def _reduce_183(val, _values, result)
Puppet.warning addcontext("Deprecation notice: must now include '$' in prototype")
result = [val[0][:value]]
@@ -2231,56 +2265,56 @@ module_eval(<<'.,.,', 'grammar.ra', 732)
end
.,.,
-module_eval(<<'.,.,', 'grammar.ra', 735)
- def _reduce_183(val, _values, result)
+module_eval(<<'.,.,', 'grammar.ra', 736)
+ def _reduce_184(val, _values, result)
result = [val[0][:value], val[2]]
result
end
.,.,
-module_eval(<<'.,.,', 'grammar.ra', 737)
- def _reduce_184(val, _values, result)
+module_eval(<<'.,.,', 'grammar.ra', 738)
+ def _reduce_185(val, _values, result)
result = [val[0][:value]]
result
end
.,.,
-# reduce 185 omitted
+# reduce 186 omitted
-module_eval(<<'.,.,', 'grammar.ra', 742)
- def _reduce_186(val, _values, result)
+module_eval(<<'.,.,', 'grammar.ra', 743)
+ def _reduce_187(val, _values, result)
result = val[1]
result
end
.,.,
-# reduce 187 omitted
+# reduce 188 omitted
-module_eval(<<'.,.,', 'grammar.ra', 747)
- def _reduce_188(val, _values, result)
+module_eval(<<'.,.,', 'grammar.ra', 748)
+ def _reduce_189(val, _values, result)
result = val[1]
result
end
.,.,
-# reduce 189 omitted
-
# reduce 190 omitted
-module_eval(<<'.,.,', 'grammar.ra', 753)
- def _reduce_191(val, _values, result)
+# reduce 191 omitted
+
+module_eval(<<'.,.,', 'grammar.ra', 754)
+ def _reduce_192(val, _values, result)
result = ast AST::Variable, :value => val[0][:value], :line => val[0][:line]
result
end
.,.,
-module_eval(<<'.,.,', 'grammar.ra', 757)
- def _reduce_192(val, _values, result)
+module_eval(<<'.,.,', 'grammar.ra', 758)
+ def _reduce_193(val, _values, result)
if val[1].instance_of?(AST::ASTArray)
result = val[1]
else
@@ -2291,8 +2325,8 @@ module_eval(<<'.,.,', 'grammar.ra', 757)
end
.,.,
-module_eval(<<'.,.,', 'grammar.ra', 764)
- def _reduce_193(val, _values, result)
+module_eval(<<'.,.,', 'grammar.ra', 765)
+ def _reduce_194(val, _values, result)
if val[1].instance_of?(AST::ASTArray)
result = val[1]
else
@@ -2303,29 +2337,29 @@ module_eval(<<'.,.,', 'grammar.ra', 764)
end
.,.,
-module_eval(<<'.,.,', 'grammar.ra', 770)
- def _reduce_194(val, _values, result)
+module_eval(<<'.,.,', 'grammar.ra', 771)
+ def _reduce_195(val, _values, result)
result = ast AST::ASTArray
result
end
.,.,
-# reduce 195 omitted
-
# reduce 196 omitted
# reduce 197 omitted
-module_eval(<<'.,.,', 'grammar.ra', 777)
- def _reduce_198(val, _values, result)
+# reduce 198 omitted
+
+module_eval(<<'.,.,', 'grammar.ra', 778)
+ def _reduce_199(val, _values, result)
result = nil
result
end
.,.,
-module_eval(<<'.,.,', 'grammar.ra', 780)
- def _reduce_199(val, _values, result)
+module_eval(<<'.,.,', 'grammar.ra', 781)
+ def _reduce_200(val, _values, result)
result = ast AST::Regex, :value => val[0][:value]
result
diff --git a/spec/unit/parser/parser.rb b/spec/unit/parser/parser.rb
index bb0fa0a..84749c3 100755
--- a/spec/unit/parser/parser.rb
+++ b/spec/unit/parser/parser.rb
@@ -411,4 +411,45 @@ describe Puppet::Parser do
@parser.load("").should == false
end
end
+
+ describe "when parsing classes" do
+ before :each do
+ @krt = Puppet::Resource::TypeCollection.new("development")
+ @parser = Puppet::Parser::Parser.new "development"
+ @parser.stubs(:known_resource_types).returns @krt
+ end
+
+ it "should create new classes" do
+ @parser.parse("class foobar {}")
+ @krt.hostclass("foobar").should be_instance_of(Puppet::Resource::Type)
+ end
+
+ it "should correctly set the parent class when one is provided" do
+ @parser.parse("class foobar inherits yayness {}")
+ @krt.hostclass("foobar").parent.should == "yayness"
+ end
+
+ it "should define the code when some is provided" do
+ @parser.parse("class foobar { $var = val }")
+ @krt.hostclass("foobar").code.should_not be_nil
+ end
+
+ it "should define parameters when provided" do
+ @parser.parse("class foobar($biz,$baz) {}")
+ @krt.hostclass("foobar").arguments.should == {"biz" => nil, "baz" => nil}
+ end
+ end
+
+ describe "when parsing resources" do
+ before :each do
+ @krt = Puppet::Resource::TypeCollection.new("development")
+ @parser = Puppet::Parser::Parser.new "development"
+ @parser.stubs(:known_resource_types).returns @krt
+ end
+
+ it "should be able to parse class resources" do
+ @krt.add(Puppet::Resource::Type.new(:hostclass, "foobar", :arguments => {"biz" => nil}))
+ lambda { @parser.parse("class { foobar: biz => stuff }") }.should_not raise_error
+ end
+ end
end
--
1.6.1
This allowed me to almost entirely remove the subclass's
'initialize' method.
Signed-off-by: Luke Kanies <lu...@reductivelabs.com>
---
lib/puppet/parser/ast/resource.rb | 2 +-
lib/puppet/parser/resource.rb | 64 ++++++++++--------------------------
lib/puppet/resource.rb | 12 +++++--
spec/unit/parser/resource.rb | 26 +++++++-------
4 files changed, 41 insertions(+), 63 deletions(-)
diff --git a/lib/puppet/parser/ast/resource.rb b/lib/puppet/parser/ast/resource.rb
index c82e0b5..095e097 100644
--- a/lib/puppet/parser/ast/resource.rb
+++ b/lib/puppet/parser/ast/resource.rb
@@ -38,7 +38,7 @@ class Resource < AST::ResourceReference
resource_titles.flatten.collect { |resource_title|
exceptwrap :type => Puppet::ParseError do
resource = Puppet::Parser::Resource.new(type, resource_title,
- :params => paramobjects,
+ :parameters => paramobjects,
:file => self.file,
:line => self.line,
:exported => self.exported,
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb
index 2d71079..2e630a2 100644
--- a/lib/puppet/parser/resource.rb
+++ b/lib/puppet/parser/resource.rb
@@ -22,7 +22,7 @@ class Puppet::Parser::Resource < Puppet::Resource
attr_accessor :source, :scope, :rails_id
attr_accessor :virtual, :override, :translated, :catalog
- attr_reader :exported, :evaluated, :params
+ attr_reader :exported, :evaluated, :parameters
# Determine whether the provided parameter name is a relationship parameter.
def self.relationship_parameter?(name)
@@ -45,8 +45,8 @@ class Puppet::Parser::Resource < Puppet::Resource
if param == :title
return self.title
end
- if @params.has_key?(param)
- @params[param].value
+ if @parameters.has_key?(param)
+ @parameters[param].value
else
nil
end
@@ -57,7 +57,7 @@ class Puppet::Parser::Resource < Puppet::Resource
end
def eachparam
- @params.each do |name, param|
+ @parameters.each do |name, param|
yield param
end
end
@@ -107,41 +107,13 @@ class Puppet::Parser::Resource < Puppet::Resource
defined?(@finished) and @finished
end
- def initialize(type, title, options)
- @scope = options[:scope]
+ def initialize(*args)
+ super
- @params = {}
- # Define all of the parameters
- if params = options[:params]
- extract_parameters(params)
- options.delete(:params)
- end
-
- # Set all of the options we can.
- options.each do |option, value|
- if respond_to?(option.to_s + "=")
- send(option.to_s + "=", value)
- options.delete(option)
- else
- raise ArgumentError, "Resources do not accept #{option}"
- end
- end
-
- unless self.scope
+ unless scope
raise ArgumentError, "Resources require a scope"
end
-
@source ||= scope.source
-
- self.relative_type = type
- self.title = title
-
- if strict? and ! resource_type
- raise ArgumentError, "Invalid resource type #{type}"
- end
-
- tag(self.type)
- tag(self.title) if valid_tag?(self.title.to_s)
end
# Is this resource modeling an isomorphic resource type?
@@ -162,7 +134,7 @@ class Puppet::Parser::Resource < Puppet::Resource
raise Puppet::ParseError.new("Only subclasses can override parameters", resource.line, resource.file)
end
# Some of these might fail, but they'll fail in the way we want.
- resource.params.each do |name, param|
+ resource.parameters.each do |name, param|
override_parameter(param)
end
end
@@ -205,11 +177,11 @@ class Puppet::Parser::Resource < Puppet::Resource
tag(*param.value) if param.name == :tag
# And store it in our parameter hash.
- @params[param.name] = param
+ @parameters[param.name] = param
end
def to_hash
- @params.inject({}) do |hash, ary|
+ @parameters.inject({}) do |hash, ary|
param = ary[1]
# Skip "undef" values.
if param.value != :undef
@@ -280,10 +252,10 @@ class Puppet::Parser::Resource < Puppet::Resource
# Add default values from our definition.
def add_defaults
scope.lookupdefaults(self.type).each do |name, param|
- unless @params.include?(name)
+ unless @parameters.include?(name)
self.debug "Adding default for %s" % name
- @params[name] = param.dup
+ @parameters[name] = param.dup
end
end
end
@@ -293,10 +265,10 @@ class Puppet::Parser::Resource < Puppet::Resource
return unless val = scope.lookupvar(name.to_s, false) and val != :undefined
# The default case: just set the value
- set_parameter(name, val) and return unless @params[name]
+ set_parameter(name, val) and return unless @parameters[name]
# For relationship params, though, join the values (a la #446).
- @params[name].value = [@params[name].value, val].flatten
+ @parameters[name].value = [@parameters[name].value, val].flatten
end
# Add any metaparams defined in our scope. This actually adds any metaparams
@@ -310,7 +282,7 @@ class Puppet::Parser::Resource < Puppet::Resource
next
end
- next if @params[name]
+ next if @parameters[name]
# Skip metaparams for which we get no value.
next unless val = scope.lookupvar(name.to_s, false) and val != :undefined
@@ -329,7 +301,7 @@ class Puppet::Parser::Resource < Puppet::Resource
def override_parameter(param)
# This can happen if the override is defining a new parameter, rather
# than replacing an existing one.
- (set_parameter(param) and return) unless current = @params[param.name]
+ (set_parameter(param) and return) unless current = @parameters[param.name]
# The parameter is already set. Fail if they're not allowed to override it.
unless param.source.child_of?(current.source)
@@ -360,7 +332,7 @@ class Puppet::Parser::Resource < Puppet::Resource
# Make sure the resource's parameters are all valid for the type.
def validate
- @params.each do |name, param|
+ @parameters.each do |name, param|
validate_parameter(name)
end
rescue => detail
@@ -372,7 +344,7 @@ class Puppet::Parser::Resource < Puppet::Resource
def extract_parameters(params)
params.each do |param|
# Don't set the same parameter twice
- if @params[param.name]
+ if @parameters[param.name]
self.fail Puppet::ParseError, "Duplicate parameter '%s' for on %s" %
[param.name, self.to_s]
end
diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb
index df808e1..91a2610 100644
--- a/lib/puppet/resource.rb
+++ b/lib/puppet/resource.rb
@@ -154,9 +154,8 @@ class Puppet::Resource
self.type = tmp_type
self.title = tmp_title
- (attributes[:parameters] || {}).each do |param, value|
- validate_parameter(param) if strict?
- self[param] = value
+ if params = attributes[:parameters]
+ extract_parameters(params)
end
tag(self.type)
@@ -365,6 +364,13 @@ class Puppet::Resource
private
+ def extract_parameters(params)
+ params.each do |param, value|
+ validate_parameter(param) if strict?
+ self[param] = value
+ end
+ end
+
def extract_type_and_title(argtype, argtitle)
if (argtitle || argtype) =~ /^([^\[\]]+)\[(.+)\]$/m then [ $1, $2 ]
elsif argtitle then [ argtype, argtitle ]
diff --git a/spec/unit/parser/resource.rb b/spec/unit/parser/resource.rb
index ee0c1e0..57c03c6 100755
--- a/spec/unit/parser/resource.rb
+++ b/spec/unit/parser/resource.rb
@@ -19,11 +19,11 @@ describe Puppet::Parser::Resource do
args[:source] ||= @source
args[:scope] ||= @scope
- params = args[:params] || {:one => "yay", :three => "rah"}
- if args[:params] == :none
- args.delete(:params)
- elsif not args[:params].is_a? Array
- args[:params] = paramify(args[:source], params)
+ params = args[:parameters] || {:one => "yay", :three => "rah"}
+ if args[:parameters] == :none
+ args.delete(:parameters)
+ elsif not args[:parameters].is_a? Array
+ args[:parameters] = paramify(args[:source], params)
end
Puppet::Parser::Resource.new("resource", "testing", args)
@@ -122,7 +122,7 @@ describe Puppet::Parser::Resource do
it "should be tagged with user tags" do
tags = [ "tag1", "tag2" ]
- @arguments[:params] = [ param(:tag, tags , :source) ]
+ @arguments[:parameters] = [ param(:tag, tags , :source) ]
res = Puppet::Parser::Resource.new("resource", "testing", @arguments)
(res.tags & tags).should == tags
end
@@ -343,7 +343,7 @@ describe Puppet::Parser::Resource do
@override.source = @resource.source
@override.source.expects(:child_of?).with("source3").never
params = {:a => :b, :c => :d}
- @override.expects(:params).returns(params)
+ @override.expects(:parameters).returns(params)
@resource.expects(:override_parameter).with(:b)
@resource.expects(:override_parameter).with(:d)
@resource.merge(@override)
@@ -354,7 +354,7 @@ describe Puppet::Parser::Resource do
@override.source = "source4"
@override.source.expects(:child_of?).with("source3").returns(true)
params = {:a => :b, :c => :d}
- @override.expects(:params).returns(params)
+ @override.expects(:parameters).returns(params)
@resource.expects(:override_parameter).with(:b)
@resource.expects(:override_parameter).with(:d)
@resource.merge(@override)
@@ -433,7 +433,7 @@ describe Puppet::Parser::Resource do
describe "when being converted to a resource" do
before do
- @parser_resource = mkresource :scope => @scope, :params => {:foo => "bar", :fee => "fum"}
+ @parser_resource = mkresource :scope => @scope, :parameters => {:foo => "bar", :fee => "fum"}
end
it "should create an instance of Puppet::Resource" do
@@ -485,14 +485,14 @@ describe Puppet::Parser::Resource do
it "should convert any parser resource references to Puppet::Resource instances" do
ref = Puppet::Resource.new("file", "/my/file")
- @parser_resource = mkresource :source => @source, :params => {:foo => "bar", :fee => ref}
+ @parser_resource = mkresource :source => @source, :parameters => {:foo => "bar", :fee => ref}
result = @parser_resource.to_resource
result[:fee].should == Puppet::Resource.new(:file, "/my/file")
end
it "should convert any parser resource references to Puppet::Resource instances even if they are in an array" do
ref = Puppet::Resource.new("file", "/my/file")
- @parser_resource = mkresource :source => @source, :params => {:foo => "bar", :fee => ["a", ref]}
+ @parser_resource = mkresource :source => @source, :parameters => {:foo => "bar", :fee => ["a", ref]}
result = @parser_resource.to_resource
result[:fee].should == ["a", Puppet::Resource.new(:file, "/my/file")]
end
@@ -500,14 +500,14 @@ describe Puppet::Parser::Resource do
it "should convert any parser resource references to Puppet::Resource instances even if they are in an array of array, and even deeper" do
ref1 = Puppet::Resource.new("file", "/my/file1")
ref2 = Puppet::Resource.new("file", "/my/file2")
- @parser_resource = mkresource :source => @source, :params => {:foo => "bar", :fee => ["a", [ref1,ref2]]}
+ @parser_resource = mkresource :source => @source, :parameters => {:foo => "bar", :fee => ["a", [ref1,ref2]]}
result = @parser_resource.to_resource
result[:fee].should == ["a", Puppet::Resource.new(:file, "/my/file1"), Puppet::Resource.new(:file, "/my/file2")]
end
it "should fail if the same param is declared twice" do
lambda do
- @parser_resource = mkresource :source => @source, :params => [
+ @parser_resource = mkresource :source => @source, :parameters => [
Puppet::Parser::Resource::Param.new(
:name => :foo, :value => "bar", :source => @source
),
--
1.6.1
In addition to those renames, this commit includes fixes
to whatever tests I needed to fix to confirm that things
were again working. I think most of these broken
tests have been broken for a while.
Signed-off-by: Luke Kanies <lu...@reductivelabs.com>
---
lib/puppet/parser/ast/collection.rb | 2 +-
lib/puppet/parser/ast/resource.rb | 10 ++--
lib/puppet/parser/ast/resource_defaults.rb | 4 +-
lib/puppet/parser/ast/resource_override.rb | 8 ++--
lib/puppet/parser/collector.rb | 4 +-
lib/puppet/parser/grammar.ra | 6 +-
lib/puppet/parser/parser.rb | 6 +-
lib/puppet/type/component.rb | 2 +-
spec/integration/parser/collector.rb | 38 ++++++++++++++++++
spec/integration/parser/functions/require.rb | 2 +-
spec/unit/other/transbucket.rb | 2 +-
spec/unit/parser/ast/resource.rb | 6 +-
spec/unit/parser/ast/resource_defaults.rb | 22 ++++++++++
spec/unit/parser/ast/resource_override.rb | 10 ++--
spec/unit/parser/collector.rb | 24 ++++++------
spec/unit/parser/parser.rb | 2 +-
spec/unit/type.rb | 4 +-
spec/unit/type/component.rb | 6 +-
spec/unit/util/reference_serializer.rb | 2 +-
test/language/ast.rb | 55 +-------------------------
test/language/functions.rb | 11 ++---
test/language/scope.rb | 55 +-------------------------
test/language/snippets.rb | 4 +-
test/lib/puppettest/parsertesting.rb | 16 +++----
test/lib/puppettest/railstesting.rb | 2 +-
test/lib/puppettest/resourcetesting.rb | 8 ++--
test/lib/puppettest/support/collection.rb | 29 -------------
27 files changed, 132 insertions(+), 208 deletions(-)
create mode 100755 spec/integration/parser/collector.rb
create mode 100755 spec/unit/parser/ast/resource_defaults.rb
delete mode 100644 test/lib/puppettest/support/collection.rb
diff --git a/lib/puppet/parser/ast/collection.rb b/lib/puppet/parser/ast/collection.rb
index 55e99fc..f3690c1 100644
--- a/lib/puppet/parser/ast/collection.rb
+++ b/lib/puppet/parser/ast/collection.rb
@@ -31,7 +31,7 @@ class Collection < AST::Branch
end
newcoll.add_override(
- :params => params,
+ :parameters => params,
:file => @file,
:line => @line,
:source => scope.source,
diff --git a/lib/puppet/parser/ast/resource.rb b/lib/puppet/parser/ast/resource.rb
index 095e097..5488724 100644
--- a/lib/puppet/parser/ast/resource.rb
+++ b/lib/puppet/parser/ast/resource.rb
@@ -8,13 +8,13 @@ class Resource < AST::ResourceReference
associates_doc
attr_accessor :title, :type, :exported, :virtual
- attr_reader :params
+ attr_reader :parameters
# Does not actually return an object; instead sets an object
# in the current scope.
def evaluate(scope)
# Evaluate all of the specified params.
- paramobjects = params.collect { |param|
+ paramobjects = parameters.collect { |param|
param.safeevaluate(scope)
}
@@ -58,11 +58,11 @@ class Resource < AST::ResourceReference
end
# Set the parameters for our object.
- def params=(params)
+ def parameters=(params)
if params.is_a?(AST::ASTArray)
- @params = params
+ @parameters = params
else
- @params = AST::ASTArray.new(
+ @parameters = AST::ASTArray.new(
:line => params.line,
:file => params.file,
:children => [params]
diff --git a/lib/puppet/parser/ast/resource_defaults.rb b/lib/puppet/parser/ast/resource_defaults.rb
index f0746ec..aec86d0 100644
--- a/lib/puppet/parser/ast/resource_defaults.rb
+++ b/lib/puppet/parser/ast/resource_defaults.rb
@@ -4,7 +4,7 @@ class Puppet::Parser::AST
# A statement syntactically similar to an ResourceDef, but uses a
# capitalized object type and cannot have a name.
class ResourceDefaults < AST::Branch
- attr_accessor :type, :params
+ attr_accessor :type, :parameters
associates_doc
@@ -14,7 +14,7 @@ class Puppet::Parser::AST
# Use a resource reference to canonize the type
ref = Puppet::Resource.new(@type, "whatever")
type = ref.type
- params = @params.safeevaluate(scope)
+ params = @parameters.safeevaluate(scope)
parsewrap do
scope.setdefaults(type, params)
diff --git a/lib/puppet/parser/ast/resource_override.rb b/lib/puppet/parser/ast/resource_override.rb
index 2d4f7a8..93ddf4d 100644
--- a/lib/puppet/parser/ast/resource_override.rb
+++ b/lib/puppet/parser/ast/resource_override.rb
@@ -8,11 +8,11 @@ class Puppet::Parser::AST
associates_doc
attr_accessor :object
- attr_reader :params
+ attr_reader :parameters
# Iterate across all of our children.
def each
- [@object,@params].flatten.each { |param|
+ [@object,@parameters].flatten.each { |param|
#Puppet.debug("yielding param %s" % param)
yield param
}
@@ -27,7 +27,7 @@ class Puppet::Parser::AST
hash = {}
# Evaluate all of the specified params.
- params = @params.collect { |param|
+ params = @parameters.collect { |param|
param.safeevaluate(scope)
}
@@ -37,7 +37,7 @@ class Puppet::Parser::AST
resource = resource.collect do |r|
res = Puppet::Parser::Resource.new(r.type, r.title,
- :params => params,
+ :parameters => params,
:file => file,
:line => line,
:source => scope.source,
diff --git a/lib/puppet/parser/collector.rb b/lib/puppet/parser/collector.rb
index 67bd336..9126cb2 100644
--- a/lib/puppet/parser/collector.rb
+++ b/lib/puppet/parser/collector.rb
@@ -42,7 +42,7 @@ class Puppet::Parser::Collector
objects.each do |res|
unless @collected.include?(res.ref)
newres = Puppet::Parser::Resource.new(res.type, res.title,
- :params => overrides[:params],
+ :parameters => overrides[:parameters],
:file => overrides[:file],
:line => overrides[:line],
:source => overrides[:source],
@@ -83,7 +83,7 @@ class Puppet::Parser::Collector
# add a resource override to the soon to be exported/realized resources
def add_override(hash)
- unless hash[:params]
+ unless hash[:parameters]
raise ArgumentError, "Exported resource try to override without parameters"
end
diff --git a/lib/puppet/parser/grammar.ra b/lib/puppet/parser/grammar.ra
index 0aa31e5..a8bc822 100644
--- a/lib/puppet/parser/grammar.ra
+++ b/lib/puppet/parser/grammar.ra
@@ -153,20 +153,20 @@ resource: classname LBRACE resourceinstances endsemi RBRACE {
result.push ast(AST::Resource,
:type => val[0],
:title => instance[0],
- :params => instance[1])
+ :parameters => instance[1])
}
} | classname LBRACE params endcomma RBRACE {
# This is a deprecated syntax.
error "All resource specifications require names"
} | classref LBRACE params endcomma RBRACE {
# a defaults setting for a type
- result = ast(AST::ResourceDefaults, :type => val[0], :params => val[2])
+ result = ast(AST::ResourceDefaults, :type => val[0], :parameters => val[2])
}
# Override a value set elsewhere in the configuration.
resourceoverride: resourceref LBRACE anyparams endcomma RBRACE {
@lexer.commentpop
- result = ast AST::ResourceOverride, :object => val[0], :params => val[2]
+ result = ast AST::ResourceOverride, :object => val[0], :parameters => val[2]
}
# Exported and virtual resources; these don't get sent to the client
diff --git a/lib/puppet/parser/parser.rb b/lib/puppet/parser/parser.rb
index a1d2341..ffcd458 100644
--- a/lib/puppet/parser/parser.rb
+++ b/lib/puppet/parser/parser.rb
@@ -1199,7 +1199,7 @@ module_eval(<<'.,.,', 'grammar.ra', 138)
result.push ast(AST::Resource,
:type => val[0],
:title => instance[0],
- :params => instance[1])
+ :parameters => instance[1])
}
result
@@ -1218,7 +1218,7 @@ module_eval(<<'.,.,', 'grammar.ra', 158)
module_eval(<<'.,.,', 'grammar.ra', 161)
def _reduce_36(val, _values, result)
# a defaults setting for a type
- result = ast(AST::ResourceDefaults, :type => val[0], :params => val[2])
+ result = ast(AST::ResourceDefaults, :type => val[0], :parameters => val[2])
result
end
@@ -1227,7 +1227,7 @@ module_eval(<<'.,.,', 'grammar.ra', 161)
module_eval(<<'.,.,', 'grammar.ra', 167)
def _reduce_37(val, _values, result)
@lexer.commentpop
- result = ast AST::ResourceOverride, :object => val[0], :params => val[2]
+ result = ast AST::ResourceOverride, :object => val[0], :parameters => val[2]
result
end
diff --git a/lib/puppet/type/component.rb b/lib/puppet/type/component.rb
index d16cdda..b62954b 100644
--- a/lib/puppet/type/component.rb
+++ b/lib/puppet/type/component.rb
@@ -40,7 +40,7 @@ Puppet::Type.newtype(:component) do
if reference.type == "Class"
# 'main' is the top class, so we want to see '//' instead of
# its name.
- if reference.title == "main"
+ if reference.title.to_s.downcase == "main"
myname = ""
else
myname = reference.title
diff --git a/spec/integration/parser/collector.rb b/spec/integration/parser/collector.rb
new file mode 100755
index 0000000..4b1279e
--- /dev/null
+++ b/spec/integration/parser/collector.rb
@@ -0,0 +1,38 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'puppet/parser/collector'
+
+describe Puppet::Parser::Collector do
+ before do
+ @scope = Puppet::Parser::Scope.new(:compiler => Puppet::Parser::Compiler.new(Puppet::Node.new("mynode")))
+
+ @resource = Puppet::Parser::Resource.new("file", "/tmp/testing", :scope => @scope, :source => "fakesource")
+ {:owner => "root", :group => "bin", :mode => "644"}.each do |param, value|
+ @resource[param] = value
+ end
+ end
+
+ def query(text)
+ code = "File <| #{text} |>"
+ parser = Puppet::Parser::Parser.new(@scope.compiler)
+ parser.parse(code).hostclass("").code[0].query
+ end
+
+ {true => [%{title == "/tmp/testing"}, %{(title == "/tmp/testing")}, %{group == bin},
+ %{title == "/tmp/testing" and group == bin}, %{title == bin or group == bin},
+ %{title == "/tmp/testing" or title == bin}, %{title == "/tmp/testing"},
+ %{(title == "/tmp/testing" or title == bin) and group == bin}],
+ false => [%{title == bin}, %{title == bin or (title == bin and group == bin)},
+ %{title != "/tmp/testing"}, %{title != "/tmp/testing" and group != bin}]
+ }.each do |result, ary|
+ ary.each do |string|
+ it "should return '#{result}' when collecting resources with '#{string}'" do
+ str, code = query(string).evaluate @scope
+ code.should be_instance_of(Proc)
+ code.call(@resource).should == result
+ end
+ end
+ end
+end
diff --git a/spec/integration/parser/functions/require.rb b/spec/integration/parser/functions/require.rb
index 87c6781..0cb8402 100755
--- a/spec/integration/parser/functions/require.rb
+++ b/spec/integration/parser/functions/require.rb
@@ -22,6 +22,6 @@ describe "The require function" do
@scope.resource["require"].should_not be_nil
ref = @scope.resource["require"]
ref.type.should == "Class"
- ref.title.should == "requiredclass"
+ ref.title.should == "Requiredclass"
end
end
diff --git a/spec/unit/other/transbucket.rb b/spec/unit/other/transbucket.rb
index 63b5137..a761951 100755
--- a/spec/unit/other/transbucket.rb
+++ b/spec/unit/other/transbucket.rb
@@ -44,7 +44,7 @@ describe Puppet::TransBucket do
it "should return use 'component' as the type and the provided type as the title if only a name is provided" do
@bucket.name = "mystuff"
- @bucket.to_ref.should == "Class[mystuff]"
+ @bucket.to_ref.should == "Class[Mystuff]"
end
it "should return nil as its reference when type and name are missing" do
diff --git a/spec/unit/parser/ast/resource.rb b/spec/unit/parser/ast/resource.rb
index 40074c7..2473fda 100755
--- a/spec/unit/parser/ast/resource.rb
+++ b/spec/unit/parser/ast/resource.rb
@@ -10,14 +10,14 @@ describe Puppet::Parser::AST::Resource do
@compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("mynode"))
@scope = Puppet::Parser::Scope.new(:compiler => @compiler)
@scope.stubs(:resource).returns(stub_everything)
- @resource = ast::Resource.new(:title => @title, :type => "file", :params => ast::ASTArray.new(:children => []) )
+ @resource = ast::Resource.new(:title => @title, :type => "file", :parameters => ast::ASTArray.new(:children => []) )
@resource.stubs(:qualified_type).returns("Resource")
end
it "should evaluate all its parameters" do
param = stub 'param'
param.expects(:safeevaluate).with(@scope).returns Puppet::Parser::Resource::Param.new(:name => "myparam", :value => "myvalue", :source => stub("source"))
- @resource.stubs(:params).returns [param]
+ @resource.stubs(:parameters).returns [param]
@resource.evaluate(@scope)
end
@@ -98,7 +98,7 @@ describe Puppet::Parser::AST::Resource do
def resource(type, params = nil)
params ||= Puppet::Parser::AST::ASTArray.new(:children => [])
- Puppet::Parser::AST::Resource.new(:type => type, :title => Puppet::Parser::AST::String.new(:value => "myresource"), :params => params)
+ Puppet::Parser::AST::Resource.new(:type => type, :title => Puppet::Parser::AST::String.new(:value => "myresource"), :parameters => params)
end
it "should be able to generate resources with fully qualified type information" do
diff --git a/spec/unit/parser/ast/resource_defaults.rb b/spec/unit/parser/ast/resource_defaults.rb
new file mode 100755
index 0000000..b2cec31
--- /dev/null
+++ b/spec/unit/parser/ast/resource_defaults.rb
@@ -0,0 +1,22 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+describe Puppet::Parser::AST::ResourceDefaults do
+
+ ast = Puppet::Parser::AST
+
+ before :each do
+ @compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("mynode"))
+ @scope = Puppet::Parser::Scope.new(:compiler => @compiler)
+ @params = Puppet::Parser::AST::ASTArray.new({})
+ @compiler.stubs(:add_override)
+ end
+
+ it "should add defaults when evaluated" do
+ default = Puppet::Parser::AST::ResourceDefaults.new :type => "file", :parameters => Puppet::Parser::AST::ASTArray.new(:children => [])
+ default.evaluate @scope
+
+ @scope.lookupdefaults("file").should_not be_nil
+ end
+end
diff --git a/spec/unit/parser/ast/resource_override.rb b/spec/unit/parser/ast/resource_override.rb
index 2735757..d327b57 100755
--- a/spec/unit/parser/ast/resource_override.rb
+++ b/spec/unit/parser/ast/resource_override.rb
@@ -7,7 +7,7 @@ describe Puppet::Parser::AST::ResourceOverride do
ast = Puppet::Parser::AST
before :each do
- @compiler = stub 'compiler'
+ @compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("mynode"))
@scope = Puppet::Parser::Scope.new(:compiler => @compiler)
@params = ast::ASTArray.new({})
@compiler.stubs(:add_override)
@@ -17,7 +17,7 @@ describe Puppet::Parser::AST::ResourceOverride do
klass = stub 'klass', :title => "title", :type => "type"
object = mock 'object'
object.expects(:safeevaluate).with(@scope).returns(klass)
- ast::ResourceOverride.new(:object => object, :params => @params ).evaluate(@scope)
+ ast::ResourceOverride.new(:object => object, :parameters => @params ).evaluate(@scope)
end
it "should tell the compiler to override the resource with our own" do
@@ -25,13 +25,13 @@ describe Puppet::Parser::AST::ResourceOverride do
klass = stub 'klass', :title => "title", :type => "one"
object = mock 'object', :safeevaluate => klass
- ast::ResourceOverride.new(:object => object , :params => @params).evaluate(@scope)
+ ast::ResourceOverride.new(:object => object , :parameters => @params).evaluate(@scope)
end
it "should return the overriden resource directly when called with one item" do
klass = stub 'klass', :title => "title", :type => "one"
object = mock 'object', :safeevaluate => klass
- override = ast::ResourceOverride.new(:object => object , :params => @params).evaluate(@scope)
+ override = ast::ResourceOverride.new(:object => object , :parameters => @params).evaluate(@scope)
override.should be_an_instance_of(Puppet::Parser::Resource)
override.title.should == "title"
override.type.should == "One"
@@ -43,7 +43,7 @@ describe Puppet::Parser::AST::ResourceOverride do
object = mock 'object', :safeevaluate => [klass1,klass2]
- override = ast::ResourceOverride.new(:object => object , :params => @params).evaluate(@scope)
+ override = ast::ResourceOverride.new(:object => object , :parameters => @params).evaluate(@scope)
override.should have(2).elements
override.each {|o| o.should be_an_instance_of(Puppet::Parser::Resource) }
end
diff --git a/spec/unit/parser/collector.rb b/spec/unit/parser/collector.rb
index 78d47c6..42da3ff 100755
--- a/spec/unit/parser/collector.rb
+++ b/spec/unit/parser/collector.rb
@@ -42,7 +42,7 @@ describe Puppet::Parser::Collector, "when initializing" do
it "should accept an optional resource override" do
@collector = Puppet::Parser::Collector.new(@scope, "resource::type", @equery, @vquery, @form)
- override = { :params => "whatever" }
+ override = { :parameters => "whatever" }
@collector.add_override(override)
@collector.overrides.should equal(override)
end
@@ -181,9 +181,9 @@ describe Puppet::Parser::Collector, "when collecting virtual and catalog resourc
@compiler.expects(:resources).returns([one])
- @collector.add_override(:params => param )
+ @collector.add_override(:parameters => param )
Puppet::Parser::Resource.expects(:new).with { |type, title, h|
- h[:params] == param
+ h[:parameters] == param
}
@collector.evaluate
@@ -197,7 +197,7 @@ describe Puppet::Parser::Collector, "when collecting virtual and catalog resourc
@compiler.expects(:resources).returns([one])
- @collector.add_override(:params => param, :source => source )
+ @collector.add_override(:parameters => param, :source => source )
Puppet::Parser::Resource.stubs(:new)
source.expects(:meta_def).with { |name,block| name == :child_of? }
@@ -213,9 +213,9 @@ describe Puppet::Parser::Collector, "when collecting virtual and catalog resourc
@compiler.expects(:resources).at_least(2).returns([one])
- @collector.add_override(:params => param )
+ @collector.add_override(:parameters => param )
Puppet::Parser::Resource.expects(:new).once.with { |type, title, h|
- h[:params] == param
+ h[:parameters] == param
}
@collector.evaluate
@@ -239,7 +239,7 @@ describe Puppet::Parser::Collector, "when collecting virtual and catalog resourc
one.expects(:virtual=).with(false)
@compiler.expects(:resources).returns([one])
- @collector.add_override(:params => param )
+ @collector.add_override(:parameters => param )
Puppet::Parser::Resource.stubs(:new).returns("whatever")
@compiler.expects(:add_override).with("whatever")
@@ -266,14 +266,14 @@ describe Puppet::Parser::Collector, "when collecting exported resources" do
confine "Cannot test Rails integration without ActiveRecord" => Puppet.features.rails?
before do
- @scope = stub 'scope', :host => "myhost", :debug => nil
- @compiler = mock 'compile'
- @scope.stubs(:compiler).returns(@compiler)
+ @compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("mynode"))
+ @scope = Puppet::Parser::Scope.new :compiler => @compiler
@resource_type = "Mytype"
@equery = "test = true"
@vquery = proc { |r| true }
Puppet.settings.stubs(:value).with(:storeconfigs).returns true
+ Puppet.settings.stubs(:value).with(:environment).returns "production"
@collector = Puppet::Parser::Collector.new(@scope, @resource_type, @equery, @vquery, :exported)
end
@@ -374,9 +374,9 @@ describe Puppet::Parser::Collector, "when collecting exported resources" do
@compiler.stubs(:add_override)
@compiler.stubs(:add_resource)
- @collector.add_override(:params => param )
+ @collector.add_override(:parameters => param )
Puppet::Parser::Resource.expects(:new).once.with { |type, title, h|
- h[:params] == param
+ h[:parameters] == param
}
@collector.evaluate
diff --git a/spec/unit/parser/parser.rb b/spec/unit/parser/parser.rb
index 8cc29c9..909a73c 100755
--- a/spec/unit/parser/parser.rb
+++ b/spec/unit/parser/parser.rb
@@ -154,7 +154,7 @@ describe Puppet::Parser do
it "should create an ast::ResourceOverride" do
ast::ResourceOverride.expects(:new).with { |arg|
- arg[:line]==1 and arg[:object].is_a?(ast::ResourceReference) and arg[:params].is_a?(ast::ResourceParam)
+ arg[:line]==1 and arg[:object].is_a?(ast::ResourceReference) and arg[:parameters].is_a?(ast::ResourceParam)
}
@parser.parse('Resource["title1","title2"] { param => value }')
end
diff --git a/spec/unit/type.rb b/spec/unit/type.rb
index 58c378f..57d5b4b 100755
--- a/spec/unit/type.rb
+++ b/spec/unit/type.rb
@@ -429,9 +429,9 @@ describe Puppet::Type::RelationshipMetaparam do
param = Puppet::Type.metaparamclass(:require).new(:resource => resource, :value => %w{Foo[bar] Class[test]})
catalog.expects(:resource).with("Foo[bar]").returns "something"
- catalog.expects(:resource).with("Class[test]").returns nil
+ catalog.expects(:resource).with("Class[Test]").returns nil
- param.expects(:fail).with { |string| string.include?("Class[test]") }
+ param.expects(:fail).with { |string| string.include?("Class[Test]") }
param.validate_relationship
end
diff --git a/spec/unit/type/component.rb b/spec/unit/type/component.rb
index 64d26d5..ab60e02 100755
--- a/spec/unit/type/component.rb
+++ b/spec/unit/type/component.rb
@@ -10,11 +10,11 @@ describe component do
end
it "should use Class as its type when a normal string is provided as the title" do
- component.new(:name => "bar").ref.should == "Class[bar]"
+ component.new(:name => "bar").ref.should == "Class[Bar]"
end
it "should always produce a resource reference string as its title" do
- component.new(:name => "bar").title.should == "Class[bar]"
+ component.new(:name => "bar").title.should == "Class[Bar]"
end
it "should have a reference string equivalent to its title" do
@@ -49,7 +49,7 @@ describe component do
describe "when building up the path" do
it "should produce the class name if the component models a class" do
- component.new(:name => "Class[foo]").pathbuilder.must == ["foo"]
+ component.new(:name => "Class[foo]").pathbuilder.must == ["Foo"]
end
it "should produce an empty string if the component models the 'main' class" do
diff --git a/spec/unit/util/reference_serializer.rb b/spec/unit/util/reference_serializer.rb
index c3da45a..cfabec4 100644
--- a/spec/unit/util/reference_serializer.rb
+++ b/spec/unit/util/reference_serializer.rb
@@ -14,7 +14,7 @@ describe Puppet::Util::ReferenceSerializer do
describe "when serializing" do
it "should yaml-dump resource references" do
- ref = Puppet::Parser::Resource::Reference.new(:type => "file", :title => "/foo")
+ ref = Puppet::Resource.new("file", "/foo")
@tester.serialize_value(ref).should =~ /^---/
end
diff --git a/test/language/ast.rb b/test/language/ast.rb
index 916c34d..a4d4d87 100755
--- a/test/language/ast.rb
+++ b/test/language/ast.rb
@@ -6,12 +6,10 @@ require 'puppettest'
require 'puppet/parser/parser'
require 'puppettest/resourcetesting'
require 'puppettest/parsertesting'
-require 'puppettest/support/collection'
class TestAST < Test::Unit::TestCase
include PuppetTest::ParserTesting
include PuppetTest::ResourceTesting
- include PuppetTest::Support::Collection
def test_if
scope = mkscope
@@ -56,41 +54,13 @@ class TestAST < Test::Unit::TestCase
ref = resourceoverride("file", "/yayness", "owner" => "blah", "group" => "boo")
end
- Puppet::Parser::Resource.expects(:new).with { |type, title, o| o.is_a?(Hash) }.returns(:override)
- scope.compiler.expects(:add_override).with(:override)
+ scope.compiler.expects(:add_override).with { |res| res.is_a?(Puppet::Parser::Resource) }
ret = nil
assert_nothing_raised do
ret = ref.evaluate scope
end
- assert_equal(:override, ret, "Did not return override")
- end
-
- # make sure our resourcedefaults ast object works correctly.
- def test_resourcedefaults
- scope = mkscope
-
- # Now make some defaults for files
- args = {:source => "/yay/ness", :group => "yayness"}
- assert_nothing_raised do
- obj = defaultobj "file", args
- obj.evaluate scope
- end
-
- hash = nil
- assert_nothing_raised do
- hash = scope.lookupdefaults("File")
- end
-
- hash.each do |name, value|
- assert_instance_of(Symbol, name) # params always convert
- assert_instance_of(Puppet::Parser::Resource::Param, value)
- end
-
- args.each do |name, value|
- assert(hash[name], "Did not get default %s" % name)
- assert_equal(value, hash[name].value)
- end
+ assert_instance_of(Puppet::Parser::Resource, ret, "Did not return override")
end
def test_collection
@@ -114,25 +84,4 @@ class TestAST < Test::Unit::TestCase
colls = scope.compiler.instance_variable_get("@collections")
assert_equal([ret], colls, "Did not store collector in config's collection list")
end
-
- def test_virtual_collexp
- scope = mkscope
-
- # make a resource
- resource = mkresource(:type => "file", :title => "/tmp/testing",
- :scope => scope, :params => {:owner => "root", :group => "bin", :mode => "644"})
-
- run_collection_queries(:virtual) do |string, result, query|
- code = nil
- assert_nothing_raised do
- str, code = query.evaluate scope
- end
-
- assert_instance_of(Proc, code)
- assert_nothing_raised do
- assert_equal(result, code.call(resource),
- "'#{string}' failed")
- end
- end
- end
end
diff --git a/test/language/functions.rb b/test/language/functions.rb
index 70605f8..8797a46 100755
--- a/test/language/functions.rb
+++ b/test/language/functions.rb
@@ -382,16 +382,13 @@ class TestLangFunctions < Test::Unit::TestCase
end
def test_search
- parser = mkparser
- scope = mkscope(:parser => parser)
+ scope = mkscope
- fun = parser.newdefine("yay::ness")
- foo = parser.newdefine("foo::bar")
+ fun = scope.known_resource_types.add Puppet::Resource::Type.new(:definition, "yay::ness")
+ foo = scope.known_resource_types.add Puppet::Resource::Type.new(:definition, "foo::bar")
search = Puppet::Parser::Functions.function(:search)
- assert_nothing_raised do
- scope.function_search(["foo", "yay"])
- end
+ scope.function_search(["foo", "yay"])
ffun = ffoo = nil
assert_nothing_raised("Search path change did not work") do
diff --git a/test/language/scope.rb b/test/language/scope.rb
index d2f6ec7..07f8aa7 100755
--- a/test/language/scope.rb
+++ b/test/language/scope.rb
@@ -118,53 +118,6 @@ class TestScope < Test::Unit::TestCase
assert_equal(top, sub.parent, "Did not find parent scope on second call")
end
- def test_includefunction
- parser = mkparser
- scope = mkscope :parser => parser
-
- myclass = parser.newclass "myclass"
- otherclass = parser.newclass "otherclass"
-
- function = Puppet::Parser::AST::Function.new(
- :name => "include",
- :ftype => :statement,
- :arguments => AST::ASTArray.new(
- :children => [nameobj("myclass"), nameobj("otherclass")]
- )
- )
-
- assert_nothing_raised do
- function.evaluate scope
- end
-
- scope.compiler.send(:evaluate_generators)
-
- [myclass, otherclass].each do |klass|
- assert(scope.compiler.class_scope(klass),
- "%s was not set" % klass.name)
- end
- end
-
- def test_definedfunction
- Puppet::Parser::Functions.function(:defined)
- parser = mkparser
- %w{one two}.each do |name|
- parser.newdefine name
- end
-
- scope = mkscope :parser => parser
-
- assert_nothing_raised {
- %w{one two file user}.each do |type|
- assert(scope.function_defined([type]),
- "Class #{type} was not considered defined")
- end
-
- assert(!scope.function_defined(["nopeness"]),
- "Class 'nopeness' was incorrectly considered defined")
- }
- end
-
# Make sure we know what we consider to be truth.
def test_truth
assert_equal(true, Puppet::Parser::Scope.true?("a string"),
@@ -179,23 +132,19 @@ class TestScope < Test::Unit::TestCase
"undef considered true")
end
- # Verify that we recursively mark as exported the results of collectable
- # components.
def test_virtual_definitions_do_not_get_evaluated
- config = mkcompiler
parser = mkparser
+ config = mkcompiler
# Create a default source
parser.newclass("")
config.topscope.source = parser.known_resource_types.hostclass("")
# And a scope resource
- scope_res = Puppet::Parser::Resource.new(:file, "/file", :scope => "scope", :source => "source")
+ scope_res = Puppet::Parser::Resource.new(:file, "/file", :scope => config.topscope)
config.topscope.resource = scope_res
args = AST::ASTArray.new(
- :file => tempfile(),
- :line => rand(100),
:children => [nameobj("arg")]
)
diff --git a/test/language/snippets.rb b/test/language/snippets.rb
index 1ef91be..a0fbe78 100755
--- a/test/language/snippets.rb
+++ b/test/language/snippets.rb
@@ -123,7 +123,7 @@ class TestSnippets < Test::Unit::TestCase
end
def randeach(type)
- [:properties, :metaparams, :params].collect { |thing|
+ [:properties, :metaparams, :parameters].collect { |thing|
randthing(thing,type)
}
end
@@ -206,7 +206,7 @@ class TestSnippets < Test::Unit::TestCase
assert_nothing_raised {
assert_equal(
- "//testing/Mytype[componentname]/File[/tmp/classtest]",
+ "//Testing/Mytype[componentname]/File[/tmp/classtest]",
file.path)
}
end
diff --git a/test/lib/puppettest/parsertesting.rb b/test/lib/puppettest/parsertesting.rb
index 44c78f2..0cc3dde 100644
--- a/test/lib/puppettest/parsertesting.rb
+++ b/test/lib/puppettest/parsertesting.rb
@@ -53,9 +53,7 @@ module PuppetTest::ParserTesting
def mknode(name = nil)
require 'puppet/node'
- name ||= "nodename"
- Puppet::Network::Handler.handler(:node)
- Puppet::Node.new(name)
+ Puppet::Node.new(name || "nodename")
end
def mkparser
@@ -64,9 +62,9 @@ module PuppetTest::ParserTesting
end
def mkscope(hash = {})
- hash[:parser] ||= mkparser
- compiler ||= mkcompiler(hash[:parser])
- compiler.topscope.source = (hash[:parser].find_hostclass("", "") || hash[:parser].newclass(""))
+ parser ||= mkparser
+ compiler ||= mkcompiler
+ compiler.topscope.source = (parser.find_hostclass("", "") || parser.newclass(""))
unless compiler.topscope.source
raise "Could not find source for scope"
@@ -108,7 +106,7 @@ module PuppetTest::ParserTesting
:line => __LINE__,
:title => title,
:type => type,
- :params => resourceinst(params)
+ :parameters => resourceinst(params)
)
}
end
@@ -126,7 +124,7 @@ module PuppetTest::ParserTesting
:line => __LINE__,
:object => resourceref(type, title),
:type => type,
- :params => resourceinst(params)
+ :parameters => resourceinst(params)
)
}
end
@@ -273,7 +271,7 @@ module PuppetTest::ParserTesting
:file => __FILE__,
:line => __LINE__,
:type => type,
- :params => past
+ :parameters => past
)
}
end
diff --git a/test/lib/puppettest/railstesting.rb b/test/lib/puppettest/railstesting.rb
index fb5c15f..04ed0bf 100644
--- a/test/lib/puppettest/railstesting.rb
+++ b/test/lib/puppettest/railstesting.rb
@@ -33,7 +33,7 @@ module PuppetTest::RailsTesting
# Now build a resource
resources = []
resources << mkresource(:type => type, :title => title, :exported => true,
- :params => params)
+ :parameters => params)
# Now collect our facts
facts = Facter.to_hash
diff --git a/test/lib/puppettest/resourcetesting.rb b/test/lib/puppettest/resourcetesting.rb
index 95fe5bc..2e4db1d 100644
--- a/test/lib/puppettest/resourcetesting.rb
+++ b/test/lib/puppettest/resourcetesting.rb
@@ -23,11 +23,11 @@ module PuppetTest::ResourceTesting
args[param] ||= value
end
- params = args[:params] || {:one => "yay", :three => "rah"}
- if args[:params] == :none
- args.delete(:params)
+ params = args[:parameters] || {:one => "yay", :three => "rah"}
+ if args[:parameters] == :none
+ args.delete(:parameters)
else
- args[:params] = paramify args[:source], params
+ args[:parameters] = paramify args[:source], params
end
Parser::Resource.new(type, title, args)
diff --git a/test/lib/puppettest/support/collection.rb b/test/lib/puppettest/support/collection.rb
deleted file mode 100644
index 9da15ea..0000000
--- a/test/lib/puppettest/support/collection.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-
-module PuppetTest::Support::Collection
- def run_collection_queries(form)
- {true => [%{title == "/tmp/testing"}, %{(title == "/tmp/testing")}, %{group == bin},
- %{title == "/tmp/testing" and group == bin}, %{title == bin or group == bin},
- %{title == "/tmp/testing" or title == bin}, %{title == "/tmp/testing"},
- %{(title == "/tmp/testing" or title == bin) and group == bin}],
- false => [%{title == bin}, %{title == bin or (title == bin and group == bin)},
- %{title != "/tmp/testing"}, %{title != "/tmp/testing" and group != bin}]
- }.each do |res, ary|
- ary.each do |str|
- if form == :virtual
- code = "File <| #{str} |>"
- else
- code = "File <<| #{str} |>>"
- end
- parser = mkparser
- query = nil
-
- assert_nothing_raised("Could not parse '#{str}'") do
- query = parser.parse(code).hostclass("").code[0].query
- end
-
- yield str, res, query
- end
- end
- end
-end
-
--
1.6.1
Signed-off-by: Luke Kanies <lu...@reductivelabs.com>
---
lib/puppet/parser/collector.rb | 6 +-
lib/puppet/parser/compiler.rb | 3 +-
lib/puppet/parser/resource.rb | 4 +-
lib/puppet/reports/store.rb | 3 +-
lib/puppet/resource.rb | 52 +++-
lib/puppet/util/rails/reference_serializer.rb | 2 +-
spec/integration/transaction.rb | 182 ++++++++++++-
spec/unit/parser/ast/resource.rb | 36 +++-
spec/unit/parser/collector.rb | 8 +-
spec/unit/parser/resource.rb | 36 +--
spec/unit/resource.rb | 33 +++
spec/unit/type/resources.rb | 13 +
test/language/ast.rb | 3 +-
test/language/ast/resource.rb | 58 ----
test/language/ast/resource_reference.rb | 2 +-
test/language/ast/variable.rb | 3 +-
test/language/snippets.rb | 4 -
test/lib/puppettest.rb | 3 +
test/other/provider.rb | 15 -
test/other/report.rb | 10 +-
test/other/transactions.rb | 369 -------------------------
test/rails/rails.rb | 1 -
test/ral/type/host.rb | 35 ---
test/ral/type/resources.rb | 16 +-
test/ral/type/sshkey.rb | 41 ---
test/util/settings.rb | 63 +----
26 files changed, 344 insertions(+), 657 deletions(-)
delete mode 100755 test/language/ast/resource.rb
diff --git a/lib/puppet/parser/collector.rb b/lib/puppet/parser/collector.rb
index 0445187..67bd336 100644
--- a/lib/puppet/parser/collector.rb
+++ b/lib/puppet/parser/collector.rb
@@ -41,9 +41,7 @@ class Puppet::Parser::Collector
# overrided those resources
objects.each do |res|
unless @collected.include?(res.ref)
- res = Puppet::Parser::Resource.new(
- :type => res.type,
- :title => res.title,
+ newres = Puppet::Parser::Resource.new(res.type, res.title,
:params => overrides[:params],
:file => overrides[:file],
:line => overrides[:line],
@@ -51,7 +49,7 @@ class Puppet::Parser::Collector
:scope => overrides[:scope]
)
- scope.compiler.add_override(res)
+ scope.compiler.add_override(newres)
end
end
end
diff --git a/lib/puppet/parser/compiler.rb b/lib/puppet/parser/compiler.rb
index 31df266..4cf71ae 100644
--- a/lib/puppet/parser/compiler.rb
+++ b/lib/puppet/parser/compiler.rb
@@ -69,7 +69,8 @@ class Puppet::Parser::Compiler
if existing.nodescope? != scope.nodescope?
raise Puppet::ParseError, "Cannot have classes, nodes, or definitions with the same name"
else
- raise Puppet::DevError, "Somehow evaluated %s %s twice" % [ existing.nodescope? ? "node" : "class", name]
+ type = existing.nodescope? ? "node" : "class"
+ raise Puppet::DevError, "Somehow evaluated #{type} #{name} twice"
end
end
@class_scopes[name] = scope
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb
index 36f1fbe..3f6d73d 100644
--- a/lib/puppet/parser/resource.rb
+++ b/lib/puppet/parser/resource.rb
@@ -108,7 +108,9 @@ class Puppet::Parser::Resource < Puppet::Resource
end
def initialize(type, title, options)
- self.type = type
+ @scope = options[:scope]
+
+ self.relative_type = type
self.title = title
@params = {}
diff --git a/lib/puppet/reports/store.rb b/lib/puppet/reports/store.rb
index 04eff82..a745275 100644
--- a/lib/puppet/reports/store.rb
+++ b/lib/puppet/reports/store.rb
@@ -18,7 +18,8 @@ Puppet::Reports.register_report(:store) do
:desc => "Client dir for %s" % client,
:owner => 'service',
:group => 'service'
- }
+ },
+ :noop => [false, "Used by settings internally."]
)
config.use("reportclient-#{client}".to_sym)
diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb
index 685a5fb..b1bd944 100644
--- a/lib/puppet/resource.rb
+++ b/lib/puppet/resource.rb
@@ -13,7 +13,8 @@ class Puppet::Resource
extend Puppet::Util::Pson
include Enumerable
attr_accessor :file, :line, :catalog, :exported, :virtual, :validate_parameters
- attr_reader :type, :title, :namespaces
+ attr_reader :title, :namespaces
+ attr_writer :relative_type
ATTRIBUTES = [:file, :line, :exported]
@@ -137,8 +138,6 @@ class Puppet::Resource
# Create our resource.
def initialize(type, title = nil, attributes = {})
- self.type, self.title = extract_type_and_title(type, title)
-
@parameters = {}
@namespaces = [""]
@@ -151,6 +150,13 @@ class Puppet::Resource
send(attr.to_s + "=", value)
end
+ # We do namespaces first, and use tmp variables, so our title
+ # canonicalization works (i.e., namespaces are set and resource
+ # types can be looked up)
+ tmp_type, tmp_title = extract_type_and_title(type, title)
+ self.type = tmp_type
+ self.title = tmp_title
+
tag(self.type)
tag(self.title) if valid_tag?(self.title)
end
@@ -166,14 +172,19 @@ class Puppet::Resource
end
def title=(value)
- if @type and klass = Puppet::Type.type(@type.to_s.downcase)
+ if klass = resource_type and klass.respond_to?(:canonicalize_ref)
value = klass.canonicalize_ref(value)
end
@title = value
end
+ # Canonize the type so we know it's always consistent.
+ def relative_type
+ munge_type_name(@relative_type)
+ end
+
def resource_type
- case type.to_s.downcase
+ case relative_type.to_s.downcase
when "class"; find_hostclass
when "node"; find_node
else
@@ -271,13 +282,18 @@ class Puppet::Resource
return result
end
- # Canonize the type so we know it's always consistent.
- def type=(value)
- if value.nil? or value.to_s.downcase == "component"
- @type = "Class"
+ def type
+ munge_type_name(if r = resource_type
+ resource_type.name
else
- @type = value.to_s.split("::").collect { |s| s.capitalize }.join("::")
- end
+ relative_type
+ end)
+ end
+
+ # Only allow people to set the relative type,
+ # so we force it to be looked up each time.
+ def type=(value)
+ @relative_type = value
end
def valid_parameter?(name)
@@ -300,11 +316,11 @@ class Puppet::Resource
end
def find_builtin_resource_type
- Puppet::Type.type(type.to_s.downcase.to_sym)
+ Puppet::Type.type(relative_type.to_s.downcase.to_sym)
end
def find_defined_resource_type
- known_resource_types.find_definition(namespaces, type.to_s.downcase)
+ known_resource_types.find_definition(namespaces, relative_type.to_s.downcase)
end
# Produce a canonical method name.
@@ -350,4 +366,14 @@ class Puppet::Resource
else raise ArgumentError, "No title provided and #{argtype.inspect} is not a valid resource reference"
end
end
+
+ def munge_type_name(value)
+ return :main if value == ""
+
+ if value.nil? or value.to_s.downcase == "component"
+ "Class"
+ else
+ value.to_s.split("::").collect { |s| s.capitalize }.join("::")
+ end
+ end
end
diff --git a/lib/puppet/util/rails/reference_serializer.rb b/lib/puppet/util/rails/reference_serializer.rb
index 63f109c..a23f2cb 100644
--- a/lib/puppet/util/rails/reference_serializer.rb
+++ b/lib/puppet/util/rails/reference_serializer.rb
@@ -15,7 +15,7 @@ module Puppet::Util::ReferenceSerializer
def serialize_value(val)
case val
- when Puppet::Parser::Resource::Reference
+ when Puppet::Resource
YAML.dump(val)
when true, false
# The database does this for us, but I prefer the
diff --git a/spec/integration/transaction.rb b/spec/integration/transaction.rb
index 7ab852b..62507ac 100755
--- a/spec/integration/transaction.rb
+++ b/spec/integration/transaction.rb
@@ -3,8 +3,17 @@
require File.dirname(__FILE__) + '/../spec_helper'
require 'puppet/transaction'
+require 'puppet_spec/files'
describe Puppet::Transaction do
+ include PuppetSpec::Files
+
+ def mk_catalog(*resources)
+ catalog = Puppet::Resource::Catalog.new(Puppet::Node.new("mynode"))
+ resources.each { |res| catalog.add_resource res }
+ catalog
+ end
+
it "should not apply generated resources if the parent resource fails" do
catalog = Puppet::Resource::Catalog.new
resource = Puppet::Type.type(:file).new :path => "/foo/bar", :backup => false
@@ -17,6 +26,7 @@ describe Puppet::Transaction do
transaction = Puppet::Transaction.new(catalog)
resource.expects(:evaluate).raises "this is a failure"
+ resource.stubs(:err)
child_resource.expects(:evaluate).never
@@ -38,15 +48,13 @@ describe Puppet::Transaction do
it "should apply exported resources" do
catalog = Puppet::Resource::Catalog.new
- resource = Puppet::Type.type(:file).new :path => "/foo/bar", :backup => false
+ path = tmpfile("exported_files")
+ resource = Puppet::Type.type(:file).new :path => path, :backup => false, :ensure => :file
resource.exported = true
catalog.add_resource resource
- transaction = Puppet::Transaction.new(catalog)
-
- resource.expects(:evaluate).never
-
- transaction.evaluate
+ catalog.apply
+ FileTest.should be_exist(path)
end
it "should not apply virtual exported resources" do
@@ -63,4 +71,166 @@ describe Puppet::Transaction do
transaction.evaluate
end
+ # Verify that one component requiring another causes the contained
+ # resources in the requiring component to get refreshed.
+ it "should propagate events from a contained resource through its container to its dependent container's contained resources" do
+ transaction = nil
+ file = Puppet::Type.type(:file).new :path => tmpfile("event_propagation"), :ensure => :present
+ execfile = File.join(tmpdir("exec_event"), "exectestingness2")
+ exec = Puppet::Type.type(:exec).new :command => "touch #{execfile}", :path => ENV['PATH']
+ catalog = mk_catalog(file)
+
+ fcomp = Puppet::Type.type(:component).new(:name => "Foo[file]")
+ catalog.add_resource fcomp
+ catalog.add_edge(fcomp, file)
+
+ ecomp = Puppet::Type.type(:component).new(:name => "Foo[exec]")
+ catalog.add_resource ecomp
+ catalog.add_resource exec
+ catalog.add_edge(ecomp, exec)
+
+ ecomp[:subscribe] = Puppet::Resource.new(:foo, "file")
+ exec[:refreshonly] = true
+
+ exec.expects(:refresh)
+ catalog.apply
+ end
+
+ # Make sure that multiple subscriptions get triggered.
+ it "should propagate events to all dependent resources" do
+ path = tmpfile("path")
+ file1 = tmpfile("file1")
+ file2 = tmpfile("file2")
+ file = Puppet::Type.type(:file).new(
+ :path => path,
+ :ensure => "file"
+ )
+ exec1 = Puppet::Type.type(:exec).new(
+ :path => ENV["PATH"],
+ :command => "touch %s" % file1,
+ :refreshonly => true,
+ :subscribe => Puppet::Resource.new(:file, path)
+ )
+ exec2 = Puppet::Type.type(:exec).new(
+ :path => ENV["PATH"],
+ :command => "touch %s" % file2,
+ :refreshonly => true,
+ :subscribe => Puppet::Resource.new(:file, path)
+ )
+
+ catalog = mk_catalog(file, exec1, exec2)
+ catalog.apply
+ FileTest.should be_exist(file1)
+ FileTest.should be_exist(file2)
+ end
+
+ it "should not let one failed refresh result in other refreshes failing" do
+ path = tmpfile("path")
+ newfile = tmpfile("file")
+ file = Puppet::Type.type(:file).new(
+ :path => path,
+ :ensure => "file"
+ )
+ exec1 = Puppet::Type.type(:exec).new(
+ :path => ENV["PATH"],
+ :command => "touch /this/cannot/possibly/exist",
+ :logoutput => true,
+ :refreshonly => true,
+ :subscribe => file,
+ :title => "one"
+ )
+ exec2 = Puppet::Type.type(:exec).new(
+ :path => ENV["PATH"],
+ :command => "touch %s" % newfile,
+ :logoutput => true,
+ :refreshonly => true,
+ :subscribe => [file, exec1],
+ :title => "two"
+ )
+
+ exec1.stubs(:err)
+
+ catalog = mk_catalog(file, exec1, exec2)
+ catalog.apply
+ FileTest.should be_exists(newfile)
+ end
+
+ it "should still trigger skipped resources" do
+ catalog = mk_catalog()
+ catalog.add_resource(*Puppet::Type.type(:schedule).mkdefaultschedules)
+
+ Puppet[:ignoreschedules] = false
+ file = Puppet::Type.type(:file).new(
+ :name => tmpfile("file"),
+ :ensure => "file",
+ :backup => false
+ )
+
+ fname = tmpfile("exec")
+ exec = Puppet::Type.type(:exec).new(
+ :name => "touch #{fname}",
+ :path => "/usr/bin:/bin",
+ :schedule => "monthly",
+ :subscribe => Puppet::Resource.new("file", file.name)
+ )
+
+ catalog.add_resource(file, exec)
+
+ # Run it once
+ catalog.apply
+ FileTest.should be_exists(fname)
+
+ exec.should_not be_scheduled
+
+ # Now remove it, so it can get created again
+ File.unlink(fname)
+
+ file[:content] = "some content"
+
+ catalog.apply
+ FileTest.should be_exists(fname)
+
+ # Now remove it, so it can get created again
+ File.unlink(fname)
+
+ # And tag our exec
+ exec.tag("testrun")
+
+ # And our file, so it runs
+ file.tag("norun")
+
+ Puppet[:tags] = "norun"
+
+ file[:content] = "totally different content"
+
+ catalog.apply
+ FileTest.should be_exists(fname)
+ end
+
+ it "should not attempt to evaluate resources with failed dependencies" do
+ exec = Puppet::Type.type(:exec).new(
+ :command => "/bin/mkdir /this/path/cannot/possibly/exit",
+ :title => "mkdir"
+ )
+
+ file1 = Puppet::Type.type(:file).new(
+ :title => "file1",
+ :path => tmpfile("file1"),
+ :require => exec,
+ :ensure => :file
+ )
+
+ file2 = Puppet::Type.type(:file).new(
+ :title => "file2",
+ :path => tmpfile("file2"),
+ :require => file1,
+ :ensure => :file
+ )
+
+ catalog = mk_catalog(exec, file1, file2)
+ catalog.apply
+
+ FileTest.should_not be_exists(file1[:path])
+ FileTest.should_not be_exists(file2[:path])
+ end
end
diff --git a/spec/unit/parser/ast/resource.rb b/spec/unit/parser/ast/resource.rb
index 391f4c7..ef65f4c 100755
--- a/spec/unit/parser/ast/resource.rb
+++ b/spec/unit/parser/ast/resource.rb
@@ -7,7 +7,7 @@ describe Puppet::Parser::AST::Resource do
before :each do
@title = stub_everything 'title'
- @compiler = stub_everything 'compiler'
+ @compiler = stub_everything 'compiler', :environment => Puppet::Node::Environment.new
@scope = Puppet::Parser::Scope.new(:compiler => @compiler)
@scope.stubs(:resource).returns(stub_everything)
@resource = ast::Resource.new(:title => @title, :type => "Resource", :params => ast::ASTArray.new(:children => []) )
@@ -99,4 +99,38 @@ describe Puppet::Parser::AST::Resource do
result[0].should be_virtual
result[0].should be_exported
end
+
+ # Related to #806, make sure resources always look up the full path to the resource.
+ describe "when generating qualified resources" do
+ before do
+ @scope = Puppet::Parser::Scope.new :compiler => Puppet::Parser::Compiler.new(Puppet::Node.new("mynode"))
+ @parser = Puppet::Parser::Parser.new(Puppet::Node::Environment.new)
+ @parser.newdefine "one"
+ @parser.newdefine "one::two"
+ @parser.newdefine "three"
+ @twoscope = @scope.newscope(:namespace => "one")
+ @twoscope.resource = @scope.resource
+ end
+
+ def resource(type, params = nil)
+ params ||= Puppet::Parser::AST::ASTArray.new(:children => [])
+ Puppet::Parser::AST::Resource.new(:type => type, :title => Puppet::Parser::AST::String.new(:value => "myresource"), :params => params)
+ end
+
+ it "should be able to generate resources with fully qualified type information" do
+ resource("two").evaluate(@twoscope)[0].type.should == "One::Two"
+ end
+
+ it "should be able to generate resources with unqualified type information" do
+ resource("one").evaluate(@twoscope)[0].type.should == "One"
+ end
+
+ it "should correctly generate resources that can look up builtin types" do
+ resource("file").evaluate(@twoscope)[0].type.should == "File"
+ end
+
+ it "should fail for resource types that do not exist" do
+ lambda { resource("nosuchtype").evaluate(@twoscope) }.should raise_error(Puppet::ParseError)
+ end
+ end
end
diff --git a/spec/unit/parser/collector.rb b/spec/unit/parser/collector.rb
index 9c2d722..78d47c6 100755
--- a/spec/unit/parser/collector.rb
+++ b/spec/unit/parser/collector.rb
@@ -174,7 +174,7 @@ describe Puppet::Parser::Collector, "when collecting virtual and catalog resourc
@collector.evaluate.should == [one]
end
- it "should create a resource with overriden parameters" do
+ it "should create a resource with overridden parameters" do
one = stub_everything 'one', :type => "Mytype", :virtual? => true, :title => "test"
param = stub 'param'
@compiler.stubs(:add_override)
@@ -182,7 +182,7 @@ describe Puppet::Parser::Collector, "when collecting virtual and catalog resourc
@compiler.expects(:resources).returns([one])
@collector.add_override(:params => param )
- Puppet::Parser::Resource.expects(:new).with { |h|
+ Puppet::Parser::Resource.expects(:new).with { |type, title, h|
h[:params] == param
}
@@ -214,7 +214,7 @@ describe Puppet::Parser::Collector, "when collecting virtual and catalog resourc
@compiler.expects(:resources).at_least(2).returns([one])
@collector.add_override(:params => param )
- Puppet::Parser::Resource.expects(:new).once.with { |h|
+ Puppet::Parser::Resource.expects(:new).once.with { |type, title, h|
h[:params] == param
}
@@ -375,7 +375,7 @@ describe Puppet::Parser::Collector, "when collecting exported resources" do
@compiler.stubs(:add_resource)
@collector.add_override(:params => param )
- Puppet::Parser::Resource.expects(:new).once.with { |h|
+ Puppet::Parser::Resource.expects(:new).once.with { |type, title, h|
h[:params] == param
}
diff --git a/spec/unit/parser/resource.rb b/spec/unit/parser/resource.rb
index 0c70c81..ee0c1e0 100755
--- a/spec/unit/parser/resource.rb
+++ b/spec/unit/parser/resource.rb
@@ -16,12 +16,8 @@ describe Puppet::Parser::Resource do
end
def mkresource(args = {})
- args[:source] ||= "source"
- args[:scope] ||= stub('scope', :source => mock('source'))
-
- {:source => "source", :scope => "scope"}.each do |param, value|
- args[param] ||= value
- end
+ args[:source] ||= @source
+ args[:scope] ||= @scope
params = args[:params] || {:one => "yay", :three => "rah"}
if args[:params] == :none
@@ -101,18 +97,18 @@ describe Puppet::Parser::Resource do
end
it "should be able to use the indexing operator to access parameters" do
- resource = Puppet::Parser::Resource.new("resource", "testing", :source => "source", :scope => "scope")
+ resource = Puppet::Parser::Resource.new("resource", "testing", :source => "source", :scope => @scope)
resource["foo"] = "bar"
resource["foo"].should == "bar"
end
it "should return the title when asked for a parameter named 'title'" do
- Puppet::Parser::Resource.new("resource", "testing", :source => "source", :scope => "scope")[:title].should == "testing"
+ Puppet::Parser::Resource.new("resource", "testing", :source => @source, :scope => @scope)[:title].should == "testing"
end
describe "when initializing" do
before do
- @arguments = {:scope => stub('scope', :source => mock('source'))}
+ @arguments = {:scope => @scope}
end
it "should fail unless #{name.to_s} is specified" do
@@ -132,17 +128,6 @@ describe Puppet::Parser::Resource do
end
end
- describe "when refering to a resource with name canonicalization" do
- before do
- @arguments = {:scope => stub('scope', :source => mock('source'))}
- end
-
- it "should canonicalize its own name" do
- res = Puppet::Parser::Resource.new("file", "/path/", @arguments)
- res.ref.should == "File[/path]"
- end
- end
-
describe "when evaluating" do
it "should evaluate the associated AST definition" do
definition = newdefine "mydefine"
@@ -294,7 +279,7 @@ describe Puppet::Parser::Resource do
describe "when being tagged" do
before do
@scope_resource = stub 'scope_resource', :tags => %w{srone srtwo}
- @scope = stub 'scope', :resource => @scope_resource
+ @scope.stubs(:resource).returns @scope_resource
@resource = Puppet::Parser::Resource.new("file", "yay", :scope => @scope, :source => mock('source'))
end
@@ -448,8 +433,7 @@ describe Puppet::Parser::Resource do
describe "when being converted to a resource" do
before do
- @source = stub 'scope', :name => "myscope"
- @parser_resource = mkresource :source => @source, :params => {:foo => "bar", :fee => "fum"}
+ @parser_resource = mkresource :scope => @scope, :params => {:foo => "bar", :fee => "fum"}
end
it "should create an instance of Puppet::Resource" do
@@ -537,7 +521,7 @@ describe Puppet::Parser::Resource do
describe "when validating" do
it "should check each parameter" do
- resource = Puppet::Parser::Resource.new :foo, "bar", :scope => stub("scope"), :source => stub("source")
+ resource = Puppet::Parser::Resource.new :foo, "bar", :scope => @scope, :source => stub("source")
resource[:one] = :two
resource[:three] = :four
resource.expects(:validate_parameter).with(:one)
@@ -546,7 +530,7 @@ describe Puppet::Parser::Resource do
end
it "should raise a parse error when there's a failure" do
- resource = Puppet::Parser::Resource.new :foo, "bar", :scope => stub("scope"), :source => stub("source")
+ resource = Puppet::Parser::Resource.new :foo, "bar", :scope => @scope, :source => stub("source")
resource[:one] = :two
resource.expects(:validate_parameter).with(:one).raises ArgumentError
lambda { resource.send(:validate) }.should raise_error(Puppet::ParseError)
@@ -556,7 +540,7 @@ describe Puppet::Parser::Resource do
describe "when setting parameters" do
before do
@source = newclass "foobar"
- @resource = Puppet::Parser::Resource.new :foo, "bar", :scope => stub("scope"), :source => @source
+ @resource = Puppet::Parser::Resource.new :foo, "bar", :scope => @scope, :source => @source
end
it "should accept Param instances and add them to the parameter list" do
diff --git a/spec/unit/resource.rb b/spec/unit/resource.rb
index 3af1716..c86ec58 100755
--- a/spec/unit/resource.rb
+++ b/spec/unit/resource.rb
@@ -160,6 +160,21 @@ describe Puppet::Resource do
resource.resource_type.should equal(type)
end
+ it "should use its namespaces to set its type name when looking up defined resource types" do
+ type = Puppet::Resource::Type.new(:definition, "foo::bar")
+ Puppet::Node::Environment.new.known_resource_types.add type
+ resource = Puppet::Resource.new("bar", "/my/file", :namespaces => ["foo"])
+ resource.type.should == "Foo::Bar"
+ end
+
+ it "should look up its resource type when set manually" do
+ type = Puppet::Resource::Type.new(:definition, "foo::bar")
+ Puppet::Node::Environment.new.known_resource_types.add type
+ resource = Puppet::Resource.new("foo", "/my/file", :namespaces => ["foo"])
+ resource.type = "bar"
+ resource.type.should == "Foo::Bar"
+ end
+
it "should use its namespaces when looking up host classes" do
resource = Puppet::Resource.new("class", "bar", :namespaces => ["foo"])
type = Puppet::Resource::Type.new(:hostclass, "foo::bar")
@@ -168,6 +183,13 @@ describe Puppet::Resource do
resource.resource_type.should equal(type)
end
+ it "should consider a class whose name is an empty string to be the main class" do
+ type = Puppet::Resource::Type.new(:hostclass, "")
+ Puppet::Node::Environment.new.known_resource_types.add type
+
+ resource = Puppet::Resource.new("class", "").type.should == :main
+ end
+
it "should return nil when looking up resource types that don't exist" do
Puppet::Resource.new("foobar", "bar").resource_type.should be_nil
end
@@ -217,6 +239,17 @@ describe Puppet::Resource do
Puppet::Resource.new("file", "/foo").should_not == Puppet::Resource.new("file", "/f")
end
+ describe "when refering to a resource with name canonicalization" do
+ before do
+ end
+
+ it "should canonicalize its own name" do
+ res = Puppet::Resource.new("file", "/path/")
+ res.title.should == "/path"
+ res.ref.should == "File[/path]"
+ end
+ end
+
describe "when managing parameters" do
before do
@resource = Puppet::Resource.new("file", "/my/file")
diff --git a/spec/unit/type/resources.rb b/spec/unit/type/resources.rb
index 480b6c0..3e65aec 100644
--- a/spec/unit/type/resources.rb
+++ b/spec/unit/type/resources.rb
@@ -52,6 +52,19 @@ describe resources do
@resources.generate.collect { |r| r.ref }.should_not include(@host1.ref)
end
+ it "should not include the skipped users" do
+ res = Puppet::Type.type(:resources).new :name => :user, :purge => true
+ res.catalog = Puppet::Resource::Catalog.new
+
+ users = [
+ Puppet::Type.type(:user).new(:name => "root")
+ ]
+ Puppet::Type.type(:user).expects(:instances).returns users
+ list = res.generate
+
+ names = list.collect { |r| r[:name] }
+ names.should_not be_include("root")
+ end
describe "when generating a purgeable resource" do
it "should be included in the generated resources" do
diff --git a/test/language/ast.rb b/test/language/ast.rb
index ed11bc1..916c34d 100755
--- a/test/language/ast.rb
+++ b/test/language/ast.rb
@@ -3,7 +3,6 @@
require File.dirname(__FILE__) + '/../lib/puppettest'
require 'puppettest'
-require 'puppet/parser/interpreter'
require 'puppet/parser/parser'
require 'puppettest/resourcetesting'
require 'puppettest/parsertesting'
@@ -57,7 +56,7 @@ class TestAST < Test::Unit::TestCase
ref = resourceoverride("file", "/yayness", "owner" => "blah", "group" => "boo")
end
- Puppet::Parser::Resource.expects(:new).with { |o| o.is_a?(Hash) }.returns(:override)
+ Puppet::Parser::Resource.expects(:new).with { |type, title, o| o.is_a?(Hash) }.returns(:override)
scope.compiler.expects(:add_override).with(:override)
ret = nil
assert_nothing_raised do
diff --git a/test/language/ast/resource.rb b/test/language/ast/resource.rb
deleted file mode 100755
index 4124655..0000000
--- a/test/language/ast/resource.rb
+++ /dev/null
@@ -1,58 +0,0 @@
-#!/usr/bin/env ruby
-#
-# Created by Luke A. Kanies on 2007-07-8.
-# Copyright (c) 2007. All rights reserved.
-
-require File.dirname(__FILE__) + '/../../lib/puppettest'
-
-require 'puppettest'
-require 'puppettest/parsertesting'
-
-class TestASTResource< Test::Unit::TestCase
- include PuppetTest
- include PuppetTest::ParserTesting
- AST = Puppet::Parser::AST
-
- def setup
- super
- @scope = mkscope
- @parser = @scope.compiler.parser
- end
-
- def newdef(type, title, params = nil)
- params ||= AST::ASTArray.new(:children => [])
- AST::Resource.new(:type => type, :title => AST::String.new(:value => title), :params => params)
- end
-
- # Related to #806, make sure resources always look up the full path to the resource.
- def test_scoped_types
- @parser.newdefine "one"
- @parser.newdefine "one::two"
- @parser.newdefine "three"
- twoscope = @scope.newscope(:namespace => "one")
- twoscope.resource = @scope.resource
- assert(twoscope.find_definition("two"), "Could not find 'two' definition")
- title = "title"
-
- # First try a qualified type
- assert_equal("One::Two", newdef("two", title).evaluate(twoscope)[0].type,
- "Defined type was not made fully qualified")
-
- # Then try a type that does not need to be qualified
- assert_equal("One", newdef("one", title).evaluate(twoscope)[0].type,
- "Unqualified defined type was not handled correctly")
-
- # Then an unqualified type from within the one namespace
- assert_equal("Three", newdef("three", title).evaluate(twoscope)[0].type,
- "Defined type was not made fully qualified")
-
- # Then a builtin type
- assert_equal("File", newdef("file", title).evaluate(twoscope)[0].type,
- "Builtin type was not handled correctly")
-
- # Now try a type that does not exist, which should throw an error.
- assert_raise(Puppet::ParseError, "Did not fail on a missing type in a resource reference") do
- newdef("nosuchtype", title).evaluate(twoscope)
- end
- end
-end
diff --git a/test/language/ast/resource_reference.rb b/test/language/ast/resource_reference.rb
index 325dd21..5abb0d6 100755
--- a/test/language/ast/resource_reference.rb
+++ b/test/language/ast/resource_reference.rb
@@ -20,7 +20,7 @@ class TestASTResourceReference < Test::Unit::TestCase
def setup
super
@scope = mkscope
- @parser = @scope.compiler.parser
+ @parser = Puppet::Parser::Parser.new(Puppet::Node::Environment.new)
end
# Related to #706, make sure resource references correctly translate to qualified types.
diff --git a/test/language/ast/variable.rb b/test/language/ast/variable.rb
index 49b1dbb..6a8b028 100755
--- a/test/language/ast/variable.rb
+++ b/test/language/ast/variable.rb
@@ -15,8 +15,7 @@ class TestVariable < Test::Unit::TestCase
def setup
super
- @interp = mkinterp
- @scope = mkscope :interp => @interp
+ @scope = mkscope
@name = "myvar"
@var = AST::Variable.new(:value => @name)
end
diff --git a/test/language/snippets.rb b/test/language/snippets.rb
index b0d98ae..1ef91be 100755
--- a/test/language/snippets.rb
+++ b/test/language/snippets.rb
@@ -74,10 +74,6 @@ class TestSnippets < Test::Unit::TestCase
end
def ast2scope(ast)
- interp = Puppet::Parser::Interpreter.new(
- :ast => ast,
- :client => client()
- )
scope = Puppet::Parser::Scope.new()
ast.evaluate(scope)
diff --git a/test/lib/puppettest.rb b/test/lib/puppettest.rb
index 786c370..32f57f3 100755
--- a/test/lib/puppettest.rb
+++ b/test/lib/puppettest.rb
@@ -226,6 +226,9 @@ module PuppetTest
Puppet[:ignoreschedules] = true
#@start = Time.now
+
+ #Facter.stubs(:value).returns "stubbed_value"
+ #Facter.stubs(:to_hash).returns({})
end
def tempfile
diff --git a/test/other/provider.rb b/test/other/provider.rb
index b0860f6..e746a33 100755
--- a/test/other/provider.rb
+++ b/test/other/provider.rb
@@ -33,21 +33,6 @@ class TestImpl < Test::Unit::TestCase
return provider
end
- # Just a quick run-through to see if the basics work
- def test_newprovider
- assert_nothing_raised do
- @provider.confine :operatingsystem => Facter["operatingsystem"].value
- @provider.defaultfor :operatingsystem => Facter["operatingsystem"].value
- end
-
- assert(@provider.suitable?, "Implementation was not considered suitable")
- assert(@provider.default?, "Implementation was not considered a default")
-
- assert_equal(@provider, @type.defaultprovider,
- "Did not correctly find default provider")
-
- end
-
def test_provider_default
nondef = nil
assert_nothing_raised {
diff --git a/test/other/report.rb b/test/other/report.rb
index 692ed54..147a0ea 100755
--- a/test/other/report.rb
+++ b/test/other/report.rb
@@ -32,7 +32,10 @@ class TestReports < Test::Unit::TestCase
config.retrieval_duration = 0.001
trans = config.apply
- return trans.generate_report
+ report = Puppet::Transaction::Report.new
+ trans.add_metrics_to_report(report)
+
+ return report
end
# Make sure we can use reports as log destinations.
@@ -224,10 +227,7 @@ class TestReports < Test::Unit::TestCase
def test_summary
report = mkreport
- summary = nil
- assert_nothing_raised("Could not create report summary") do
- summary = report.summary
- end
+ summary = report.summary
%w{Changes Total Resources}.each do |main|
assert(summary.include?(main), "Summary did not include info for %s" % main)
diff --git a/test/other/transactions.rb b/test/other/transactions.rb
index 32a7558..69602e6 100755
--- a/test/other/transactions.rb
+++ b/test/other/transactions.rb
@@ -118,369 +118,6 @@ class TestTransactions < Test::Unit::TestCase
assert_equal({inst.title => inst}, $prefetched, "evaluate did not call prefetch")
end
- def test_refreshes_generate_events
- path = tempfile()
- firstpath = tempfile()
- secondpath = tempfile()
- file = Puppet::Type.type(:file).new(:title => "file", :path => path, :content => "yayness")
- first = Puppet::Type.type(:exec).new(:title => "first",
- :command => "/bin/echo first > #{firstpath}",
- :subscribe => Puppet::Resource.new(:file, path),
- :refreshonly => true
- )
- second = Puppet::Type.type(:exec).new(:title => "second",
- :command => "/bin/echo second > #{secondpath}",
- :subscribe => Puppet::Resource.new(:exec, "first"),
- :refreshonly => true
- )
-
- assert_apply(file, first, second)
-
- assert(FileTest.exists?(secondpath), "Refresh did not generate an event")
- end
-
- unless %x{groups}.chomp.split(/ /).length > 1
- $stderr.puts "You must be a member of more than one group to test transactions"
- else
- def ingroup(gid)
- require 'etc'
- begin
- group = Etc.getgrgid(gid)
- rescue => detail
- puts "Could not retrieve info for group %s: %s" % [gid, detail]
- return nil
- end
-
- return @groups.include?(group.name)
- end
-
- def setup
- super
- @groups = %x{groups}.chomp.split(/ /)
- unless @groups.length > 1
- p @groups
- raise "You must be a member of more than one group to test this"
- end
- end
-
- def newfile(hash = {})
- tmpfile = tempfile()
- File.open(tmpfile, "w") { |f| f.puts rand(100) }
-
- # XXX now, because os x apparently somehow allows me to make a file
- # owned by a group i'm not a member of, i have to verify that
- # the file i just created is owned by one of my groups
- # grrr
- unless ingroup(File.stat(tmpfile).gid)
- Puppet.info "Somehow created file in non-member group %s; fixing" %
- File.stat(tmpfile).gid
-
- require 'etc'
- firstgr = @groups[0]
- unless firstgr.is_a?(Integer)
- str = Etc.getgrnam(firstgr)
- firstgr = str.gid
- end
- File.chown(nil, firstgr, tmpfile)
- end
-
- hash[:name] = tmpfile
- assert_nothing_raised() {
- return Puppet::Type.type(:file).new(hash)
- }
- end
-
- def newexec(file)
- assert_nothing_raised() {
- return Puppet::Type.type(:exec).new(
- :name => "touch %s" % file,
- :path => "/bin:/usr/bin:/sbin:/usr/sbin",
- :returns => 0
- )
- }
- end
-
- # modify a file and then roll the modifications back
- def test_filerollback
- transaction = nil
- file = newfile()
-
- properties = {}
- check = [:group,:mode]
- file[:check] = check
-
- assert_nothing_raised() {
- file.retrieve
- }
-
- assert_nothing_raised() {
- check.each { |property|
- value = file.property(property).retrieve
- assert(value)
- properties[property] = value
- }
- }
-
-
- component = mk_catalog("file",file)
- require 'etc'
- groupname = Etc.getgrgid(File.stat(file.name).gid).name
- assert_nothing_raised() {
- # Find a group that it's not set to
- group = @groups.find { |group| group != groupname }
- unless group
- raise "Could not find suitable group"
- end
- file[:group] = group
-
- file[:mode] = "755"
- }
- trans = assert_events([:file_changed, :file_changed], component)
- file.retrieve
-
- assert_rollback_events(trans, [:file_changed, :file_changed], "file")
-
- assert_nothing_raised() {
- file.retrieve
- }
- properties.each { |property,value|
- assert_equal(
- value, file.value(property), "File %s remained %s" % [property, file.value(property)]
- )
- }
- end
-
- # test that services are correctly restarted and that work is done
- # in the right order
- def test_refreshing
- transaction = nil
- file = newfile()
- execfile = File.join(tmpdir(), "exectestingness")
- exec = newexec(execfile)
- properties = {}
- check = [:group,:mode]
- file[:check] = check
- file[:group] = @groups[0]
-
- config = mk_catalog(file)
- config.apply
-
- @@tmpfiles << execfile
-
- # 'subscribe' expects an array of arrays
- exec[:subscribe] = Puppet::Resource.new(file.class.name,file.name)
- exec[:refreshonly] = true
-
- assert_nothing_raised() {
- file.retrieve
- exec.retrieve
- }
-
- check.each { |property|
- properties[property] = file.value(property)
- }
- assert_nothing_raised() {
- file[:mode] = "755"
- }
-
- # Make a new catalog so the resource relationships get
- # set up.
- config = mk_catalog(file, exec)
-
- trans = assert_events([:file_changed, :triggered], config)
-
- assert(FileTest.exists?(execfile), "Execfile does not exist")
- File.unlink(execfile)
- assert_nothing_raised() {
- file[:group] = @groups[1]
- }
-
- trans = assert_events([:file_changed, :triggered], config)
- assert(FileTest.exists?(execfile), "Execfile does not exist")
- end
-
- # Verify that one component requiring another causes the contained
- # resources in the requiring component to get refreshed.
- def test_refresh_across_two_components
- transaction = nil
- file = newfile()
- execfile = File.join(tmpdir(), "exectestingness2")
- @@tmpfiles << execfile
- exec = newexec(execfile)
- properties = {}
- check = [:group,:mode]
- file[:check] = check
- file[:group] = @groups[0]
- assert_apply(file)
-
- config = Puppet::Resource::Catalog.new
- fcomp = Puppet::Type.type(:component).new(:name => "file")
- config.add_resource fcomp
- config.add_resource file
- config.add_edge(fcomp, file)
-
- ecomp = Puppet::Type.type(:component).new(:name => "exec")
- config.add_resource ecomp
- config.add_resource exec
- config.add_edge(ecomp, exec)
-
- # 'subscribe' expects an array of arrays
- #component[:require] = [[file.class.name,file.name]]
- ecomp[:subscribe] = fcomp
- exec[:refreshonly] = true
-
- trans = assert_events([], config)
-
- assert_nothing_raised() {
- file[:group] = @groups[1]
- file[:mode] = "755"
- }
-
- trans = assert_events([:file_changed, :file_changed, :triggered], config)
- end
-
- # Make sure that multiple subscriptions get triggered.
- def test_multisubs
- path = tempfile()
- file1 = tempfile()
- file2 = tempfile()
- file = Puppet::Type.type(:file).new(
- :path => path,
- :ensure => "file"
- )
- exec1 = Puppet::Type.type(:exec).new(
- :path => ENV["PATH"],
- :command => "touch %s" % file1,
- :refreshonly => true,
- :subscribe => Puppet::Resource.new(:file, path)
- )
- exec2 = Puppet::Type.type(:exec).new(
- :path => ENV["PATH"],
- :command => "touch %s" % file2,
- :refreshonly => true,
- :subscribe => Puppet::Resource.new(:file, path)
- )
-
- assert_apply(file, exec1, exec2)
- assert(FileTest.exists?(file1), "File 1 did not get created")
- assert(FileTest.exists?(file2), "File 2 did not get created")
- end
-
- # Make sure that a failed trigger doesn't result in other events not
- # getting triggered.
- def test_failedrefreshes
- path = tempfile()
- newfile = tempfile()
- file = Puppet::Type.type(:file).new(
- :path => path,
- :ensure => "file"
- )
- exec1 = Puppet::Type.type(:exec).new(
- :path => ENV["PATH"],
- :command => "touch /this/cannot/possibly/exist",
- :logoutput => true,
- :refreshonly => true,
- :subscribe => file,
- :title => "one"
- )
- exec2 = Puppet::Type.type(:exec).new(
- :path => ENV["PATH"],
- :command => "touch %s" % newfile,
- :logoutput => true,
- :refreshonly => true,
- :subscribe => [file, exec1],
- :title => "two"
- )
-
- assert_apply(file, exec1, exec2)
- assert(FileTest.exists?(newfile), "Refresh file did not get created")
- end
-
- # Make sure that unscheduled and untagged objects still respond to events
- def test_unscheduled_and_untagged_response
- Puppet::Type.type(:schedule).mkdefaultschedules
- Puppet[:ignoreschedules] = false
- file = Puppet::Type.type(:file).new(
- :name => tempfile(),
- :ensure => "file",
- :backup => false
- )
-
- fname = tempfile()
- exec = Puppet::Type.type(:exec).new(
- :name => "touch %s" % fname,
- :path => "/usr/bin:/bin",
- :schedule => "monthly",
- :subscribe => Puppet::Resource.new("file", file.name)
- )
-
- config = mk_catalog(file, exec)
-
- # Run it once
- assert_apply(config)
- assert(FileTest.exists?(fname), "File did not get created")
-
- assert(!exec.scheduled?, "Exec is somehow scheduled")
-
- # Now remove it, so it can get created again
- File.unlink(fname)
-
- file[:content] = "some content"
-
- assert_events([:file_changed, :triggered], config)
-
- assert(FileTest.exists?(fname), "File did not get recreated")
-
- # Now remove it, so it can get created again
- File.unlink(fname)
-
- # And tag our exec
- exec.tag("testrun")
-
- # And our file, so it runs
- file.tag("norun")
-
- Puppet[:tags] = "norun"
-
- file[:content] = "totally different content"
-
- assert(! file.insync?(file.retrieve), "Uh, file is in sync?")
-
- assert_events([:file_changed, :triggered], config)
- assert(FileTest.exists?(fname), "File did not get recreated")
- end
-
- def test_failed_reqs_mean_no_run
- exec = Puppet::Type.type(:exec).new(
- :command => "/bin/mkdir /this/path/cannot/possibly/exit",
- :title => "mkdir"
- )
-
- file1 = Puppet::Type.type(:file).new(
- :title => "file1",
- :path => tempfile(),
- :require => exec,
- :ensure => :file
- )
-
- file2 = Puppet::Type.type(:file).new(
- :title => "file2",
- :path => tempfile(),
- :require => file1,
- :ensure => :file
- )
-
- config = mk_catalog(exec, file1, file2)
-
- assert_apply(config)
-
- assert(! FileTest.exists?(file1[:path]),
- "File got created even tho its dependency failed")
- assert(! FileTest.exists?(file2[:path]),
- "File got created even tho its deep dependency failed")
- end
- end
-
# We need to generate resources before we prefetch them, else generated
# resources that require prefetching don't work.
def test_generate_before_prefetch
@@ -787,13 +424,7 @@ class TestTransactions < Test::Unit::TestCase
def test_explicit_dependencies_beat_automatic
# Create a couple of different resource sets that have automatic relationships and make sure the manual relationships win
rels = {}
- # First users and groups
- group = Puppet::Type.type(:group).new(:name => nonrootgroup.name, :ensure => :present)
- user = Puppet::Type.type(:user).new(:name => nonrootuser.name, :ensure => :present, :gid => group.title)
-
# Now add the explicit relationship
- group[:require] = user
- rels[group] = user
# Now files
d = tempfile()
f = File.join(d, "file")
diff --git a/test/rails/rails.rb b/test/rails/rails.rb
index c3b48b9..7f4b366 100755
--- a/test/rails/rails.rb
+++ b/test/rails/rails.rb
@@ -4,7 +4,6 @@ require File.dirname(__FILE__) + '/../lib/puppettest'
require 'puppet'
require 'puppet/rails'
-require 'puppet/parser/interpreter'
require 'puppet/parser/parser'
require 'puppet/network/client'
require 'puppettest'
diff --git a/test/ral/type/host.rb b/test/ral/type/host.rb
index 537adc7..308e84b 100755
--- a/test/ral/type/host.rb
+++ b/test/ral/type/host.rb
@@ -108,17 +108,6 @@ class TestHost < Test::Unit::TestCase
# This was a hard bug to track down.
assert_instance_of(String, current_values[host.property(:ip)])
- host[:alias] = %w{madstop kirby yayness}
-
- assert_events([:host_changed], host)
-
- assert_nothing_raised {
- current_values = host.retrieve
- }
-
- assert_equal(%w{madstop kirby yayness},
- current_values[host.property(:alias)])
-
host[:ensure] = :absent
assert_events([:host_removed], host)
end
@@ -182,28 +171,4 @@ class TestHost < Test::Unit::TestCase
host[:name] = "y"
}
end
-
- def test_aliasisproperty
- assert_equal(:property, @hosttype.attrtype(:alias))
- end
-
- def test_multivalues
- host = mkhost
- assert_raise(Puppet::Error) {
- host[:alias] = "puppetmasterd yayness"
- }
- end
-
- def test_puppetalias
- host = mkhost()
- catalog = mk_catalog(host)
-
- assert_nothing_raised {
- host[:alias] = "testing"
- }
-
- same = catalog.resource(:host, "testing")
- assert(same, "Could not retrieve by alias")
- end
end
-
diff --git a/test/ral/type/resources.rb b/test/ral/type/resources.rb
index 8d9f092..adc75cb 100755
--- a/test/ral/type/resources.rb
+++ b/test/ral/type/resources.rb
@@ -67,6 +67,7 @@ class TestResources < Test::Unit::TestCase
assert_nothing_raised do
purger = @type.new :name => "purgetest", :noop => true, :loglevel => :warning
end
+ purger.catalog = Puppet::Resource::Catalog.new
assert(purger, "did not get purger manager")
add_purge_lister()
@@ -172,20 +173,5 @@ class TestResources < Test::Unit::TestCase
assert(res.check(@user.create(:name => high)), "high user %s failed check" % high)
end
end
-
- # The other half of #408.
- def test_check_is_called
- res = Puppet::Type.type(:resources).new :name => :user, :purge => true
-
- list = nil
- assert_nothing_raised { list = res.generate }
-
- assert(! list.empty?, "did not get any users")
-
- bad = list.find_all { |u|
- %w{root bin nobody}.include?(u[:name]) or (cv = u.retrieve and cv[u.property(:uid)] < 500)
- }
- assert(bad.empty?, "incorrectly passed users %s" % bad.collect { |u| u[:name]}.join(", "))
- end
end
diff --git a/test/ral/type/sshkey.rb b/test/ral/type/sshkey.rb
index 74dd812..b68c14b 100755
--- a/test/ral/type/sshkey.rb
+++ b/test/ral/type/sshkey.rb
@@ -98,47 +98,6 @@ class TestSSHKey < Test::Unit::TestCase
end
- def test_moddingkey
- key = mkkey()
-
- @catalog.apply
-
- key.retrieve
-
- aliases = %w{madstop kirby yayness}
- key[:alias] = aliases
-
- @catalog.apply
-
- aliases.each do |name|
- assert_equal(key.object_id, @catalog.resource(:sshkey, name).object_id, "alias %s was not set" % name)
- end
- end
-
- def test_aliasisproperty
- assert_equal(:property, @sshkeytype.attrtype(:alias))
- end
-
- def test_multivalues
- key = mkkey
- assert_raise(Puppet::Error) {
- key[:alias] = "puppetmasterd yayness"
- }
- end
-
- def test_puppetalias
- key = mkkey()
-
- assert_nothing_raised {
- key[:alias] = "testing"
- }
-
- key.finish
-
- same = @catalog.resource(:sshkey, "testing")
- assert(same, "Could not retrieve by alias")
- end
-
def test_removal
sshkey = mkkey()
assert_nothing_raised {
diff --git a/test/util/settings.rb b/test/util/settings.rb
index c9e3245..2ff0bff 100755
--- a/test/util/settings.rb
+++ b/test/util/settings.rb
@@ -78,10 +78,8 @@ class TestSettings < Test::Unit::TestCase
end
def mkconfig
- c = nil
- assert_nothing_raised {
- c = Puppet::Util::Settings.new
- }
+ c = Puppet::Util::Settings.new
+ c.setdefaults :main, :noop => [false, "foo"]
return c
end
@@ -303,6 +301,8 @@ yay = /a/path
end
def test_addargs_functional
+ @config = Puppet::Util::Settings.new
+
@config.setdefaults("testing",
:onboolean => [true, "An on bool"],
:string => ["a string", "A string arg"]
@@ -483,7 +483,7 @@ yay = /a/path
assert_nothing_raised {
config.setdefaults(:yayness, name => { :default => value, :desc => name.to_s})
}
- elem = config.element(name)
+ elem = config.setting(name)
assert_instance_of(type, elem,
"%s got created as wrong type" % value.inspect)
@@ -529,7 +529,7 @@ yay = /a/path
assert_nothing_raised do
config.setdefaults :test, :blocktest => {:default => "yay", :desc => "boo", :hook => proc { |value| testing = value }}
end
- elem = config.element(:blocktest)
+ elem = config.setting(:blocktest)
assert_nothing_raised do
assert_equal("yay", elem.value)
@@ -572,45 +572,6 @@ yay = /a/path
assert_equal("footest", testing)
end
- def test_no_modify_root
- config = mkconfig
- config.setdefaults(:yay,
- :mydir => {:default => tempfile(),
- :mode => 0644,
- :owner => "root",
- :group => "root",
- :desc => "yay"
- },
- :mkusers => [false, "yay"]
- )
-
- assert_nothing_raised do
- config.use(:yay)
- end
-
- # Now enable it so they'll be added
- config[:mkusers] = true
-
- comp = config.to_catalog
-
- comp.vertices.find_all { |r| r.class.name == :user }.each do |u|
- assert(u.name != "root", "Tried to manage root user")
- end
- comp.vertices.find_all { |r| r.class.name == :group }.each do |u|
- assert(u.name != "root", "Tried to manage root group")
- assert(u.name != "wheel", "Tried to manage wheel group")
- end
-
-# assert(yay, "Did not find yay component")
-# yay.each do |c|
-# puts @config.ref
-# end
-# assert(! yay.find { |o| o.class.name == :user and o.name == "root" },
-# "Found root user")
-# assert(! yay.find { |o| o.class.name == :group and o.name == "root" },
-# "Found root group")
- end
-
# #415
def test_remove_trailing_spaces
config = mkconfig()
@@ -666,15 +627,15 @@ yay = /a/path
end
# Test to make sure that we can set and get a short name
- def test_celement_short_name
- element = nil
- assert_nothing_raised("Could not create celement") do
- element = Setting.new :short => "n", :desc => "anything", :settings => Puppet::Util::Settings.new
+ def test_setting_short_name
+ setting= nil
+ assert_nothing_raised("Could not create setting") do
+ setting= Setting.new :short => "n", :desc => "anything", :settings => Puppet::Util::Settings.new
end
- assert_equal("n", element.short, "Short value is not retained")
+ assert_equal("n", setting.short, "Short value is not retained")
assert_raise(ArgumentError,"Allowed multicharactered short names.") do
- element = Setting.new :short => "no", :desc => "anything", :settings => Puppet::Util::Settings.new
+ setting= Setting.new :short => "no", :desc => "anything", :settings => Puppet::Util::Settings.new
end
end
--
1.6.1
So, to get nodes to show as Node[foo] and classes as
Class[Foo::Bar], but defined resources to show up as
Foo::Bar[baz], we have to do some silliness.
Signed-off-by: Luke Kanies <lu...@reductivelabs.com>
---
lib/puppet/resource.rb | 156 +++++++++++++++++-----
spec/unit/resource.rb | 214 +++++++++++++++++++------------
test/language/ast/resource_reference.rb | 77 -----------
3 files changed, 252 insertions(+), 195 deletions(-)
delete mode 100755 test/language/ast/resource_reference.rb
diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb
index 91a2610..fa6fea1 100644
--- a/lib/puppet/resource.rb
+++ b/lib/puppet/resource.rb
@@ -13,8 +13,7 @@ class Puppet::Resource
extend Puppet::Util::Pson
include Enumerable
attr_accessor :file, :line, :catalog, :exported, :virtual, :validate_parameters, :strict
- attr_reader :title, :namespaces
- attr_writer :relative_type
+ attr_reader :namespaces
ATTRIBUTES = [:file, :line, :exported]
@@ -158,6 +157,8 @@ class Puppet::Resource
extract_parameters(params)
end
+ resolve_type_and_title()
+
tag(self.type)
tag(self.title) if valid_tag?(self.title)
@@ -177,23 +178,38 @@ class Puppet::Resource
end
def title=(value)
- if klass = resource_type and klass.respond_to?(:canonicalize_ref)
- value = klass.canonicalize_ref(value)
- end
- @title = value
+ @unresolved_title = value
+ @title = nil
end
- # Canonize the type so we know it's always consistent.
- def relative_type
- munge_type_name(@relative_type)
+ def old_title
+ if type == "Class" and value == ""
+ @title = :main
+ return
+ end
+
+ if klass = resource_type
+ p klass
+ if type == "Class"
+ value = munge_type_name(resource_type.name)
+ end
+
+ if klass.respond_to?(:canonicalize_ref)
+ value = klass.canonicalize_ref(value)
+ end
+ elsif type == "Class"
+ value = munge_type_name(value)
+ end
+
+ @title = value
end
def resource_type
- case relative_type.to_s.downcase
- when "class"; find_hostclass
- when "node"; find_node
+ case type
+ when "Class"; find_hostclass(title)
+ when "Node"; find_node(title)
else
- find_builtin_resource_type || find_defined_resource_type
+ find_resource_type(type)
end
end
@@ -287,18 +303,26 @@ class Puppet::Resource
return result
end
- def type
- munge_type_name(if r = resource_type
- resource_type.name
- else
- relative_type
- end)
+ # We have to lazy-evaluate this.
+ def title=(value)
+ @title = nil
+ @unresolved_title = value
end
- # Only allow people to set the relative type,
- # so we force it to be looked up each time.
+ # We have to lazy-evaluate this.
def type=(value)
- @relative_type = value
+ @type = nil
+ @unresolved_type = value || "Class"
+ end
+
+ def title
+ resolve_type_and_title unless @title
+ @title
+ end
+
+ def type
+ resolve_type_and_title unless @type
+ @type
end
def valid_parameter?(name)
@@ -311,21 +335,25 @@ class Puppet::Resource
private
- def find_node
- known_resource_types.node(title)
+ def find_node(name)
+ known_resource_types.node(name)
end
- def find_hostclass
+ def find_hostclass(title)
name = title == :main ? "" : title
known_resource_types.find_hostclass(namespaces, name)
end
- def find_builtin_resource_type
- Puppet::Type.type(relative_type.to_s.downcase.to_sym)
+ def find_resource_type(type)
+ find_builtin_resource_type(type) || find_defined_resource_type(type)
+ end
+
+ def find_builtin_resource_type(type)
+ Puppet::Type.type(type.to_s.downcase.to_sym)
end
- def find_defined_resource_type
- known_resource_types.find_definition(namespaces, relative_type.to_s.downcase)
+ def find_defined_resource_type(type)
+ known_resource_types.find_definition(namespaces, type.to_s.downcase)
end
# Produce a canonical method name.
@@ -362,8 +390,6 @@ class Puppet::Resource
return bucket
end
- private
-
def extract_parameters(params)
params.each do |param, value|
validate_parameter(param) if strict?
@@ -380,12 +406,72 @@ class Puppet::Resource
end
def munge_type_name(value)
- return :main if value == ""
+ return :main if value == :main
+ return "Class" if value == "" or value.nil? or value.to_s.downcase == "component"
+
+ value.to_s.split("::").collect { |s| s.capitalize }.join("::")
+ end
+
+ # This is an annoyingly complicated method for resolving qualified
+ # types as necessary, and putting them in type or title attributes.
+ def resolve_type_and_title
+ if @unresolved_type
+ @type = resolve_type
+ @unresolved_type = nil
+ end
+ if @unresolved_title
+ @title = resolve_title
+ @unresolved_title = nil
+ end
+ end
+
+ def resolve_type
+ type = munge_type_name(@unresolved_type)
+
+ case type
+ when "Class", "Node";
+ return type
+ else
+ # Otherwise, some kind of builtin or defined resource type
+ return munge_type_name(if r = find_resource_type(type)
+ r.name
+ else
+ type
+ end)
+ end
+ end
+
+ # This method only works if resolve_type was called first
+ def resolve_title
+ case @type
+ when "Node"; return @unresolved_title
+ when "Class";
+ resolve_title_for_class(@unresolved_title)
+ else
+ resolve_title_for_resource(@unresolved_title)
+ end
+ end
+
+ def resolve_title_for_class(title)
+ if title == "" or title == :main
+ return :main
+ end
+
+ if klass = find_hostclass(title)
+ result = klass.name
+
+ if klass.respond_to?(:canonicalize_ref)
+ result = klass.canonicalize_ref(result)
+ end
+ end
+ return munge_type_name(result || title)
+ end
- if value.nil? or value.to_s.downcase == "component"
- "Class"
+ def resolve_title_for_resource(title)
+ if type = find_resource_type(@type) and type.respond_to?(:canonicalize_ref)
+ return type.canonicalize_ref(title)
else
- value.to_s.split("::").collect { |s| s.capitalize }.join("::")
+ return title
end
end
end
diff --git a/spec/unit/resource.rb b/spec/unit/resource.rb
index a4952c0..f516c59 100755
--- a/spec/unit/resource.rb
+++ b/spec/unit/resource.rb
@@ -48,7 +48,7 @@ describe Puppet::Resource do
it "should set its type to 'Class' and its title to the passed title if the passed type is :component and the title has no square brackets in it" do
ref = Puppet::Resource.new(:component, "foo")
ref.type.should == "Class"
- ref.title.should == "foo"
+ ref.title.should == "Foo"
end
it "should interpret the title as a reference and assign appropriately if the type is :component and the title contains square brackets" do
@@ -60,7 +60,7 @@ describe Puppet::Resource do
it "should set the type to 'Class' if it is nil and the title contains no square brackets" do
ref = Puppet::Resource.new(nil, "yay")
ref.type.should == "Class"
- ref.title.should == "yay"
+ ref.title.should == "Yay"
end
it "should interpret the title as a reference and assign appropriately if the type is nil and the title contains square brackets" do
@@ -113,108 +113,159 @@ describe Puppet::Resource do
end
it "should support specifying namespaces" do
- Puppet::Resource.new("file", "/my/file", :namespaces => [:foo]).namespaces.should == [:foo]
+ Puppet::Resource.new("file", "/my/file", :namespaces => ["foo"]).namespaces.should == ["foo"]
end
it "should convert namespaces to an array if not specified as one" do
- Puppet::Resource.new("file", "/my/file", :namespaces => :foo).namespaces.should == [:foo]
+ Puppet::Resource.new("file", "/my/file", :namespaces => "foo").namespaces.should == ["foo"]
end
it "should default to a single amespace of an empty string" do
Puppet::Resource.new("file", "/my/file").namespaces.should == [""]
end
- it "should be able to look up its resource type when the type is a builtin resource" do
- Puppet::Resource.new("file", "/my/file").resource_type.should equal(Puppet::Type.type(:file))
- end
+ describe "and munging its type and title" do
+ describe "when modeling a builtin resource" do
+ it "should be able to find the resource type" do
+ Puppet::Resource.new("file", "/my/file").resource_type.should equal(Puppet::Type.type(:file))
+ end
- it "should be able to look up its resource type via its environment when the type is a defined resource type" do
- resource = Puppet::Resource.new("foobar", "/my/file")
- type = Puppet::Resource::Type.new(:definition, "foobar")
- resource.environment.known_resource_types.add type
+ it "should set its type to the capitalized type name" do
+ Puppet::Resource.new("file", "/my/file").type.should == "File"
+ end
+ end
- resource.resource_type.should equal(type)
- end
+ describe "when modeling a defined resource" do
+ describe "that exists" do
+ before do
+ @type = Puppet::Resource::Type.new(:definition, "foo::bar")
+ Puppet::Node::Environment.new.known_resource_types.add @type
+ end
- it "should be able to look up its resource type via its environment when the type is a node" do
- resource = Puppet::Resource.new("node", "foobar")
- node = Puppet::Resource::Type.new(:node, "foobar")
- resource.environment.known_resource_types.add node
+ it "should set its type to the capitalized type name" do
+ Puppet::Resource.new("foo::bar", "/my/file").type.should == "Foo::Bar"
+ end
- resource.resource_type.should equal(node)
- end
+ it "should be able to find the resource type" do
+ Puppet::Resource.new("foo::bar", "/my/file").resource_type.should equal(@type)
+ end
- it "should be able to look up its resource type via its environment when the type is a class" do
- resource = Puppet::Resource.new("class", "foobar")
- klass = Puppet::Resource::Type.new(:hostclass, "foobar")
- resource.environment.known_resource_types.add klass
+ it "should set its title to the provided title" do
+ Puppet::Resource.new("foo::bar", "/my/file").title.should == "/my/file"
+ end
- resource.resource_type.should equal(klass)
- end
+ describe "and the resource is unqualified and models a qualified resource type" do
+ it "should set its type to the fully qualified resource type" do
+ Puppet::Resource.new("bar", "/my/file", :namespaces => %w{foo}).type.should == "Foo::Bar"
+ end
- it "should use its namespaces when looking up defined resource types" do
- resource = Puppet::Resource.new("bar", "/my/file", :namespaces => ["foo"])
- type = Puppet::Resource::Type.new(:definition, "foo::bar")
- resource.environment.known_resource_types.add type
+ it "should be able to find the resource type" do
+ Puppet::Resource.new("bar", "/my/file", :namespaces => %w{foo}).resource_type.should equal(@type)
+ end
+ end
+ end
- resource.resource_type.should equal(type)
- end
+ describe "that does not exist" do
+ it "should set its resource type to the capitalized resource type name" do
+ Puppet::Resource.new("foo::bar", "/my/file").type.should == "Foo::Bar"
+ end
+ end
+ end
- it "should use its namespaces to set its type name when looking up defined resource types" do
- type = Puppet::Resource::Type.new(:definition, "foo::bar")
- Puppet::Node::Environment.new.known_resource_types.add type
- resource = Puppet::Resource.new("bar", "/my/file", :namespaces => ["foo"])
- resource.type.should == "Foo::Bar"
- end
+ describe "when modeling a node" do
+ # Life's easier with nodes, because they can't be qualified.
+ it "should set its type to 'Node' and its title to the provided title" do
+ node = Puppet::Resource.new("node", "foo")
+ node.type.should == "Node"
+ node.title.should == "foo"
+ end
+ end
- it "should look up its resource type when set manually" do
- type = Puppet::Resource::Type.new(:definition, "foo::bar")
- Puppet::Node::Environment.new.known_resource_types.add type
- resource = Puppet::Resource.new("foo", "/my/file", :namespaces => ["foo"])
- resource.type = "bar"
- resource.type.should == "Foo::Bar"
- end
+ describe "when modeling a class" do
+ it "should set its type to 'Class'" do
+ Puppet::Resource.new("class", "foo").type.should == "Class"
+ end
- it "should use its namespaces when looking up host classes" do
- resource = Puppet::Resource.new("class", "bar", :namespaces => ["foo"])
- type = Puppet::Resource::Type.new(:hostclass, "foo::bar")
- resource.environment.known_resource_types.add type
+ describe "that exists" do
+ before do
+ @type = Puppet::Resource::Type.new(:hostclass, "foo::bar")
+ Puppet::Node::Environment.new.known_resource_types.add @type
+ end
+
+ it "should set its title to the capitalized, fully qualified resource type" do
+ Puppet::Resource.new("class", "foo::bar").title.should == "Foo::Bar"
+ end
+
+ it "should be able to find the resource type" do
+ Puppet::Resource.new("class", "foo::bar").resource_type.should equal(@type)
+ end
+
+ describe "and the resource is unqualified and models a qualified class" do
+ it "should set its title to the fully qualified resource type" do
+ Puppet::Resource.new("class", "bar", :namespaces => %w{foo}).title.should == "Foo::Bar"
+ end
+
+ it "should be able to find the resource type" do
+ Puppet::Resource.new("class", "bar", :namespaces => %w{foo}).resource_type.should equal(@type)
+ end
+
+ it "should set its type to 'Class'" do
+ Puppet::Resource.new("class", "bar", :namespaces => %w{foo}).type.should == "Class"
+ end
+ end
+ end
- resource.resource_type.should equal(type)
- end
+ describe "that does not exist" do
+ it "should set its type to 'Class' and its title to the capitalized provided name" do
+ klass = Puppet::Resource.new("class", "foo::bar")
+ klass.type.should == "Class"
+ klass.title.should == "Foo::Bar"
+ end
+ end
- it "should consider a class whose name is an empty string to be the main class" do
- type = Puppet::Resource::Type.new(:hostclass, "")
- Puppet::Node::Environment.new.known_resource_types.add type
+ describe "and its name is set to the empty string" do
+ it "should set its title to :main" do
+ Puppet::Resource.new("class", "").title.should == :main
+ end
+
+ describe "and a class exists whose name is the empty string" do # this was a bit tough to track down
+ it "should set its title to :main" do
+ @type = Puppet::Resource::Type.new(:hostclass, "")
+ Puppet::Node::Environment.new.known_resource_types.add @type
+
+ Puppet::Resource.new("class", "").title.should == :main
+ end
+ end
+ end
- resource = Puppet::Resource.new("class", "").type.should == :main
+ describe "and its name is set to :main" do
+ it "should set its title to :main" do
+ Puppet::Resource.new("class", :main).title.should == :main
+ end
+
+ describe "and a class exists whose name is the empty string" do # this was a bit tough to track down
+ it "should set its title to :main" do
+ @type = Puppet::Resource::Type.new(:hostclass, "")
+ Puppet::Node::Environment.new.known_resource_types.add @type
+
+ Puppet::Resource.new("class", :main).title.should == :main
+ end
+ end
+ end
+ end
end
it "should return nil when looking up resource types that don't exist" do
Puppet::Resource.new("foobar", "bar").resource_type.should be_nil
end
- it "should fail when an invalid parameter is used and parameter validation is enabled" do
- type = Puppet::Resource::Type.new(:definition, "foobar")
- Puppet::Node::Environment.new.known_resource_types.add type
- resource = Puppet::Resource.new("foobar", "/my/file", :validate_parameters => true)
- lambda { resource[:yay] = true }.should raise_error(ArgumentError)
- end
-
- it "should not fail when an invalid parameter is used and parameter validation is disabled" do
+ it "should not fail when an invalid parameter is used and strict mode is disabled" do
type = Puppet::Resource::Type.new(:definition, "foobar")
Puppet::Node::Environment.new.known_resource_types.add type
resource = Puppet::Resource.new("foobar", "/my/file")
resource[:yay] = true
end
- it "should not fail when a valid parameter is used and parameter validation is enabled" do
- type = Puppet::Resource::Type.new(:definition, "foobar", :arguments => {"yay" => nil})
- Puppet::Node::Environment.new.known_resource_types.add type
- resource = Puppet::Resource.new("foobar", "/my/file", :validate_parameters => true)
- resource[:yay] = true
- end
-
it "should be considered equivalent to another resource if their type and title match and no parameters are set" do
Puppet::Resource.new("file", "/f").should == Puppet::Resource.new("file", "/f")
end
@@ -239,10 +290,7 @@ describe Puppet::Resource do
Puppet::Resource.new("file", "/foo").should_not == Puppet::Resource.new("file", "/f")
end
- describe "when refering to a resource with name canonicalization" do
- before do
- end
-
+ describe "when referring to a resource with name canonicalization" do
it "should canonicalize its own name" do
res = Puppet::Resource.new("file", "/path/")
res.title.should == "/path"
diff --git a/test/language/ast/resource_reference.rb b/test/language/ast/resource_reference.rb
deleted file mode 100755
index 5abb0d6..0000000
--- a/test/language/ast/resource_reference.rb
+++ /dev/null
@@ -1,77 +0,0 @@
-#!/usr/bin/env ruby
-#
-# Created by Luke A. Kanies on 2007-07-8.
-# Copyright (c) 2007. All rights reserved.
-
-require File.dirname(__FILE__) + '/../../lib/puppettest'
-
-require 'puppettest'
-require 'puppettest/parsertesting'
-
-class TestASTResourceReference < Test::Unit::TestCase
- include PuppetTest
- include PuppetTest::ParserTesting
- AST = Puppet::Parser::AST
-
- def newref(type, title)
- AST::ResourceReference.new(:type => type, :title => AST::String.new(:value => title))
- end
-
- def setup
- super
- @scope = mkscope
- @parser = Puppet::Parser::Parser.new(Puppet::Node::Environment.new)
- end
-
- # Related to #706, make sure resource references correctly translate to qualified types.
- def test_scoped_references
- @parser.newdefine "one"
- @parser.newdefine "one::two"
- @parser.newdefine "three"
- twoscope = @scope.newscope(:namespace => "one")
- assert(twoscope.find_definition("two"), "Could not find 'two' definition")
- title = "title"
-
- # First try a qualified type
- assert_equal("One::Two", newref("two", title).evaluate(twoscope).type,
- "Defined type was not made fully qualified")
-
- # Then try a type that does not need to be qualified
- assert_equal("One", newref("one", title).evaluate(twoscope).type,
- "Unqualified defined type was not handled correctly")
-
- # Then an unqualified type from within the one namespace
- assert_equal("Three", newref("three", title).evaluate(twoscope).type,
- "Defined type was not made fully qualified")
-
- # Then a builtin type
- assert_equal("File", newref("file", title).evaluate(twoscope).type,
- "Builtin type was not handled correctly")
-
- # Now try a type that does not exist, which should throw an error.
- assert_raise(Puppet::ParseError, "Did not fail on a missing type in a resource reference") do
- newref("nosuchtype", title).evaluate(twoscope)
- end
-
- # Now run the same tests, but with the classes
- @parser.newclass "four"
- @parser.newclass "one::five"
-
- # First try an unqualified type
- assert_equal("four", newref("class", "four").evaluate(twoscope).title,
- "Unqualified class was not found")
-
- # Then a qualified class
- assert_equal("one::five", newref("class", "five").evaluate(twoscope).title,
- "Class was not made fully qualified")
-
- # Then try a type that does not need to be qualified
- assert_equal("four", newref("class", "four").evaluate(twoscope).title,
- "Unqualified class was not handled correctly")
-
- # Now try a type that does not exist, which should throw an error.
- assert_raise(Puppet::ParseError, "Did not fail on a missing type in a resource reference") do
- newref("class", "nosuchclass").evaluate(twoscope)
- end
- end
-end
--
1.6.1
diff --git a/lib/puppet/node/environment.rb b/lib/puppet/node/environment.rb
index 5d44833..c65f78b 100644
--- a/lib/puppet/node/environment.rb
+++ b/lib/puppet/node/environment.rb
@@ -7,6 +7,20 @@ end
# Model the environment that a node can operate in. This class just
# provides a simple wrapper for the functionality around environments.
class Puppet::Node::Environment
+ module Helper
+ def environment
+ Puppet::Node::Environment.new(@environment)
+ end
+
+ def environment=(env)
+ if env.is_a?(String) or env.is_a?(Symbol)
+ @environment = env
+ else
+ @environment = env.name
+ end
+ end
+ end
+
include Puppet::Util::Cacher
@seen = {}
diff --git a/spec/unit/node/environment.rb b/spec/unit/node/environment.rb
index 9d94216..459b24f 100755
--- a/spec/unit/node/environment.rb
+++ b/spec/unit/node/environment.rb
@@ -216,4 +216,28 @@ describe Puppet::Node::Environment do
end
end
end
+
+ describe Puppet::Node::Environment::Helper do
+ before do
+ @helper = Object.new
+ @helper.extend(Puppet::Node::Environment::Helper)
+ end
+
+ it "should be able to set and retrieve the environment" do
+ @helper.environment = :foo
+ @helper.environment.name.should == :foo
+ end
+
+ it "should accept an environment directly" do
+ env = Puppet::Node::Environment.new :foo
+ @helper.environment = env
+ @helper.environment.name.should == :foo
+ end
+
+ it "should accept an environment as a string" do
+ env = Puppet::Node::Environment.new "foo"
+ @helper.environment = env
+ @helper.environment.name.should == :foo
diff --git a/spec/unit/node/environment.rb b/spec/unit/node/environment.rb
index 459b24f..9536373 100755
--- a/spec/unit/node/environment.rb
+++ b/spec/unit/node/environment.rb
@@ -171,7 +171,7 @@ describe Puppet::Node::Environment do
describe ".modules" do
it "should return a module named for every directory in each module path" do
env = Puppet::Node::Environment.new("testing")
- env.expects(:modulepath).returns %w{/a /b}
+ env.stubs(:modulepath).returns %w{/a /b}
Dir.expects(:entries).with("/a").returns %w{foo bar}
Dir.expects(:entries).with("/b").returns %w{bee baz}
@@ -180,7 +180,7 @@ describe Puppet::Node::Environment do
it "should remove duplicates" do
env = Puppet::Node::Environment.new("testing")
- env.expects(:modulepath).returns %w{/a /b}
+ env.stubs(:modulepath).returns %w{/a /b}
Dir.expects(:entries).with("/a").returns %w{foo}
Dir.expects(:entries).with("/b").returns %w{foo}
@@ -189,7 +189,7 @@ describe Puppet::Node::Environment do
it "should ignore invalid modules" do
env = Puppet::Node::Environment.new("testing")
- env.expects(:modulepath).returns %w{/a}
+ env.stubs(:modulepath).returns %w{/a}
Dir.expects(:entries).with("/a").returns %w{foo bar}
Puppet::Module.expects(:new).with { |name, env| name == "foo" }.returns mock("foomod", :name => "foo")
@@ -200,7 +200,7 @@ describe Puppet::Node::Environment do
it "should create modules with the correct environment" do
env = Puppet::Node::Environment.new("testing")
- env.expects(:modulepath).returns %w{/a}
+ env.stubs(:modulepath).returns %w{/a}
Dir.expects(:entries).with("/a").returns %w{foo}
env.modules.each {|mod| mod.environment.should == env }
--
1.6.1
Signed-off-by: Luke Kanies <lu...@reductivelabs.com>
---
lib/puppet/parser/scope.rb | 15 +++------------
lib/puppet/resource/type_collection.rb | 27 +++++++++++++++++----------
spec/unit/resource/type_collection.rb | 11 +++++++++--
3 files changed, 29 insertions(+), 24 deletions(-)
diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb
index 2d99524..3e3e901 100644
--- a/lib/puppet/parser/scope.rb
+++ b/lib/puppet/parser/scope.rb
@@ -22,6 +22,7 @@ class Puppet::Parser::Scope
attr_accessor :base, :keyword, :nodescope
attr_accessor :top, :translated, :compiler
attr_writer :parent
+ attr_reader :namespaces
# A demeterific shortcut to the catalog.
def catalog
@@ -86,21 +87,11 @@ class Puppet::Parser::Scope
end
def find_hostclass(name)
- @namespaces.each do |namespace|
- if r = known_resource_types.find_hostclass(namespace, name)
- return r
- end
- end
- return nil
+ known_resource_types.find_hostclass(namespaces, name)
end
def find_definition(name)
- @namespaces.each do |namespace|
- if r = known_resource_types.find_definition(namespace, name)
- return r
- end
- end
- return nil
+ known_resource_types.find_definition(namespaces, name)
end
def findresource(string, name = nil)
diff --git a/lib/puppet/resource/type_collection.rb b/lib/puppet/resource/type_collection.rb
index 7ca95b1..a0bd2dd 100644
--- a/lib/puppet/resource/type_collection.rb
+++ b/lib/puppet/resource/type_collection.rb
@@ -75,24 +75,31 @@ class Puppet::Resource::TypeCollection
@definitions[munge_name(name)]
end
- def find(namespace, name, type)
+ def find(namespaces, name, type)
if r = find_fully_qualified(name, type)
return r
end
- ary = namespace.split("::")
+ namespaces = Array(namespaces)
- while ary.length > 0
- tmp_namespace = ary.join("::")
- if r = find_partially_qualified(tmp_namespace, name, type)
- return r
+ namespaces.each do |namespace|
+ ary = namespace.split("::")
+
+ while ary.length > 0
+ tmp_namespace = ary.join("::")
+ if r = find_partially_qualified(tmp_namespace, name, type)
+ return r
+ end
+
+ # Delete the second to last object, which reduces our namespace by one.
+ ary.pop
end
- # Delete the second to last object, which reduces our namespace by one.
- ary.pop
+ if result = send(type, name)
+ return result
+ end
end
-
- send(type, name)
+ nil
end
def find_node(name)
diff --git a/spec/unit/resource/type_collection.rb b/spec/unit/resource/type_collection.rb
index 2fc364d..3de5e50 100644
--- a/spec/unit/resource/type_collection.rb
+++ b/spec/unit/resource/type_collection.rb
@@ -127,14 +127,21 @@ describe Puppet::Resource::TypeCollection do
loader.find("namespace", "::foo::bar", :hostclass).should be_nil
end
- it "should return the partially qualified object if it exists in the provided namespace" do
+ it "should return the partially qualified object if it exists in a provided namespace" do
loader = Puppet::Resource::TypeCollection.new("env")
instance = Puppet::Resource::Type.new(:hostclass, "foo::bar::baz")
loader.add instance
loader.find("foo", "bar::baz", :hostclass).should equal(instance)
end
- it "should return the unqualified object if it exists in the provided namespace" do
+ it "should be able to find partially qualified objects in any of the provided namespaces" do
+ loader = Puppet::Resource::TypeCollection.new("env")
+ instance = Puppet::Resource::Type.new(:hostclass, "foo::bar::baz")
+ loader.add instance
+ loader.find(["nons", "foo", "otherns"], "bar::baz", :hostclass).should equal(instance)
+ end
+
+ it "should return the unqualified object if it exists in a provided namespace" do
loader = Puppet::Resource::TypeCollection.new("env")
instance = Puppet::Resource::Type.new(:hostclass, "foo::bar")
loader.add instance
--
1.6.1
Signed-off-by: Luke Kanies <lu...@reductivelabs.com>
---
lib/puppet/parser/ast/resource.rb | 3 +-
lib/puppet/parser/resource.rb | 10 +++-
lib/puppet/resource.rb | 18 +++++---
spec/unit/parser/ast/resource.rb | 82 +++++++++++++++----------------------
spec/unit/resource.rb | 14 ++++++
5 files changed, 68 insertions(+), 59 deletions(-)
diff --git a/lib/puppet/parser/ast/resource.rb b/lib/puppet/parser/ast/resource.rb
index 5da40b3..c82e0b5 100644
--- a/lib/puppet/parser/ast/resource.rb
+++ b/lib/puppet/parser/ast/resource.rb
@@ -44,7 +44,8 @@ class Resource < AST::ResourceReference
:exported => self.exported,
:virtual => virt,
:source => scope.source,
- :scope => scope
+ :scope => scope,
+ :strict => true
)
# And then store the resource in the compiler.
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb
index 3f6d73d..2d71079 100644
--- a/lib/puppet/parser/resource.rb
+++ b/lib/puppet/parser/resource.rb
@@ -110,9 +110,6 @@ class Puppet::Parser::Resource < Puppet::Resource
def initialize(type, title, options)
@scope = options[:scope]
- self.relative_type = type
- self.title = title
-
@params = {}
# Define all of the parameters
if params = options[:params]
@@ -136,6 +133,13 @@ class Puppet::Parser::Resource < Puppet::Resource
@source ||= scope.source
+ self.relative_type = type
+ self.title = title
+
+ if strict? and ! resource_type
+ raise ArgumentError, "Invalid resource type #{type}"
+ end
+
tag(self.type)
tag(self.title) if valid_tag?(self.title.to_s)
end
diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb
index b1bd944..df808e1 100644
--- a/lib/puppet/resource.rb
+++ b/lib/puppet/resource.rb
@@ -12,7 +12,7 @@ class Puppet::Resource
extend Puppet::Util::Pson
include Enumerable
- attr_accessor :file, :line, :catalog, :exported, :virtual, :validate_parameters
+ attr_accessor :file, :line, :catalog, :exported, :virtual, :validate_parameters, :strict
attr_reader :title, :namespaces
attr_writer :relative_type
@@ -130,7 +130,7 @@ class Puppet::Resource
end
end
- %w{exported virtual}.each do |m|
+ %w{exported virtual strict}.each do |m|
define_method(m+"?") do
self.send(m)
end
@@ -141,10 +141,7 @@ class Puppet::Resource
@parameters = {}
@namespaces = [""]
- (attributes[:parameters] || {}).each do |param, value|
- self[param] = value
- end
-
+ # Set things like namespaces and strictness first.
attributes.each do |attr, value|
next if attr == :parameters
send(attr.to_s + "=", value)
@@ -157,8 +154,17 @@ class Puppet::Resource
self.type = tmp_type
self.title = tmp_title
+ (attributes[:parameters] || {}).each do |param, value|
+ validate_parameter(param) if strict?
+ self[param] = value
+ end
+
tag(self.type)
tag(self.title) if valid_tag?(self.title)
+
+ if strict? and ! resource_type
+ raise ArgumentError, "Invalid resource type #{type}"
+ end
end
def ref
diff --git a/spec/unit/parser/ast/resource.rb b/spec/unit/parser/ast/resource.rb
index ef65f4c..40074c7 100755
--- a/spec/unit/parser/ast/resource.rb
+++ b/spec/unit/parser/ast/resource.rb
@@ -6,11 +6,11 @@ describe Puppet::Parser::AST::Resource do
ast = Puppet::Parser::AST
before :each do
- @title = stub_everything 'title'
- @compiler = stub_everything 'compiler', :environment => Puppet::Node::Environment.new
+ @title = Puppet::Parser::AST::String.new(:value => "mytitle")
+ @compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("mynode"))
@scope = Puppet::Parser::Scope.new(:compiler => @compiler)
@scope.stubs(:resource).returns(stub_everything)
- @resource = ast::Resource.new(:title => @title, :type => "Resource", :params => ast::ASTArray.new(:children => []) )
+ @resource = ast::Resource.new(:title => @title, :type => "file", :params => ast::ASTArray.new(:children => []) )
@resource.stubs(:qualified_type).returns("Resource")
end
@@ -23,73 +23,57 @@ describe Puppet::Parser::AST::Resource do
end
it "should evaluate its title" do
-
- @title.expects(:safeevaluate).with(@scope)
-
- @resource.evaluate(@scope)
+ @resource.evaluate(@scope)[0].title.should == "mytitle"
end
it "should flatten the titles array" do
- titles = stub 'titles'
- title_array = stub 'title_array', :is_a? => true
-
- titles.stubs(:safeevaluate).with(@scope).returns(title_array)
+ titles = []
+ %w{one two}.each do |title|
+ titles << Puppet::Parser::AST::String.new(:value => title)
+ end
- title_array.expects(:flatten).returns([])
+ array = Puppet::Parser::AST::ASTArray.new(:children => titles)
- @resource.title = titles
- @resource.evaluate(@scope)
+ @resource.title = array
+ result = @resource.evaluate(@scope).collect { |r| r.title }
+ result.should be_include("one")
+ result.should be_include("two")
end
- it "should create one resource objects per title" do
- titles = stub 'titles'
- title_array = stub 'title_array', :is_a? => true
+ it "should create and return one resource objects per title" do
+ titles = []
+ %w{one two}.each do |title|
+ titles << Puppet::Parser::AST::String.new(:value => title)
+ end
- title_array.stubs(:flatten).returns([@title])
- titles.stubs(:safeevaluate).with(@scope).returns(title_array)
+ array = Puppet::Parser::AST::ASTArray.new(:children => titles)
- @resource.title = titles
- result = @resource.evaluate(@scope)
- result[0].should be_instance_of(Puppet::Parser::Resource)
- result[0].title.should == @title
+ @resource.title = array
+ result = @resource.evaluate(@scope).collect { |r| r.title }
+ result.should be_include("one")
+ result.should be_include("two")
end
it "should handover resources to the compiler" do
- resource = stub 'resource'
- titles = stub 'titles'
- title_array = stub 'title_array', :is_a? => true
-
- title_array.stubs(:flatten).returns([@title])
- titles.stubs(:safeevaluate).with(@scope).returns(title_array)
- Puppet::Parser::Resource.stubs(:new).returns(resource)
-
- @compiler.expects(:add_resource).with(@scope, resource)
-
- @resource.title = titles
- @resource.evaluate(@scope)
- end
-
- it "should return the newly created resources" do
- resource = stub 'resource'
- titles = stub 'titles'
- title_array = stub 'title_array', :is_a? => true
+ titles = []
+ %w{one two}.each do |title|
+ titles << Puppet::Parser::AST::String.new(:value => title)
+ end
- title_array.stubs(:flatten).returns([@title])
- titles.stubs(:safeevaluate).with(@scope).returns(title_array)
+ array = Puppet::Parser::AST::ASTArray.new(:children => titles)
- @compiler.stubs(:add_resource)
+ @resource.title = array
+ result = @resource.evaluate(@scope)
- @resource.title = titles
- @resource.evaluate(@scope)[0].should be_instance_of(Puppet::Parser::Resource)
+ result.each do |res|
+ @compiler.catalog.resource(res.ref).should be_instance_of(Puppet::Parser::Resource)
+ end
end
-
it "should generate virtual resources if it is virtual" do
@resource.virtual = true
result = @resource.evaluate(@scope)
result[0].should be_virtual
-
- @resource.evaluate(@scope)
end
it "should generate virtual and exported resources if it is exported" do
diff --git a/spec/unit/resource.rb b/spec/unit/resource.rb
index c86ec58..a4952c0 100755
--- a/spec/unit/resource.rb
+++ b/spec/unit/resource.rb
@@ -250,6 +250,20 @@ describe Puppet::Resource do
end
end
+ describe "when running in strict mode" do
+ it "should be strict" do
+ Puppet::Resource.new("file", "/path", :strict => true).should be_strict
+ end
+
+ it "should fail if invalid parameters are used" do
+ lambda { Puppet::Resource.new("file", "/path", :strict => true, :parameters => {:nosuchparam => "bar"}) }.should raise_error
+ end
+
+ it "should fail if the resource type cannot be resolved" do
+ lambda { Puppet::Resource.new("nosuchtype", "/path", :strict => true) }.should raise_error
+ end
+ end
+
describe "when managing parameters" do
before do
@resource = Puppet::Resource.new("file", "/my/file")
--
1.6.1
diff --git a/spec/lib/puppet_spec/files.rb b/spec/lib/puppet_spec/files.rb
index 542ad6e..aad3740 100644
--- a/spec/lib/puppet_spec/files.rb
+++ b/spec/lib/puppet_spec/files.rb
@@ -1,9 +1,19 @@
+require 'fileutils'
+
# A support module for testing files.
module PuppetSpec::Files
def tmpfile(name)
source = Tempfile.new(name)
path = source.path
source.close!
+ $tmpfiles ||= []
+ $tmpfiles << path
path
end
+
+ def tmpdir(name)
+ file = tmpfile(name)
+ FileUtils.mkdir_p(file)
+ file
+ end
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 0a603cd..e3dd6b9 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -39,6 +39,20 @@ Spec::Runner.configure do |config|
config.prepend_after :each do
Puppet.settings.clear
Puppet::Node::Environment.clear
+
+ if defined?($tmpfiles)
+ $tmpfiles.each do |file|
+ unless file.include?("/tmp") or file.include?("/var/folders")
+ puts "Not deleting tmpfile #{file} outside of /tmp or /var/folders"
+ next
+ end
+ if FileTest.exist?(file)
+ system("chmod -R 755 #{file}")
+ system("rm -rf #{file}")
+ end
+ end
+ $tmpfiles.clear
+ end
end
end
diff --git a/test/executables/puppetmodule.rb b/test/executables/puppetmodule.rb
deleted file mode 100755
index ce28796..0000000
--- a/test/executables/puppetmodule.rb
+++ /dev/null
@@ -1,55 +0,0 @@
-#!/usr/bin/env ruby
-
-require File.dirname(__FILE__) + '/../lib/puppettest'
-
-require 'puppettest'
-
-class TestPuppetModule < Test::Unit::TestCase
- include PuppetTest::ExeTest
-
-
- def setup
- super
- @module = File.join(basedir, "ext", "module_puppet")
- end
-
- def test_existence
- assert(FileTest.exists?(@module), "Module does not exist")
- end
-
- def test_execution
- file = tempfile()
-
- createdfile = tempfile()
-
- File.open(file, "w") { |f|
- f.puts "class yaytest { file { \"#{createdfile}\": ensure => file } }"
- }
-
- output = nil
- cmd = @module
- cmd += " --verbose"
- #cmd += " --fqdn %s" % fqdn
- cmd += " --confdir %s" % Puppet[:confdir]
- cmd += " --vardir %s" % Puppet[:vardir]
- if Puppet[:debug]
- cmd += " --logdest %s" % "console"
- cmd += " --debug"
- cmd += " --trace"
- else
- cmd += " --logdest %s" % "/dev/null"
- end
-
- ENV["CFALLCLASSES"] = "yaytest:all"
- libsetup
-
- out = nil
- assert_nothing_raised {
- out = %x{#{cmd + " " + file} 2>&1}
- }
- assert($? == 0, "Puppet module exited with code %s: %s" % [$?.to_i, out])
-
- assert(FileTest.exists?(createdfile), "Failed to create config'ed file")
diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb
index a05d85b..828b1b3 100644
--- a/lib/puppet/util/settings.rb
+++ b/lib/puppet/util/settings.rb
@@ -1,8 +1,6 @@
require 'puppet'
require 'sync'
-require 'puppet/transportable'
require 'getoptlong'
-
require 'puppet/external/event-loop'
require 'puppet/util/cacher'
require 'puppet/util/loadedfile'
@@ -568,8 +566,6 @@ class Puppet::Util::Settings
end
# Convert the settings we manage into a catalog full of resources that model those settings.
- # We currently have to go through Trans{Object,Bucket} instances,
- # because this hasn't been ported yet.
def to_catalog(*sections)
sections = nil if sections.empty?
--
1.6.1
This is possible because resource types defined
in the language are visible outside of the parser,
via the environment.
This will enable lots of code removal and simplication.
Signed-off-by: Luke Kanies <lu...@reductivelabs.com>
---
lib/puppet/parser/resource.rb | 2 +-
lib/puppet/provider/ldap.rb | 2 +-
lib/puppet/provider/nameservice.rb | 2 +-
lib/puppet/resource.rb | 56 +++++++++++++++++---
lib/puppet/resource/type.rb | 4 +-
lib/puppet/transportable.rb | 2 +-
lib/puppet/type.rb | 5 ++
lib/puppet/type/component.rb | 4 +-
spec/unit/provider/ldap.rb | 6 +-
spec/unit/resource.rb | 102 ++++++++++++++++++++++++++++++++++--
spec/unit/resource/type.rb | 18 +++---
spec/unit/type.rb | 12 ++++
test/language/resource.rb | 8 ++--
test/lib/puppettest/fakes.rb | 2 +-
14 files changed, 187 insertions(+), 38 deletions(-)
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb
index 63d028c..428b9df 100644
--- a/lib/puppet/parser/resource.rb
+++ b/lib/puppet/parser/resource.rb
@@ -396,7 +396,7 @@ class Puppet::Parser::Resource
# Now make sure it's a valid argument to our class. These checks
# are organized in order of commonhood -- most types, it's a valid
# argument and paramcheck is enabled.
- if @ref.typeclass.validattr?(param)
+ if @ref.typeclass.valid_parameter?(param)
true
elsif %w{name title}.include?(param) # always allow these
true
diff --git a/lib/puppet/provider/ldap.rb b/lib/puppet/provider/ldap.rb
index be66838..38668e5 100644
--- a/lib/puppet/provider/ldap.rb
+++ b/lib/puppet/provider/ldap.rb
@@ -78,7 +78,7 @@ class Puppet::Provider::Ldap < Puppet::Provider
param, values = ary
# Skip any attributes we don't manage.
- next result unless self.class.resource_type.validattr?(param)
+ next result unless self.class.resource_type.valid_parameter?(param)
paramclass = self.class.resource_type.attrclass(param)
diff --git a/lib/puppet/provider/nameservice.rb b/lib/puppet/provider/nameservice.rb
index cc517ee..57441dd 100644
--- a/lib/puppet/provider/nameservice.rb
+++ b/lib/puppet/provider/nameservice.rb
@@ -44,7 +44,7 @@ class Puppet::Provider::NameService < Puppet::Provider
end
def options(name, hash)
- unless resource_type.validattr?(name)
+ unless resource_type.valid_parameter?(name)
raise Puppet::DevError, "%s is not a valid attribute for %s" %
[name, resource_type.name]
end
diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb
index ab03bfd..35676ba 100644
--- a/lib/puppet/resource.rb
+++ b/lib/puppet/resource.rb
@@ -1,16 +1,20 @@
require 'puppet'
require 'puppet/util/tagging'
-require 'puppet/resource/reference'
require 'puppet/util/pson'
# The simplest resource class. Eventually it will function as the
# base class for all resource-like behaviour.
class Puppet::Resource
+ require 'puppet/resource/reference'
include Puppet::Util::Tagging
+
+ require 'puppet/resource/type_collection_helper'
+ include Puppet::Resource::TypeCollectionHelper
+
extend Puppet::Util::Pson
include Enumerable
- attr_accessor :file, :line, :catalog, :exported, :virtual
- attr_writer :type, :title
+ attr_accessor :file, :line, :catalog, :exported, :virtual, :namespace, :validate_parameters
+ attr_writer :type, :title, :environment
ATTRIBUTES = [:file, :line, :exported]
@@ -77,6 +81,7 @@ class Puppet::Resource
# Set a given parameter. Converts all passed names
# to lower-case symbols.
def []=(param, value)
+ validate_parameter(param) if validate_parameters
@parameters[parameter_name(param)] = value
end
@@ -109,7 +114,13 @@ class Puppet::Resource
# Create our resource.
def initialize(type, title, attributes = {})
+ # Doing this, instead of including it in the class,
+ # is the only way I could get the load order to work
+ # here.
+ extend Puppet::Node::Environment::Helper
+
@parameters = {}
+ @namespace = ""
(attributes[:parameters] || {}).each do |param, value|
self[param] = value
@@ -131,6 +142,15 @@ class Puppet::Resource
@reference.to_s
end
+ def resource_type
+ case type.to_s.downcase
+ when "class"; find_hostclass
+ when "node"; find_node
+ else
+ find_builtin_resource_type || find_defined_resource_type
+ end
+ end
+
# Get our title information from the reference, since it will canonize it for us.
def title
@reference.title
@@ -227,8 +247,33 @@ class Puppet::Resource
return result
end
+ def valid_parameter?(name)
+ resource_type.valid_parameter?(name)
+ end
+
+ def validate_parameter(name)
+ raise ArgumentError, "Invalid parameter #{name}" unless valid_parameter?(name)
+ end
+
private
+ def find_node
+ known_resource_types.node(title)
+ end
+
+ def find_hostclass
+ name = title == :main ? "" : title
+ known_resource_types.find_hostclass(namespace, name)
+ end
+
+ def find_builtin_resource_type
+ Puppet::Type.type(type.to_s.downcase.to_sym)
+ end
+
+ def find_defined_resource_type
+ known_resource_types.find_definition(namespace, type.to_s.downcase)
+ end
+
# Produce a canonical method name.
def parameter_name(param)
param = param.to_s.downcase.to_sym
@@ -248,11 +293,6 @@ class Puppet::Resource
end
end
- # Retrieve the resource type.
- def resource_type
- Puppet::Type.type(type)
- end
-
# Create an old-style TransBucket instance, for non-builtin resource types.
def to_transbucket
bucket = Puppet::TransBucket.new([])
diff --git a/lib/puppet/resource/type.rb b/lib/puppet/resource/type.rb
index f5e0eeb..cadd034 100644
--- a/lib/puppet/resource/type.rb
+++ b/lib/puppet/resource/type.rb
@@ -145,7 +145,7 @@ class Puppet::Resource::Type
set = {}
resource.to_hash.each do |param, value|
param = param.to_sym
- fail Puppet::ParseError, "#{resource.ref} does not accept attribute #{param}" unless validattr?(param)
+ fail Puppet::ParseError, "#{resource.ref} does not accept attribute #{param}" unless valid_parameter?(param)
exceptwrap { scope.setvar(param.to_s, value) }
@@ -174,7 +174,7 @@ class Puppet::Resource::Type
end
# Check whether a given argument is valid.
- def validattr?(param)
+ def valid_parameter?(param)
param = param.to_s
return true if param == "name"
diff --git a/lib/puppet/transportable.rb b/lib/puppet/transportable.rb
index 68977dc..1970d9f 100644
--- a/lib/puppet/transportable.rb
+++ b/lib/puppet/transportable.rb
@@ -49,7 +49,7 @@ module Puppet
def to_component
trans = TransObject.new(ref, :component)
@params.each { |param,value|
- next unless Puppet::Type::Component.validattr?(param)
+ next unless Puppet::Type::Component.valid_parameter?(param)
Puppet.debug "Defining %s on %s" % [param, ref]
trans[param] = value
}
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index 2f7b57a..f2b1d5c 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -388,6 +388,11 @@ class Type
end
end
+ # This is a forward-compatibility method - it's the validity interface we'll use in Puppet::Resource.
+ def self.valid_parameter?(name)
+ validattr?(name)
+ end
+
# Return either the attribute alias or the attribute.
def attr_alias(name)
name = symbolize(name)
diff --git a/lib/puppet/type/component.rb b/lib/puppet/type/component.rb
index 5fed176..bf9007a 100644
--- a/lib/puppet/type/component.rb
+++ b/lib/puppet/type/component.rb
@@ -14,14 +14,14 @@ Puppet::Type.newtype(:component) do
# Override how parameters are handled so that we support the extra
# parameters that are used with defined resource types.
def [](param)
- return super if self.class.validattr?(param)
+ return super if self.class.valid_parameter?(param)
@extra_parameters[param.to_sym]
end
# Override how parameters are handled so that we support the extra
# parameters that are used with defined resource types.
def []=(param, value)
- return super if self.class.validattr?(param)
+ return super if self.class.valid_parameter?(param)
@extra_parameters[param.to_sym] = value
end
diff --git a/spec/unit/provider/ldap.rb b/spec/unit/provider/ldap.rb
index fd5d1bd..6c58208 100755
--- a/spec/unit/provider/ldap.rb
+++ b/spec/unit/provider/ldap.rb
@@ -131,7 +131,7 @@ describe Puppet::Provider::Ldap do
@property_class = stub 'property_class', :array_matching => :all, :superclass => Puppet::Property
@resource_class.stubs(:attrclass).with(:one).returns(@property_class)
- @resource_class.stubs(:validattr?).returns true
+ @resource_class.stubs(:valid_parameter?).returns true
end
it "should store a copy of the hash as its ldap_properties" do
@@ -161,7 +161,7 @@ describe Puppet::Provider::Ldap do
end
it "should discard any properties not valid in the resource class" do
- @resource_class.expects(:validattr?).with(:a).returns false
+ @resource_class.expects(:valid_parameter?).with(:a).returns false
@property_class.stubs(:array_matching).returns :all
instance = @class.new(:one => %w{two three}, :a => %w{b})
@@ -177,7 +177,7 @@ describe Puppet::Provider::Ldap do
@instance = @class.new
@property_class = stub 'property_class', :array_matching => :all, :superclass => Puppet::Property
- @resource_class = stub 'resource_class', :attrclass => @property_class, :validattr? => true, :validproperties => [:one, :two]
+ @resource_class = stub 'resource_class', :attrclass => @property_class, :valid_parameter? => true, :validproperties => [:one, :two]
@class.stubs(:resource_type).returns @resource_class
end
diff --git a/spec/unit/resource.rb b/spec/unit/resource.rb
index 32b0017..df632e1 100755
--- a/spec/unit/resource.rb
+++ b/spec/unit/resource.rb
@@ -90,20 +90,111 @@ describe Puppet::Resource do
resource.should be_exported
end
- it "should support an environment attribute"
+ it "should support an environment attribute" do
+ Puppet::Resource.new("file", "/my/file", :environment => :foo).environment.name.should == :foo
+ end
+
+ it "should support a namespace attribute" do
+ Puppet::Resource.new("file", "/my/file", :namespace => :foo).namespace.should == :foo
+ end
+
+ it "should default to a namespace of an empty string" do
+ Puppet::Resource.new("file", "/my/file").namespace.should == ""
+ end
+
+ it "should be able to look up its resource type when the type is a builtin resource" do
+ Puppet::Resource.new("file", "/my/file").resource_type.should equal(Puppet::Type.type(:file))
+ end
+
+ it "should be able to look up its resource type via its environment when the type is a defined resource type" do
+ resource = Puppet::Resource.new("foobar", "/my/file")
+ type = Puppet::Resource::Type.new(:definition, "foobar")
+ resource.environment.known_resource_types.add type
+
+ resource.resource_type.should equal(type)
+ end
+
+ it "should be able to look up its resource type via its environment when the type is a node" do
+ resource = Puppet::Resource.new("node", "foobar")
+ node = Puppet::Resource::Type.new(:node, "foobar")
+ resource.environment.known_resource_types.add node
+
+ resource.resource_type.should equal(node)
+ end
+
+ it "should be able to look up its resource type via its environment when the type is a class" do
+ resource = Puppet::Resource.new("class", "foobar")
+ klass = Puppet::Resource::Type.new(:hostclass, "foobar")
+ resource.environment.known_resource_types.add klass
- it "should convert its environment into an environment instance if one is provided"
+ resource.resource_type.should equal(klass)
+ end
+
+ it "should use its namespace when looking up defined resource types" do
+ resource = Puppet::Resource.new("bar", "/my/file", :namespace => "foo")
+ type = Puppet::Resource::Type.new(:definition, "foo::bar")
+ resource.environment.known_resource_types.add type
+
+ resource.resource_type.should equal(type)
+ end
- it "should support a namespace attribute"
+ it "should use its namespace when looking up host classes" do
+ resource = Puppet::Resource.new("class", "bar", :namespace => "foo")
+ type = Puppet::Resource::Type.new(:hostclass, "foo::bar")
+ resource.environment.known_resource_types.add type
+
+ resource.resource_type.should equal(type)
+ end
+
+ it "should return nil when looking up resource types that don't exist" do
+ Puppet::Resource.new("foobar", "bar").resource_type.should be_nil
+ end
+
+ it "should fail when an invalid parameter is used and parameter validation is enabled" do
+ type = Puppet::Resource::Type.new(:definition, "foobar")
+ Puppet::Node::Environment.new.known_resource_types.add type
+ resource = Puppet::Resource.new("foobar", "/my/file", :validate_parameters => true)
+ lambda { resource[:yay] = true }.should raise_error(ArgumentError)
+ end
+
+ it "should not fail when an invalid parameter is used and parameter validation is disabled" do
+ type = Puppet::Resource::Type.new(:definition, "foobar")
+ Puppet::Node::Environment.new.known_resource_types.add type
+ resource = Puppet::Resource.new("foobar", "/my/file")
+ resource[:yay] = true
+ end
+
+ it "should not fail when a valid parameter is used and parameter validation is enabled" do
+ type = Puppet::Resource::Type.new(:definition, "foobar", :arguments => {"yay" => nil})
+ Puppet::Node::Environment.new.known_resource_types.add type
+ resource = Puppet::Resource.new("foobar", "/my/file", :validate_parameters => true)
+ resource[:yay] = true
+ end
describe "when managing parameters" do
before do
@resource = Puppet::Resource.new("file", "/my/file")
end
- it "should be able to check whether parameters are valid when the resource models builtin resources"
+ it "should correctly detect when provided parameters are not valid for builtin types" do
+ Puppet::Resource.new("file", "/my/file").should_not be_valid_parameter("foobar")
+ end
+
+ it "should correctly detect when provided parameters are valid for builtin types" do
+ Puppet::Resource.new("file", "/my/file").should be_valid_parameter("mode")
+ end
+
+ it "should correctly detect when provided parameters are not valid for defined resource types" do
+ type = Puppet::Resource::Type.new(:definition, "foobar")
+ Puppet::Node::Environment.new.known_resource_types.add type
+ Puppet::Resource.new("foobar", "/my/file").should_not be_valid_parameter("myparam")
+ end
- it "should be able to check whether parameters are valid when the resource models defined resources"
+ it "should correctly detect when provided parameters are valid for defined resource types" do
+ type = Puppet::Resource::Type.new(:definition, "foobar", :arguments => {"myparam" => nil})
+ Puppet::Node::Environment.new.known_resource_types.add type
+ Puppet::Resource.new("foobar", "/my/file").should be_valid_parameter("myparam")
+ end
it "should allow setting and retrieving of parameters" do
@resource[:foo] = "bar"
@@ -138,6 +229,7 @@ describe Puppet::Resource do
it "should be able to set the name for non-builtin types" do
resource = Puppet::Resource.new(:foo, "bar")
+ resource[:name] = "eh"
lambda { resource[:name] = "eh" }.should_not raise_error
end
diff --git a/spec/unit/resource/type.rb b/spec/unit/resource/type.rb
index a5fb679..41ea8e1 100755
--- a/spec/unit/resource/type.rb
+++ b/spec/unit/resource/type.rb
@@ -138,37 +138,37 @@ describe Puppet::Resource::Type do
it "should set any provided arguments with the keys as symbols" do
type = Puppet::Resource::Type.new(:hostclass, "foo", :arguments => {:foo => "bar", :baz => "biz"})
- type.should be_validattr("foo")
- type.should be_validattr("baz")
+ type.should be_valid_parameter("foo")
+ type.should be_valid_parameter("baz")
end
it "should set any provided arguments with they keys as strings" do
type = Puppet::Resource::Type.new(:hostclass, "foo", :arguments => {"foo" => "bar", "baz" => "biz"})
- type.should be_validattr(:foo)
- type.should be_validattr(:baz)
+ type.should be_valid_parameter(:foo)
+ type.should be_valid_parameter(:baz)
end
it "should function if provided no arguments" do
type = Puppet::Resource::Type.new(:hostclass, "foo")
- type.should_not be_validattr(:foo)
+ type.should_not be_valid_parameter(:foo)
end
end
describe "when testing the validity of an attribute" do
it "should return true if the parameter was typed at initialization" do
- Puppet::Resource::Type.new(:hostclass, "foo", :arguments => {"foo" => "bar"}).should be_validattr("foo")
+ Puppet::Resource::Type.new(:hostclass, "foo", :arguments => {"foo" => "bar"}).should be_valid_parameter("foo")
end
it "should return true if it is a metaparam" do
- Puppet::Resource::Type.new(:hostclass, "foo").should be_validattr("require")
+ Puppet::Resource::Type.new(:hostclass, "foo").should be_valid_parameter("require")
end
it "should return true if the parameter is named 'name'" do
- Puppet::Resource::Type.new(:hostclass, "foo").should be_validattr("name")
+ Puppet::Resource::Type.new(:hostclass, "foo").should be_valid_parameter("name")
end
it "should return false if it is not a metaparam and was not provided at initialization" do
- Puppet::Resource::Type.new(:hostclass, "foo").should_not be_validattr("yayness")
+ Puppet::Resource::Type.new(:hostclass, "foo").should_not be_valid_parameter("yayness")
end
end
diff --git a/spec/unit/type.rb b/spec/unit/type.rb
index cfc061f..6bdbe37 100755
--- a/spec/unit/type.rb
+++ b/spec/unit/type.rb
@@ -7,6 +7,18 @@ describe Puppet::Type do
Puppet::Type.ancestors.should be_include(Puppet::Util::Cacher)
end
+ it "should consider a parameter to be valid if it is a valid parameter" do
+ Puppet::Type.type(:mount).should be_valid_parameter(:path)
+ end
+
+ it "should consider a parameter to be valid if it is a valid property" do
+ Puppet::Type.type(:mount).should be_valid_parameter(:fstype)
+ end
+
+ it "should consider a parameter to be valid if it is a valid metaparam" do
+ Puppet::Type.type(:mount).should be_valid_parameter(:noop)
+ end
+
it "should use its catalog as its expirer" do
catalog = Puppet::Resource::Catalog.new
resource = Puppet::Type.type(:mount).new(:name => "foo", :fstype => "bar", :pass => 1, :ensure => :present)
diff --git a/test/language/resource.rb b/test/language/resource.rb
index 69e82fd..c1d116f 100755
--- a/test/language/resource.rb
+++ b/test/language/resource.rb
@@ -67,17 +67,17 @@ class TestResource < PuppetTest::TestCase
res.instance_variable_set("@ref", ref)
klass = mock("class")
ref.expects(:typeclass).returns(klass).times(4)
- klass.expects(:validattr?).with("good").returns(true)
+ klass.expects(:valid_parameter?).with("good").returns(true)
assert(res.send(:paramcheck, :good), "Did not allow valid param")
# It's name or title
- klass.expects(:validattr?).with("name").returns(false)
+ klass.expects(:valid_parameter?).with("name").returns(false)
assert(res.send(:paramcheck, :name), "Did not allow name")
- klass.expects(:validattr?).with("title").returns(false)
+ klass.expects(:valid_parameter?).with("title").returns(false)
assert(res.send(:paramcheck, :title), "Did not allow title")
# It's not actually allowed
- klass.expects(:validattr?).with("other").returns(false)
+ klass.expects(:valid_parameter?).with("other").returns(false)
res.expects(:fail)
ref.expects(:type)
res.send(:paramcheck, :other)
diff --git a/test/lib/puppettest/fakes.rb b/test/lib/puppettest/fakes.rb
index db6ca4d..0aedb59 100644
--- a/test/lib/puppettest/fakes.rb
+++ b/test/lib/puppettest/fakes.rb
@@ -35,7 +35,7 @@ module PuppetTest
def []=(param, value)
param = symbolize(param)
- unless @realresource.validattr?(param)
+ unless @realresource.valid_parameter?(param)
raise Puppet::DevError, "Invalid attribute %s for %s" %
[param, @realresource.name]
end
--
1.6.1
The reason for all of this is that we previously only
looked up builtin resource types from outside the parser,
but now that the defined resource types are available globally
via environments, we can push that lookup code to Resource.
Once we do that, however, we have to have environment and
namespace information in every resource.
Here I remove the Resource::Reference classes (except
the AST class), and use Resource instances instead. I
did this because the shared code between the two classes
got incredibly complicated, such that they should have had
a hierarchical relationship disallowed by their constants.
This complexity convinced me just to get rid of References
entirely.
I also make Puppet::Parser::Resource a subclass
of Puppet::Resource.
There are still broken tests in test/, but this was a big
enough commit I wanted to get it in.
Signed-off-by: Luke Kanies <lu...@reductivelabs.com>
---
lib/puppet.rb | 1 -
lib/puppet/parser/ast/resource.rb | 8 +-
lib/puppet/parser/ast/resource_defaults.rb | 2 +-
lib/puppet/parser/ast/resource_override.rb | 4 +-
lib/puppet/parser/ast/resource_reference.rb | 85 +----
lib/puppet/parser/collector.rb | 2 +-
lib/puppet/parser/compiler.rb | 4 +-
lib/puppet/parser/functions/defined.rb | 6 +-
lib/puppet/parser/functions/require.rb | 2 +-
lib/puppet/parser/parser_support.rb | 11 -
lib/puppet/parser/resource.rb | 153 ++++------
lib/puppet/parser/resource/reference.rb | 103 ------
lib/puppet/rails/param_value.rb | 2 +-
lib/puppet/resource.rb | 115 +++++--
lib/puppet/resource/catalog.rb | 4 +-
lib/puppet/resource/reference.rb | 90 -----
lib/puppet/resource/type.rb | 8 +-
lib/puppet/resource/type_collection.rb | 27 ++-
lib/puppet/transportable.rb | 12 +-
lib/puppet/type.rb | 6 +-
lib/puppet/type/component.rb | 2 +-
lib/puppet/type/tidy.rb | 4 +-
lib/puppet/util/settings.rb | 1 -
spec/integration/application/puppet.rb | 2 +-
spec/integration/indirector/catalog/compiler.rb | 1 +
spec/unit/configurer.rb | 3 +-
spec/unit/indirector/catalog/compiler.rb | 6 +-
spec/unit/parser/ast/resource.rb | 29 +-
spec/unit/parser/ast/resource_reference.rb | 51 +--
spec/unit/parser/collector.rb | 3 +-
spec/unit/parser/compiler.rb | 11 +-
spec/unit/parser/functions/defined.rb | 50 +++
spec/unit/parser/functions/require.rb | 2 +-
spec/unit/parser/functions/tag.rb | 24 ++
spec/unit/parser/parser.rb | 16 +
spec/unit/parser/resource.rb | 143 ++++++---
spec/unit/parser/resource/reference.rb | 134 --------
spec/unit/parser/scope.rb | 157 +++++++++-
spec/unit/rails/param_value.rb | 2 +-
spec/unit/resource.rb | 209 ++++++++-----
spec/unit/resource/catalog.rb | 2 +-
spec/unit/resource/reference.rb | 111 ------
spec/unit/resource/type.rb | 6 +-
spec/unit/resource/type_collection.rb | 42 +++-
spec/unit/type.rb | 8 +-
spec/unit/type/tidy.rb | 2 +-
test/language/functions.rb | 108 +------
test/language/parser.rb | 406 ++---------------------
test/language/resource.rb | 172 ----------
test/language/scope.rb | 207 +-----------
test/language/snippets.rb | 1 -
test/lib/puppettest/parsertesting.rb | 17 +-
test/lib/puppettest/resourcetesting.rb | 11 +-
test/other/events.rb | 6 +-
test/other/relationships.rb | 2 +-
test/other/transactions.rb | 12 +-
test/ral/type/exec.rb | 4 +-
57 files changed, 845 insertions(+), 1767 deletions(-)
delete mode 100644 lib/puppet/parser/resource/reference.rb
delete mode 100644 lib/puppet/resource/reference.rb
create mode 100755 spec/unit/parser/functions/defined.rb
create mode 100755 spec/unit/parser/functions/tag.rb
delete mode 100755 spec/unit/parser/resource/reference.rb
delete mode 100755 spec/unit/resource/reference.rb
create mode 100644 spec/unit/transportable.rb
delete mode 100755 test/language/resource.rb
diff --git a/lib/puppet.rb b/lib/puppet.rb
index dc5c123..3eccb7d 100644
--- a/lib/puppet.rb
+++ b/lib/puppet.rb
@@ -168,7 +168,6 @@ end
require 'puppet/type'
require 'puppet/parser'
require 'puppet/resource'
-require 'puppet/resource/reference'
require 'puppet/network'
require 'puppet/ssl'
require 'puppet/module'
diff --git a/lib/puppet/parser/ast/resource.rb b/lib/puppet/parser/ast/resource.rb
index d222893..5da40b3 100644
--- a/lib/puppet/parser/ast/resource.rb
+++ b/lib/puppet/parser/ast/resource.rb
@@ -14,7 +14,7 @@ class Resource < AST::ResourceReference
# in the current scope.
def evaluate(scope)
# Evaluate all of the specified params.
- paramobjects = @params.collect { |param|
+ paramobjects = params.collect { |param|
param.safeevaluate(scope)
}
@@ -25,8 +25,6 @@ class Resource < AST::ResourceReference
resource_titles = [resource_titles]
end
- resource_type = qualified_type(scope)
-
# We want virtual to be true if exported is true. We can't
# just set :virtual => self.virtual in the initialization,
# because sometimes the :virtual attribute is set *after*
@@ -39,9 +37,7 @@ class Resource < AST::ResourceReference
# many times.
resource_titles.flatten.collect { |resource_title|
exceptwrap :type => Puppet::ParseError do
- resource = Puppet::Parser::Resource.new(
- :type => resource_type,
- :title => resource_title,
+ resource = Puppet::Parser::Resource.new(type, resource_title,
:params => paramobjects,
:file => self.file,
:line => self.line,
diff --git a/lib/puppet/parser/ast/resource_defaults.rb b/lib/puppet/parser/ast/resource_defaults.rb
index 3fde7ad..f0746ec 100644
--- a/lib/puppet/parser/ast/resource_defaults.rb
+++ b/lib/puppet/parser/ast/resource_defaults.rb
@@ -12,7 +12,7 @@ class Puppet::Parser::AST
# object type.
def evaluate(scope)
# Use a resource reference to canonize the type
- ref = Puppet::Resource::Reference.new(@type, "whatever")
+ ref = Puppet::Resource.new(@type, "whatever")
type = ref.type
params = @params.safeevaluate(scope)
diff --git a/lib/puppet/parser/ast/resource_override.rb b/lib/puppet/parser/ast/resource_override.rb
index 5eac509..2d4f7a8 100644
--- a/lib/puppet/parser/ast/resource_override.rb
+++ b/lib/puppet/parser/ast/resource_override.rb
@@ -36,9 +36,7 @@ class Puppet::Parser::AST
resource = [resource] unless resource.is_a?(Array)
resource = resource.collect do |r|
- res = Puppet::Parser::Resource.new(
- :type => r.type,
- :title => r.title,
+ res = Puppet::Parser::Resource.new(r.type, r.title,
:params => params,
:file => file,
:line => line,
diff --git a/lib/puppet/parser/ast/resource_reference.rb b/lib/puppet/parser/ast/resource_reference.rb
index 794e505..8e09a8e 100644
--- a/lib/puppet/parser/ast/resource_reference.rb
+++ b/lib/puppet/parser/ast/resource_reference.rb
@@ -1,76 +1,23 @@
+require 'puppet/parser/ast'
require 'puppet/parser/ast/branch'
+require 'puppet/resource'
-class Puppet::Parser::AST
- # A reference to an object. Only valid as an rvalue.
- class ResourceReference < AST::Branch
- attr_accessor :title, :type
- # Is the type a builtin type?
- def builtintype?(type)
- if typeklass = Puppet::Type.type(type)
- return typeklass
- else
- return false
- end
- end
-
- def each
- [@type,@title].flatten.each { |param|
- #Puppet.debug("yielding param %s" % param)
- yield param
- }
- end
+class Puppet::Parser::AST::ResourceReference < Puppet::Parser::AST::Branch
+ attr_accessor :title, :type
- # Evaluate our object, but just return a simple array of the type
- # and name.
- def evaluate(scope)
- title = @title.safeevaluate(scope)
- title = [title] unless title.is_a?(Array)
-
- if @type.to_s.downcase == "class"
- resource_type = "class"
- title = title.collect { |t| qualified_class(scope, t) }
- else
- resource_type = qualified_type(scope)
- end
-
- title = title.collect { |t| Puppet::Parser::Resource::Reference.new(
- :type => resource_type, :title => t
- ) }
- return title.pop if title.length == 1
- return title
- end
-
- # Look up a fully qualified class name.
- def qualified_class(scope, title)
- # Look up the full path to the class
- if classobj = scope.find_hostclass(title)
- title = classobj.name
- else
- raise Puppet::ParseError, "Could not find class %s" % title
- end
- end
-
- # Look up a fully-qualified type. This method is
- # also used in AST::Resource.
- def qualified_type(scope, title = nil)
- # We want a lower-case type. For some reason.
- objtype = @type.downcase
- unless builtintype?(objtype)
- if dtype = scope.find_definition(objtype)
- objtype = dtype.name
- else
- raise Puppet::ParseError, "Could not find resource type %s" % objtype
- end
- end
- return objtype
- end
+ # Evaluate our object, but just return a simple array of the type
+ # and name.
+ def evaluate(scope)
+ titles = Array(title.safeevaluate(scope)).collect { |t| Puppet::Resource.new(type, t, :namespaces => scope.namespaces) }
+ return titles.pop if titles.length == 1
+ return titles
+ end
- def to_s
- if title.is_a?(ASTArray)
- "#{type.to_s.capitalize}#{title}"
- else
- "#{type.to_s.capitalize}[#{title}]"
- end
+ def to_s
+ if title.is_a?(Puppet::Parser::AST::ASTArray)
+ "#{type.to_s.capitalize}#{title}"
+ else
+ "#{type.to_s.capitalize}[#{title}]"
end
end
end
diff --git a/lib/puppet/parser/collector.rb b/lib/puppet/parser/collector.rb
index a6763c4..0445187 100644
--- a/lib/puppet/parser/collector.rb
+++ b/lib/puppet/parser/collector.rb
@@ -75,7 +75,7 @@ class Puppet::Parser::Collector
@collected = {}
# Canonize the type
- @type = Puppet::Resource::Reference.new(type, "whatever").type
+ @type = Puppet::Resource.new(type, "whatever").type
@equery = equery
@vquery = vquery
diff --git a/lib/puppet/parser/compiler.rb b/lib/puppet/parser/compiler.rb
index 09489ef..31df266 100644
--- a/lib/puppet/parser/compiler.rb
+++ b/lib/puppet/parser/compiler.rb
@@ -307,9 +307,9 @@ class Puppet::Parser::Compiler
# Find and evaluate our main object, if possible.
def evaluate_main
- @main = known_resource_types.find_hostclass("", "") || known_resource_types.add(Puppet::Resource::Type.new(:hostclass, ""))
+ @main = known_resource_types.find_hostclass([""], "") || known_resource_types.add(Puppet::Resource::Type.new(:hostclass, ""))
@topscope.source = @main
- @main_resource = Puppet::Parser::Resource.new(:type => "class", :title => :main, :scope => @topscope, :source => @main)
+ @main_resource = Puppet::Parser::Resource.new("class", :main, :scope => @topscope, :source => @main)
@topscope.resource = @main_resource
@resources << @main_resource
diff --git a/lib/puppet/parser/functions/defined.rb b/lib/puppet/parser/functions/defined.rb
index 5ad74a7..4d1d8c6 100644
--- a/lib/puppet/parser/functions/defined.rb
+++ b/lib/puppet/parser/functions/defined.rb
@@ -6,21 +6,21 @@ Puppet::Parser::Functions::newfunction(:defined, :type => :rvalue, :doc => "Dete
(e.g., ``if defined(File['/tmp/myfile']) { ... }``). This function is unfortunately
dependent on the parse order of the configuration when testing whether a resource is defined.") do |vals|
result = false
+ vals = [vals] unless vals.is_a?(Array)
vals.each do |val|
case val
when String
- # For some reason, it doesn't want me to return from here.
if Puppet::Type.type(val) or find_definition(val) or find_hostclass(val)
result = true
break
end
- when Puppet::Parser::Resource::Reference
+ when Puppet::Resource
if findresource(val.to_s)
result = true
break
end
else
- raise ArgumentError, "Invalid argument of type %s to 'defined'" % val.class
+ raise ArgumentError, "Invalid argument of type '#{val.class}' to 'defined'"
end
end
result
diff --git a/lib/puppet/parser/functions/require.rb b/lib/puppet/parser/functions/require.rb
index d72169a..6b163a9 100644
--- a/lib/puppet/parser/functions/require.rb
+++ b/lib/puppet/parser/functions/require.rb
@@ -42,7 +42,7 @@ fail if used with earlier clients.
# The 'obvious' way is just to add an edge in the catalog,
# but that is considered a containment edge, not a dependency
# edge, so it usually gets lost on the client.
- ref = Puppet::Parser::Resource::Reference.new(:type => :class, :title => klass)
+ ref = Puppet::Resource.new(:class, klass)
resource.set_parameter(:require, ref)
end
end
diff --git a/lib/puppet/parser/parser_support.rb b/lib/puppet/parser/parser_support.rb
index e6bc46b..d43b0d3 100644
--- a/lib/puppet/parser/parser_support.rb
+++ b/lib/puppet/parser/parser_support.rb
@@ -388,15 +388,4 @@ class Puppet::Parser::Parser
def watch_file(filename)
known_resource_types.watch_file(filename)
end
-
- private
-
- def check_and_add_to_watched_files(filename)
- unless @files.include?(filename)
- @files[filename] = Puppet::Util::LoadedFile.new(filename)
- return true
- else
- return false
- end
- end
end
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb
index 428b9df..36f1fbe 100644
--- a/lib/puppet/parser/resource.rb
+++ b/lib/puppet/parser/resource.rb
@@ -1,8 +1,11 @@
-# A resource that we're managing. This handles making sure that only subclasses
-# can set parameters.
-class Puppet::Parser::Resource
+require 'puppet/resource'
+
+# The primary difference between this class and its
+# parent is that this class has rules on who can set
+# parameters
+class Puppet::Parser::Resource < Puppet::Resource
require 'puppet/parser/resource/param'
- require 'puppet/parser/resource/reference'
+ require 'puppet/resource'
require 'puppet/util/tagging'
require 'puppet/file_collection/lookup'
require 'puppet/parser/yaml_trimmer'
@@ -29,15 +32,8 @@ class Puppet::Parser::Resource
@relationship_names.include?(name)
end
- # Proxy a few methods to our @ref object.
- [:builtin?, :type, :title].each do |method|
- define_method(method) do
- @ref.send(method)
- end
- end
-
# Set up some boolean test methods
- [:exported, :translated, :override, :virtual, :evaluated].each do |method|
+ [:translated, :override, :evaluated].each do |method|
newmeth = (method.to_s + "?").intern
define_method(newmeth) do
self.send(method)
@@ -60,25 +56,25 @@ class Puppet::Parser::Resource
set_parameter(param, value)
end
- def builtin=(bool)
- @ref.builtin = bool
- end
-
def eachparam
@params.each do |name, param|
yield param
end
end
+ def environment
+ scope.environment
+ end
+
# Retrieve the associated definition and evaluate it.
def evaluate
- if klass = @ref.definedtype
+ if klass = resource_type and ! builtin_type?
finish()
return klass.evaluate_code(self)
elsif builtin?
- devfail "Cannot evaluate a builtin type"
+ devfail "Cannot evaluate a builtin type (#{type})"
else
- self.fail "Cannot find definition %s" % self.type
+ self.fail "Cannot find definition #{type}"
end
ensure
@evaluated = true
@@ -111,61 +107,41 @@ class Puppet::Parser::Resource
defined?(@finished) and @finished
end
- def initialize(options)
+ def initialize(type, title, options)
+ self.type = type
+ self.title = title
+
+ @params = {}
+ # Define all of the parameters
+ if params = options[:params]
+ extract_parameters(params)
+ options.delete(:params)
+ end
+
# Set all of the options we can.
options.each do |option, value|
if respond_to?(option.to_s + "=")
send(option.to_s + "=", value)
options.delete(option)
+ else
+ raise ArgumentError, "Resources do not accept #{option}"
end
end
unless self.scope
raise ArgumentError, "Resources require a scope"
end
- @source ||= scope.source
-
- options = symbolize_options(options)
-
- # Set up our reference.
- if type = options[:type] and title = options[:title]
- options.delete(:type)
- options.delete(:title)
- else
- raise ArgumentError, "Resources require a type and title"
- end
-
- @ref = Reference.new(:type => type, :title => title, :scope => self.scope)
-
- @params = {}
-
- # Define all of the parameters
- if params = options[:params]
- options.delete(:params)
- params.each do |param|
- # Don't set the same parameter twice
- if @params[param.name]
- self.fail Puppet::ParseError, "Duplicate parameter '%s' for on %s" %
- [param.name, self.to_s]
- end
-
- set_parameter(param)
- end
- end
- # Throw an exception if we've got any arguments left to set.
- unless options.empty?
- raise ArgumentError, "Resources do not accept %s" % options.keys.collect { |k| k.to_s }.join(", ")
- end
+ @source ||= scope.source
- tag(@ref.type)
- tag(@ref.title) if valid_tag?(@ref.title.to_s)
+ tag(self.type)
+ tag(self.title) if valid_tag?(self.title.to_s)
end
# Is this resource modeling an isomorphic resource type?
def isomorphic?
- if builtin?
- return @ref.builtintype.isomorphic?
+ if builtin_type?
+ return resource_type.isomorphic?
else
return true
end
@@ -199,12 +175,8 @@ class Puppet::Parser::Resource
@name
end
- # This *significantly* reduces the number of calls to Puppet.[].
- def paramcheck?
- unless defined? @@paramcheck
- @@paramcheck = Puppet[:paramcheck]
- end
- @@paramcheck
+ def namespaces
+ scope.namespaces
end
# A temporary occasion, until I get paths in the scopes figured out.
@@ -212,11 +184,6 @@ class Puppet::Parser::Resource
to_s
end
- # Return the short version of our name.
- def ref
- @ref.to_s
- end
-
# Define a parameter in our resource.
# if we ever receive a parameter named 'tag', set
# the resource tags with its value.
@@ -254,16 +221,16 @@ class Puppet::Parser::Resource
result = Puppet::Resource.new(type, title)
to_hash.each do |p, v|
- if v.is_a?(Puppet::Parser::Resource::Reference)
- v = Puppet::Resource::Reference.new(v.type, v.title)
+ if v.is_a?(Puppet::Resource)
+ v = Puppet::Resource.new(v.type, v.title)
elsif v.is_a?(Array)
# flatten resource references arrays
- if v.flatten.find { |av| av.is_a?(Puppet::Parser::Resource::Reference) }
+ if v.flatten.find { |av| av.is_a?(Puppet::Resource) }
v = v.flatten
end
v = v.collect do |av|
- if av.is_a?(Puppet::Parser::Resource::Reference)
- av = Puppet::Resource::Reference.new(av.type, av.title)
+ if av.is_a?(Puppet::Resource)
+ av = Puppet::Resource.new(av.type, av.title)
end
av
end
@@ -289,10 +256,6 @@ class Puppet::Parser::Resource
return result
end
- def to_s
- self.ref
- end
-
# Translate our object to a transportable object.
def to_trans
return nil if virtual?
@@ -389,28 +352,26 @@ class Puppet::Parser::Resource
set_parameter(param)
end
- # Verify that all passed parameters are valid. This throws an error if
- # there's a problem, so we don't have to worry about the return value.
- def paramcheck(param)
- param = param.to_s
- # Now make sure it's a valid argument to our class. These checks
- # are organized in order of commonhood -- most types, it's a valid
- # argument and paramcheck is enabled.
- if @ref.typeclass.valid_parameter?(param)
- true
- elsif %w{name title}.include?(param) # always allow these
- true
- elsif paramcheck?
- self.fail Puppet::ParseError, "Invalid parameter '%s' for type '%s'" %
- [param, @ref.type]
- end
- end
-
# Make sure the resource's parameters are all valid for the type.
def validate
@params.each do |name, param|
- # Make sure it's a valid parameter.
- paramcheck(name)
+ validate_parameter(name)
+ end
+ rescue => detail
+ fail Puppet::ParseError, detail.to_s
+ end
+
+ private
+
+ def extract_parameters(params)
+ params.each do |param|
+ # Don't set the same parameter twice
+ if @params[param.name]
+ self.fail Puppet::ParseError, "Duplicate parameter '%s' for on %s" %
+ [param.name, self.to_s]
+ end
+
+ set_parameter(param)
end
end
end
diff --git a/lib/puppet/parser/resource/reference.rb b/lib/puppet/parser/resource/reference.rb
deleted file mode 100644
index ac1c79a..0000000
--- a/lib/puppet/parser/resource/reference.rb
+++ /dev/null
@@ -1,103 +0,0 @@
-# A reference to a resource. Mostly just the type and title.
-require 'puppet/resource/reference'
-require 'puppet/file_collection/lookup'
-require 'puppet/parser/yaml_trimmer'
-
-require 'puppet/resource/type_collection_helper'
-
-# A reference to a resource. Mostly just the type and title.
-class Puppet::Parser::Resource::Reference < Puppet::Resource::Reference
- include Puppet::Parser::YamlTrimmer
- include Puppet::FileCollection::Lookup
- include Puppet::Util::MethodHelper
- include Puppet::Util::Errors
- include Puppet::Resource::TypeCollectionHelper
-
- attr_accessor :builtin, :file, :line, :scope
-
- # Are we a builtin type?
- def builtin?
- unless defined? @builtin
- if builtintype()
- @builtin = true
- else
- @builtin = false
- end
- end
-
- @builtin
- end
-
- def builtintype
- if t = Puppet::Type.type(self.type.downcase) and t.name != :component
- t
- else
- nil
- end
- end
-
- # Return the defined type for our obj. This can return classes,
- # definitions or nodes.
- def definedtype
- unless defined? @definedtype
- case self.type
- when "Class" # look for host classes
- name = self.title == :main ? "" : self.title
- unless tmp = known_resource_types.find_hostclass("", name)
- fail Puppet::ParseError, "Could not find '#{title}' class"
- end
- when "Node" # look for node definitions
- unless tmp = known_resource_types.node(self.title)
- fail Puppet::ParseError, "Could not find node '%s'" % self.title
- end
- else # normal definitions
- # The resource type is capitalized, so we have to downcase. Really,
- # we should have a better interface for finding these, but eh.
- tmp = known_resource_types.definition(self.type.downcase)
- end
-
- if tmp
- @definedtype = tmp
- else
- fail Puppet::ParseError, "Could not find resource type '%s'" % self.type
- end
- end
-
- @definedtype
- end
-
- def environment
- scope.environment
- end
-
- def initialize(hash)
- set_options(hash)
- requiredopts(:type, :title)
- end
-
- def skip_for_yaml
- %w{@typeclass @definedtype}
- end
-
- def to_ref
- # We have to return different cases to provide backward compatibility
- # from 0.24.x to 0.23.x.
- if builtin?
- return [type.to_s.downcase, title.to_s]
- else
- return [type.to_s, title.to_s]
- end
- end
-
- def typeclass
- unless defined? @typeclass
- if tmp = builtintype || definedtype
- @typeclass = tmp
- else
- fail Puppet::ParseError, "Could not find type %s" % self.type
- end
- end
-
- @typeclass
- end
-end
diff --git a/lib/puppet/rails/param_value.rb b/lib/puppet/rails/param_value.rb
index b298924..d0bb8d7 100644
--- a/lib/puppet/rails/param_value.rb
+++ b/lib/puppet/rails/param_value.rb
@@ -23,7 +23,7 @@ class Puppet::Rails::ParamValue < ActiveRecord::Base
def self.munge_parser_values(value)
values = value.is_a?(Array) ? value : [value]
values.map do |v|
- if v.is_a?(Puppet::Resource::Reference)
+ if v.is_a?(Puppet::Resource)
v
else
v.to_s
diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb
index 35676ba..685a5fb 100644
--- a/lib/puppet/resource.rb
+++ b/lib/puppet/resource.rb
@@ -5,7 +5,6 @@ require 'puppet/util/pson'
# The simplest resource class. Eventually it will function as the
# base class for all resource-like behaviour.
class Puppet::Resource
- require 'puppet/resource/reference'
include Puppet::Util::Tagging
require 'puppet/resource/type_collection_helper'
@@ -13,8 +12,8 @@ class Puppet::Resource
extend Puppet::Util::Pson
include Enumerable
- attr_accessor :file, :line, :catalog, :exported, :virtual, :namespace, :validate_parameters
- attr_writer :type, :title, :environment
+ attr_accessor :file, :line, :catalog, :exported, :virtual, :validate_parameters
+ attr_reader :type, :title, :namespaces
ATTRIBUTES = [:file, :line, :exported]
@@ -91,6 +90,13 @@ class Puppet::Resource
@parameters[parameter_name(param)]
end
+ def ==(other)
+ return false unless other.respond_to?(:title) and self.type == other.type and self.title == other.title
+
+ return false unless to_hash == other.to_hash
+ true
+ end
+
# Compatibility method.
def builtin?
builtin_type?
@@ -98,7 +104,7 @@ class Puppet::Resource
# Is this a builtin resource type?
def builtin_type?
- @reference.builtin_type?
+ resource_type.is_a?(Class)
end
# Iterate over each param/value pair, as required for Enumerable.
@@ -106,6 +112,23 @@ class Puppet::Resource
@parameters.each { |p,v| yield p, v }
end
+ # These two methods are extracted into a Helper
+ # module, but file load order prevents me
+ # from including them in the class, and I had weird
+ # behaviour (i.e., sometimes it didn't work) when
+ # I directly extended each resource with the helper.
+ def environment
+ Puppet::Node::Environment.new(@environment)
+ end
+
+ def environment=(env)
+ if env.is_a?(String) or env.is_a?(Symbol)
+ @environment = env
+ else
+ @environment = env.name
+ end
+ end
+
%w{exported virtual}.each do |m|
define_method(m+"?") do
self.send(m)
@@ -113,14 +136,11 @@ class Puppet::Resource
end
# Create our resource.
- def initialize(type, title, attributes = {})
- # Doing this, instead of including it in the class,
- # is the only way I could get the load order to work
- # here.
- extend Puppet::Node::Environment::Helper
+ def initialize(type, title = nil, attributes = {})
+ self.type, self.title = extract_type_and_title(type, title)
@parameters = {}
- @namespace = ""
+ @namespaces = [""]
(attributes[:parameters] || {}).each do |param, value|
self[param] = value
@@ -131,15 +151,25 @@ class Puppet::Resource
send(attr.to_s + "=", value)
end
- @reference = Puppet::Resource::Reference.new(type, title)
-
- tag(@reference.type)
- tag(@reference.title) if valid_tag?(@reference.title)
+ tag(self.type)
+ tag(self.title) if valid_tag?(self.title)
end
- # Provide a reference to our resource in the canonical form.
def ref
- @reference.to_s
+ to_s
+ end
+
+ # Find our resource.
+ def resolve
+ return catalog.resource(to_s) if catalog
+ return nil
+ end
+
+ def title=(value)
+ if @type and klass = Puppet::Type.type(@type.to_s.downcase)
+ value = klass.canonicalize_ref(value)
+ end
+ @title = value
end
def resource_type
@@ -151,16 +181,6 @@ class Puppet::Resource
end
end
- # Get our title information from the reference, since it will canonize it for us.
- def title
- @reference.title
- end
-
- # Get our type information from the reference, since it will canonize it for us.
- def type
- @reference.type
- end
-
# Produce a simple hash of our parameters.
def to_hash
result = @parameters.dup
@@ -171,7 +191,7 @@ class Puppet::Resource
end
def to_s
- return ref
+ "#{type}[#{title}]"
end
# Convert our resource to Puppet code.
@@ -203,7 +223,7 @@ class Puppet::Resource
# Translate our object to a backward-compatible transportable object.
def to_trans
- if @reference.builtin_type?
+ if builtin_type?
result = to_transobject
else
result = to_transbucket
@@ -215,16 +235,20 @@ class Puppet::Resource
return result
end
+ def to_trans_ref
+ [type.to_s, title.to_s]
+ end
+
# Create an old-style TransObject instance, for builtin resource types.
def to_transobject
# Now convert to a transobject
- result = Puppet::TransObject.new(@reference.title, @reference.type)
+ result = Puppet::TransObject.new(title, type)
to_hash.each do |p, v|
- if v.is_a?(Puppet::Resource::Reference)
+ if v.is_a?(Puppet::Resource)
v = v.to_trans_ref
elsif v.is_a?(Array)
v = v.collect { |av|
- if av.is_a?(Puppet::Resource::Reference)
+ if av.is_a?(Puppet::Resource)
av = av.to_trans_ref
end
av
@@ -247,6 +271,15 @@ class Puppet::Resource
return result
end
+ # Canonize the type so we know it's always consistent.
+ def type=(value)
+ if value.nil? or value.to_s.downcase == "component"
+ @type = "Class"
+ else
+ @type = value.to_s.split("::").collect { |s| s.capitalize }.join("::")
+ end
+ end
+
def valid_parameter?(name)
resource_type.valid_parameter?(name)
end
@@ -263,7 +296,7 @@ class Puppet::Resource
def find_hostclass
name = title == :main ? "" : title
- known_resource_types.find_hostclass(namespace, name)
+ known_resource_types.find_hostclass(namespaces, name)
end
def find_builtin_resource_type
@@ -271,7 +304,7 @@ class Puppet::Resource
end
def find_defined_resource_type
- known_resource_types.find_definition(namespace, type.to_s.downcase)
+ known_resource_types.find_definition(namespaces, type.to_s.downcase)
end
# Produce a canonical method name.
@@ -283,10 +316,14 @@ class Puppet::Resource
param
end
+ def namespaces=(ns)
+ @namespaces = Array(ns)
+ end
+
# The namevar for our resource type. If the type doesn't exist,
# always use :name.
def namevar
- if t = resource_type
+ if builtin_type? and t = resource_type
t.namevar
else
:name
@@ -303,4 +340,14 @@ class Puppet::Resource
# TransBuckets don't support parameters, which is why they're being deprecated.
return bucket
end
+
+ private
+
+ def extract_type_and_title(argtype, argtitle)
+ if (argtitle || argtype) =~ /^([^\[\]]+)\[(.+)\]$/m then [ $1, $2 ]
+ elsif argtitle then [ argtype, argtitle ]
+ elsif argtype.is_a?(Puppet::Type) then [ argtype.class.name, argtype.title ]
+ else raise ArgumentError, "No title provided and #{argtype.inspect} is not a valid resource reference"
+ end
+ end
end
diff --git a/lib/puppet/resource/catalog.rb b/lib/puppet/resource/catalog.rb
index cb61285..916e8c6 100644
--- a/lib/puppet/resource/catalog.rb
+++ b/lib/puppet/resource/catalog.rb
@@ -376,12 +376,12 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph
# Always create a resource reference, so that it always canonizes how we
# are referring to them.
if title
- ref = Puppet::Resource::Reference.new(type, title).to_s
+ ref = Puppet::Resource.new(type, title).to_s
else
# If they didn't provide a title, then we expect the first
# argument to be of the form 'Class[name]', which our
# Reference class canonizes for us.
- ref = Puppet::Resource::Reference.new(nil, type).to_s
+ ref = Puppet::Resource.new(nil, type).to_s
end
@resource_table[ref]
end
diff --git a/lib/puppet/resource/reference.rb b/lib/puppet/resource/reference.rb
deleted file mode 100644
index eddb2d9..0000000
--- a/lib/puppet/resource/reference.rb
+++ /dev/null
@@ -1,90 +0,0 @@
-#
-# Created by Luke Kanies on 2007-11-28.
-# Copyright (c) 2007. All rights reserved.
-
-require 'puppet'
-require 'puppet/resource'
-
-# A simple class to canonize how we refer to and retrieve
-# resources.
-class Puppet::Resource::Reference
- attr_reader :type, :title
- attr_accessor :catalog
-
- def ==(other)
- other.respond_to?(:title) and self.type == other.type and self.title == other.title
- end
-
- def builtin_type?
- builtin_type ? true : false
- end
-
- def initialize(argtype, argtitle = nil)
- self.type,self.title =
- if (argtitle || argtype) =~ /^([^\[\]]+)\[(.+)\]$/m then [ $1, $2 ]
- elsif argtitle then [ argtype, argtitle ]
- elsif argtype.is_a?(Puppet::Type) then [ argtype.class.name, argtype.title ]
- else raise ArgumentError, "No title provided and #{argtype.inspect} is not a valid resource reference"
- end
- @builtin_type = nil
- end
-
- # Find our resource.
- def resolve
- return catalog.resource(to_s) if catalog
- return nil
- end
-
- def title=(value)
- if @type and klass = Puppet::Type.type(@type.to_s.downcase)
- value = klass.canonicalize_ref(value)
- end
- @title = value
- end
-
- # Canonize the type so we know it's always consistent.
- def type=(value)
- if value.nil? or value.to_s.downcase == "component"
- @type = "Class"
- else
- # LAK:NOTE See http://snurl.com/21zf8 [groups_google_com]
- x = @type = value.to_s.split("::").collect { |s| s.capitalize }.join("::")
- end
-
- if @title
- self.title = @title
- end
- end
-
- # Convert to the reference format that TransObject uses. Yay backward
- # compatibility.
- def to_trans_ref
- # We have to return different cases to provide backward compatibility
- # from 0.24.x to 0.23.x.
- if builtin_type?
- return [type.to_s.downcase, title.to_s]
- else
- return [type.to_s, title.to_s]
- end
- end
-
- # Convert to the standard way of referring to resources.
- def to_s
- "%s[%s]" % [@type, @title]
- end
-
- private
-
- def builtin_type
- if @builtin_type.nil?
- if @type =~ /::/
- @builtin_type = false
- elsif klass = Puppet::Type.type(@type.to_s.downcase)
- @builtin_type = true
- else
- @builtin_type = false
- end
- end
- @builtin_type
- end
-end
diff --git a/lib/puppet/resource/type.rb b/lib/puppet/resource/type.rb
index cadd034..f82b6dc 100644
--- a/lib/puppet/resource/type.rb
+++ b/lib/puppet/resource/type.rb
@@ -61,11 +61,11 @@ class Puppet::Resource::Type
# Add code from a new instance to our code.
def merge(other)
- fail ArgumentError, "#{name} is not a class; cannot add code to it" unless type == :hostclass
- fail ArgumentError, "#{other.name} is not a class; cannot add code from it" unless other.type == :hostclass
+ fail "#{name} is not a class; cannot add code to it" unless type == :hostclass
+ fail "#{other.name} is not a class; cannot add code from it" unless other.type == :hostclass
if parent and other.parent and parent != other.parent
- fail ArgumentError, "Cannot merge classes with different parent classes"
+ fail "Cannot merge classes with different parent classes (#{name} => #{parent} vs. #{other.name} => #{other.parent})"
end
# We know they're either equal or only one is set, so keep whichever parent is specified.
@@ -115,7 +115,7 @@ class Puppet::Resource::Type
return resource
end
- resource = Puppet::Parser::Resource.new(:type => resource_type, :title => name, :scope => scope, :source => self)
+ resource = Puppet::Parser::Resource.new(resource_type, name, :scope => scope, :source => self)
scope.compiler.add_resource(scope, resource)
scope.catalog.tag(*resource.tags)
resource
diff --git a/lib/puppet/resource/type_collection.rb b/lib/puppet/resource/type_collection.rb
index a0bd2dd..e2ca562 100644
--- a/lib/puppet/resource/type_collection.rb
+++ b/lib/puppet/resource/type_collection.rb
@@ -1,6 +1,12 @@
class Puppet::Resource::TypeCollection
attr_reader :environment
+ def clear
+ @hostclasses.clear
+ @definitions.clear
+ @nodes.clear
+ end
+
def initialize(env)
@environment = env.is_a?(String) ? Puppet::Node::Environment.new(env) : env
@hostclasses = {}
@@ -19,6 +25,10 @@ class Puppet::Resource::TypeCollection
end
def add(instance)
+ if instance.type == :hostclass and other = @hostclasses[instance.name] and other.type == :hostclass
+ other.merge(instance)
+ return other
+ end
method = "add_#{instance.type}"
send(method, instance)
instance.code_collection = self
@@ -26,8 +36,8 @@ class Puppet::Resource::TypeCollection
end
def add_hostclass(instance)
- dupe_check(instance, @hostclasses) { |dupe| "Class #{instance.name} is already defined#{dupe.error_context}; cannot redefine" }
- dupe_check(instance, @definitions) { |dupe| "Definition #{instance.name} is already defined#{dupe.error_context}; cannot be redefined as a class" }
+ dupe_check(instance, @hostclasses) { |dupe| "Class '#{instance.name}' is already defined#{dupe.error_context}; cannot redefine" }
+ dupe_check(instance, @definitions) { |dupe| "Definition '#{instance.name}' is already defined#{dupe.error_context}; cannot be redefined as a class" }
@hostclasses[instance.name] = instance
instance
@@ -38,7 +48,7 @@ class Puppet::Resource::TypeCollection
end
def add_node(instance)
- dupe_check(instance, @nodes) { |dupe| "Node #{instance.name} is already defined#{dupe.error_context}; cannot redefine" }
+ dupe_check(instance, @nodes) { |dupe| "Node '#{instance.name}' is already defined#{dupe.error_context}; cannot redefine" }
@node_list << instance
@nodes[instance.name] = instance
@@ -67,8 +77,10 @@ class Puppet::Resource::TypeCollection
@nodes.length > 0
end
- def add_definition(code)
- @definitions[code.name] = code
+ def add_definition(instance)
+ dupe_check(instance, @hostclasses) { |dupe| "'#{instance.name}' is already defined#{dupe.error_context} as a class; cannot redefine as a definition" }
+ dupe_check(instance, @definitions) { |dupe| "Definition '#{instance.name}' is already defined#{dupe.error_context}; cannot be redefined" }
+ @definitions[instance.name] = instance
end
def definition(name)
@@ -76,12 +88,13 @@ class Puppet::Resource::TypeCollection
end
def find(namespaces, name, type)
+ #Array("") == [] for some reason
+ namespaces = [namespaces] unless namespaces.is_a?(Array)
+
if r = find_fully_qualified(name, type)
return r
end
- namespaces = Array(namespaces)
-
namespaces.each do |namespace|
ary = namespace.split("::")
diff --git a/lib/puppet/transportable.rb b/lib/puppet/transportable.rb
index 1970d9f..c488170 100644
--- a/lib/puppet/transportable.rb
+++ b/lib/puppet/transportable.rb
@@ -1,5 +1,5 @@
require 'puppet'
-require 'puppet/resource/reference'
+require 'puppet/resource'
require 'yaml'
module Puppet
@@ -36,7 +36,7 @@ module Puppet
def ref
unless defined? @ref
- @ref = Puppet::Resource::Reference.new(@type, @name)
+ @ref = Puppet::Resource.new(@type, @name)
end
@ref.to_s
end
@@ -225,11 +225,11 @@ module Puppet
def to_ref
unless defined? @ref
if self.type and self.name
- @ref = Puppet::Resource::Reference.new(self.type, self.name)
+ @ref = Puppet::Resource.new(self.type, self.name)
elsif self.type and ! self.name # This is old-school node types
- @ref = Puppet::Resource::Reference.new("node", self.type)
+ @ref = Puppet::Resource.new("node", self.type)
elsif ! self.type and self.name
- @ref = Puppet::Resource::Reference.new("component", self.name)
+ @ref = Puppet::Resource.new("component", self.name)
else
@ref = nil
end
@@ -244,7 +244,7 @@ module Puppet
# Create a normalized resource from our TransObject.
def to_resource
params = defined?(@parameters) ? @parameters.dup : {}
- Puppet::Resource.new(type, name, params)
+ Puppet::Resource.new(type, name, :parameters => params)
end
def param(param,value)
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index f2b1d5c..e1412c0 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -9,7 +9,7 @@ require 'puppet/metatype/manager'
require 'puppet/util/errors'
require 'puppet/util/log_paths'
require 'puppet/util/logging'
-require 'puppet/resource/reference'
+require 'puppet/resource'
require 'puppet/util/cacher'
require 'puppet/file_collection/lookup'
require 'puppet/util/tagging'
@@ -1285,10 +1285,10 @@ class Type
def munge(references)
references = [references] unless references.is_a?(Array)
references.collect do |ref|
- if ref.is_a?(Puppet::Resource::Reference)
+ if ref.is_a?(Puppet::Resource)
ref
else
- Puppet::Resource::Reference.new(ref)
+ Puppet::Resource.new(ref)
end
end
end
diff --git a/lib/puppet/type/component.rb b/lib/puppet/type/component.rb
index bf9007a..d16cdda 100644
--- a/lib/puppet/type/component.rb
+++ b/lib/puppet/type/component.rb
@@ -65,7 +65,7 @@ Puppet::Type.newtype(:component) do
end
def title=(str)
- @reference = Puppet::Resource::Reference.new(str)
+ @reference = Puppet::Resource.new(str)
end
def refresh
diff --git a/lib/puppet/type/tidy.rb b/lib/puppet/type/tidy.rb
index b5ccb3f..f382fe2 100755
--- a/lib/puppet/type/tidy.rb
+++ b/lib/puppet/type/tidy.rb
@@ -275,9 +275,9 @@ Puppet::Type.newtype(:tidy) do
dir = File.dirname(path)
next unless resource = files_by_name[dir]
if resource[:require]
- resource[:require] << Puppet::Resource::Reference.new(:file, path)
+ resource[:require] << Puppet::Resource.new(:file, path)
else
- resource[:require] = [Puppet::Resource::Reference.new(:file, path)]
+ resource[:require] = [Puppet::Resource.new(:file, path)]
end
end
diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb
index 3941762..9bcf53f 100644
--- a/lib/puppet/util/settings.rb
+++ b/lib/puppet/util/settings.rb
@@ -5,7 +5,6 @@ require 'puppet/external/event-loop'
require 'puppet/util/cacher'
require 'puppet/util/loadedfile'
require 'puppet/resource'
-require 'puppet/resource/reference'
# The class for handling configuration files.
class Puppet::Util::Settings
diff --git a/spec/integration/application/puppet.rb b/spec/integration/application/puppet.rb
index 1342f3c..cfafc9c 100755
--- a/spec/integration/application/puppet.rb
+++ b/spec/integration/application/puppet.rb
@@ -14,7 +14,7 @@ describe "Puppet" do
it "should be able to apply catalogs provided in a file in pson" do
file_to_create = tmpfile("pson_catalog")
catalog = Puppet::Resource::Catalog.new
- resource = Puppet::Resource.new(:file, file_to_create, :content => "my stuff")
+ resource = Puppet::Resource.new(:file, file_to_create, :parameters => {:content => "my stuff"})
catalog.add_resource resource
manifest = tmpfile("manifest")
diff --git a/spec/integration/indirector/catalog/compiler.rb b/spec/integration/indirector/catalog/compiler.rb
index 16102ca..b4067a6 100755
--- a/spec/integration/indirector/catalog/compiler.rb
+++ b/spec/integration/indirector/catalog/compiler.rb
@@ -8,6 +8,7 @@ Puppet::Resource::Catalog.indirection.terminus(:compiler)
describe Puppet::Resource::Catalog::Compiler do
before do
+ Facter.stubs(:value).returns "something"
@catalog = Puppet::Resource::Catalog.new
@one = Puppet::Resource.new(:file, "/one")
diff --git a/spec/unit/configurer.rb b/spec/unit/configurer.rb
index 8a3577c..ca1216c 100755
--- a/spec/unit/configurer.rb
+++ b/spec/unit/configurer.rb
@@ -33,6 +33,7 @@ describe Puppet::Configurer, "when executing a catalog run" do
before do
Puppet.settings.stubs(:use).returns(true)
@agent = Puppet::Configurer.new
+ @agent.stubs(:prepare)
@agent.stubs(:facts_for_uploading).returns({})
@agent.stubs(:retrieve_catalog).returns Puppet::Resource::Catalog.new
@@ -71,7 +72,7 @@ describe Puppet::Configurer, "when executing a catalog run" do
it "should log a failure and do nothing if no catalog can be retrieved" do
@agent.expects(:retrieve_catalog).returns nil
- Puppet.expects(:err)
+ Puppet.expects(:err).with "Could not retrieve catalog; skipping run"
@agent.run
end
diff --git a/spec/unit/indirector/catalog/compiler.rb b/spec/unit/indirector/catalog/compiler.rb
index d11daaa..8339d18 100755
--- a/spec/unit/indirector/catalog/compiler.rb
+++ b/spec/unit/indirector/catalog/compiler.rb
@@ -11,7 +11,7 @@ describe Puppet::Resource::Catalog::Compiler do
before do
Puppet::Rails.stubs(:init)
Facter.stubs(:to_hash).returns({})
- Facter.stubs(:[]).returns(Facter::Util::Fact.new("something"))
+ Facter.stubs(:value).returns(Facter::Util::Fact.new("something"))
end
describe "when initializing" do
@@ -44,7 +44,7 @@ describe Puppet::Resource::Catalog::Compiler do
describe "and storeconfigs is enabled" do
before do
- Puppet.settings[:storeconfigs] = true
+ Puppet.settings.expects(:value).with(:storeconfigs).returns true
end
it "should initialize Rails if it is available" do
@@ -141,11 +141,11 @@ describe Puppet::Resource::Catalog::Compiler do
describe "when extracting facts from the request" do
before do
+ Facter.stubs(:value).returns "something"
@compiler = Puppet::Resource::Catalog::Compiler.new
@request = stub 'request', :options => {}
@facts = stub 'facts', :save => nil
- Facter.stubs(:value).returns "something"
end
it "should do nothing if no facts are provided" do
diff --git a/spec/unit/parser/ast/resource.rb b/spec/unit/parser/ast/resource.rb
index b257cb1..391f4c7 100755
--- a/spec/unit/parser/ast/resource.rb
+++ b/spec/unit/parser/ast/resource.rb
@@ -9,16 +9,15 @@ describe Puppet::Parser::AST::Resource do
@title = stub_everything 'title'
@compiler = stub_everything 'compiler'
@scope = Puppet::Parser::Scope.new(:compiler => @compiler)
- @param1 = stub_everything 'parameter', :is_a? => true
@scope.stubs(:resource).returns(stub_everything)
- @params = ast::ASTArray.new( :children => [@param1])
- @resource = ast::Resource.new(:title => @title, :type => "Resource", :params => @params )
+ @resource = ast::Resource.new(:title => @title, :type => "Resource", :params => ast::ASTArray.new(:children => []) )
@resource.stubs(:qualified_type).returns("Resource")
- Puppet::Parser::Resource.stubs(:new).returns(stub_everything)
end
it "should evaluate all its parameters" do
- @param1.expects(:safeevaluate).with(@scope)
+ param = stub 'param'
+ param.expects(:safeevaluate).with(@scope).returns Puppet::Parser::Resource::Param.new(:name => "myparam", :value => "myvalue", :source => stub("source"))
+ @resource.stubs(:params).returns [param]
@resource.evaluate(@scope)
end
@@ -49,10 +48,10 @@ describe Puppet::Parser::AST::Resource do
title_array.stubs(:flatten).returns([@title])
titles.stubs(:safeevaluate).with(@scope).returns(title_array)
- Puppet::Parser::Resource.expects(:new).with { |hash| hash[:title] == @title }
-
@resource.title = titles
- @resource.evaluate(@scope)
+ result = @resource.evaluate(@scope)
+ result[0].should be_instance_of(Puppet::Parser::Resource)
+ result[0].title.should == @title
end
it "should handover resources to the compiler" do
@@ -77,18 +76,18 @@ describe Puppet::Parser::AST::Resource do
title_array.stubs(:flatten).returns([@title])
titles.stubs(:safeevaluate).with(@scope).returns(title_array)
- Puppet::Parser::Resource.stubs(:new).returns(resource)
- @compiler.stubs(:add_resource).with(resource)
+ @compiler.stubs(:add_resource)
@resource.title = titles
- @resource.evaluate(@scope).should == [resource]
+ @resource.evaluate(@scope)[0].should be_instance_of(Puppet::Parser::Resource)
end
it "should generate virtual resources if it is virtual" do
@resource.virtual = true
- Puppet::Parser::Resource.expects(:new).with { |hash| hash[:virtual] == true }
+ result = @resource.evaluate(@scope)
+ result[0].should be_virtual
@resource.evaluate(@scope)
end
@@ -96,8 +95,8 @@ describe Puppet::Parser::AST::Resource do
it "should generate virtual and exported resources if it is exported" do
@resource.exported = true
- Puppet::Parser::Resource.expects(:new).with { |hash| hash[:virtual] == true and hash[:exported] == true }
-
- @resource.evaluate(@scope)
+ result = @resource.evaluate(@scope)
+ result[0].should be_virtual
+ result[0].should be_exported
end
end
diff --git a/spec/unit/parser/ast/resource_reference.rb b/spec/unit/parser/ast/resource_reference.rb
index 10d9678..ee42694 100755
--- a/spec/unit/parser/ast/resource_reference.rb
+++ b/spec/unit/parser/ast/resource_reference.rb
@@ -10,54 +10,31 @@ describe Puppet::Parser::AST::ResourceReference do
@scope = Puppet::Parser::Scope.new()
end
- def newref(title, type)
+ def newref(type, title)
title = stub 'title', :safeevaluate => title
ref = Puppet::Parser::AST::ResourceReference.new(:type => type, :title => title)
end
- it "should evaluate correctly reference to builtin types" do
- newref("/tmp/yay", "File").evaluate(@scope).to_s.should == "File[/tmp/yay]"
+ it "should correctly produce reference strings" do
+ newref("File", "/tmp/yay").evaluate(@scope).to_s.should == "File[/tmp/yay]"
end
- %{ "one::two" "one-two"}.each do |type|
- it "should evaluate correctly reference to define" do
- klass = stub 'klass', :title => "three", :name => type
- @scope.stubs(:find_definition).returns(klass)
-
- newref("three", type).evaluate(@scope).to_ref.should == Puppet::Parser::Resource::Reference.new( :type => type, :title => "three" ).to_ref
- end
+ it "should produce a single resource when the title evaluates to a string" do
+ newref("File", "/tmp/yay").evaluate(@scope).should == Puppet::Resource.new("file", "/tmp/yay")
end
- it "should be able to call qualified_class" do
- klass = stub 'klass', :title => "three", :name => "one"
- @scope.expects(:find_hostclass).with("one").returns(klass)
- newref("three","class").qualified_class(@scope,"one").should == "one"
- end
-
- it "should be able to find qualified classes when evaluating" do
- klass = stub 'klass', :title => "one", :name => "one"
- @scope.stubs(:find_hostclass).returns(klass)
-
- evaled = newref("one", "class").evaluate(@scope)
- evaled.type.should == "Class"
- evaled.title.should == "one"
- end
-
- it "should return an array of reference if given an array of titles" do
+ it "should return an array of resources if given an array of titles" do
titles = mock 'titles', :safeevaluate => ["title1","title2"]
- ref = ast::ResourceReference.new( :title => titles, :type => "Resource" )
- ref.stubs(:qualified_type).with(@scope).returns("Resource")
-
- ref.evaluate(@scope).should have(2).elements
+ ref = ast::ResourceReference.new( :title => titles, :type => "File" )
+ ref.evaluate(@scope).should == [
+ Puppet::Resource.new("file", "title1"),
+ Puppet::Resource.new("file", "title2")
+ ]
end
- it "should qualify class of all titles for Class resource references" do
- titles = mock 'titles', :safeevaluate => ["title1","title2"]
- ref = ast::ResourceReference.new( :title => titles, :type => "Class" )
- ref.expects(:qualified_class).with(@scope,"title1").returns("class")
- ref.expects(:qualified_class).with(@scope,"title2").returns("class")
-
- ref.evaluate(@scope)
+ it "should pass its scope's namespaces to all created resource references" do
+ @scope.add_namespace "foo"
+ newref("File", "/tmp/yay").evaluate(@scope).namespaces.should == ["foo"]
end
it "should return a correct representation when converting to string" do
diff --git a/spec/unit/parser/collector.rb b/spec/unit/parser/collector.rb
index 7f88bf7..9c2d722 100755
--- a/spec/unit/parser/collector.rb
+++ b/spec/unit/parser/collector.rb
@@ -52,11 +52,10 @@ end
describe Puppet::Parser::Collector, "when collecting specific virtual resources" do
before do
@scope = mock 'scope'
- @resource_type = mock 'resource_type'
@vquery = mock 'vquery'
@equery = mock 'equery'
- @collector = Puppet::Parser::Collector.new(@scope, @resource_type, @equery, @vquery, :virtual)
+ @collector = Puppet::Parser::Collector.new(@scope, "resource_type", @equery, @vquery, :virtual)
end
it "should not fail when it does not find any resources to collect" do
diff --git a/spec/unit/parser/compiler.rb b/spec/unit/parser/compiler.rb
index 79e63c5..6b36ac5 100755
--- a/spec/unit/parser/compiler.rb
+++ b/spec/unit/parser/compiler.rb
@@ -183,10 +183,9 @@ describe Puppet::Parser::Compiler do
it "should evaluate the main class if it exists" do
compile_stub(:evaluate_main)
- main_class = mock 'main_class'
+ main_class = @known_resource_types.add Puppet::Resource::Type.new(:hostclass, "")
main_class.expects(:evaluate_code).with { |r| r.is_a?(Puppet::Parser::Resource) }
@compiler.topscope.expects(:source=).with(main_class)
- @known_resource_types.stubs(:find_hostclass).with("", "").returns(main_class)
@compiler.compile
end
@@ -194,7 +193,7 @@ describe Puppet::Parser::Compiler do
it "should create a new, empty 'main' if no main class exists" do
compile_stub(:evaluate_main)
@compiler.compile
- @known_resource_types.find_hostclass("", "").should be_instance_of(Puppet::Resource::Type)
+ @known_resource_types.find_hostclass([""], "").should be_instance_of(Puppet::Resource::Type)
end
it "should evaluate any node classes" do
@@ -261,7 +260,7 @@ describe Puppet::Parser::Compiler do
it "should call finish() on all resources" do
# Add a resource that does respond to :finish
- resource = Puppet::Parser::Resource.new :scope => @scope, :type => "file", :title => "finish"
+ resource = Puppet::Parser::Resource.new "file", "finish", :scope => @scope
resource.expects(:finish)
@compiler.add_resource(@scope, resource)
@@ -277,12 +276,12 @@ describe Puppet::Parser::Compiler do
it "should call finish() in add_resource order" do
resources = sequence('resources')
- resource1 = Puppet::Parser::Resource.new :scope => @scope, :type => "file", :title => "finish1"
+ resource1 = Puppet::Parser::Resource.new "file", "finish1", :scope => @scope
resource1.expects(:finish).in_sequence(resources)
@compiler.add_resource(@scope, resource1)
- resource2 = Puppet::Parser::Resource.new :scope => @scope, :type => "file", :title => "finish2"
+ resource2 = Puppet::Parser::Resource.new "file", "finish2", :scope => @scope
resource2.expects(:finish).in_sequence(resources)
@compiler.add_resource(@scope, resource2)
diff --git a/spec/unit/parser/functions/defined.rb b/spec/unit/parser/functions/defined.rb
new file mode 100755
index 0000000..0da8c4a
--- /dev/null
+++ b/spec/unit/parser/functions/defined.rb
@@ -0,0 +1,50 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+describe "the 'defined' function" do
+
+ before :each do
+ @scope = Puppet::Parser::Scope.new()
+ @compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("foo"))
+ @scope.compiler = @compiler
+ end
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("defined").should == "function_defined"
+ end
+
+ it "should be true when the name is defined as a class" do
+ @scope.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "yayness")
+ @scope.function_defined("yayness").should be_true
+ end
+
+ it "should be true when the name is defined as a definition" do
+ @scope.known_resource_types.add Puppet::Resource::Type.new(:definition, "yayness")
+ @scope.function_defined("yayness").should be_true
+ end
+
+ it "should be true when the name is defined as a builtin type" do
+ @scope.function_defined("file").should be_true
+ end
+
+
+ it "should be true when any of the provided names are defined" do
+ @scope.known_resource_types.add Puppet::Resource::Type.new(:definition, "yayness")
+ @scope.function_defined(["meh", "yayness", "booness"]).should be_true
+ end
+
+ it "should be false when a single given name is not defined" do
+ @scope.function_defined("meh").should be_false
+ end
+
+ it "should be false when none of the names are defined" do
+ @scope.function_defined(["meh", "yayness", "booness"]).should be_false
+ end
+
+ it "should be true when a resource reference is provided and the resource is in the catalog" do
+ resource = Puppet::Resource.new("file", "/my/file")
+ @compiler.add_resource(@scope, resource)
+ @scope.function_defined(resource).should be_true
+ end
+end
diff --git a/spec/unit/parser/functions/require.rb b/spec/unit/parser/functions/require.rb
index 577a52a..605b8a1 100755
--- a/spec/unit/parser/functions/require.rb
+++ b/spec/unit/parser/functions/require.rb
@@ -26,7 +26,7 @@ describe "the require function" do
end
it "should set the 'require' prarameter on the resource to a resource reference" do
- @resource.expects(:set_parameter).with { |name, value| name == :require and value.is_a?(Puppet::Parser::Resource::Reference) }
+ @resource.expects(:set_parameter).with { |name, value| name == :require and value.is_a?(Puppet::Resource) }
@scope.stubs(:function_include)
@scope.function_require("myclass")
end
diff --git a/spec/unit/parser/functions/tag.rb b/spec/unit/parser/functions/tag.rb
new file mode 100755
index 0000000..5fb467e
--- /dev/null
+++ b/spec/unit/parser/functions/tag.rb
@@ -0,0 +1,24 @@
+#! /usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+describe "the 'tag' function" do
+
+ before :each do
+ @scope = Puppet::Parser::Scope.new()
+ end
+
+ it "should exist" do
+ Puppet::Parser::Functions.function(:tag).should == "function_tag"
+ end
+
+ it "should tag the resource with any provided tags" do
+ resource = Puppet::Parser::Resource.new(:file, "/file", :scope => @scope)
+ @scope.expects(:resource).returns resource
+
+ @scope.function_tag ["one", "two"]
+
+ resource.should be_tagged("one")
+ resource.should be_tagged("two")
+ end
+end
diff --git a/spec/unit/parser/parser.rb b/spec/unit/parser/parser.rb
index 84749c3..8cc29c9 100755
--- a/spec/unit/parser/parser.rb
+++ b/spec/unit/parser/parser.rb
@@ -429,6 +429,12 @@ describe Puppet::Parser do
@krt.hostclass("foobar").parent.should == "yayness"
end
+ it "should correctly set the parent class for multiple classes at a time" do
+ @parser.parse("class foobar inherits yayness {}\nclass boo inherits bar {}")
+ @krt.hostclass("foobar").parent.should == "yayness"
+ @krt.hostclass("boo").parent.should == "bar"
+ end
+
it "should define the code when some is provided" do
@parser.parse("class foobar { $var = val }")
@krt.hostclass("foobar").code.should_not be_nil
@@ -451,5 +457,15 @@ describe Puppet::Parser do
@krt.add(Puppet::Resource::Type.new(:hostclass, "foobar", :arguments => {"biz" => nil}))
lambda { @parser.parse("class { foobar: biz => stuff }") }.should_not raise_error
end
+
+ it "should correctly mark exported resources as exported" do
+ @parser.parse("@@file { '/file': }")
+ @krt.hostclass("").code[0].exported.should be_true
+ end
+
+ it "should correctly mark virtual resources as virtual" do
+ @parser.parse("@file { '/file': }")
+ @krt.hostclass("").code[0].virtual.should be_true
+ end
end
end
diff --git a/spec/unit/parser/resource.rb b/spec/unit/parser/resource.rb
index bb3001c..0c70c81 100755
--- a/spec/unit/parser/resource.rb
+++ b/spec/unit/parser/resource.rb
@@ -19,7 +19,7 @@ describe Puppet::Parser::Resource do
args[:source] ||= "source"
args[:scope] ||= stub('scope', :source => mock('source'))
- {:type => "resource", :title => "testing", :source => "source", :scope => "scope"}.each do |param, value|
+ {:source => "source", :scope => "scope"}.each do |param, value|
args[param] ||= value
end
@@ -30,7 +30,7 @@ describe Puppet::Parser::Resource do
args[:params] = paramify(args[:source], params)
end
- Puppet::Parser::Resource.new(args)
+ Puppet::Parser::Resource.new("resource", "testing", args)
end
def param(name, value, source)
@@ -61,19 +61,31 @@ describe Puppet::Parser::Resource do
Puppet::Parser::Resource.ancestors.should be_include(Puppet::FileCollection::Lookup)
end
+ it "should get its environment from its scope" do
+ scope = stub 'scope', :source => stub("source")
+ scope.expects(:environment).returns "foo"
+ Puppet::Parser::Resource.new("file", "whatever", :scope => scope).environment.should == "foo"
+ end
+
+ it "should get its namespaces from its scope" do
+ scope = stub 'scope', :source => stub("source")
+ scope.expects(:namespaces).returns %w{one two}
+ Puppet::Parser::Resource.new("file", "whatever", :scope => scope).namespaces.should == %w{one two}
+ end
+
it "should be isomorphic if it is builtin and models an isomorphic type" do
Puppet::Type.type(:file).expects(:isomorphic?).returns(true)
- @resource = Puppet::Parser::Resource.new(:type => "file", :title => "whatever", :scope => @scope, :source => @source).isomorphic?.should be_true
+ @resource = Puppet::Parser::Resource.new("file", "whatever", :scope => @scope, :source => @source).isomorphic?.should be_true
end
it "should not be isomorphic if it is builtin and models a non-isomorphic type" do
Puppet::Type.type(:file).expects(:isomorphic?).returns(false)
- @resource = Puppet::Parser::Resource.new(:type => "file", :title => "whatever", :scope => @scope, :source => @source).isomorphic?.should be_false
+ @resource = Puppet::Parser::Resource.new("file", "whatever", :scope => @scope, :source => @source).isomorphic?.should be_false
end
it "should be isomorphic if it is not builtin" do
newdefine "whatever"
- @resource = Puppet::Parser::Resource.new(:type => "whatever", :title => "whatever", :scope => @scope, :source => @source).isomorphic?.should be_true
+ @resource = Puppet::Parser::Resource.new("whatever", "whatever", :scope => @scope, :source => @source).isomorphic?.should be_true
end
it "should have a array-indexing method for retrieving parameter values" do
@@ -89,77 +101,68 @@ describe Puppet::Parser::Resource do
end
it "should be able to use the indexing operator to access parameters" do
- resource = Puppet::Parser::Resource.new(:type => "resource", :title => "testing", :source => "source", :scope => "scope")
+ resource = Puppet::Parser::Resource.new("resource", "testing", :source => "source", :scope => "scope")
resource["foo"] = "bar"
resource["foo"].should == "bar"
end
it "should return the title when asked for a parameter named 'title'" do
- Puppet::Parser::Resource.new(:type => "resource", :title => "testing", :source => "source", :scope => "scope")[:title].should == "testing"
+ Puppet::Parser::Resource.new("resource", "testing", :source => "source", :scope => "scope")[:title].should == "testing"
end
describe "when initializing" do
before do
- @arguments = {:type => "resource", :title => "testing", :scope => stub('scope', :source => mock('source'))}
+ @arguments = {:scope => stub('scope', :source => mock('source'))}
end
- [:type, :title, :scope].each do |name|
- it "should fail unless #{name.to_s} is specified" do
- try = @arguments.dup
- try.delete(name)
- lambda { Puppet::Parser::Resource.new(try) }.should raise_error(ArgumentError)
- end
+ it "should fail unless #{name.to_s} is specified" do
+ lambda { Puppet::Parser::Resource.new('file', '/my/file') }.should raise_error(ArgumentError)
end
it "should set the reference correctly" do
- res = Puppet::Parser::Resource.new(@arguments)
+ res = Puppet::Parser::Resource.new("resource", "testing", @arguments)
res.ref.should == "Resource[testing]"
end
it "should be tagged with user tags" do
tags = [ "tag1", "tag2" ]
@arguments[:params] = [ param(:tag, tags , :source) ]
- res = Puppet::Parser::Resource.new(@arguments)
+ res = Puppet::Parser::Resource.new("resource", "testing", @arguments)
(res.tags & tags).should == tags
end
end
describe "when refering to a resource with name canonicalization" do
before do
- @arguments = {:type => "file", :title => "/path/", :scope => stub('scope', :source => mock('source'))}
+ @arguments = {:scope => stub('scope', :source => mock('source'))}
end
it "should canonicalize its own name" do
- res = Puppet::Parser::Resource.new(@arguments)
+ res = Puppet::Parser::Resource.new("file", "/path/", @arguments)
res.ref.should == "File[/path]"
end
end
describe "when evaluating" do
- before do
- @type = Puppet::Parser::Resource
-
- @definition = newdefine "mydefine"
- @class = newclass "myclass"
- @nodedef = newnode("mynode")
- end
-
it "should evaluate the associated AST definition" do
- res = @type.new(:type => "mydefine", :title => "whatever", :scope => @scope, :source => @source)
- @definition.expects(:evaluate_code).with(res)
+ definition = newdefine "mydefine"
+ res = Puppet::Parser::Resource.new("mydefine", "whatever", :scope => @scope, :source => @source)
+ definition.expects(:evaluate_code).with(res)
res.evaluate
end
it "should evaluate the associated AST class" do
- res = @type.new(:type => "class", :title => "myclass", :scope => @scope, :source => @source)
+ @class = newclass "myclass"
+ res = Puppet::Parser::Resource.new("class", "myclass", :scope => @scope, :source => @source)
@class.expects(:evaluate_code).with(res)
res.evaluate
end
it "should evaluate the associated AST node" do
- res = @type.new(:type => "node", :title => "mynode", :scope => @scope, :source => @source)
- @nodedef.expects(:evaluate_code).with(res)
+ nodedef = newnode("mynode")
+ res = Puppet::Parser::Resource.new("node", "mynode", :scope => @scope, :source => @source)
+ nodedef.expects(:evaluate_code).with(res)
res.evaluate
end
end
@@ -169,7 +172,7 @@ describe Puppet::Parser::Resource do
@class = newclass "myclass"
@nodedef = newnode("mynode")
- @resource = Puppet::Parser::Resource.new(:type => "file", :title => "whatever", :scope => @scope, :source => @source)
+ @resource = Puppet::Parser::Resource.new("file", "whatever", :scope => @scope, :source => @source)
end
it "should do nothing if it has already been finished" do
@@ -292,7 +295,7 @@ describe Puppet::Parser::Resource do
before do
@scope_resource = stub 'scope_resource', :tags => %w{srone srtwo}
@scope = stub 'scope', :resource => @scope_resource
- @resource = Puppet::Parser::Resource.new(:type => "file", :title => "yay", :scope => @scope, :source => mock('source'))
+ @resource = Puppet::Parser::Resource.new("file", "yay", :scope => @scope, :source => mock('source'))
end
it "should get tagged with the resource type" do
@@ -304,19 +307,19 @@ describe Puppet::Parser::Resource do
end
it "should get tagged with each name in the title if the title is a qualified class name" do
- resource = Puppet::Parser::Resource.new(:type => "file", :title => "one::two", :scope => @scope, :source => mock('source'))
+ resource = Puppet::Parser::Resource.new("file", "one::two", :scope => @scope, :source => mock('source'))
resource.tags.should be_include("one")
resource.tags.should be_include("two")
end
it "should get tagged with each name in the type if the type is a qualified class name" do
- resource = Puppet::Parser::Resource.new(:type => "one::two", :title => "whatever", :scope => @scope, :source => mock('source'))
+ resource = Puppet::Parser::Resource.new("one::two", "whatever", :scope => @scope, :source => mock('source'))
resource.tags.should be_include("one")
resource.tags.should be_include("two")
end
it "should not get tagged with non-alphanumeric titles" do
- resource = Puppet::Parser::Resource.new(:type => "file", :title => "this is a test", :scope => @scope, :source => mock('source'))
+ resource = Puppet::Parser::Resource.new("file", "this is a test", :scope => @scope, :source => mock('source'))
resource.tags.should_not be_include("this is a test")
end
@@ -496,26 +499,26 @@ describe Puppet::Parser::Resource do
@parser_resource.to_resource.virtual.should be_true
end
- it "should convert any parser resource references to Puppet::Resource::Reference instances" do
- ref = Puppet::Parser::Resource::Reference.new(:title => "/my/file", :type => "file")
+ it "should convert any parser resource references to Puppet::Resource instances" do
+ ref = Puppet::Resource.new("file", "/my/file")
@parser_resource = mkresource :source => @source, :params => {:foo => "bar", :fee => ref}
result = @parser_resource.to_resource
- result[:fee].should == Puppet::Resource::Reference.new(:file, "/my/file")
+ result[:fee].should == Puppet::Resource.new(:file, "/my/file")
end
- it "should convert any parser resource references to Puppet::Resource::Reference instances even if they are in an array" do
- ref = Puppet::Parser::Resource::Reference.new(:title => "/my/file", :type => "file")
+ it "should convert any parser resource references to Puppet::Resource instances even if they are in an array" do
+ ref = Puppet::Resource.new("file", "/my/file")
@parser_resource = mkresource :source => @source, :params => {:foo => "bar", :fee => ["a", ref]}
result = @parser_resource.to_resource
- result[:fee].should == ["a", Puppet::Resource::Reference.new(:file, "/my/file")]
+ result[:fee].should == ["a", Puppet::Resource.new(:file, "/my/file")]
end
- it "should convert any parser resource references to Puppet::Resource::Reference instances even if they are in an array of array, and even deeper" do
- ref1 = Puppet::Parser::Resource::Reference.new(:title => "/my/file1", :type => "file")
- ref2 = Puppet::Parser::Resource::Reference.new(:title => "/my/file2", :type => "file")
+ it "should convert any parser resource references to Puppet::Resource instances even if they are in an array of array, and even deeper" do
+ ref1 = Puppet::Resource.new("file", "/my/file1")
+ ref2 = Puppet::Resource.new("file", "/my/file2")
@parser_resource = mkresource :source => @source, :params => {:foo => "bar", :fee => ["a", [ref1,ref2]]}
result = @parser_resource.to_resource
- result[:fee].should == ["a", Puppet::Resource::Reference.new(:file, "/my/file1"), Puppet::Resource::Reference.new(:file, "/my/file2")]
+ result[:fee].should == ["a", Puppet::Resource.new(:file, "/my/file1"), Puppet::Resource.new(:file, "/my/file2")]
end
it "should fail if the same param is declared twice" do
@@ -531,4 +534,52 @@ describe Puppet::Parser::Resource do
end.should raise_error(Puppet::ParseError)
end
end
+
+ describe "when validating" do
+ it "should check each parameter" do
+ resource = Puppet::Parser::Resource.new :foo, "bar", :scope => stub("scope"), :source => stub("source")
+ resource[:one] = :two
+ resource[:three] = :four
+ resource.expects(:validate_parameter).with(:one)
+ resource.expects(:validate_parameter).with(:three)
+ resource.send(:validate)
+ end
+
+ it "should raise a parse error when there's a failure" do
+ resource = Puppet::Parser::Resource.new :foo, "bar", :scope => stub("scope"), :source => stub("source")
+ resource[:one] = :two
+ resource.expects(:validate_parameter).with(:one).raises ArgumentError
+ lambda { resource.send(:validate) }.should raise_error(Puppet::ParseError)
+ end
+ end
+
+ describe "when setting parameters" do
+ before do
+ @source = newclass "foobar"
+ @resource = Puppet::Parser::Resource.new :foo, "bar", :scope => stub("scope"), :source => @source
+ end
+
+ it "should accept Param instances and add them to the parameter list" do
+ param = Puppet::Parser::Resource::Param.new :name => "foo", :value => "bar", :source => @source
+ @resource.set_parameter(param)
+ @resource["foo"].should == "bar"
+ end
+
+ it "should fail when provided a parameter name but no value" do
+ lambda { @resource.set_parameter("myparam") }.should raise_error(ArgumentError)
+ end
+
+ it "should use its source when provided a parameter name and value" do
+ @resource.set_parameter("myparam", "myvalue")
+ @resource["myparam"].should == "myvalue"
+ end
+ end
+
+ # part of #629 -- the undef keyword. Make sure 'undef' params get skipped.
+ it "should not include 'undef' parameters when converting itself to a hash" do
+ resource = Puppet::Parser::Resource.new "file", "/tmp/testing", :source => mock("source"), :scope => mock("scope")
+ resource[:owner] = :undef
+ resource[:mode] = "755"
+ resource.to_hash[:owner].should be_nil
+ end
end
diff --git a/spec/unit/parser/resource/reference.rb b/spec/unit/parser/resource/reference.rb
deleted file mode 100755
index a386042..0000000
--- a/spec/unit/parser/resource/reference.rb
+++ /dev/null
@@ -1,134 +0,0 @@
-#!/usr/bin/env ruby
-
-require File.dirname(__FILE__) + '/../../../spec_helper'
-
-describe Puppet::Parser::Resource::Reference do
- before do
- @type = Puppet::Parser::Resource::Reference
- end
-
- it "should get its environment from its scope" do
- env = stub 'environment'
- scope = stub 'scope', :environment => env
- @type.new(:title => "foo", :type => "bar", :scope => scope).environment.should equal(env)
- end
-
- it "should use the resource type collection helper to find its known resource types" do
- Puppet::Parser::Resource::Reference.ancestors.should include(Puppet::Resource::TypeCollectionHelper)
- end
-
- it "should use the file lookup module" do
- Puppet::Parser::Resource::Reference.ancestors.should be_include(Puppet::FileCollection::Lookup)
- end
-
- it "should require a type" do
- proc { @type.new(:title => "yay") }.should raise_error(Puppet::DevError)
- end
-
- it "should require a title" do
- proc { @type.new(:type => "file") }.should raise_error(Puppet::DevError)
- end
-
- it "should know when it refers to a builtin type" do
- ref = @type.new(:type => "file", :title => "/tmp/yay")
- ref.builtin?.should be_true
- ref.builtintype.should equal(Puppet::Type.type(:file))
- end
-
- it "should return a downcased relationship-style resource reference for defined types" do
- ref = @type.new(:type => "file", :title => "/tmp/yay")
- ref.to_ref.should == ["file", "/tmp/yay"]
- end
-
- it "should return a capitalized relationship-style resource reference for defined types" do
- ref = @type.new(:type => "whatever", :title => "/tmp/yay")
- ref.to_ref.should == ["Whatever", "/tmp/yay"]
- end
-
- it "should return a resource reference string when asked" do
- ref = @type.new(:type => "file", :title => "/tmp/yay")
- ref.to_s.should == "File[/tmp/yay]"
- end
-
- it "should canonize resource reference types" do
- ref = @type.new(:type => "foo::bar", :title => "/tmp/yay")
- ref.to_s.should == "Foo::Bar[/tmp/yay]"
- end
-
- it "should canonize resource reference values" do
- ref = @type.new(:type => "file", :title => "/tmp/yay/")
- ref.to_s.should == "File[/tmp/yay]"
- end
-
- it "should canonize resource reference values without order dependencies" do
- args = [[:title, "/tmp/yay/"], [:type, "file"]]
- ref = @type.new(args)
- ref.to_s.should == "File[/tmp/yay]"
- end
-
-end
-
-describe Puppet::Parser::Resource::Reference, " when modeling defined types" do
- def newclass(name)
- @known_resource_types.add Puppet::Resource::Type.new(:hostclass, name)
- end
-
- def newdefine(name)
- @known_resource_types.add Puppet::Resource::Type.new(:definition, name)
- end
-
- def newnode(name)
- @known_resource_types.add Puppet::Resource::Type.new(:node, name)
- end
-
- before do
- @type = Puppet::Parser::Resource::Reference
-
- @known_resource_types = Puppet::Resource::TypeCollection.new("myenv")
- @definition = newdefine("mydefine")
- @class = newclass("myclass")
- @nodedef = newnode("mynode")
- @node = Puppet::Node.new("yaynode")
-
- @compiler = Puppet::Parser::Compiler.new(@node)
- @compiler.environment.stubs(:known_resource_types).returns @known_resource_types
- end
-
- it "should be able to find defined types" do
- ref = @type.new(:type => "mydefine", :title => "/tmp/yay", :scope => @compiler.topscope)
- ref.builtin?.should be_false
- ref.definedtype.should equal(@definition)
- end
-
- it "should be able to find classes" do
- ref = @type.new(:type => "class", :title => "myclass", :scope => @compiler.topscope)
- ref.builtin?.should be_false
- ref.definedtype.should equal(@class)
- end
-
- it "should be able to find nodes" do
- ref = @type.new(:type => "node", :title => "mynode", :scope => @compiler.topscope)
- ref.builtin?.should be_false
- ref.definedtype.object_id.should == @nodedef.object_id
- end
-
- it "should only look for fully qualified classes" do
- top = newclass "top"
- sub = newclass "other::top"
-
- scope = @compiler.topscope.class.new(:parent => @compiler.topscope, :namespace => "other", :compiler => @compiler)
-
- ref = @type.new(:type => "class", :title => "top", :scope => scope)
- ref.definedtype.name.should equal(top.name)
- end
-
- it "should only look for fully qualified definitions" do
- top = newdefine "top"
- sub = newdefine "other::top"
-
- scope = @compiler.topscope.class.new(:parent => @compiler.topscope, :namespace => "other", :compiler => @compiler)
-
- ref = @type.new(:type => "top", :title => "foo", :scope => scope)
- ref.definedtype.name.should equal(top.name)
- end
-end
diff --git a/spec/unit/parser/scope.rb b/spec/unit/parser/scope.rb
index 4e8a11b..8c5d289 100755
--- a/spec/unit/parser/scope.rb
+++ b/spec/unit/parser/scope.rb
@@ -8,6 +8,7 @@ describe Puppet::Parser::Scope do
# This is necessary so we don't try to use the compiler to discover our parent.
@topscope.parent = nil
@scope = Puppet::Parser::Scope.new()
+ @scope.compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("foo"))
@scope.parent = @topscope
end
@@ -64,7 +65,7 @@ describe Puppet::Parser::Scope do
def create_class_scope(name)
klass = newclass(name)
- Puppet::Parser::Resource.new(:type => "class", :title => name, :scope => @scope, :source => mock('source')).evaluate
+ Puppet::Parser::Resource.new("class", name, :scope => @scope, :source => mock('source')).evaluate
return @compiler.class_scope(klass)
end
@@ -265,6 +266,114 @@ describe Puppet::Parser::Scope do
@scope.strinterp('==${10}==').should == "==value=="
end
+
+ describe "with qualified variables" do
+ before do
+ @scopes = {}
+ klass = @scope.known_resource_types.add(Puppet::Resource::Type.new(:hostclass, ""))
+ Puppet::Parser::Resource.new("class", :main, :scope => @scope, :source => mock('source')).evaluate
+ @scopes[""] = @scope.compiler.class_scope(klass)
+ @scopes[""].setvar("test", "value")
+
+ %w{one one::two one::two::three}.each do |name|
+ klass = @scope.known_resource_types.add(Puppet::Resource::Type.new(:hostclass, name))
+ Puppet::Parser::Resource.new("class", name, :scope => @scope, :source => mock('source')).evaluate
+ @scopes[name] = @scope.compiler.class_scope(klass)
+ @scopes[name].setvar("test", "value-#{name.sub(/.+::/,'')}")
+ end
+ end
+ {
+ "===${one::two::three::test}===" => "===value-three===",
+ "===$one::two::three::test===" => "===value-three===",
+ "===${one::two::test}===" => "===value-two===",
+ "===$one::two::test===" => "===value-two===",
+ "===${one::test}===" => "===value-one===",
+ "===$one::test===" => "===value-one===",
+ "===${::test}===" => "===value===",
+ "===$::test===" => "===value==="
+ }.each do |input, output|
+ it "should parse '#{input}' correctly" do
+ @scope.strinterp(input).should == output
+ end
+ end
+ end
+
+ tests = {
+ "===${test}===" => "===value===",
+ "===${test} ${test} ${test}===" => "===value value value===",
+ "===$test ${test} $test===" => "===value value value===",
+ "===\\$test===" => "===$test===",
+ '===\\$test string===' => "===$test string===",
+ '===$test string===' => "===value string===",
+ '===a testing $===' => "===a testing $===",
+ '===a testing \$===' => "===a testing $===",
+ "===an escaped \\\n carriage return===" => "===an escaped carriage return===",
+ '\$' => "$",
+ '\s' => "\s",
+ '\t' => "\t",
+ '\n' => "\n"
+ }
+
+ tests.each do |input, output|
+ it "should parse '#{input}' correctly" do
+ @scope.setvar("test", "value")
+ @scope.strinterp(input).should == output
+ end
+ end
+
+ # #523
+ %w{d f h l w z}.each do |l|
+ it "should parse '#{l}' when escaped" do
+ string = "\\" + l
+ @scope.strinterp(string).should == string
+ end
+ end
+ end
+
+ def test_strinterp
+ # Make and evaluate our classes so the qualified lookups work
+ parser = mkparser
+ klass = parser.newclass("")
+ scope = mkscope(:parser => parser)
+ Puppet::Parser::Resource.new(:type => "class", :title => :main, :scope => scope, :source => mock('source')).evaluate
+
+ assert_nothing_raised {
+ scope.setvar("test","value")
+ }
+
+ scopes = {"" => scope}
+
+ %w{one one::two one::two::three}.each do |name|
+ klass = parser.newclass(name)
+ Puppet::Parser::Resource.new(:type => "class", :title => name, :scope => scope, :source => mock('source')).evaluate
+ scopes[name] = scope.compiler.class_scope(klass)
+ scopes[name].setvar("test", "value-%s" % name.sub(/.+::/,''))
+ end
+
+ assert_equal("value", scope.lookupvar("::test"), "did not look up qualified value correctly")
+ tests.each do |input, output|
+ assert_nothing_raised("Failed to scan %s" % input.inspect) do
+ assert_equal(output, scope.strinterp(input),
+ 'did not parserret %s correctly' % input.inspect)
+ end
+ end
+
+ logs = []
+ Puppet::Util::Log.close
+ Puppet::Util::Log.newdestination(logs)
+
+ # #523
+ %w{d f h l w z}.each do |l|
+ string = "\\" + l
+ assert_nothing_raised do
+ assert_equal(string, scope.strinterp(string),
+ 'did not parserret %s correctly' % string)
+ end
+
+ assert(logs.detect { |m| m.message =~ /Unrecognised escape/ },
+ "Did not get warning about escape sequence with %s" % string)
+ logs.clear
+ end
end
describe "when setting ephemeral vars from matches" do
@@ -307,4 +416,50 @@ describe Puppet::Parser::Scope do
@scope.lookupvar("foo").should == ""
end
end
+
+ it "should use its namespaces to find hostclasses" do
+ klass = @scope.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "a::b::c")
+ @scope.add_namespace "a::b"
+ @scope.find_hostclass("c").should equal(klass)
+ end
+
+ it "should use its namespaces to find definitions" do
+ define = @scope.known_resource_types.add Puppet::Resource::Type.new(:definition, "a::b::c")
+ @scope.add_namespace "a::b"
+ @scope.find_definition("c").should equal(define)
+ end
+
+ describe "when managing defaults" do
+ it "should be able to set and lookup defaults" do
+ param = Puppet::Parser::Resource::Param.new(:name => :myparam, :value => "myvalue", :source => stub("source"))
+ @scope.setdefaults(:mytype, param)
+ @scope.lookupdefaults(:mytype).should == {:myparam => param}
+ end
+
+ it "should fail if a default is already defined and a new default is being defined" do
+ param = Puppet::Parser::Resource::Param.new(:name => :myparam, :value => "myvalue", :source => stub("source"))
+ @scope.setdefaults(:mytype, param)
+ lambda { @scope.setdefaults(:mytype, param) }.should raise_error(Puppet::ParseError)
+ end
+
+ it "should return multiple defaults at once" do
+ param1 = Puppet::Parser::Resource::Param.new(:name => :myparam, :value => "myvalue", :source => stub("source"))
+ @scope.setdefaults(:mytype, param1)
+ param2 = Puppet::Parser::Resource::Param.new(:name => :other, :value => "myvalue", :source => stub("source"))
+ @scope.setdefaults(:mytype, param2)
+
+ @scope.lookupdefaults(:mytype).should == {:myparam => param1, :other => param2}
+ end
+
+ it "should look up defaults defined in parent scopes" do
+ param1 = Puppet::Parser::Resource::Param.new(:name => :myparam, :value => "myvalue", :source => stub("source"))
+ @scope.setdefaults(:mytype, param1)
+
+ child_scope = @scope.newscope
+ param2 = Puppet::Parser::Resource::Param.new(:name => :other, :value => "myvalue", :source => stub("source"))
+ child_scope.setdefaults(:mytype, param2)
+
+ child_scope.lookupdefaults(:mytype).should == {:myparam => param1, :other => param2}
+ end
+ end
end
diff --git a/spec/unit/rails/param_value.rb b/spec/unit/rails/param_value.rb
index 26e87fe..070ac82 100755
--- a/spec/unit/rails/param_value.rb
+++ b/spec/unit/rails/param_value.rb
@@ -42,7 +42,7 @@ describe "Puppet::Rails::ParamValue" do
end
it "should not convert Resource References into strings" do
- ref = Puppet::Resource::Reference.new(:file, "/file")
+ ref = Puppet::Resource.new(:file, "/file")
Puppet::Rails::ParamValue.from_parser_param(:myparam, ref)[0][:value].should == ref
end
end
diff --git a/spec/unit/resource.rb b/spec/unit/resource.rb
index df632e1..3af1716 100755
--- a/spec/unit/resource.rb
+++ b/spec/unit/resource.rb
@@ -12,71 +12,89 @@ describe Puppet::Resource do
end
end
- describe "when initializing" do
- it "should require the type and title" do
- lambda { Puppet::Resource.new }.should raise_error(ArgumentError)
- end
+ it "should have a :title attribute" do
+ Puppet::Resource.new(:file, "foo").title.should == "foo"
+ end
- it "should create a resource reference with its type and title" do
- ref = Puppet::Resource::Reference.new("file", "/f")
- Puppet::Resource::Reference.expects(:new).with("file", "/f").returns ref
- Puppet::Resource.new("file", "/f")
- end
+ it "should require the type and title" do
+ lambda { Puppet::Resource.new }.should raise_error(ArgumentError)
+ end
- it "should tag itself with its type" do
- Puppet::Resource.new("file", "/f").should be_tagged("file")
- end
+ it "should canonize types to capitalized strings" do
+ Puppet::Resource.new(:file, "foo").type.should == "File"
+ end
- it "should tag itself with its title if the title is a valid tag" do
- Puppet::Resource.new("file", "bar").should be_tagged("bar")
- end
+ it "should canonize qualified types so all strings are capitalized" do
+ Puppet::Resource.new("foo::bar", "foo").type.should == "Foo::Bar"
+ end
- it "should not tag itself with its title if the title is a not valid tag" do
- Puppet::Resource.new("file", "/bar").should_not be_tagged("/bar")
- end
+ it "should tag itself with its type" do
+ Puppet::Resource.new("file", "/f").should be_tagged("file")
+ end
- it "should allow setting of attributes" do
- Puppet::Resource.new("file", "/bar", :file => "/foo").file.should == "/foo"
- Puppet::Resource.new("file", "/bar", :exported => true).should be_exported
- end
+ it "should tag itself with its title if the title is a valid tag" do
+ Puppet::Resource.new("file", "bar").should be_tagged("bar")
end
- it "should use the resource reference to determine its type" do
- ref = Puppet::Resource::Reference.new("file", "/f")
- Puppet::Resource::Reference.expects(:new).returns ref
- resource = Puppet::Resource.new("file", "/f")
- ref.expects(:type).returns "mytype"
- resource.type.should == "mytype"
+ it "should not tag itself with its title if the title is a not valid tag" do
+ Puppet::Resource.new("file", "/bar").should_not be_tagged("/bar")
end
- it "should use its resource reference to determine its title" do
- ref = Puppet::Resource::Reference.new("file", "/f")
- Puppet::Resource::Reference.expects(:new).returns ref
- resource = Puppet::Resource.new("file", "/f")
- ref.expects(:title).returns "mytitle"
- resource.title.should == "mytitle"
+ it "should allow setting of attributes" do
+ Puppet::Resource.new("file", "/bar", :file => "/foo").file.should == "/foo"
+ Puppet::Resource.new("file", "/bar", :exported => true).should be_exported
end
- it "should use its resource reference to determine whether it is builtin" do
- ref = Puppet::Resource::Reference.new("file", "/f")
- Puppet::Resource::Reference.expects(:new).returns ref
- resource = Puppet::Resource.new("file", "/f")
- ref.expects(:builtin_type?).returns "yep"
- resource.builtin_type?.should == "yep"
+ it "should set its type to 'Class' and its title to the passed title if the passed type is :component and the title has no square brackets in it" do
+ ref = Puppet::Resource.new(:component, "foo")
+ ref.type.should == "Class"
+ ref.title.should == "foo"
end
- it "should call its builtin_type? method when 'builtin?' is called" do
- resource = Puppet::Resource.new("file", "/f")
- resource.expects(:builtin_type?).returns "foo"
- resource.builtin?.should == "foo"
+ it "should interpret the title as a reference and assign appropriately if the type is :component and the title contains square brackets" do
+ ref = Puppet::Resource.new(:component, "foo::bar[yay]")
+ ref.type.should == "Foo::Bar"
+ ref.title.should == "yay"
end
- it "should use its resource reference to produce its canonical reference string" do
- ref = Puppet::Resource::Reference.new("file", "/f")
- Puppet::Resource::Reference.expects(:new).returns ref
- resource = Puppet::Resource.new("file", "/f")
- ref.expects(:to_s).returns "Foo[bar]"
- resource.ref.should == "Foo[bar]"
+ it "should set the type to 'Class' if it is nil and the title contains no square brackets" do
+ ref = Puppet::Resource.new(nil, "yay")
+ ref.type.should == "Class"
+ ref.title.should == "yay"
+ end
+
+ it "should interpret the title as a reference and assign appropriately if the type is nil and the title contains square brackets" do
+ ref = Puppet::Resource.new(nil, "foo::bar[yay]")
+ ref.type.should == "Foo::Bar"
+ ref.title.should == "yay"
+ end
+
+ it "should interpret the title as a reference and assign appropriately if the type is nil and the title contains nested square brackets" do
+ ref = Puppet::Resource.new(nil, "foo::bar[baz[yay]]")
+ ref.type.should == "Foo::Bar"
+ ref.title.should =="baz[yay]"
+ end
+
+ it "should interpret the type as a reference and assign appropriately if the title is nil and the type contains square brackets" do
+ ref = Puppet::Resource.new("foo::bar[baz]")
+ ref.type.should == "Foo::Bar"
+ ref.title.should =="baz"
+ end
+
+ it "should be able to extract its information from a Puppet::Type instance" do
+ ral = Puppet::Type.type(:file).new :path => "/foo"
+ ref = Puppet::Resource.new(ral)
+ ref.type.should == "File"
+ ref.title.should == "/foo"
+ end
+
+
+ it "should fail if the title is nil and the type is not a valid resource reference string" do
+ lambda { Puppet::Resource.new("foo") }.should raise_error(ArgumentError)
+ end
+
+ it "should be able to produce a backward-compatible reference array" do
+ Puppet::Resource.new("foobar", "/f").to_trans_ref.should == %w{Foobar /f}
end
it "should be taggable" do
@@ -94,12 +112,16 @@ describe Puppet::Resource do
Puppet::Resource.new("file", "/my/file", :environment => :foo).environment.name.should == :foo
end
- it "should support a namespace attribute" do
- Puppet::Resource.new("file", "/my/file", :namespace => :foo).namespace.should == :foo
+ it "should support specifying namespaces" do
+ Puppet::Resource.new("file", "/my/file", :namespaces => [:foo]).namespaces.should == [:foo]
+ end
+
+ it "should convert namespaces to an array if not specified as one" do
+ Puppet::Resource.new("file", "/my/file", :namespaces => :foo).namespaces.should == [:foo]
end
- it "should default to a namespace of an empty string" do
- Puppet::Resource.new("file", "/my/file").namespace.should == ""
+ it "should default to a single amespace of an empty string" do
+ Puppet::Resource.new("file", "/my/file").namespaces.should == [""]
end
it "should be able to look up its resource type when the type is a builtin resource" do
@@ -130,16 +152,16 @@ describe Puppet::Resource do
resource.resource_type.should equal(klass)
end
- it "should use its namespace when looking up defined resource types" do
- resource = Puppet::Resource.new("bar", "/my/file", :namespace => "foo")
+ it "should use its namespaces when looking up defined resource types" do
+ resource = Puppet::Resource.new("bar", "/my/file", :namespaces => ["foo"])
type = Puppet::Resource::Type.new(:definition, "foo::bar")
resource.environment.known_resource_types.add type
resource.resource_type.should equal(type)
end
- it "should use its namespace when looking up host classes" do
- resource = Puppet::Resource.new("class", "bar", :namespace => "foo")
+ it "should use its namespaces when looking up host classes" do
+ resource = Puppet::Resource.new("class", "bar", :namespaces => ["foo"])
type = Puppet::Resource::Type.new(:hostclass, "foo::bar")
resource.environment.known_resource_types.add type
@@ -171,6 +193,30 @@ describe Puppet::Resource do
resource[:yay] = true
end
+ it "should be considered equivalent to another resource if their type and title match and no parameters are set" do
+ Puppet::Resource.new("file", "/f").should == Puppet::Resource.new("file", "/f")
+ end
+
+ it "should be considered equivalent to another resource if their type, title, and parameters are equal" do
+ Puppet::Resource.new("file", "/f", :parameters => {:foo => "bar"}).should == Puppet::Resource.new("file", "/f", :parameters => {:foo => "bar"})
+ end
+
+ it "should not be considered equivalent to another resource if their type and title match but parameters are different" do
+ Puppet::Resource.new("file", "/f", :parameters => {:fee => "baz"}).should_not == Puppet::Resource.new("file", "/f", :parameters => {:foo => "bar"})
+ end
+
+ it "should not be considered equivalent to a non-resource" do
+ Puppet::Resource.new("file", "/f").should_not == "foo"
+ end
+
+ it "should not be considered equivalent to another resource if their types do not match" do
+ Puppet::Resource.new("file", "/f").should_not == Puppet::Resource.new("exec", "/f")
+ end
+
+ it "should not be considered equivalent to another resource if their titles do not match" do
+ Puppet::Resource.new("file", "/foo").should_not == Puppet::Resource.new("file", "/f")
+ end
+
describe "when managing parameters" do
before do
@resource = Puppet::Resource.new("file", "/my/file")
@@ -305,7 +351,10 @@ describe Puppet::Resource do
end
it "should set :name to the title if :name is not present for non-builtin types" do
+ krt = Puppet::Resource::TypeCollection.new("myenv")
+ krt.add Puppet::Resource::Type.new(:definition, :foo)
resource = Puppet::Resource.new :foo, "bar"
+ resource.stubs(:known_resource_types).returns krt
resource.to_hash[:name].should == "bar"
end
end
@@ -334,25 +383,19 @@ describe Puppet::Resource do
end
describe "when converting to a RAL resource" do
- before do
- @resource = Puppet::Resource.new("file", "/my/file")
- @resource["one"] = "test"
- @resource["two"] = "other"
- end
-
- it "should use the resource type's :create method to create the resource if the resource is of a builtin type" do
- type = mock 'resource type'
- type.expects(:new).with(@resource).returns(:myresource)
- Puppet::Type.expects(:type).with(@resource.type).returns(type)
- @resource.to_ral.should == :myresource
+ it "should use the resource type's :new method to create the resource if the resource is of a builtin type" do
+ resource = Puppet::Resource.new("file", "/my/file")
+ result = resource.to_ral
+ result.should be_instance_of(Puppet::Type.type(:file))
+ result[:path].should == "/my/file"
end
it "should convert to a component instance if the resource type is not of a builtin type" do
- component = mock 'component type'
- Puppet::Type::Component.expects(:new).with(@resource).returns "meh"
+ resource = Puppet::Resource.new("foobar", "somename")
+ result = resource.to_ral
- Puppet::Type.expects(:type).with(@resource.type).returns(nil)
- @resource.to_ral.should == "meh"
+ result.should be_instance_of(Puppet::Type.type(:component))
+ result.title.should == "Foobar[somename]"
end
end
@@ -450,13 +493,13 @@ describe Puppet::Resource do
end
it "should convert resource references into the backward-compatible form" do
- @resource[:foo] = Puppet::Resource::Reference.new(:file, "/f")
- @resource.to_trans["foo"].should == %w{file /f}
+ @resource[:foo] = Puppet::Resource.new(:file, "/f")
+ @resource.to_trans["foo"].should == %w{File /f}
end
it "should convert resource references into the backward-compatible form even when within arrays" do
- @resource[:foo] = ["a", Puppet::Resource::Reference.new(:file, "/f")]
- @resource.to_trans["foo"].should == ["a", %w{file /f}]
+ @resource[:foo] = ["a", Puppet::Resource.new(:file, "/f")]
+ @resource.to_trans["foo"].should == ["a", %w{File /f}]
end
end
end
@@ -599,4 +642,16 @@ describe Puppet::Resource do
resource['foo'].should == %w{one}
end
end
+
+ describe "when resolving resources with a catalog" do
+ it "should resolve all resources using the catalog" do
+ catalog = mock 'catalog'
+ resource = Puppet::Resource.new("foo::bar", "yay")
+ resource.catalog = catalog
+
+ catalog.expects(:resource).with("Foo::Bar[yay]").returns(:myresource)
+
+ resource.resolve.should == :myresource
+ end
+ end
end
diff --git a/spec/unit/resource/catalog.rb b/spec/unit/resource/catalog.rb
index 5822b89..f3347ed 100755
--- a/spec/unit/resource/catalog.rb
+++ b/spec/unit/resource/catalog.rb
@@ -109,7 +109,7 @@ describe Puppet::Resource::Catalog, "when compiling" do
end
def mkresource(type, name)
- Puppet::Parser::Resource.new(:type => type, :title => name, :source => @source, :scope => @scope)
+ Puppet::Parser::Resource.new(type, name, :source => @source, :scope => @scope)
end
it "should always create a TransBucket for the 'main' class" do
diff --git a/spec/unit/resource/reference.rb b/spec/unit/resource/reference.rb
deleted file mode 100755
index 7a97045..0000000
--- a/spec/unit/resource/reference.rb
+++ /dev/null
@@ -1,111 +0,0 @@
-#!/usr/bin/env ruby
-
-require File.dirname(__FILE__) + '/../../spec_helper'
-
-require 'puppet/resource/reference'
-
-describe Puppet::Resource::Reference do
- it "should have a :title attribute" do
- Puppet::Resource::Reference.new(:file, "foo").title.should == "foo"
- end
-
- it "should canonize types to capitalized strings" do
- Puppet::Resource::Reference.new(:file, "foo").type.should == "File"
- end
-
- it "should canonize qualified types so all strings are capitalized" do
- Puppet::Resource::Reference.new("foo::bar", "foo").type.should == "Foo::Bar"
- end
-
- it "should set its type to 'Class' and its title to the passed title if the passed type is :component and the title has no square brackets in it" do
- ref = Puppet::Resource::Reference.new(:component, "foo")
- ref.type.should == "Class"
- ref.title.should == "foo"
- end
-
- it "should interpret the title as a reference and assign appropriately if the type is :component and the title contains square brackets" do
- ref = Puppet::Resource::Reference.new(:component, "foo::bar[yay]")
- ref.type.should == "Foo::Bar"
- ref.title.should == "yay"
- end
-
- it "should set the type to 'Class' if it is nil and the title contains no square brackets" do
- ref = Puppet::Resource::Reference.new(nil, "yay")
- ref.type.should == "Class"
- ref.title.should == "yay"
- end
-
- it "should interpret the title as a reference and assign appropriately if the type is nil and the title contains square brackets" do
- ref = Puppet::Resource::Reference.new(nil, "foo::bar[yay]")
- ref.type.should == "Foo::Bar"
- ref.title.should == "yay"
- end
-
- it "should interpret the title as a reference and assign appropriately if the type is nil and the title contains nested square brackets" do
- ref = Puppet::Resource::Reference.new(nil, "foo::bar[baz[yay]]")
- ref.type.should == "Foo::Bar"
- ref.title.should =="baz[yay]"
- end
-
- it "should interpret the type as a reference and assign appropriately if the title is nil and the type contains square brackets" do
- ref = Puppet::Resource::Reference.new("foo::bar[baz]")
- ref.type.should == "Foo::Bar"
- ref.title.should =="baz"
- end
-
- it "should be able to extract its information from a Puppet::Type instance" do
- ral = Puppet::Type.type(:file).new :path => "/foo"
- ref = Puppet::Resource::Reference.new(ral)
- ref.type.should == "File"
- ref.title.should == "/foo"
- end
-
-
- it "should fail if the title is nil and the type is not a valid resource reference string" do
- lambda { Puppet::Resource::Reference.new("foo") }.should raise_error(ArgumentError)
- end
-
- it "should be considered builtin if an existing resource type matches the type" do
- Puppet::Resource::Reference.new("file", "/f").should be_builtin_type
- end
-
- it "should be not considered builtin if an existing resource type does not match the type" do
- Puppet::Resource::Reference.new("foobar", "/f").should_not be_builtin_type
- end
-
- it "should be able to produce a backward-compatible reference array" do
- Puppet::Resource::Reference.new("foobar", "/f").to_trans_ref.should == %w{Foobar /f}
- end
-
- it "should downcase resource types when producing a backward-compatible reference array for builtin resource types" do
- Puppet::Resource::Reference.new("file", "/f").to_trans_ref.should == %w{file /f}
- end
-
- it "should be considered equivalent to another reference if their type and title match" do
- Puppet::Resource::Reference.new("file", "/f").should == Puppet::Resource::Reference.new("file", "/f")
- end
-
- it "should not be considered equivalent to a non-reference" do
- Puppet::Resource::Reference.new("file", "/f").should_not == "foo"
- end
-
- it "should not be considered equivalent to another reference if their types do not match" do
- Puppet::Resource::Reference.new("file", "/f").should_not == Puppet::Resource::Reference.new("exec", "/f")
- end
-
- it "should not be considered equivalent to another reference if their titles do not match" do
- Puppet::Resource::Reference.new("file", "/foo").should_not == Puppet::Resource::Reference.new("file", "/f")
- end
-
- describe "when resolving resources with a catalog" do
- it "should resolve all resources using the catalog" do
- config = mock 'catalog'
- ref = Puppet::Resource::Reference.new("foo::bar", "yay")
- ref.catalog = config
-
- config.expects(:resource).with("Foo::Bar[yay]").returns(:myresource)
-
- ref.resolve.should == :myresource
- end
- end
-end
diff --git a/spec/unit/resource/type.rb b/spec/unit/resource/type.rb
index 41ea8e1..2e592c0 100755
--- a/spec/unit/resource/type.rb
+++ b/spec/unit/resource/type.rb
@@ -451,13 +451,13 @@ describe Puppet::Resource::Type do
end
it "should fail unless it is a class" do
- lambda { Puppet::Resource::Type.new(:node, "bar").merge("foo") }.should raise_error(ArgumentError)
+ lambda { Puppet::Resource::Type.new(:node, "bar").merge("foo") }.should raise_error(Puppet::Error)
end
it "should fail unless the source instance is a class" do
dest = Puppet::Resource::Type.new(:hostclass, "bar")
source = Puppet::Resource::Type.new(:node, "foo")
- lambda { dest.merge(source) }.should raise_error(ArgumentError)
+ lambda { dest.merge(source) }.should raise_error(Puppet::Error)
end
it "should fail if both classes have different parent classes" do
@@ -466,7 +466,7 @@ describe Puppet::Resource::Type do
code.add Puppet::Resource::Type.new(:hostclass, parent)
code.add Puppet::Resource::Type.new(:hostclass, child, :parent => parent)
end
- lambda { code.hostclass("b").merge(code.hostclass("d")) }.should raise_error(ArgumentError)
+ lambda { code.hostclass("b").merge(code.hostclass("d")) }.should raise_error(Puppet::Error)
end
it "should copy the other class's parent if it has not parent" do
diff --git a/spec/unit/resource/type_collection.rb b/spec/unit/resource/type_collection.rb
index 3de5e50..a2a213f 100644
--- a/spec/unit/resource/type_collection.rb
+++ b/spec/unit/resource/type_collection.rb
@@ -64,7 +64,32 @@ describe Puppet::Resource::TypeCollection do
@code.definition("foo").should equal(define)
end
+ it "should merge new classes with existing classes of the same name" do
+ loader = Puppet::Resource::TypeCollection.new("env")
+ first = Puppet::Resource::Type.new(:hostclass, "foo")
+ second = Puppet::Resource::Type.new(:hostclass, "foo")
+ loader.add first
+ first.expects(:merge).with(second)
+ loader.add(second)
+ end
+
+ it "should remove all nodes, classes, and definitions when cleared" do
+ loader = Puppet::Resource::TypeCollection.new("env")
+ loader.add Puppet::Resource::Type.new(:hostclass, "class")
+ loader.add Puppet::Resource::Type.new(:definition, "define")
+ loader.add Puppet::Resource::Type.new(:node, "node")
+
+ loader.clear
+ loader.hostclass("class").should be_nil
+ loader.definition("define").should be_nil
+ loader.node("node").should be_nil
+ end
+
%w{hostclass node definition}.each do |data|
+ before do
+ @instance = Puppet::Resource::Type.new(data, "foo")
+ end
+
it "should have a method for adding a #{data}" do
Puppet::Resource::TypeCollection.new("env").should respond_to("add_" + data)
end
@@ -75,10 +100,12 @@ describe Puppet::Resource::TypeCollection do
loader.send(data, @instance.name).should equal(@instance)
end
- it "should fail to add a #{data} when one already exists" do
- loader = Puppet::Resource::TypeCollection.new("env")
- loader.add @instance
- lambda { loader.add(@instance) }.should raise_error(Puppet::ParseError)
+ unless data == "hostclass"
+ it "should fail to add a #{data} when one already exists" do
+ loader = Puppet::Resource::TypeCollection.new("env")
+ loader.add @instance
+ lambda { loader.add(@instance) }.should raise_error(Puppet::ParseError)
+ end
end
it "should return the added #{data}" do
@@ -127,6 +154,13 @@ describe Puppet::Resource::TypeCollection do
loader.find("namespace", "::foo::bar", :hostclass).should be_nil
end
+ it "should be able to find classes in the base namespace" do
+ loader = Puppet::Resource::TypeCollection.new("env")
+ instance = Puppet::Resource::Type.new(:hostclass, "foo")
+ loader.add instance
+ loader.find("", "foo", :hostclass).should equal(instance)
+ end
+
it "should return the partially qualified object if it exists in a provided namespace" do
loader = Puppet::Resource::TypeCollection.new("env")
instance = Puppet::Resource::Type.new(:hostclass, "foo::bar::baz")
diff --git a/spec/unit/transportable.rb b/spec/unit/transportable.rb
new file mode 100644
index 0000000..e69de29
diff --git a/spec/unit/type.rb b/spec/unit/type.rb
index 6bdbe37..58c378f 100755
--- a/spec/unit/type.rb
+++ b/spec/unit/type.rb
@@ -408,13 +408,13 @@ describe Puppet::Type::RelationshipMetaparam do
@metaparam = Puppet::Type.metaparamclass(:require).new :resource => @resource
end
- it "should accept Puppet::Resource::Reference instances" do
- ref = Puppet::Resource::Reference.new(:file, "/foo")
+ it "should accept Puppet::Resource instances" do
+ ref = Puppet::Resource.new(:file, "/foo")
@metaparam.munge(ref)[0].should equal(ref)
end
- it "should turn any string into a Puppet::Resource::Reference" do
- @metaparam.munge("File[/ref]")[0].should be_instance_of(Puppet::Resource::Reference)
+ it "should turn any string into a Puppet::Resource" do
+ @metaparam.munge("File[/ref]")[0].should be_instance_of(Puppet::Resource)
end
end
diff --git a/spec/unit/type/tidy.rb b/spec/unit/type/tidy.rb
index 88e2e28..a3ca4a1 100755
--- a/spec/unit/type/tidy.rb
+++ b/spec/unit/type/tidy.rb
@@ -384,7 +384,7 @@ describe tidy do
"/what/ever/one/subone" => ["/what/ever/one/subone/ssone"]
}.each do |parent, children|
children.each do |child|
- ref = Puppet::Resource::Reference.new(:file, child)
+ ref = Puppet::Resource.new(:file, child)
result[parent][:require].find { |req| req.to_s == ref.to_s }.should_not be_nil
end
end
diff --git a/test/language/functions.rb b/test/language/functions.rb
index af07325..70605f8 100755
--- a/test/language/functions.rb
+++ b/test/language/functions.rb
@@ -289,16 +289,12 @@ class TestLangFunctions < Test::Unit::TestCase
Puppet[:code] = %{file { "#{file}": content => template("#{template}") }}
Puppet[:environment] = "yay"
- interp = Puppet::Parser::Interpreter.new
node = mknode
- node.stubs(:environment).returns("yay")
+ node.stubs(:environment).returns Puppet::Node::Environment.new
Puppet[:environment] = "yay"
- catalog = nil
- assert_nothing_raised {
- catalog = interp.compile(node)
- }
+ catalog = Puppet::Parser::Compiler.new(node).compile
version = catalog.version
@@ -317,7 +313,7 @@ class TestLangFunctions < Test::Unit::TestCase
f.puts "new text"
end
- newversion = interp.compile(node).version
+ newversion = Puppet::Parser::Compiler.new(node).compile.version
assert(version != newversion, "Parse date did not change")
end
@@ -385,100 +381,6 @@ class TestLangFunctions < Test::Unit::TestCase
"Did not set function correctly")
end
- def test_realize
- scope = mkscope
- parser = scope.compiler.parser
-
- realize = Puppet::Parser::Functions.function(:realize)
-
- # Make a definition
- parser.newdefine("mytype")
-
- [%w{file /tmp/virtual}, %w{mytype yay}].each do |type, title|
- # Make a virtual resource
- virtual = mkresource(:type => type, :title => title,
- :virtual => true, :params => {}, :scope => scope)
-
- scope.compiler.add_resource(scope, virtual)
-
- ref = Puppet::Parser::Resource::Reference.new(
- :type => type, :title => title,
- :scope => scope
- )
- # Now call the realize function
- assert_nothing_raised do
- scope.function_realize(ref)
- end
-
- # Make sure it created a collection
- assert_equal(1, scope.compiler.collections.length,
- "Did not set collection")
-
- assert_nothing_raised do
- scope.compiler.collections.each do |coll| coll.evaluate end
- end
- scope.compiler.collections.clear
-
- # Now make sure the virtual resource is no longer virtual
- assert(! virtual.virtual?, "Did not make virtual resource real")
- end
-
- # Make sure we puke on any resource that doesn't exist
- none = Puppet::Parser::Resource::Reference.new(
- :type => "file", :title => "/tmp/nosuchfile",
- :scope => scope
- )
-
- # The function works
- assert_nothing_raised do
- scope.function_realize(none.to_s)
- end
-
- # Make sure it created a collection
- assert_equal(1, scope.compiler.collections.length,
- "Did not set collection")
-
- # And the collection has our resource in it
- assert_equal([none.to_s], scope.compiler.collections[0].resources,
- "Did not set resources in collection")
- end
-
- def test_defined
- scope = mkscope
- parser = scope.compiler.parser
-
- defined = Puppet::Parser::Functions.function(:defined)
-
- parser.newclass("yayness")
- parser.newdefine("rahness")
-
- assert_nothing_raised do
- assert(scope.function_defined("yayness"), "yayness class was not considered defined")
- assert(scope.function_defined("rahness"), "rahness definition was not considered defined")
- assert(scope.function_defined("service"), "service type was not considered defined")
- assert(! scope.function_defined("fakness"), "fakeness was considered defined")
- end
-
- # Now make sure any match in a list will work
- assert(scope.function_defined(["booness", "yayness", "fakeness"]),
- "A single answer was not sufficient to return true")
-
- # and make sure multiple falses are still false
- assert(! scope.function_defined(%w{no otherno stillno}),
- "Multiple falses were somehow true")
-
- # Now make sure we can test resources
- scope.compiler.add_resource(scope, mkresource(:type => "file", :title => "/tmp/rahness",
- :scope => scope, :source => scope.source,
- :params => {:owner => "root"}))
-
- yep = Puppet::Parser::Resource::Reference.new(:type => "file", :title => "/tmp/rahness")
- nope = Puppet::Parser::Resource::Reference.new(:type => "file", :title => "/tmp/fooness")
-
- assert(scope.function_defined([yep]), "valid resource was not considered defined")
- assert(! scope.function_defined([nope]), "invalid resource was considered defined")
- end
-
def test_search
parser = mkparser
scope = mkscope(:parser => parser)
@@ -503,7 +405,7 @@ class TestLangFunctions < Test::Unit::TestCase
def test_include
scope = mkscope
- parser = scope.compiler.parser
+ parser = mkparser
include = Puppet::Parser::Functions.function(:include)
@@ -569,7 +471,7 @@ class TestLangFunctions < Test::Unit::TestCase
generate = Puppet::Parser::Functions.function(:generate)
scope = mkscope
- parser = scope.compiler.parser
+ parser = mkparser
val = nil
assert_nothing_raised("Could not call generator with no args") do
diff --git a/test/language/parser.rb b/test/language/parser.rb
index 758072d..09c819c 100755
--- a/test/language/parser.rb
+++ b/test/language/parser.rb
@@ -18,8 +18,14 @@ class TestParser < Test::Unit::TestCase
#@lexer = Puppet::Parser::Lexer.new()
end
+ def teardown
+ super
+ Puppet::Node::Environment.clear
+ end
+
def test_each_file
textfiles { |file|
+ Puppet::Node::Environment.clear
parser = mkparser
Puppet.debug("parsing %s" % file) if __FILE__ == $0
assert_nothing_raised() {
@@ -379,9 +385,7 @@ file { "/tmp/yayness":
assert_instance_of(Puppet::Parser::AST::IfStatement, ret)
parser = mkparser
str2 = %{if true { #{exec.call("true")} } else { #{exec.call("false")} }}
- assert_nothing_raised {
- ret = parser.parse(str2).hostclass("").code[0]
- }
+ ret = parser.parse(str2).hostclass("").code[0]
assert_instance_of(Puppet::Parser::AST::IfStatement, ret)
assert_instance_of(Puppet::Parser::AST::Else, ret.else)
end
@@ -410,7 +414,7 @@ file { "/tmp/yayness":
}
sub = parser.hostclass("container::one")
assert(sub, "Could not find one")
- assert_equal("container::deep::sub", sub.parentclass)
+ assert_equal("container::deep::sub", sub.parent)
# Finally, try including a qualified class
assert_nothing_raised("Could not include fully qualified class") {
@@ -435,78 +439,11 @@ file { "/tmp/yayness":
assert_nothing_raised do
out = parser.parse "Exec { path => '/usr/bin:/usr/sbin' }"
assert_instance_of(Puppet::Resource::TypeCollection, out)
- assert_equal("", parser.hostclass("").classname)
+ assert_equal("", parser.hostclass("").name)
assert_equal("", parser.hostclass("").namespace)
end
end
- # Make sure virtual and exported resources work appropriately.
- def test_virtualresources
- tests = [:virtual]
- if Puppet.features.rails?
- catalog_cache_class = Puppet::Resource::Catalog.indirection.cache_class
- facts_cache_class = Puppet::Node::Facts.indirection.cache_class
- node_cache_class = Puppet::Node.indirection.cache_class
- Puppet[:storeconfigs] = true
- tests << :exported
- end
-
- tests.each do |form|
- parser = mkparser
-
- if form == :virtual
- at = "@"
- else
- at = "@@"
- end
-
- check = proc do |res, msg|
- if res.is_a?(Puppet::Parser::Resource)
- txt = res.ref
- else
- txt = res.class
- end
- # Real resources get marked virtual when exported
- if form == :virtual or res.is_a?(Puppet::Parser::Resource)
- assert(res.virtual, "#{msg} #{at}#{txt} is not virtual")
- end
- if form == :virtual
- assert(! res.exported, "#{msg} #{at}#{txt} is exported")
- else
- assert(res.exported, "#{msg} #{at}#{txt} is not exported")
- end
- end
-
- ret = nil
- assert_nothing_raised do
- ret = parser.parse("#{at}file { '/tmp/testing': owner => root }")
- end
-
- assert_instance_of(AST::ASTArray, ret.hostclass("").code)
- resdef = ret.hostclass("").code[0]
- assert_instance_of(AST::Resource, resdef)
- assert_equal("/tmp/testing", resdef.title.value)
- # We always get an astarray back, so...
- check.call(resdef, "simple resource")
-
- # Now let's try it with multiple resources in the same spec
- assert_nothing_raised do
- ret = parser.parse("#{at}file { ['/tmp/1', '/tmp/2']: owner => root }")
- end
-
- ret.hostclass("").each do |res|
- assert_instance_of(AST::Resource, res)
- check.call(res, "multiresource")
- end
- end
- if Puppet.features.rails?
- Puppet[:storeconfigs] = false
- Puppet::Resource::Catalog.cache_class = catalog_cache_class
- Puppet::Node::Facts.cache_class = facts_cache_class
- Puppet::Node.cache_class = node_cache_class
- end
- end
-
def test_collections
tests = [:virtual]
if Puppet.features.rails?
@@ -518,6 +455,7 @@ file { "/tmp/yayness":
end
tests.each do |form|
+ Puppet::Node::Environment.clear
parser = mkparser
if form == :virtual
@@ -545,6 +483,7 @@ file { "/tmp/yayness":
def test_collectionexpressions
%w{== !=}.each do |oper|
+ Puppet::Node::Environment.clear
str = "File <| title #{oper} '/tmp/testing' |>"
parser = mkparser
@@ -612,30 +551,6 @@ file { "/tmp/yayness":
end
end
- # We've had problems with files other than site.pp importing into main.
- def test_importing_into_main
- top = tempfile()
- other = tempfile()
- File.open(top, "w") do |f|
- f.puts "import '#{other}'"
- end
-
- file = tempfile()
- File.open(other, "w") do |f|
- f.puts "file { '#{file}': ensure => present }"
- end
-
- Puppet[:manifest] = top
- interp = Puppet::Parser::Interpreter.new
-
- code = nil
- assert_nothing_raised do
- code = interp.compile(mknode).extract.flatten
- end
- assert(code.length == 1, "Did not get the file")
- assert_instance_of(Puppet::TransObject, code[0])
- end
-
def test_fully_qualified_definitions
parser = mkparser
@@ -799,196 +714,10 @@ file { "/tmp/yayness":
end
assert_instance_of(Puppet::Resource::TypeCollection, result, "Did not get a ASTSet back from parsing")
- assert_instance_of(AST::HostClass, result.hostclass("yay"), "Did not create 'yay' class")
- assert_instance_of(AST::HostClass, result.hostclass(""), "Did not create main class")
- assert_instance_of(AST::Definition, result.definition("bar"), "Did not create 'bar' definition")
- assert_instance_of(AST::Node, result.node("foo"), "Did not create 'foo' node")
- end
-
- # Make sure our node gets added to the node table.
- def test_newnode
- parser = mkparser
-
- # First just try calling it directly
- assert_nothing_raised {
- parser.newnode("mynode", :code => :yay)
- }
-
- assert_equal(:yay, parser.node("mynode").code)
-
- # Now make sure that trying to redefine it throws an error.
- assert_raise(Puppet::ParseError) {
- parser.newnode("mynode", {})
- }
-
- # Now try one with no code
- assert_nothing_raised {
- parser.newnode("simplenode", :parent => :foo)
- }
-
- # Now define the parent node
- parser.newnode(:foo)
-
- # And make sure we get things back correctly
- assert_equal(:foo, parser.node("simplenode").parentclass)
- assert_nil(parser.node("simplenode").code)
-
- # Now make sure that trying to redefine it throws an error.
- assert_raise(Puppet::ParseError) {
- parser.newnode("mynode", {})
- }
-
- # Test multiple names
- names = ["one", "two", "three"]
- assert_nothing_raised {
- parser.newnode(names, {:code => :yay, :parent => :foo})
- }
-
- names.each do |name|
- assert_equal(:yay, parser.node(name).code)
- assert_equal(:foo, parser.node(name).parentclass)
- # Now make sure that trying to redefine it throws an error.
- assert_raise(Puppet::ParseError) {
- parser.newnode(name, {})
- }
- end
- end
-
- def test_newdefine
- parser = mkparser
-
- assert_nothing_raised {
- parser.newdefine("mydefine", :code => :yay,
- :arguments => ["a", stringobj("b")])
- }
-
- mydefine = parser.definition("mydefine")
- assert(mydefine, "Could not find definition")
- assert_equal("", mydefine.namespace)
- assert_equal("mydefine", mydefine.classname)
-
- assert_raise(Puppet::ParseError) do
- parser.newdefine("mydefine", :code => :yay,
- :arguments => ["a", stringobj("b")])
- end
-
- # Now define the same thing in a different scope
- assert_nothing_raised {
- parser.newdefine("other::mydefine", :code => :other,
- :arguments => ["a", stringobj("b")])
- }
- other = parser.definition("other::mydefine")
- assert(other, "Could not find definition")
- assert(parser.definition("other::mydefine"),
- "Could not find other::mydefine")
- assert_equal(:other, other.code)
- assert_equal("other", other.namespace)
- assert_equal("other::mydefine", other.classname)
- end
-
- def test_newclass
- scope = mkscope
- parser = scope.compiler.parser
-
- mkcode = proc do |ary|
- classes = ary.collect do |string|
- AST::FlatString.new(:value => string)
- end
- AST::ASTArray.new(:children => classes)
- end
-
-
- # First make sure that code is being appended
- code = mkcode.call(%w{original code})
-
- klass = nil
- assert_nothing_raised {
- klass = parser.newclass("myclass", :code => code)
- }
-
- assert(klass, "Did not return class")
-
- assert(parser.hostclass("myclass"), "Could not find definition")
- assert_equal("myclass", parser.hostclass("myclass").classname)
- assert_equal(%w{original code},
- parser.hostclass("myclass").code.evaluate(scope))
-
- # Newclass behaves differently than the others -- it just appends
- # the code to the existing class.
- code = mkcode.call(%w{something new})
- assert_nothing_raised do
- klass = parser.newclass("myclass", :code => code)
- end
- assert(klass, "Did not return class when appending")
- assert_equal(%w{original code something new},
- parser.hostclass("myclass").code.evaluate(scope))
-
- # Now create the same class name in a different scope
- assert_nothing_raised {
- klass = parser.newclass("other::myclass",
- :code => mkcode.call(%w{something diff}))
- }
- assert(klass, "Did not return class")
- other = parser.hostclass("other::myclass")
- assert(other, "Could not find class")
- assert_equal("other::myclass", other.classname)
- assert_equal("other::myclass", other.namespace)
- assert_equal(%w{something diff},
- other.code.evaluate(scope))
-
- # Make sure newclass deals correctly with nodes with no code
- klass = parser.newclass("nocode")
- assert(klass, "Did not return class")
-
- assert_nothing_raised do
- klass = parser.newclass("nocode", :code => mkcode.call(%w{yay test}))
- end
- assert(klass, "Did not return class with no code")
- assert_equal(%w{yay test},
- parser.hostclass("nocode").code.evaluate(scope))
-
- # Then try merging something into nothing
- parser.newclass("nocode2", :code => mkcode.call(%w{foo test}))
- assert(klass, "Did not return class with no code")
-
- assert_nothing_raised do
- klass = parser.newclass("nocode2")
- end
- assert(klass, "Did not return class with no code")
- assert_equal(%w{foo test},
- parser.hostclass("nocode2").code.evaluate(scope))
-
- # And lastly, nothing and nothing
- klass = parser.newclass("nocode3")
- assert(klass, "Did not return class with no code")
-
- assert_nothing_raised do
- klass = parser.newclass("nocode3")
- end
- assert(klass, "Did not return class with no code")
- assert_nil(parser.hostclass("nocode3").code)
- end
-
- # Make sure you can't have classes and defines with the same name in the
- # same scope.
- def test_classes_beat_defines
- parser = mkparser
-
- assert_nothing_raised {
- parser.newclass("yay::funtest")
- }
-
- assert_raise(Puppet::ParseError) do
- parser.newdefine("yay::funtest")
- end
-
- assert_nothing_raised {
- parser.newdefine("yay::yaytest")
- }
-
- assert_raise(Puppet::ParseError) do
- parser.newclass("yay::yaytest")
- end
+ assert_instance_of(Puppet::Resource::Type, result.hostclass("yay"), "Did not create 'yay' class")
+ assert_instance_of(Puppet::Resource::Type, result.hostclass(""), "Did not create main class")
+ assert_instance_of(Puppet::Resource::Type, result.definition("bar"), "Did not create 'bar' definition")
+ assert_instance_of(Puppet::Resource::Type, result.node("foo"), "Did not create 'foo' node")
end
def test_namesplit
@@ -1005,50 +734,6 @@ file { "/tmp/yayness":
end
end
- # Now make sure we get appropriate behaviour with parent class conflicts.
- def test_newclass_parentage
- parser = mkparser
- parser.newclass("base1")
- parser.newclass("one::two::three")
-
- # First create it with no parentclass.
- assert_nothing_raised {
- parser.newclass("sub")
- }
- assert(parser.hostclass("sub"), "Could not find definition")
- assert_nil(parser.hostclass("sub").parentclass)
-
- # Make sure we can't set the parent class to ourself.
- assert_raise(Puppet::ParseError) {
- parser.newclass("sub", :parent => "sub")
- }
-
- # Now create another one, with a parentclass.
- assert_nothing_raised {
- parser.newclass("sub", :parent => "base1")
- }
-
- # Make sure we get the right parent class, and make sure it's not an object.
- assert_equal("base1",
- parser.hostclass("sub").parentclass)
-
- # Now make sure we get a failure if we try to conflict.
- assert_raise(Puppet::ParseError) {
- parser.newclass("sub", :parent => "one::two::three")
- }
-
- # Make sure that failure didn't screw us up in any way.
- assert_equal("base1",
- parser.hostclass("sub").parentclass)
- # But make sure we can create a class with a fq parent
- assert_nothing_raised {
- parser.newclass("another", :parent => "one::two::three")
- }
- assert_equal("one::two::three",
- parser.hostclass("another").parentclass)
-
- end
-
# Setup a module.
def mk_module(name, files = {})
mdir = File.join(@dir, name)
@@ -1091,22 +776,22 @@ file { "/tmp/yayness":
# Try to load the module automatically now
klass = parser.find_hostclass("", name)
- assert_instance_of(AST::HostClass, klass, "Did not autoload class from module init file")
- assert_equal(name, klass.classname, "Incorrect class was returned")
+ assert_instance_of(Puppet::Resource::Type, klass, "Did not autoload class from module init file")
+ assert_equal(name, klass.name, "Incorrect class was returned")
# Try loading the simple module when we're in something other than the base namespace.
parser = mkparser
klass = parser.find_hostclass("something::else", name)
- assert_instance_of(AST::HostClass, klass, "Did not autoload class from module init file")
- assert_equal(name, klass.classname, "Incorrect class was returned")
+ assert_instance_of(Puppet::Resource::Type, klass, "Did not autoload class from module init file")
+ assert_equal(name, klass.name, "Incorrect class was returned")
# Now try it with a definition as the base file
name = "simpdef"
mk_module(name, :define => true, :init => [name])
klass = parser.find_definition("", name)
- assert_instance_of(AST::Definition, klass, "Did not autoload class from module init file")
- assert_equal(name, klass.classname, "Incorrect class was returned")
+ assert_instance_of(Puppet::Resource::Type, klass, "Did not autoload class from module init file")
+ assert_equal(name, klass.name, "Incorrect class was returned")
# Now try it with namespace classes where both classes are in the init file
parser = mkparser
@@ -1116,14 +801,14 @@ file { "/tmp/yayness":
# First try it with a namespace
klass = parser.find_hostclass("both", name)
- assert_instance_of(AST::HostClass, klass, "Did not autoload sub class from module init file with a namespace")
- assert_equal("both::sub", klass.classname, "Incorrect class was returned")
+ assert_instance_of(Puppet::Resource::Type, klass, "Did not autoload sub class from module init file with a namespace")
+ assert_equal("both::sub", klass.name, "Incorrect class was returned")
# Now try it using the fully qualified name
parser = mkparser
klass = parser.find_hostclass("", "both::sub")
- assert_instance_of(AST::HostClass, klass, "Did not autoload sub class from module init file with no namespace")
- assert_equal("both::sub", klass.classname, "Incorrect class was returned")
+ assert_instance_of(Puppet::Resource::Type, klass, "Did not autoload sub class from module init file with no namespace")
+ assert_equal("both::sub", klass.name, "Incorrect class was returned")
# Now try it with the class in a different file
@@ -1134,14 +819,14 @@ file { "/tmp/yayness":
# First try it with a namespace
klass = parser.find_hostclass("separate", name)
- assert_instance_of(AST::HostClass, klass, "Did not autoload sub class from separate file with a namespace")
- assert_equal("separate::sub", klass.classname, "Incorrect class was returned")
+ assert_instance_of(Puppet::Resource::Type, klass, "Did not autoload sub class from separate file with a namespace")
+ assert_equal("separate::sub", klass.name, "Incorrect class was returned")
# Now try it using the fully qualified name
parser = mkparser
klass = parser.find_hostclass("", "separate::sub")
- assert_instance_of(AST::HostClass, klass, "Did not autoload sub class from separate file with no namespace")
- assert_equal("separate::sub", klass.classname, "Incorrect class was returned")
+ assert_instance_of(Puppet::Resource::Type, klass, "Did not autoload sub class from separate file with no namespace")
+ assert_equal("separate::sub", klass.name, "Incorrect class was returned")
# Now make sure we don't get a failure when there's no module file
parser = mkparser
@@ -1153,22 +838,22 @@ file { "/tmp/yayness":
assert_nothing_raised("Could not autoload file when module file is missing") do
klass = parser.find_hostclass("alone", name)
end
- assert_instance_of(AST::HostClass, klass, "Did not autoload sub class from alone file with a namespace")
- assert_equal("alone::sub", klass.classname, "Incorrect class was returned")
+ assert_instance_of(Puppet::Resource::Type, klass, "Did not autoload sub class from alone file with a namespace")
+ assert_equal("alone::sub", klass.name, "Incorrect class was returned")
# Now try it using the fully qualified name
parser = mkparser
klass = parser.find_hostclass("", "alone::sub")
- assert_instance_of(AST::HostClass, klass, "Did not autoload sub class from alone file with no namespace")
- assert_equal("alone::sub", klass.classname, "Incorrect class was returned")
+ assert_instance_of(Puppet::Resource::Type, klass, "Did not autoload sub class from alone file with no namespace")
+ assert_equal("alone::sub", klass.name, "Incorrect class was returned")
# and with the definition in its own file
name = "mymod"
mk_module(name, :define => true, :mydefine => ["mymod::mydefine"])
klass = parser.find_definition("", "mymod::mydefine")
- assert_instance_of(AST::Definition, klass, "Did not autoload definition from its own file")
- assert_equal("mymod::mydefine", klass.classname, "Incorrect definition was returned")
+ assert_instance_of(Puppet::Resource::Type, klass, "Did not autoload definition from its own file")
+ assert_equal("mymod::mydefine", klass.name, "Incorrect definition was returned")
end
# Make sure class, node, and define methods are case-insensitive
@@ -1187,25 +872,4 @@ file { "/tmp/yayness":
assert_equal(result, parser.find_definition("", "fUntEst"),
"%s was not matched" % "fUntEst")
end
-
- def test_manifests_with_multiple_environments
- parser = mkparser :environment => "something"
-
- # We use an exception to cut short the processing to simplify our stubbing
- #Puppet::Module.expects(:find_manifests).with("test", {:cwd => ".", :environment => "something"}).raises(Puppet::ParseError)
- Puppet::Parser::Files.expects(:find_manifests).with("test", {:cwd => ".", :environment => "something"}).returns([])
-
- assert_raise(Puppet::ImportError) do
- parser.import("test")
- end
- end
-
- def test_watch_file_only_once
- FileTest.stubs(:exists?).returns(true)
- parser = mkparser
- parser.watch_file("doh")
- parser.watch_file("doh")
- assert_equal(1, parser.files.select { |name, file| file.file == "doh" }.length, "Length of watched 'doh' files was not 1")
- end
end
-
diff --git a/test/language/resource.rb b/test/language/resource.rb
deleted file mode 100755
index c1d116f..0000000
--- a/test/language/resource.rb
+++ /dev/null
@@ -1,172 +0,0 @@
-#!/usr/bin/env ruby
-
-require File.dirname(__FILE__) + '/../lib/puppettest'
-
-require 'puppettest'
-require 'puppettest/resourcetesting'
-
-class TestResource < PuppetTest::TestCase
- include PuppetTest
- include PuppetTest::ParserTesting
- include PuppetTest::ResourceTesting
- Parser = Puppet::Parser
- AST = Parser::AST
- Resource = Puppet::Parser::Resource
- Reference = Puppet::Parser::Resource::Reference
-
- def setup
- super
- Puppet[:trace] = false
- end
-
- def teardown
- mocha_verify
- end
-
- # Make sure we paramcheck our params
- def test_validate
- res = mkresource
- params = res.instance_variable_get("@params")
- params[:one] = :two
- params[:three] = :four
- res.expects(:paramcheck).with(:one)
- res.expects(:paramcheck).with(:three)
- res.send(:validate)
- end
-
- def test_set_parameter
- res = mkresource
- params = res.instance_variable_get("@params")
-
- # First test the simple case: It's already a parameter
- param = stub('param', :name => "pname")
- param.expects(:is_a?).with(Resource::Param).returns(true)
- res.send(:set_parameter, param)
- assert_equal(param, params["pname"], "Parameter was not added to hash")
-
- # Now the case where there's no value but it's not a param
- param = mock('param')
- param.expects(:is_a?).with(Resource::Param).returns(false)
- assert_raise(ArgumentError, "Did not fail when a non-param was passed") do
- res.send(:set_parameter, param)
- end
-
- # and the case where a value is passed in
- param = stub :name => "pname", :value => "whatever"
- Resource::Param.expects(:new).with(:name => "pname", :value => "myvalue", :source => res.source).returns(param)
- res.send(:set_parameter, "pname", "myvalue")
- assert_equal(param, params["pname"], "Did not put param in hash")
- end
-
- def test_paramcheck
- # There are three cases here:
-
- # It's a valid parameter
- res = mkresource
- ref = mock('ref')
- res.instance_variable_set("@ref", ref)
- klass = mock("class")
- ref.expects(:typeclass).returns(klass).times(4)
- klass.expects(:valid_parameter?).with("good").returns(true)
- assert(res.send(:paramcheck, :good), "Did not allow valid param")
-
- # It's name or title
- klass.expects(:valid_parameter?).with("name").returns(false)
- assert(res.send(:paramcheck, :name), "Did not allow name")
- klass.expects(:valid_parameter?).with("title").returns(false)
- assert(res.send(:paramcheck, :title), "Did not allow title")
-
- # It's not actually allowed
- klass.expects(:valid_parameter?).with("other").returns(false)
- res.expects(:fail)
- ref.expects(:type)
- res.send(:paramcheck, :other)
- end
-
- def test_evaluate
- # First try the most common case, we're not a builtin type.
- res = mkresource
- ref = res.instance_variable_get("@ref")
- type = mock("type")
- ref.expects(:definedtype).returns(type)
- res.expects(:finish)
- res.scope = mock("scope")
-
- type.expects(:evaluate_code).with(res)
-
- res.evaluate
- end
-
- def test_proxymethods
- res = Parser::Resource.new :type => "evaltest", :title => "yay",
- :source => mock("source"), :scope => mkscope
-
- assert_equal("Evaltest", res.type)
- assert_equal("yay", res.title)
- assert_equal(false, res.builtin?)
- end
-
- # This is a bit of a weird one -- the user should not actually know
- # that components exist, so we want references to act like they're not
- # builtin
- def test_components_are_not_builtin
- ref = Parser::Resource::Reference.new(:type => "component", :title => "yay")
-
- assert_nil(ref.builtintype, "Definition was considered builtin")
- end
-
- # The second part of #539 - make sure resources pass the arguments
- # correctly.
- def test_title_with_definitions
- parser = mkparser
- define = parser.newdefine "yayness",
- :code => resourcedef("file", "/tmp",
- "owner" => varref("name"), "mode" => varref("title"))
-
-
- klass = parser.find_hostclass("", "")
- should = {:name => :owner, :title => :mode}
- [
- {:name => "one", :title => "two"},
- {:title => "three"},
- ].each do |hash|
- config = mkcompiler parser
- args = {:type => "yayness", :title => hash[:title],
- :source => klass, :scope => config.topscope}
- if hash[:name]
- args[:params] = {:name => hash[:name]}
- else
- args[:params] = {} # override the defaults
- end
-
- res = nil
- assert_nothing_raised("Could not create res with %s" % hash.inspect) do
- res = mkresource(args)
- end
- assert_nothing_raised("Could not eval res with %s" % hash.inspect) do
- res.evaluate
- end
-
- made = config.topscope.findresource("File[/tmp]")
- assert(made, "Did not create resource with %s" % hash.inspect)
- should.each do |orig, param|
- assert_equal(hash[orig] || hash[:title], made[param],
- "%s was not set correctly with %s" % [param, hash.inspect])
- end
- end
- end
-
- # part of #629 -- the undef keyword. Make sure 'undef' params get skipped.
- def test_undef_and_to_hash
- res = mkresource :type => "file", :title => "/tmp/testing",
- :source => mock("source"), :scope => mkscope,
- :params => {:owner => :undef, :mode => "755"}
-
- hash = nil
- assert_nothing_raised("Could not convert resource with undef to hash") do
- hash = res.to_hash
- end
-
- assert_nil(hash[:owner], "got a value for an undef parameter")
- end
-end
diff --git a/test/language/scope.rb b/test/language/scope.rb
index 8b06e0d..d2f6ec7 100755
--- a/test/language/scope.rb
+++ b/test/language/scope.rb
@@ -20,6 +20,11 @@ class TestScope < Test::Unit::TestCase
include PuppetTest::ParserTesting
include PuppetTest::ResourceTesting
+ def setup
+ Puppet::Node::Environment.clear
+ super
+ end
+
def to_ary(hash)
hash.collect { |key,value|
[key,value]
@@ -102,60 +107,6 @@ class TestScope < Test::Unit::TestCase
}
end
- def test_setdefaults
- config = mkcompiler
-
- scope = config.topscope
-
- defaults = scope.instance_variable_get("@defaults")
-
- # First the case where there are no defaults and we pass a single param
- param = stub :name => "myparam", :file => "f", :line => "l"
- scope.setdefaults(:mytype, param)
- assert_equal({"myparam" => param}, defaults[:mytype], "Did not set default correctly")
-
- # Now the case where we pass in multiple parameters
- param1 = stub :name => "one", :file => "f", :line => "l"
- param2 = stub :name => "two", :file => "f", :line => "l"
- scope.setdefaults(:newtype, [param1, param2])
- assert_equal({"one" => param1, "two" => param2}, defaults[:newtype], "Did not set multiple defaults correctly")
-
- # And the case where there's actually a conflict. Use the first default for this.
- newparam = stub :name => "myparam", :file => "f", :line => "l"
- assert_raise(Puppet::ParseError, "Allowed resetting of defaults") do
- scope.setdefaults(:mytype, param)
- end
- assert_equal({"myparam" => param}, defaults[:mytype], "Replaced default even though there was a failure")
- end
-
- def test_lookupdefaults
- config = mkcompiler
- top = config.topscope
-
- # Make a subscope
- sub = config.newscope(top)
-
- topdefs = top.instance_variable_get("@defaults")
- subdefs = sub.instance_variable_get("@defaults")
-
- # First add some defaults to our top scope
- topdefs[:t1] = {:p1 => :p2, :p3 => :p4}
- topdefs[:t2] = {:p5 => :p6}
-
- # Then the sub scope
- subdefs[:t1] = {:p1 => :p7, :p8 => :p9}
- subdefs[:t2] = {:p5 => :p10, :p11 => :p12}
-
- # Now make sure we get the correct list back
- result = nil
- assert_nothing_raised("Could not get defaults") do
- result = sub.lookupdefaults(:t1)
- end
- assert_equal(:p9, result[:p8], "Did not get child defaults")
- assert_equal(:p4, result[:p3], "Did not override parent defaults with child default")
- assert_equal(:p7, result[:p1], "Did not get parent defaults")
- end
-
def test_parent
config = mkcompiler
top = config.topscope
@@ -167,86 +118,6 @@ class TestScope < Test::Unit::TestCase
assert_equal(top, sub.parent, "Did not find parent scope on second call")
end
- def test_strinterp
- # Make and evaluate our classes so the qualified lookups work
- parser = mkparser
- klass = parser.newclass("")
- scope = mkscope(:parser => parser)
- Puppet::Parser::Resource.new(:type => "class", :title => :main, :scope => scope, :source => mock('source')).evaluate
-
- assert_nothing_raised {
- scope.setvar("test","value")
- }
-
- scopes = {"" => scope}
-
- %w{one one::two one::two::three}.each do |name|
- klass = parser.newclass(name)
- Puppet::Parser::Resource.new(:type => "class", :title => name, :scope => scope, :source => mock('source')).evaluate
- scopes[name] = scope.compiler.class_scope(klass)
- scopes[name].setvar("test", "value-%s" % name.sub(/.+::/,''))
- end
-
- assert_equal("value", scope.lookupvar("::test"), "did not look up qualified value correctly")
- tests = {
- "string ${test}" => "string value",
- "string ${one::two::three::test}" => "string value-three",
- "string $one::two::three::test" => "string value-three",
- "string ${one::two::test}" => "string value-two",
- "string $one::two::test" => "string value-two",
- "string ${one::test}" => "string value-one",
- "string $one::test" => "string value-one",
- "string ${::test}" => "string value",
- "string $::test" => "string value",
- "string ${test} ${test} ${test}" => "string value value value",
- "string $test ${test} $test" => "string value value value",
- "string \\$test" => "string $test",
- '\\$test string' => "$test string",
- '$test string' => "value string",
- 'a testing $' => "a testing $",
- 'a testing \$' => "a testing $",
- "an escaped \\\n carriage return" => "an escaped carriage return",
- '\$' => "$",
- '\s' => "\s",
- '\t' => "\t",
- '\n' => "\n"
- }
-
- tests.each do |input, output|
- assert_nothing_raised("Failed to scan %s" % input.inspect) do
- assert_equal(output, scope.strinterp(input),
- 'did not parserret %s correctly' % input.inspect)
- end
- end
-
- logs = []
- Puppet::Util::Log.close
- Puppet::Util::Log.newdestination(logs)
-
- # #523
- %w{d f h l w z}.each do |l|
- string = "\\" + l
- assert_nothing_raised do
- assert_equal(string, scope.strinterp(string),
- 'did not parserret %s correctly' % string)
- end
-
- assert(logs.detect { |m| m.message =~ /Unrecognised escape/ },
- "Did not get warning about escape sequence with %s" % string)
- logs.clear
- end
- end
-
- def test_tagfunction
- Puppet::Parser::Functions.function(:tag)
- scope = mkscope
- resource = mock 'resource'
- scope.resource = resource
- resource.expects(:tag).with("yayness", "booness")
-
- scope.function_tag(%w{yayness booness})
- end
-
def test_includefunction
parser = mkparser
scope = mkscope :parser => parser
@@ -270,7 +141,7 @@ class TestScope < Test::Unit::TestCase
[myclass, otherclass].each do |klass|
assert(scope.compiler.class_scope(klass),
- "%s was not set" % klass.classname)
+ "%s was not set" % klass.name)
end
end
@@ -312,13 +183,14 @@ class TestScope < Test::Unit::TestCase
# components.
def test_virtual_definitions_do_not_get_evaluated
config = mkcompiler
- parser = config.parser
+ parser = mkparser
# Create a default source
- config.topscope.source = parser.newclass "", ""
+ parser.newclass("")
+ config.topscope.source = parser.known_resource_types.hostclass("")
# And a scope resource
- scope_res = stub 'scope_resource', :virtual? => true, :exported? => false, :tags => [], :builtin? => true, :type => "eh", :title => "bee"
+ scope_res = Puppet::Parser::Resource.new(:file, "/file", :scope => "scope", :source => "source")
config.topscope.resource = scope_res
args = AST::ASTArray.new(
@@ -374,20 +246,13 @@ include yay
@@host { puppet: ip => \"192.168.0.3\" }
Host <<||>>"
- interp = nil
- assert_nothing_raised {
- interp = Puppet::Parser::Interpreter.new
- }
-
config = nil
# We run it twice because we want to make sure there's no conflict
# if we pull it up from the database.
node = mknode
- node.parameters = {"hostname" => node.name}
+ node.merge "hostname" => node.name
2.times { |i|
- assert_nothing_raised {
- config = interp.compile(node)
- }
+ config = Puppet::Parser::Compiler.new(node).compile
flat = config.extract.flatten
@@ -417,54 +282,6 @@ Host <<||>>"
"Did not add extra namespace correctly")
end
- def test_find_hostclass_and_find_definition
- parser = mkparser
-
- # Make sure our scope calls the parser find_hostclass method with
- # the right namespaces
- scope = mkscope :parser => parser
-
- parser.metaclass.send(:attr_accessor, :last)
-
- methods = [:find_hostclass, :find_definition]
- methods.each do |m|
- parser.meta_def(m) do |namespace, name|
- @checked ||= []
- @checked << [namespace, name]
-
- # Only return a value on the last call.
- if @last == namespace
- ret = @checked.dup
- @checked.clear
- return ret
- else
- return nil
- end
- end
- end
-
- test = proc do |should|
- parser.last = scope.namespaces[-1]
- methods.each do |method|
- result = scope.send(method, "testing")
- assert_equal(should, result,
- "did not get correct value from %s with namespaces %s" %
- [method, scope.namespaces.inspect])
- end
- end
-
- # Start with the empty namespace
- assert_nothing_raised { test.call([["", "testing"]]) }
-
- # Now add a namespace
- scope.add_namespace("a")
- assert_nothing_raised { test.call([["a", "testing"]]) }
-
- # And another
- scope.add_namespace("b")
- assert_nothing_raised { test.call([["a", "testing"], ["b", "testing"]]) }
- end
-
# #629 - undef should be "" or :undef
def test_lookupvar_with_undef
scope = mkscope
diff --git a/test/language/snippets.rb b/test/language/snippets.rb
index 5c7805c..b0d98ae 100755
--- a/test/language/snippets.rb
+++ b/test/language/snippets.rb
@@ -3,7 +3,6 @@
require File.dirname(__FILE__) + '/../lib/puppettest'
require 'puppet'
-require 'puppet/parser/interpreter'
require 'puppet/parser/parser'
require 'puppet/network/client'
require 'puppet/network/handler'
diff --git a/test/lib/puppettest/parsertesting.rb b/test/lib/puppettest/parsertesting.rb
index dee38eb..44c78f2 100644
--- a/test/lib/puppettest/parsertesting.rb
+++ b/test/lib/puppettest/parsertesting.rb
@@ -47,9 +47,8 @@ module PuppetTest::ParserTesting
end
def mkcompiler(parser = nil)
- parser ||= mkparser
node = mknode
- return Compiler.new(node, parser)
+ return Compiler.new(node)
end
def mknode(name = nil)
@@ -59,12 +58,9 @@ module PuppetTest::ParserTesting
Puppet::Node.new(name)
end
- def mkinterp
- Puppet::Parser::Interpreter.new
- end
-
- def mkparser(args = {})
- Puppet::Parser::Parser.new(args)
+ def mkparser
+ Puppet::Node::Environment.clear
+ Puppet::Parser::Parser.new(Puppet::Node::Environment.new)
end
def mkscope(hash = {})
@@ -306,13 +302,10 @@ module PuppetTest::ParserTesting
interp = nil
oldmanifest = Puppet[:manifest]
Puppet[:manifest] = manifest
- assert_nothing_raised {
- interp = Puppet::Parser::Interpreter.new
- }
trans = nil
assert_nothing_raised {
- trans = interp.compile(mknode)
+ trans = Puppet::Parser::Compiler.new(mknode).compile
}
config = nil
diff --git a/test/lib/puppettest/resourcetesting.rb b/test/lib/puppettest/resourcetesting.rb
index d4469a2..95fe5bc 100644
--- a/test/lib/puppettest/resourcetesting.rb
+++ b/test/lib/puppettest/resourcetesting.rb
@@ -15,9 +15,12 @@ module PuppetTest::ResourceTesting
args[:source] ||= "source"
args[:scope] ||= mkscope
- {:type => "resource", :title => "testing",
- :source => "source", :scope => "scope"}.each do |param, value|
- args[param] ||= value
+ type = args[:type] || "resource"
+ title = args[:title] || "testing"
+ args.delete(:type)
+ args.delete(:title)
+ {:source => "source", :scope => "scope"}.each do |param, value|
+ args[param] ||= value
end
params = args[:params] || {:one => "yay", :three => "rah"}
@@ -27,7 +30,7 @@ module PuppetTest::ResourceTesting
args[:params] = paramify args[:source], params
end
- Parser::Resource.new(args)
+ Parser::Resource.new(type, title, args)
end
def param(name, value, source)
diff --git a/test/other/events.rb b/test/other/events.rb
index 052afc0..b82e545 100755
--- a/test/other/events.rb
+++ b/test/other/events.rb
@@ -19,7 +19,7 @@ class TestEvents < Test::Unit::TestCase
:name => "echo true",
:path => "/usr/bin:/bin",
:refreshonly => true,
- :subscribe => Puppet::Resource::Reference.new(file.class.name, file.name)
+ :subscribe => Puppet::Resource.new(file.class.name, file.name)
)
comp = mk_catalog("eventtesting", file, exec)
@@ -39,7 +39,7 @@ class TestEvents < Test::Unit::TestCase
:name => "echo true",
:path => "/usr/bin:/bin",
:refreshonly => true,
- :require => Puppet::Resource::Reference.new(file.class.name, file.name)
+ :require => Puppet::Resource.new(file.class.name, file.name)
)
@@ -71,7 +71,7 @@ class TestEvents < Test::Unit::TestCase
)
exec[:subscribe] = files.collect { |f|
- Puppet::Resource::Reference.new(:file, f.name)
+ Puppet::Resource.new(:file, f.name)
}
comp = mk_catalog(exec, *files)
diff --git a/test/other/relationships.rb b/test/other/relationships.rb
index b15ff50..e9d3a93 100755
--- a/test/other/relationships.rb
+++ b/test/other/relationships.rb
@@ -80,7 +80,7 @@ class TestRelationships < Test::Unit::TestCase
# Testing #411. It was a problem with builddepends.
def test_missing_deps
- file = Puppet::Type.type(:file).new :path => tempfile, :require => Puppet::Resource::Reference.new("file", "/no/such/file")
+ file = Puppet::Type.type(:file).new :path => tempfile, :require => Puppet::Resource.new("file", "/no/such/file")
assert_raise(Puppet::Error) do
file.builddepends
diff --git a/test/other/transactions.rb b/test/other/transactions.rb
index d0c6b85..32a7558 100755
--- a/test/other/transactions.rb
+++ b/test/other/transactions.rb
@@ -125,12 +125,12 @@ class TestTransactions < Test::Unit::TestCase
file = Puppet::Type.type(:file).new(:title => "file", :path => path, :content => "yayness")
first = Puppet::Type.type(:exec).new(:title => "first",
:command => "/bin/echo first > #{firstpath}",
- :subscribe => Puppet::Resource::Reference.new(:file, path),
+ :subscribe => Puppet::Resource.new(:file, path),
:refreshonly => true
)
second = Puppet::Type.type(:exec).new(:title => "second",
:command => "/bin/echo second > #{secondpath}",
- :subscribe => Puppet::Resource::Reference.new(:exec, "first"),
+ :subscribe => Puppet::Resource.new(:exec, "first"),
:refreshonly => true
)
@@ -268,7 +268,7 @@ class TestTransactions < Test::Unit::TestCase
@@tmpfiles << execfile
# 'subscribe' expects an array of arrays
- exec[:subscribe] = Puppet::Resource::Reference.new(file.class.name,file.name)
+ exec[:subscribe] = Puppet::Resource.new(file.class.name,file.name)
exec[:refreshonly] = true
assert_nothing_raised() {
@@ -352,13 +352,13 @@ class TestTransactions < Test::Unit::TestCase
:path => ENV["PATH"],
:command => "touch %s" % file1,
:refreshonly => true,
- :subscribe => Puppet::Resource::Reference.new(:file, path)
+ :subscribe => Puppet::Resource.new(:file, path)
)
exec2 = Puppet::Type.type(:exec).new(
:path => ENV["PATH"],
:command => "touch %s" % file2,
:refreshonly => true,
- :subscribe => Puppet::Resource::Reference.new(:file, path)
+ :subscribe => Puppet::Resource.new(:file, path)
)
assert_apply(file, exec1, exec2)
@@ -411,7 +411,7 @@ class TestTransactions < Test::Unit::TestCase
:name => "touch %s" % fname,
:path => "/usr/bin:/bin",
:schedule => "monthly",
- :subscribe => Puppet::Resource::Reference.new("file", file.name)
+ :subscribe => Puppet::Resource.new("file", file.name)
)
config = mk_catalog(file, exec)
diff --git a/test/ral/type/exec.rb b/test/ral/type/exec.rb
index 6c1a82a..3a3d75b 100755
--- a/test/ral/type/exec.rb
+++ b/test/ral/type/exec.rb
@@ -195,7 +195,7 @@ class TestExec < Test::Unit::TestCase
exec = Puppet::Type.type(:exec).new(
:command => oexe,
- :require => Puppet::Resource::Reference.new(:file, oexe)
+ :require => Puppet::Resource.new(:file, oexe)
)
comp = mk_catalog("Testing", file, exec)
@@ -418,7 +418,7 @@ class TestExec < Test::Unit::TestCase
:path => basedir,
:recurse => true,
:mode => "755",
- :require => Puppet::Resource::Reference.new("exec", "mkdir")
+ :require => Puppet::Resource.new("exec", "mkdir")
)
}
--
1.6.1
Signed-off-by: Luke Kanies <lu...@reductivelabs.com>
---
lib/puppet/parser/grammar.ra | 5 +----
lib/puppet/parser/parser.rb | 7 ++-----
2 files changed, 3 insertions(+), 9 deletions(-)
diff --git a/lib/puppet/parser/grammar.ra b/lib/puppet/parser/grammar.ra
index 5dbf6f4..0aa31e5 100644
--- a/lib/puppet/parser/grammar.ra
+++ b/lib/puppet/parser/grammar.ra
@@ -657,7 +657,7 @@ hostclass: CLASS classname argumentlist classparent LBRACE statements RBRACE {
@lexer.commentpop
# Our class gets defined in the parent namespace, not our own.
@lexer.namepop
- newclass classname(val[1]), :arguments => val[2], :code => val[5], :parent => val[3], :line => val[0][:line]
+ newclass classname(val[1]), :arguments => val[2], :parent => val[3], :code => val[5], :line => val[0][:line]
result = nil
} | CLASS classname argumentlist classparent LBRACE RBRACE {
@lexer.commentpop
@@ -795,9 +795,6 @@ module Puppet
class AlreadyImportedError < ImportError; end
end
-Puppet[:typecheck] = true
-Puppet[:paramcheck] = true
-
---- inner ----
# It got too annoying having code in a file that needs to be compiled.
diff --git a/lib/puppet/parser/parser.rb b/lib/puppet/parser/parser.rb
index 2f7d754..a1d2341 100644
--- a/lib/puppet/parser/parser.rb
+++ b/lib/puppet/parser/parser.rb
@@ -17,14 +17,11 @@ module Puppet
class AlreadyImportedError < ImportError; end
end
-Puppet[:typecheck] = true
-Puppet[:paramcheck] = true
-
module Puppet
module Parser
class Parser < Racc::Parser
-module_eval(<<'...end grammar.ra/module_eval...', 'grammar.ra', 802)
+module_eval(<<'...end grammar.ra/module_eval...', 'grammar.ra', 799)
# It got too annoying having code in a file that needs to be compiled.
require 'puppet/parser/parser_support'
@@ -2083,7 +2080,7 @@ module_eval(<<'.,.,', 'grammar.ra', 656)
@lexer.commentpop
# Our class gets defined in the parent namespace, not our own.
@lexer.namepop
- newclass classname(val[1]), :arguments => val[2], :code => val[5], :parent => val[3], :line => val[0][:line]
+ newclass classname(val[1]), :arguments => val[2], :parent => val[3], :code => val[5], :line => val[0][:line]
result = nil
result
--
1.6.1
Signed-off-by: Luke Kanies <lu...@reductivelabs.com>
---
lib/puppet/resource/type.rb | 21 +++++++++++++++++--
spec/unit/resource/type.rb | 45 ++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 62 insertions(+), 4 deletions(-)
diff --git a/lib/puppet/resource/type.rb b/lib/puppet/resource/type.rb
index f82b6dc..0a0c3be 100644
--- a/lib/puppet/resource/type.rb
+++ b/lib/puppet/resource/type.rb
@@ -25,9 +25,14 @@ class Puppet::Resource::Type
# Now evaluate the code associated with this class or definition.
def evaluate_code(resource)
- # Create a new scope.
- scope = subscope(resource.scope, resource)
- scope.compiler.class_set(name, scope)
+ scope = resource.scope
+
+ if tmp = evaluate_parent_type(resource)
+ scope = tmp
+ end
+
+ scope = subscope(scope, resource)
+ scope.compiler.class_set(name, scope) unless type == :definition
set_resource_parameters(resource, scope)
@@ -206,6 +211,12 @@ class Puppet::Resource::Type
end
end
+ def evaluate_parent_type(resource)
+ return unless klass = parent_type and parent_resource = resource.scope.compiler.catalog.resource(:class, klass.name)
+ parent_resource.evaluate unless parent_resource.evaluated?
+ return parent_scope(resource.scope, klass)
+ end
+
# Split an fq name into a namespace and name
def namesplit(fullname)
ary = fullname.split("::")
@@ -214,6 +225,10 @@ class Puppet::Resource::Type
return ns, n
end
+ def parent_scope(scope, klass)
+ scope.compiler.class_scope(klass) || raise(Puppet::DevError, "Could not find scope for #{klass.name}")
+ end
+
def set_name_and_namespace(name)
if name.is_a?(Regexp)
@name = name
diff --git a/spec/unit/resource/type.rb b/spec/unit/resource/type.rb
index 2e592c0..fe839d9 100755
--- a/spec/unit/resource/type.rb
+++ b/spec/unit/resource/type.rb
@@ -324,7 +324,7 @@ describe Puppet::Resource::Type do
before do
@compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("mynode"))
@scope = Puppet::Parser::Scope.new :compiler => @compiler
- @resource = stub 'resource', :title => "yay", :name => "yea", :ref => "Foo[bar]", :scope => @scope
+ @resource = Puppet::Parser::Resource.new(:foo, "yay", :scope => @scope)
@type = Puppet::Resource::Type.new(:hostclass, "foo")
@type.stubs(:set_resource_parameters)
end
@@ -345,6 +345,15 @@ describe Puppet::Resource::Type do
@compiler.class_scope(@type).should equal(subscope)
end
+ it "should still create a scope but not store it if the type is a definition" do
+ subscope = stub 'subscope', :compiler => @compiler, :setvar => nil
+
+ @type = Puppet::Resource::Type.new(:definition, "foo")
+ @type.expects(:subscope).with(@scope, @resource).returns subscope
+ @type.evaluate_code(@resource)
+ @compiler.class_scope(@type).should be_nil
+ end
+
it "should evaluate the code if any is provided" do
code = stub 'code'
@type.stubs(:code).returns code
@@ -359,6 +368,40 @@ describe Puppet::Resource::Type do
@type.evaluate_code(@resource)
end
+
+ describe "and it has a parent class" do
+ before do
+ @parent_type = Puppet::Resource::Type.new(:hostclass, "parent")
+ @compiler
+ @type.parent = "parent"
+ @parent_resource = Puppet::Parser::Resource.new(:class, "parent", :scope => @scope)
+
+ @compiler.add_resource @scope, @parent_resource
+
+ @type.code_collection = @scope.known_resource_types
+ @type.code_collection.add @parent_type
+ end
+
+ it "should evaluate the parent's resource" do
+ @type.evaluate_code(@resource)
+
+ @compiler.class_scope(@parent_type).should_not be_nil
+ end
+
+ it "should not evaluate the parent's resource if it has already been evaluated" do
+ @parent_resource.evaluate
+
+ @parent_resource.expects(:evaluate).never
+
+ @type.evaluate_code(@resource)
+ end
+
+ it "should use the parent's scope as its base scope" do
+ @type.evaluate_code(@resource)
+
+ @scope.compiler.class_scope(@type).parent.object_id.should == @scope.compiler.class_scope(@parent_type).object_id
+ end
+ end
end
describe "when creating a resource" do
--
1.6.1
Signed-off-by: Luke Kanies <lu...@reductivelabs.com>
---
lib/puppet/resource.rb | 12 +++++++++---
lib/puppet/transportable.rb | 2 +-
lib/puppet/util/settings.rb | 4 ++--
spec/integration/util/settings.rb | 4 ++--
spec/unit/resource.rb | 25 ++++++++++++++++++++-----
spec/unit/type.rb | 8 ++++----
6 files changed, 38 insertions(+), 17 deletions(-)
diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb
index 91dd547..ab03bfd 100644
--- a/lib/puppet/resource.rb
+++ b/lib/puppet/resource.rb
@@ -108,14 +108,20 @@ class Puppet::Resource
end
# Create our resource.
- def initialize(type, title, parameters = {})
- @reference = Puppet::Resource::Reference.new(type, title)
+ def initialize(type, title, attributes = {})
@parameters = {}
- parameters.each do |param, value|
+ (attributes[:parameters] || {}).each do |param, value|
self[param] = value
end
+ attributes.each do |attr, value|
+ next if attr == :parameters
+ send(attr.to_s + "=", value)
+ end
+
+ @reference = Puppet::Resource::Reference.new(type, title)
+
tag(@reference.type)
tag(@reference.title) if valid_tag?(@reference.title)
end
diff --git a/lib/puppet/transportable.rb b/lib/puppet/transportable.rb
index 85a75d4..68977dc 100644
--- a/lib/puppet/transportable.rb
+++ b/lib/puppet/transportable.rb
@@ -80,7 +80,7 @@ module Puppet
# Create a normalized resource from our TransObject.
def to_resource
- result = Puppet::Resource.new(type, name, @params.dup)
+ result = Puppet::Resource.new(type, name, :parameters => @params.dup)
result.tag(*tags)
result
diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb
index e6e1333..a05d85b 100644
--- a/lib/puppet/util/settings.rb
+++ b/lib/puppet/util/settings.rb
@@ -814,14 +814,14 @@ Generated on #{Time.now}.
next unless sections.nil? or sections.include?(setting.section)
if user = setting.owner and user != "root" and catalog.resource(:user, user).nil?
- resource = Puppet::Resource.new(:user, user, :ensure => :present)
+ resource = Puppet::Resource.new(:user, user, :parameters => {:ensure => :present})
if self[:group]
resource[:gid] = self[:group]
end
catalog.add_resource resource
end
if group = setting.group and ! %w{root wheel}.include?(group) and catalog.resource(:group, group).nil?
- catalog.add_resource Puppet::Resource.new(:group, group, :ensure => :present)
+ catalog.add_resource Puppet::Resource.new(:group, group, :parameters => {:ensure => :present})
end
end
end
diff --git a/spec/integration/util/settings.rb b/spec/integration/util/settings.rb
index 146b988..faab9db 100755
--- a/spec/integration/util/settings.rb
+++ b/spec/integration/util/settings.rb
@@ -9,7 +9,7 @@ describe Puppet::Util::Settings do
it "should be able to make needed directories" do
settings = Puppet::Util::Settings.new
- settings.setdefaults :main, :maindir => [tmpfile("main"), "a"]
+ settings.setdefaults :main, :maindir => [tmpfile("main"), "a"], :noop => [false, "meh"]
settings.use(:main)
@@ -18,7 +18,7 @@ describe Puppet::Util::Settings do
it "should make its directories with the corret modes" do
settings = Puppet::Util::Settings.new
- settings.setdefaults :main, :maindir => {:default => tmpfile("main"), :desc => "a", :mode => 0750}
+ settings.setdefaults :main, :maindir => {:default => tmpfile("main"), :desc => "a", :mode => 0750}, :noop => [false, "meh"]
settings.use(:main)
diff --git a/spec/unit/resource.rb b/spec/unit/resource.rb
index b26f4f9..32b0017 100755
--- a/spec/unit/resource.rb
+++ b/spec/unit/resource.rb
@@ -23,10 +23,6 @@ describe Puppet::Resource do
Puppet::Resource.new("file", "/f")
end
- it "should allow setting of parameters" do
- Puppet::Resource.new("file", "/f", :noop => true)[:noop].should be_true
- end
-
it "should tag itself with its type" do
Puppet::Resource.new("file", "/f").should be_tagged("file")
end
@@ -38,6 +34,11 @@ describe Puppet::Resource do
it "should not tag itself with its title if the title is a not valid tag" do
Puppet::Resource.new("file", "/bar").should_not be_tagged("/bar")
end
+
+ it "should allow setting of attributes" do
+ Puppet::Resource.new("file", "/bar", :file => "/foo").file.should == "/foo"
+ Puppet::Resource.new("file", "/bar", :exported => true).should be_exported
+ end
end
it "should use the resource reference to determine its type" do
@@ -89,16 +90,30 @@ describe Puppet::Resource do
resource.should be_exported
end
+ it "should support an environment attribute"
+
+ it "should convert its environment into an environment instance if one is provided"
+
+ it "should support a namespace attribute"
+
describe "when managing parameters" do
before do
@resource = Puppet::Resource.new("file", "/my/file")
end
+ it "should be able to check whether parameters are valid when the resource models builtin resources"
+
+ it "should be able to check whether parameters are valid when the resource models defined resources"
+
it "should allow setting and retrieving of parameters" do
@resource[:foo] = "bar"
@resource[:foo].should == "bar"
end
+ it "should allow setting of parameters at initialization" do
+ Puppet::Resource.new("file", "/my/file", :parameters => {:foo => "bar"})[:foo].should == "bar"
+ end
+
it "should canonicalize retrieved parameter names to treat symbols and strings equivalently" do
@resource[:foo] = "bar"
@resource["foo"].should == "bar"
@@ -255,7 +270,7 @@ describe Puppet::Resource do
describe "when converting to puppet code" do
before do
- @resource = Puppet::Resource.new("one::two", "/my/file", :noop => true, :foo => %w{one two})
+ @resource = Puppet::Resource.new("one::two", "/my/file", :parameters => {:noop => true, :foo => %w{one two}})
end
it "should print the type and title" do
diff --git a/spec/unit/type.rb b/spec/unit/type.rb
index 11bedaa..cfc061f 100755
--- a/spec/unit/type.rb
+++ b/spec/unit/type.rb
@@ -125,7 +125,7 @@ describe Puppet::Type do
describe "and passed a Puppet::Resource instance" do
it "should set its title to the title of the resource if the resource type is equal to the current type" do
- resource = Puppet::Resource.new(:mount, "/foo", :name => "/other")
+ resource = Puppet::Resource.new(:mount, "/foo", :parameters => {:name => "/other"})
Puppet::Type.type(:mount).new(resource).title.should == "/foo"
end
@@ -152,7 +152,7 @@ describe Puppet::Type do
end
it "should copy the resource's parameters as its own" do
- resource = Puppet::Resource.new(:mount, "/foo", :atboot => true, :fstype => "boo")
+ resource = Puppet::Resource.new(:mount, "/foo", :parameters => {:atboot => true, :fstype => "boo"})
params = Puppet::Type.type(:mount).new(resource).to_hash
params[:fstype].should == "boo"
params[:atboot].should == true
@@ -214,7 +214,7 @@ describe Puppet::Type do
it "should set the attributes in the order returned by the class's :allattrs method" do
Puppet::Type.type(:mount).stubs(:allattrs).returns([:name, :atboot, :noop])
- resource = Puppet::Resource.new(:mount, "/foo", :name => "myname", :atboot => "myboot", :noop => "whatever")
+ resource = Puppet::Resource.new(:mount, "/foo", :parameters => {:name => "myname", :atboot => "myboot", :noop => "whatever"})
set = []
@@ -231,7 +231,7 @@ describe Puppet::Type do
it "should always set the name and then default provider before anything else" do
Puppet::Type.type(:mount).stubs(:allattrs).returns([:provider, :name, :atboot])
- resource = Puppet::Resource.new(:mount, "/foo", :name => "myname", :atboot => "myboot")
+ resource = Puppet::Resource.new(:mount, "/foo", :parameters => {:name => "myname", :atboot => "myboot"})
set = []
--
1.6.1
Shouldn't happen often, but it's easier to be more failure-tolerant.
Signed-off-by: Luke Kanies <lu...@reductivelabs.com>
---
lib/puppet/node/environment.rb | 1 +
spec/unit/node/environment.rb | 5 +++++
2 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/lib/puppet/node/environment.rb b/lib/puppet/node/environment.rb
index c65f78b..3bffc62 100644
--- a/lib/puppet/node/environment.rb
+++ b/lib/puppet/node/environment.rb
@@ -27,6 +27,7 @@ class Puppet::Node::Environment
# Return an existing environment instance, or create a new one.
def self.new(name = nil)
+ return name if name.is_a?(self)
name ||= Puppet.settings.value(:environment)
raise ArgumentError, "Environment name must be specified" unless name
diff --git a/spec/unit/node/environment.rb b/spec/unit/node/environment.rb
index 9536373..b4f44d0 100755
--- a/spec/unit/node/environment.rb
+++ b/spec/unit/node/environment.rb
@@ -43,6 +43,11 @@ describe Puppet::Node::Environment do
Puppet::Node::Environment.new(:one).to_s.should == "one"
end
+ it "should just return any provided environment if an environment is provided as the name" do
+ one = Puppet::Node::Environment.new(:one)
+ Puppet::Node::Environment.new(one).should equal(one)
+ end
+
describe "when managing known resource types" do
before do
@env = Puppet::Node::Environment.new("dev")
--
1.6.1