diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb index 972e9e66c..ab127602b 100644 --- a/lib/puppet/defaults.rb +++ b/lib/puppet/defaults.rb @@ -1,790 +1,793 @@ # The majority of the system configuration parameters are set in this file. module Puppet setdefaults(:main, :confdir => [Puppet.run_mode.conf_dir, "The main Puppet configuration directory. The default for this parameter is calculated based on the user. If the process is running as root or the user that `puppet master` is supposed to run as, it defaults to a system directory, but if it's running as any other user, it defaults to being in `~`."], :vardir => [Puppet.run_mode.var_dir, "Where Puppet stores dynamic and growing data. The default for this parameter is calculated specially, like `confdir`_."], :name => [Puppet.application_name.to_s, "The name of the application, if we are running as one. The default is essentially $0 without the path or `.rb`."], :run_mode => [Puppet.run_mode.name.to_s, "The effective 'run mode' of the application: master, agent, or user."] ) setdefaults(:main, :logdir => Puppet.run_mode.logopts) setdefaults(:main, :trace => [false, "Whether to print stack traces on some errors"], :autoflush => [false, "Whether log files should always flush to disk."], :syslogfacility => ["daemon", "What syslog facility to use when logging to syslog. Syslog has a fixed list of valid facilities, and you must choose one of those; you cannot just make one up."], :statedir => { :default => "$vardir/state", :mode => 01755, :desc => "The directory where Puppet state is stored. Generally, this directory can be removed without causing harm (although it might result in spurious service restarts)." }, :rundir => { :default => Puppet.run_mode.run_dir, :mode => 01777, :desc => "Where Puppet PID files are kept." }, :genconfig => [false, "Whether to just print a configuration to stdout and exit. Only makes sense when used interactively. Takes into account arguments specified on the CLI."], :genmanifest => [false, "Whether to just print a manifest to stdout and exit. Only makes sense when used interactively. Takes into account arguments specified on the CLI."], :configprint => ["", "Print the value of a specific configuration parameter. If a parameter is provided for this, then the value is printed and puppet exits. Comma-separate multiple values. For a list of all values, specify 'all'. This feature is only available in Puppet versions higher than 0.18.4."], :color => ["ansi", "Whether to use colors when logging to the console. Valid values are `ansi` (equivalent to `true`), `html` (mostly used during testing with TextMate), and `false`, which produces no color."], :mkusers => [false, "Whether to create the necessary user and group that puppet agent will run as."], :manage_internal_file_permissions => [true, "Whether Puppet should manage the owner, group, and mode of files it uses internally" ], :onetime => {:default => false, :desc => "Run the configuration once, rather than as a long-running daemon. This is useful for interactively running puppetd.", :short => 'o' }, :path => {:default => "none", :desc => "The shell search path. Defaults to whatever is inherited from the parent process.", :call_on_define => true, # Call our hook with the default value, so we always get the libdir set. :hook => proc do |value| ENV["PATH"] = "" if ENV["PATH"].nil? ENV["PATH"] = value unless value == "none" paths = ENV["PATH"].split(File::PATH_SEPARATOR) %w{/usr/sbin /sbin}.each do |path| ENV["PATH"] += File::PATH_SEPARATOR + path unless paths.include?(path) end value end }, :libdir => {:default => "$vardir/lib", :desc => "An extra search path for Puppet. This is only useful for those files that Puppet will load on demand, and is only guaranteed to work for those cases. In fact, the autoload mechanism is responsible for making sure this directory is in Ruby's search path", :call_on_define => true, # Call our hook with the default value, so we always get the libdir set. :hook => proc do |value| $LOAD_PATH.delete(@oldlibdir) if defined?(@oldlibdir) and $LOAD_PATH.include?(@oldlibdir) @oldlibdir = value $LOAD_PATH << value end }, :ignoreimport => [false, "A parameter that can be used in commit hooks, since it enables you to parse-check a single file rather than requiring that all files exist."], :authconfig => [ "$confdir/namespaceauth.conf", "The configuration file that defines the rights to the different namespaces and methods. This can be used as a coarse-grained authorization system for both `puppet agent` and `puppet master`." ], :environment => {:default => "production", :desc => "The environment Puppet is running in. For clients (e.g., `puppet agent`) this determines the environment itself, which is used to find modules and much more. For servers (i.e., `puppet master`) this provides the default environment for nodes we know nothing about." }, :diff_args => ["-u", "Which arguments to pass to the diff command when printing differences between files."], :diff => ["diff", "Which diff command to use when printing differences between files."], :show_diff => [false, "Whether to print a contextual diff when files are being replaced. The diff is printed on stdout, so this option is meaningless unless you are running Puppet interactively. This feature currently requires the `diff/lcs` Ruby library."], :daemonize => { :default => true, :desc => "Send the process into the background. This is the default.", :short => "D" }, :maximum_uid => [4294967290, "The maximum allowed UID. Some platforms use negative UIDs but then ship with tools that do not know how to handle signed ints, so the UIDs show up as huge numbers that can then not be fed back into the system. This is a hackish way to fail in a slightly more useful way when that happens."], :node_terminus => ["plain", "Where to find information about nodes."], :catalog_terminus => ["compiler", "Where to get node catalogs. This is useful to change if, for instance, you'd like to pre-compile catalogs and store them in memcached or some other easily-accessed store."], :facts_terminus => [Puppet.application_name.to_s == "master" ? 'yaml' : 'facter', "The node facts terminus."], :httplog => { :default => "$logdir/http.log", :owner => "root", :mode => 0640, :desc => "Where the puppet agent web server logs." }, :http_proxy_host => ["none", "The HTTP proxy host to use for outgoing connections. Note: You may need to use a FQDN for the server hostname when using a proxy."], :http_proxy_port => [3128, "The HTTP proxy port to use for outgoing connections"], :filetimeout => [ 15, "The minimum time to wait (in seconds) between checking for updates in configuration files. This timeout determines how quickly Puppet checks whether a file (such as manifests or templates) has changed on disk." ], :queue_type => ["stomp", "Which type of queue to use for asynchronous processing."], :queue_type => ["stomp", "Which type of queue to use for asynchronous processing."], :queue_source => ["stomp://localhost:61613/", "Which type of queue to use for asynchronous processing. If your stomp server requires authentication, you can include it in the URI as long as your stomp client library is at least 1.1.1"], :async_storeconfigs => {:default => false, :desc => "Whether to use a queueing system to provide asynchronous database integration. Requires that `puppetqd` be running and that 'PSON' support for ruby be installed.", :hook => proc do |value| if value # This reconfigures the terminii for Node, Facts, and Catalog Puppet.settings[:storeconfigs] = true # But then we modify the configuration Puppet::Resource::Catalog.cache_class = :queue else raise "Cannot disable asynchronous storeconfigs in a running process" end end }, :thin_storeconfigs => {:default => false, :desc => "Boolean; wether storeconfigs store in the database only the facts and exported resources. If true, then storeconfigs performance will be higher and still allow exported/collected resources, but other usage external to Puppet might not work", :hook => proc do |value| Puppet.settings[:storeconfigs] = true if value end }, :config_version => ["", "How to determine the configuration version. By default, it will be the time that the configuration is parsed, but you can provide a shell script to override how the version is determined. The output of this script will be added to every log message in the reports, allowing you to correlate changes on your hosts to the source version on the server."], :zlib => [true, "Boolean; whether to use the zlib library", ], :prerun_command => ["", "A command to run before every agent run. If this command returns a non-zero return code, the entire Puppet run will fail."], :postrun_command => ["", "A command to run after every agent run. If this command returns a non-zero return code, the entire Puppet run will be considered to have failed, even though it might have performed work during the normal run."], :freeze_main => [false, "Freezes the 'main' class, disallowing any code to be added to it. This essentially means that you can't have any code outside of a node, class, or definition other than in the site manifest."] ) hostname = Facter["hostname"].value domain = Facter["domain"].value if domain and domain != "" fqdn = [hostname, domain].join(".") else fqdn = hostname end Puppet.setdefaults( :main, # We have to downcase the fqdn, because the current ssl stuff (as oppsed to in master) doesn't have good facilities for # manipulating naming. :certname => {:default => fqdn.downcase, :desc => "The name to use when handling certificates. Defaults to the fully qualified domain name.", :call_on_define => true, # Call our hook with the default value, so we're always downcased :hook => proc { |value| raise(ArgumentError, "Certificate names must be lower case; see #1168") unless value == value.downcase }}, :certdnsnames => ['', "The DNS names on the Server certificate as a colon-separated list. If it's anything other than an empty string, it will be used as an alias in the created certificate. By default, only the server gets an alias set up, and only for 'puppet'."], :certdir => { :default => "$ssldir/certs", :owner => "service", :desc => "The certificate directory." }, :ssldir => { :default => "$confdir/ssl", :mode => 0771, :owner => "service", :desc => "Where SSL certificates are kept." }, :publickeydir => { :default => "$ssldir/public_keys", :owner => "service", :desc => "The public key directory." }, :requestdir => { :default => "$ssldir/certificate_requests", :owner => "service", :desc => "Where host certificate requests are stored." }, :privatekeydir => { :default => "$ssldir/private_keys", :mode => 0750, :owner => "service", :desc => "The private key directory." }, :privatedir => { :default => "$ssldir/private", :mode => 0750, :owner => "service", :desc => "Where the client stores private certificate information." }, :passfile => { :default => "$privatedir/password", :mode => 0640, :owner => "service", :desc => "Where puppet agent stores the password for its private key. Generally unused." }, :hostcsr => { :default => "$ssldir/csr_$certname.pem", :mode => 0644, :owner => "service", :desc => "Where individual hosts store and look for their certificate requests." }, :hostcert => { :default => "$certdir/$certname.pem", :mode => 0644, :owner => "service", :desc => "Where individual hosts store and look for their certificates." }, :hostprivkey => { :default => "$privatekeydir/$certname.pem", :mode => 0600, :owner => "service", :desc => "Where individual hosts store and look for their private key." }, :hostpubkey => { :default => "$publickeydir/$certname.pem", :mode => 0644, :owner => "service", :desc => "Where individual hosts store and look for their public key." }, :localcacert => { :default => "$certdir/ca.pem", :mode => 0644, :owner => "service", :desc => "Where each client stores the CA certificate." }, :hostcrl => { :default => "$ssldir/crl.pem", :mode => 0644, :owner => "service", :desc => "Where the host's certificate revocation list can be found. This is distinct from the certificate authority's CRL." }, :certificate_revocation => [true, "Whether certificate revocation should be supported by downloading a Certificate Revocation List (CRL) to all clients. If enabled, CA chaining will almost definitely not work."] ) setdefaults( :ca, :ca_name => ["Puppet CA: $certname", "The name to use the Certificate Authority certificate."], :cadir => { :default => "$ssldir/ca", :owner => "service", :group => "service", :mode => 0770, :desc => "The root directory for the certificate authority." }, :cacert => { :default => "$cadir/ca_crt.pem", :owner => "service", :group => "service", :mode => 0660, :desc => "The CA certificate." }, :cakey => { :default => "$cadir/ca_key.pem", :owner => "service", :group => "service", :mode => 0660, :desc => "The CA private key." }, :capub => { :default => "$cadir/ca_pub.pem", :owner => "service", :group => "service", :desc => "The CA public key." }, :cacrl => { :default => "$cadir/ca_crl.pem", :owner => "service", :group => "service", :mode => 0664, :desc => "The certificate revocation list (CRL) for the CA. Will be used if present but otherwise ignored.", :hook => proc do |value| if value == 'false' Puppet.warning "Setting the :cacrl to 'false' is deprecated; Puppet will just ignore the crl if yours is missing" end end }, :caprivatedir => { :default => "$cadir/private", :owner => "service", :group => "service", :mode => 0770, :desc => "Where the CA stores private certificate information." }, :csrdir => { :default => "$cadir/requests", :owner => "service", :group => "service", :desc => "Where the CA stores certificate requests" }, :signeddir => { :default => "$cadir/signed", :owner => "service", :group => "service", :mode => 0770, :desc => "Where the CA stores signed certificates." }, :capass => { :default => "$caprivatedir/ca.pass", :owner => "service", :group => "service", :mode => 0660, :desc => "Where the CA stores the password for the private key" }, :serial => { :default => "$cadir/serial", :owner => "service", :group => "service", :mode => 0644, :desc => "Where the serial number for certificates is stored." }, :autosign => { :default => "$confdir/autosign.conf", :mode => 0644, :desc => "Whether to enable autosign. Valid values are true (which autosigns any key request, and is a very bad idea), false (which never autosigns any key request), and the path to a file, which uses that configuration file to determine which keys to sign."}, :ca_days => ["", "How long a certificate should be valid. This parameter is deprecated, use ca_ttl instead"], :ca_ttl => ["5y", "The default TTL for new certificates; valid values must be an integer, optionally followed by one of the units 'y' (years of 365 days), 'd' (days), 'h' (hours), or 's' (seconds). The unit defaults to seconds. If this parameter is set, ca_days is ignored. Examples are '3600' (one hour) and '1825d', which is the same as '5y' (5 years) "], :ca_md => ["md5", "The type of hash used in certificates."], :req_bits => [2048, "The bit length of the certificates."], :keylength => [1024, "The bit length of keys."], :cert_inventory => { :default => "$cadir/inventory.txt", :mode => 0644, :owner => "service", :group => "service", :desc => "A Complete listing of all certificates" } ) # Define the config default. setdefaults( Puppet.settings[:name], :config => ["$confdir/puppet.conf", "The configuration file for #{Puppet[:name]}."], :pidfile => ["$rundir/$name.pid", "The pid file"], :bindaddress => ["", "The address a listening server should bind to. Mongrel servers default to 127.0.0.1 and WEBrick defaults to 0.0.0.0."], :servertype => {:default => "webrick", :desc => "The type of server to use. Currently supported options are webrick and mongrel. If you use mongrel, you will need a proxy in front of the process or processes, since Mongrel cannot speak SSL.", :call_on_define => true, # Call our hook with the default value, so we always get the correct bind address set. :hook => proc { |value| value == "webrick" ? Puppet.settings[:bindaddress] = "0.0.0.0" : Puppet.settings[:bindaddress] = "127.0.0.1" if Puppet.settings[:bindaddress] == "" } } ) setdefaults(:master, :user => ["puppet", "The user puppet master should run as."], :group => ["puppet", "The group puppet master should run as."], :manifestdir => ["$confdir/manifests", "Where puppet master looks for its manifests."], :manifest => ["$manifestdir/site.pp", "The entry-point manifest for puppet master."], :code => ["", "Code to parse directly. This is essentially only used by `puppet`, and should only be set if you're writing your own Puppet executable"], :masterlog => { :default => "$logdir/puppetmaster.log", :owner => "service", :group => "service", :mode => 0660, :desc => "Where puppet master logs. This is generally not used, since syslog is the default log destination." }, :masterhttplog => { :default => "$logdir/masterhttp.log", :owner => "service", :group => "service", :mode => 0660, :create => true, :desc => "Where the puppet master web server logs." }, :masterport => [8140, "Which port puppet master listens on."], :parseonly => [false, "Just check the syntax of the manifests."], :node_name => ["cert", "How the puppetmaster determines the client's identity and sets the 'hostname', 'fqdn' and 'domain' facts for use in the manifest, in particular for determining which 'node' statement applies to the client. Possible values are 'cert' (use the subject's CN in the client's certificate) and 'facter' (use the hostname that the client reported in its facts)"], :bucketdir => { :default => "$vardir/bucket", :mode => 0750, :owner => "service", :group => "service", :desc => "Where FileBucket files are stored." }, :rest_authconfig => [ "$confdir/auth.conf", "The configuration file that defines the rights to the different rest indirections. This can be used as a fine-grained authorization system for `puppet master`." ], :ca => [true, "Wether the master should function as a certificate authority."], :modulepath => {:default => "$confdir/modules:/usr/share/puppet/modules", :desc => "The search path for modules as a colon-separated list of directories.", :type => :setting }, # We don't want this to be considered a file, since it's multiple files. :ssl_client_header => ["HTTP_X_CLIENT_DN", "The header containing an authenticated client's SSL DN. Only used with Mongrel. This header must be set by the proxy to the authenticated client's SSL DN (e.g., `/CN=puppet.puppetlabs.com`). See http://projects.puppetlabs.com/projects/puppet/wiki/Using_Mongrel for more information."], :ssl_client_verify_header => ["HTTP_X_CLIENT_VERIFY", "The header containing the status message of the client verification. Only used with Mongrel. This header must be set by the proxy to 'SUCCESS' if the client successfully authenticated, and anything else otherwise. See http://projects.puppetlabs.com/projects/puppet/wiki/Using_Mongrel for more information."], # To make sure this directory is created before we try to use it on the server, we need # it to be in the server section (#1138). :yamldir => {:default => "$vardir/yaml", :owner => "service", :group => "service", :mode => "750", :desc => "The directory in which YAML data is stored, usually in a subdirectory."}, :server_datadir => {:default => "$vardir/server_data", :owner => "service", :group => "service", :mode => "750", :desc => "The directory in which serialized data is stored, usually in a subdirectory."}, :reports => ["store", "The list of reports to generate. All reports are looked for in `puppet/reports/name.rb`, and multiple report names should be comma-separated (whitespace is okay)." ], :reportdir => {:default => "$vardir/reports", :mode => 0750, :owner => "service", :group => "service", :desc => "The directory in which to store reports received from the client. Each client gets a separate subdirectory."}, :reporturl => ["http://localhost:3000/reports", "The URL used by the http reports processor to send reports"], :fileserverconfig => ["$confdir/fileserver.conf", "Where the fileserver configuration is stored."], + :strict_hostname_checking => [false, "Whether to only search for the complete + hostname as it is in the certificate when searching for node information + in the catalogs."] + ) + + setdefaults(:metrics, :rrddir => {:default => "$vardir/rrd", :owner => "service", :group => "service", :desc => "The directory where RRD database files are stored. Directories for each reporting host will be created under this directory." }, :rrdinterval => ["$runinterval", "How often RRD should expect data. - This should match how often the hosts report back to the server."], - :strict_hostname_checking => [false, "Whether to only search for the complete - hostname as it is in the certificate when searching for node information - in the catalogs."] + This should match how often the hosts report back to the server."] ) setdefaults(:agent, :localconfig => { :default => "$statedir/localconfig", :owner => "root", :mode => 0660, :desc => "Where puppet agent caches the local configuration. An extension indicating the cache format is added automatically."}, :statefile => { :default => "$statedir/state.yaml", :mode => 0660, :desc => "Where puppet agent and puppet master store state associated with the running configuration. In the case of puppet master, this file reflects the state discovered through interacting with clients." }, :clientyamldir => {:default => "$vardir/client_yaml", :mode => "750", :desc => "The directory in which client-side YAML data is stored."}, :client_datadir => {:default => "$vardir/client_data", :mode => "750", :desc => "The directory in which serialized data is stored on the client."}, :classfile => { :default => "$statedir/classes.txt", :owner => "root", :mode => 0644, :desc => "The file in which puppet agent stores a list of the classes associated with the retrieved configuration. Can be loaded in the separate `puppet` executable using the `--loadclasses` option."}, :puppetdlog => { :default => "$logdir/puppetd.log", :owner => "root", :mode => 0640, :desc => "The log file for puppet agent. This is generally not used." }, :server => ["puppet", "The server to which server puppet agent should connect"], :ignoreschedules => [false, "Boolean; whether puppet agent should ignore schedules. This is useful for initial puppet agent runs."], :puppetport => [8139, "Which port puppet agent listens on."], :noop => [false, "Whether puppet agent should be run in noop mode."], :runinterval => [1800, # 30 minutes "How often puppet agent applies the client configuration; in seconds."], :listen => [false, "Whether puppet agent should listen for connections. If this is true, then by default only the `runner` server is started, which allows remote authorized and authenticated nodes to connect and trigger `puppet agent` runs."], :ca_server => ["$server", "The server to use for certificate authority requests. It's a separate server because it cannot and does not need to horizontally scale."], :ca_port => ["$masterport", "The port to use for the certificate authority."], :catalog_format => { :default => "", :desc => "(Deprecated for 'preferred_serialization_format') What format to use to dump the catalog. Only supports 'marshal' and 'yaml'. Only matters on the client, since it asks the server for a specific format.", :hook => proc { |value| if value Puppet.warning "Setting 'catalog_format' is deprecated; use 'preferred_serialization_format' instead." Puppet.settings[:preferred_serialization_format] = value end } }, :preferred_serialization_format => ["pson", "The preferred means of serializing ruby instances for passing over the wire. This won't guarantee that all instances will be serialized using this method, since not all classes can be guaranteed to support this format, but it will be used for all classes that support it."], :puppetdlockfile => [ "$statedir/puppetdlock", "A lock file to temporarily stop puppet agent from doing anything."], :usecacheonfailure => [true, "Whether to use the cached configuration when the remote configuration will not compile. This option is useful for testing new configurations, where you want to fix the broken configuration rather than reverting to a known-good one." ], :use_cached_catalog => [false, "Whether to only use the cached catalog rather than compiling a new catalog on every run. Puppet can be run with this enabled by default and then selectively disabled when a recompile is desired."], :ignorecache => [false, "Ignore cache and always recompile the configuration. This is useful for testing new configurations, where the local cache may in fact be stale even if the timestamps are up to date - if the facts change or if the server changes." ], :downcasefacts => [false, "Whether facts should be made all lowercase when sent to the server."], :dynamicfacts => ["memorysize,memoryfree,swapsize,swapfree", "Facts that are dynamic; these facts will be ignored when deciding whether changed facts should result in a recompile. Multiple facts should be comma-separated."], :splaylimit => ["$runinterval", "The maximum time to delay before runs. Defaults to being the same as the run interval."], :splay => [false, "Whether to sleep for a pseudo-random (but consistent) amount of time before a run."], :clientbucketdir => { :default => "$vardir/clientbucket", :mode => 0750, :desc => "Where FileBucket files are stored locally." }, :configtimeout => [120, "How long the client should wait for the configuration to be retrieved before considering it a failure. This can help reduce flapping if too many clients contact the server at one time." ], :reportserver => { :default => "$server", :call_on_define => false, :desc => "(Deprecated for 'report_server') The server to which to send transaction reports.", :hook => proc do |value| Puppet.settings[:report_server] = value if value end }, :report_server => ["$server", "The server to which to send transaction reports." ], :report_port => ["$masterport", "The port to communicate with the report_server." ], :report => [false, "Whether to send reports after every transaction." ], :graph => [false, "Whether to create dot graph files for the different configuration graphs. These dot files can be interpreted by tools like OmniGraffle or dot (which is part of ImageMagick)."], :graphdir => ["$statedir/graphs", "Where to store dot-outputted graphs."], :http_compression => [false, "Allow http compression in REST communication with the master. This setting might improve performance for agent -> master communications over slow WANs. Your puppetmaster needs to support compression (usually by activating some settings in a reverse-proxy in front of the puppetmaster, which rules out webrick). It is harmless to activate this settings if your master doesn't support compression, but if it supports it, this setting might reduce performance on high-speed LANs."] ) # Plugin information. setdefaults( :main, :plugindest => ["$libdir", "Where Puppet should store plugins that it pulls down from the central server."], :pluginsource => ["puppet://$server/plugins", "From where to retrieve plugins. The standard Puppet `file` type is used for retrieval, so anything that is a valid file source can be used here."], :pluginsync => [false, "Whether plugins should be synced with the central server."], :pluginsignore => [".svn CVS .git", "What files to ignore when pulling down plugins."] ) # Central fact information. setdefaults( :main, :factpath => {:default => "$vardir/lib/facter:$vardir/facts", :desc => "Where Puppet should look for facts. Multiple directories should be colon-separated, like normal PATH variables.", :call_on_define => true, # Call our hook with the default value, so we always get the value added to facter. :type => :setting, # Don't consider it a file, because it could be multiple colon-separated files :hook => proc { |value| Facter.search(value) if Facter.respond_to?(:search) }}, :factdest => ["$vardir/facts/", "Where Puppet should store facts that it pulls down from the central server."], :factsource => ["puppet://$server/facts/", "From where to retrieve facts. The standard Puppet `file` type is used for retrieval, so anything that is a valid file source can be used here."], :factsync => [false, "Whether facts should be synced with the central server."], :factsignore => [".svn CVS", "What files to ignore when pulling down facts."] ) setdefaults( :tagmail, :tagmap => ["$confdir/tagmail.conf", "The mapping between reporting tags and email addresses."], :sendmail => [%x{which sendmail 2>/dev/null}.chomp, "Where to find the sendmail binary with which to send email."], :reportfrom => ["report@" + [Facter["hostname"].value, Facter["domain"].value].join("."), "The 'from' email address for the reports."], :smtpserver => ["none", "The server through which to send email reports."] ) setdefaults( :rails, :dblocation => { :default => "$statedir/clientconfigs.sqlite3", :mode => 0660, :owner => "service", :group => "service", :desc => "The database cache for client configurations. Used for querying within the language." }, :dbadapter => [ "sqlite3", "The type of database to use." ], :dbmigrate => [ false, "Whether to automatically migrate the database." ], :dbname => [ "puppet", "The name of the database to use." ], :dbserver => [ "localhost", "The database server for caching. Only used when networked databases are used."], :dbport => [ "", "The database password for caching. Only used when networked databases are used."], :dbuser => [ "puppet", "The database user for caching. Only used when networked databases are used."], :dbpassword => [ "puppet", "The database password for caching. Only used when networked databases are used."], :dbsocket => [ "", "The database socket location. Only used when networked databases are used. Will be ignored if the value is an empty string."], :dbconnections => [ 0, "The number of database connections. Only used when networked databases are used. Will be ignored if the value is an empty string or is less than 1."], :railslog => {:default => "$logdir/rails.log", :mode => 0600, :owner => "service", :group => "service", :desc => "Where Rails-specific logs are sent" }, :rails_loglevel => ["info", "The log level for Rails connections. The value must be a valid log level within Rails. Production environments normally use `info` and other environments normally use `debug`."] ) setdefaults( :couchdb, :couchdb_url => ["http://127.0.0.1:5984/puppet", "The url where the puppet couchdb database will be created"] ) setdefaults( :transaction, :tags => ["", "Tags to use to find resources. If this is set, then only resources tagged with the specified tags will be applied. Values must be comma-separated."], :evaltrace => [false, "Whether each resource should log when it is being evaluated. This allows you to interactively see exactly what is being done."], :summarize => [false, "Whether to print a transaction summary." ] ) setdefaults( :main, :external_nodes => ["none", "An external command that can produce node information. The output must be a YAML dump of a hash, and that hash must have one or both of `classes` and `parameters`, where `classes` is an array and `parameters` is a hash. For unknown nodes, the commands should exit with a non-zero exit code. This command makes it straightforward to store your node mapping information in other data sources like databases."]) setdefaults( :ldap, :ldapnodes => [false, "Whether to search for node configurations in LDAP. See http://projects.puppetlabs.com/projects/puppet/wiki/LDAP_Nodes for more information."], :ldapssl => [false, "Whether SSL should be used when searching for nodes. Defaults to false because SSL usually requires certificates to be set up on the client side."], :ldaptls => [false, "Whether TLS should be used when searching for nodes. Defaults to false because TLS usually requires certificates to be set up on the client side."], :ldapserver => ["ldap", "The LDAP server. Only used if `ldapnodes` is enabled."], :ldapport => [389, "The LDAP port. Only used if `ldapnodes` is enabled."], :ldapstring => ["(&(objectclass=puppetClient)(cn=%s))", "The search string used to find an LDAP node."], :ldapclassattrs => ["puppetclass", "The LDAP attributes to use to define Puppet classes. Values should be comma-separated."], :ldapstackedattrs => ["puppetvar", "The LDAP attributes that should be stacked to arrays by adding the values in all hierarchy elements of the tree. Values should be comma-separated."], :ldapattrs => ["all", "The LDAP attributes to include when querying LDAP for nodes. All returned attributes are set as variables in the top-level scope. Multiple values should be comma-separated. The value 'all' returns all attributes."], :ldapparentattr => ["parentnode", "The attribute to use to define the parent node."], :ldapuser => ["", "The user to use to connect to LDAP. Must be specified as a full DN."], :ldappassword => ["", "The password to use to connect to LDAP."], :ldapbase => ["", "The search base for LDAP searches. It's impossible to provide a meaningful default here, although the LDAP libraries might have one already set. Generally, it should be the 'ou=Hosts' branch under your main directory."] ) setdefaults(:master, :storeconfigs => {:default => false, :desc => "Whether to store each client's configuration. This requires ActiveRecord from Ruby on Rails.", :call_on_define => true, # Call our hook with the default value, so we always get the libdir set. :hook => proc do |value| require 'puppet/node' require 'puppet/node/facts' if value require 'puppet/rails' raise "StoreConfigs not supported without ActiveRecord 2.1 or higher" unless Puppet.features.rails? Puppet::Resource::Catalog.cache_class = :active_record unless Puppet.settings[:async_storeconfigs] Puppet::Node::Facts.cache_class = :active_record Puppet::Node.cache_class = :active_record end end } ) # This doesn't actually work right now. setdefaults( :parser, :lexical => [false, "Whether to use lexical scoping (vs. dynamic)."], :templatedir => ["$vardir/templates", "Where Puppet looks for template files. Can be a list of colon-seperated directories." ] ) end diff --git a/lib/puppet/dsl/resource_type_api.rb b/lib/puppet/dsl/resource_type_api.rb index ecb914189..8810d5368 100644 --- a/lib/puppet/dsl/resource_type_api.rb +++ b/lib/puppet/dsl/resource_type_api.rb @@ -1,46 +1,34 @@ require 'puppet/resource/type' +# Type of the objects inside of which pure ruby manifest files are +# executed. Provides methods for creating defines, hostclasses, and +# nodes. class Puppet::DSL::ResourceTypeAPI + def initialize + @__created_ast_objects__ = [] + end + def define(name, *args, &block) - result = __mk_resource_type__(:definition, name, Hash.new, block) - result.set_arguments(__munge_type_arguments__(args)) + args = args.inject([]) do |result, item| + if item.is_a?(Hash) + item.each { |p, v| result << [p, v] } + else + result << item + end + result + end + @__created_ast_objects__.push Puppet::Parser::AST::Definition.new(name, {:arguments => args}, &block) nil end def hostclass(name, options = {}, &block) - __mk_resource_type__(:hostclass, name, options, block) + @__created_ast_objects__.push Puppet::Parser::AST::Hostclass.new(name, options, &block) nil end def node(name, options = {}, &block) - __mk_resource_type__(:node, name, options, block) + name = [name] unless name.is_a?(Array) + @__created_ast_objects__.push Puppet::Parser::AST::Node.new(name, options, &block) nil end - - # Note: we don't want the user to call the following methods - # directly. However, we can't stop them by making the methods - # private because the user's .rb code gets instance_eval'ed on an - # instance of this class. So instead we name the methods using - # double underscores to discourage customers from calling them. - - def __mk_resource_type__(type, name, options, code) - klass = Puppet::Resource::Type.new(type, name, options) - - klass.ruby_code = code if code - - Thread.current[:known_resource_types].add klass - - klass - end - - def __munge_type_arguments__(args) - args.inject([]) do |result, item| - if item.is_a?(Hash) - item.each { |p, v| result << [p, v] } - else - result << item - end - result - end - end end diff --git a/lib/puppet/node/environment.rb b/lib/puppet/node/environment.rb index 3f67474f9..3d55ac1a0 100644 --- a/lib/puppet/node/environment.rb +++ b/lib/puppet/node/environment.rb @@ -1,147 +1,173 @@ require 'puppet/util/cacher' require 'monitor' # Just define it, so this class has fewer load dependencies. class Puppet::Node 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 = {} # 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 symbol = name.to_sym return @seen[symbol] if @seen[symbol] obj = self.allocate obj.send :initialize, symbol @seen[symbol] = obj end def self.current Thread.current[:environment] || root end def self.current=(env) Thread.current[:environment] = new(env) end def self.root @root end # This is only used for testing. def self.clear @seen.clear end attr_reader :name # Return an environment-specific setting. def [](param) Puppet.settings.value(param, self.name) end def initialize(name) @name = name extend MonitorMixin end def known_resource_types # This makes use of short circuit evaluation to get the right thread-safe # per environment semantics with an efficient most common cases; we almost # always just return our thread's known-resource types. Only at the start # of a compilation (after our thread var has been set to nil) or when the # environment has changed do we delve deeper. Thread.current[:known_resource_types] = nil if (krt = Thread.current[:known_resource_types]) && krt.environment != self Thread.current[:known_resource_types] ||= synchronize { if @known_resource_types.nil? or @known_resource_types.stale? @known_resource_types = Puppet::Resource::TypeCollection.new(self) - @known_resource_types.perform_initial_import + @known_resource_types.import_ast(perform_initial_import, '') end @known_resource_types } end def module(name) mod = Puppet::Module.new(name, self) return nil unless mod.exist? mod end # Cache the modulepath, so that we aren't searching through # all known directories all the time. cached_attr(:modulepath, :ttl => Puppet[:filetimeout]) do dirs = self[:modulepath].split(File::PATH_SEPARATOR) dirs = ENV["PUPPETLIB"].split(File::PATH_SEPARATOR) + dirs if ENV["PUPPETLIB"] validate_dirs(dirs) end # Return all modules from this environment. # Cache the list, because it can be expensive to create. cached_attr(:modules, :ttl => Puppet[:filetimeout]) do module_names = modulepath.collect { |path| Dir.entries(path) }.flatten.uniq module_names.collect do |path| begin Puppet::Module.new(path, self) rescue Puppet::Module::Error => e nil end end.compact end # Cache the manifestdir, so that we aren't searching through # all known directories all the time. cached_attr(:manifestdir, :ttl => Puppet[:filetimeout]) do validate_dirs(self[:manifestdir].split(File::PATH_SEPARATOR)) end def to_s name.to_s end # The only thing we care about when serializing an environment is its # identity; everything else is ephemeral and should not be stored or # transmitted. def to_zaml(z) self.to_s.to_zaml(z) end def validate_dirs(dirs) dirs.collect do |dir| if dir !~ /^#{File::SEPARATOR}/ File.join(Dir.getwd, dir) else dir end end.find_all do |p| p =~ /^#{File::SEPARATOR}/ && FileTest.directory?(p) end end + private + + def perform_initial_import + return empty_parse_result if Puppet.settings[:ignoreimport] + parser = Puppet::Parser::Parser.new(self) + if code = Puppet.settings.uninterpolated_value(:code, name.to_s) and code != "" + parser.string = code + else + file = Puppet.settings.value(:manifest, name.to_s) + return empty_parse_result unless File.exist?(file) + parser.file = file + end + parser.parse + rescue => detail + msg = "Could not parse for environment #{self}: #{detail}" + error = Puppet::Error.new(msg) + error.set_backtrace(detail.backtrace) + raise error + end + + def empty_parse_result + # Return an empty toplevel hostclass to use as the result of + # perform_initial_import when no file was actually loaded. + return Puppet::Parser::AST::Hostclass.new('') + end + @root = new(:'*root*') end diff --git a/lib/puppet/parser/ast.rb b/lib/puppet/parser/ast.rb index 54e034acb..03891160b 100644 --- a/lib/puppet/parser/ast.rb +++ b/lib/puppet/parser/ast.rb @@ -1,134 +1,138 @@ # the parent class for all of our syntactical objects require 'puppet' require 'puppet/util/autoload' require 'puppet/file_collection/lookup' # The base class for all of the objects that make up the parse trees. # Handles things like file name, line #, and also does the initialization # for all of the parameters of all of the child objects. class Puppet::Parser::AST # Do this so I don't have to type the full path in all of the subclasses AST = Puppet::Parser::AST include Puppet::FileCollection::Lookup include Puppet::Util::Errors include Puppet::Util::MethodHelper include Puppet::Util::Docs attr_accessor :parent, :scope # don't fetch lexer comment by default def use_docs self.class.use_docs end # allow our subclass to specify they want documentation class << self attr_accessor :use_docs def associates_doc self.use_docs = true end end # Does this ast object set something? If so, it gets evaluated first. def self.settor? if defined?(@settor) @settor else false end end # Evaluate the current object. Just a stub method, since the subclass # should override this method. # of the contained children and evaluates them in turn, returning a # list of all of the collected values, rejecting nil values def evaluate(*options) raise Puppet::DevError, "Did not override #evaluate in #{self.class}" end # Throw a parse error. def parsefail(message) self.fail(Puppet::ParseError, message) end # Wrap a statemp in a reusable way so we always throw a parse error. def parsewrap exceptwrap :type => Puppet::ParseError do yield end end # The version of the evaluate method that should be called, because it # correctly handles errors. It is critical to use this method because # it can enable you to catch the error where it happens, rather than # much higher up the stack. def safeevaluate(*options) # We duplicate code here, rather than using exceptwrap, because this # is called so many times during parsing. begin return self.evaluate(*options) rescue Puppet::Error => detail raise adderrorcontext(detail) rescue => detail error = Puppet::Error.new(detail.to_s) # We can't use self.fail here because it always expects strings, # not exceptions. raise adderrorcontext(error, detail) end end # Initialize the object. Requires a hash as the argument, and # takes each of the parameters of the hash and calls the settor # method for them. This is probably pretty inefficient and should # likely be changed at some point. def initialize(args) set_options(args) end # evaluate ourselves, and match def evaluate_match(value, scope) obj = self.safeevaluate(scope) obj = obj.downcase if obj.respond_to?(:downcase) value = value.downcase if value.respond_to?(:downcase) obj = Puppet::Parser::Scope.number?(obj) || obj value = Puppet::Parser::Scope.number?(value) || value # "" == undef for case/selector/if obj == value or (obj == "" and value == :undef) end end # And include all of the AST subclasses. require 'puppet/parser/ast/arithmetic_operator' require 'puppet/parser/ast/astarray' require 'puppet/parser/ast/asthash' -require 'puppet/parser/ast/branch' require 'puppet/parser/ast/boolean_operator' +require 'puppet/parser/ast/branch' require 'puppet/parser/ast/caseopt' require 'puppet/parser/ast/casestatement' require 'puppet/parser/ast/collection' require 'puppet/parser/ast/collexpr' require 'puppet/parser/ast/comparison_operator' +require 'puppet/parser/ast/definition' require 'puppet/parser/ast/else' require 'puppet/parser/ast/function' +require 'puppet/parser/ast/hostclass' require 'puppet/parser/ast/ifstatement' require 'puppet/parser/ast/in_operator' require 'puppet/parser/ast/leaf' require 'puppet/parser/ast/match_operator' require 'puppet/parser/ast/minus' +require 'puppet/parser/ast/node' require 'puppet/parser/ast/nop' require 'puppet/parser/ast/not' +require 'puppet/parser/ast/relationship' require 'puppet/parser/ast/resource' require 'puppet/parser/ast/resource_defaults' +require 'puppet/parser/ast/resource_instance' require 'puppet/parser/ast/resource_override' require 'puppet/parser/ast/resource_reference' require 'puppet/parser/ast/resourceparam' require 'puppet/parser/ast/selector' require 'puppet/parser/ast/tag' require 'puppet/parser/ast/vardef' -require 'puppet/parser/ast/relationship' diff --git a/lib/puppet/parser/ast/astarray.rb b/lib/puppet/parser/ast/astarray.rb index 529998e3c..7283a1f6c 100644 --- a/lib/puppet/parser/ast/astarray.rb +++ b/lib/puppet/parser/ast/astarray.rb @@ -1,61 +1,50 @@ require 'puppet/parser/ast/branch' class Puppet::Parser::AST # The basic container class. This object behaves almost identically # to a normal array except at initialization time. Note that its name # is 'AST::ASTArray', rather than plain 'AST::Array'; I had too many # bugs when it was just 'AST::Array', because things like # 'object.is_a?(Array)' never behaved as I expected. class ASTArray < Branch include Enumerable # Return a child by index. Probably never used. def [](index) @children[index] end # Evaluate our children. def evaluate(scope) - # Make a new array, so we don't have to deal with the details of - # flattening and such - items = [] - - # First clean out any AST::ASTArrays - @children.each { |child| - if child.instance_of?(AST::ASTArray) - child.each do |ac| - items << ac + result = [] + @children.each do |child| + # Skip things that respond to :instantiate (classes, nodes, + # and definitions), because they have already been + # instantiated. + if !child.respond_to?(:instantiate) + item = child.safeevaluate(scope) + if !item.nil? + # nil values are implicitly removed. + result.push(item) end - else - items << child end - } - - rets = items.flatten.collect { |child| - child.safeevaluate(scope) - } - rets.reject { |o| o.nil? } + end + result end def push(*ary) ary.each { |child| #Puppet.debug "adding %s(%s) of type %s to %s" % # [child, child.object_id, child.class.to_s.sub(/.+::/,''), # self.object_id] @children.push(child) } self end def to_s "[" + @children.collect { |c| c.to_s }.join(', ') + "]" end end - - # A simple container class, containing the parameters for an object. - # Used for abstracting the grammar declarations. Basically unnecessary - # except that I kept finding bugs because I had too many arrays that - # meant completely different things. - class ResourceInstance < ASTArray; end end diff --git a/lib/puppet/parser/ast/caseopt.rb b/lib/puppet/parser/ast/caseopt.rb index 4e296e82f..db4c2b024 100644 --- a/lib/puppet/parser/ast/caseopt.rb +++ b/lib/puppet/parser/ast/caseopt.rb @@ -1,64 +1,52 @@ require 'puppet/parser/ast/branch' class Puppet::Parser::AST # Each individual option in a case statement. class CaseOpt < AST::Branch attr_accessor :value, :statements # CaseOpt is a bit special -- we just want the value first, # so that CaseStatement can compare, and then it will selectively # decide whether to fully evaluate this option def each [@value,@statements].each { |child| yield child } end # Are we the default option? def default? # Cache the @default value. return @default if defined?(@default) - if @value.is_a?(AST::ASTArray) - @value.each { |subval| - if subval.is_a?(AST::Default) - @default = true - break - end - } - else - @default = true if @value.is_a?(AST::Default) - end + @value.each { |subval| + if subval.is_a?(AST::Default) + @default = true + break + end + } @default ||= false @default end # You can specify a list of values; return each in turn. def eachvalue(scope) - if @value.is_a?(AST::ASTArray) - @value.each { |subval| - yield subval.safeevaluate(scope) - } - else - yield @value.safeevaluate(scope) - end + @value.each { |subval| + yield subval.safeevaluate(scope) + } end def eachopt - if @value.is_a?(AST::ASTArray) - @value.each { |subval| - yield subval - } - else - yield @value - end + @value.each { |subval| + yield subval + } end # Evaluate the actual statements; this only gets called if # our option matched. def evaluate(scope) @statements.safeevaluate(scope) end end end diff --git a/lib/puppet/parser/ast/definition.rb b/lib/puppet/parser/ast/definition.rb new file mode 100644 index 000000000..c43422f82 --- /dev/null +++ b/lib/puppet/parser/ast/definition.rb @@ -0,0 +1,17 @@ +require 'puppet/parser/ast/top_level_construct' + +class Puppet::Parser::AST::Definition < Puppet::Parser::AST::TopLevelConstruct + attr_accessor :context + + def initialize(name, context = {}, &ruby_code) + @name = name + @context = context + @ruby_code = ruby_code + end + + def instantiate(modname) + new_definition = Puppet::Resource::Type.new(:definition, @name, @context.merge(:module_name => modname)) + new_definition.ruby_code = @ruby_code if @ruby_code + [new_definition] + end +end diff --git a/lib/puppet/parser/ast/hostclass.rb b/lib/puppet/parser/ast/hostclass.rb new file mode 100644 index 000000000..cab5e4a24 --- /dev/null +++ b/lib/puppet/parser/ast/hostclass.rb @@ -0,0 +1,29 @@ +require 'puppet/parser/ast/top_level_construct' + +class Puppet::Parser::AST::Hostclass < Puppet::Parser::AST::TopLevelConstruct + attr_accessor :name, :context + + def initialize(name, context = {}, &ruby_code) + @context = context + @name = name + @ruby_code = ruby_code + end + + def instantiate(modname) + new_class = Puppet::Resource::Type.new(:hostclass, @name, @context.merge(:module_name => modname)) + new_class.ruby_code = @ruby_code if @ruby_code + all_types = [new_class] + if code + code.each do |nested_ast_node| + if nested_ast_node.respond_to? :instantiate + all_types += nested_ast_node.instantiate(modname) + end + end + end + return all_types + end + + def code() + @context[:code] + end +end diff --git a/lib/puppet/parser/ast/node.rb b/lib/puppet/parser/ast/node.rb new file mode 100644 index 000000000..b69a5c4e0 --- /dev/null +++ b/lib/puppet/parser/ast/node.rb @@ -0,0 +1,20 @@ +require 'puppet/parser/ast/top_level_construct' + +class Puppet::Parser::AST::Node < Puppet::Parser::AST::TopLevelConstruct + attr_accessor :names, :context + + def initialize(names, context = {}, &ruby_code) + raise ArgumentError, "names should be an array" unless names.is_a? Array + @names = names + @context = context + @ruby_code = ruby_code + end + + def instantiate(modname) + @names.collect do |name| + new_node = Puppet::Resource::Type.new(:node, name, @context.merge(:module_name => modname)) + new_node.ruby_code = @ruby_code if @ruby_code + new_node + end + end +end diff --git a/lib/puppet/parser/ast/resource.rb b/lib/puppet/parser/ast/resource.rb index 6909c85c2..bd15d9935 100644 --- a/lib/puppet/parser/ast/resource.rb +++ b/lib/puppet/parser/ast/resource.rb @@ -1,74 +1,66 @@ require 'puppet/parser/ast/resource_reference' # Any normal puppet resource declaration. Can point to a definition or a # builtin type. class Puppet::Parser::AST -class Resource < AST::ResourceReference +class Resource < AST::Branch associates_doc - attr_accessor :title, :type, :exported, :virtual - attr_reader :parameters + attr_accessor :type, :instances, :exported, :virtual # Does not actually return an object; instead sets an object # in the current scope. def evaluate(scope) - # Evaluate all of the specified params. - paramobjects = parameters.collect { |param| - param.safeevaluate(scope) - } - - resource_titles = @title.safeevaluate(scope) - - # it's easier to always use an array, even for only one name - resource_titles = [resource_titles] unless resource_titles.is_a?(Array) - # 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* # :exported, in which case it clobbers :exported if :exported # is true. Argh, this was a very tough one to track down. virt = self.virtual || self.exported - # This is where our implicit iteration takes place; if someone - # passed an array as the name, then we act just like the called us - # many times. - fully_qualified_type, resource_titles = scope.resolve_type_and_titles(type, resource_titles) + # First level of implicit iteration: build a resource for each + # instance. This handles things like: + # file { '/foo': owner => blah; '/bar': owner => blah } + @instances.collect { |instance| - resource_titles.flatten.collect { |resource_title| - exceptwrap :type => Puppet::ParseError do - resource = Puppet::Parser::Resource.new( - fully_qualified_type, resource_title, - :parameters => paramobjects, - :file => self.file, - :line => self.line, - :exported => self.exported, - :virtual => virt, - :source => scope.source, - :scope => scope, - :strict => true - ) + # Evaluate all of the specified params. + paramobjects = instance.parameters.collect { |param| + param.safeevaluate(scope) + } - # And then store the resource in the compiler. - # At some point, we need to switch all of this to return - # resources instead of storing them like this. - scope.compiler.add_resource(scope, resource) - resource - end - }.reject { |resource| resource.nil? } - end + resource_titles = instance.title.safeevaluate(scope) + + # it's easier to always use an array, even for only one name + resource_titles = [resource_titles] unless resource_titles.is_a?(Array) + + fully_qualified_type, resource_titles = scope.resolve_type_and_titles(type, resource_titles) + + # Second level of implicit iteration; build a resource for each + # title. This handles things like: + # file { ['/foo', '/bar']: owner => blah } + resource_titles.flatten.collect { |resource_title| + exceptwrap :type => Puppet::ParseError do + resource = Puppet::Parser::Resource.new( + fully_qualified_type, resource_title, + :parameters => paramobjects, + :file => self.file, + :line => self.line, + :exported => self.exported, + :virtual => virt, + :source => scope.source, + :scope => scope, + :strict => true + ) - # Set the parameters for our object. - def parameters=(params) - if params.is_a?(AST::ASTArray) - @parameters = params - else - @parameters = AST::ASTArray.new( - :line => params.line, - :file => params.file, - :children => [params] - ) - end + # And then store the resource in the compiler. + # At some point, we need to switch all of this to return + # resources instead of storing them like this. + scope.compiler.add_resource(scope, resource) + resource + end + } + }.flatten.reject { |resource| resource.nil? } end end end diff --git a/lib/puppet/parser/ast/resource_instance.rb b/lib/puppet/parser/ast/resource_instance.rb new file mode 100644 index 000000000..ebfb17bf1 --- /dev/null +++ b/lib/puppet/parser/ast/resource_instance.rb @@ -0,0 +1,9 @@ +require 'puppet/parser/ast/branch' + +class Puppet::Parser::AST + class ResourceInstance < Branch + # A simple container for a parameter for an object. Consists of a + # title and a set of parameters. + attr_accessor :title, :parameters + end +end diff --git a/lib/puppet/parser/ast/resource_override.rb b/lib/puppet/parser/ast/resource_override.rb index e0be889ff..d638202ab 100644 --- a/lib/puppet/parser/ast/resource_override.rb +++ b/lib/puppet/parser/ast/resource_override.rb @@ -1,68 +1,67 @@ require 'puppet/parser/ast/resource' class Puppet::Parser::AST # Set a parameter on a resource specification created somewhere else in the # configuration. The object is responsible for verifying that this is allowed. - class ResourceOverride < Resource + class ResourceOverride < AST::Branch associates_doc - attr_accessor :object - attr_reader :parameters + attr_accessor :object, :parameters # Iterate across all of our children. def each [@object,@parameters].flatten.each { |param| #Puppet.debug("yielding param #{param}") yield param } end # Does not actually return an object; instead sets an object # in the current scope. def evaluate(scope) # Get our object reference. resource = @object.safeevaluate(scope) hash = {} # Evaluate all of the specified params. params = @parameters.collect { |param| param.safeevaluate(scope) } # Now we just create a normal resource, but we call a very different # method on the scope. resource = [resource] unless resource.is_a?(Array) resource = resource.collect do |r| res = Puppet::Parser::Resource.new( r.type, r.title, :parameters => params, :file => file, :line => line, :source => scope.source, :scope => scope ) # Now we tell the scope that it's an override, and it behaves as # necessary. scope.compiler.add_override(res) res end # decapsulate array in case of only one item return(resource.length == 1 ? resource.pop : resource) end # Create our ResourceDef. Handles type checking for us. def initialize(hash) @checked = false super #self.typecheck(@type.value) end end end diff --git a/lib/puppet/parser/ast/top_level_construct.rb b/lib/puppet/parser/ast/top_level_construct.rb new file mode 100644 index 000000000..901a939c2 --- /dev/null +++ b/lib/puppet/parser/ast/top_level_construct.rb @@ -0,0 +1,4 @@ +# The base class for AST nodes representing top level things: +# hostclasses, definitions, and nodes. +class Puppet::Parser::AST::TopLevelConstruct < Puppet::Parser::AST +end diff --git a/lib/puppet/parser/grammar.ra b/lib/puppet/parser/grammar.ra index 7a316d4d7..ecb27f363 100644 --- a/lib/puppet/parser/grammar.ra +++ b/lib/puppet/parser/grammar.ra @@ -1,875 +1,798 @@ # vim: syntax=ruby # the parser class Puppet::Parser::Parser token STRING DQPRE DQMID DQPOST token LBRACK RBRACK LBRACE RBRACE SYMBOL FARROW COMMA TRUE token FALSE EQUALS APPENDS LESSEQUAL NOTEQUAL DOT COLON LLCOLLECT RRCOLLECT token QMARK LPAREN RPAREN ISEQUAL GREATEREQUAL GREATERTHAN LESSTHAN token IF ELSE IMPORT DEFINE ELSIF VARIABLE CLASS INHERITS NODE BOOLEAN token NAME SEMIC CASE DEFAULT AT LCOLLECT RCOLLECT CLASSNAME CLASSREF token NOT OR AND UNDEF PARROW PLUS MINUS TIMES DIV LSHIFT RSHIFT UMINUS token MATCH NOMATCH REGEX IN_EDGE OUT_EDGE IN_EDGE_SUB OUT_EDGE_SUB token IN prechigh right NOT nonassoc UMINUS left IN MATCH NOMATCH left TIMES DIV left MINUS PLUS left LSHIFT RSHIFT left NOTEQUAL ISEQUAL left GREATEREQUAL GREATERTHAN LESSTHAN LESSEQUAL left AND left OR preclow rule -program: statements { - if val[0] - # Make sure we always return an array. - if val[0].is_a?(AST::ASTArray) - if val[0].children.empty? - result = nil - else - result = val[0] - end - else - result = aryfy(val[0]) - end - else - result = nil - end -} +program: statements_and_declarations | nil -statements: statement - | statements statement { - if val[0] and val[1] - if val[0].instance_of?(AST::ASTArray) + statements_and_declarations: statement_or_declaration { + result = ast AST::ASTArray, :children => (val[0] ? [val[0]] : []) + } + | statements_and_declarations statement_or_declaration { + if val[1] val[0].push(val[1]) - result = val[0] - else - result = ast AST::ASTArray, :children => [val[0],val[1]] end - elsif obj = (val[0] || val[1]) - result = obj - else result = nil + result = val[0] + } + +# statements is like statements_and_declarations, but it doesn't allow +# nested definitions, classes, or nodes. +statements: statements_and_declarations { + val[0].each do |stmt| + if stmt.is_a?(AST::TopLevelConstruct) + error "Classes, definitions, and nodes may only appear at toplevel or inside other classes", \ + :line => stmt.context[:line], :file => stmt.context[:file] + end end + result = val[0] } # The main list of valid statements -statement: resource +statement_or_declaration: resource | virtualresource | collection | assignment | casestatement | ifstatement_begin | import | fstatement | definition | hostclass | nodedef | resourceoverride | append | relationship relationship: relationship_side edge relationship_side { result = AST::Relationship.new(val[0], val[2], val[1][:value], ast_context) } | relationship edge relationship_side { result = AST::Relationship.new(val[0], val[2], val[1][:value], ast_context) } relationship_side: resource | resourceref | collection edge: IN_EDGE | OUT_EDGE | IN_EDGE_SUB | OUT_EDGE_SUB fstatement: NAME LPAREN funcvalues RPAREN { - args = aryfy(val[2]) result = ast AST::Function, :name => val[0][:value], :line => val[0][:line], - :arguments => args, + :arguments => val[2], :ftype => :statement } | NAME LPAREN funcvalues COMMA RPAREN { - args = aryfy(val[2]) result = ast AST::Function, :name => val[0][:value], :line => val[0][:line], - :arguments => args, + :arguments => val[2], :ftype => :statement } | NAME LPAREN RPAREN { result = ast AST::Function, :name => val[0][:value], :line => val[0][:line], :arguments => AST::ASTArray.new({}), :ftype => :statement } | NAME funcvalues { - args = aryfy(val[1]) result = ast AST::Function, :name => val[0][:value], :line => val[0][:line], - :arguments => args, + :arguments => val[1], :ftype => :statement } -funcvalues: namestring - | resourceref +funcvalues: namestring { result = aryfy(val[0]) } + | resourceref { result = aryfy(val[0]) } | funcvalues COMMA namestring { - result = aryfy(val[0], val[2]) - result.line = @lexer.line - result.file = @lexer.file + val[0].push(val[2]) + result = val[0] } | funcvalues COMMA resourceref { - unless val[0].is_a?(AST::ASTArray) - val[0] = aryfy(val[0]) - end - - val[0].push(val[2]) - - result = val[0] + val[0].push(val[2]) + result = val[0] } # This is *almost* an rvalue, but I couldn't get a full # rvalue to work without scads of shift/reduce conflicts. namestring: name | variable | type | boolean | funcrvalue | selector | quotedtext | hasharrayaccesses | CLASSNAME { result = ast AST::Name, :value => val[0][:value] } resource: classname LBRACE resourceinstances endsemi RBRACE { @lexer.commentpop - array = val[2] - array = [array] if array.instance_of?(AST::ResourceInstance) - result = ast AST::ASTArray - - # this iterates across each specified resourceinstance - array.each { |instance| - raise Puppet::Dev, "Got something that isn't an instance" unless instance.instance_of?(AST::ResourceInstance) - # now, i need to somehow differentiate between those things with - # arrays in their names, and normal things - - result.push ast( - AST::Resource, - :type => val[0], - :title => instance[0], - - :parameters => instance[1]) - } + result = ast(AST::Resource, :type => val[0], :instances => val[2]) } | 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 @lexer.commentpop 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], :parameters => val[2] } # Exported and virtual resources; these don't get sent to the client # unless they get collected elsewhere in the db. virtualresource: at resource { type = val[0] if (type == :exported and ! Puppet[:storeconfigs]) and ! Puppet[:parseonly] Puppet.warning addcontext("You cannot collect without storeconfigs being set") end error "Defaults are not virtualizable" if val[1].is_a? AST::ResourceDefaults method = type.to_s + "=" - # Just mark our resources as exported and pass them through. - if val[1].instance_of?(AST::ASTArray) - val[1].each do |obj| - obj.send(method, true) - end - else - val[1].send(method, true) - end + # Just mark our resource as exported and pass it through. + val[1].send(method, true) result = val[1] } at: AT { result = :virtual } | AT AT { result = :exported } # A collection statement. Currently supports no arguments at all, but eventually # will, I assume. collection: classref collectrhand LBRACE anyparams endcomma RBRACE { @lexer.commentpop Puppet.warning addcontext("Collection names must now be capitalized") if val[0] =~ /^[a-z]/ type = val[0].downcase args = {:type => type} if val[1].is_a?(AST::CollExpr) args[:query] = val[1] args[:query].type = type args[:form] = args[:query].form else args[:form] = val[1] end if args[:form] == :exported and ! Puppet[:storeconfigs] and ! Puppet[:parseonly] Puppet.warning addcontext("You cannot collect exported resources without storeconfigs being set; the collection will be ignored") end args[:override] = val[3] result = ast AST::Collection, args } | classref collectrhand { if val[0] =~ /^[a-z]/ Puppet.warning addcontext("Collection names must now be capitalized") end type = val[0].downcase args = {:type => type } if val[1].is_a?(AST::CollExpr) args[:query] = val[1] args[:query].type = type args[:form] = args[:query].form else args[:form] = val[1] end if args[:form] == :exported and ! Puppet[:storeconfigs] and ! Puppet[:parseonly] Puppet.warning addcontext("You cannot collect exported resources without storeconfigs being set; the collection will be ignored") end result = ast AST::Collection, args } collectrhand: LCOLLECT collstatements RCOLLECT { if val[1] result = val[1] result.form = :virtual else result = :virtual end } | LLCOLLECT collstatements RRCOLLECT { if val[1] result = val[1] result.form = :exported else result = :exported end } # A mini-language for handling collection comparisons. This is organized # to avoid the need for precedence indications. collstatements: nil | collstatement | collstatements colljoin collstatement { result = ast AST::CollExpr, :test1 => val[0], :oper => val[1], :test2 => val[2] } collstatement: collexpr | LPAREN collstatements RPAREN { result = val[1] result.parens = true } colljoin: AND { result=val[0][:value] } | OR { result=val[0][:value] } collexpr: colllval ISEQUAL simplervalue { result = ast AST::CollExpr, :test1 => val[0], :oper => val[1][:value], :test2 => val[2] #result = ast AST::CollExpr #result.push *val } | colllval NOTEQUAL simplervalue { result = ast AST::CollExpr, :test1 => val[0], :oper => val[1][:value], :test2 => val[2] #result = ast AST::CollExpr #result.push *val } colllval: variable | name resourceinst: resourcename COLON params endcomma { - result = ast AST::ResourceInstance, :children => [val[0],val[2]] + result = ast AST::ResourceInstance, :title => val[0], :parameters => val[2] } -resourceinstances: resourceinst +resourceinstances: resourceinst { result = aryfy(val[0]) } | resourceinstances SEMIC resourceinst { - if val[0].instance_of?(AST::ResourceInstance) - result = ast AST::ASTArray, :children => [val[0],val[2]] - else val[0].push val[2] result = val[0] - end } endsemi: # nothing | SEMIC undef: UNDEF { result = ast AST::Undef, :value => :undef } name: NAME { result = ast AST::Name, :value => val[0][:value], :line => val[0][:line] } type: CLASSREF { result = ast AST::Type, :value => val[0][:value], :line => val[0][:line] } resourcename: quotedtext | name | type | selector | variable | array | hasharrayaccesses assignment: VARIABLE EQUALS expression { raise Puppet::ParseError, "Cannot assign to variables in other namespaces" if val[0][:value] =~ /::/ # this is distinct from referencing a variable variable = ast AST::Name, :value => val[0][:value], :line => val[0][:line] result = ast AST::VarDef, :name => variable, :value => val[2], :line => val[0][:line] } | hasharrayaccess EQUALS expression { result = ast AST::VarDef, :name => val[0], :value => val[2] } append: VARIABLE APPENDS expression { variable = ast AST::Name, :value => val[0][:value], :line => val[0][:line] result = ast AST::VarDef, :name => variable, :value => val[2], :append => true, :line => val[0][:line] } params: # nothing { result = ast AST::ASTArray } - | param { result = val[0] } + | param { result = aryfy(val[0]) } | params COMMA param { - if val[0].instance_of?(AST::ASTArray) val[0].push(val[2]) result = val[0] - else - result = ast AST::ASTArray, :children => [val[0],val[2]] - end } param: NAME FARROW rvalue { result = ast AST::ResourceParam, :param => val[0][:value], :line => val[0][:line], :value => val[2] } addparam: NAME PARROW rvalue { result = ast AST::ResourceParam, :param => val[0][:value], :line => val[0][:line], :value => val[2], :add => true } anyparam: param | addparam anyparams: # nothing { result = ast AST::ASTArray } - | anyparam { result = val[0] } + | anyparam { result = aryfy(val[0]) } | anyparams COMMA anyparam { - if val[0].instance_of?(AST::ASTArray) val[0].push(val[2]) result = val[0] - else - result = ast AST::ASTArray, :children => [val[0],val[2]] - end } -rvalues: rvalue - | rvalues comma rvalue { - if val[0].instance_of?(AST::ASTArray) - result = val[0].push(val[2]) - else - result = ast AST::ASTArray, :children => [val[0],val[2]] - end -} +rvalues: rvalue { result = aryfy(val[0]) } + | rvalues comma rvalue { result = val[0].push(val[2]) } simplervalue: quotedtext | name | type | boolean | selector | variable rvalue: quotedtext | name | type | boolean | selector | variable | array | hash | hasharrayaccesses | resourceref | funcrvalue | undef # We currently require arguments in these functions. funcrvalue: NAME LPAREN funcvalues RPAREN { - args = aryfy(val[2]) result = ast AST::Function, :name => val[0][:value], :line => val[0][:line], - :arguments => args, + :arguments => val[2], :ftype => :rvalue } | NAME LPAREN RPAREN { result = ast AST::Function, :name => val[0][:value], :line => val[0][:line], :arguments => AST::ASTArray.new({}), :ftype => :rvalue } quotedtext: STRING { result = ast AST::String, :value => val[0][:value], :line => val[0][:line] } | DQPRE dqrval { result = ast AST::Concat, :value => [ast(AST::String,val[0])]+val[1], :line => val[0][:line] } dqrval: expression dqtail { result = [val[0]] + val[1] } dqtail: DQPOST { result = [ast(AST::String,val[0])] } | DQMID dqrval { result = [ast(AST::String,val[0])] + val[1] } boolean: BOOLEAN { result = ast AST::Boolean, :value => val[0][:value], :line => val[0][:line] } resourceref: NAME LBRACK rvalues RBRACK { Puppet.warning addcontext("Deprecation notice: Resource references should now be capitalized") result = ast AST::ResourceReference, :type => val[0][:value], :line => val[0][:line], :title => val[2] } | classref LBRACK rvalues RBRACK { result = ast AST::ResourceReference, :type => val[0], :title => val[2] } ifstatement_begin: IF ifstatement { result = val[1] } ifstatement: expression LBRACE statements RBRACE else { @lexer.commentpop args = { :test => val[0], :statements => val[2] } args[:else] = val[4] if val[4] result = ast AST::IfStatement, args } | expression LBRACE RBRACE else { @lexer.commentpop args = { :test => val[0], :statements => ast(AST::Nop) } args[:else] = val[3] if val[3] result = ast AST::IfStatement, args } else: # nothing | ELSIF ifstatement { result = ast AST::Else, :statements => val[1] } | ELSE LBRACE statements RBRACE { @lexer.commentpop result = ast AST::Else, :statements => val[2] } | ELSE LBRACE RBRACE { @lexer.commentpop result = ast AST::Else, :statements => ast(AST::Nop) } # Unlike yacc/bison, it seems racc # gives tons of shift/reduce warnings # with the following syntax: # # expression: ... # | expression arithop expressio { ... } # # arithop: PLUS | MINUS | DIVIDE | TIMES ... # # So I had to develop the expression by adding one rule # per operator :-( expression: rvalue | expression IN rvalue { result = ast AST::InOperator, :lval => val[0], :rval => val[2] } | expression MATCH regex { result = ast AST::MatchOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } | expression NOMATCH regex { result = ast AST::MatchOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } | expression PLUS expression { result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } | expression MINUS expression { result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } | expression DIV expression { result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } | expression TIMES expression { result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } | expression LSHIFT expression { result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } | expression RSHIFT expression { result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } | MINUS expression =UMINUS { result = ast AST::Minus, :value => val[1] } | expression NOTEQUAL expression { result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } | expression ISEQUAL expression { result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } | expression GREATERTHAN expression { result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } | expression GREATEREQUAL expression { result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } | expression LESSTHAN expression { result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } | expression LESSEQUAL expression { result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } | NOT expression { result = ast AST::Not, :value => val[1] } | expression AND expression { result = ast AST::BooleanOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } | expression OR expression { result = ast AST::BooleanOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } | LPAREN expression RPAREN { result = val[1] } casestatement: CASE rvalue LBRACE caseopts RBRACE { @lexer.commentpop - options = val[3] - options = ast AST::ASTArray, :children => [val[3]] unless options.instance_of?(AST::ASTArray) - result = ast AST::CaseStatement, :test => val[1], :options => options + result = ast AST::CaseStatement, :test => val[1], :options => val[3] } -caseopts: caseopt +caseopts: caseopt { result = aryfy(val[0]) } | caseopts caseopt { - if val[0].instance_of?(AST::ASTArray) val[0].push val[1] result = val[0] - else - result = ast AST::ASTArray, :children => [val[0], val[1]] - end } caseopt: casevalues COLON LBRACE statements RBRACE { @lexer.commentpop result = ast AST::CaseOpt, :value => val[0], :statements => val[3] } | casevalues COLON LBRACE RBRACE { @lexer.commentpop result = ast( AST::CaseOpt, :value => val[0], :statements => ast(AST::ASTArray) ) } -casevalues: selectlhand +casevalues: selectlhand { result = aryfy(val[0]) } | casevalues COMMA selectlhand { - if val[0].instance_of?(AST::ASTArray) val[0].push(val[2]) result = val[0] - else - result = ast AST::ASTArray, :children => [val[0],val[2]] - end } selector: selectlhand QMARK svalues { result = ast AST::Selector, :param => val[0], :values => val[2] } svalues: selectval | LBRACE sintvalues endcomma RBRACE { @lexer.commentpop result = val[1] } sintvalues: selectval | sintvalues comma selectval { if val[0].instance_of?(AST::ASTArray) val[0].push(val[2]) result = val[0] else result = ast AST::ASTArray, :children => [val[0],val[2]] end } selectval: selectlhand FARROW rvalue { result = ast AST::ResourceParam, :param => val[0], :value => val[2] } selectlhand: name | type | quotedtext | variable | funcrvalue | boolean | undef | DEFAULT { result = ast AST::Default, :value => val[0][:value], :line => val[0][:line] } | regex # These are only used for importing, and we don't interpolate there. string: STRING { result = [val[0][:value]] } strings: string | strings COMMA string { result = val[0] += val[2] } import: IMPORT strings { val[1].each do |file| import(file) end - result = AST::ASTArray.new(:children => []) + result = nil } # Disable definition inheritance for now. 8/27/06, luke #definition: DEFINE NAME argumentlist parent LBRACE statements RBRACE { definition: DEFINE classname argumentlist LBRACE statements RBRACE { @lexer.commentpop - newdefine classname(val[1]), :arguments => val[2], :code => val[4], :line => val[0][:line] + result = Puppet::Parser::AST::Definition.new(classname(val[1]), + ast_context(true).merge(:arguments => val[2], :code => val[4], + :line => val[0][:line])) @lexer.indefine = false - result = nil #} | DEFINE NAME argumentlist parent LBRACE RBRACE { } | DEFINE classname argumentlist LBRACE RBRACE { @lexer.commentpop - newdefine classname(val[1]), :arguments => val[2], :line => val[0][:line] + result = Puppet::Parser::AST::Definition.new(classname(val[1]), + ast_context(true).merge(:arguments => val[2], :line => val[0][:line])) @lexer.indefine = false - result = nil } #hostclass: CLASS NAME argumentlist parent LBRACE statements RBRACE { -hostclass: CLASS classname argumentlist classparent LBRACE statements RBRACE { +hostclass: CLASS classname argumentlist classparent LBRACE statements_and_declarations RBRACE { @lexer.commentpop # Our class gets defined in the parent namespace, not our own. @lexer.namepop - newclass classname(val[1]), :arguments => val[2], :parent => val[3], :code => val[5], :line => val[0][:line] - result = nil + result = Puppet::Parser::AST::Hostclass.new(classname(val[1]), + ast_context(true).merge(:arguments => val[2], :parent => val[3], + :code => val[5], :line => val[0][:line])) } | 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]), :arguments => val[2], :parent => val[3], :line => val[0][:line] - result = nil + result = Puppet::Parser::AST::Hostclass.new(classname(val[1]), + ast_context(true).merge(:arguments => val[2], :parent => val[3], + :line => val[0][:line])) } nodedef: NODE hostnames nodeparent LBRACE statements RBRACE { @lexer.commentpop - newnode val[1], :parent => val[2], :code => val[4], :line => val[0][:line] - result = nil + result = Puppet::Parser::AST::Node.new(val[1], + ast_context(true).merge(:parent => val[2], :code => val[4], + :line => val[0][:line])) } | NODE hostnames nodeparent LBRACE RBRACE { @lexer.commentpop - newnode val[1], :parent => val[2], :line => val[0][:line] - result = nil + result = Puppet::Parser::AST::Node.new(val[1], ast_context(true).merge(:parent => val[2], :line => val[0][:line])) } 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. -hostnames: nodename +hostnames: nodename { + result = [result] +} | hostnames COMMA nodename { result = val[0] - result = [result] unless result.is_a?(Array) result << val[2] } nodename: hostname { result = ast AST::HostName, :value => val[0] } hostname: NAME { result = val[0][:value] } | STRING { result = val[0][:value] } | DEFAULT { result = val[0][:value] } | regex nil: { result = nil } nothing: { result = ast AST::ASTArray, :children => [] } argumentlist: nil | LPAREN nothing RPAREN { result = nil } | LPAREN arguments RPAREN { result = val[1] result = [result] unless result[0].is_a?(Array) } arguments: argument | arguments COMMA argument { result = val[0] result = [result] unless result[0].is_a?(Array) result << val[2] } argument: NAME EQUALS rvalue { Puppet.warning addcontext("Deprecation notice: must now include '$' in prototype") result = [val[0][:value], val[2]] } | NAME { Puppet.warning addcontext("Deprecation notice: must now include '$' in prototype") result = [val[0][:value]] } | VARIABLE EQUALS rvalue { result = [val[0][:value], val[2]] } | VARIABLE { result = [val[0][:value]] } nodeparent: nil | INHERITS hostname { result = val[1] } classparent: nil | INHERITS classnameordefault { result = val[1] } classnameordefault: classname | DEFAULT variable: VARIABLE { result = ast AST::Variable, :value => val[0][:value], :line => val[0][:line] } -array: LBRACK rvalues RBRACK { - if val[1].instance_of?(AST::ASTArray) - result = val[1] - else - result = ast AST::ASTArray, :children => [val[1]] - end -} - | LBRACK rvalues COMMA RBRACK { - if val[1].instance_of?(AST::ASTArray) - result = val[1] - else - result = ast AST::ASTArray, :children => [val[1]] - end -} | LBRACK RBRACK { - result = ast AST::ASTArray -} +array: LBRACK rvalues RBRACK { result = val[1] } + | LBRACK rvalues COMMA RBRACK { result = val[1] } + | LBRACK RBRACK { result = ast AST::ASTArray } comma: FARROW | COMMA endcomma: # nothing | COMMA { result = nil } regex: REGEX { result = ast AST::Regex, :value => val[0][:value] } hash: LBRACE hashpairs RBRACE { if val[1].instance_of?(AST::ASTHash) result = val[1] else result = ast AST::ASTHash, { :value => val[1] } end } | LBRACE hashpairs COMMA RBRACE { if val[1].instance_of?(AST::ASTHash) result = val[1] else result = ast AST::ASTHash, { :value => val[1] } end } | LBRACE RBRACE { result = ast AST::ASTHash } hashpairs: hashpair | hashpairs COMMA hashpair { if val[0].instance_of?(AST::ASTHash) result = val[0].merge(val[2]) else result = ast AST::ASTHash, :value => val[0] result.merge(val[2]) end } hashpair: key FARROW rvalue { result = ast AST::ASTHash, { :value => { val[0] => val[2] } } } key: NAME { result = val[0][:value] } | quotedtext { result = val[0] } hasharrayaccess: VARIABLE LBRACK rvalue RBRACK { result = ast AST::HashOrArrayAccess, :variable => val[0][:value], :key => val[2] } hasharrayaccesses: hasharrayaccess | hasharrayaccess LBRACK rvalue RBRACK { result = ast AST::HashOrArrayAccess, :variable => val[0], :key => val[2] } end ---- header ---- require 'puppet' require 'puppet/util/loadedfile' require 'puppet/parser/lexer' require 'puppet/parser/ast' module Puppet class ParseError < Puppet::Error; end class ImportError < Racc::ParseError; end class AlreadyImportedError < ImportError; end end ---- inner ---- # It got too annoying having code in a file that needs to be compiled. require 'puppet/parser/parser_support' # Make emacs happy # Local Variables: # mode: ruby # End: # $Id$ diff --git a/lib/puppet/parser/parser.rb b/lib/puppet/parser/parser.rb index 5be9e5a3f..60b272e76 100644 --- a/lib/puppet/parser/parser.rb +++ b/lib/puppet/parser/parser.rb @@ -1,2602 +1,2513 @@ # # DO NOT MODIFY!!!! # This file is automatically generated by racc 1.4.5 # from racc grammer file "grammar.ra". # require 'racc/parser' require 'puppet' require 'puppet/util/loadedfile' require 'puppet/parser/lexer' require 'puppet/parser/ast' module Puppet - class ParseError < Puppet::Error; end - class ImportError < Racc::ParseError; end - class AlreadyImportedError < ImportError; end + class ParseError < Puppet::Error; end + class ImportError < Racc::ParseError; end + class AlreadyImportedError < ImportError; end end module Puppet module Parser class Parser < Racc::Parser -module_eval <<'..end grammar.ra modeval..id7145220b1b', 'grammar.ra', 876 +module_eval <<'..end grammar.ra modeval..id6362f948d9', 'grammar.ra', 788 # It got too annoying having code in a file that needs to be compiled. require 'puppet/parser/parser_support' # Make emacs happy # Local Variables: # mode: ruby # End: # $Id$ -..end grammar.ra modeval..id7145220b1b +..end grammar.ra modeval..id6362f948d9 ##### racc 1.4.5 generates ### racc_reduce_table = [ 0, 0, :racc_error, - 1, 70, :_reduce_1, 1, 70, :_reduce_none, - 1, 71, :_reduce_none, + 1, 70, :_reduce_none, + 1, 71, :_reduce_3, 2, 71, :_reduce_4, + 1, 74, :_reduce_5, 1, 73, :_reduce_none, 1, 73, :_reduce_none, 1, 73, :_reduce_none, 1, 73, :_reduce_none, 1, 73, :_reduce_none, 1, 73, :_reduce_none, 1, 73, :_reduce_none, 1, 73, :_reduce_none, 1, 73, :_reduce_none, 1, 73, :_reduce_none, 1, 73, :_reduce_none, 1, 73, :_reduce_none, 1, 73, :_reduce_none, 1, 73, :_reduce_none, - 3, 87, :_reduce_19, - 3, 87, :_reduce_20, - 1, 88, :_reduce_none, - 1, 88, :_reduce_none, - 1, 88, :_reduce_none, - 1, 89, :_reduce_none, + 3, 88, :_reduce_20, + 3, 88, :_reduce_21, 1, 89, :_reduce_none, 1, 89, :_reduce_none, 1, 89, :_reduce_none, - 4, 81, :_reduce_28, - 5, 81, :_reduce_29, - 3, 81, :_reduce_30, - 2, 81, :_reduce_31, - 1, 91, :_reduce_none, - 1, 91, :_reduce_none, - 3, 91, :_reduce_34, - 3, 91, :_reduce_35, - 1, 92, :_reduce_none, - 1, 92, :_reduce_none, - 1, 92, :_reduce_none, - 1, 92, :_reduce_none, - 1, 92, :_reduce_none, - 1, 92, :_reduce_none, - 1, 92, :_reduce_none, - 1, 92, :_reduce_none, - 1, 92, :_reduce_44, - 5, 74, :_reduce_45, - 5, 74, :_reduce_46, - 5, 74, :_reduce_47, - 5, 85, :_reduce_48, - 2, 75, :_reduce_49, - 1, 108, :_reduce_50, - 2, 108, :_reduce_51, - 6, 76, :_reduce_52, - 2, 76, :_reduce_53, - 3, 109, :_reduce_54, - 3, 109, :_reduce_55, - 1, 110, :_reduce_none, - 1, 110, :_reduce_none, - 3, 110, :_reduce_58, + 1, 90, :_reduce_none, + 1, 90, :_reduce_none, + 1, 90, :_reduce_none, + 1, 90, :_reduce_none, + 4, 82, :_reduce_29, + 5, 82, :_reduce_30, + 3, 82, :_reduce_31, + 2, 82, :_reduce_32, + 1, 92, :_reduce_33, + 1, 92, :_reduce_34, + 3, 92, :_reduce_35, + 3, 92, :_reduce_36, + 1, 93, :_reduce_none, + 1, 93, :_reduce_none, + 1, 93, :_reduce_none, + 1, 93, :_reduce_none, + 1, 93, :_reduce_none, + 1, 93, :_reduce_none, + 1, 93, :_reduce_none, + 1, 93, :_reduce_none, + 1, 93, :_reduce_45, + 5, 75, :_reduce_46, + 5, 75, :_reduce_47, + 5, 75, :_reduce_48, + 5, 86, :_reduce_49, + 2, 76, :_reduce_50, + 1, 109, :_reduce_51, + 2, 109, :_reduce_52, + 6, 77, :_reduce_53, + 2, 77, :_reduce_54, + 3, 110, :_reduce_55, + 3, 110, :_reduce_56, 1, 111, :_reduce_none, - 3, 111, :_reduce_60, - 1, 112, :_reduce_61, - 1, 112, :_reduce_62, - 3, 113, :_reduce_63, - 3, 113, :_reduce_64, - 1, 114, :_reduce_none, - 1, 114, :_reduce_none, - 4, 116, :_reduce_67, - 1, 102, :_reduce_none, - 3, 102, :_reduce_69, - 0, 103, :_reduce_none, - 1, 103, :_reduce_none, - 1, 118, :_reduce_72, - 1, 93, :_reduce_73, - 1, 95, :_reduce_74, - 1, 117, :_reduce_none, - 1, 117, :_reduce_none, - 1, 117, :_reduce_none, - 1, 117, :_reduce_none, - 1, 117, :_reduce_none, - 1, 117, :_reduce_none, - 1, 117, :_reduce_none, - 3, 77, :_reduce_82, - 3, 77, :_reduce_83, - 3, 86, :_reduce_84, - 0, 104, :_reduce_85, - 1, 104, :_reduce_86, - 3, 104, :_reduce_87, - 3, 122, :_reduce_88, - 3, 124, :_reduce_89, - 1, 125, :_reduce_none, - 1, 125, :_reduce_none, - 0, 107, :_reduce_92, - 1, 107, :_reduce_93, - 3, 107, :_reduce_94, - 1, 126, :_reduce_none, - 3, 126, :_reduce_96, - 1, 115, :_reduce_none, - 1, 115, :_reduce_none, - 1, 115, :_reduce_none, - 1, 115, :_reduce_none, + 1, 111, :_reduce_none, + 3, 111, :_reduce_59, + 1, 112, :_reduce_none, + 3, 112, :_reduce_61, + 1, 113, :_reduce_62, + 1, 113, :_reduce_63, + 3, 114, :_reduce_64, + 3, 114, :_reduce_65, 1, 115, :_reduce_none, 1, 115, :_reduce_none, - 1, 123, :_reduce_none, - 1, 123, :_reduce_none, - 1, 123, :_reduce_none, - 1, 123, :_reduce_none, - 1, 123, :_reduce_none, - 1, 123, :_reduce_none, - 1, 123, :_reduce_none, - 1, 123, :_reduce_none, - 1, 123, :_reduce_none, - 1, 123, :_reduce_none, - 1, 123, :_reduce_none, - 1, 123, :_reduce_none, - 4, 97, :_reduce_115, - 3, 97, :_reduce_116, - 1, 99, :_reduce_117, - 2, 99, :_reduce_118, - 2, 129, :_reduce_119, - 1, 130, :_reduce_120, - 2, 130, :_reduce_121, - 1, 96, :_reduce_122, - 4, 90, :_reduce_123, - 4, 90, :_reduce_124, - 2, 79, :_reduce_125, - 5, 131, :_reduce_126, - 4, 131, :_reduce_127, - 0, 132, :_reduce_none, - 2, 132, :_reduce_129, - 4, 132, :_reduce_130, - 3, 132, :_reduce_131, - 1, 120, :_reduce_none, - 3, 120, :_reduce_133, - 3, 120, :_reduce_134, - 3, 120, :_reduce_135, - 3, 120, :_reduce_136, - 3, 120, :_reduce_137, - 3, 120, :_reduce_138, - 3, 120, :_reduce_139, - 3, 120, :_reduce_140, - 3, 120, :_reduce_141, - 2, 120, :_reduce_142, - 3, 120, :_reduce_143, - 3, 120, :_reduce_144, - 3, 120, :_reduce_145, - 3, 120, :_reduce_146, - 3, 120, :_reduce_147, - 3, 120, :_reduce_148, - 2, 120, :_reduce_149, - 3, 120, :_reduce_150, - 3, 120, :_reduce_151, - 3, 120, :_reduce_152, - 5, 78, :_reduce_153, - 1, 134, :_reduce_none, - 2, 134, :_reduce_155, - 5, 135, :_reduce_156, - 4, 135, :_reduce_157, - 1, 136, :_reduce_none, - 3, 136, :_reduce_159, - 3, 98, :_reduce_160, + 4, 117, :_reduce_68, + 1, 103, :_reduce_69, + 3, 103, :_reduce_70, + 0, 104, :_reduce_none, + 1, 104, :_reduce_none, + 1, 119, :_reduce_73, + 1, 94, :_reduce_74, + 1, 96, :_reduce_75, + 1, 118, :_reduce_none, + 1, 118, :_reduce_none, + 1, 118, :_reduce_none, + 1, 118, :_reduce_none, + 1, 118, :_reduce_none, + 1, 118, :_reduce_none, + 1, 118, :_reduce_none, + 3, 78, :_reduce_83, + 3, 78, :_reduce_84, + 3, 87, :_reduce_85, + 0, 105, :_reduce_86, + 1, 105, :_reduce_87, + 3, 105, :_reduce_88, + 3, 123, :_reduce_89, + 3, 125, :_reduce_90, + 1, 126, :_reduce_none, + 1, 126, :_reduce_none, + 0, 108, :_reduce_93, + 1, 108, :_reduce_94, + 3, 108, :_reduce_95, + 1, 127, :_reduce_96, + 3, 127, :_reduce_97, + 1, 116, :_reduce_none, + 1, 116, :_reduce_none, + 1, 116, :_reduce_none, + 1, 116, :_reduce_none, + 1, 116, :_reduce_none, + 1, 116, :_reduce_none, + 1, 124, :_reduce_none, + 1, 124, :_reduce_none, + 1, 124, :_reduce_none, + 1, 124, :_reduce_none, + 1, 124, :_reduce_none, + 1, 124, :_reduce_none, + 1, 124, :_reduce_none, + 1, 124, :_reduce_none, + 1, 124, :_reduce_none, + 1, 124, :_reduce_none, + 1, 124, :_reduce_none, + 1, 124, :_reduce_none, + 4, 98, :_reduce_116, + 3, 98, :_reduce_117, + 1, 100, :_reduce_118, + 2, 100, :_reduce_119, + 2, 130, :_reduce_120, + 1, 131, :_reduce_121, + 2, 131, :_reduce_122, + 1, 97, :_reduce_123, + 4, 91, :_reduce_124, + 4, 91, :_reduce_125, + 2, 80, :_reduce_126, + 5, 132, :_reduce_127, + 4, 132, :_reduce_128, + 0, 133, :_reduce_none, + 2, 133, :_reduce_130, + 4, 133, :_reduce_131, + 3, 133, :_reduce_132, + 1, 121, :_reduce_none, + 3, 121, :_reduce_134, + 3, 121, :_reduce_135, + 3, 121, :_reduce_136, + 3, 121, :_reduce_137, + 3, 121, :_reduce_138, + 3, 121, :_reduce_139, + 3, 121, :_reduce_140, + 3, 121, :_reduce_141, + 3, 121, :_reduce_142, + 2, 121, :_reduce_143, + 3, 121, :_reduce_144, + 3, 121, :_reduce_145, + 3, 121, :_reduce_146, + 3, 121, :_reduce_147, + 3, 121, :_reduce_148, + 3, 121, :_reduce_149, + 2, 121, :_reduce_150, + 3, 121, :_reduce_151, + 3, 121, :_reduce_152, + 3, 121, :_reduce_153, + 5, 79, :_reduce_154, + 1, 135, :_reduce_155, + 2, 135, :_reduce_156, + 5, 136, :_reduce_157, + 4, 136, :_reduce_158, + 1, 137, :_reduce_159, + 3, 137, :_reduce_160, + 3, 99, :_reduce_161, + 1, 139, :_reduce_none, + 4, 139, :_reduce_163, + 1, 141, :_reduce_none, + 3, 141, :_reduce_165, + 3, 140, :_reduce_166, + 1, 138, :_reduce_none, + 1, 138, :_reduce_none, + 1, 138, :_reduce_none, 1, 138, :_reduce_none, - 4, 138, :_reduce_162, - 1, 140, :_reduce_none, - 3, 140, :_reduce_164, - 3, 139, :_reduce_165, - 1, 137, :_reduce_none, - 1, 137, :_reduce_none, - 1, 137, :_reduce_none, - 1, 137, :_reduce_none, - 1, 137, :_reduce_none, - 1, 137, :_reduce_none, - 1, 137, :_reduce_none, - 1, 137, :_reduce_173, - 1, 137, :_reduce_none, - 1, 141, :_reduce_175, - 1, 142, :_reduce_none, - 3, 142, :_reduce_177, - 2, 80, :_reduce_178, - 6, 82, :_reduce_179, - 5, 82, :_reduce_180, - 7, 83, :_reduce_181, - 6, 83, :_reduce_182, + 1, 138, :_reduce_none, + 1, 138, :_reduce_none, + 1, 138, :_reduce_none, + 1, 138, :_reduce_174, + 1, 138, :_reduce_none, + 1, 142, :_reduce_176, + 1, 143, :_reduce_none, + 3, 143, :_reduce_178, + 2, 81, :_reduce_179, + 6, 83, :_reduce_180, + 5, 83, :_reduce_181, + 7, 84, :_reduce_182, 6, 84, :_reduce_183, - 5, 84, :_reduce_184, - 1, 106, :_reduce_185, - 1, 101, :_reduce_186, - 1, 101, :_reduce_187, - 1, 101, :_reduce_188, - 1, 145, :_reduce_none, - 3, 145, :_reduce_190, - 1, 147, :_reduce_191, + 6, 85, :_reduce_184, + 5, 85, :_reduce_185, + 1, 107, :_reduce_186, + 1, 102, :_reduce_187, + 1, 102, :_reduce_188, + 1, 102, :_reduce_189, + 1, 146, :_reduce_190, + 3, 146, :_reduce_191, 1, 148, :_reduce_192, - 1, 148, :_reduce_193, - 1, 148, :_reduce_194, - 1, 148, :_reduce_none, - 0, 72, :_reduce_196, - 0, 149, :_reduce_197, - 1, 143, :_reduce_none, - 3, 143, :_reduce_199, - 3, 143, :_reduce_200, - 1, 150, :_reduce_none, - 3, 150, :_reduce_202, - 3, 151, :_reduce_203, - 1, 151, :_reduce_204, - 3, 151, :_reduce_205, - 1, 151, :_reduce_206, - 1, 146, :_reduce_none, - 2, 146, :_reduce_208, + 1, 149, :_reduce_193, + 1, 149, :_reduce_194, + 1, 149, :_reduce_195, + 1, 149, :_reduce_none, + 0, 72, :_reduce_197, + 0, 150, :_reduce_198, 1, 144, :_reduce_none, - 2, 144, :_reduce_210, - 1, 152, :_reduce_none, - 1, 152, :_reduce_none, - 1, 94, :_reduce_213, - 3, 119, :_reduce_214, - 4, 119, :_reduce_215, - 2, 119, :_reduce_216, - 1, 127, :_reduce_none, - 1, 127, :_reduce_none, - 0, 105, :_reduce_none, - 1, 105, :_reduce_220, - 1, 133, :_reduce_221, - 3, 128, :_reduce_222, - 4, 128, :_reduce_223, - 2, 128, :_reduce_224, + 3, 144, :_reduce_200, + 3, 144, :_reduce_201, + 1, 151, :_reduce_none, + 3, 151, :_reduce_203, + 3, 152, :_reduce_204, + 1, 152, :_reduce_205, + 3, 152, :_reduce_206, + 1, 152, :_reduce_207, + 1, 147, :_reduce_none, + 2, 147, :_reduce_209, + 1, 145, :_reduce_none, + 2, 145, :_reduce_211, 1, 153, :_reduce_none, - 3, 153, :_reduce_226, + 1, 153, :_reduce_none, + 1, 95, :_reduce_214, + 3, 120, :_reduce_215, + 4, 120, :_reduce_216, + 2, 120, :_reduce_217, + 1, 128, :_reduce_none, + 1, 128, :_reduce_none, + 0, 106, :_reduce_none, + 1, 106, :_reduce_221, + 1, 134, :_reduce_222, + 3, 129, :_reduce_223, + 4, 129, :_reduce_224, + 2, 129, :_reduce_225, + 1, 154, :_reduce_none, 3, 154, :_reduce_227, - 1, 155, :_reduce_228, - 1, 155, :_reduce_229, - 4, 121, :_reduce_230, - 1, 100, :_reduce_none, - 4, 100, :_reduce_232 ] + 3, 155, :_reduce_228, + 1, 156, :_reduce_229, + 1, 156, :_reduce_230, + 4, 122, :_reduce_231, + 1, 101, :_reduce_none, + 4, 101, :_reduce_233 ] -racc_reduce_n = 233 +racc_reduce_n = 234 -racc_shift_n = 384 +racc_shift_n = 385 racc_action_table = [ - 256, 257, 228, 82, 54, 72, 75, 181, 251, 48, - 72, 75, 194, 205, 210, 163, 156, 348, 46, 47, - 344, 184, 201, 203, 206, 209, 162, 352, 54, 182, - 351, 169, 54, -168, 72, 75, 241, 242, 102, 305, - 106, 158, 58, 193, 230, 60, 204, 208, 193, 306, - 213, 196, 197, 198, 200, 202, 97, 207, 211, 72, - 75, 72, 75, 163, 199, 59, 58, 71, 245, 60, - 58, 83, 86, 60, 162, 92, 244, 72, 75, 169, - 78, 100, 352, 269, 89, 351, 63, 94, 64, 59, - 228, 326, 71, 59, 162, 59, 83, 86, 83, 268, - 92, 65, 92, 184, 76, 78, 307, 137, 163, 89, - 162, 89, 72, 75, 83, 268, 241, 242, 92, 162, - 59, 163, 59, 137, 169, 62, 254, 89, 207, 211, - 72, 75, 162, 308, 102, 199, 106, 169, 59, 255, - 213, 196, 197, 198, -166, 162, 309, 207, 211, 83, - 268, 310, 97, 92, 199, 72, 75, 355, 137, 102, - -170, 106, 89, 71, 218, 356, 173, 83, 86, 220, - 313, 92, -171, 59, 72, 75, 78, 100, 37, 218, - 89, 249, 38, 94, 220, 246, 247, 173, 71, 11, - 210, 59, 83, 86, 246, 367, 92, 271, 201, 37, - -167, 78, 37, 38, 270, 89, 38, 71, 246, 247, - 11, 83, 86, 11, 14, 92, 59, 72, 75, 76, - 78, 102, 278, 106, 89, 277, 213, 196, 197, 198, - 200, 202, 275, 207, 211, 59, 246, 274, 152, 97, - 199, 37, 318, 72, 75, 127, 319, 102, -169, 106, - 71, 63, 11, 14, 83, 86, -167, 37, 92, 207, - 211, 127, -169, 78, 100, 97, 199, 89, 11, 14, - 94, -166, 117, 72, 75, -185, 71, 82, 59, 336, - 83, 86, 197, 198, 92, 231, 338, 207, 211, 78, - 100, 181, 48, 89, 199, 74, 94, 240, -168, 72, - 75, 241, 242, 102, 59, 106, 71, 184, 176, 37, - 83, 86, 59, 38, 92, 345, 322, 175, 76, 78, - 11, 97, -172, 89, -171, 72, 75, -170, 59, 102, - 214, 106, 71, 64, 59, 215, 83, 86, 173, 217, - 92, -23, -23, -23, -23, 78, 100, 97, 155, 89, - 72, 75, 94, 122, 102, 152, 106, 82, 71, 223, - 59, 122, 83, 86, 72, 75, 92, -168, 102, 225, - 106, 78, 100, -166, 276, 89, 226, 117, 94, 44, - 45, 41, 42, 71, -169, -167, 59, 83, 86, 72, - 75, 92, 226, 102, 229, 106, 78, 71, 52, -168, - 89, 83, 86, 72, 75, 92, -166, 102, -169, 106, - 78, 59, 197, 198, 89, -167, -171, 207, 211, 365, - 231, 152, 71, 234, 199, 59, 83, 86, 50, 210, - 92, -21, -21, -21, -21, 78, 71, 201, 372, 89, - 83, 86, 49, 374, 92, 72, 75, 228, -220, 78, - 59, 226, 354, 89, 377, 72, 75, 40, 39, 102, - 237, 106, 341, nil, 59, 213, 196, 197, 198, 200, - 202, nil, 207, 211, nil, nil, nil, 97, 162, 199, - nil, nil, 83, 268, nil, nil, 92, nil, 71, nil, - nil, 137, 83, 86, nil, 89, 92, 44, 45, 41, - 42, 78, 100, 72, 75, 89, 59, 102, 94, 106, - 213, 196, 197, 198, 200, 202, 59, 207, 211, nil, - 213, 196, 197, 198, 199, 97, nil, 207, 211, 72, - 75, nil, nil, 102, 199, 106, 71, nil, nil, nil, - 83, 86, nil, nil, 92, nil, nil, nil, nil, 78, - 100, 97, nil, 89, nil, nil, 94, nil, nil, 72, - 75, nil, 71, 102, 59, 106, 83, 86, nil, nil, - 92, nil, nil, nil, nil, 78, 100, nil, nil, 89, - nil, 97, 94, nil, nil, 72, 75, nil, nil, 102, - 59, 106, 71, nil, nil, nil, 83, 86, nil, nil, - 92, nil, nil, nil, nil, 78, 100, 97, nil, 89, - 72, 75, 94, nil, 102, nil, 106, nil, 71, nil, - 59, nil, 83, 86, 72, 75, 92, nil, 102, nil, - nil, 78, 100, nil, nil, 89, nil, nil, 94, nil, - nil, nil, nil, 71, nil, nil, 59, 83, 86, 72, - 75, 92, nil, 102, nil, 106, 78, 71, nil, nil, - 89, 83, 143, nil, nil, 92, nil, nil, nil, nil, - 137, 59, nil, nil, 89, 72, 75, nil, nil, 102, - nil, 106, 71, nil, nil, 59, 83, 86, nil, nil, - 92, nil, nil, nil, nil, 78, nil, 97, nil, 89, - nil, 72, 75, nil, nil, 102, nil, 106, 71, nil, - 59, nil, 83, 86, nil, nil, 92, nil, nil, nil, - nil, 78, 100, 97, nil, 89, nil, nil, 94, nil, - nil, 72, 75, nil, 71, 102, 59, 106, 83, 86, - nil, nil, 92, nil, nil, nil, nil, 78, 100, nil, - nil, 89, nil, 97, 94, nil, nil, 72, 75, nil, - nil, 102, 59, 106, 71, nil, nil, nil, 83, 86, - nil, nil, 92, nil, nil, nil, nil, 78, 100, 97, - nil, 89, 72, 75, 94, nil, 102, nil, 106, nil, - 71, nil, 59, nil, 83, 86, nil, nil, 92, nil, - nil, nil, nil, 78, 100, nil, nil, 89, 72, 75, - 94, nil, 102, nil, 106, 71, nil, nil, 59, 83, - 86, nil, nil, 92, nil, nil, nil, nil, 78, nil, - 97, nil, 89, nil, 72, 75, nil, nil, 102, nil, - 106, 71, nil, 59, nil, 83, 86, nil, nil, 92, - nil, nil, 72, 75, 78, 100, 97, nil, 89, 72, - 75, 94, nil, 102, nil, 106, nil, 71, nil, 59, - nil, 83, 86, nil, nil, 92, nil, nil, nil, nil, - 78, 100, nil, nil, 89, 162, nil, 94, nil, 83, - 268, nil, 71, 92, nil, 59, 83, 86, 137, nil, - 92, nil, 89, nil, nil, 78, 72, 75, nil, 89, - 102, nil, 106, 59, nil, nil, nil, nil, nil, nil, - 59, nil, nil, nil, nil, 72, 75, nil, 97, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, 71, - nil, nil, nil, 83, 86, nil, nil, 92, 177, nil, - 72, 75, 78, 100, nil, nil, 89, nil, 71, 94, - nil, nil, 83, 86, nil, nil, 92, 59, 72, 75, - 76, 78, 102, 339, 106, 89, nil, nil, nil, nil, - nil, nil, nil, 71, nil, nil, 59, 83, 86, nil, - 97, 92, nil, 72, 75, 76, 78, 102, nil, 106, - 89, 71, nil, 72, 75, 83, 86, nil, nil, 92, - nil, 59, nil, nil, 78, 100, nil, nil, 89, 72, - 75, 94, nil, nil, nil, nil, 71, nil, nil, 59, - 83, 86, nil, nil, 92, nil, 162, nil, nil, 78, - 83, 268, nil, 89, 92, nil, 72, 75, nil, 137, - 102, nil, 162, 89, 59, nil, 83, 268, nil, nil, - 92, nil, 72, 75, 59, 137, 102, nil, 106, 89, - nil, nil, 72, 75, nil, nil, 102, nil, 106, 71, - 59, nil, nil, 83, 268, nil, nil, 92, nil, nil, - nil, nil, 137, nil, 97, 71, 89, nil, nil, 83, - 86, nil, nil, 92, nil, 71, nil, 59, 78, 83, - 86, nil, 89, 92, nil, nil, nil, nil, 78, 100, - 72, 75, 89, 59, 102, 94, 106, 213, 196, 197, - 198, 200, 202, 59, 207, 211, nil, nil, nil, 72, - 75, 199, 97, 102, 189, 106, 72, 75, nil, nil, - 102, nil, 106, 71, nil, nil, nil, 83, 86, nil, - nil, 92, nil, nil, nil, nil, 78, 100, 72, 75, - 89, nil, 71, 94, nil, nil, 83, 86, nil, 71, - 92, 59, nil, 83, 86, 78, nil, 92, nil, 89, - nil, nil, 78, 72, 75, nil, 89, 102, nil, 106, - 59, 162, nil, nil, nil, 83, 268, 59, nil, 92, - nil, 72, 75, nil, 137, 102, nil, 106, 89, nil, - nil, nil, nil, nil, nil, nil, 71, nil, nil, 59, - 83, 86, nil, 97, 92, nil, nil, nil, nil, 78, - nil, 72, 75, 89, 71, 102, nil, 106, 83, 86, - nil, nil, 92, nil, 59, nil, nil, 78, 100, nil, - nil, 89, nil, 97, 94, nil, nil, 72, 75, nil, - nil, 102, 59, 106, 71, nil, nil, nil, 83, 86, - nil, nil, 92, nil, nil, nil, nil, 78, 100, 97, - nil, 89, nil, nil, 94, nil, nil, nil, nil, nil, - 71, nil, 59, nil, 83, 86, 212, nil, 92, nil, - nil, nil, nil, 78, 100, 205, 210, 89, nil, nil, - 94, nil, nil, nil, 201, 203, 206, 209, 59, nil, - 205, 210, nil, nil, nil, nil, nil, nil, nil, 201, - 203, 206, 209, nil, nil, nil, nil, nil, 204, 208, - nil, nil, 213, 196, 197, 198, 200, 202, nil, 207, - 211, nil, nil, 204, 208, nil, 199, 213, 196, 197, - 198, 200, 202, nil, 207, 211, 205, 210, nil, nil, - nil, 199, nil, nil, nil, 201, 203, 206, 209, nil, - nil, 205, 210, nil, nil, nil, nil, nil, nil, nil, - 201, 203, 206, 209, nil, nil, nil, nil, nil, 204, - 208, nil, nil, 213, 196, 197, 198, 200, 202, nil, - 207, 211, nil, nil, 204, 208, nil, 199, 213, 196, - 197, 198, 200, 202, nil, 207, 211, 205, 210, nil, - nil, nil, 199, nil, nil, nil, 201, 203, 206, 209, - nil, nil, 205, 210, nil, nil, nil, nil, nil, nil, - 273, 201, 203, 206, 209, nil, nil, nil, nil, nil, - nil, 208, nil, nil, 213, 196, 197, 198, 200, 202, - nil, 207, 211, nil, nil, 204, 208, nil, 199, 213, - 196, 197, 198, 200, 202, nil, 207, 211, 205, 210, - nil, nil, nil, 199, nil, nil, nil, 201, 203, 206, - 209, nil, nil, 26, 210, 33, 1, nil, 7, 12, - nil, 17, 201, 23, nil, 29, nil, 3, nil, nil, - 11, 14, nil, 210, nil, 213, 196, 197, 198, 200, - 202, 201, 207, 211, nil, nil, nil, nil, nil, 199, - 213, 196, 197, 198, 200, 202, nil, 207, 211, nil, - nil, 324, nil, nil, 199, nil, nil, nil, nil, 213, - 196, 197, 198, 200, 202, nil, 207, 211, nil, nil, - 379, nil, 26, 199, 33, 1, nil, 7, 12, nil, - 17, nil, 23, nil, 29, nil, 3, nil, nil, 11, - 14, 26, 382, 33, 1, nil, 7, 12, nil, 17, - nil, 23, nil, 29, nil, 3, nil, nil, 11, 14, - nil, 296, nil, 26, nil, 33, 1, nil, 7, 12, - nil, 17, nil, 23, nil, 29, nil, 3, nil, nil, - 11, 14, 26, 364, 33, 1, nil, 7, 12, nil, - 17, nil, 23, nil, 29, nil, 3, nil, nil, 11, - 14, nil, 381, nil, 26, nil, 33, 1, nil, 7, - 12, nil, 17, nil, 23, nil, 29, nil, 3, nil, - nil, 11, 14, 26, 383, 33, 1, nil, 7, 12, - nil, 17, nil, 23, nil, 29, nil, 3, nil, nil, - 11, 14, nil, 357, nil, 26, nil, 33, 1, nil, - 7, 12, nil, 17, nil, 23, nil, 29, nil, 3, - nil, nil, 11, 14, 26, 363, 33, 1, nil, 7, - 12, nil, 17, nil, 23, nil, 29, nil, 3, nil, - nil, 11, 14, nil, 375, nil, 26, nil, 33, 1, - nil, 7, 12, nil, 17, nil, 23, nil, 29, nil, - 3, nil, nil, 11, 14, 26, 304, 33, 1, nil, - 7, 12, nil, 17, nil, 23, nil, 29, nil, 3, - nil, nil, 11, 14, nil, 349, nil, 26, nil, 33, - 1, nil, 7, 12, nil, 17, nil, 23, nil, 29, - nil, 3, nil, nil, 11, 14, 26, nil, 33, 1, - nil, 7, 12, nil, 17, nil, 23, nil, 29, nil, - 3, nil, nil, 11, 14, 26, nil, 33, 1, nil, - 7, 12, nil, 17, nil, 23, nil, 29, nil, 3, - nil, nil, 11, 14 ] + 242, 243, 55, 231, 356, 112, 157, 113, 78, 298, + 68, 71, 357, 181, 186, 326, 344, 340, 55, 295, + 114, 231, 177, 179, 182, 185, 170, 294, 68, 71, + 286, 158, 100, 285, 103, 68, 71, 291, 292, 55, + 59, 291, 292, 61, 111, 233, 180, 184, 198, 231, + 189, 172, 173, 174, 176, 178, 59, 183, 187, 61, + -168, 66, 170, 60, 175, 79, 81, 186, 202, 88, + 112, 166, 79, 252, 74, 177, 88, 59, 84, 60, + 61, 139, 68, 71, 333, 84, 100, 117, 103, 60, + 36, -170, 68, 71, 38, 306, 60, 307, 203, 240, + 60, 10, 203, 189, 172, 173, 174, 176, 178, 202, + 183, 187, 241, 202, 209, 66, 218, 175, 209, 79, + 81, 219, 284, 88, 309, 202, 256, 283, 74, 79, + 252, 308, 84, 88, 203, 68, 71, 310, 139, 100, + 203, 103, 84, 60, 218, 202, 256, 367, 36, 219, + 209, 202, 38, 60, 68, 71, 209, 95, 100, 10, + 103, 68, 71, 68, 71, 100, 337, 103, 66, 335, + 199, 154, 79, 81, 173, 174, 88, 183, 187, 183, + 187, 74, 99, 95, 175, 84, 175, 66, 90, 311, + 337, 79, 81, 335, 66, 88, 60, 287, 79, 81, + 74, 198, 88, 315, 84, 68, 71, 74, 99, -172, + 213, 84, 68, 71, 90, 60, 100, 36, 103, 68, + 71, 38, 60, 100, 318, 103, 68, 71, 10, 15, + 36, -167, 213, 355, 38, 167, 36, 313, 202, 154, + 127, 10, 79, 252, 323, 66, 88, 10, 15, 79, + 81, 139, 66, 88, 166, 84, 79, 81, 74, 202, + 88, 229, 84, 79, 252, 74, 60, 88, 49, 84, + 68, 71, 139, 60, 78, -186, 84, 47, 48, 49, + 60, 329, 36, 170, 183, 187, 127, 60, -169, 68, + 71, 175, 70, 10, 15, 68, 71, 161, -171, 100, + 289, 103, -169, 66, 291, 292, 60, 79, 81, 258, + -167, 88, -170, 256, 257, 72, 74, 95, -168, 60, + 84, 156, 66, 154, 68, 71, 79, 81, 66, 122, + 88, 60, 79, 81, 72, 74, 88, -170, -173, 84, + -172, 74, 99, 68, 71, 84, -171, 100, 90, 103, + 60, 200, 334, 68, 71, 213, 60, 202, 215, 254, + 338, 79, 252, 173, 174, 88, 122, 296, 183, 187, + 139, 256, 257, 216, 84, 175, 66, 234, 68, 71, + 79, 81, 113, 117, 88, 60, 202, 217, 78, 74, + 79, 252, 353, 84, 88, 53, 68, 71, 223, 139, + 100, 260, 103, 84, 60, 43, 44, 40, 41, 358, + 52, 66, 51, 225, 60, 79, 81, -169, 229, 88, + 365, 68, 71, 72, 74, 100, 238, 103, 84, 66, + 228, -167, 234, 79, 81, 372, 373, 88, -169, 60, + -167, -170, 74, 95, -168, -172, 84, 68, 71, 45, + 375, 100, 229, 103, 66, -221, 232, 60, 79, 81, + 378, 39, 88, -24, -24, -24, -24, 74, 99, 95, + -168, 84, 383, 384, 90, nil, nil, 68, 71, nil, + 66, 100, 60, 103, 79, 81, nil, nil, 88, -22, + -22, -22, -22, 74, 99, nil, nil, 84, nil, 95, + 90, nil, nil, 68, 71, nil, nil, 100, 60, 103, + 66, nil, nil, nil, 79, 81, nil, nil, 88, 43, + 44, 40, 41, 74, 99, 95, nil, 84, nil, nil, + 90, nil, nil, 68, 71, nil, 66, 100, 60, 103, + 79, 81, nil, nil, 88, nil, nil, nil, nil, 74, + 99, nil, nil, 84, nil, 95, 90, nil, nil, 68, + 71, nil, nil, 100, 60, 103, 66, nil, nil, nil, + 79, 81, nil, nil, 88, nil, nil, 68, 71, 74, + 99, 100, nil, 84, 68, 71, 90, nil, 100, nil, + 103, nil, 66, nil, 60, nil, 79, 81, nil, nil, + 88, nil, nil, nil, nil, 74, 95, nil, nil, 84, + 66, nil, nil, nil, 79, 144, nil, 66, 88, nil, + 60, 79, 81, 139, nil, 88, nil, 84, nil, nil, + 74, 99, nil, nil, 84, 68, 71, 90, 60, 100, + nil, 103, nil, nil, nil, 60, nil, nil, nil, nil, + nil, nil, nil, nil, 68, 71, nil, 95, 100, nil, + 103, 68, 71, nil, nil, 100, nil, 103, 66, nil, + nil, nil, 79, 81, nil, nil, 88, nil, nil, 68, + 71, 74, 99, nil, nil, 84, nil, 66, 90, nil, + nil, 79, 81, nil, 66, 88, 60, nil, 79, 81, + 74, nil, 88, nil, 84, 68, 71, 74, nil, nil, + nil, 84, 202, nil, nil, 60, 79, 252, nil, nil, + 88, nil, 60, nil, nil, 139, 68, 71, 162, 84, + 100, nil, 103, nil, nil, nil, nil, nil, 66, nil, + 60, nil, 79, 81, nil, nil, 88, nil, 95, nil, + 72, 74, 68, 71, nil, 84, 100, nil, 103, 66, + nil, nil, nil, 79, 81, nil, 60, 88, nil, nil, + nil, nil, 74, 99, 95, nil, 84, 68, 71, 90, + nil, nil, nil, nil, nil, 66, nil, 60, nil, 79, + 81, nil, nil, 88, nil, nil, nil, nil, 74, 99, + 327, nil, 84, 68, 71, 90, nil, 100, nil, 103, + 66, nil, nil, 60, 79, 81, nil, nil, 88, nil, + nil, nil, 72, 74, nil, 95, nil, 84, 68, 71, + nil, nil, 100, nil, 103, nil, 66, nil, 60, nil, + 79, 81, 68, 71, 88, nil, 100, nil, 103, 74, + 99, nil, nil, 84, nil, nil, 90, nil, nil, nil, + nil, 66, nil, nil, 60, 79, 81, 68, 71, 88, + nil, 100, nil, 103, 74, 66, nil, nil, 84, 79, + 81, 68, 71, 88, nil, 100, nil, nil, 74, 60, + nil, nil, 84, nil, nil, nil, nil, nil, nil, nil, + 66, nil, nil, 60, 79, 81, nil, nil, 88, nil, + nil, 68, 71, 74, 66, nil, nil, 84, 79, 252, + nil, nil, 88, nil, nil, nil, nil, 139, 60, 68, + 71, 84, nil, 100, nil, 103, nil, nil, nil, nil, + nil, nil, 60, nil, 202, nil, nil, nil, 79, 252, + nil, 95, 88, nil, nil, nil, nil, 139, nil, 68, + 71, 84, 66, 100, nil, 103, 79, 81, nil, nil, + 88, nil, 60, nil, nil, 74, 99, nil, nil, 84, + nil, 95, 90, nil, nil, 68, 71, nil, nil, 100, + 60, 103, 66, nil, nil, nil, 79, 81, nil, nil, + 88, nil, nil, nil, nil, 74, 99, 95, nil, 84, + nil, nil, 90, nil, nil, 68, 71, nil, 66, 100, + 60, 103, 79, 81, nil, nil, 88, nil, nil, nil, + nil, 74, 99, nil, nil, 84, nil, 95, 90, nil, + nil, 68, 71, nil, nil, 100, 60, 103, 66, nil, + nil, nil, 79, 81, nil, nil, 88, nil, nil, nil, + nil, 74, 99, 95, nil, 84, nil, nil, 90, nil, + nil, 68, 71, nil, 66, 100, 60, 103, 79, 81, + nil, nil, 88, nil, nil, nil, nil, 74, 99, nil, + nil, 84, nil, 95, 90, nil, nil, 68, 71, nil, + nil, 100, 60, 103, 66, nil, nil, nil, 79, 81, + nil, nil, 88, nil, nil, nil, nil, 74, 99, 95, + nil, 84, nil, nil, 90, nil, nil, 68, 71, nil, + 66, 100, 60, 103, 79, 81, nil, nil, 88, nil, + nil, nil, nil, 74, 99, nil, nil, 84, nil, 95, + 90, nil, nil, 68, 71, nil, nil, 100, 60, 103, + 66, nil, nil, nil, 79, 81, nil, nil, 88, nil, + nil, nil, nil, 74, 99, 95, nil, 84, 68, 71, + 90, nil, 100, 193, 103, nil, 66, nil, 60, nil, + 79, 81, nil, nil, 88, nil, nil, nil, nil, 74, + 99, nil, nil, 84, 68, 71, 90, nil, 100, nil, + 103, 66, nil, nil, 60, 79, 81, nil, nil, 88, + nil, nil, nil, nil, 74, nil, 95, nil, 84, nil, + 68, 71, nil, nil, 100, nil, 103, 66, nil, 60, + nil, 79, 81, nil, nil, 88, nil, nil, nil, nil, + 74, 99, 95, nil, 84, nil, nil, 90, nil, nil, + nil, nil, nil, 66, nil, 60, nil, 79, 81, 188, + nil, 88, nil, nil, nil, nil, 74, 99, 181, 186, + 84, nil, nil, 90, nil, nil, nil, 177, 179, 182, + 185, 60, nil, 181, 186, nil, nil, nil, nil, nil, + nil, 282, 177, 179, 182, 185, nil, nil, nil, nil, + nil, 180, 184, nil, nil, 189, 172, 173, 174, 176, + 178, nil, 183, 187, nil, nil, 180, 184, nil, 175, + 189, 172, 173, 174, 176, 178, nil, 183, 187, 181, + 186, nil, nil, nil, 175, nil, nil, nil, 177, 179, + 182, 185, nil, nil, 181, 186, nil, nil, nil, nil, + nil, nil, nil, 177, 179, 182, 185, nil, nil, nil, + nil, nil, nil, nil, nil, nil, 189, 172, 173, 174, + 176, 178, nil, 183, 187, nil, nil, 180, 184, nil, + 175, 189, 172, 173, 174, 176, 178, nil, 183, 187, + 181, 186, nil, nil, nil, 175, nil, nil, nil, 177, + 179, 182, 185, nil, nil, 181, 186, nil, nil, nil, + nil, nil, nil, nil, 177, 179, 182, 185, nil, nil, + nil, nil, nil, 180, 184, nil, nil, 189, 172, 173, + 174, 176, 178, nil, 183, 187, nil, nil, nil, 184, + nil, 175, 189, 172, 173, 174, 176, 178, nil, 183, + 187, 181, 186, nil, nil, nil, 175, nil, nil, nil, + 177, 179, 182, 185, nil, nil, nil, 186, nil, 189, + 172, 173, 174, 176, 178, 177, 183, 187, nil, nil, + nil, nil, nil, 175, 180, 184, 186, nil, 189, 172, + 173, 174, 176, 178, 177, 183, 187, nil, nil, nil, + nil, 186, 175, 189, 172, 173, 174, 176, 178, 177, + 183, 187, nil, nil, nil, nil, nil, 175, nil, nil, + nil, nil, 189, 172, 173, 174, 176, 178, nil, 183, + 187, 280, nil, nil, nil, nil, 175, 189, 172, 173, + 174, 176, 178, nil, 183, 187, nil, nil, nil, nil, + 325, 175, 26, nil, 32, 1, nil, 8, 11, nil, + 18, nil, 23, nil, 29, nil, 2, nil, nil, 10, + 15, 26, 363, 32, 1, nil, 8, 11, nil, 18, + nil, 23, nil, 29, nil, 2, nil, nil, 10, 15, + nil, 382, nil, 26, nil, 32, 1, nil, 8, 11, + nil, 18, nil, 23, nil, 29, nil, 2, nil, nil, + 10, 15, 26, 380, 32, 1, nil, 8, 11, nil, + 18, nil, 23, nil, 29, nil, 2, nil, nil, 10, + 15, nil, 376, nil, 26, nil, 32, 1, nil, 8, + 11, nil, 18, nil, 23, nil, 29, nil, 2, nil, + nil, 10, 15, 26, 305, 32, 1, nil, 8, 11, + nil, 18, nil, 23, nil, 29, nil, 2, nil, nil, + 10, 15, nil, nil, nil, 26, nil, 32, 1, nil, + 8, 11, nil, 18, nil, 23, nil, 29, nil, 2, + nil, nil, 10, 15, 26, nil, 32, 1, nil, 8, + 11, nil, 18, nil, 23, nil, 29, nil, 2, nil, + nil, 10, 15, 26, nil, 32, 1, nil, 8, 11, + nil, 18, nil, 23, nil, 29, nil, 2, nil, nil, + 10, 15, 26, nil, 32, 1, nil, 8, 11, nil, + 18, nil, 23, nil, 29, nil, 2, nil, nil, 10, + 15, 189, 172, 173, 174, 176, 178, nil, 183, 187, + 189, 172, 173, 174, nil, 175, nil, 183, 187, 189, + 172, 173, 174, nil, 175, nil, 183, 187, nil, nil, + nil, nil, nil, 175 ] racc_action_check = [ - 180, 180, 152, 86, 156, 106, 106, 272, 174, 7, - 277, 277, 106, 180, 180, 65, 55, 277, 7, 7, - 272, 86, 180, 180, 180, 180, 65, 296, 17, 80, - 296, 65, 158, 95, 202, 202, 174, 174, 202, 218, - 202, 55, 156, 106, 152, 156, 180, 180, 277, 219, - 180, 180, 180, 180, 180, 180, 202, 180, 180, 181, - 181, 368, 368, 239, 180, 156, 17, 202, 165, 17, - 158, 202, 202, 158, 239, 202, 165, 182, 182, 239, - 202, 202, 349, 182, 202, 349, 22, 202, 22, 17, - 143, 243, 181, 158, 368, 202, 181, 181, 368, 368, - 181, 22, 368, 143, 181, 181, 220, 368, 163, 181, - 182, 368, 355, 355, 182, 182, 243, 243, 182, 163, - 181, 62, 368, 182, 163, 22, 178, 182, 281, 281, - 351, 351, 62, 221, 351, 281, 351, 62, 182, 178, - 285, 285, 285, 285, 101, 355, 221, 285, 285, 355, - 355, 224, 351, 355, 285, 341, 341, 300, 355, 341, - 91, 341, 355, 351, 308, 300, 226, 351, 351, 308, - 227, 351, 90, 355, 184, 184, 351, 351, 12, 122, - 351, 171, 12, 351, 122, 171, 171, 229, 341, 12, - 286, 351, 341, 341, 343, 343, 341, 184, 286, 1, - 87, 341, 30, 1, 183, 341, 30, 184, 183, 183, - 1, 184, 184, 30, 30, 184, 341, 196, 196, 184, - 184, 196, 195, 196, 184, 195, 286, 286, 286, 286, - 286, 286, 188, 286, 286, 184, 188, 188, 231, 196, - 286, 120, 232, 197, 197, 120, 233, 197, 103, 197, - 196, 85, 120, 120, 196, 196, 105, 43, 196, 280, - 280, 43, 84, 196, 196, 197, 280, 196, 43, 43, - 196, 81, 215, 23, 23, 78, 197, 23, 196, 250, - 197, 197, 279, 279, 197, 252, 253, 279, 279, 197, - 197, 77, 71, 197, 279, 23, 197, 160, 68, 26, - 26, 160, 160, 26, 197, 26, 23, 268, 67, 234, - 23, 23, 211, 234, 23, 274, 234, 66, 23, 23, - 234, 26, 107, 23, 108, 198, 198, 109, 207, 198, - 114, 198, 26, 115, 23, 119, 26, 26, 64, 121, - 26, 35, 35, 35, 35, 26, 26, 198, 52, 26, - 29, 29, 26, 51, 29, 50, 29, 127, 198, 132, - 26, 36, 198, 198, 307, 307, 198, 133, 307, 136, - 307, 198, 198, 138, 192, 198, 139, 33, 198, 34, - 34, 34, 34, 29, 140, 142, 198, 29, 29, 305, - 305, 29, 315, 305, 144, 305, 29, 307, 16, 327, - 29, 307, 307, 199, 199, 307, 328, 199, 330, 199, - 307, 29, 297, 297, 307, 331, 332, 297, 297, 337, - 153, 175, 305, 154, 297, 307, 305, 305, 9, 288, - 305, 28, 28, 28, 28, 305, 199, 288, 352, 305, - 199, 199, 8, 356, 199, 298, 298, 173, 367, 199, - 305, 172, 298, 199, 369, 200, 200, 3, 2, 200, - 157, 200, 263, nil, 199, 288, 288, 288, 288, 288, - 288, nil, 288, 288, nil, nil, nil, 200, 298, 288, - nil, nil, 298, 298, nil, nil, 298, nil, 200, nil, - nil, 298, 200, 200, nil, 298, 200, 4, 4, 4, - 4, 200, 200, 39, 39, 200, 298, 39, 200, 39, - 293, 293, 293, 293, 293, 293, 200, 293, 293, nil, - 283, 283, 283, 283, 293, 39, nil, 283, 283, 201, - 201, nil, nil, 201, 283, 201, 39, nil, nil, nil, - 39, 39, nil, nil, 39, nil, nil, nil, nil, 39, - 39, 201, nil, 39, nil, nil, 39, nil, nil, 46, - 46, nil, 201, 46, 39, 46, 201, 201, nil, nil, - 201, nil, nil, nil, nil, 201, 201, nil, nil, 201, - nil, 46, 201, nil, nil, 47, 47, nil, nil, 47, - 201, 47, 46, nil, nil, nil, 46, 46, nil, nil, - 46, nil, nil, nil, nil, 46, 46, 47, nil, 46, - 48, 48, 46, nil, 48, nil, 48, nil, 47, nil, - 46, nil, 47, 47, 49, 49, 47, nil, 49, nil, - nil, 47, 47, nil, nil, 47, nil, nil, 47, nil, - nil, nil, nil, 48, nil, nil, 47, 48, 48, 176, - 176, 48, nil, 176, nil, 176, 48, 49, nil, nil, - 48, 49, 49, nil, nil, 49, nil, nil, nil, nil, - 49, 48, nil, nil, 49, 203, 203, nil, nil, 203, - nil, 203, 176, nil, nil, 49, 176, 176, nil, nil, - 176, nil, nil, nil, nil, 176, nil, 203, nil, 176, - nil, 204, 204, nil, nil, 204, nil, 204, 203, nil, - 176, nil, 203, 203, nil, nil, 203, nil, nil, nil, - nil, 203, 203, 204, nil, 203, nil, nil, 203, nil, - nil, 205, 205, nil, 204, 205, 203, 205, 204, 204, - nil, nil, 204, nil, nil, nil, nil, 204, 204, nil, - nil, 204, nil, 205, 204, nil, nil, 100, 100, nil, - nil, 100, 204, 100, 205, nil, nil, nil, 205, 205, - nil, nil, 205, nil, nil, nil, nil, 205, 205, 100, - nil, 205, 63, 63, 205, nil, 63, nil, 63, nil, - 100, nil, 205, nil, 100, 100, nil, nil, 100, nil, - nil, nil, nil, 100, 100, nil, nil, 100, 208, 208, - 100, nil, 208, nil, 208, 63, nil, nil, 100, 63, - 63, nil, nil, 63, nil, nil, nil, nil, 63, nil, - 208, nil, 63, nil, 209, 209, nil, nil, 209, nil, - 209, 208, nil, 63, nil, 208, 208, nil, nil, 208, - nil, nil, 269, 269, 208, 208, 209, nil, 208, 276, - 276, 208, nil, 276, nil, 276, nil, 209, nil, 208, - nil, 209, 209, nil, nil, 209, nil, nil, nil, nil, - 209, 209, nil, nil, 209, 269, nil, 209, nil, 269, - 269, nil, 276, 269, nil, 209, 276, 276, 269, nil, - 276, nil, 269, nil, nil, 276, 256, 256, nil, 276, - 256, nil, 256, 269, nil, nil, nil, nil, nil, nil, - 276, nil, nil, nil, nil, 74, 74, nil, 256, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, 256, - nil, nil, nil, 256, 256, nil, nil, 256, 74, nil, - 254, 254, 256, 256, nil, nil, 256, nil, 74, 256, - nil, nil, 74, 74, nil, nil, 74, 256, 75, 75, - 74, 74, 75, 254, 75, 74, nil, nil, nil, nil, - nil, nil, nil, 254, nil, nil, 74, 254, 254, nil, - 75, 254, nil, 248, 248, 254, 254, 248, nil, 248, - 254, 75, nil, 245, 245, 75, 75, nil, nil, 75, - nil, 254, nil, nil, 75, 75, nil, nil, 75, 244, - 244, 75, nil, nil, nil, nil, 248, nil, nil, 75, - 248, 248, nil, nil, 248, nil, 245, nil, nil, 248, - 245, 245, nil, 248, 245, nil, 225, 225, nil, 245, - 225, nil, 244, 245, 248, nil, 244, 244, nil, nil, - 244, nil, 82, 82, 245, 244, 82, nil, 82, 244, - nil, nil, 210, 210, nil, nil, 210, nil, 210, 225, - 244, nil, nil, 225, 225, nil, nil, 225, nil, nil, - nil, nil, 225, nil, 210, 82, 225, nil, nil, 82, - 82, nil, nil, 82, nil, 210, nil, 225, 82, 210, - 210, nil, 82, 210, nil, nil, nil, nil, 210, 210, - 213, 213, 210, 82, 213, 210, 213, 284, 284, 284, - 284, 284, 284, 210, 284, 284, nil, nil, nil, 102, - 102, 284, 213, 102, 102, 102, 230, 230, nil, nil, - 230, nil, 230, 213, nil, nil, nil, 213, 213, nil, - nil, 213, nil, nil, nil, nil, 213, 213, 214, 214, - 213, nil, 102, 213, nil, nil, 102, 102, nil, 230, - 102, 213, nil, 230, 230, 102, nil, 230, nil, 102, - nil, nil, 230, 228, 228, nil, 230, 228, nil, 228, - 102, 214, nil, nil, nil, 214, 214, 230, nil, 214, - nil, 94, 94, nil, 214, 94, nil, 94, 214, nil, - nil, nil, nil, nil, nil, nil, 228, nil, nil, 214, - 228, 228, nil, 94, 228, nil, nil, nil, nil, 228, - nil, 97, 97, 228, 94, 97, nil, 97, 94, 94, - nil, nil, 94, nil, 228, nil, nil, 94, 94, nil, - nil, 94, nil, 97, 94, nil, nil, 206, 206, nil, - nil, 206, 94, 206, 97, nil, nil, nil, 97, 97, - nil, nil, 97, nil, nil, nil, nil, 97, 97, 206, - nil, 97, nil, nil, 97, nil, nil, nil, nil, nil, - 206, nil, 97, nil, 206, 206, 111, nil, 206, nil, - nil, nil, nil, 206, 206, 111, 111, 206, nil, nil, - 206, nil, nil, nil, 111, 111, 111, 111, 206, nil, - 124, 124, nil, nil, nil, nil, nil, nil, nil, 124, - 124, 124, 124, nil, nil, nil, nil, nil, 111, 111, - nil, nil, 111, 111, 111, 111, 111, 111, nil, 111, - 111, nil, nil, 124, 124, nil, 111, 124, 124, 124, - 124, 124, 124, nil, 124, 124, 130, 130, nil, nil, - nil, 124, nil, nil, nil, 130, 130, 130, 130, nil, - nil, 131, 131, nil, nil, nil, nil, nil, nil, nil, - 131, 131, 131, 131, nil, nil, nil, nil, nil, 130, - 130, nil, nil, 130, 130, 130, 130, 130, 130, nil, - 130, 130, nil, nil, 131, 131, nil, 130, 131, 131, - 131, 131, 131, 131, nil, 131, 131, 287, 287, nil, - nil, nil, 131, nil, nil, nil, 287, 287, 287, 287, - nil, nil, 186, 186, nil, nil, nil, nil, nil, nil, - 186, 186, 186, 186, 186, nil, nil, nil, nil, nil, - nil, 287, nil, nil, 287, 287, 287, 287, 287, 287, - nil, 287, 287, nil, nil, 186, 186, nil, 287, 186, - 186, 186, 186, 186, 186, nil, 186, 186, 291, 291, - nil, nil, nil, 186, nil, nil, nil, 291, 291, 291, - 291, nil, nil, 19, 292, 19, 19, nil, 19, 19, - nil, 19, 292, 19, nil, 19, nil, 19, nil, nil, - 19, 19, nil, 289, nil, 291, 291, 291, 291, 291, - 291, 289, 291, 291, nil, nil, nil, nil, nil, 291, - 292, 292, 292, 292, 292, 292, nil, 292, 292, nil, - nil, 237, nil, nil, 292, nil, nil, nil, nil, 289, - 289, 289, 289, 289, 289, nil, 289, 289, nil, nil, - 372, nil, 237, 289, 237, 237, nil, 237, 237, nil, - 237, nil, 237, nil, 237, nil, 237, nil, nil, 237, - 237, 372, 378, 372, 372, nil, 372, 372, nil, 372, - nil, 372, nil, 372, nil, 372, nil, nil, 372, 372, - nil, 212, nil, 378, nil, 378, 378, nil, 378, 378, - nil, 378, nil, 378, nil, 378, nil, 378, nil, nil, - 378, 378, 212, 323, 212, 212, nil, 212, 212, nil, - 212, nil, 212, nil, 212, nil, 212, nil, nil, 212, - 212, nil, 374, nil, 323, nil, 323, 323, nil, 323, - 323, nil, 323, nil, 323, nil, 323, nil, 323, nil, - nil, 323, 323, 374, 380, 374, 374, nil, 374, 374, - nil, 374, nil, 374, nil, 374, nil, 374, nil, nil, - 374, 374, nil, 303, nil, 380, nil, 380, 380, nil, - 380, 380, nil, 380, nil, 380, nil, 380, nil, 380, - nil, nil, 380, 380, 303, 319, 303, 303, nil, 303, - 303, nil, 303, nil, 303, nil, 303, nil, 303, nil, - nil, 303, 303, nil, 362, nil, 319, nil, 319, 319, - nil, 319, 319, nil, 319, nil, 319, nil, 319, nil, - 319, nil, nil, 319, 319, 362, 217, 362, 362, nil, - 362, 362, nil, 362, nil, 362, nil, 362, nil, 362, - nil, nil, 362, 362, nil, 295, nil, 217, nil, 217, - 217, nil, 217, 217, nil, 217, nil, 217, nil, 217, - nil, 217, nil, nil, 217, 217, 295, nil, 295, 295, - nil, 295, 295, nil, 295, nil, 295, nil, 295, nil, - 295, nil, nil, 295, 295, 0, nil, 0, 0, nil, - 0, 0, nil, 0, nil, 0, nil, 0, nil, 0, - nil, nil, 0, 0 ] + 164, 164, 158, 154, 301, 27, 56, 27, 81, 214, + 285, 285, 301, 164, 164, 239, 293, 285, 18, 206, + 27, 213, 164, 164, 164, 164, 81, 206, 175, 175, + 194, 56, 175, 194, 175, 368, 368, 214, 214, 157, + 158, 293, 293, 158, 27, 154, 164, 164, 285, 144, + 164, 164, 164, 164, 164, 164, 18, 164, 164, 18, + 85, 175, 144, 158, 164, 175, 175, 272, 368, 175, + 83, 261, 368, 368, 175, 272, 368, 157, 175, 18, + 157, 368, 161, 161, 261, 368, 161, 216, 161, 175, + 1, 82, 356, 356, 1, 218, 368, 219, 203, 163, + 157, 1, 114, 272, 272, 272, 272, 272, 272, 203, + 272, 272, 163, 114, 203, 161, 122, 272, 114, 161, + 161, 122, 192, 161, 221, 356, 192, 192, 161, 356, + 356, 220, 161, 356, 290, 335, 335, 221, 356, 335, + 111, 335, 356, 161, 309, 290, 331, 331, 11, 309, + 290, 111, 11, 356, 329, 329, 111, 335, 329, 11, + 329, 48, 48, 103, 103, 48, 334, 48, 335, 334, + 103, 200, 335, 335, 262, 262, 335, 263, 263, 262, + 262, 335, 335, 48, 263, 335, 262, 329, 335, 224, + 280, 329, 329, 280, 48, 329, 335, 197, 48, 48, + 329, 103, 48, 227, 329, 295, 295, 48, 48, 87, + 229, 48, 307, 307, 48, 329, 307, 33, 307, 306, + 306, 33, 48, 306, 230, 306, 299, 299, 33, 33, + 225, 80, 232, 299, 225, 77, 46, 225, 295, 234, + 46, 225, 295, 295, 235, 307, 295, 46, 46, 307, + 307, 295, 306, 307, 75, 295, 306, 306, 307, 299, + 306, 212, 307, 299, 299, 306, 295, 299, 8, 306, + 23, 23, 299, 307, 23, 74, 299, 8, 8, 66, + 306, 249, 42, 252, 264, 264, 42, 299, 65, 166, + 166, 264, 23, 42, 42, 26, 26, 64, 89, 26, + 201, 26, 94, 23, 201, 201, 187, 23, 23, 169, + 101, 23, 102, 169, 169, 23, 23, 26, 105, 183, + 23, 53, 166, 52, 294, 294, 166, 166, 26, 50, + 166, 23, 26, 26, 166, 166, 26, 143, 106, 166, + 107, 26, 26, 29, 29, 26, 108, 29, 26, 29, + 166, 110, 279, 167, 167, 113, 26, 294, 115, 167, + 283, 294, 294, 281, 281, 294, 37, 211, 281, 281, + 294, 211, 211, 116, 294, 281, 29, 288, 170, 170, + 29, 29, 119, 32, 29, 294, 167, 121, 127, 29, + 167, 167, 297, 29, 167, 17, 287, 287, 133, 167, + 287, 170, 287, 167, 29, 3, 3, 3, 3, 304, + 13, 170, 12, 134, 167, 170, 170, 136, 320, 170, + 324, 172, 172, 170, 170, 172, 159, 172, 170, 287, + 140, 141, 155, 287, 287, 337, 342, 287, 346, 170, + 347, 349, 287, 172, 350, 351, 287, 45, 45, 5, + 357, 45, 142, 45, 172, 367, 147, 287, 172, 172, + 369, 2, 172, 4, 4, 4, 4, 172, 172, 45, + 146, 172, 379, 381, 172, nil, nil, 173, 173, nil, + 45, 173, 172, 173, 45, 45, nil, nil, 45, 31, + 31, 31, 31, 45, 45, nil, nil, 45, nil, 173, + 45, nil, nil, 47, 47, nil, nil, 47, 45, 47, + 173, nil, nil, nil, 173, 173, nil, nil, 173, 6, + 6, 6, 6, 173, 173, 47, nil, 173, nil, nil, + 173, nil, nil, 174, 174, nil, 47, 174, 173, 174, + 47, 47, nil, nil, 47, nil, nil, nil, nil, 47, + 47, nil, nil, 47, nil, 174, 47, nil, nil, 49, + 49, nil, nil, 49, 47, 49, 174, nil, nil, nil, + 174, 174, nil, nil, 174, nil, nil, 51, 51, 174, + 174, 51, nil, 174, 176, 176, 174, nil, 176, nil, + 176, nil, 49, nil, 174, nil, 49, 49, nil, nil, + 49, nil, nil, nil, nil, 49, 176, nil, nil, 49, + 51, nil, nil, nil, 51, 51, nil, 176, 51, nil, + 49, 176, 176, 51, nil, 176, nil, 51, nil, nil, + 176, 176, nil, nil, 176, 177, 177, 176, 51, 177, + nil, 177, nil, nil, nil, 176, nil, nil, nil, nil, + nil, nil, nil, nil, 112, 112, nil, 177, 112, nil, + 112, 259, 259, nil, nil, 259, nil, 259, 177, nil, + nil, nil, 177, 177, nil, nil, 177, nil, nil, 254, + 254, 177, 177, nil, nil, 177, nil, 112, 177, nil, + nil, 112, 112, nil, 259, 112, 177, nil, 259, 259, + 112, nil, 259, nil, 112, 70, 70, 259, nil, nil, + nil, 259, 254, nil, nil, 112, 254, 254, nil, nil, + 254, nil, 259, nil, nil, 254, 242, 242, 70, 254, + 242, nil, 242, nil, nil, nil, nil, nil, 70, nil, + 254, nil, 70, 70, nil, nil, 70, nil, 242, nil, + 70, 70, 71, 71, nil, 70, 71, nil, 71, 242, + nil, nil, nil, 242, 242, nil, 70, 242, nil, nil, + nil, nil, 242, 242, 71, nil, 242, 240, 240, 242, + nil, nil, nil, nil, nil, 71, nil, 242, nil, 71, + 71, nil, nil, 71, nil, nil, nil, nil, 71, 71, + 240, nil, 71, 178, 178, 71, nil, 178, nil, 178, + 240, nil, nil, 71, 240, 240, nil, nil, 240, nil, + nil, nil, 240, 240, nil, 178, nil, 240, 233, 233, + nil, nil, 233, nil, 233, nil, 178, nil, 240, nil, + 178, 178, 78, 78, 178, nil, 78, nil, 78, 178, + 178, nil, nil, 178, nil, nil, 178, nil, nil, nil, + nil, 233, nil, nil, 178, 233, 233, 231, 231, 233, + nil, 231, nil, 231, 233, 78, nil, nil, 233, 78, + 78, 228, 228, 78, nil, 228, nil, nil, 78, 233, + nil, nil, 78, nil, nil, nil, nil, nil, nil, nil, + 231, nil, nil, 78, 231, 231, nil, nil, 231, nil, + nil, 215, 215, 231, 228, nil, nil, 231, 228, 228, + nil, nil, 228, nil, nil, nil, nil, 228, 231, 179, + 179, 228, nil, 179, nil, 179, nil, nil, nil, nil, + nil, nil, 228, nil, 215, nil, nil, nil, 215, 215, + nil, 179, 215, nil, nil, nil, nil, 215, nil, 185, + 185, 215, 179, 185, nil, 185, 179, 179, nil, nil, + 179, nil, 215, nil, nil, 179, 179, nil, nil, 179, + nil, 185, 179, nil, nil, 181, 181, nil, nil, 181, + 179, 181, 185, nil, nil, nil, 185, 185, nil, nil, + 185, nil, nil, nil, nil, 185, 185, 181, nil, 185, + nil, nil, 185, nil, nil, 189, 189, nil, 181, 189, + 185, 189, 181, 181, nil, nil, 181, nil, nil, nil, + nil, 181, 181, nil, nil, 181, nil, 189, 181, nil, + nil, 90, 90, nil, nil, 90, 181, 90, 189, nil, + nil, nil, 189, 189, nil, nil, 189, nil, nil, nil, + nil, 189, 189, 90, nil, 189, nil, nil, 189, nil, + nil, 182, 182, nil, 90, 182, 189, 182, 90, 90, + nil, nil, 90, nil, nil, nil, nil, 90, 90, nil, + nil, 90, nil, 182, 90, nil, nil, 184, 184, nil, + nil, 184, 90, 184, 182, nil, nil, nil, 182, 182, + nil, nil, 182, nil, nil, nil, nil, 182, 182, 184, + nil, 182, nil, nil, 182, nil, nil, 95, 95, nil, + 184, 95, 182, 95, 184, 184, nil, nil, 184, nil, + nil, nil, nil, 184, 184, nil, nil, 184, nil, 95, + 184, nil, nil, 99, 99, nil, nil, 99, 184, 99, + 95, nil, nil, nil, 95, 95, nil, nil, 95, nil, + nil, nil, nil, 95, 95, 99, nil, 95, 100, 100, + 95, nil, 100, 100, 100, nil, 99, nil, 95, nil, + 99, 99, nil, nil, 99, nil, nil, nil, nil, 99, + 99, nil, nil, 99, 186, 186, 99, nil, 186, nil, + 186, 100, nil, nil, 99, 100, 100, nil, nil, 100, + nil, nil, nil, nil, 100, nil, 186, nil, 100, nil, + 180, 180, nil, nil, 180, nil, 180, 186, nil, 100, + nil, 186, 186, nil, nil, 186, nil, nil, nil, nil, + 186, 186, 180, nil, 186, nil, nil, 186, nil, nil, + nil, nil, nil, 180, nil, 186, nil, 180, 180, 91, + nil, 180, nil, nil, nil, nil, 180, 180, 91, 91, + 180, nil, nil, 180, nil, nil, nil, 91, 91, 91, + 91, 180, nil, 190, 190, nil, nil, nil, nil, nil, + nil, 190, 190, 190, 190, 190, nil, nil, nil, nil, + nil, 91, 91, nil, nil, 91, 91, 91, 91, 91, + 91, nil, 91, 91, nil, nil, 190, 190, nil, 91, + 190, 190, 190, 190, 190, 190, nil, 190, 190, 274, + 274, nil, nil, nil, 190, nil, nil, nil, 274, 274, + 274, 274, nil, nil, 132, 132, nil, nil, nil, nil, + nil, nil, nil, 132, 132, 132, 132, nil, nil, nil, + nil, nil, nil, nil, nil, nil, 274, 274, 274, 274, + 274, 274, nil, 274, 274, nil, nil, 132, 132, nil, + 274, 132, 132, 132, 132, 132, 132, nil, 132, 132, + 131, 131, nil, nil, nil, 132, nil, nil, nil, 131, + 131, 131, 131, nil, nil, 270, 270, nil, nil, nil, + nil, nil, nil, nil, 270, 270, 270, 270, nil, nil, + nil, nil, nil, 131, 131, nil, nil, 131, 131, 131, + 131, 131, 131, nil, 131, 131, nil, nil, nil, 270, + nil, 131, 270, 270, 270, 270, 270, 270, nil, 270, + 270, 129, 129, nil, nil, nil, 270, nil, nil, nil, + 129, 129, 129, 129, nil, nil, nil, 269, nil, 276, + 276, 276, 276, 276, 276, 269, 276, 276, nil, nil, + nil, nil, nil, 276, 129, 129, 275, nil, 129, 129, + 129, 129, 129, 129, 275, 129, 129, nil, nil, nil, + nil, 271, 129, 269, 269, 269, 269, 269, 269, 271, + 269, 269, nil, nil, nil, nil, nil, 269, nil, nil, + nil, nil, 275, 275, 275, 275, 275, 275, nil, 275, + 275, 188, nil, nil, nil, nil, 275, 271, 271, 271, + 271, 271, 271, nil, 271, 271, nil, nil, nil, nil, + 238, 271, 188, nil, 188, 188, nil, 188, 188, nil, + 188, nil, 188, nil, 188, nil, 188, nil, nil, 188, + 188, 238, 311, 238, 238, nil, 238, 238, nil, 238, + nil, 238, nil, 238, nil, 238, nil, nil, 238, 238, + nil, 375, nil, 311, nil, 311, 311, nil, 311, 311, + nil, 311, nil, 311, nil, 311, nil, 311, nil, nil, + 311, 311, 375, 372, 375, 375, nil, 375, 375, nil, + 375, nil, 375, nil, 375, nil, 375, nil, nil, 375, + 375, nil, 362, nil, 372, nil, 372, 372, nil, 372, + 372, nil, 372, nil, 372, nil, 372, nil, 372, nil, + nil, 372, 372, 362, 217, 362, 362, nil, 362, 362, + nil, 362, nil, 362, nil, 362, nil, 362, nil, nil, + 362, 362, nil, nil, nil, 217, nil, 217, 217, nil, + 217, 217, nil, 217, nil, 217, nil, 217, nil, 217, + nil, nil, 217, 217, 0, nil, 0, 0, nil, 0, + 0, nil, 0, nil, 0, nil, 0, nil, 0, nil, + nil, 0, 0, 20, nil, 20, 20, nil, 20, 20, + nil, 20, nil, 20, nil, 20, nil, 20, nil, nil, + 20, 20, 278, nil, 278, 278, nil, 278, 278, nil, + 278, nil, 278, nil, 278, nil, 278, nil, nil, 278, + 278, 267, 267, 267, 267, 267, 267, nil, 267, 267, + 266, 266, 266, 266, nil, 267, nil, 266, 266, 268, + 268, 268, 268, nil, 266, nil, 268, 268, nil, nil, + nil, nil, nil, 268 ] racc_action_pointer = [ - 1795, 163, 443, 413, 433, nil, nil, 3, 434, 420, - nil, nil, 142, nil, nil, nil, 398, 26, nil, 1483, - nil, nil, 80, 271, nil, nil, 297, nil, 367, 348, - 166, nil, nil, 375, 315, 277, 337, nil, nil, 501, - nil, nil, nil, 221, nil, nil, 557, 583, 608, 622, - 315, 329, 348, nil, nil, 4, nil, nil, nil, nil, - nil, nil, 97, 780, 298, -9, 309, 302, 275, nil, - nil, 286, nil, nil, 923, 966, nil, 279, 269, nil, - 6, 248, 1060, nil, 239, 245, -3, 177, nil, nil, - 149, 137, nil, nil, 1209, 10, nil, 1239, nil, nil, - 755, 121, 1137, 225, nil, 233, 3, 299, 301, 304, - nil, 1298, nil, nil, 322, 325, nil, nil, nil, 323, - 205, 331, 144, nil, 1313, nil, nil, 351, nil, nil, - 1359, 1374, 352, 344, nil, nil, 328, nil, 350, 364, - 361, nil, 362, 79, 374, nil, nil, nil, nil, nil, - nil, nil, -9, 408, 386, nil, 2, 452, 30, nil, - 251, nil, nil, 84, nil, 50, nil, nil, nil, nil, - nil, 174, 439, 436, -14, 381, 647, nil, 114, nil, - -4, 57, 75, 197, 172, nil, 1435, nil, 225, nil, - nil, nil, 363, nil, nil, 213, 215, 241, 323, 401, - 453, 527, 32, 673, 699, 729, 1265, 265, 806, 832, - 1070, 249, 1612, 1118, 1166, 270, nil, 1757, 24, 24, - 91, 121, nil, nil, 142, 1044, 126, 161, 1191, 147, - 1144, 198, 233, 238, 273, nil, nil, 1552, nil, 39, - nil, nil, nil, 66, 1017, 1001, nil, nil, 991, nil, - 270, nil, 273, 279, 948, nil, 904, nil, nil, nil, - nil, nil, nil, 451, nil, nil, nil, nil, 283, 850, - nil, nil, -5, nil, 308, nil, 857, 8, nil, 226, - 198, 67, nil, 466, 1073, 86, 172, 1420, 411, 1515, - nil, 1481, 1496, 456, nil, 1776, -4, 356, 443, nil, - 145, nil, nil, 1694, nil, 387, nil, 362, 129, nil, - nil, nil, nil, nil, nil, 380, nil, nil, nil, 1716, - nil, nil, nil, 1634, nil, nil, nil, 376, 383, nil, - 385, 392, 393, nil, nil, nil, nil, 410, nil, nil, - nil, 153, nil, 183, nil, nil, nil, nil, nil, 51, - nil, 128, 430, nil, nil, 110, 435, nil, nil, nil, - nil, nil, 1735, nil, nil, nil, nil, 439, 59, 445, - nil, nil, 1571, nil, 1653, nil, nil, nil, 1593, nil, - 1675, nil, nil, nil ] + 1674, 54, 417, 341, 399, 434, 455, nil, 262, nil, + nil, 112, 404, 402, nil, nil, nil, 395, 16, nil, + 1693, nil, nil, 268, nil, nil, 293, -1, nil, 341, + nil, 425, 381, 181, nil, nil, nil, 342, nil, nil, + nil, nil, 246, nil, nil, 445, 200, 501, 159, 557, + 305, 575, 283, 321, nil, nil, -6, nil, nil, nil, + nil, nil, nil, nil, 291, 265, 273, nil, nil, nil, + 703, 750, nil, nil, 269, 242, nil, 212, 840, nil, + 208, 2, 68, 64, nil, 37, nil, 186, nil, 275, + 1039, 1261, nil, nil, 279, 1125, nil, nil, nil, 1151, + 1176, 287, 289, 161, nil, 295, 315, 317, 323, nil, + 343, 116, 652, 315, 78, 350, 361, nil, nil, 374, + nil, 379, 81, nil, nil, nil, nil, 382, nil, 1444, + nil, 1383, 1337, 391, 376, nil, 394, nil, nil, nil, + 389, 408, 440, 314, 38, nil, 447, 436, nil, nil, + nil, nil, nil, nil, -8, 420, nil, 37, 0, 418, + nil, 80, nil, 87, -4, nil, 287, 351, nil, 302, + 376, nil, 419, 475, 531, 26, 582, 633, 801, 927, + 1228, 983, 1069, 256, 1095, 957, 1202, 243, 1532, 1013, + 1276, nil, 115, nil, 21, nil, nil, 186, nil, nil, + 131, 254, nil, 74, nil, nil, 1, nil, nil, nil, + nil, 360, 249, 10, -13, 909, 85, 1655, 80, 82, + 106, 112, nil, nil, 181, 194, nil, 194, 879, 170, + 215, 865, 192, 826, 199, 235, nil, nil, 1551, 8, + 775, nil, 724, nil, nil, nil, nil, nil, nil, 270, + nil, nil, 259, nil, 677, nil, nil, nil, nil, 659, + nil, 59, 118, 116, 223, nil, 1716, 1707, 1725, 1459, + 1398, 1493, 49, nil, 1322, 1478, 1425, nil, 1712, 343, + 159, 307, nil, 353, nil, 8, nil, 394, 365, nil, + 110, nil, nil, -9, 322, 203, nil, 383, nil, 224, + nil, -8, nil, nil, 400, nil, 217, 210, nil, 109, + nil, 1573, nil, nil, nil, nil, nil, nil, nil, nil, + 406, nil, nil, nil, 411, nil, nil, nil, nil, 152, + nil, 135, nil, nil, 135, 133, nil, 427, nil, nil, + nil, nil, 427, nil, nil, nil, 415, 417, nil, 418, + 421, 422, nil, nil, nil, nil, 90, 442, nil, nil, + nil, nil, 1633, nil, nil, nil, nil, 446, 33, 451, + nil, nil, 1614, nil, nil, 1592, nil, nil, nil, 463, + nil, 464, nil, nil, nil ] racc_action_default = [ - -196, -233, -233, -50, -233, -8, -9, -233, -233, -22, - -10, -187, -188, -11, -185, -12, -233, -233, -13, -1, - -14, -2, -233, -186, -15, -3, -233, -16, -5, -233, - -233, -17, -6, -233, -18, -7, -196, -188, -186, -233, - -51, -26, -27, -233, -24, -25, -233, -233, -233, -85, - -92, -196, -233, -195, -193, -196, -189, -191, -192, -221, - -194, -4, -196, -233, -85, -196, -53, -231, -42, -174, - -43, -213, -117, -33, -233, -233, -44, -31, -74, -32, - -233, -36, -233, -122, -37, -233, -73, -38, -172, -72, - -39, -40, -173, -41, -233, -103, -111, -233, -132, -112, - -233, -104, -233, -108, -110, -105, -233, -114, -106, -113, - -109, -233, -125, -107, -233, -233, -49, -175, -176, -178, - -233, -233, -197, -198, -83, -19, -22, -186, -21, -23, - -82, -84, -233, -75, -86, -81, -70, -74, -76, -219, - -79, -68, -77, -73, -233, -171, -170, -80, -78, -90, - -91, -93, -233, -219, -196, 384, -233, -233, -233, -207, - -233, -57, -213, -196, -59, -233, -66, -65, -56, -73, - -95, -233, -219, -233, -233, -92, -233, -30, -233, -118, - -233, -233, -233, -233, -233, -142, -233, -149, -233, -216, - -229, -225, -233, -228, -224, -233, -233, -233, -233, -233, - -233, -233, -233, -233, -233, -233, -233, -233, -233, -233, - -233, -233, -233, -233, -233, -233, -20, -233, -206, -233, - -204, -233, -201, -230, -233, -71, -220, -233, -233, -85, - -233, -220, -233, -233, -233, -209, -190, -233, -208, -233, - -54, -62, -61, -233, -233, -233, -217, -218, -233, -124, - -233, -55, -219, -233, -233, -28, -233, -120, -119, -35, - -34, -168, -166, -233, -169, -160, -167, -161, -73, -233, - -123, -116, -233, -152, -218, -214, -233, -233, -222, -137, - -139, -138, -133, -140, -144, -141, -146, -151, -148, -145, - -134, -150, -147, -143, -135, -233, -128, -136, -233, -154, - -233, -158, -177, -233, -180, -233, -199, -233, -233, -200, - -45, -69, -87, -46, -88, -219, -89, -94, -48, -233, - -211, -210, -212, -233, -184, -58, -60, -97, -98, -63, - -102, -99, -100, -101, -64, -96, -47, -233, -232, -29, - -121, -233, -163, -219, -115, -215, -227, -226, -223, -128, - -127, -233, -233, -155, -153, -233, -233, -179, -205, -203, - -202, -67, -233, -182, -183, -52, -165, -218, -233, -233, - -126, -129, -233, -159, -233, -181, -164, -162, -233, -131, - -233, -157, -130, -156 ] + -197, -234, -51, -19, -8, -234, -234, -9, -234, -10, + -188, -189, -234, -23, -11, -186, -12, -234, -234, -13, + -1, -14, -2, -187, -15, -3, -234, -234, -16, -234, + -17, -6, -234, -234, -18, -7, -189, -197, -187, -52, + -27, -28, -234, -25, -26, -234, -234, -234, -234, -234, + -197, -86, -93, -234, -196, -194, -197, -190, -192, -193, + -222, -195, -4, -42, -232, -43, -214, -175, -118, -44, + -234, -234, -45, -34, -75, -32, -33, -234, -234, -123, + -37, -74, -38, -234, -73, -39, -173, -40, -174, -41, + -234, -234, -126, -108, -104, -234, -112, -133, -113, -234, + -234, -105, -109, -234, -111, -106, -115, -107, -114, -110, + -54, -197, -234, -86, -197, -234, -179, -176, -177, -234, + -50, -234, -198, -199, -24, -21, -23, -187, -22, -84, + -20, -83, -85, -234, -197, -79, -76, -87, -82, -75, + -71, -77, -220, -80, -74, -69, -78, -234, -172, -171, + -81, -91, -92, -94, -234, -220, 385, -234, -234, -234, + -208, -234, -31, -234, -234, -119, -234, -234, -96, -234, + -234, -143, -234, -234, -234, -234, -234, -234, -234, -234, + -234, -234, -234, -234, -234, -234, -234, -234, -234, -234, + -234, -150, -234, -217, -234, -230, -226, -234, -229, -225, + -93, -234, -214, -197, -58, -60, -234, -67, -57, -74, + -66, -234, -220, -234, -234, -234, -234, -234, -207, -205, + -234, -234, -202, -231, -234, -234, -210, -234, -72, -221, + -234, -234, -86, -234, -221, -234, -191, -209, -234, -234, + -234, -29, -234, -121, -120, -36, -35, -169, -167, -234, + -170, -161, -74, -168, -234, -162, -218, -219, -124, -234, + -117, -234, -138, -140, -139, -134, -141, -145, -142, -147, + -152, -149, -146, -135, -151, -148, -144, -136, -5, -234, + -129, -137, -153, -219, -215, -234, -223, -234, -220, -55, + -234, -63, -62, -234, -234, -234, -125, -234, -56, -234, + -155, -234, -159, -178, -234, -181, -234, -234, -200, -234, + -201, -234, -212, -213, -211, -46, -70, -88, -47, -89, + -220, -90, -95, -49, -234, -185, -233, -30, -122, -234, + -164, -220, -97, -116, -129, -234, -128, -234, -216, -227, + -224, -228, -234, -59, -61, -102, -98, -99, -64, -103, + -100, -101, -65, -48, -156, -154, -234, -234, -180, -206, + -204, -203, -234, -183, -68, -184, -166, -219, -234, -234, + -127, -130, -234, -53, -160, -234, -182, -165, -163, -234, + -132, -234, -158, -131, -157 ] racc_goto_table = [ - 22, 9, 68, 112, 53, 118, 61, 36, 91, 222, - 19, 267, 70, 93, 2, 227, 139, 191, 51, 22, - 9, 179, 77, 56, 73, 149, 21, 141, 133, 232, - 115, 172, 153, 2, 146, 263, 125, 116, 135, 148, - 147, 299, 129, 22, 126, 260, 160, 350, 250, 174, - 128, 171, 43, 68, 121, 329, 334, 298, 368, 91, - 258, 265, 123, 70, 93, 317, 343, 301, 136, 154, - 183, 119, 224, 178, 233, 73, 55, 123, 157, 66, - 238, 159, 120, 219, 221, 190, 325, 321, 195, 16, - 188, nil, nil, nil, nil, nil, nil, nil, 342, nil, - 370, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, 216, nil, nil, nil, nil, 260, 129, - 22, 126, 263, nil, nil, 353, nil, 128, 337, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, 81, - nil, nil, nil, 53, nil, 53, nil, 243, nil, nil, - 149, 301, nil, nil, nil, nil, nil, 252, nil, nil, - 68, 261, 236, 68, nil, 138, 91, 146, nil, 91, - 70, 93, nil, 70, 93, nil, nil, nil, 166, nil, - 235, 166, 259, 272, nil, 73, nil, 302, 347, nil, - 81, 361, nil, 261, 290, 360, 315, 376, 294, 146, - nil, 312, 340, 311, 133, nil, 149, nil, 373, nil, - 146, nil, 22, 9, 135, 148, 147, 22, 9, 369, - nil, 263, 295, 327, 327, nil, 2, 303, nil, 146, - 146, 2, nil, 68, 333, 333, nil, 22, 9, 91, - 320, 88, nil, 70, 93, nil, nil, 323, 261, nil, - nil, 2, nil, nil, 146, 259, 190, nil, nil, nil, - nil, nil, nil, nil, nil, nil, nil, 88, nil, nil, - nil, nil, nil, nil, nil, 87, nil, 261, nil, 166, - nil, nil, 61, 146, nil, nil, nil, nil, nil, nil, - 61, nil, 88, nil, nil, 22, 9, 81, 262, nil, - 81, 142, nil, 22, 9, nil, nil, nil, nil, 2, - 61, nil, nil, nil, nil, nil, nil, 2, nil, 22, - 9, nil, nil, 22, 9, nil, 87, nil, 371, 362, - 262, nil, nil, 2, 261, nil, nil, 2, nil, nil, - 146, 138, nil, nil, nil, nil, nil, 261, nil, 61, - nil, nil, nil, 146, nil, 166, nil, nil, nil, nil, - 328, 328, 22, 9, 114, 61, nil, 61, nil, 84, - 81, nil, 22, 9, 22, 9, 2, 90, 22, 9, - 22, 9, 378, 132, 380, 262, 2, nil, 2, nil, - nil, nil, 2, nil, 2, 140, nil, nil, 170, 88, - 88, nil, 88, 145, nil, nil, nil, nil, 167, nil, - nil, 167, nil, nil, 262, nil, nil, 170, nil, nil, - 84, nil, nil, nil, nil, nil, nil, nil, 90, nil, - nil, nil, 88, 87, 266, nil, 87, 170, nil, nil, - nil, nil, nil, 88, nil, nil, nil, nil, nil, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, 88, 88, nil, nil, 266, nil, nil, nil, - nil, 262, 88, nil, nil, nil, nil, 142, nil, nil, - nil, nil, nil, nil, 262, nil, nil, 88, nil, nil, - nil, nil, nil, nil, nil, nil, 331, 331, nil, nil, - nil, nil, nil, nil, nil, nil, 87, nil, nil, 167, - nil, 253, nil, nil, nil, nil, 88, nil, nil, nil, - nil, 266, nil, nil, nil, nil, nil, 84, 264, nil, - 84, nil, nil, nil, 282, 90, 145, nil, 90, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - 266, nil, nil, nil, nil, nil, nil, nil, nil, nil, - 264, nil, nil, 314, nil, 316, nil, 124, 145, nil, - nil, 140, nil, 88, 130, 131, nil, nil, nil, 145, - nil, nil, nil, 335, nil, 167, 88, nil, nil, nil, - 330, 330, nil, nil, nil, nil, nil, nil, 332, 332, - 84, nil, nil, 180, nil, nil, nil, 266, 90, nil, - nil, 346, nil, nil, nil, 264, nil, nil, nil, nil, - 266, nil, 185, 145, nil, 186, nil, nil, 187, nil, + 27, 13, 5, 37, 62, 255, 249, 20, 118, 196, + 92, 89, 142, 50, 155, 300, 69, 63, 222, 336, + 27, 13, 5, 165, 73, 75, 57, 279, 348, 352, + 246, 151, 145, 119, 343, 150, 121, 230, 65, 149, + 299, 22, 27, 126, 138, 135, 27, 126, 201, 134, + 235, 214, 120, 87, 302, 86, 304, 244, 89, 42, + 169, 128, 46, 69, 63, 128, 136, 251, 368, 331, + 322, 73, 163, 370, 212, 125, 124, 324, 123, 130, + 124, 148, 192, 86, 116, 65, 140, 224, 56, 159, + 227, 123, 330, 249, 211, 237, 220, 160, 221, 354, + 87, 110, 86, 115, 246, 314, 194, 297, 17, nil, + nil, nil, nil, nil, nil, nil, nil, nil, 195, nil, + nil, nil, nil, 133, nil, nil, nil, nil, nil, nil, + nil, nil, nil, nil, 54, nil, nil, nil, 302, nil, + 293, nil, nil, nil, nil, nil, nil, nil, nil, nil, + nil, nil, 168, nil, 89, 149, nil, nil, 89, 69, + 63, nil, 288, 69, 63, 236, nil, 245, nil, nil, + nil, 73, 261, 82, 168, 226, nil, nil, nil, 151, + nil, 65, 247, 342, nil, 65, 168, nil, 27, 13, + 5, 339, 303, 320, 328, 374, 87, 148, 86, 86, + 87, 143, 86, 149, 80, 361, 377, 249, 317, 316, + nil, 379, 150, 151, 381, 364, 149, 27, 13, 5, + 82, 138, 135, nil, nil, nil, 369, 312, 89, nil, + 247, nil, 141, 69, 63, 239, nil, nil, 27, 13, + 5, 245, 149, 136, nil, 148, nil, 86, nil, 265, + nil, 80, nil, nil, nil, 65, nil, nil, 148, nil, + 86, 210, 62, nil, 210, nil, nil, nil, 85, 247, + 87, nil, 86, 54, 54, nil, nil, nil, 27, 13, + 5, nil, 149, 149, 148, nil, 86, 149, 345, 345, + nil, nil, 207, nil, nil, 207, 146, nil, nil, 273, + 195, nil, nil, 277, nil, 319, nil, 321, nil, 346, + 346, 27, 13, 5, 247, 85, 82, 250, 362, 371, + 82, nil, nil, nil, 351, 351, 86, 86, nil, 148, + nil, 86, nil, 332, nil, nil, nil, nil, nil, nil, + nil, nil, nil, nil, 149, nil, 62, 80, 248, nil, + nil, 80, nil, 210, nil, nil, 149, nil, nil, nil, + nil, 341, 27, 13, 5, 250, nil, nil, nil, nil, + nil, 247, 27, 13, 5, 27, 13, 5, 143, nil, + 359, 360, nil, 247, 207, nil, 148, nil, 86, nil, + 82, nil, 129, nil, 131, 132, 248, nil, 148, nil, + 86, nil, nil, 366, 250, nil, nil, nil, nil, 141, + nil, 85, 253, nil, nil, 85, nil, nil, 164, nil, + nil, 80, nil, nil, nil, nil, nil, nil, nil, nil, + nil, nil, nil, nil, nil, 248, nil, 171, nil, nil, + 210, nil, 190, nil, 349, 349, 191, nil, nil, 250, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - 358, nil, 359, nil, 264, nil, nil, nil, nil, nil, - nil, nil, 145, nil, nil, nil, nil, nil, nil, nil, + 253, nil, nil, nil, nil, nil, nil, nil, nil, nil, + nil, 207, nil, 146, nil, 347, 347, nil, nil, nil, + 248, nil, nil, nil, nil, 85, nil, nil, nil, nil, + nil, nil, nil, nil, nil, nil, nil, nil, nil, 253, + nil, nil, nil, nil, nil, nil, 250, nil, nil, nil, + nil, nil, nil, nil, nil, nil, nil, nil, 250, 262, + 263, 264, nil, 266, 267, 268, 269, 270, 271, 272, + nil, 274, 275, 276, nil, nil, 281, 248, nil, 350, + 350, nil, nil, nil, 253, nil, nil, nil, nil, 248, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, nil, nil, nil, 366, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, 264, nil, nil, nil, nil, nil, nil, nil, 145, - nil, nil, nil, nil, 264, nil, nil, nil, nil, nil, - nil, nil, 145, nil, 279, 280, 281, nil, 283, 284, - 285, 286, 287, 288, 289, nil, 291, 292, 293, nil, - nil, 297, nil, nil, nil, nil, nil, nil, nil, nil, + nil, nil, nil, nil, nil, nil, nil, nil, nil, 164, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, nil, 180 ] + nil, 253, nil, nil, nil, nil, nil, nil, nil, nil, + nil, nil, nil, 253 ] racc_goto_check = [ - 37, 21, 30, 62, 64, 72, 4, 32, 28, 82, - 2, 70, 31, 29, 52, 36, 35, 85, 32, 37, - 21, 60, 22, 78, 21, 53, 3, 47, 30, 36, - 37, 35, 38, 52, 28, 68, 19, 5, 31, 29, - 50, 66, 7, 37, 21, 23, 41, 63, 36, 41, - 5, 57, 20, 30, 74, 46, 46, 65, 58, 28, - 61, 69, 3, 31, 29, 56, 71, 68, 33, 74, - 57, 73, 34, 22, 75, 21, 76, 3, 77, 40, - 79, 3, 20, 80, 81, 30, 42, 83, 84, 1, - 57, nil, nil, nil, nil, nil, nil, nil, 70, nil, - 63, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, 19, nil, nil, nil, nil, 23, 7, - 37, 21, 68, nil, nil, 66, nil, 5, 36, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, 24, - nil, nil, nil, 64, nil, 64, nil, 41, nil, nil, - 53, 68, nil, nil, nil, nil, nil, 38, nil, nil, - 30, 30, 78, 30, nil, 24, 28, 28, nil, 28, - 31, 29, nil, 31, 29, nil, nil, nil, 24, nil, - 3, 24, 21, 22, nil, 21, nil, 72, 85, nil, - 24, 36, nil, 30, 64, 82, 35, 70, 64, 28, - nil, 53, 60, 47, 30, nil, 53, nil, 68, nil, - 28, nil, 37, 21, 31, 29, 50, 37, 21, 36, - nil, 68, 2, 30, 30, nil, 52, 2, nil, 28, - 28, 52, nil, 30, 29, 29, nil, 37, 21, 28, - 32, 49, nil, 31, 29, nil, nil, 2, 30, nil, - nil, 52, nil, nil, 28, 21, 30, nil, nil, nil, - nil, nil, nil, nil, nil, nil, nil, 49, nil, nil, - nil, nil, nil, nil, nil, 26, nil, 30, nil, 24, - nil, nil, 4, 28, nil, nil, nil, nil, nil, nil, - 4, nil, 49, nil, nil, 37, 21, 24, 24, nil, - 24, 26, nil, 37, 21, nil, nil, nil, nil, 52, - 4, nil, nil, nil, nil, nil, nil, 52, nil, 37, - 21, nil, nil, 37, 21, nil, 26, nil, 62, 2, - 24, nil, nil, 52, 30, nil, nil, 52, nil, nil, - 28, 24, nil, nil, nil, nil, nil, 30, nil, 4, - nil, nil, nil, 28, nil, 24, nil, nil, nil, nil, - 24, 24, 37, 21, 54, 4, nil, 4, nil, 25, - 24, nil, 37, 21, 37, 21, 52, 27, 37, 21, - 37, 21, 2, 54, 2, 24, 52, nil, 52, nil, - nil, nil, 52, nil, 52, 25, nil, nil, 54, 49, - 49, nil, 49, 27, nil, nil, nil, nil, 25, nil, - nil, 25, nil, nil, 24, nil, nil, 54, nil, nil, - 25, nil, nil, nil, nil, nil, nil, nil, 27, nil, - nil, nil, 49, 26, 26, nil, 26, 54, nil, nil, - nil, nil, nil, 49, nil, nil, nil, nil, nil, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, 49, 49, nil, nil, 26, nil, nil, nil, - nil, 24, 49, nil, nil, nil, nil, 26, nil, nil, - nil, nil, nil, nil, 24, nil, nil, 49, nil, nil, - nil, nil, nil, nil, nil, nil, 26, 26, nil, nil, - nil, nil, nil, nil, nil, nil, 26, nil, nil, 25, - nil, 54, nil, nil, nil, nil, 49, nil, nil, nil, - nil, 26, nil, nil, nil, nil, nil, 25, 25, nil, - 25, nil, nil, nil, 54, 27, 27, nil, 27, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - 26, nil, nil, nil, nil, nil, nil, nil, nil, nil, - 25, nil, nil, 54, nil, 54, nil, 51, 27, nil, - nil, 25, nil, 49, 51, 51, nil, nil, nil, 27, - nil, nil, nil, 54, nil, 25, 49, nil, nil, nil, - 25, 25, nil, nil, nil, nil, nil, nil, 27, 27, - 25, nil, nil, 51, nil, nil, nil, 26, 27, nil, - nil, 54, nil, nil, nil, 25, nil, nil, nil, nil, - 26, nil, 51, 27, nil, 51, nil, nil, 51, nil, + 38, 22, 53, 33, 4, 71, 69, 2, 73, 86, + 63, 29, 36, 33, 39, 67, 32, 30, 83, 64, + 38, 22, 53, 61, 22, 23, 79, 5, 47, 47, + 24, 54, 48, 38, 43, 51, 75, 37, 31, 29, + 66, 3, 38, 22, 32, 30, 38, 22, 42, 75, + 37, 42, 6, 28, 69, 50, 5, 62, 29, 21, + 58, 6, 21, 32, 30, 6, 31, 70, 59, 72, + 57, 22, 23, 64, 36, 20, 8, 5, 3, 20, + 8, 28, 58, 50, 74, 31, 34, 76, 77, 78, + 35, 3, 71, 69, 58, 80, 81, 3, 82, 67, + 28, 41, 50, 55, 24, 84, 85, 37, 1, nil, + nil, nil, nil, nil, nil, nil, nil, nil, 31, nil, + nil, nil, nil, 55, nil, nil, nil, nil, nil, nil, + nil, nil, nil, nil, 65, nil, nil, nil, 69, nil, + 42, nil, nil, nil, nil, nil, nil, nil, nil, nil, + nil, nil, 55, nil, 29, 29, nil, nil, 29, 32, + 30, nil, 39, 32, 30, 79, nil, 22, nil, nil, + nil, 22, 23, 26, 55, 3, nil, nil, nil, 54, + nil, 31, 31, 37, nil, 31, 55, nil, 38, 22, + 53, 86, 73, 36, 61, 69, 28, 28, 50, 50, + 28, 26, 50, 29, 25, 83, 71, 69, 54, 48, + nil, 5, 51, 54, 5, 37, 29, 38, 22, 53, + 26, 32, 30, nil, nil, nil, 37, 33, 29, nil, + 31, nil, 25, 32, 30, 55, nil, nil, 38, 22, + 53, 22, 29, 31, nil, 28, nil, 50, nil, 55, + nil, 25, nil, nil, nil, 31, nil, nil, 28, nil, + 50, 26, 4, nil, 26, nil, nil, nil, 27, 31, + 28, nil, 50, 65, 65, nil, nil, nil, 38, 22, + 53, nil, 29, 29, 28, nil, 50, 29, 30, 30, + nil, nil, 25, nil, nil, 25, 27, nil, nil, 65, + 31, nil, nil, 65, nil, 55, nil, 55, nil, 31, + 31, 38, 22, 53, 31, 27, 26, 26, 2, 63, + 26, nil, nil, nil, 28, 28, 50, 50, nil, 28, + nil, 50, nil, 55, nil, nil, nil, nil, nil, nil, + nil, nil, nil, nil, 29, nil, 4, 25, 25, nil, + nil, 25, nil, 26, nil, nil, 29, nil, nil, nil, + nil, 55, 38, 22, 53, 26, nil, nil, nil, nil, + nil, 31, 38, 22, 53, 38, 22, 53, 26, nil, + 55, 55, nil, 31, 25, nil, 28, nil, 50, nil, + 26, nil, 52, nil, 52, 52, 25, nil, 28, nil, + 50, nil, nil, 55, 26, nil, nil, nil, nil, 25, + nil, 27, 27, nil, nil, 27, nil, nil, 52, nil, + nil, 25, nil, nil, nil, nil, nil, nil, nil, nil, + nil, nil, nil, nil, nil, 25, nil, 52, nil, nil, + 26, nil, 52, nil, 26, 26, 52, nil, nil, 26, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - 54, nil, 54, nil, 25, nil, nil, nil, nil, nil, - nil, nil, 27, nil, nil, nil, nil, nil, nil, nil, + 27, nil, nil, nil, nil, nil, nil, nil, nil, nil, + nil, 25, nil, 27, nil, 25, 25, nil, nil, nil, + 25, nil, nil, nil, nil, 27, nil, nil, nil, nil, + nil, nil, nil, nil, nil, nil, nil, nil, nil, 27, + nil, nil, nil, nil, nil, nil, 26, nil, nil, nil, + nil, nil, nil, nil, nil, nil, nil, nil, 26, 52, + 52, 52, nil, 52, 52, 52, 52, 52, 52, 52, + nil, 52, 52, 52, nil, nil, 52, 25, nil, 27, + 27, nil, nil, nil, 27, nil, nil, nil, nil, 25, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, nil, nil, nil, 54, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, 25, nil, nil, nil, nil, nil, nil, nil, 27, - nil, nil, nil, nil, 25, nil, nil, nil, nil, nil, - nil, nil, 27, nil, 51, 51, 51, nil, 51, 51, - 51, 51, 51, 51, 51, nil, 51, 51, 51, nil, - nil, 51, nil, nil, nil, nil, nil, nil, nil, nil, + nil, nil, nil, nil, nil, nil, nil, nil, nil, 52, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, nil, 51 ] + nil, 27, nil, nil, nil, nil, nil, nil, nil, nil, + nil, nil, nil, 27 ] racc_goto_pointer = [ - nil, 89, 10, 26, -13, 7, nil, -1, nil, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, -7, - 48, 1, -1, -136, 116, 346, 252, 354, -15, -10, - -21, -11, 6, 19, -64, -33, -124, 0, -18, nil, - 57, -16, -153, nil, nil, nil, -189, -22, nil, 218, - -9, 528, 14, -25, 335, nil, -166, -12, -285, nil, - -54, -120, -23, -249, -13, -157, -173, nil, -147, -121, - -171, -203, -28, 38, 18, -80, 59, 23, 6, -78, - -39, -38, -113, -147, -18, -89, nil ] + nil, 108, 7, 41, -16, -161, 19, nil, 34, nil, + nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, + 33, 56, 1, 2, -136, 181, 150, 245, 30, -12, + -6, 15, -7, 2, 35, -50, -39, -105, 0, -38, + nil, 74, -63, -256, nil, nil, nil, -266, -19, nil, + 32, -16, 347, 2, -21, 74, nil, -164, -18, -263, + nil, -48, -107, -16, -261, 116, -175, -200, nil, -161, + -100, -162, -185, -24, 52, -1, -47, 70, 33, 8, + -63, -26, -24, -104, -120, 3, -94, nil ] racc_goto_default = [ - nil, nil, nil, 168, 25, 28, 32, 35, 5, 6, - 10, 13, 15, 18, 20, 24, 27, 31, 34, 4, - nil, 99, nil, 79, 101, 103, 105, 108, 109, 113, - 95, 96, 8, nil, nil, nil, nil, 85, nil, 30, - nil, nil, 161, 239, 164, 165, nil, nil, 144, 107, - 110, 111, 67, 134, 98, 150, 151, nil, 248, 104, - nil, nil, nil, nil, 69, nil, nil, 300, 80, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, 57, - nil, nil, nil, nil, nil, nil, 192 ] + nil, nil, 278, 208, 25, nil, 31, 35, 4, 7, + 9, 14, 16, 19, 21, 24, 28, 30, 34, 3, + 6, nil, 98, nil, 76, 101, 102, 105, 107, 108, + 93, 94, 96, 12, nil, nil, nil, nil, 83, nil, + 33, nil, nil, 204, 290, 205, 206, nil, nil, 147, + 106, 109, 91, 64, 137, 97, 152, 153, nil, 259, + 104, nil, nil, nil, nil, 67, nil, nil, 301, 77, + nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, + 58, nil, nil, nil, nil, nil, nil, 197 ] racc_token_table = { false => 0, Object.new => 1, :STRING => 2, :DQPRE => 3, :DQMID => 4, :DQPOST => 5, :LBRACK => 6, :RBRACK => 7, :LBRACE => 8, :RBRACE => 9, :SYMBOL => 10, :FARROW => 11, :COMMA => 12, :TRUE => 13, :FALSE => 14, :EQUALS => 15, :APPENDS => 16, :LESSEQUAL => 17, :NOTEQUAL => 18, :DOT => 19, :COLON => 20, :LLCOLLECT => 21, :RRCOLLECT => 22, :QMARK => 23, :LPAREN => 24, :RPAREN => 25, :ISEQUAL => 26, :GREATEREQUAL => 27, :GREATERTHAN => 28, :LESSTHAN => 29, :IF => 30, :ELSE => 31, :IMPORT => 32, :DEFINE => 33, :ELSIF => 34, :VARIABLE => 35, :CLASS => 36, :INHERITS => 37, :NODE => 38, :BOOLEAN => 39, :NAME => 40, :SEMIC => 41, :CASE => 42, :DEFAULT => 43, :AT => 44, :LCOLLECT => 45, :RCOLLECT => 46, :CLASSNAME => 47, :CLASSREF => 48, :NOT => 49, :OR => 50, :AND => 51, :UNDEF => 52, :PARROW => 53, :PLUS => 54, :MINUS => 55, :TIMES => 56, :DIV => 57, :LSHIFT => 58, :RSHIFT => 59, :UMINUS => 60, :MATCH => 61, :NOMATCH => 62, :REGEX => 63, :IN_EDGE => 64, :OUT_EDGE => 65, :IN_EDGE_SUB => 66, :OUT_EDGE_SUB => 67, :IN => 68 } racc_use_result_var = true racc_nt_base = 69 Racc_arg = [ racc_action_table, racc_action_check, racc_action_default, racc_action_pointer, racc_goto_table, racc_goto_check, racc_goto_default, racc_goto_pointer, racc_nt_base, racc_reduce_table, racc_token_table, racc_shift_n, racc_reduce_n, racc_use_result_var ] Racc_token_to_s_table = [ '$end', 'error', 'STRING', 'DQPRE', 'DQMID', 'DQPOST', 'LBRACK', 'RBRACK', 'LBRACE', 'RBRACE', 'SYMBOL', 'FARROW', 'COMMA', 'TRUE', 'FALSE', 'EQUALS', 'APPENDS', 'LESSEQUAL', 'NOTEQUAL', 'DOT', 'COLON', 'LLCOLLECT', 'RRCOLLECT', 'QMARK', 'LPAREN', 'RPAREN', 'ISEQUAL', 'GREATEREQUAL', 'GREATERTHAN', 'LESSTHAN', 'IF', 'ELSE', 'IMPORT', 'DEFINE', 'ELSIF', 'VARIABLE', 'CLASS', 'INHERITS', 'NODE', 'BOOLEAN', 'NAME', 'SEMIC', 'CASE', 'DEFAULT', 'AT', 'LCOLLECT', 'RCOLLECT', 'CLASSNAME', 'CLASSREF', 'NOT', 'OR', 'AND', 'UNDEF', 'PARROW', 'PLUS', 'MINUS', 'TIMES', 'DIV', 'LSHIFT', 'RSHIFT', 'UMINUS', 'MATCH', 'NOMATCH', 'REGEX', 'IN_EDGE', 'OUT_EDGE', 'IN_EDGE_SUB', 'OUT_EDGE_SUB', 'IN', '$start', 'program', -'statements', +'statements_and_declarations', 'nil', -'statement', +'statement_or_declaration', +'statements', 'resource', 'virtualresource', 'collection', 'assignment', 'casestatement', 'ifstatement_begin', 'import', 'fstatement', 'definition', 'hostclass', 'nodedef', 'resourceoverride', 'append', 'relationship', 'relationship_side', 'edge', 'resourceref', 'funcvalues', 'namestring', 'name', 'variable', 'type', 'boolean', 'funcrvalue', 'selector', 'quotedtext', 'hasharrayaccesses', 'classname', 'resourceinstances', 'endsemi', 'params', 'endcomma', 'classref', 'anyparams', 'at', 'collectrhand', 'collstatements', 'collstatement', 'colljoin', 'collexpr', 'colllval', 'simplervalue', 'resourceinst', 'resourcename', 'undef', 'array', 'expression', 'hasharrayaccess', 'param', 'rvalue', 'addparam', 'anyparam', 'rvalues', 'comma', 'hash', 'dqrval', 'dqtail', 'ifstatement', 'else', 'regex', 'caseopts', 'caseopt', 'casevalues', 'selectlhand', 'svalues', 'selectval', 'sintvalues', 'string', 'strings', 'argumentlist', 'classparent', 'hostnames', 'nodeparent', 'nodename', 'hostname', 'nothing', 'arguments', 'argument', 'classnameordefault', 'hashpairs', 'hashpair', 'key'] Racc_debug_parser = false ##### racc system variables end ##### # reduce 0 omitted -module_eval <<'.,.,', 'grammar.ra', 46 - def _reduce_1( val, _values, result ) - if val[0] - # Make sure we always return an array. - if val[0].is_a?(AST::ASTArray) - if val[0].children.empty? - result = nil - else - result = val[0] - end - else - result = aryfy(val[0]) - end - else - result = nil - end - result - end -.,., + # reduce 1 omitted # reduce 2 omitted - # reduce 3 omitted +module_eval <<'.,.,', 'grammar.ra', 36 + def _reduce_3( val, _values, result ) + result = ast AST::ASTArray, :children => (val[0] ? [val[0]] : []) + result + end +.,., -module_eval <<'.,.,', 'grammar.ra', 62 +module_eval <<'.,.,', 'grammar.ra', 42 def _reduce_4( val, _values, result ) - if val[0] and val[1] - if val[0].instance_of?(AST::ASTArray) - val[0].push(val[1]) - result = val[0] - else - result = ast AST::ASTArray, :children => [val[0],val[1]] - end - elsif obj = (val[0] || val[1]) - result = obj - else result = nil + if val[1] + val[0].push(val[1]) end + result = val[0] result end .,., - # reduce 5 omitted +module_eval <<'.,.,', 'grammar.ra', 54 + def _reduce_5( val, _values, result ) + val[0].each do |stmt| + if stmt.is_a?(AST::TopLevelConstruct) + error "Classes, definitions, and nodes may only appear at toplevel or inside other classes", \ + :line => stmt.context[:line], :file => stmt.context[:file] + end + end + result = val[0] + result + end +.,., # reduce 6 omitted # reduce 7 omitted # reduce 8 omitted # reduce 9 omitted # reduce 10 omitted # reduce 11 omitted # reduce 12 omitted # reduce 13 omitted # reduce 14 omitted # reduce 15 omitted # reduce 16 omitted # reduce 17 omitted # reduce 18 omitted -module_eval <<'.,.,', 'grammar.ra', 82 - def _reduce_19( val, _values, result ) - result = AST::Relationship.new(val[0], val[2], val[1][:value], ast_context) + # reduce 19 omitted + +module_eval <<'.,.,', 'grammar.ra', 74 + def _reduce_20( val, _values, result ) + result = AST::Relationship.new(val[0], val[2], val[1][:value], ast_context) result end .,., -module_eval <<'.,.,', 'grammar.ra', 85 - def _reduce_20( val, _values, result ) +module_eval <<'.,.,', 'grammar.ra', 77 + def _reduce_21( val, _values, result ) result = AST::Relationship.new(val[0], val[2], val[1][:value], ast_context) result end .,., - # reduce 21 omitted - # reduce 22 omitted # reduce 23 omitted # reduce 24 omitted # reduce 25 omitted # reduce 26 omitted # reduce 27 omitted -module_eval <<'.,.,', 'grammar.ra', 98 - def _reduce_28( val, _values, result ) - args = aryfy(val[2]) - result = ast AST::Function, - :name => val[0][:value], - :line => val[0][:line], - :arguments => args, - :ftype => :statement - result - end -.,., + # reduce 28 omitted -module_eval <<'.,.,', 'grammar.ra', 106 +module_eval <<'.,.,', 'grammar.ra', 89 def _reduce_29( val, _values, result ) - args = aryfy(val[2]) - result = ast AST::Function, - :name => val[0][:value], - :line => val[0][:line], - :arguments => args, - :ftype => :statement + result = ast AST::Function, + :name => val[0][:value], + :line => val[0][:line], + :arguments => val[2], + :ftype => :statement result end .,., -module_eval <<'.,.,', 'grammar.ra', 112 +module_eval <<'.,.,', 'grammar.ra', 96 def _reduce_30( val, _values, result ) - result = ast AST::Function, - :name => val[0][:value], - :line => val[0][:line], - :arguments => AST::ASTArray.new({}), - :ftype => :statement + result = ast AST::Function, + :name => val[0][:value], + :line => val[0][:line], + :arguments => val[2], + :ftype => :statement result end .,., -module_eval <<'.,.,', 'grammar.ra', 120 +module_eval <<'.,.,', 'grammar.ra', 102 def _reduce_31( val, _values, result ) - args = aryfy(val[1]) - result = ast AST::Function, - :name => val[0][:value], - :line => val[0][:line], - :arguments => args, - :ftype => :statement + result = ast AST::Function, + :name => val[0][:value], + :line => val[0][:line], + :arguments => AST::ASTArray.new({}), + :ftype => :statement result end .,., - # reduce 32 omitted +module_eval <<'.,.,', 'grammar.ra', 109 + def _reduce_32( val, _values, result ) + result = ast AST::Function, + :name => val[0][:value], + :line => val[0][:line], + :arguments => val[1], + :ftype => :statement + result + end +.,., - # reduce 33 omitted +module_eval <<'.,.,', 'grammar.ra', 110 + def _reduce_33( val, _values, result ) + result = aryfy(val[0]) + result + end +.,., -module_eval <<'.,.,', 'grammar.ra', 128 +module_eval <<'.,.,', 'grammar.ra', 111 def _reduce_34( val, _values, result ) - result = aryfy(val[0], val[2]) - result.line = @lexer.line - result.file = @lexer.file + result = aryfy(val[0]) result end .,., -module_eval <<'.,.,', 'grammar.ra', 137 +module_eval <<'.,.,', 'grammar.ra', 116 def _reduce_35( val, _values, result ) - unless val[0].is_a?(AST::ASTArray) - val[0] = aryfy(val[0]) - end - val[0].push(val[2]) - result = val[0] result end .,., - # reduce 36 omitted +module_eval <<'.,.,', 'grammar.ra', 120 + def _reduce_36( val, _values, result ) + val[0].push(val[2]) + result = val[0] + result + end +.,., # reduce 37 omitted # reduce 38 omitted # reduce 39 omitted # reduce 40 omitted # reduce 41 omitted # reduce 42 omitted # reduce 43 omitted -module_eval <<'.,.,', 'grammar.ra', 151 - def _reduce_44( val, _values, result ) - result = ast AST::Name, :value => val[0][:value] - result - end -.,., + # reduce 44 omitted -module_eval <<'.,.,', 'grammar.ra', 173 +module_eval <<'.,.,', 'grammar.ra', 134 def _reduce_45( val, _values, result ) - @lexer.commentpop - array = val[2] - if array.instance_of?(AST::ResourceInstance) - array = [array] - end - result = ast AST::ASTArray - - # this iterates across each specified resourceinstance - array.each { |instance| - unless instance.instance_of?(AST::ResourceInstance) - raise Puppet::Dev, "Got something that isn't an instance" - end - # now, i need to somehow differentiate between those things with - # arrays in their names, and normal things - result.push ast(AST::Resource, - :type => val[0], - :title => instance[0], - :parameters => instance[1]) - } + result = ast AST::Name, :value => val[0][:value] result end .,., -module_eval <<'.,.,', 'grammar.ra', 176 +module_eval <<'.,.,', 'grammar.ra', 139 def _reduce_46( val, _values, result ) - # This is a deprecated syntax. - error "All resource specifications require names" + @lexer.commentpop + result = ast(AST::Resource, :type => val[0], :instances => val[2]) result end .,., -module_eval <<'.,.,', 'grammar.ra', 180 +module_eval <<'.,.,', 'grammar.ra', 142 def _reduce_47( val, _values, result ) - # a defaults setting for a type - @lexer.commentpop - result = ast(AST::ResourceDefaults, :type => val[0], :parameters => val[2]) + # This is a deprecated syntax. + error "All resource specifications require names" result end .,., -module_eval <<'.,.,', 'grammar.ra', 186 +module_eval <<'.,.,', 'grammar.ra', 146 def _reduce_48( val, _values, result ) - @lexer.commentpop - result = ast AST::ResourceOverride, :object => val[0], :parameters => val[2] + # a defaults setting for a type + @lexer.commentpop + result = ast(AST::ResourceDefaults, :type => val[0], :parameters => val[2]) result end .,., -module_eval <<'.,.,', 'grammar.ra', 213 +module_eval <<'.,.,', 'grammar.ra', 152 def _reduce_49( val, _values, result ) - type = val[0] + @lexer.commentpop + result = ast AST::ResourceOverride, :object => val[0], :parameters => val[2] + result + end +.,., - if (type == :exported and ! Puppet[:storeconfigs]) and ! Puppet[:parseonly] - Puppet.warning addcontext("You cannot collect without storeconfigs being set") - end +module_eval <<'.,.,', 'grammar.ra', 171 + def _reduce_50( val, _values, result ) + type = val[0] - if val[1].is_a? AST::ResourceDefaults - error "Defaults are not virtualizable" - end + if (type == :exported and ! Puppet[:storeconfigs]) and ! Puppet[:parseonly] + Puppet.warning addcontext("You cannot collect without storeconfigs being set") + end - method = type.to_s + "=" + error "Defaults are not virtualizable" if val[1].is_a? AST::ResourceDefaults - # Just mark our resources as exported and pass them through. - if val[1].instance_of?(AST::ASTArray) - val[1].each do |obj| - obj.send(method, true) - end - else - val[1].send(method, true) - end + method = type.to_s + "=" - result = val[1] + # Just mark our resource as exported and pass it through. + val[1].send(method, true) + + result = val[1] result end .,., -module_eval <<'.,.,', 'grammar.ra', 214 - def _reduce_50( val, _values, result ) +module_eval <<'.,.,', 'grammar.ra', 172 + def _reduce_51( val, _values, result ) result = :virtual result end .,., -module_eval <<'.,.,', 'grammar.ra', 215 - def _reduce_51( val, _values, result ) +module_eval <<'.,.,', 'grammar.ra', 173 + def _reduce_52( val, _values, result ) result = :exported result end .,., -module_eval <<'.,.,', 'grammar.ra', 240 - def _reduce_52( val, _values, result ) - @lexer.commentpop - if val[0] =~ /^[a-z]/ - Puppet.warning addcontext("Collection names must now be capitalized") - end - type = val[0].downcase - args = {:type => type} - - if val[1].is_a?(AST::CollExpr) - args[:query] = val[1] - args[:query].type = type - args[:form] = args[:query].form - else - args[:form] = val[1] - end - if args[:form] == :exported and ! Puppet[:storeconfigs] and ! Puppet[:parseonly] - Puppet.warning addcontext("You cannot collect exported resources without storeconfigs being set; the collection will be ignored") - end - args[:override] = val[3] - result = ast AST::Collection, args +module_eval <<'.,.,', 'grammar.ra', 196 + def _reduce_53( val, _values, result ) + @lexer.commentpop + Puppet.warning addcontext("Collection names must now be capitalized") if val[0] =~ /^[a-z]/ + type = val[0].downcase + args = {:type => type} + + if val[1].is_a?(AST::CollExpr) + args[:query] = val[1] + args[:query].type = type + args[:form] = args[:query].form + else + args[:form] = val[1] + end + if args[:form] == :exported and ! Puppet[:storeconfigs] and ! Puppet[:parseonly] + Puppet.warning addcontext("You cannot collect exported resources without storeconfigs being set; the collection will be ignored") + end + args[:override] = val[3] + result = ast AST::Collection, args result end .,., -module_eval <<'.,.,', 'grammar.ra', 259 - def _reduce_53( val, _values, result ) +module_eval <<'.,.,', 'grammar.ra', 215 + def _reduce_54( val, _values, result ) if val[0] =~ /^[a-z]/ - Puppet.warning addcontext("Collection names must now be capitalized") - end - type = val[0].downcase - args = {:type => type } - - if val[1].is_a?(AST::CollExpr) - args[:query] = val[1] - args[:query].type = type - args[:form] = args[:query].form - else - args[:form] = val[1] - end - if args[:form] == :exported and ! Puppet[:storeconfigs] and ! Puppet[:parseonly] - Puppet.warning addcontext("You cannot collect exported resources without storeconfigs being set; the collection will be ignored") - end - result = ast AST::Collection, args + Puppet.warning addcontext("Collection names must now be capitalized") + end + type = val[0].downcase + args = {:type => type } + + if val[1].is_a?(AST::CollExpr) + args[:query] = val[1] + args[:query].type = type + args[:form] = args[:query].form + else + args[:form] = val[1] + end + if args[:form] == :exported and ! Puppet[:storeconfigs] and ! Puppet[:parseonly] + Puppet.warning addcontext("You cannot collect exported resources without storeconfigs being set; the collection will be ignored") + end + result = ast AST::Collection, args result end .,., -module_eval <<'.,.,', 'grammar.ra', 269 - def _reduce_54( val, _values, result ) - if val[1] - result = val[1] - result.form = :virtual - else - result = :virtual - end +module_eval <<'.,.,', 'grammar.ra', 225 + def _reduce_55( val, _values, result ) + if val[1] + result = val[1] + result.form = :virtual + else + result = :virtual + end result end .,., -module_eval <<'.,.,', 'grammar.ra', 277 - def _reduce_55( val, _values, result ) +module_eval <<'.,.,', 'grammar.ra', 233 + def _reduce_56( val, _values, result ) if val[1] - result = val[1] - result.form = :exported - else - result = :exported - end + result = val[1] + result.form = :exported + else + result = :exported + end result end .,., - # reduce 56 omitted - # reduce 57 omitted -module_eval <<'.,.,', 'grammar.ra', 285 - def _reduce_58( val, _values, result ) + # reduce 58 omitted + +module_eval <<'.,.,', 'grammar.ra', 241 + def _reduce_59( val, _values, result ) result = ast AST::CollExpr, :test1 => val[0], :oper => val[1], :test2 => val[2] result end .,., - # reduce 59 omitted + # reduce 60 omitted -module_eval <<'.,.,', 'grammar.ra', 291 - def _reduce_60( val, _values, result ) +module_eval <<'.,.,', 'grammar.ra', 247 + def _reduce_61( val, _values, result ) result = val[1] result.parens = true result end .,., -module_eval <<'.,.,', 'grammar.ra', 292 - def _reduce_61( val, _values, result ) +module_eval <<'.,.,', 'grammar.ra', 248 + def _reduce_62( val, _values, result ) result=val[0][:value] result end .,., -module_eval <<'.,.,', 'grammar.ra', 293 - def _reduce_62( val, _values, result ) +module_eval <<'.,.,', 'grammar.ra', 249 + def _reduce_63( val, _values, result ) result=val[0][:value] result end .,., -module_eval <<'.,.,', 'grammar.ra', 300 - def _reduce_63( val, _values, result ) - result = ast AST::CollExpr, :test1 => val[0], :oper => val[1][:value], :test2 => val[2] - #result = ast AST::CollExpr - #result.push *val +module_eval <<'.,.,', 'grammar.ra', 256 + def _reduce_64( val, _values, result ) + result = ast AST::CollExpr, :test1 => val[0], :oper => val[1][:value], :test2 => val[2] + #result = ast AST::CollExpr + #result.push *val result end .,., -module_eval <<'.,.,', 'grammar.ra', 305 - def _reduce_64( val, _values, result ) +module_eval <<'.,.,', 'grammar.ra', 261 + def _reduce_65( val, _values, result ) result = ast AST::CollExpr, :test1 => val[0], :oper => val[1][:value], :test2 => val[2] #result = ast AST::CollExpr #result.push *val result end .,., - # reduce 65 omitted - # reduce 66 omitted -module_eval <<'.,.,', 'grammar.ra', 312 - def _reduce_67( val, _values, result ) - result = ast AST::ResourceInstance, :children => [val[0],val[2]] + # reduce 67 omitted + +module_eval <<'.,.,', 'grammar.ra', 268 + def _reduce_68( val, _values, result ) + result = ast AST::ResourceInstance, :title => val[0], :parameters => val[2] result end .,., - # reduce 68 omitted - -module_eval <<'.,.,', 'grammar.ra', 322 +module_eval <<'.,.,', 'grammar.ra', 269 def _reduce_69( val, _values, result ) - if val[0].instance_of?(AST::ResourceInstance) - result = ast AST::ASTArray, :children => [val[0],val[2]] - else - val[0].push val[2] - result = val[0] - end + result = aryfy(val[0]) result end .,., - # reduce 70 omitted - - # reduce 71 omitted - -module_eval <<'.,.,', 'grammar.ra', 329 - def _reduce_72( val, _values, result ) - result = ast AST::Undef, :value => :undef +module_eval <<'.,.,', 'grammar.ra', 274 + def _reduce_70( val, _values, result ) + val[0].push val[2] + result = val[0] result end .,., -module_eval <<'.,.,', 'grammar.ra', 333 + # reduce 71 omitted + + # reduce 72 omitted + +module_eval <<'.,.,', 'grammar.ra', 281 def _reduce_73( val, _values, result ) - result = ast AST::Name, :value => val[0][:value], :line => val[0][:line] + result = ast AST::Undef, :value => :undef result end .,., -module_eval <<'.,.,', 'grammar.ra', 337 +module_eval <<'.,.,', 'grammar.ra', 285 def _reduce_74( val, _values, result ) - result = ast AST::Type, :value => val[0][:value], :line => val[0][:line] + result = ast AST::Name, :value => val[0][:value], :line => val[0][:line] result end .,., - # reduce 75 omitted +module_eval <<'.,.,', 'grammar.ra', 289 + def _reduce_75( val, _values, result ) + result = ast AST::Type, :value => val[0][:value], :line => val[0][:line] + result + end +.,., # reduce 76 omitted # reduce 77 omitted # reduce 78 omitted # reduce 79 omitted # reduce 80 omitted # reduce 81 omitted -module_eval <<'.,.,', 'grammar.ra', 354 - def _reduce_82( val, _values, result ) - if val[0][:value] =~ /::/ - raise Puppet::ParseError, "Cannot assign to variables in other namespaces" - end - # this is distinct from referencing a variable - variable = ast AST::Name, :value => val[0][:value], :line => val[0][:line] - result = ast AST::VarDef, :name => variable, :value => val[2], :line => val[0][:line] - result - end -.,., + # reduce 82 omitted -module_eval <<'.,.,', 'grammar.ra', 357 +module_eval <<'.,.,', 'grammar.ra', 304 def _reduce_83( val, _values, result ) - result = ast AST::VarDef, :name => val[0], :value => val[2] + raise Puppet::ParseError, "Cannot assign to variables in other namespaces" if val[0][:value] =~ /::/ + # this is distinct from referencing a variable + variable = ast AST::Name, :value => val[0][:value], :line => val[0][:line] + result = ast AST::VarDef, :name => variable, :value => val[2], :line => val[0][:line] result end .,., -module_eval <<'.,.,', 'grammar.ra', 362 +module_eval <<'.,.,', 'grammar.ra', 307 def _reduce_84( val, _values, result ) - variable = ast AST::Name, :value => val[0][:value], :line => val[0][:line] - result = ast AST::VarDef, :name => variable, :value => val[2], :append => true, :line => val[0][:line] + result = ast AST::VarDef, :name => val[0], :value => val[2] result end .,., -module_eval <<'.,.,', 'grammar.ra', 367 +module_eval <<'.,.,', 'grammar.ra', 312 def _reduce_85( val, _values, result ) - result = ast AST::ASTArray + variable = ast AST::Name, :value => val[0][:value], :line => val[0][:line] + result = ast AST::VarDef, :name => variable, :value => val[2], :append => true, :line => val[0][:line] result end .,., -module_eval <<'.,.,', 'grammar.ra', 367 +module_eval <<'.,.,', 'grammar.ra', 317 def _reduce_86( val, _values, result ) - result = val[0] + result = ast AST::ASTArray result end .,., -module_eval <<'.,.,', 'grammar.ra', 376 +module_eval <<'.,.,', 'grammar.ra', 317 def _reduce_87( val, _values, result ) - if val[0].instance_of?(AST::ASTArray) - val[0].push(val[2]) - result = val[0] - else - result = ast AST::ASTArray, :children => [val[0],val[2]] - end + result = aryfy(val[0]) result end .,., -module_eval <<'.,.,', 'grammar.ra', 380 +module_eval <<'.,.,', 'grammar.ra', 322 def _reduce_88( val, _values, result ) - result = ast AST::ResourceParam, :param => val[0][:value], :line => val[0][:line], :value => val[2] + val[0].push(val[2]) + result = val[0] result end .,., -module_eval <<'.,.,', 'grammar.ra', 385 +module_eval <<'.,.,', 'grammar.ra', 326 def _reduce_89( val, _values, result ) - result = ast AST::ResourceParam, :param => val[0][:value], :line => val[0][:line], :value => val[2], - :add => true + result = ast AST::ResourceParam, :param => val[0][:value], :line => val[0][:line], :value => val[2] result end .,., - # reduce 90 omitted - - # reduce 91 omitted - -module_eval <<'.,.,', 'grammar.ra', 393 - def _reduce_92( val, _values, result ) - result = ast AST::ASTArray +module_eval <<'.,.,', 'grammar.ra', 331 + def _reduce_90( val, _values, result ) + result = ast AST::ResourceParam, :param => val[0][:value], :line => val[0][:line], :value => val[2], + :add => true result end .,., -module_eval <<'.,.,', 'grammar.ra', 393 + # reduce 91 omitted + + # reduce 92 omitted + +module_eval <<'.,.,', 'grammar.ra', 339 def _reduce_93( val, _values, result ) - result = val[0] + result = ast AST::ASTArray result end .,., -module_eval <<'.,.,', 'grammar.ra', 402 +module_eval <<'.,.,', 'grammar.ra', 339 def _reduce_94( val, _values, result ) - if val[0].instance_of?(AST::ASTArray) - val[0].push(val[2]) - result = val[0] - else - result = ast AST::ASTArray, :children => [val[0],val[2]] - end + result = aryfy(val[0]) result end .,., - # reduce 95 omitted +module_eval <<'.,.,', 'grammar.ra', 344 + def _reduce_95( val, _values, result ) + val[0].push(val[2]) + result = val[0] + result + end +.,., -module_eval <<'.,.,', 'grammar.ra', 411 +module_eval <<'.,.,', 'grammar.ra', 345 def _reduce_96( val, _values, result ) - if val[0].instance_of?(AST::ASTArray) - result = val[0].push(val[2]) - else - result = ast AST::ASTArray, :children => [val[0],val[2]] - end + result = aryfy(val[0]) result end .,., - # reduce 97 omitted +module_eval <<'.,.,', 'grammar.ra', 346 + def _reduce_97( val, _values, result ) + result = val[0].push(val[2]) + result + end +.,., # reduce 98 omitted # reduce 99 omitted # reduce 100 omitted # reduce 101 omitted # reduce 102 omitted # reduce 103 omitted # reduce 104 omitted # reduce 105 omitted # reduce 106 omitted # reduce 107 omitted # reduce 108 omitted # reduce 109 omitted # reduce 110 omitted # reduce 111 omitted # reduce 112 omitted # reduce 113 omitted # reduce 114 omitted -module_eval <<'.,.,', 'grammar.ra', 440 - def _reduce_115( val, _values, result ) - args = aryfy(val[2]) - result = ast AST::Function, - :name => val[0][:value], :line => val[0][:line], - :arguments => args, - :ftype => :rvalue - result - end -.,., + # reduce 115 omitted -module_eval <<'.,.,', 'grammar.ra', 445 +module_eval <<'.,.,', 'grammar.ra', 375 def _reduce_116( val, _values, result ) - result = ast AST::Function, - :name => val[0][:value], :line => val[0][:line], - :arguments => AST::ASTArray.new({}), - :ftype => :rvalue + result = ast AST::Function, + :name => val[0][:value], :line => val[0][:line], + :arguments => val[2], + :ftype => :rvalue result end .,., -module_eval <<'.,.,', 'grammar.ra', 446 +module_eval <<'.,.,', 'grammar.ra', 380 def _reduce_117( val, _values, result ) - result = ast AST::String, :value => val[0][:value], :line => val[0][:line] + result = ast AST::Function, + :name => val[0][:value], :line => val[0][:line], + :arguments => AST::ASTArray.new({}), + :ftype => :rvalue result end .,., -module_eval <<'.,.,', 'grammar.ra', 447 +module_eval <<'.,.,', 'grammar.ra', 381 def _reduce_118( val, _values, result ) - result = ast AST::Concat, :value => [ast(AST::String,val[0])]+val[1], :line => val[0][:line] + result = ast AST::String, :value => val[0][:value], :line => val[0][:line] result end .,., -module_eval <<'.,.,', 'grammar.ra', 449 +module_eval <<'.,.,', 'grammar.ra', 382 def _reduce_119( val, _values, result ) - result = [val[0]] + val[1] + result = ast AST::Concat, :value => [ast(AST::String,val[0])]+val[1], :line => val[0][:line] result end .,., -module_eval <<'.,.,', 'grammar.ra', 451 +module_eval <<'.,.,', 'grammar.ra', 384 def _reduce_120( val, _values, result ) - result = [ast(AST::String,val[0])] + result = [val[0]] + val[1] result end .,., -module_eval <<'.,.,', 'grammar.ra', 452 +module_eval <<'.,.,', 'grammar.ra', 386 def _reduce_121( val, _values, result ) - result = [ast(AST::String,val[0])] + val[1] + result = [ast(AST::String,val[0])] result end .,., -module_eval <<'.,.,', 'grammar.ra', 457 +module_eval <<'.,.,', 'grammar.ra', 387 def _reduce_122( val, _values, result ) - result = ast AST::Boolean, :value => val[0][:value], :line => val[0][:line] + result = [ast(AST::String,val[0])] + val[1] result end .,., -module_eval <<'.,.,', 'grammar.ra', 462 +module_eval <<'.,.,', 'grammar.ra', 392 def _reduce_123( val, _values, result ) - Puppet.warning addcontext("Deprecation notice: Resource references should now be capitalized") - result = ast AST::ResourceReference, :type => val[0][:value], :line => val[0][:line], :title => val[2] + result = ast AST::Boolean, :value => val[0][:value], :line => val[0][:line] result end .,., -module_eval <<'.,.,', 'grammar.ra', 464 +module_eval <<'.,.,', 'grammar.ra', 397 def _reduce_124( val, _values, result ) - result = ast AST::ResourceReference, :type => val[0], :title => val[2] + Puppet.warning addcontext("Deprecation notice: Resource references should now be capitalized") + result = ast AST::ResourceReference, :type => val[0][:value], :line => val[0][:line], :title => val[2] result end .,., -module_eval <<'.,.,', 'grammar.ra', 468 +module_eval <<'.,.,', 'grammar.ra', 399 def _reduce_125( val, _values, result ) - result = val[1] + result = ast AST::ResourceReference, :type => val[0], :title => val[2] result end .,., -module_eval <<'.,.,', 'grammar.ra', 482 +module_eval <<'.,.,', 'grammar.ra', 403 def _reduce_126( val, _values, result ) - @lexer.commentpop - args = { - :test => val[0], - :statements => val[2] - } + result = val[1] + result + end +.,., - if val[4] - args[:else] = val[4] - end +module_eval <<'.,.,', 'grammar.ra', 415 + def _reduce_127( val, _values, result ) + @lexer.commentpop + args = { + :test => val[0], + :statements => val[2] + } + + args[:else] = val[4] if val[4] - result = ast AST::IfStatement, args + result = ast AST::IfStatement, args result end .,., -module_eval <<'.,.,', 'grammar.ra', 495 - def _reduce_127( val, _values, result ) +module_eval <<'.,.,', 'grammar.ra', 426 + def _reduce_128( val, _values, result ) @lexer.commentpop args = { - :test => val[0], - :statements => ast(AST::Nop) - } + :test => val[0], + :statements => ast(AST::Nop) + } - if val[3] - args[:else] = val[3] - end + args[:else] = val[3] if val[3] - result = ast AST::IfStatement, args + result = ast AST::IfStatement, args result end .,., - # reduce 128 omitted + # reduce 129 omitted -module_eval <<'.,.,', 'grammar.ra', 501 - def _reduce_129( val, _values, result ) - #@lexer.commentpop +module_eval <<'.,.,', 'grammar.ra', 431 + def _reduce_130( val, _values, result ) result = ast AST::Else, :statements => val[1] result end .,., -module_eval <<'.,.,', 'grammar.ra', 505 - def _reduce_130( val, _values, result ) +module_eval <<'.,.,', 'grammar.ra', 435 + def _reduce_131( val, _values, result ) @lexer.commentpop result = ast AST::Else, :statements => val[2] result end .,., -module_eval <<'.,.,', 'grammar.ra', 509 - def _reduce_131( val, _values, result ) +module_eval <<'.,.,', 'grammar.ra', 439 + def _reduce_132( val, _values, result ) @lexer.commentpop result = ast AST::Else, :statements => ast(AST::Nop) result end .,., - # reduce 132 omitted + # reduce 133 omitted -module_eval <<'.,.,', 'grammar.ra', 526 - def _reduce_133( val, _values, result ) - result = ast AST::InOperator, :lval => val[0], :rval => val[2] - result - end -.,., - -module_eval <<'.,.,', 'grammar.ra', 529 +module_eval <<'.,.,', 'grammar.ra', 456 def _reduce_134( val, _values, result ) - result = ast AST::MatchOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + result = ast AST::InOperator, :lval => val[0], :rval => val[2] result end .,., -module_eval <<'.,.,', 'grammar.ra', 532 +module_eval <<'.,.,', 'grammar.ra', 459 def _reduce_135( val, _values, result ) result = ast AST::MatchOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] result end .,., -module_eval <<'.,.,', 'grammar.ra', 535 +module_eval <<'.,.,', 'grammar.ra', 462 def _reduce_136( val, _values, result ) - result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + result = ast AST::MatchOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] result end .,., -module_eval <<'.,.,', 'grammar.ra', 538 +module_eval <<'.,.,', 'grammar.ra', 465 def _reduce_137( val, _values, result ) result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] result end .,., -module_eval <<'.,.,', 'grammar.ra', 541 +module_eval <<'.,.,', 'grammar.ra', 468 def _reduce_138( val, _values, result ) result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] result end .,., -module_eval <<'.,.,', 'grammar.ra', 544 +module_eval <<'.,.,', 'grammar.ra', 471 def _reduce_139( val, _values, result ) result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] result end .,., -module_eval <<'.,.,', 'grammar.ra', 547 +module_eval <<'.,.,', 'grammar.ra', 474 def _reduce_140( val, _values, result ) result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] result end .,., -module_eval <<'.,.,', 'grammar.ra', 550 +module_eval <<'.,.,', 'grammar.ra', 477 def _reduce_141( val, _values, result ) result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] result end .,., -module_eval <<'.,.,', 'grammar.ra', 553 +module_eval <<'.,.,', 'grammar.ra', 480 def _reduce_142( val, _values, result ) - result = ast AST::Minus, :value => val[1] + result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] result end .,., -module_eval <<'.,.,', 'grammar.ra', 556 +module_eval <<'.,.,', 'grammar.ra', 483 def _reduce_143( val, _values, result ) - result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + result = ast AST::Minus, :value => val[1] result end .,., -module_eval <<'.,.,', 'grammar.ra', 559 +module_eval <<'.,.,', 'grammar.ra', 486 def _reduce_144( val, _values, result ) result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] result end .,., -module_eval <<'.,.,', 'grammar.ra', 562 +module_eval <<'.,.,', 'grammar.ra', 489 def _reduce_145( val, _values, result ) result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] result end .,., -module_eval <<'.,.,', 'grammar.ra', 565 +module_eval <<'.,.,', 'grammar.ra', 492 def _reduce_146( val, _values, result ) result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] result end .,., -module_eval <<'.,.,', 'grammar.ra', 568 +module_eval <<'.,.,', 'grammar.ra', 495 def _reduce_147( val, _values, result ) result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] result end .,., -module_eval <<'.,.,', 'grammar.ra', 571 +module_eval <<'.,.,', 'grammar.ra', 498 def _reduce_148( val, _values, result ) result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] result end .,., -module_eval <<'.,.,', 'grammar.ra', 574 +module_eval <<'.,.,', 'grammar.ra', 501 def _reduce_149( val, _values, result ) - result = ast AST::Not, :value => val[1] + result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] result end .,., -module_eval <<'.,.,', 'grammar.ra', 577 +module_eval <<'.,.,', 'grammar.ra', 504 def _reduce_150( val, _values, result ) - result = ast AST::BooleanOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + result = ast AST::Not, :value => val[1] result end .,., -module_eval <<'.,.,', 'grammar.ra', 580 +module_eval <<'.,.,', 'grammar.ra', 507 def _reduce_151( val, _values, result ) result = ast AST::BooleanOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] result end .,., -module_eval <<'.,.,', 'grammar.ra', 583 +module_eval <<'.,.,', 'grammar.ra', 510 def _reduce_152( val, _values, result ) - result = val[1] + result = ast AST::BooleanOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] result end .,., -module_eval <<'.,.,', 'grammar.ra', 592 +module_eval <<'.,.,', 'grammar.ra', 513 def _reduce_153( val, _values, result ) - @lexer.commentpop - options = val[3] - unless options.instance_of?(AST::ASTArray) - options = ast AST::ASTArray, :children => [val[3]] - end - result = ast AST::CaseStatement, :test => val[1], :options => options + result = val[1] result end .,., - # reduce 154 omitted +module_eval <<'.,.,', 'grammar.ra', 518 + def _reduce_154( val, _values, result ) + @lexer.commentpop + result = ast AST::CaseStatement, :test => val[1], :options => val[3] + result + end +.,., -module_eval <<'.,.,', 'grammar.ra', 602 +module_eval <<'.,.,', 'grammar.ra', 519 def _reduce_155( val, _values, result ) - if val[0].instance_of?(AST::ASTArray) - val[0].push val[1] - result = val[0] - else - result = ast AST::ASTArray, :children => [val[0], val[1]] - end + result = aryfy(val[0]) result end .,., -module_eval <<'.,.,', 'grammar.ra', 607 +module_eval <<'.,.,', 'grammar.ra', 524 def _reduce_156( val, _values, result ) - @lexer.commentpop - result = ast AST::CaseOpt, :value => val[0], :statements => val[3] + val[0].push val[1] + result = val[0] result end .,., -module_eval <<'.,.,', 'grammar.ra', 613 +module_eval <<'.,.,', 'grammar.ra', 529 def _reduce_157( val, _values, result ) - @lexer.commentpop - result = ast(AST::CaseOpt, - :value => val[0], - :statements => ast(AST::ASTArray) - ) + @lexer.commentpop + result = ast AST::CaseOpt, :value => val[0], :statements => val[3] result end .,., - # reduce 158 omitted +module_eval <<'.,.,', 'grammar.ra', 538 + def _reduce_158( val, _values, result ) + @lexer.commentpop -module_eval <<'.,.,', 'grammar.ra', 623 + result = ast( + AST::CaseOpt, + :value => val[0], + + :statements => ast(AST::ASTArray) + ) + result + end +.,., + +module_eval <<'.,.,', 'grammar.ra', 539 def _reduce_159( val, _values, result ) - if val[0].instance_of?(AST::ASTArray) - val[0].push(val[2]) - result = val[0] - else - result = ast AST::ASTArray, :children => [val[0],val[2]] - end + result = aryfy(val[0]) result end .,., -module_eval <<'.,.,', 'grammar.ra', 627 +module_eval <<'.,.,', 'grammar.ra', 544 def _reduce_160( val, _values, result ) - result = ast AST::Selector, :param => val[0], :values => val[2] + val[0].push(val[2]) + result = val[0] result end .,., - # reduce 161 omitted +module_eval <<'.,.,', 'grammar.ra', 548 + def _reduce_161( val, _values, result ) + result = ast AST::Selector, :param => val[0], :values => val[2] + result + end +.,., + + # reduce 162 omitted -module_eval <<'.,.,', 'grammar.ra', 633 - def _reduce_162( val, _values, result ) +module_eval <<'.,.,', 'grammar.ra', 554 + def _reduce_163( val, _values, result ) @lexer.commentpop result = val[1] result end .,., - # reduce 163 omitted + # reduce 164 omitted -module_eval <<'.,.,', 'grammar.ra', 643 - def _reduce_164( val, _values, result ) +module_eval <<'.,.,', 'grammar.ra', 564 + def _reduce_165( val, _values, result ) if val[0].instance_of?(AST::ASTArray) - val[0].push(val[2]) - result = val[0] - else - result = ast AST::ASTArray, :children => [val[0],val[2]] - end + val[0].push(val[2]) + result = val[0] + else + result = ast AST::ASTArray, :children => [val[0],val[2]] + end result end .,., -module_eval <<'.,.,', 'grammar.ra', 647 - def _reduce_165( val, _values, result ) - result = ast AST::ResourceParam, :param => val[0], :value => val[2] +module_eval <<'.,.,', 'grammar.ra', 568 + def _reduce_166( val, _values, result ) + result = ast AST::ResourceParam, :param => val[0], :value => val[2] result end .,., - # reduce 166 omitted - # reduce 167 omitted # reduce 168 omitted # reduce 169 omitted # reduce 170 omitted # reduce 171 omitted # reduce 172 omitted -module_eval <<'.,.,', 'grammar.ra', 658 - def _reduce_173( val, _values, result ) + # reduce 173 omitted + +module_eval <<'.,.,', 'grammar.ra', 579 + def _reduce_174( val, _values, result ) result = ast AST::Default, :value => val[0][:value], :line => val[0][:line] result end .,., - # reduce 174 omitted + # reduce 175 omitted -module_eval <<'.,.,', 'grammar.ra', 661 - def _reduce_175( val, _values, result ) +module_eval <<'.,.,', 'grammar.ra', 582 + def _reduce_176( val, _values, result ) result = [val[0][:value]] result end .,., - # reduce 176 omitted + # reduce 177 omitted -module_eval <<'.,.,', 'grammar.ra', 663 - def _reduce_177( val, _values, result ) - result = val[0] += val[2] - result - end -.,., - -module_eval <<'.,.,', 'grammar.ra', 672 +module_eval <<'.,.,', 'grammar.ra', 584 def _reduce_178( val, _values, result ) - val[1].each do |file| - import(file) - end - - result = AST::ASTArray.new(:children => []) + result = val[0] += val[2] result end .,., -module_eval <<'.,.,', 'grammar.ra', 683 +module_eval <<'.,.,', 'grammar.ra', 593 def _reduce_179( val, _values, result ) - @lexer.commentpop - newdefine classname(val[1]), :arguments => val[2], :code => val[4], :line => val[0][:line] - @lexer.indefine = false - result = nil + val[1].each do |file| + import(file) + end -#} | DEFINE NAME argumentlist parent LBRACE RBRACE { + result = nil result end .,., -module_eval <<'.,.,', 'grammar.ra', 688 +module_eval <<'.,.,', 'grammar.ra', 605 def _reduce_180( val, _values, result ) - @lexer.commentpop - newdefine classname(val[1]), :arguments => val[2], :line => val[0][:line] - @lexer.indefine = false - result = nil + @lexer.commentpop + result = Puppet::Parser::AST::Definition.new(classname(val[1]), + ast_context(true).merge(:arguments => val[2], :code => val[4], + :line => val[0][:line])) + @lexer.indefine = false + +#} | DEFINE NAME argumentlist parent LBRACE RBRACE { result end .,., -module_eval <<'.,.,', 'grammar.ra', 697 +module_eval <<'.,.,', 'grammar.ra', 610 def _reduce_181( val, _values, result ) - @lexer.commentpop - # Our class gets defined in the parent namespace, not our own. - @lexer.namepop - newclass classname(val[1]), :arguments => val[2], :parent => val[3], :code => val[5], :line => val[0][:line] - result = nil + @lexer.commentpop + result = Puppet::Parser::AST::Definition.new(classname(val[1]), + ast_context(true).merge(:arguments => val[2], :line => val[0][:line])) + @lexer.indefine = false result end .,., -module_eval <<'.,.,', 'grammar.ra', 703 +module_eval <<'.,.,', 'grammar.ra', 620 def _reduce_182( val, _values, result ) - @lexer.commentpop - # Our class gets defined in the parent namespace, not our own. - @lexer.namepop - newclass classname(val[1]), :arguments => val[2], :parent => val[3], :line => val[0][:line] - result = nil + @lexer.commentpop + # Our class gets defined in the parent namespace, not our own. + @lexer.namepop + result = Puppet::Parser::AST::Hostclass.new(classname(val[1]), + ast_context(true).merge(:arguments => val[2], :parent => val[3], + :code => val[5], :line => val[0][:line])) result end .,., -module_eval <<'.,.,', 'grammar.ra', 709 +module_eval <<'.,.,', 'grammar.ra', 627 def _reduce_183( val, _values, result ) - @lexer.commentpop - newnode val[1], :parent => val[2], :code => val[4], :line => val[0][:line] - result = nil + @lexer.commentpop + # Our class gets defined in the parent namespace, not our own. + @lexer.namepop + result = Puppet::Parser::AST::Hostclass.new(classname(val[1]), + ast_context(true).merge(:arguments => val[2], :parent => val[3], + :line => val[0][:line])) result end .,., -module_eval <<'.,.,', 'grammar.ra', 713 +module_eval <<'.,.,', 'grammar.ra', 634 def _reduce_184( val, _values, result ) - @lexer.commentpop - newnode val[1], :parent => val[2], :line => val[0][:line] - result = nil + @lexer.commentpop + result = Puppet::Parser::AST::Node.new(val[1], + ast_context(true).merge(:parent => val[2], :code => val[4], + :line => val[0][:line])) result end .,., -module_eval <<'.,.,', 'grammar.ra', 714 +module_eval <<'.,.,', 'grammar.ra', 637 def _reduce_185( val, _values, result ) - result = val[0][:value] + @lexer.commentpop + result = Puppet::Parser::AST::Node.new(val[1], ast_context(true).merge(:parent => val[2], :line => val[0][:line])) result end .,., -module_eval <<'.,.,', 'grammar.ra', 716 +module_eval <<'.,.,', 'grammar.ra', 638 def _reduce_186( val, _values, result ) result = val[0][:value] result end .,., -module_eval <<'.,.,', 'grammar.ra', 717 +module_eval <<'.,.,', 'grammar.ra', 640 def _reduce_187( val, _values, result ) result = val[0][:value] result end .,., -module_eval <<'.,.,', 'grammar.ra', 718 +module_eval <<'.,.,', 'grammar.ra', 641 def _reduce_188( val, _values, result ) - result = "class" + result = val[0][:value] result end .,., - # reduce 189 omitted +module_eval <<'.,.,', 'grammar.ra', 642 + def _reduce_189( val, _values, result ) + result = "class" + result + end +.,., -module_eval <<'.,.,', 'grammar.ra', 728 +module_eval <<'.,.,', 'grammar.ra', 649 def _reduce_190( val, _values, result ) - result = val[0] - result = [result] unless result.is_a?(Array) - result << val[2] + result = [result] result end .,., -module_eval <<'.,.,', 'grammar.ra', 732 +module_eval <<'.,.,', 'grammar.ra', 653 def _reduce_191( val, _values, result ) - result = ast AST::HostName, :value => val[0] + result = val[0] + result << val[2] result end .,., -module_eval <<'.,.,', 'grammar.ra', 733 +module_eval <<'.,.,', 'grammar.ra', 657 def _reduce_192( val, _values, result ) - result = val[0][:value] + result = ast AST::HostName, :value => val[0] result end .,., -module_eval <<'.,.,', 'grammar.ra', 734 +module_eval <<'.,.,', 'grammar.ra', 658 def _reduce_193( val, _values, result ) result = val[0][:value] result end .,., -module_eval <<'.,.,', 'grammar.ra', 735 +module_eval <<'.,.,', 'grammar.ra', 659 def _reduce_194( val, _values, result ) result = val[0][:value] result end .,., - # reduce 195 omitted - -module_eval <<'.,.,', 'grammar.ra', 741 - def _reduce_196( val, _values, result ) - result = nil +module_eval <<'.,.,', 'grammar.ra', 660 + def _reduce_195( val, _values, result ) + result = val[0][:value] result end .,., -module_eval <<'.,.,', 'grammar.ra', 745 + # reduce 196 omitted + +module_eval <<'.,.,', 'grammar.ra', 666 def _reduce_197( val, _values, result ) - result = ast AST::ASTArray, :children => [] + result = nil + result + end +.,., + +module_eval <<'.,.,', 'grammar.ra', 670 + def _reduce_198( val, _values, result ) + result = ast AST::ASTArray, :children => [] result end .,., - # reduce 198 omitted + # reduce 199 omitted -module_eval <<'.,.,', 'grammar.ra', 750 - def _reduce_199( val, _values, result ) +module_eval <<'.,.,', 'grammar.ra', 675 + def _reduce_200( val, _values, result ) result = nil result end .,., -module_eval <<'.,.,', 'grammar.ra', 754 - def _reduce_200( val, _values, result ) +module_eval <<'.,.,', 'grammar.ra', 679 + def _reduce_201( val, _values, result ) result = val[1] result = [result] unless result[0].is_a?(Array) result end .,., - # reduce 201 omitted + # reduce 202 omitted -module_eval <<'.,.,', 'grammar.ra', 761 - def _reduce_202( val, _values, result ) +module_eval <<'.,.,', 'grammar.ra', 686 + def _reduce_203( val, _values, result ) result = val[0] result = [result] unless result[0].is_a?(Array) result << val[2] result end .,., -module_eval <<'.,.,', 'grammar.ra', 766 - def _reduce_203( val, _values, result ) - Puppet.warning addcontext("Deprecation notice: must now include '$' in prototype") - result = [val[0][:value], val[2]] +module_eval <<'.,.,', 'grammar.ra', 691 + def _reduce_204( val, _values, result ) + Puppet.warning addcontext("Deprecation notice: must now include '$' in prototype") + result = [val[0][:value], val[2]] result end .,., -module_eval <<'.,.,', 'grammar.ra', 770 - def _reduce_204( val, _values, result ) +module_eval <<'.,.,', 'grammar.ra', 695 + def _reduce_205( val, _values, result ) Puppet.warning addcontext("Deprecation notice: must now include '$' in prototype") result = [val[0][:value]] result end .,., -module_eval <<'.,.,', 'grammar.ra', 772 - def _reduce_205( val, _values, result ) - result = [val[0][:value], val[2]] +module_eval <<'.,.,', 'grammar.ra', 697 + def _reduce_206( val, _values, result ) + result = [val[0][:value], val[2]] result end .,., -module_eval <<'.,.,', 'grammar.ra', 774 - def _reduce_206( val, _values, result ) - result = [val[0][:value]] +module_eval <<'.,.,', 'grammar.ra', 699 + def _reduce_207( val, _values, result ) + result = [val[0][:value]] result end .,., - # reduce 207 omitted + # reduce 208 omitted -module_eval <<'.,.,', 'grammar.ra', 779 - def _reduce_208( val, _values, result ) +module_eval <<'.,.,', 'grammar.ra', 704 + def _reduce_209( val, _values, result ) result = val[1] result end .,., - # reduce 209 omitted + # reduce 210 omitted -module_eval <<'.,.,', 'grammar.ra', 784 - def _reduce_210( val, _values, result ) +module_eval <<'.,.,', 'grammar.ra', 709 + def _reduce_211( val, _values, result ) result = val[1] result end .,., - # reduce 211 omitted - # reduce 212 omitted -module_eval <<'.,.,', 'grammar.ra', 790 - def _reduce_213( val, _values, result ) - result = ast AST::Variable, :value => val[0][:value], :line => val[0][:line] - result - end -.,., + # reduce 213 omitted -module_eval <<'.,.,', 'grammar.ra', 798 +module_eval <<'.,.,', 'grammar.ra', 715 def _reduce_214( val, _values, result ) - if val[1].instance_of?(AST::ASTArray) - result = val[1] - else - result = ast AST::ASTArray, :children => [val[1]] - end + result = ast AST::Variable, :value => val[0][:value], :line => val[0][:line] result end .,., -module_eval <<'.,.,', 'grammar.ra', 805 +module_eval <<'.,.,', 'grammar.ra', 716 def _reduce_215( val, _values, result ) - if val[1].instance_of?(AST::ASTArray) - result = val[1] - else - result = ast AST::ASTArray, :children => [val[1]] - end + result = val[1] result end .,., -module_eval <<'.,.,', 'grammar.ra', 807 +module_eval <<'.,.,', 'grammar.ra', 717 def _reduce_216( val, _values, result ) - result = ast AST::ASTArray + result = val[1] result end .,., - # reduce 217 omitted +module_eval <<'.,.,', 'grammar.ra', 718 + def _reduce_217( val, _values, result ) + result = ast AST::ASTArray + result + end +.,., # reduce 218 omitted # reduce 219 omitted -module_eval <<'.,.,', 'grammar.ra', 812 - def _reduce_220( val, _values, result ) + # reduce 220 omitted + +module_eval <<'.,.,', 'grammar.ra', 724 + def _reduce_221( val, _values, result ) result = nil result end .,., -module_eval <<'.,.,', 'grammar.ra', 817 - def _reduce_221( val, _values, result ) - result = ast AST::Regex, :value => val[0][:value] +module_eval <<'.,.,', 'grammar.ra', 729 + def _reduce_222( val, _values, result ) + result = ast AST::Regex, :value => val[0][:value] result end .,., -module_eval <<'.,.,', 'grammar.ra', 825 - def _reduce_222( val, _values, result ) - if val[1].instance_of?(AST::ASTHash) - result = val[1] - else - result = ast AST::ASTHash, { :value => val[1] } - end +module_eval <<'.,.,', 'grammar.ra', 737 + def _reduce_223( val, _values, result ) + if val[1].instance_of?(AST::ASTHash) + result = val[1] + else + result = ast AST::ASTHash, { :value => val[1] } + end result end .,., -module_eval <<'.,.,', 'grammar.ra', 832 - def _reduce_223( val, _values, result ) +module_eval <<'.,.,', 'grammar.ra', 744 + def _reduce_224( val, _values, result ) if val[1].instance_of?(AST::ASTHash) - result = val[1] - else - result = ast AST::ASTHash, { :value => val[1] } - end + result = val[1] + else + result = ast AST::ASTHash, { :value => val[1] } + end result end .,., -module_eval <<'.,.,', 'grammar.ra', 834 - def _reduce_224( val, _values, result ) - result = ast AST::ASTHash +module_eval <<'.,.,', 'grammar.ra', 746 + def _reduce_225( val, _values, result ) + result = ast AST::ASTHash result end .,., - # reduce 225 omitted + # reduce 226 omitted -module_eval <<'.,.,', 'grammar.ra', 844 - def _reduce_226( val, _values, result ) +module_eval <<'.,.,', 'grammar.ra', 756 + def _reduce_227( val, _values, result ) if val[0].instance_of?(AST::ASTHash) - result = val[0].merge(val[2]) - else - result = ast AST::ASTHash, :value => val[0] - result.merge(val[2]) - end + result = val[0].merge(val[2]) + else + result = ast AST::ASTHash, :value => val[0] + result.merge(val[2]) + end result end .,., -module_eval <<'.,.,', 'grammar.ra', 848 - def _reduce_227( val, _values, result ) - result = ast AST::ASTHash, { :value => { val[0] => val[2] } } +module_eval <<'.,.,', 'grammar.ra', 760 + def _reduce_228( val, _values, result ) + result = ast AST::ASTHash, { :value => { val[0] => val[2] } } result end .,., -module_eval <<'.,.,', 'grammar.ra', 849 - def _reduce_228( val, _values, result ) +module_eval <<'.,.,', 'grammar.ra', 761 + def _reduce_229( val, _values, result ) result = val[0][:value] result end .,., -module_eval <<'.,.,', 'grammar.ra', 850 - def _reduce_229( val, _values, result ) +module_eval <<'.,.,', 'grammar.ra', 762 + def _reduce_230( val, _values, result ) result = val[0] result end .,., -module_eval <<'.,.,', 'grammar.ra', 855 - def _reduce_230( val, _values, result ) - result = ast AST::HashOrArrayAccess, :variable => val[0][:value], :key => val[2] +module_eval <<'.,.,', 'grammar.ra', 767 + def _reduce_231( val, _values, result ) + result = ast AST::HashOrArrayAccess, :variable => val[0][:value], :key => val[2] result end .,., - # reduce 231 omitted + # reduce 232 omitted -module_eval <<'.,.,', 'grammar.ra', 860 - def _reduce_232( val, _values, result ) +module_eval <<'.,.,', 'grammar.ra', 772 + def _reduce_233( val, _values, result ) result = ast AST::HashOrArrayAccess, :variable => val[0], :key => val[2] result end .,., def _reduce_none( val, _values, result ) result end end # class Parser end # module Parser end # module Puppet diff --git a/lib/puppet/parser/parser_support.rb b/lib/puppet/parser/parser_support.rb index c90c1978f..16cd0ee0f 100644 --- a/lib/puppet/parser/parser_support.rb +++ b/lib/puppet/parser/parser_support.rb @@ -1,237 +1,212 @@ # I pulled this into a separate file, because I got # tired of rebuilding the parser.rb file all the time. class Puppet::Parser::Parser require 'puppet/parser/functions' require 'puppet/parser/files' require 'puppet/resource/type_collection' require 'puppet/resource/type_collection_helper' require 'puppet/resource/type' require 'monitor' AST = Puppet::Parser::AST include Puppet::Resource::TypeCollectionHelper attr_reader :version, :environment attr_accessor :files attr_accessor :lexer # Add context to a message; useful for error messages and such. def addcontext(message, obj = nil) obj ||= @lexer message += " on line #{obj.line}" if file = obj.file message += " in file #{file}" end message end - # Create an AST array out of all of the args - def aryfy(*args) - if args[0].instance_of?(AST::ASTArray) - result = args.shift - args.each { |arg| - result.push arg - } - else - result = ast AST::ASTArray, :children => args - end - - result + # Create an AST array containing a single element + def aryfy(arg) + ast AST::ASTArray, :children => [arg] end # Create an AST object, and automatically add the file and line information if # available. def ast(klass, hash = {}) klass.new ast_context(klass.use_docs).merge(hash) end def ast_context(include_docs = false) result = { :line => lexer.line, :file => lexer.file } result[:doc] = lexer.getcomment(result[:line]) if include_docs result end # The fully qualifed name, with the full namespace. def classname(name) [@lexer.namespace, name].join("::").sub(/^::/, '') end def clear initvars end # Raise a Parse error. - def error(message) + def error(message, options = {}) if brace = @lexer.expected message += "; expected '%s'" end except = Puppet::ParseError.new(message) - except.line = @lexer.line - except.file = @lexer.file if @lexer.file + except.line = options[:line] || @lexer.line + except.file = options[:file] || @lexer.file raise except end def file @lexer.file end def file=(file) unless FileTest.exist?(file) unless file =~ /\.pp$/ file = file + ".pp" end raise Puppet::Error, "Could not find file #{file}" unless FileTest.exist?(file) end raise Puppet::AlreadyImportedError, "Import loop detected" if known_resource_types.watching_file?(file) watch_file(file) @lexer.file = file end [:hostclass, :definition, :node, :nodes?].each do |method| define_method(method) do |*args| known_resource_types.send(method, *args) end end def find_hostclass(namespace, name) - known_resource_types.find_or_load(namespace, name, :hostclass) + known_resource_types.find_hostclass(namespace, name) end def find_definition(namespace, name) - known_resource_types.find_or_load(namespace, name, :definition) + known_resource_types.find_definition(namespace, name) end def import(file) known_resource_types.loader.import(file, @lexer.file) end def initialize(env) # The environment is needed to know how to find the resource type collection. @environment = env.is_a?(String) ? Puppet::Node::Environment.new(env) : env initvars end # Initialize or reset all of our variables. def initvars @lexer = Puppet::Parser::Lexer.new end # Split an fq name into a namespace and name def namesplit(fullname) ary = fullname.split("::") n = ary.pop || "" ns = ary.join("::") return ns, n end - # Create a new class, or merge with an existing class. - def newclass(name, options = {}) - known_resource_types.add Puppet::Resource::Type.new(:hostclass, name, ast_context(true).merge(options)) - end - - # Create a new definition. - def newdefine(name, options = {}) - known_resource_types.add Puppet::Resource::Type.new(:definition, name, ast_context(true).merge(options)) - end - - # Create a new node. Nodes are special, because they're stored in a global - # table, not according to namespaces. - def newnode(names, options = {}) - names = [names] unless names.instance_of?(Array) - context = ast_context(true) - names.collect do |name| - known_resource_types.add(Puppet::Resource::Type.new(:node, name, context.merge(options))) - end - end - def on_error(token,value,stack) if token == 0 # denotes end of file value = 'end of file' else value = "'#{value[:value]}'" end error = "Syntax error at #{value}" if brace = @lexer.expected error += "; expected '#{brace}'" end except = Puppet::ParseError.new(error) except.line = @lexer.line except.file = @lexer.file if @lexer.file raise except end # how should I do error handling here? def parse(string = nil) - return parse_ruby_file if self.file =~ /\.rb$/ - self.string = string if string - begin - @yydebug = false - main = yyparse(@lexer,:scan) - rescue Racc::ParseError => except - error = Puppet::ParseError.new(except) - error.line = @lexer.line - error.file = @lexer.file - error.set_backtrace except.backtrace - raise error - rescue Puppet::ParseError => except - except.line ||= @lexer.line - except.file ||= @lexer.file - raise except - rescue Puppet::Error => except - # and this is a framework error - except.line ||= @lexer.line - except.file ||= @lexer.file - raise except - rescue Puppet::DevError => except - except.line ||= @lexer.line - except.file ||= @lexer.file - raise except - rescue => except - error = Puppet::DevError.new(except.message) - error.line = @lexer.line - error.file = @lexer.file - error.set_backtrace except.backtrace - raise error - end - if main - # Store the results as the top-level class. - newclass("", :code => main) + if self.file =~ /\.rb$/ + main = parse_ruby_file + else + self.string = string if string + begin + @yydebug = false + main = yyparse(@lexer,:scan) + rescue Racc::ParseError => except + error = Puppet::ParseError.new(except) + error.line = @lexer.line + error.file = @lexer.file + error.set_backtrace except.backtrace + raise error + rescue Puppet::ParseError => except + except.line ||= @lexer.line + except.file ||= @lexer.file + raise except + rescue Puppet::Error => except + # and this is a framework error + except.line ||= @lexer.line + except.file ||= @lexer.file + raise except + rescue Puppet::DevError => except + except.line ||= @lexer.line + except.file ||= @lexer.file + raise except + rescue => except + error = Puppet::DevError.new(except.message) + error.line = @lexer.line + error.file = @lexer.file + error.set_backtrace except.backtrace + raise error + end end - return known_resource_types + # Store the results as the top-level class. + return Puppet::Parser::AST::Hostclass.new('', :code => main) ensure @lexer.clear end def parse_ruby_file # Execute the contents of the file inside its own "main" object so # that it can call methods in the resource type API. - Puppet::DSL::ResourceTypeAPI.new.instance_eval(File.read(self.file)) + main_object = Puppet::DSL::ResourceTypeAPI.new + main_object.instance_eval(File.read(self.file)) + + # Then extract any types that were created. + Puppet::Parser::AST::ASTArray.new :children => main_object.instance_eval { @__created_ast_objects__ } end def string=(string) @lexer.string = string end def version known_resource_types.version end # Add a new file to be checked when we're checking to see if we should be # reparsed. This is basically only used by the TemplateWrapper to let the # parser know about templates that should be parsed. def watch_file(filename) known_resource_types.watch_file(filename) end end diff --git a/lib/puppet/parser/type_loader.rb b/lib/puppet/parser/type_loader.rb index bae560381..140c9f2ca 100644 --- a/lib/puppet/parser/type_loader.rb +++ b/lib/puppet/parser/type_loader.rb @@ -1,148 +1,145 @@ require 'puppet/node/environment' class Puppet::Parser::TypeLoader include Puppet::Node::Environment::Helper # Helper class that makes sure we don't try to import the same file # more than once from either the same thread or different threads. class Helper include MonitorMixin def initialize super # These hashes are indexed by filename @state = {} # :doing or :done @thread = {} # if :doing, thread that's doing the parsing @cond_var = {} # if :doing, condition var that will be signaled when done. end # Execute the supplied block exactly once per file, no matter how # many threads have asked for it to run. If another thread is # already executing it, wait for it to finish. If this thread is # already executing it, return immediately without executing the # block. # # Note: the reason for returning immediately if this thread is # already executing the block is to handle the case of a circular # import--when this happens, we attempt to recursively re-parse a # file that we are already in the process of parsing. To prevent # an infinite regress we need to simply do nothing when the # recursive import is attempted. def do_once(file) need_to_execute = synchronize do case @state[file] when :doing if @thread[file] != Thread.current @cond_var[file].wait end false when :done false else @state[file] = :doing @thread[file] = Thread.current @cond_var[file] = new_cond true end end if need_to_execute begin yield ensure synchronize do @state[file] = :done @thread.delete(file) @cond_var.delete(file).broadcast end end end end end # Import our files. def import(file, current_file = nil) return if Puppet[:ignoreimport] # use a path relative to the file doing the importing if current_file dir = current_file.sub(%r{[^/]+$},'').sub(/\/$/, '') else dir = "." end if dir == "" dir = "." end pat = file modname, files = Puppet::Parser::Files.find_manifests(pat, :cwd => dir, :environment => environment) if files.size == 0 raise Puppet::ImportError.new("No file(s) found for import of '#{pat}'") end + loaded_asts = [] files.each do |file| unless file =~ /^#{File::SEPARATOR}/ file = File.join(dir, file) end @loading_helper.do_once(file) do - parse_file(file) + loaded_asts << parse_file(file) end end - - modname + loaded_asts.inject([]) do |loaded_types, ast| + loaded_types + known_resource_types.import_ast(ast, modname) + end end def known_resource_types environment.known_resource_types end def initialize(env) self.environment = env @loading_helper = Helper.new end - def load_until(namespaces, name) - return nil if name == "" # special-case main. - name2files(namespaces, name).each do |filename| - modname = begin - import(filename) + # Try to load the object with the given fully qualified name. + def try_load_fqname(type, fqname) + return nil if fqname == "" # special-case main. + name2files(fqname).each do |filename| + begin + imported_types = import(filename) + if result = imported_types.find { |t| t.type == type and t.name == fqname } + Puppet.debug "Automatically imported #{fqname} from #{filename} into #{environment}" + return result + end rescue Puppet::ImportError => detail # We couldn't load the item # I'm not convienced we should just drop these errors, but this # preserves existing behaviours. - nil - end - if result = yield(filename) - Puppet.debug "Automatically imported #{name} from #{filename} into #{environment}" - result.module_name = modname if modname and result.respond_to?(:module_name=) - return result end end - nil - end - - def name2files(namespaces, name) - return [name.sub(/^::/, '').gsub("::", File::SEPARATOR)] if name =~ /^::/ - - result = namespaces.inject([]) do |names_to_try, namespace| - fullname = (namespace + "::#{name}").sub(/^::/, '') - - # Try to load the module init file if we're a qualified name - names_to_try << fullname.split("::")[0] if fullname.include?("::") - - # Then the fully qualified name - names_to_try << fullname - end - - # Otherwise try to load the bare name on its own. This - # is appropriate if the class we're looking for is in a - # module that's different from our namespace. - result << name - result.uniq.collect { |f| f.gsub("::", File::SEPARATOR) } + # Nothing found. + return nil end def parse_file(file) Puppet.debug("importing '#{file}' in environment #{environment}") parser = Puppet::Parser::Parser.new(environment) parser.file = file - parser.parse + return parser.parse + end + + private + + # Return a list of all file basenames that should be tried in order + # to load the object with the given fully qualified name. + def name2files(fqname) + result = [] + ary = fqname.split("::") + while ary.length > 0 + result << ary.join(File::SEPARATOR) + ary.pop + end + return result end + end diff --git a/lib/puppet/provider/nameservice/directoryservice.rb b/lib/puppet/provider/nameservice/directoryservice.rb index 965a2aa60..106d99eb3 100644 --- a/lib/puppet/provider/nameservice/directoryservice.rb +++ b/lib/puppet/provider/nameservice/directoryservice.rb @@ -1,516 +1,548 @@ # Created by Jeff McCune on 2007-07-22 # Copyright (c) 2007. All rights reserved. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation (version 2 of the License) # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA require 'puppet' require 'puppet/provider/nameservice' require 'facter/util/plist' require 'cgi' class Puppet::Provider::NameService class DirectoryService < Puppet::Provider::NameService # JJM: Dive into the singleton_class class << self # JJM: This allows us to pass information when calling # Puppet::Type.type # e.g. Puppet::Type.type(:user).provide :directoryservice, :ds_path => "Users" # This is referenced in the get_ds_path class method attr_writer :ds_path attr_writer :macosx_version_major end initvars commands :dscl => "/usr/bin/dscl" commands :dseditgroup => "/usr/sbin/dseditgroup" commands :sw_vers => "/usr/bin/sw_vers" confine :operatingsystem => :darwin defaultfor :operatingsystem => :darwin # JJM 2007-07-25: This map is used to map NameService attributes to their # corresponding DirectoryService attribute names. # See: http://images.apple.com/server/docs.Open_Directory_v10.4.pdf # JJM: Note, this is de-coupled from the Puppet::Type, and must # be actively maintained. There may also be collisions with different # types (Users, Groups, Mounts, Hosts, etc...) @@ds_to_ns_attribute_map = { 'RecordName' => :name, 'PrimaryGroupID' => :gid, 'NFSHomeDirectory' => :home, 'UserShell' => :shell, 'UniqueID' => :uid, 'RealName' => :comment, 'Password' => :password, 'GeneratedUID' => :guid, 'IPAddress' => :ip_address, 'ENetAddress' => :en_address, 'GroupMembership' => :members, } # JJM The same table as above, inverted. @@ns_to_ds_attribute_map = { :name => 'RecordName', :gid => 'PrimaryGroupID', :home => 'NFSHomeDirectory', :shell => 'UserShell', :uid => 'UniqueID', :comment => 'RealName', :password => 'Password', :guid => 'GeneratedUID', :en_address => 'ENetAddress', :ip_address => 'IPAddress', :members => 'GroupMembership', } @@password_hash_dir = "/var/db/shadow/hash" def self.instances # JJM Class method that provides an array of instance objects of this # type. # JJM: Properties are dependent on the Puppet::Type we're managine. type_property_array = [:name] + @resource_type.validproperties # Create a new instance of this Puppet::Type for each object present # on the system. list_all_present.collect do |name_string| self.new(single_report(name_string, *type_property_array)) end end def self.get_ds_path # JJM: 2007-07-24 This method dynamically returns the DS path we're concerned with. # For example, if we're working with an user type, this will be /Users # with a group type, this will be /Groups. # @ds_path is an attribute of the class itself. return @ds_path if defined?(@ds_path) # JJM: "Users" or "Groups" etc ... (Based on the Puppet::Type) # Remember this is a class method, so self.class is Class # Also, @resource_type seems to be the reference to the # Puppet::Type this class object is providing for. @resource_type.name.to_s.capitalize + "s" end def self.get_macosx_version_major return @macosx_version_major if defined?(@macosx_version_major) begin # Make sure we've loaded all of the facts Facter.loadfacts if Facter.value(:macosx_productversion_major) product_version_major = Facter.value(:macosx_productversion_major) else # TODO: remove this code chunk once we require Facter 1.5.5 or higher. Puppet.warning("DEPRECATION WARNING: Future versions of the directoryservice provider will require Facter 1.5.5 or newer.") product_version = Facter.value(:macosx_productversion) fail("Could not determine OS X version from Facter") if product_version.nil? product_version_major = product_version.scan(/(\d+)\.(\d+)./).join(".") end fail("#{product_version_major} is not supported by the directoryservice provider") if %w{10.0 10.1 10.2 10.3}.include?(product_version_major) @macosx_version_major = product_version_major return @macosx_version_major rescue Puppet::ExecutionFailure => detail fail("Could not determine OS X version: #{detail}") end end def self.list_all_present # JJM: List all objects of this Puppet::Type already present on the system. begin dscl_output = execute(get_exec_preamble("-list")) rescue Puppet::ExecutionFailure => detail fail("Could not get #{@resource_type.name} list from DirectoryService") end dscl_output.split("\n") end def self.parse_dscl_url_data(dscl_output) # we need to construct a Hash from the dscl -url output to match # that returned by the dscl -plist output for 10.5+ clients. # # Nasty assumptions: # a) no values *end* in a colon ':', only keys # b) if a line ends in a colon and the next line does start with # a space, then the second line is a value of the first. # c) (implied by (b)) keys don't start with spaces. dscl_plist = {} dscl_output.split("\n").inject([]) do |array, line| if line =~ /^\s+/ # it's a value array[-1] << line # add the value to the previous key else array << line end array end.compact dscl_output.each do |line| # This should be a 'normal' entry. key and value on one line. # We split on ': ' to deal with keys/values with a colon in them. split_array = line.split(/:\s+/) key = split_array.first value = CGI::unescape(split_array.last.strip.chomp) # We need to treat GroupMembership separately as it is currently # the only attribute we care about multiple values for, and # the values can never contain spaces (shortnames) # We also make every value an array to be consistent with the # output of dscl -plist under 10.5 if key == "GroupMembership" dscl_plist[key] = value.split(/\s/) else dscl_plist[key] = [value] end end dscl_plist end def self.parse_dscl_plist_data(dscl_output) Plist.parse_xml(dscl_output) end def self.generate_attribute_hash(input_hash, *type_properties) attribute_hash = {} input_hash.keys.each do |key| ds_attribute = key.sub("dsAttrTypeStandard:", "") next unless (@@ds_to_ns_attribute_map.keys.include?(ds_attribute) and type_properties.include? @@ds_to_ns_attribute_map[ds_attribute]) ds_value = input_hash[key] case @@ds_to_ns_attribute_map[ds_attribute] when :members ds_value = ds_value # only members uses arrays so far when :gid, :uid # OS X stores objects like uid/gid as strings. # Try casting to an integer for these cases to be # consistent with the other providers and the group type # validation begin ds_value = Integer(ds_value[0]) rescue ArgumentError ds_value = ds_value[0] end else ds_value = ds_value[0] end attribute_hash[@@ds_to_ns_attribute_map[ds_attribute]] = ds_value end # NBK: need to read the existing password here as it's not actually # stored in the user record. It is stored at a path that involves the # UUID of the user record for non-Mobile local acccounts. # Mobile Accounts are out of scope for this provider for now attribute_hash[:password] = self.get_password(attribute_hash[:guid]) if @resource_type.validproperties.include?(:password) and Puppet.features.root? attribute_hash end def self.single_report(resource_name, *type_properties) # JJM 2007-07-24: # Given a the name of an object and a list of properties of that # object, return all property values in a hash. # # This class method returns nil if the object doesn't exist # Otherwise, it returns a hash of the object properties. all_present_str_array = list_all_present # NBK: shortcut the process if the resource is missing return nil unless all_present_str_array.include? resource_name dscl_vector = get_exec_preamble("-read", resource_name) begin dscl_output = execute(dscl_vector) rescue Puppet::ExecutionFailure => detail fail("Could not get report. command execution failed.") end # Two code paths is ugly, but until we can drop 10.4 support we don't # have a lot of choice. Ultimately this should all be done using Ruby # to access the DirectoryService APIs directly, but that's simply not # feasible for a while yet. case self.get_macosx_version_major when "10.4" dscl_plist = self.parse_dscl_url_data(dscl_output) when "10.5", "10.6" dscl_plist = self.parse_dscl_plist_data(dscl_output) end self.generate_attribute_hash(dscl_plist, *type_properties) end def self.get_exec_preamble(ds_action, resource_name = nil) # JJM 2007-07-24 # DSCL commands are often repetitive and contain the same positional # arguments over and over. See http://developer.apple.com/documentation/Porting/Conceptual/PortingUnix/additionalfeatures/chapter_10_section_9.html # for an example of what I mean. # This method spits out proper DSCL commands for us. # We EXPECT name to be @resource[:name] when called from an instance object. # 10.4 doesn't support the -plist option for dscl, and 10.5 has a # different format for the -url output with objects with spaces in # their values. *sigh*. Use -url for 10.4 in the hope this can be # deprecated one day, and use -plist for 10.5 and higher. case self.get_macosx_version_major when "10.4" command_vector = [ command(:dscl), "-url", "." ] when "10.5", "10.6" command_vector = [ command(:dscl), "-plist", "." ] end # JJM: The actual action to perform. See "man dscl" # Common actiosn: -create, -delete, -merge, -append, -passwd command_vector << ds_action # JJM: get_ds_path will spit back "Users" or "Groups", # etc... Depending on the Puppet::Type of our self. if resource_name command_vector << "/#{get_ds_path}/#{resource_name}" else command_vector << "/#{get_ds_path}" end # JJM: This returns most of the preamble of the command. # e.g. 'dscl / -create /Users/mccune' command_vector end def self.set_password(resource_name, guid, password_hash) password_hash_file = "#{@@password_hash_dir}/#{guid}" begin File.open(password_hash_file, 'w') { |f| f.write(password_hash)} rescue Errno::EACCES => detail fail("Could not write to password hash file: #{detail}") end # NBK: For shadow hashes, the user AuthenticationAuthority must contain a value of # ";ShadowHash;". The LKDC in 10.5 makes this more interesting though as it # will dynamically generate ;Kerberosv5;;username@LKDC:SHA1 attributes if # missing. Thus we make sure we only set ;ShadowHash; if it is missing, and # we can do this with the merge command. This allows people to continue to # use other custom AuthenticationAuthority attributes without stomping on them. # # There is a potential problem here in that we're only doing this when setting # the password, and the attribute could get modified at other times while the # hash doesn't change and so this doesn't get called at all... but # without switching all the other attributes to merge instead of create I can't # see a simple enough solution for this that doesn't modify the user record # every single time. This should be a rather rare edge case. (famous last words) dscl_vector = self.get_exec_preamble("-merge", resource_name) dscl_vector << "AuthenticationAuthority" << ";ShadowHash;" begin dscl_output = execute(dscl_vector) rescue Puppet::ExecutionFailure => detail fail("Could not set AuthenticationAuthority.") end end def self.get_password(guid) password_hash = nil password_hash_file = "#{@@password_hash_dir}/#{guid}" if File.exists?(password_hash_file) and File.file?(password_hash_file) fail("Could not read password hash file at #{password_hash_file}") if not File.readable?(password_hash_file) f = File.new(password_hash_file) password_hash = f.read f.close end password_hash end + # Unlike most other *nixes, OS X doesn't provide built in functionality + # for automatically assigning uids and gids to accounts, so we set up these + # methods for consumption by functionality like --mkusers + # By default we restrict to a reasonably sane range for system accounts + def self.next_system_id(id_type, min_id=20) + dscl_args = ['.', '-list'] + if id_type == 'uid' + dscl_args << '/Users' << 'uid' + elsif id_type == 'gid' + dscl_args << '/Groups' << 'gid' + else + fail("Invalid id_type #{id_type}. Only 'uid' and 'gid' supported") + end + dscl_out = dscl(dscl_args) + # We're ok with throwing away negative uids here. + ids = dscl_out.split.compact.collect { |l| l.to_i if l.match(/^\d+$/) } + ids.compact!.sort! { |a,b| a.to_f <=> b.to_f } + # We're just looking for an unused id in our sorted array. + ids.each_index do |i| + next_id = ids[i] + 1 + return next_id if ids[i+1] != next_id and next_id >= min_id + end + end + + def ensure=(ensure_value) super # We need to loop over all valid properties for the type we're # managing and call the method which sets that property value # dscl can't create everything at once unfortunately. if ensure_value == :present @resource.class.validproperties.each do |name| next if name == :ensure # LAK: We use property.sync here rather than directly calling # the settor method because the properties might do some kind # of conversion. In particular, the user gid property might # have a string and need to convert it to a number if @resource.should(name) @resource.property(name).sync elsif value = autogen(name) self.send(name.to_s + "=", value) else next end end end end def password=(passphrase) exec_arg_vector = self.class.get_exec_preamble("-read", @resource.name) exec_arg_vector << @@ns_to_ds_attribute_map[:guid] begin guid_output = execute(exec_arg_vector) guid_plist = Plist.parse_xml(guid_output) # Although GeneratedUID like all DirectoryService values can be multi-valued # according to the schema, in practice user accounts cannot have multiple UUIDs # otherwise Bad Things Happen, so we just deal with the first value. guid = guid_plist["dsAttrTypeStandard:#{@@ns_to_ds_attribute_map[:guid]}"][0] self.class.set_password(@resource.name, guid, passphrase) rescue Puppet::ExecutionFailure => detail fail("Could not set #{param} on #{@resource.class.name}[#{@resource.name}]: #{detail}") end end # NBK: we override @parent.set as we need to execute a series of commands # to deal with array values, rather than the single command nameservice.rb # expects to be returned by modifycmd. Thus we don't bother defining modifycmd. def set(param, value) self.class.validate(param, value) current_members = @property_value_cache_hash[:members] if param == :members # If we are meant to be authoritative for the group membership # then remove all existing members who haven't been specified # in the manifest. remove_unwanted_members(current_members, value) if @resource[:auth_membership] and not current_members.nil? # if they're not a member, make them one. add_members(current_members, value) else exec_arg_vector = self.class.get_exec_preamble("-create", @resource[:name]) # JJM: The following line just maps the NS name to the DS name # e.g. { :uid => 'UniqueID' } exec_arg_vector << @@ns_to_ds_attribute_map[symbolize(param)] # JJM: The following line sends the actual value to set the property to exec_arg_vector << value.to_s begin execute(exec_arg_vector) rescue Puppet::ExecutionFailure => detail fail("Could not set #{param} on #{@resource.class.name}[#{@resource.name}]: #{detail}") end end end # NBK: we override @parent.create as we need to execute a series of commands # to create objects with dscl, rather than the single command nameservice.rb # expects to be returned by addcmd. Thus we don't bother defining addcmd. def create if exists? info "already exists" return nil end # NBK: First we create the object with a known guid so we can set the contents # of the password hash if required # Shelling out sucks, but for a single use case it doesn't seem worth # requiring people install a UUID library that doesn't come with the system. # This should be revisited if Puppet starts managing UUIDs for other platform # user records. guid = %x{/usr/bin/uuidgen}.chomp exec_arg_vector = self.class.get_exec_preamble("-create", @resource[:name]) exec_arg_vector << @@ns_to_ds_attribute_map[:guid] << guid begin execute(exec_arg_vector) rescue Puppet::ExecutionFailure => detail fail("Could not set GeneratedUID for #{@resource.class.name} #{@resource.name}: #{detail}") end if value = @resource.should(:password) and value != "" self.class.set_password(@resource[:name], guid, value) end # Now we create all the standard properties Puppet::Type.type(@resource.class.name).validproperties.each do |property| next if property == :ensure - if value = @resource.should(property) and value != "" + value = @resource.should(property) + if property == :gid and value.nil? + value = self.class.next_system_id(id_type='gid') + end + if property == :uid and value.nil? + value = self.class.next_system_id(id_type='uid') + end + if value != "" and not value.nil? if property == :members add_members(nil, value) else exec_arg_vector = self.class.get_exec_preamble("-create", @resource[:name]) exec_arg_vector << @@ns_to_ds_attribute_map[symbolize(property)] next if property == :password # skip setting the password here exec_arg_vector << value.to_s begin execute(exec_arg_vector) rescue Puppet::ExecutionFailure => detail fail("Could not create #{@resource.class.name} #{@resource.name}: #{detail}") end end end end end def remove_unwanted_members(current_members, new_members) current_members.each do |member| if not new_members.include?(member) cmd = [:dseditgroup, "-o", "edit", "-n", ".", "-d", member, @resource[:name]] begin execute(cmd) rescue Puppet::ExecutionFailure => detail fail("Could not remove #{member} from group: #{@resource.name}, #{detail}") end end end end def add_members(current_members, new_members) new_members.each do |new_member| if current_members.nil? or not current_members.include?(new_member) cmd = [:dseditgroup, "-o", "edit", "-n", ".", "-a", new_member, @resource[:name]] begin execute(cmd) rescue Puppet::ExecutionFailure => detail fail("Could not add #{new_member} to group: #{@resource.name}, #{detail}") end end end end def deletecmd # JJM: Like addcmd, only called when deleting the object itself # Note, this isn't used to delete properties of the object, # at least that's how I understand it... self.class.get_exec_preamble("-delete", @resource[:name]) end def getinfo(refresh = false) # JJM 2007-07-24: # Override the getinfo method, which is also defined in nameservice.rb # This method returns and sets @infohash # I'm not re-factoring the name "getinfo" because this method will be # most likely called by nameservice.rb, which I didn't write. if refresh or (! defined?(@property_value_cache_hash) or ! @property_value_cache_hash) # JJM 2007-07-24: OK, there's a bit of magic that's about to # happen... Let's see how strong my grip has become... =) # # self is a provider instance of some Puppet::Type, like # Puppet::Type::User::ProviderDirectoryservice for the case of the # user type and this provider. # # self.class looks like "user provider directoryservice", if that # helps you ... # # self.class.resource_type is a reference to the Puppet::Type class, # probably Puppet::Type::User or Puppet::Type::Group, etc... # # self.class.resource_type.validproperties is a class method, # returning an Array of the valid properties of that specific # Puppet::Type. # # So... something like [:comment, :home, :password, :shell, :uid, # :groups, :ensure, :gid] # # Ultimately, we add :name to the list, delete :ensure from the # list, then report on the remaining list. Pretty whacky, ehh? type_properties = [:name] + self.class.resource_type.validproperties type_properties.delete(:ensure) if type_properties.include? :ensure type_properties << :guid # append GeneratedUID so we just get the report here @property_value_cache_hash = self.class.single_report(@resource[:name], *type_properties) [:uid, :gid].each do |param| @property_value_cache_hash[param] = @property_value_cache_hash[param].to_i if @property_value_cache_hash and @property_value_cache_hash.include?(param) end end @property_value_cache_hash end end end diff --git a/lib/puppet/resource/type.rb b/lib/puppet/resource/type.rb index 7b21e55dc..3edf286bb 100644 --- a/lib/puppet/resource/type.rb +++ b/lib/puppet/resource/type.rb @@ -1,334 +1,336 @@ require 'puppet/parser/parser' require 'puppet/util/warnings' require 'puppet/util/errors' require 'puppet/util/inline_docs' require 'puppet/parser/ast/leaf' require 'puppet/dsl' class Puppet::Resource::Type Puppet::ResourceType = self include Puppet::Util::InlineDocs include Puppet::Util::Warnings include Puppet::Util::Errors RESOURCE_SUPERTYPES = [:hostclass, :node, :definition] - attr_accessor :file, :line, :doc, :code, :ruby_code, :parent, :resource_type_collection, :module_name - attr_reader :type, :namespace, :arguments, :behaves_like + attr_accessor :file, :line, :doc, :code, :ruby_code, :parent, :resource_type_collection + attr_reader :type, :namespace, :arguments, :behaves_like, :module_name RESOURCE_SUPERTYPES.each do |t| define_method("#{t}?") { self.type == t } end require 'puppet/indirector' extend Puppet::Indirector indirects :resource_type, :terminus_class => :parser def self.from_pson(data) name = data.delete('name') or raise ArgumentError, "Resource Type names must be specified" type = data.delete('type') || "definition" data = data.inject({}) { |result, ary| result[ary[0].intern] = ary[1]; result } new(type, name, data) end def to_pson_data_hash data = [:code, :doc, :line, :file, :parent].inject({}) do |hash, param| next hash unless value = self.send(param) hash[param.to_s] = value hash end data['arguments'] = arguments.dup data['name'] = name data['type'] = type data end def to_pson(*args) to_pson_data_hash.to_pson(*args) end # Are we a child of the passed class? Do a recursive search up our # parentage tree to figure it out. def child_of?(klass) return false unless parent return(klass == parent_type ? true : parent_type.child_of?(klass)) end # Now evaluate the code associated with this class or definition. def evaluate_code(resource) scope = resource.scope if tmp = evaluate_parent_type(resource) scope = tmp end scope = subscope(scope, resource) unless resource.title == :main scope.compiler.add_class(name) unless definition? set_resource_parameters(resource, scope) code.safeevaluate(scope) if code evaluate_ruby_code(resource, scope) if ruby_code end def initialize(type, name, options = {}) @type = type.to_s.downcase.to_sym raise ArgumentError, "Invalid resource supertype '#{type}'" unless RESOURCE_SUPERTYPES.include?(@type) name = convert_from_ast(name) if name.is_a?(Puppet::Parser::AST::HostName) set_name_and_namespace(name) [:code, :doc, :line, :file, :parent].each do |param| next unless value = options[param] send(param.to_s + "=", value) end set_arguments(options[:arguments]) + + @module_name = options[:module_name] end # This is only used for node names, and really only when the node name # is a regexp. def match(string) return string.to_s.downcase == name unless name_is_regex? @name =~ string end # Add code from a new instance to our code. def merge(other) 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 fail "Cannot have code outside of a class/node/define because 'freeze_main' is enabled" if name == "" and Puppet.settings[:freeze_main] if parent and other.parent and parent != other.parent 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. self.parent ||= other.parent if other.doc self.doc ||= "" self.doc += other.doc end # This might just be an empty, stub class. return unless other.code unless self.code self.code = other.code return end array_class = Puppet::Parser::AST::ASTArray self.code = array_class.new(:children => [self.code]) unless self.code.is_a?(array_class) if other.code.is_a?(array_class) code.children += other.code.children else code.children << other.code end end # Make an instance of our resource type. This is only possible # for those classes and nodes that don't have any arguments, and is # only useful for things like the 'include' function. def mk_plain_resource(scope) type == :definition and raise ArgumentError, "Cannot create resources for defined resource types" resource_type = type == :hostclass ? :class : :node # Make sure our parent class has been evaluated, if we have one. if parent parent_resource = scope.catalog.resource(resource_type, parent) unless parent_resource parent_type(scope).mk_plain_resource(scope) end end # Do nothing if the resource already exists; this makes sure we don't # get multiple copies of the class resource, which helps provide the # singleton nature of classes. if resource = scope.catalog.resource(resource_type, name) return resource end resource = Puppet::Parser::Resource.new(resource_type, name, :scope => scope, :source => self) scope.compiler.add_resource(scope, resource) scope.catalog.tag(*resource.tags) resource end def name return @name unless @name.is_a?(Regexp) @name.source.downcase.gsub(/[^-\w:.]/,'').sub(/^\.+/,'') end def name_is_regex? @name.is_a?(Regexp) end # MQR TODO: # # The change(s) introduced by the fix for #4270 are mostly silly & should be # removed, though we didn't realize it at the time. If it can be established/ # ensured that nodes never call parent_type and that resource_types are always # (as they should be) members of exactly one resource_type_collection the # following method could / should be replaced with: # # def parent_type # @parent_type ||= parent && ( # resource_type_collection.find_or_load([name],parent,type.to_sym) || # fail Puppet::ParseError, "Could not find parent resource type '#{parent}' of type #{type} in #{resource_type_collection.environment}" # ) # end # # ...and then the rest of the changes around passing in scope reverted. # def parent_type(scope = nil) return nil unless parent unless @parent_type raise "Must pass scope to parent_type when called first time" unless scope unless @parent_type = scope.environment.known_resource_types.send("find_#{type}", [name], parent) fail Puppet::ParseError, "Could not find parent resource type '#{parent}' of type #{type} in #{scope.environment}" end end @parent_type end # Set any arguments passed by the resource as variables in the scope. def set_resource_parameters(resource, scope) set = {} resource.to_hash.each do |param, value| param = param.to_sym fail Puppet::ParseError, "#{resource.ref} does not accept attribute #{param}" unless valid_parameter?(param) exceptwrap { scope.setvar(param.to_s, value) } set[param] = true end # Verify that all required arguments are either present or # have been provided with defaults. arguments.each do |param, default| param = param.to_sym next if set.include?(param) # Even if 'default' is a false value, it's an AST value, so this works fine fail Puppet::ParseError, "Must pass #{param} to #{resource.ref}" unless default value = default.safeevaluate(scope) scope.setvar(param.to_s, value) # Set it in the resource, too, so the value makes it to the client. resource[param] = value end if @type == :hostclass scope.setvar("title", resource.title.to_s.downcase) unless set.include? :title scope.setvar("name", resource.name.to_s.downcase ) unless set.include? :name else scope.setvar("title", resource.title ) unless set.include? :title scope.setvar("name", resource.name ) unless set.include? :name end scope.setvar("module_name", module_name) if module_name and ! set.include? :module_name if caller_name = scope.parent_module_name and ! set.include?(:caller_module_name) scope.setvar("caller_module_name", caller_name) end scope.class_set(self.name,scope) if hostclass? or node? end # Create a new subscope in which to evaluate our code. def subscope(scope, resource) scope.newscope :resource => resource, :namespace => self.namespace, :source => self end # Check whether a given argument is valid. def valid_parameter?(param) param = param.to_s return true if param == "name" return true if Puppet::Type.metaparam?(param) return false unless defined?(@arguments) return(arguments.include?(param) ? true : false) end def set_arguments(arguments) @arguments = {} return if arguments.nil? arguments.each do |arg, default| arg = arg.to_s warn_if_metaparam(arg, default) @arguments[arg] = default end end private def convert_from_ast(name) value = name.value if value.is_a?(Puppet::Parser::AST::Regex) name = value.value else name = value end end def evaluate_parent_type(resource) return unless klass = parent_type(resource.scope) and parent_resource = resource.scope.compiler.catalog.resource(:class, klass.name) || resource.scope.compiler.catalog.resource(:node, klass.name) parent_resource.evaluate unless parent_resource.evaluated? parent_scope(resource.scope, klass) end def evaluate_ruby_code(resource, scope) Puppet::DSL::ResourceAPI.new(resource, scope, ruby_code).evaluate end # Split an fq name into a namespace and name def namesplit(fullname) ary = fullname.split("::") n = ary.pop || "" ns = ary.join("::") return ns, n end def parent_scope(scope, klass) scope.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 @namespace = "" else @name = name.to_s.downcase # Note we're doing something somewhat weird here -- we're setting # the class's namespace to its fully qualified name. This means # anything inside that class starts looking in that namespace first. @namespace, ignored_shortname = @type == :hostclass ? [@name, ''] : namesplit(@name) end end def warn_if_metaparam(param, default) return unless Puppet::Type.metaparamclass(param) if default warnonce "#{param} is a metaparam; this value will inherit to all contained resources" else raise Puppet::ParseError, "#{param} is a metaparameter; please choose another parameter name in the #{self.name} definition" end end end diff --git a/lib/puppet/resource/type_collection.rb b/lib/puppet/resource/type_collection.rb index 63d110395..a96927613 100644 --- a/lib/puppet/resource/type_collection.rb +++ b/lib/puppet/resource/type_collection.rb @@ -1,214 +1,204 @@ 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 = {} @definitions = {} @nodes = {} # So we can keep a list and match the first-defined regex @node_list = [] @watched_files = {} end + def import_ast(ast, modname) + ast.instantiate(modname).each do |instance| + add(instance) + end + end + def <<(thing) add(thing) self 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.resource_type_collection = self instance 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" } @hostclasses[instance.name] = instance instance end def hostclass(name) @hostclasses[munge_name(name)] end def add_node(instance) dupe_check(instance, @nodes) { |dupe| "Node '#{instance.name}' is already defined#{dupe.error_context}; cannot redefine" } @node_list << instance @nodes[instance.name] = instance instance end def loader require 'puppet/parser/type_loader' @loader ||= Puppet::Parser::TypeLoader.new(environment) end def node(name) name = munge_name(name) if node = @nodes[name] return node end @node_list.each do |node| next unless node.name_is_regex? return node if node.match(name) end nil end def node_exists?(name) @nodes[munge_name(name)] end def nodes? @nodes.length > 0 end 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) @definitions[munge_name(name)] end - def find(namespaces, name, type) - #Array("") == [] for some reason - namespaces = [namespaces] unless namespaces.is_a?(Array) - - if name =~ /^::/ - return send(type, name.sub(/^::/, '')) - end - - 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 - - if result = send(type, name) - return result - end - end - nil - end - - def find_or_load(namespaces, name, type) - name = name.downcase - namespaces = [namespaces] unless namespaces.is_a?(Array) - namespaces = namespaces.collect { |ns| ns.downcase } - - # This could be done in the load_until, but the knowledge seems to - # belong here. - if r = find(namespaces, name, type) - return r - end - - loader.load_until(namespaces, name) { find(namespaces, name, type) } - end - def find_node(namespaces, name) - find("", name, :node) + @nodes[munge_name(name)] end def find_hostclass(namespaces, name) find_or_load(namespaces, name, :hostclass) end def find_definition(namespaces, name) find_or_load(namespaces, name, :definition) end [:hostclasses, :nodes, :definitions].each do |m| define_method(m) do instance_variable_get("@#{m}").dup end end - def perform_initial_import - return if Puppet.settings[:ignoreimport] - parser = Puppet::Parser::Parser.new(environment) - if code = Puppet.settings.uninterpolated_value(:code, environment.to_s) and code != "" - parser.string = code - else - file = Puppet.settings.value(:manifest, environment.to_s) - return unless File.exist?(file) - parser.file = file - end - parser.parse - rescue => detail - msg = "Could not parse for environment #{environment}: #{detail}" - error = Puppet::Error.new(msg) - error.set_backtrace(detail.backtrace) - raise error - end - def stale? @watched_files.values.detect { |file| file.changed? } end def version return @version if defined?(@version) if environment[:config_version] == "" @version = Time.now.to_i return @version end @version = Puppet::Util.execute([environment[:config_version]]).strip rescue Puppet::ExecutionFailure => e raise Puppet::ParseError, "Unable to set config_version: #{e.message}" end def watch_file(file) @watched_files[file] = Puppet::Util::LoadedFile.new(file) end def watching_file?(file) @watched_files.include?(file) end private - def find_partially_qualified(namespace, name, type) - send(type, [namespace, name].join("::")) + # Return a list of all possible fully-qualified names that might be + # meant by the given name, in the context of namespaces. + def resolve_namespaces(namespaces, name) + name = name.downcase + if name =~ /^::/ + # name is explicitly fully qualified, so just return it, sans + # initial "::". + return [name.sub(/^::/, '')] + end + if name == "" + # The name "" has special meaning--it always refers to a "main" + # hostclass which contains all toplevel resources. + return [""] + end + + namespaces = [namespaces] unless namespaces.is_a?(Array) + namespaces = namespaces.collect { |ns| ns.downcase } + + result = [] + namespaces.each do |namespace| + ary = namespace.split("::") + + # Search each namespace nesting in innermost-to-outermost order. + while ary.length > 0 + result << "#{ary.join("::")}::#{name}" + ary.pop + end + + # Finally, search the toplevel namespace. + result << name + end + + return result.uniq + end + + # Resolve namespaces and find the given object. Autoload it if + # necessary. + def find_or_load(namespaces, name, type) + resolve_namespaces(namespaces, name).each do |fqname| + if result = send(type, fqname) || loader.try_load_fqname(type, fqname) + return result + end + end + + # Nothing found. + return nil end def munge_name(name) name.to_s.downcase end def dupe_check(instance, hash) return unless dupe = hash[instance.name] message = yield dupe instance.fail Puppet::ParseError, message end end diff --git a/lib/puppet/util/rdoc/parser.rb b/lib/puppet/util/rdoc/parser.rb index f9becede1..ce34442ab 100644 --- a/lib/puppet/util/rdoc/parser.rb +++ b/lib/puppet/util/rdoc/parser.rb @@ -1,480 +1,485 @@ # Puppet "parser" for the rdoc system # The parser uses puppet parser and traverse the AST to instruct RDoc about # our current structures. It also parses ruby files that could contain # either custom facts or puppet plugins (functions, types...) # rdoc mandatory includes require "rdoc/code_objects" require "puppet/util/rdoc/code_objects" require "rdoc/tokenstream" require "rdoc/markup/simple_markup/preprocess" require "rdoc/parsers/parserfactory" module RDoc class Parser extend ParserFactory SITE = "__site__" - attr_accessor :ast, :input_file_name, :top_level + attr_accessor :input_file_name, :top_level # parser registration into RDoc parse_files_matching(/\.(rb|pp)$/) # called with the top level file def initialize(top_level, file_name, content, options, stats) @options = options @stats = stats @input_file_name = file_name @top_level = PuppetTopLevel.new(top_level) @progress = $stderr unless options.quiet end # main entry point def scan - env = Puppet::Node::Environment.new - unless env.known_resource_types.watching_file?(@input_file_name) + environment = Puppet::Node::Environment.new + unless environment.known_resource_types.watching_file?(@input_file_name) Puppet.info "rdoc: scanning #{@input_file_name}" if @input_file_name =~ /\.pp$/ - @parser = Puppet::Parser::Parser.new(env) + @parser = Puppet::Parser::Parser.new(environment) @parser.file = @input_file_name - @ast = @parser.parse + @known_resource_types = environment.known_resource_types + @parser.parse.instantiate('').each do |type| + @known_resource_types.add type + end + scan_top_level(@top_level) end - scan_top_level(@top_level) end @top_level end # Due to a bug in RDoc, we need to roll our own find_module_named # The issue is that RDoc tries harder by asking the parent for a class/module # of the name. But by doing so, it can mistakenly use a module of same name # but from which we are not descendant. def find_object_named(container, name) return container if container.name == name container.each_classmodule do |m| return m if m.name == name end nil end # walk down the namespace and lookup/create container as needed def get_class_or_module(container, name) # class ::A -> A is in the top level if name =~ /^::/ container = @top_level end names = name.split('::') final_name = names.pop names.each do |name| prev_container = container container = find_object_named(container, name) container ||= prev_container.add_class(PuppetClass, name, nil) end [container, final_name] end # split_module tries to find if +path+ belongs to the module path # if it does, it returns the module name, otherwise if we are sure # it is part of the global manifest path, "__site__" is returned. # And finally if this path couldn't be mapped anywhere, nil is returned. def split_module(path) # find a module fullpath = File.expand_path(path) Puppet.debug "rdoc: testing #{fullpath}" if fullpath =~ /(.*)\/([^\/]+)\/(?:manifests|plugins|lib)\/.+\.(pp|rb)$/ modpath = $1 name = $2 Puppet.debug "rdoc: module #{name} into #{modpath} ?" Puppet::Module.modulepath.each do |mp| if File.identical?(modpath,mp) Puppet.debug "rdoc: found module #{name}" return name end end end if fullpath =~ /\.(pp|rb)$/ # there can be paths we don't want to scan under modules # imagine a ruby or manifest that would be distributed as part as a module # but we don't want those to be hosted under Puppet::Module.modulepath.each do |mp| # check that fullpath is a descendant of mp dirname = fullpath while (dirname = File.dirname(dirname)) != '/' return nil if File.identical?(dirname,mp) end end end # we are under a global manifests Puppet.debug "rdoc: global manifests" SITE end # create documentation for the top level +container+ def scan_top_level(container) # use the module README as documentation for the module comment = "" readme = File.join(File.dirname(File.dirname(@input_file_name)), "README") comment = File.open(readme,"r") { |f| f.read } if FileTest.readable?(readme) look_for_directives_in(container, comment) unless comment.empty? # infer module name from directory name = split_module(@input_file_name) if name.nil? # skip .pp files that are not in manifests directories as we can't guarantee they're part # of a module or the global configuration. container.document_self = false return end Puppet.debug "rdoc: scanning for #{name}" container.module_name = name container.global=true if name == SITE @stats.num_modules += 1 container, name = get_class_or_module(container,name) mod = container.add_module(PuppetModule, name) mod.record_location(@top_level) mod.comment = comment if @input_file_name =~ /\.pp$/ parse_elements(mod) elsif @input_file_name =~ /\.rb$/ parse_plugins(mod) end end # create documentation for include statements we can find in +code+ # and associate it with +container+ def scan_for_include_or_require(container, code) code = [code] unless code.is_a?(Array) code.each do |stmt| scan_for_include_or_require(container,stmt.children) if stmt.is_a?(Puppet::Parser::AST::ASTArray) if stmt.is_a?(Puppet::Parser::AST::Function) and ['include','require'].include?(stmt.name) stmt.arguments.each do |included| Puppet.debug "found #{stmt.name}: #{included.value}" container.send("add_#{stmt.name}",Include.new(included.value, stmt.doc)) end end end end # create documentation for realize statements we can find in +code+ # and associate it with +container+ def scan_for_realize(container, code) code = [code] unless code.is_a?(Array) code.each do |stmt| scan_for_realize(container,stmt.children) if stmt.is_a?(Puppet::Parser::AST::ASTArray) if stmt.is_a?(Puppet::Parser::AST::Function) and stmt.name == 'realize' stmt.arguments.each do |realized| Puppet.debug "found #{stmt.name}: #{realized}" container.add_realize(Include.new(realized.to_s, stmt.doc)) end end end end # create documentation for global variables assignements we can find in +code+ # and associate it with +container+ def scan_for_vardef(container, code) code = [code] unless code.is_a?(Array) code.each do |stmt| scan_for_vardef(container,stmt.children) if stmt.is_a?(Puppet::Parser::AST::ASTArray) if stmt.is_a?(Puppet::Parser::AST::VarDef) Puppet.debug "rdoc: found constant: #{stmt.name} = #{stmt.value}" container.add_constant(Constant.new(stmt.name.to_s, stmt.value.to_s, stmt.doc)) end end end # create documentation for resources we can find in +code+ # and associate it with +container+ def scan_for_resource(container, code) code = [code] unless code.is_a?(Array) code.each do |stmt| scan_for_resource(container,stmt.children) if stmt.is_a?(Puppet::Parser::AST::ASTArray) if stmt.is_a?(Puppet::Parser::AST::Resource) and !stmt.type.nil? begin type = stmt.type.split("::").collect { |s| s.capitalize }.join("::") - title = stmt.title.is_a?(Puppet::Parser::AST::ASTArray) ? stmt.title.to_s.gsub(/\[(.*)\]/,'\1') : stmt.title.to_s - Puppet.debug "rdoc: found resource: #{type}[#{title}]" + stmt.instances.each do |inst| + title = inst.title.is_a?(Puppet::Parser::AST::ASTArray) ? inst.title.to_s.gsub(/\[(.*)\]/,'\1') : inst.title.to_s + Puppet.debug "rdoc: found resource: #{type}[#{title}]" - param = [] - stmt.parameters.children.each do |p| - res = {} - res["name"] = p.param - res["value"] = "#{p.value.to_s}" unless p.value.nil? + param = [] + inst.parameters.children.each do |p| + res = {} + res["name"] = p.param + res["value"] = "#{p.value.to_s}" unless p.value.nil? - param << res - end + param << res + end - container.add_resource(PuppetResource.new(type, title, stmt.doc, param)) + container.add_resource(PuppetResource.new(type, title, stmt.doc, param)) + end rescue => detail raise Puppet::ParseError, "impossible to parse resource in #{stmt.file} at line #{stmt.line}: #{detail}" end end end end def resource_stmt_to_ref(stmt) type = stmt.type.split("::").collect { |s| s.capitalize }.join("::") title = stmt.title.is_a?(Puppet::Parser::AST::ASTArray) ? stmt.title.to_s.gsub(/\[(.*)\]/,'\1') : stmt.title.to_s param = stmt.params.children.collect do |p| {"name" => p.param, "value" => p.value.to_s} end PuppetResource.new(type, title, stmt.doc, param) end # create documentation for a class named +name+ def document_class(name, klass, container) Puppet.debug "rdoc: found new class #{name}" container, name = get_class_or_module(container, name) superclass = klass.parent superclass = "" if superclass.nil? or superclass.empty? @stats.num_classes += 1 comment = klass.doc look_for_directives_in(container, comment) unless comment.empty? cls = container.add_class(PuppetClass, name, superclass) # it is possible we already encountered this class, while parsing some namespaces # from other classes of other files. But at that time we couldn't know this class superclass # so, now we know it and force it. cls.superclass = superclass cls.record_location(@top_level) # scan class code for include code = klass.code.children if klass.code.is_a?(Puppet::Parser::AST::ASTArray) code ||= klass.code unless code.nil? scan_for_include_or_require(cls, code) scan_for_realize(cls, code) scan_for_resource(cls, code) if Puppet.settings[:document_all] end cls.comment = comment rescue => detail raise Puppet::ParseError, "impossible to parse class '#{name}' in #{klass.file} at line #{klass.line}: #{detail}" end # create documentation for a node def document_node(name, node, container) Puppet.debug "rdoc: found new node #{name}" superclass = node.parent superclass = "" if superclass.nil? or superclass.empty? comment = node.doc look_for_directives_in(container, comment) unless comment.empty? n = container.add_node(name, superclass) n.record_location(@top_level) code = node.code.children if node.code.is_a?(Puppet::Parser::AST::ASTArray) code ||= node.code unless code.nil? scan_for_include_or_require(n, code) scan_for_realize(n, code) scan_for_vardef(n, code) scan_for_resource(n, code) if Puppet.settings[:document_all] end n.comment = comment rescue => detail raise Puppet::ParseError, "impossible to parse node '#{name}' in #{node.file} at line #{node.line}: #{detail}" end # create documentation for a define def document_define(name, define, container) Puppet.debug "rdoc: found new definition #{name}" # find superclas if any @stats.num_methods += 1 # find the parent # split define name by :: to find the complete module hierarchy container, name = get_class_or_module(container,name) # build up declaration declaration = "" define.arguments.each do |arg,value| declaration << "\$#{arg}" unless value.nil? declaration << " => " case value when Puppet::Parser::AST::Leaf declaration << "'#{value.value}'" when Puppet::Parser::AST::ASTArray declaration << "[#{value.children.collect { |v| "'#{v}'" }.join(", ")}]" else declaration << "#{value.to_s}" end end declaration << ", " end declaration.chop!.chop! if declaration.size > 1 # register method into the container meth = AnyMethod.new(declaration, name) meth.comment = define.doc container.add_method(meth) look_for_directives_in(container, meth.comment) unless meth.comment.empty? meth.params = "( #{declaration} )" meth.visibility = :public meth.document_self = true meth.singleton = false rescue => detail raise Puppet::ParseError, "impossible to parse definition '#{name}' in #{define.file} at line #{define.line}: #{detail}" end # Traverse the AST tree and produce code-objects node # that contains the documentation def parse_elements(container) Puppet.debug "rdoc: scanning manifest" - @ast.hostclasses.values.sort { |a,b| a.name <=> b.name }.each do |klass| + @known_resource_types.hostclasses.values.sort { |a,b| a.name <=> b.name }.each do |klass| name = klass.name if klass.file == @input_file_name unless name.empty? document_class(name,klass,container) else # on main class document vardefs code = klass.code.children if klass.code.is_a?(Puppet::Parser::AST::ASTArray) code ||= klass.code scan_for_vardef(container, code) unless code.nil? end end end - @ast.definitions.each do |name, define| + @known_resource_types.definitions.each do |name, define| if define.file == @input_file_name document_define(name,define,container) end end - @ast.nodes.each do |name, node| + @known_resource_types.nodes.each do |name, node| if node.file == @input_file_name document_node(name.to_s,node,container) end end end # create documentation for plugins def parse_plugins(container) Puppet.debug "rdoc: scanning plugin or fact" if @input_file_name =~ /\/facter\/[^\/]+\.rb$/ parse_fact(container) else parse_puppet_plugin(container) end end # this is a poor man custom fact parser :-) def parse_fact(container) comments = "" current_fact = nil File.open(@input_file_name) do |of| of.each do |line| # fetch comments if line =~ /^[ \t]*# ?(.*)$/ comments += $1 + "\n" elsif line =~ /^[ \t]*Facter.add\(['"](.*?)['"]\)/ current_fact = Fact.new($1,{}) look_for_directives_in(container, comments) unless comments.empty? current_fact.comment = comments container.add_fact(current_fact) current_fact.record_location(@top_level) comments = "" Puppet.debug "rdoc: found custom fact #{current_fact.name}" elsif line =~ /^[ \t]*confine[ \t]*:(.*?)[ \t]*=>[ \t]*(.*)$/ current_fact.confine = { :type => $1, :value => $2 } unless current_fact.nil? else # unknown line type comments ="" end end end end # this is a poor man puppet plugin parser :-) # it doesn't extract doc nor desc :-( def parse_puppet_plugin(container) comments = "" current_plugin = nil File.open(@input_file_name) do |of| of.each do |line| # fetch comments if line =~ /^[ \t]*# ?(.*)$/ comments += $1 + "\n" elsif line =~ /^[ \t]*newfunction[ \t]*\([ \t]*:(.*?)[ \t]*,[ \t]*:type[ \t]*=>[ \t]*(:rvalue|:lvalue)\)/ current_plugin = Plugin.new($1, "function") container.add_plugin(current_plugin) look_for_directives_in(container, comments) unless comments.empty? current_plugin.comment = comments current_plugin.record_location(@top_level) comments = "" Puppet.debug "rdoc: found new function plugins #{current_plugin.name}" elsif line =~ /^[ \t]*Puppet::Type.newtype[ \t]*\([ \t]*:(.*?)\)/ current_plugin = Plugin.new($1, "type") container.add_plugin(current_plugin) look_for_directives_in(container, comments) unless comments.empty? current_plugin.comment = comments current_plugin.record_location(@top_level) comments = "" Puppet.debug "rdoc: found new type plugins #{current_plugin.name}" elsif line =~ /module Puppet::Parser::Functions/ # skip else # unknown line type comments ="" end end end end # look_for_directives_in scans the current +comment+ for RDoc directives def look_for_directives_in(context, comment) preprocess = SM::PreProcess.new(@input_file_name, @options.rdoc_include) preprocess.handle(comment) do |directive, param| case directive when "stopdoc" context.stop_doc "" when "startdoc" context.start_doc context.force_documentation = true "" when "enddoc" #context.done_documenting = true #"" throw :enddoc when "main" options = Options.instance options.main_page = param "" when "title" options = Options.instance options.title = param "" when "section" context.set_current_section(param, comment) comment.replace("") # 1.8 doesn't support #clear break else warn "Unrecognized directive '#{directive}'" break end end remove_private_comments(comment) end def remove_private_comments(comment) comment.gsub!(/^#--.*?^#\+\+/m, '') comment.sub!(/^#--.*/m, '') end end end diff --git a/lib/puppet/util/zaml.rb b/lib/puppet/util/zaml.rb index 64c58f9a3..ae4da8612 100644 --- a/lib/puppet/util/zaml.rb +++ b/lib/puppet/util/zaml.rb @@ -1,318 +1,317 @@ # # ZAML -- A partial replacement for YAML, writen with speed and code clarity # in mind. ZAML fixes one YAML bug (loading Exceptions) and provides # a replacement for YAML.dump unimaginatively called ZAML.dump, # which is faster on all known cases and an order of magnitude faster # with complex structures. # # http://github.com/hallettj/zaml # # Authors: Markus Roberts, Jesse Hallett, Ian McIntosh, Igal Koshevoy, Simon Chiang # require 'yaml' class ZAML VERSION = "0.1.1" # # Class Methods # def self.dump(stuff, where='') z = new stuff.to_zaml(z) where << z.to_s end # # Instance Methods # def initialize @result = [] @indent = nil @structured_key_prefix = nil - Label.counter_reset + @previously_emitted_object = {} + @next_free_label_number = 0 emit('--- ') end def nested(tail=' ') old_indent = @indent @indent = "#{@indent || "\n"}#{tail}" yield @indent = old_indent end class Label # # YAML only wants objects in the datastream once; if the same object # occurs more than once, we need to emit a label ("&idxxx") on the # first occurrence and then emit a back reference (*idxxx") on any # subsequent occurrence(s). # # To accomplish this we keeps a hash (by object id) of the labels of # the things we serialize as we begin to serialize them. The labels # initially serialize as an empty string (since most objects are only # going to be be encountered once), but can be changed to a valid # (by assigning it a number) the first time it is subsequently used, # if it ever is. Note that we need to do the label setup BEFORE we # start to serialize the object so that circular structures (in # which we will encounter a reference to the object as we serialize # it can be handled). # - def self.counter_reset - @@previously_emitted_object = {} - @@next_free_label_number = 0 - end + attr_accessor :this_label_number def initialize(obj,indent) @indent = indent @this_label_number = nil - @@previously_emitted_object[obj.object_id] = self end def to_s @this_label_number ? ('&id%03d%s' % [@this_label_number, @indent]) : '' end def reference - @this_label_number ||= (@@next_free_label_number += 1) @reference ||= '*id%03d' % @this_label_number end - def self.for(obj) - @@previously_emitted_object[obj.object_id] - end + end + def label_for(obj) + @previously_emitted_object[obj.object_id] end def new_label_for(obj) - Label.new(obj,(Hash === obj || Array === obj) ? "#{@indent || "\n"} " : ' ') + label = Label.new(obj,(Hash === obj || Array === obj) ? "#{@indent || "\n"} " : ' ') + @previously_emitted_object[obj.object_id] = label + label end def first_time_only(obj) - if label = Label.for(obj) + if label = label_for(obj) + label.this_label_number ||= (@next_free_label_number += 1) emit(label.reference) else if @structured_key_prefix and not obj.is_a? String emit(@structured_key_prefix) @structured_key_prefix = nil end emit(new_label_for(obj)) yield end end def emit(s) @result << s @recent_nl = false unless s.kind_of?(Label) end def nl(s='') emit(@indent || "\n") unless @recent_nl emit(s) @recent_nl = true end def to_s @result.join end def prefix_structured_keys(x) @structured_key_prefix = x yield nl unless @structured_key_prefix @structured_key_prefix = nil end end ################################################################ # # Behavior for custom classes # ################################################################ class Object def to_yaml_properties instance_variables.sort # Default YAML behavior end def zamlized_class_name(root) cls = self.class "!ruby/#{root.name.downcase}#{cls == root ? '' : ":#{cls.respond_to?(:name) ? cls.name : cls}"}" end def to_zaml(z) z.first_time_only(self) { z.emit(zamlized_class_name(Object)) z.nested { instance_variables = to_yaml_properties if instance_variables.empty? z.emit(" {}") else instance_variables.each { |v| z.nl v[1..-1].to_zaml(z) # Remove leading '@' z.emit(': ') instance_variable_get(v).to_zaml(z) } end } } end end ################################################################ # # Behavior for built-in classes # ################################################################ class NilClass def to_zaml(z) z.emit('') # NOTE: blank turns into nil in YAML.load end end class Symbol def to_zaml(z) z.emit(self.inspect) end end class TrueClass def to_zaml(z) z.emit('true') end end class FalseClass def to_zaml(z) z.emit('false') end end class Numeric def to_zaml(z) z.emit(self) end end class Regexp def to_zaml(z) z.first_time_only(self) { z.emit("#{zamlized_class_name(Regexp)} #{inspect}") } end end class Exception def to_zaml(z) z.emit(zamlized_class_name(Exception)) z.nested { z.nl("message: ") message.to_zaml(z) } end # # Monkey patch for buggy Exception restore in YAML # # This makes it work for now but is not very future-proof; if things # change we'll most likely want to remove this. To mitigate the risks # as much as possible, we test for the bug before appling the patch. # if respond_to? :yaml_new and yaml_new(self, :tag, "message" => "blurp").message != "blurp" def self.yaml_new( klass, tag, val ) o = YAML.object_maker( klass, {} ).exception(val.delete( 'message')) val.each_pair do |k,v| o.instance_variable_set("@#{k}", v) end o end end end class String ZAML_ESCAPES = %w{\x00 \x01 \x02 \x03 \x04 \x05 \x06 \a \x08 \t \n \v \f \r \x0e \x0f \x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17 \x18 \x19 \x1a \e \x1c \x1d \x1e \x1f } def escaped_for_zaml gsub( /\x5C/, "\\\\\\" ). # Demi-kludge for Maglev/rubinius; the regexp should be /\\/ but parsetree chokes on that. gsub( /"/, "\\\"" ). gsub( /([\x00-\x1F])/ ) { |x| ZAML_ESCAPES[ x.unpack("C")[0] ] }. gsub( /([\x80-\xFF])/ ) { |x| "\\x#{x.unpack("C")[0].to_s(16)}" } end def to_zaml(z) z.first_time_only(self) { num = '[-+]?(0x)?\d+\.?\d*' case when self == '' z.emit('""') # when self =~ /[\x00-\x08\x0B\x0C\x0E-\x1F\x80-\xFF]/ # z.emit("!binary |\n") # z.emit([self].pack("m*")) when ( (self =~ /\A(true|false|yes|no|on|null|off|#{num}(:#{num})*|!|=|~)$/i) or (self =~ /\A\n* /) or (self =~ /[\s:]$/) or (self =~ /^[>|][-+\d]*\s/i) or (self[-1..-1] =~ /\s/) or (self =~ /[\x00-\x08\x0B\x0C\x0E-\x1F\x80-\xFF]/) or (self =~ /[,\[\]\{\}\r\t]|:\s|\s#/) or (self =~ /\A([-:?!#&*'"]|<<|%.+:.)/) ) z.emit("\"#{escaped_for_zaml}\"") when self =~ /\n/ if self[-1..-1] == "\n" then z.emit('|+') else z.emit('|-') end z.nested { split("\n",-1).each { |line| z.nl; z.emit(line.chomp("\n")) } } else z.emit(self) end } end end class Hash def to_zaml(z) z.first_time_only(self) { z.nested { if empty? z.emit('{}') else each_pair { |k, v| z.nl z.prefix_structured_keys('? ') { k.to_zaml(z) } z.emit(': ') v.to_zaml(z) } end } } end end class Array def to_zaml(z) z.first_time_only(self) { z.nested { if empty? z.emit('[]') else each { |v| z.nl('- '); v.to_zaml(z) } end } } end end class Time def to_zaml(z) # 2008-12-06 10:06:51.373758 -07:00 ms = ("%0.6f" % (usec * 1e-6)).sub(/^\d+\./,'') offset = "%+0.2i:%0.2i" % [utc_offset / 3600, (utc_offset / 60) % 60] z.emit(self.strftime("%Y-%m-%d %H:%M:%S.#{ms} #{offset}")) end end class Date def to_zaml(z) z.emit(strftime('%Y-%m-%d')) end end class Range def to_zaml(z) z.first_time_only(self) { z.emit(zamlized_class_name(Range)) z.nested { z.nl z.emit('begin: ') z.emit(first) z.nl z.emit('end: ') z.emit(last) z.nl z.emit('excl: ') z.emit(exclude_end?) } } end end diff --git a/spec/integration/parser/collector_spec.rb b/spec/integration/parser/collector_spec.rb index 73273c909..b1cfc51c7 100755 --- a/spec/integration/parser/collector_spec.rb +++ b/spec/integration/parser/collector_spec.rb @@ -1,38 +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 + return parser.parse(code).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/compiler_spec.rb b/spec/integration/parser/compiler_spec.rb index f80221e3d..f731692b3 100755 --- a/spec/integration/parser/compiler_spec.rb +++ b/spec/integration/parser/compiler_spec.rb @@ -1,93 +1,134 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../spec_helper' describe Puppet::Parser::Compiler do before :each do @node = Puppet::Node.new "testnode" @scope_resource = stub 'scope_resource', :builtin? => true, :finish => nil, :ref => 'Class[main]' @scope = stub 'scope', :resource => @scope_resource, :source => mock("source") end after do Puppet.settings.clear end it "should be able to determine the configuration version from a local version control repository" do # This should always work, because we should always be # in the puppet repo when we run this. version = %x{git rev-parse HEAD}.chomp Puppet.settings[:config_version] = 'git rev-parse HEAD' @parser = Puppet::Parser::Parser.new "development" @compiler = Puppet::Parser::Compiler.new(@node) @compiler.catalog.version.should == version end it "should not create duplicate resources when a class is referenced both directly and indirectly by the node classifier (4792)" do Puppet[:code] = <<-PP class foo { notify { foo_notify: } include bar } class bar { notify { bar_notify: } } PP @node.stubs(:classes).returns(['foo', 'bar']) catalog = Puppet::Parser::Compiler.compile(@node) catalog.resource("Notify[foo_notify]").should_not be_nil catalog.resource("Notify[bar_notify]").should_not be_nil end describe "when resolving class references" do it "should favor local scope, even if there's an included class in topscope" do Puppet[:code] = <<-PP class experiment { class baz { } notify {"x" : require => Class[Baz] } } class baz { } include baz include experiment include experiment::baz PP catalog = Puppet::Parser::Compiler.compile(Puppet::Node.new("mynode")) notify_resource = catalog.resource( "Notify[x]" ) notify_resource[:require].title.should == "Experiment::Baz" end it "should favor local scope, even if there's an unincluded class in topscope" do Puppet[:code] = <<-PP class experiment { class baz { } notify {"x" : require => Class[Baz] } } class baz { } include experiment include experiment::baz PP catalog = Puppet::Parser::Compiler.compile(Puppet::Node.new("mynode")) notify_resource = catalog.resource( "Notify[x]" ) notify_resource[:require].title.should == "Experiment::Baz" end end + + it "should recompute the version after input files are re-parsed" do + Puppet[:code] = 'class foo { }' + Time.stubs(:now).returns(1) + node = Puppet::Node.new('mynode') + Puppet::Parser::Compiler.compile(node).version.should == 1 + Time.stubs(:now).returns(2) + Puppet::Parser::Compiler.compile(node).version.should == 1 # no change because files didn't change + Puppet::Resource::TypeCollection.any_instance.stubs(:stale?).returns(true).then.returns(false) # pretend change + Puppet::Parser::Compiler.compile(node).version.should == 2 + end + + ['class', 'define', 'node'].each do |thing| + it "should not allow #{thing} inside evaluated conditional constructs" do + Puppet[:code] = <<-PP + if true { + #{thing} foo { + } + notify { decoy: } + } + PP + + begin + Puppet::Parser::Compiler.compile(Puppet::Node.new("mynode")) + raise "compilation should have raised Puppet::Error" + rescue Puppet::Error => e + e.message.should =~ /at line 2/ + end + end + end + + it "should not allow classes inside unevaluated conditional constructs" do + Puppet[:code] = <<-PP + if false { + class foo { + } + } + PP + + lambda { Puppet::Parser::Compiler.compile(Puppet::Node.new("mynode")) }.should raise_error(Puppet::Error) + end end diff --git a/spec/integration/parser/parser_spec.rb b/spec/integration/parser/parser_spec.rb index 7b85bcacb..0d9aa51e1 100755 --- a/spec/integration/parser/parser_spec.rb +++ b/spec/integration/parser/parser_spec.rb @@ -1,113 +1,115 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../spec_helper' describe Puppet::Parser::Parser do module ParseMatcher class ParseAs def initialize(klass) @parser = Puppet::Parser::Parser.new "development" @class = klass end def result_instance - @result.hostclass("").code[0] + @result.code[0] end def matches?(string) @string = string @result = @parser.parse(string) result_instance.instance_of?(@class) end def description "parse as a #{@class}" end def failure_message " expected #{@string} to parse as #{@class} but was #{result_instance.class}" end def negative_failure_message " expected #{@string} not to parse as #{@class}" end end def parse_as(klass) ParseAs.new(klass) end class ParseWith def initialize(block) @parser = Puppet::Parser::Parser.new "development" @block = block end def result_instance - @result.hostclass("").code[0] + @result.code[0] end def matches?(string) @string = string @result = @parser.parse(string) @block.call(result_instance) end def description "parse with the block evaluating to true" end def failure_message " expected #{@string} to parse with a true result in the block" end def negative_failure_message " expected #{@string} not to parse with a true result in the block" end end def parse_with(&block) ParseWith.new(block) end end include ParseMatcher before :each do @resource_type_collection = Puppet::Resource::TypeCollection.new("env") @parser = Puppet::Parser::Parser.new "development" end describe "when parsing comments before statement" do it "should associate the documentation to the statement AST node" do ast = @parser.parse(""" # comment class test {} """) - ast.hostclass("test").doc.should == "comment\n" + ast.code[0].should be_a(Puppet::Parser::AST::Hostclass) + ast.code[0].name.should == 'test' + ast.code[0].instantiate('')[0].doc.should == "comment\n" end end describe "when parsing" do it "should be able to parse normal left to right relationships" do "Notify[foo] -> Notify[bar]".should parse_as(Puppet::Parser::AST::Relationship) end it "should be able to parse right to left relationships" do "Notify[foo] <- Notify[bar]".should parse_as(Puppet::Parser::AST::Relationship) end it "should be able to parse normal left to right subscriptions" do "Notify[foo] ~> Notify[bar]".should parse_as(Puppet::Parser::AST::Relationship) end it "should be able to parse right to left subscriptions" do "Notify[foo] <~ Notify[bar]".should parse_as(Puppet::Parser::AST::Relationship) end it "should correctly set the arrow type of a relationship" do "Notify[foo] <~ Notify[bar]".should parse_with { |rel| rel.arrow == "<~" } end end end diff --git a/spec/unit/application/apply_spec.rb b/spec/unit/application/apply_spec.rb index 85098f490..edb41b5c3 100755 --- a/spec/unit/application/apply_spec.rb +++ b/spec/unit/application/apply_spec.rb @@ -1,405 +1,404 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/application/apply' require 'puppet/file_bucket/dipper' describe Puppet::Application::Apply do before :each do @apply = Puppet::Application[:apply] Puppet::Util::Log.stubs(:newdestination) Puppet::Util::Log.stubs(:level=) end [:debug,:loadclasses,:verbose,:use_nodes,:detailed_exitcodes].each do |option| it "should declare handle_#{option} method" do @apply.should respond_to("handle_#{option}".to_sym) end it "should store argument value when calling handle_#{option}" do @apply.options.expects(:[]=).with(option, 'arg') @apply.send("handle_#{option}".to_sym, 'arg') end end it "should set the code to the provided code when :execute is used" do @apply.options.expects(:[]=).with(:code, 'arg') @apply.send("handle_execute".to_sym, 'arg') end it "should ask Puppet::Application to parse Puppet configuration file" do @apply.should_parse_config?.should be_true end describe "when applying options" do it "should set the log destination with --logdest" do Puppet::Log.expects(:newdestination).with("console") @apply.handle_logdest("console") end it "should put the logset options to true" do @apply.options.expects(:[]=).with(:logset,true) @apply.handle_logdest("console") end end describe "during setup" do before :each do Puppet::Log.stubs(:newdestination) Puppet.stubs(:trap) Puppet::Log.stubs(:level=) Puppet.stubs(:parse_config) Puppet::FileBucket::Dipper.stubs(:new) STDIN.stubs(:read) @apply.options.stubs(:[]).with(any_parameters) end it "should set show_diff on --noop" do Puppet.stubs(:[]=) Puppet.stubs(:[]).with(:config) Puppet.stubs(:[]).with(:noop).returns(true) Puppet.expects(:[]=).with(:show_diff, true) @apply.setup end it "should set console as the log destination if logdest option wasn't provided" do Puppet::Log.expects(:newdestination).with(:console) @apply.setup end it "should set INT trap" do @apply.expects(:trap).with(:INT) @apply.setup end it "should set log level to debug if --debug was passed" do @apply.options.stubs(:[]).with(:debug).returns(true) Puppet::Log.expects(:level=).with(:debug) @apply.setup end it "should set log level to info if --verbose was passed" do @apply.options.stubs(:[]).with(:verbose).returns(true) Puppet::Log.expects(:level=).with(:info) @apply.setup end it "should print puppet config if asked to in Puppet config" do @apply.stubs(:exit) Puppet.settings.stubs(:print_configs?).returns(true) Puppet.settings.expects(:print_configs) @apply.setup end it "should exit after printing puppet config if asked to in Puppet config" do Puppet.settings.stubs(:print_configs?).returns(true) lambda { @apply.setup }.should raise_error(SystemExit) end end describe "when executing" do it "should dispatch to parseonly if parseonly is set" do @apply.stubs(:options).returns({}) Puppet.stubs(:[]).with(:parseonly).returns(true) @apply.expects(:parseonly) @apply.run_command end it "should dispatch to 'apply' if it was called with 'apply'" do @apply.options[:catalog] = "foo" @apply.expects(:apply) @apply.run_command end it "should dispatch to main if parseonly is not set" do @apply.stubs(:options).returns({}) Puppet.stubs(:[]).with(:parseonly).returns(false) @apply.expects(:main) @apply.run_command end describe "the parseonly command" do before :each do - Puppet.stubs(:[]).with(:environment) + @environment = Puppet::Node::Environment.new("env") + Puppet.stubs(:[]).with(:environment).returns(@environment) Puppet.stubs(:[]).with(:manifest).returns("site.pp") Puppet.stubs(:err) @apply.stubs(:exit) @apply.options.stubs(:[]).with(:code).returns "some code" - @collection = stub_everything - Puppet::Resource::TypeCollection.stubs(:new).returns(@collection) end - it "should use a Puppet Resource Type Collection to parse the file" do - @collection.expects(:perform_initial_import) + it "should use the environment to parse the file" do + @environment.stubs(:perform_initial_import) @apply.parseonly end it "should exit with exit code 0 if no error" do @apply.expects(:exit).with(0) @apply.parseonly end it "should exit with exit code 1 if error" do - @collection.stubs(:perform_initial_import).raises(Puppet::ParseError) + @environment.stubs(:perform_initial_import).raises(Puppet::ParseError) @apply.expects(:exit).with(1) @apply.parseonly end end describe "the main command" do before :each do Puppet.stubs(:[]) Puppet.settings.stubs(:use) Puppet.stubs(:[]).with(:prerun_command).returns "" Puppet.stubs(:[]).with(:postrun_command).returns "" Puppet.stubs(:[]).with(:trace).returns(true) @apply.options.stubs(:[]) @facts = stub_everything 'facts' Puppet::Node::Facts.stubs(:find).returns(@facts) @node = stub_everything 'node' Puppet::Node.stubs(:find).returns(@node) @catalog = stub_everything 'catalog' @catalog.stubs(:to_ral).returns(@catalog) Puppet::Resource::Catalog.stubs(:find).returns(@catalog) STDIN.stubs(:read) @transaction = stub_everything 'transaction' @catalog.stubs(:apply).returns(@transaction) @apply.stubs(:exit) end it "should set the code to run from --code" do @apply.options.stubs(:[]).with(:code).returns("code to run") Puppet.expects(:[]=).with(:code,"code to run") @apply.main end it "should set the code to run from STDIN if no arguments" do @apply.command_line.stubs(:args).returns([]) STDIN.stubs(:read).returns("code to run") Puppet.expects(:[]=).with(:code,"code to run") @apply.main end it "should set the manifest if a file is passed on command line and the file exists" do File.stubs(:exist?).with('site.pp').returns true @apply.command_line.stubs(:args).returns(['site.pp']) Puppet.expects(:[]=).with(:manifest,"site.pp") @apply.main end it "should raise an error if a file is passed on command line and the file does not exist" do File.stubs(:exist?).with('noexist.pp').returns false @apply.command_line.stubs(:args).returns(['noexist.pp']) lambda { @apply.main }.should raise_error(RuntimeError, 'Could not find file noexist.pp') end it "should set the manifest to the first file and warn other files will be skipped" do File.stubs(:exist?).with('starwarsIV').returns true File.expects(:exist?).with('starwarsI').never @apply.command_line.stubs(:args).returns(['starwarsIV', 'starwarsI', 'starwarsII']) Puppet.expects(:[]=).with(:manifest,"starwarsIV") Puppet.expects(:warning).with('Only one file can be applied per run. Skipping starwarsI, starwarsII') @apply.main end it "should collect the node facts" do Puppet::Node::Facts.expects(:find).returns(@facts) @apply.main end it "should raise an error if we can't find the node" do Puppet::Node::Facts.expects(:find).returns(nil) lambda { @apply.main }.should raise_error end it "should look for the node" do Puppet::Node.expects(:find).returns(@node) @apply.main end it "should raise an error if we can't find the node" do Puppet::Node.expects(:find).returns(nil) lambda { @apply.main }.should raise_error end it "should merge in our node the loaded facts" do @facts.stubs(:values).returns("values") @node.expects(:merge).with("values") @apply.main end it "should load custom classes if loadclasses" do @apply.options.stubs(:[]).with(:loadclasses).returns(true) Puppet.stubs(:[]).with(:classfile).returns("/etc/puppet/classes.txt") FileTest.stubs(:exists?).with("/etc/puppet/classes.txt").returns(true) FileTest.stubs(:readable?).with("/etc/puppet/classes.txt").returns(true) File.stubs(:read).with("/etc/puppet/classes.txt").returns("class") @node.expects(:classes=) @apply.main end it "should compile the catalog" do Puppet::Resource::Catalog.expects(:find).returns(@catalog) @apply.main end it "should transform the catalog to ral" do @catalog.expects(:to_ral).returns(@catalog) @apply.main end it "should finalize the catalog" do @catalog.expects(:finalize) @apply.main end it "should call the prerun and postrun commands on a Configurer instance" do configurer = stub 'configurer' Puppet::Configurer.expects(:new).returns configurer configurer.expects(:execute_prerun_command) configurer.expects(:execute_postrun_command) @apply.main end it "should apply the catalog" do @catalog.expects(:apply).returns(stub_everything 'transaction') @apply.main end describe "with detailed_exitcodes" do it "should exit with report's computed exit status" do Puppet.stubs(:[]).with(:noop).returns(false) @apply.options.stubs(:[]).with(:detailed_exitcodes).returns(true) report = stub 'report', :exit_status => 666 @transaction.stubs(:report).returns(report) @apply.expects(:exit).with(666) @apply.main end it "should always exit with 0 if option is disabled" do Puppet.stubs(:[]).with(:noop).returns(false) @apply.options.stubs(:[]).with(:detailed_exitcodes).returns(false) report = stub 'report', :exit_status => 666 @transaction.stubs(:report).returns(report) @apply.expects(:exit).with(0) @apply.main end it "should always exit with 0 if --noop" do Puppet.stubs(:[]).with(:noop).returns(true) @apply.options.stubs(:[]).with(:detailed_exitcodes).returns(true) report = stub 'report', :exit_status => 666 @transaction.stubs(:report).returns(report) @apply.expects(:exit).with(0) @apply.main end end end describe "the 'apply' command" do it "should read the catalog in from disk if a file name is provided" do @apply.options[:catalog] = "/my/catalog.pson" File.expects(:read).with("/my/catalog.pson").returns "something" Puppet::Resource::Catalog.stubs(:convert_from).with(:pson,'something').returns Puppet::Resource::Catalog.new @apply.apply end it "should read the catalog in from stdin if '-' is provided" do @apply.options[:catalog] = "-" $stdin.expects(:read).returns "something" Puppet::Resource::Catalog.stubs(:convert_from).with(:pson,'something').returns Puppet::Resource::Catalog.new @apply.apply end it "should deserialize the catalog from the default format" do @apply.options[:catalog] = "/my/catalog.pson" File.stubs(:read).with("/my/catalog.pson").returns "something" Puppet::Resource::Catalog.stubs(:default_format).returns :rot13_piglatin Puppet::Resource::Catalog.stubs(:convert_from).with(:rot13_piglatin,'something').returns Puppet::Resource::Catalog.new @apply.apply end it "should fail helpfully if deserializing fails" do @apply.options[:catalog] = "/my/catalog.pson" File.stubs(:read).with("/my/catalog.pson").returns "something syntacically invalid" lambda { @apply.apply }.should raise_error(Puppet::Error) end it "should convert plain data structures into a catalog if deserialization does not do so" do @apply.options[:catalog] = "/my/catalog.pson" File.stubs(:read).with("/my/catalog.pson").returns "something" Puppet::Resource::Catalog.stubs(:convert_from).with(:pson,"something").returns({:foo => "bar"}) Puppet::Resource::Catalog.expects(:pson_create).with({:foo => "bar"}).returns(Puppet::Resource::Catalog.new) @apply.apply end it "should convert the catalog to a RAL catalog and use a Configurer instance to apply it" do @apply.options[:catalog] = "/my/catalog.pson" File.stubs(:read).with("/my/catalog.pson").returns "something" catalog = Puppet::Resource::Catalog.new Puppet::Resource::Catalog.stubs(:convert_from).with(:pson,'something').returns catalog catalog.expects(:to_ral).returns "mycatalog" configurer = stub 'configurer' Puppet::Configurer.expects(:new).returns configurer configurer.expects(:run).with(:catalog => "mycatalog") @apply.apply end end end end diff --git a/spec/unit/application/master_spec.rb b/spec/unit/application/master_spec.rb index 216c7dc90..e657445a4 100644 --- a/spec/unit/application/master_spec.rb +++ b/spec/unit/application/master_spec.rb @@ -1,453 +1,452 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/application/master' require 'puppet/daemon' require 'puppet/network/server' describe Puppet::Application::Master do before :each do @master = Puppet::Application[:master] @daemon = stub_everything 'daemon' Puppet::Daemon.stubs(:new).returns(@daemon) Puppet::Util::Log.stubs(:newdestination) Puppet::Util::Log.stubs(:level=) Puppet::Node.stubs(:terminus_class=) Puppet::Node.stubs(:cache_class=) Puppet::Node::Facts.stubs(:terminus_class=) Puppet::Node::Facts.stubs(:cache_class=) Puppet::Transaction::Report.stubs(:terminus_class=) Puppet::Resource::Catalog.stubs(:terminus_class=) end it "should operate in master run_mode" do @master.class.run_mode.name.should equal(:master) end it "should ask Puppet::Application to parse Puppet configuration file" do @master.should_parse_config?.should be_true end it "should declare a main command" do @master.should respond_to(:main) end it "should declare a parseonly command" do @master.should respond_to(:parseonly) end it "should declare a compile command" do @master.should respond_to(:compile) end it "should declare a preinit block" do @master.should respond_to(:preinit) end describe "during preinit" do before :each do @master.stubs(:trap) end it "should catch INT" do @master.stubs(:trap).with { |arg,block| arg == :INT } @master.preinit end it "should create a Puppet Daemon" do Puppet::Daemon.expects(:new).returns(@daemon) @master.preinit end it "should give ARGV to the Daemon" do argv = stub 'argv' ARGV.stubs(:dup).returns(argv) @daemon.expects(:argv=).with(argv) @master.preinit end end [:debug,:verbose].each do |option| it "should declare handle_#{option} method" do @master.should respond_to("handle_#{option}".to_sym) end it "should store argument value when calling handle_#{option}" do @master.options.expects(:[]=).with(option, 'arg') @master.send("handle_#{option}".to_sym, 'arg') end end describe "when applying options" do before do @master.command_line.stubs(:args).returns([]) end it "should set the log destination with --logdest" do Puppet::Log.expects(:newdestination).with("console") @master.handle_logdest("console") end it "should put the setdest options to true" do @master.options.expects(:[]=).with(:setdest,true) @master.handle_logdest("console") end it "should parse the log destination from ARGV" do @master.command_line.stubs(:args).returns(%w{--logdest /my/file}) Puppet::Util::Log.expects(:newdestination).with("/my/file") @master.parse_options end end describe "during setup" do before :each do Puppet::Log.stubs(:newdestination) Puppet.stubs(:settraps) Puppet::Log.stubs(:level=) Puppet::SSL::CertificateAuthority.stubs(:instance) Puppet::SSL::CertificateAuthority.stubs(:ca?) Puppet.settings.stubs(:use) @master.options.stubs(:[]).with(any_parameters) end it "should set log level to debug if --debug was passed" do @master.options.stubs(:[]).with(:debug).returns(true) Puppet::Log.expects(:level=).with(:debug) @master.setup end it "should set log level to info if --verbose was passed" do @master.options.stubs(:[]).with(:verbose).returns(true) Puppet::Log.expects(:level=).with(:info) @master.setup end it "should set console as the log destination if no --logdest and --daemonize" do @master.stubs(:[]).with(:daemonize).returns(:false) Puppet::Log.expects(:newdestination).with(:syslog) @master.setup end it "should set syslog as the log destination if no --logdest and not --daemonize" do Puppet::Log.expects(:newdestination).with(:syslog) @master.setup end it "should set syslog as the log destination if --rack" do @master.options.stubs(:[]).with(:rack).returns(:true) Puppet::Log.expects(:newdestination).with(:syslog) @master.setup end it "should print puppet config if asked to in Puppet config" do @master.stubs(:exit) Puppet.settings.stubs(:print_configs?).returns(true) Puppet.settings.expects(:print_configs) @master.setup end it "should exit after printing puppet config if asked to in Puppet config" do Puppet.settings.stubs(:print_configs?).returns(true) lambda { @master.setup }.should raise_error(SystemExit) end it "should tell Puppet.settings to use :main,:ssl and :master category" do Puppet.settings.expects(:use).with(:main,:master,:ssl) @master.setup end it "should cache class in yaml" do Puppet::Node.expects(:cache_class=).with(:yaml) @master.setup end describe "with no ca" do it "should set the ca_location to none" do Puppet::SSL::Host.expects(:ca_location=).with(:none) @master.setup end end describe "with a ca configured" do before :each do Puppet::SSL::CertificateAuthority.stubs(:ca?).returns(true) end it "should set the ca_location to local" do Puppet::SSL::Host.expects(:ca_location=).with(:local) @master.setup end it "should tell Puppet.settings to use :ca category" do Puppet.settings.expects(:use).with(:ca) @master.setup end it "should instantiate the CertificateAuthority singleton" do Puppet::SSL::CertificateAuthority.expects(:instance) @master.setup end end end describe "when running" do before do @master.preinit end it "should dispatch to parseonly if parseonly is set" do Puppet.stubs(:[]).with(:parseonly).returns(true) @master.options[:node] = nil @master.expects(:parseonly) @master.run_command end it "should dispatch to compile if called with --compile" do @master.options[:node] = "foo" @master.expects(:compile) @master.run_command end it "should dispatch to main if parseonly is not set" do Puppet.stubs(:[]).with(:parseonly).returns(false) @master.options[:node] = nil @master.expects(:main) @master.run_command end describe "the parseonly command" do before :each do - Puppet.stubs(:[]).with(:environment) + @environment = Puppet::Node::Environment.new("env") + Puppet.stubs(:[]).with(:environment).returns(@environment) Puppet.stubs(:[]).with(:manifest).returns("site.pp") Puppet.stubs(:err) @master.stubs(:exit) - @collection = stub_everything - Puppet::Resource::TypeCollection.stubs(:new).returns(@collection) end it "should use a Puppet Resource Type Collection to parse the file" do - @collection.expects(:perform_initial_import) + @environment.expects(:perform_initial_import) @master.parseonly end it "should exit with exit code 0 if no error" do @master.expects(:exit).with(0) @master.parseonly end it "should exit with exit code 1 if error" do - @collection.stubs(:perform_initial_import).raises(Puppet::ParseError) + @environment.stubs(:perform_initial_import).raises(Puppet::ParseError) @master.expects(:exit).with(1) @master.parseonly end end describe "the compile command" do before do Puppet.stubs(:[]).with(:environment) Puppet.stubs(:[]).with(:manifest).returns("site.pp") Puppet.stubs(:err) @master.stubs(:jj) @master.stubs(:exit) Puppet.features.stubs(:pson?).returns true end it "should fail if pson isn't available" do Puppet.features.expects(:pson?).returns false lambda { @master.compile }.should raise_error end it "should compile a catalog for the specified node" do @master.options[:node] = "foo" Puppet::Resource::Catalog.expects(:find).with("foo").returns Puppet::Resource::Catalog.new $stdout.stubs(:puts) @master.compile end it "should convert the catalog to a pure-resource catalog and use 'jj' to pretty-print the catalog" do catalog = Puppet::Resource::Catalog.new Puppet::Resource::Catalog.expects(:find).returns catalog catalog.expects(:to_resource).returns("rescat") @master.options[:node] = "foo" @master.expects(:jj).with("rescat") @master.compile end it "should exit with error code 30 if no catalog can be found" do @master.options[:node] = "foo" Puppet::Resource::Catalog.expects(:find).returns nil @master.expects(:exit).with(30) $stderr.expects(:puts) @master.compile end it "should exit with error code 30 if there's a failure" do @master.options[:node] = "foo" Puppet::Resource::Catalog.expects(:find).raises ArgumentError @master.expects(:exit).with(30) $stderr.expects(:puts) @master.compile end end describe "the main command" do before :each do @master.preinit @server = stub_everything 'server' Puppet::Network::Server.stubs(:new).returns(@server) @app = stub_everything 'app' Puppet::SSL::Host.stubs(:localhost) Puppet::SSL::CertificateAuthority.stubs(:ca?) Process.stubs(:uid).returns(1000) Puppet.stubs(:service) Puppet.stubs(:[]) Puppet.stubs(:notice) Puppet.stubs(:start) end it "should create a Server" do Puppet::Network::Server.expects(:new) @master.main end it "should give the server to the daemon" do @daemon.expects(:server=).with(@server) @master.main end it "should create the server with the right XMLRPC handlers" do Puppet::Network::Server.expects(:new).with { |args| args[:xmlrpc_handlers] == [:Status, :FileServer, :Master, :Report, :Filebucket]} @master.main end it "should create the server with a :ca xmlrpc handler if needed" do Puppet.stubs(:[]).with(:ca).returns(true) Puppet::Network::Server.expects(:new).with { |args| args[:xmlrpc_handlers].include?(:CA) } @master.main end it "should generate a SSL cert for localhost" do Puppet::SSL::Host.expects(:localhost) @master.main end it "should make sure to *only* hit the CA for data" do Puppet::SSL::CertificateAuthority.stubs(:ca?).returns(true) Puppet::SSL::Host.expects(:ca_location=).with(:only) @master.main end it "should drop privileges if running as root" do Puppet.features.stubs(:root?).returns true Puppet::Util.expects(:chuser) @master.main end it "should daemonize if needed" do Puppet.stubs(:[]).with(:daemonize).returns(true) @daemon.expects(:daemonize) @master.main end it "should start the service" do @daemon.expects(:start) @master.main end describe "with --rack" do confine "Rack is not available" => Puppet.features.rack? before do require 'puppet/network/http/rack' Puppet::Network::HTTP::Rack.stubs(:new).returns(@app) end it "it should create the app with REST and XMLRPC support" do @master.options.stubs(:[]).with(:rack).returns(:true) Puppet::Network::HTTP::Rack.expects(:new).with { |args| args[:xmlrpc_handlers] == [:Status, :FileServer, :Master, :Report, :Filebucket] and args[:protocols] == [:rest, :xmlrpc] } @master.main end it "it should not start a daemon" do @master.options.stubs(:[]).with(:rack).returns(:true) @daemon.expects(:start).never @master.main end it "it should return the app" do @master.options.stubs(:[]).with(:rack).returns(:true) app = @master.main app.should equal(@app) end end end end end diff --git a/spec/unit/dsl/resource_type_api_spec.rb b/spec/unit/dsl/resource_type_api_spec.rb index 4f4eb7e01..c9a5d272f 100755 --- a/spec/unit/dsl/resource_type_api_spec.rb +++ b/spec/unit/dsl/resource_type_api_spec.rb @@ -1,66 +1,54 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/dsl/resource_type_api' describe Puppet::DSL::ResourceTypeAPI do - # Run the given block in the context of a new ResourceTypeAPI - # object. + # Verify that the block creates a single AST node through the API, + # instantiate that AST node into a types, and return that type. def test_api_call(&block) - Thread.current[:known_resource_types] = Puppet::Resource::TypeCollection.new(:env) - Puppet::DSL::ResourceTypeAPI.new.instance_eval(&block) + main_object = Puppet::DSL::ResourceTypeAPI.new + main_object.instance_eval(&block) + created_ast_objects = main_object.instance_eval { @__created_ast_objects__ } + created_ast_objects.length.should == 1 + new_types = created_ast_objects[0].instantiate('') + new_types.length.should == 1 + new_types[0] ensure - Thread.current[:known_resource_types] = nil + Thread.current[:ruby_file_parse_result] = nil end [:definition, :node, :hostclass].each do |type| method = type == :definition ? "define" : type it "should be able to create a #{type}" do - newtype = Puppet::Resource::Type.new(:hostclass, "foo") - Puppet::Resource::Type.expects(:new).with { |t, n, args| t == type }.returns newtype - test_api_call { send(method, "myname") } + newtype = test_api_call { send(method, "myname").should == nil } + newtype.should be_a(Puppet::Resource::Type) + newtype.type.should == type end it "should use the provided name when creating a #{type}" do - type = Puppet::Resource::Type.new(:hostclass, "foo") - Puppet::Resource::Type.expects(:new).with { |t, n, args| n == "myname" }.returns type - test_api_call { send(method, "myname") } + newtype = test_api_call { send(method, "myname") } + newtype.name.should == "myname" end unless type == :definition - it "should pass in any provided options" do - type = Puppet::Resource::Type.new(:hostclass, "foo") - Puppet::Resource::Type.expects(:new).with { |t, n, args| args == {:myarg => :myvalue} }.returns type - test_api_call { send(method, "myname", :myarg => :myvalue) } + it "should pass in any provided options when creating a #{type}" do + newtype = test_api_call { send(method, "myname", :line => 200) } + newtype.line.should == 200 end end it "should set any provided block as the type's ruby code" do - Puppet::Resource::Type.any_instance.expects(:ruby_code=).with { |blk| blk.call == 'foo' } - test_api_call { send(method, "myname") { 'foo' } } - end - - it "should add the type to the current environment's known resource types" do - begin - newtype = Puppet::Resource::Type.new(:hostclass, "foo") - Puppet::Resource::Type.expects(:new).returns newtype - known_resource_types = Puppet::Resource::TypeCollection.new(:env) - Thread.current[:known_resource_types] = known_resource_types - known_resource_types.expects(:add).with(newtype) - Puppet::DSL::ResourceTypeAPI.new.instance_eval { hostclass "myname" } - ensure - Thread.current[:known_resource_types] = nil - end + newtype = test_api_call { send(method, "myname") { 'method_result' } } + newtype.ruby_code.call.should == 'method_result' end end describe "when creating a definition" do it "should use the provided options to define valid arguments for the resource type" do - newtype = Puppet::Resource::Type.new(:definition, "foo") - Puppet::Resource::Type.expects(:new).returns newtype - test_api_call { define("myname", :arg1, :arg2) } - newtype.instance_eval { @arguments }.should == { 'arg1' => nil, 'arg2' => nil } + newtype = test_api_call { define("myname", :arg1, :arg2) } + newtype.arguments.should == { 'arg1' => nil, 'arg2' => nil } end end end diff --git a/spec/unit/node/environment_spec.rb b/spec/unit/node/environment_spec.rb index 6edcce56c..be2980879 100755 --- a/spec/unit/node/environment_spec.rb +++ b/spec/unit/node/environment_spec.rb @@ -1,277 +1,328 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/node/environment' require 'puppet/util/execution' describe Puppet::Node::Environment do after do Puppet::Node::Environment.clear end it "should include the Cacher module" do Puppet::Node::Environment.ancestors.should be_include(Puppet::Util::Cacher) end it "should use the filetimeout for the ttl for the modulepath" do Puppet::Node::Environment.attr_ttl(:modulepath).should == Integer(Puppet[:filetimeout]) end it "should use the filetimeout for the ttl for the module list" do Puppet::Node::Environment.attr_ttl(:modules).should == Integer(Puppet[:filetimeout]) end it "should use the filetimeout for the ttl for the manifestdir" do Puppet::Node::Environment.attr_ttl(:manifestdir).should == Integer(Puppet[:filetimeout]) end it "should use the default environment if no name is provided while initializing an environment" do Puppet.settings.expects(:value).with(:environment).returns("one") Puppet::Node::Environment.new.name.should == :one end it "should treat environment instances as singletons" do Puppet::Node::Environment.new("one").should equal(Puppet::Node::Environment.new("one")) end it "should treat an environment specified as names or strings as equivalent" do Puppet::Node::Environment.new(:one).should equal(Puppet::Node::Environment.new("one")) end it "should return its name when converted to a string" 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") @collection = Puppet::Resource::TypeCollection.new(@env) - @collection.stubs(:perform_initial_import) + @env.stubs(:perform_initial_import).returns(Puppet::Parser::AST::Hostclass.new('')) Thread.current[:known_resource_types] = nil end it "should create a resource type collection if none exists" do Puppet::Resource::TypeCollection.expects(:new).with(@env).returns @collection @env.known_resource_types.should equal(@collection) end it "should reuse any existing resource type collection" do @env.known_resource_types.should equal(@env.known_resource_types) end it "should perform the initial import when creating a new collection" do - @collection.expects(:perform_initial_import) - Puppet::Resource::TypeCollection.expects(:new).returns @collection - + @env = Puppet::Node::Environment.new("dev") + @env.expects(:perform_initial_import).returns(Puppet::Parser::AST::Hostclass.new('')) @env.known_resource_types end it "should return the same collection even if stale if it's the same thread" do Puppet::Resource::TypeCollection.stubs(:new).returns @collection @env.known_resource_types.stubs(:stale?).returns true @env.known_resource_types.should equal(@collection) end it "should return the current thread associated collection if there is one" do Thread.current[:known_resource_types] = @collection @env.known_resource_types.should equal(@collection) end it "should give to all threads the same collection if it didn't change" do Puppet::Resource::TypeCollection.expects(:new).with(@env).returns @collection @env.known_resource_types t = Thread.new { @env.known_resource_types.should equal(@collection) } t.join end it "should give to new threads a new collection if it isn't stale" do Puppet::Resource::TypeCollection.expects(:new).with(@env).returns @collection @env.known_resource_types.expects(:stale?).returns(true) Puppet::Resource::TypeCollection.expects(:new).returns @collection t = Thread.new { @env.known_resource_types.should equal(@collection) } t.join end end [:modulepath, :manifestdir].each do |setting| it "should validate the #{setting} directories" do path = %w{/one /two}.join(File::PATH_SEPARATOR) env = Puppet::Node::Environment.new("testing") env.stubs(:[]).with(setting).returns path env.expects(:validate_dirs).with(%w{/one /two}) env.send(setting) end it "should return the validated dirs for #{setting}" do path = %w{/one /two}.join(File::PATH_SEPARATOR) env = Puppet::Node::Environment.new("testing") env.stubs(:[]).with(setting).returns path env.stubs(:validate_dirs).returns %w{/one /two} env.send(setting).should == %w{/one /two} end end it "should prefix the value of the 'PUPPETLIB' environment variable to the module path if present" do Puppet::Util::Execution.withenv("PUPPETLIB" => %w{/l1 /l2}.join(File::PATH_SEPARATOR)) do env = Puppet::Node::Environment.new("testing") module_path = %w{/one /two}.join(File::PATH_SEPARATOR) env.expects(:validate_dirs).with(%w{/l1 /l2 /one /two}).returns %w{/l1 /l2 /one /two} env.expects(:[]).with(:modulepath).returns module_path env.modulepath.should == %w{/l1 /l2 /one /two} end end describe "when validating modulepath or manifestdir directories" do it "should not return non-directories" do env = Puppet::Node::Environment.new("testing") FileTest.expects(:directory?).with("/one").returns true FileTest.expects(:directory?).with("/two").returns false env.validate_dirs(%w{/one /two}).should == %w{/one} end it "should use the current working directory to fully-qualify unqualified paths" do FileTest.stubs(:directory?).returns true env = Puppet::Node::Environment.new("testing") two = File.join(Dir.getwd, "two") env.validate_dirs(%w{/one two}).should == ["/one", two] end end describe "when modeling a specific environment" do it "should have a method for returning the environment name" do Puppet::Node::Environment.new("testing").name.should == :testing end it "should provide an array-like accessor method for returning any environment-specific setting" do env = Puppet::Node::Environment.new("testing") env.should respond_to(:[]) end it "should ask the Puppet settings instance for the setting qualified with the environment name" do Puppet.settings.expects(:value).with("myvar", :testing).returns("myval") env = Puppet::Node::Environment.new("testing") env["myvar"].should == "myval" end it "should be able to return an individual module that exists in its module path" do env = Puppet::Node::Environment.new("testing") mod = mock 'module' Puppet::Module.expects(:new).with("one", env).returns mod mod.expects(:exist?).returns true env.module("one").should equal(mod) end it "should return nil if asked for a module that does not exist in its path" do env = Puppet::Node::Environment.new("testing") mod = mock 'module' Puppet::Module.expects(:new).with("one", env).returns mod mod.expects(:exist?).returns false env.module("one").should be_nil end it "should be able to return its modules" do Puppet::Node::Environment.new("testing").should respond_to(:modules) end 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).at_least_once.returns %w{/a /b} Dir.expects(:entries).with("/a").returns %w{foo bar} Dir.expects(:entries).with("/b").returns %w{bee baz} env.modules.collect{|mod| mod.name}.sort.should == %w{foo bar bee baz}.sort end it "should remove duplicates" do env = Puppet::Node::Environment.new("testing") env.expects(:modulepath).returns( %w{/a /b} ).at_least_once Dir.expects(:entries).with("/a").returns %w{foo} Dir.expects(:entries).with("/b").returns %w{foo} env.modules.collect{|mod| mod.name}.sort.should == %w{foo} end it "should ignore invalid modules" do env = Puppet::Node::Environment.new("testing") 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") Puppet::Module.expects(:new).with { |name, env| name == "bar" }.raises( Puppet::Module::InvalidName, "name is invalid" ) env.modules.collect{|mod| mod.name}.sort.should == %w{foo} end it "should create modules with the correct environment" do env = Puppet::Node::Environment.new("testing") env.expects(:modulepath).at_least_once.returns %w{/a} Dir.expects(:entries).with("/a").returns %w{foo} env.modules.each {|mod| mod.environment.should == env } end it "should cache the module list" do env = Puppet::Node::Environment.new("testing") env.expects(:modulepath).at_least_once.returns %w{/a} Dir.expects(:entries).once.with("/a").returns %w{foo} env.modules env.modules 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 end end + + describe "when performing initial import" do + before do + @parser = stub 'parser', :file= => nil, :string => nil, :parse => nil + Puppet::Parser::Parser.stubs(:new).returns @parser + @env = Puppet::Node::Environment.new("env") + end + + it "should create a new parser instance" do + Puppet::Parser::Parser.expects(:new).returns @parser + @env.instance_eval { perform_initial_import } + end + + it "should set the parser's string to the 'code' setting and parse if code is available" do + Puppet.settings[:code] = "my code" + @parser.expects(:string=).with "my code" + @parser.expects(:parse) + @env.instance_eval { perform_initial_import } + end + + it "should set the parser's file to the 'manifest' setting and parse if no code is available and the manifest is available" do + File.stubs(:expand_path).with("/my/file").returns "/my/file" + File.expects(:exist?).with("/my/file").returns true + Puppet.settings[:manifest] = "/my/file" + @parser.expects(:file=).with "/my/file" + @parser.expects(:parse) + @env.instance_eval { perform_initial_import } + end + + it "should not attempt to load a manifest if none is present" do + File.stubs(:expand_path).with("/my/file").returns "/my/file" + File.expects(:exist?).with("/my/file").returns false + Puppet.settings[:manifest] = "/my/file" + @parser.expects(:file=).never + @parser.expects(:parse).never + @env.instance_eval { perform_initial_import } + end + + it "should fail helpfully if there is an error importing" do + File.stubs(:exist?).returns true + @parser.expects(:parse).raises ArgumentError + lambda { @env.instance_eval { perform_initial_import } }.should raise_error(Puppet::Error) + end + + it "should not do anything if the ignore_import settings is set" do + Puppet.settings[:ignoreimport] = true + @parser.expects(:string=).never + @parser.expects(:file=).never + @parser.expects(:parse).never + @env.instance_eval { perform_initial_import } + end + end end diff --git a/spec/unit/parser/ast/astarray_spec.rb b/spec/unit/parser/ast/astarray_spec.rb index f79d6c533..8794848b6 100755 --- a/spec/unit/parser/ast/astarray_spec.rb +++ b/spec/unit/parser/ast/astarray_spec.rb @@ -1,72 +1,55 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../../spec_helper' describe Puppet::Parser::AST::ASTArray do before :each do @scope = Puppet::Parser::Scope.new end it "should have a [] accessor" do array = Puppet::Parser::AST::ASTArray.new :children => [] array.should respond_to(:[]) end it "should evaluate all its children" do item1 = stub "item1", :is_a? => true item2 = stub "item2", :is_a? => true item1.expects(:safeevaluate).with(@scope).returns(123) item2.expects(:safeevaluate).with(@scope).returns(246) operator = Puppet::Parser::AST::ASTArray.new :children => [item1,item2] operator.evaluate(@scope) end - it "should evaluate childrens of type ASTArray" do - item1 = stub "item1", :is_a? => true - item2 = stub "item2" - item2.stubs(:is_a?).with(Puppet::Parser::AST).returns(true) - item2.stubs(:instance_of?).with(Puppet::Parser::AST::ASTArray).returns(true) - item2.stubs(:each).yields(item1) - - item1.expects(:safeevaluate).with(@scope).returns(123) - - operator = Puppet::Parser::AST::ASTArray.new :children => [item2] - operator.evaluate(@scope).should == [123] - end - - it "should flatten children coming from children ASTArray" do - item1 = stub "item1", :is_a? => true - item2 = stub "item2" - item2.stubs(:is_a?).with(Puppet::Parser::AST).returns(true) - item2.stubs(:instance_of?).with(Puppet::Parser::AST::ASTArray).returns(true) - item2.stubs(:each).yields([item1]) - - item1.expects(:safeevaluate).with(@scope).returns(123) - - operator = Puppet::Parser::AST::ASTArray.new :children => [item2] - operator.evaluate(@scope).should == [123] + it "should not flatten children coming from children ASTArray" do + item = Puppet::Parser::AST::String.new :value => 'foo' + inner_array = Puppet::Parser::AST::ASTArray.new :children => [item, item] + operator = Puppet::Parser::AST::ASTArray.new :children => [inner_array, inner_array] + operator.evaluate(@scope).should == [['foo', 'foo'], ['foo', 'foo']] end it "should not flatten the results of children evaluation" do - item1 = stub "item1", :is_a? => true - item2 = stub "item2" - item2.stubs(:is_a?).with(Puppet::Parser::AST).returns(true) - item2.stubs(:instance_of?).with(Puppet::Parser::AST::ASTArray).returns(true) - item2.stubs(:each).yields([item1]) - - item1.expects(:safeevaluate).with(@scope).returns([123]) + item = Puppet::Parser::AST::String.new :value => 'foo' + item.stubs(:evaluate).returns(['foo']) + operator = Puppet::Parser::AST::ASTArray.new :children => [item, item] + operator.evaluate(@scope).should == [['foo'], ['foo']] + end - operator = Puppet::Parser::AST::ASTArray.new :children => [item2] - operator.evaluate(@scope).should == [[123]] + it "should discard nil results from children evaluation" do + item1 = Puppet::Parser::AST::String.new :value => 'foo' + item2 = Puppet::Parser::AST::String.new :value => 'foo' + item2.stubs(:evaluate).returns(nil) + operator = Puppet::Parser::AST::ASTArray.new :children => [item1, item2] + operator.evaluate(@scope).should == ['foo'] end it "should return a valid string with to_s" do a = stub 'a', :is_a? => true, :to_s => "a" b = stub 'b', :is_a? => true, :to_s => "b" array = Puppet::Parser::AST::ASTArray.new :children => [a,b] array.to_s.should == "[a, b]" end end diff --git a/spec/unit/parser/ast/definition_spec.rb b/spec/unit/parser/ast/definition_spec.rb new file mode 100644 index 000000000..b7b2c851c --- /dev/null +++ b/spec/unit/parser/ast/definition_spec.rb @@ -0,0 +1,22 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../../spec_helper' + +describe Puppet::Parser::AST::Definition do + it "should make its context available through an accessor" do + definition = Puppet::Parser::AST::Definition.new('foo', :line => 5) + definition.context.should == {:line => 5} + end + + describe "when instantiated" do + it "should create a definition with the proper type, name, context, and module name" do + definition = Puppet::Parser::AST::Definition.new('foo', :line => 5) + instantiated_definitions = definition.instantiate('modname') + instantiated_definitions.length.should == 1 + instantiated_definitions[0].type.should == :definition + instantiated_definitions[0].name.should == 'foo' + instantiated_definitions[0].line.should == 5 + instantiated_definitions[0].module_name.should == 'modname' + end + end +end diff --git a/spec/unit/parser/ast/hostclass_spec.rb b/spec/unit/parser/ast/hostclass_spec.rb new file mode 100644 index 000000000..b22eba98b --- /dev/null +++ b/spec/unit/parser/ast/hostclass_spec.rb @@ -0,0 +1,73 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../../spec_helper' + +describe Puppet::Parser::AST::Hostclass do + def ast + Puppet::Parser::AST + end + + def newarray(*elems) + ast::ASTArray.new({}).push(*elems) + end + + it "should make its name and context available through accessors" do + hostclass = ast::Hostclass.new('foo', :line => 5) + hostclass.name.should == 'foo' + hostclass.context.should == {:line => 5} + end + + it "should make its code available through an accessor" do + code = newarray + hostclass = ast::Hostclass.new('foo', :code => code) + hostclass.code.should be_equal(code) + end + + describe "when instantiated" do + it "should create a class with the proper type, code, name, context, and module name" do + code = newarray + hostclass = ast::Hostclass.new('foo', :code => code, :line => 5) + instantiated_class = hostclass.instantiate('modname')[0] + instantiated_class.type.should == :hostclass + instantiated_class.name.should == 'foo' + instantiated_class.code.should be_equal(code) + instantiated_class.line.should == 5 + instantiated_class.module_name.should == 'modname' + end + + it "should instantiate all nested classes, defines, and nodes with the same module name." do + nested_objects = newarray(ast::Hostclass.new('foo::child1'), + ast::Definition.new('foo::child2'), + ast::Definition.new('child3')) + hostclass = ast::Hostclass.new('foo', :code => nested_objects) + instantiated_classes = hostclass.instantiate('modname') + instantiated_classes.length.should == 4 + instantiated_classes[0].name.should == 'foo' + instantiated_classes[1].name.should == 'foo::child1' + instantiated_classes[2].name.should == 'foo::child2' + instantiated_classes[3].name.should == 'child3' + instantiated_classes.each { |cls| cls.module_name.should == 'modname' } + end + + it "should handle a nested class that contains its own nested classes." do + foo_bar_baz = ast::Hostclass.new('foo::bar::baz') + foo_bar = ast::Hostclass.new('foo::bar', :code => newarray(foo_bar_baz)) + foo = ast::Hostclass.new('foo', :code => newarray(foo_bar)) + instantiated_classes = foo.instantiate('') + instantiated_classes.length.should == 3 + instantiated_classes[0].name.should == 'foo' + instantiated_classes[1].name.should == 'foo::bar' + instantiated_classes[2].name.should == 'foo::bar::baz' + end + + it "should skip nested elements that are not classes, definitions, or nodes." do + func = ast::Function.new(:name => 'biz', :arguments => newarray(ast::Name.new(:value => 'baz'))) + foo = ast::Hostclass.new('foo', :code => newarray(func)) + instantiated_classes = foo.instantiate('') + instantiated_classes.length.should == 1 + instantiated_classes[0].should be_a(Puppet::Resource::Type) + instantiated_classes[0].name.should == 'foo' + end + end +end + diff --git a/spec/unit/parser/ast/node_spec.rb b/spec/unit/parser/ast/node_spec.rb new file mode 100644 index 000000000..3e8017de0 --- /dev/null +++ b/spec/unit/parser/ast/node_spec.rb @@ -0,0 +1,31 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../../spec_helper' + +describe Puppet::Parser::AST::Node do + describe "when instantiated" do + it "should make its names and context available through accessors" do + node = Puppet::Parser::AST::Node.new(['foo', 'bar'], :line => 5) + node.names.should == ['foo', 'bar'] + node.context.should == {:line => 5} + end + + it "should create a node with the proper type, name, context, and module name" do + node = Puppet::Parser::AST::Node.new(['foo'], :line => 5) + instantiated_nodes = node.instantiate('modname') + instantiated_nodes.length.should == 1 + instantiated_nodes[0].type.should == :node + instantiated_nodes[0].name.should == 'foo' + instantiated_nodes[0].line.should == 5 + instantiated_nodes[0].module_name.should == 'modname' + end + + it "should handle multiple names" do + node = Puppet::Parser::AST::Node.new(['foo', 'bar']) + instantiated_nodes = node.instantiate('modname') + instantiated_nodes.length.should == 2 + instantiated_nodes[0].name.should == 'foo' + instantiated_nodes[1].name.should == 'bar' + end + end +end diff --git a/spec/unit/parser/ast/resource_spec.rb b/spec/unit/parser/ast/resource_spec.rb index 5c94ac0e9..a8e783256 100755 --- a/spec/unit/parser/ast/resource_spec.rb +++ b/spec/unit/parser/ast/resource_spec.rb @@ -1,127 +1,138 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../../spec_helper' describe Puppet::Parser::AST::Resource do ast = Puppet::Parser::AST before :each do @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 => "file", :parameters => ast::ASTArray.new(:children => []) ) + @instance = ast::ResourceInstance.new(:title => @title, :parameters => ast::ASTArray.new(:children => [])) + @resource = ast::Resource.new(:type => "file", :instances => ast::ASTArray.new(:children => [@instance])) @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(:parameters).returns [param] + @instance.stubs(:parameters).returns [param] @resource.evaluate(@scope) end it "should evaluate its title" do @resource.evaluate(@scope)[0].title.should == "mytitle" end it "should flatten the titles array" do titles = [] %w{one two}.each do |title| titles << Puppet::Parser::AST::String.new(:value => title) end array = Puppet::Parser::AST::ASTArray.new(:children => titles) - @resource.title = array + @instance.title = array result = @resource.evaluate(@scope).collect { |r| r.title } result.should be_include("one") result.should be_include("two") end 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 array = Puppet::Parser::AST::ASTArray.new(:children => titles) - @resource.title = array + @instance.title = array result = @resource.evaluate(@scope).collect { |r| r.title } result.should be_include("one") result.should be_include("two") end + it "should implicitly iterate over instances" do + new_title = Puppet::Parser::AST::String.new(:value => "other_title") + new_instance = ast::ResourceInstance.new(:title => new_title, :parameters => ast::ASTArray.new(:children => [])) + @resource.instances.push(new_instance) + @resource.evaluate(@scope).collect { |r| r.title }.should == ["mytitle", "other_title"] + end + it "should handover resources to the compiler" do titles = [] %w{one two}.each do |title| titles << Puppet::Parser::AST::String.new(:value => title) end array = Puppet::Parser::AST::ASTArray.new(:children => titles) - @resource.title = array + @instance.title = array result = @resource.evaluate(@scope) 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 end it "should generate virtual and exported resources if it is exported" do @resource.exported = true result = @resource.evaluate(@scope) 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" + ["one", "one::two", "three"].each do |name| + @parser.environment.known_resource_types.add(Puppet::Resource::Type.new(:definition, name, {})) + end @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"), :parameters => params) + instance = Puppet::Parser::AST::ResourceInstance.new( + :title => Puppet::Parser::AST::String.new(:value => "myresource"), :parameters => params) + Puppet::Parser::AST::Resource.new(:type => type, + :instances => Puppet::Parser::AST::ASTArray.new(:children => [instance])) 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 correctly generate resources that can look up defined classes by title" do @scope.known_resource_types.add_hostclass Puppet::Resource::Type.new(:hostclass, "Myresource", {}) res = resource("class").evaluate(@twoscope)[0] res.type.should == "Class" res.title.should == "Myresource" 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/parser_spec.rb b/spec/unit/parser/parser_spec.rb index f73e07a5c..b4e1518c4 100755 --- a/spec/unit/parser/parser_spec.rb +++ b/spec/unit/parser/parser_spec.rb @@ -1,403 +1,412 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../spec_helper' describe Puppet::Parser do ast = Puppet::Parser::AST before :each do @known_resource_types = Puppet::Resource::TypeCollection.new("development") @parser = Puppet::Parser::Parser.new "development" @parser.stubs(:known_resource_types).returns @known_resource_types @true_ast = Puppet::Parser::AST::Boolean.new :value => true end it "should require an environment at initialization" do lambda { Puppet::Parser::Parser.new }.should raise_error(ArgumentError) end it "should set the environment" do env = Puppet::Node::Environment.new Puppet::Parser::Parser.new(env).environment.should == env end it "should convert the environment into an environment instance if a string is provided" do env = Puppet::Node::Environment.new("testing") Puppet::Parser::Parser.new("testing").environment.should == env end it "should be able to look up the environment-specific resource type collection" do rtc = Puppet::Node::Environment.new("development").known_resource_types parser = Puppet::Parser::Parser.new "development" parser.known_resource_types.should equal(rtc) end it "should delegate importing to the known resource type loader" do parser = Puppet::Parser::Parser.new "development" parser.known_resource_types.loader.expects(:import).with("newfile", "current_file") parser.lexer.expects(:file).returns "current_file" parser.import("newfile") end describe "when parsing files" do before do FileTest.stubs(:exist?).returns true File.stubs(:read).returns "" @parser.stubs(:watch_file) end it "should treat files ending in 'rb' as ruby files" do @parser.expects(:parse_ruby_file) @parser.file = "/my/file.rb" @parser.parse end end describe "when parsing append operator" do it "should not raise syntax errors" do lambda { @parser.parse("$var += something") }.should_not raise_error end it "shouldraise syntax error on incomplete syntax " do lambda { @parser.parse("$var += ") }.should raise_error end - it "should call ast::VarDef with append=true" do - ast::VarDef.expects(:new).with { |h| h[:append] == true } - @parser.parse("$var += 2") + it "should create ast::VarDef with append=true" do + vardef = @parser.parse("$var += 2").code[0] + vardef.should be_a(Puppet::Parser::AST::VarDef) + vardef.append.should == true end it "should work with arrays too" do - ast::VarDef.expects(:new).with { |h| h[:append] == true } - @parser.parse("$var += ['test']") + vardef = @parser.parse("$var += ['test']").code[0] + vardef.should be_a(Puppet::Parser::AST::VarDef) + vardef.append.should == true end end describe "when parsing 'if'" do it "not, it should create the correct ast objects" do ast::Not.expects(:new).with { |h| h[:value].is_a?(ast::Boolean) } @parser.parse("if ! true { $var = 1 }") end it "boolean operation, it should create the correct ast objects" do ast::BooleanOperator.expects(:new).with { |h| h[:rval].is_a?(ast::Boolean) and h[:lval].is_a?(ast::Boolean) and h[:operator]=="or" } @parser.parse("if true or true { $var = 1 }") end it "comparison operation, it should create the correct ast objects" do ast::ComparisonOperator.expects(:new).with { |h| h[:lval].is_a?(ast::Name) and h[:rval].is_a?(ast::Name) and h[:operator]=="<" } @parser.parse("if 1 < 2 { $var = 1 }") end end describe "when parsing if complex expressions" do it "should create a correct ast tree" do aststub = stub_everything 'ast' ast::ComparisonOperator.expects(:new).with { |h| h[:rval].is_a?(ast::Name) and h[:lval].is_a?(ast::Name) and h[:operator]==">" }.returns(aststub) ast::ComparisonOperator.expects(:new).with { |h| h[:rval].is_a?(ast::Name) and h[:lval].is_a?(ast::Name) and h[:operator]=="==" }.returns(aststub) ast::BooleanOperator.expects(:new).with { |h| h[:rval]==aststub and h[:lval]==aststub and h[:operator]=="and" } @parser.parse("if (1 > 2) and (1 == 2) { $var = 1 }") end it "should raise an error on incorrect expression" do lambda { @parser.parse("if (1 > 2 > ) or (1 == 2) { $var = 1 }") }.should raise_error end end describe "when parsing resource references" do it "should not raise syntax errors" do lambda { @parser.parse('exec { test: param => File["a"] }') }.should_not raise_error end it "should not raise syntax errors with multiple references" do lambda { @parser.parse('exec { test: param => File["a","b"] }') }.should_not raise_error end it "should create an ast::ResourceReference" do - ast::Resource.stubs(:new) ast::ResourceReference.expects(:new).with { |arg| arg[:line]==1 and arg[:type]=="File" and arg[:title].is_a?(ast::ASTArray) } @parser.parse('exec { test: command => File["a","b"] }') end end describe "when parsing resource overrides" do it "should not raise syntax errors" do lambda { @parser.parse('Resource["title"] { param => value }') }.should_not raise_error end it "should not raise syntax errors with multiple overrides" do lambda { @parser.parse('Resource["title1","title2"] { param => value }') }.should_not raise_error end 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[:parameters].is_a?(ast::ResourceParam) - } - @parser.parse('Resource["title1","title2"] { param => value }') + #ast::ResourceOverride.expects(:new).with { |arg| + # arg[:line]==1 and arg[:object].is_a?(ast::ResourceReference) and arg[:parameters].is_a?(ast::ResourceParam) + #} + ro = @parser.parse('Resource["title1","title2"] { param => value }').code[0] + ro.should be_a(ast::ResourceOverride) + ro.line.should == 1 + ro.object.should be_a(ast::ResourceReference) + ro.parameters[0].should be_a(ast::ResourceParam) end end describe "when parsing if statements" do it "should not raise errors with empty if" do lambda { @parser.parse("if true { }") }.should_not raise_error end it "should not raise errors with empty else" do lambda { @parser.parse("if false { notice('if') } else { }") }.should_not raise_error end it "should not raise errors with empty if and else" do lambda { @parser.parse("if false { } else { }") }.should_not raise_error end it "should create a nop node for empty branch" do ast::Nop.expects(:new) @parser.parse("if true { }") end it "should create a nop node for empty else branch" do ast::Nop.expects(:new) @parser.parse("if true { notice('test') } else { }") end it "should build a chain of 'ifs' if there's an 'elsif'" do ast = @parser.parse(<<-PP) if true { notice('test') } elsif true {} else { } PP end end describe "when parsing function calls" do it "should not raise errors with no arguments" do lambda { @parser.parse("tag()") }.should_not raise_error end it "should not raise errors with rvalue function with no args" do lambda { @parser.parse("$a = template()") }.should_not raise_error end it "should not raise errors with arguments" do lambda { @parser.parse("notice(1)") }.should_not raise_error end it "should not raise errors with multiple arguments" do lambda { @parser.parse("notice(1,2)") }.should_not raise_error end it "should not raise errors with multiple arguments and a trailing comma" do lambda { @parser.parse("notice(1,2,)") }.should_not raise_error end end describe "when parsing arrays with trailing comma" do it "should not raise errors with a trailing comma" do lambda { @parser.parse("$a = [1,2,]") }.should_not raise_error end end describe "when providing AST context" do before do @lexer = stub 'lexer', :line => 50, :file => "/foo/bar", :getcomment => "whev" @parser.stubs(:lexer).returns @lexer end it "should include the lexer's line" do @parser.ast_context[:line].should == 50 end it "should include the lexer's file" do @parser.ast_context[:file].should == "/foo/bar" end it "should include the docs if directed to do so" do @parser.ast_context(true)[:doc].should == "whev" end it "should not include the docs when told not to" do @parser.ast_context(false)[:doc].should be_nil end it "should not include the docs by default" do @parser.ast_context[:doc].should be_nil end end describe "when building ast nodes" do before do @lexer = stub 'lexer', :line => 50, :file => "/foo/bar", :getcomment => "whev" @parser.stubs(:lexer).returns @lexer @class = stub 'class', :use_docs => false end it "should return a new instance of the provided class created with the provided options" do @class.expects(:new).with { |opts| opts[:foo] == "bar" } @parser.ast(@class, :foo => "bar") end it "should merge the ast context into the provided options" do @class.expects(:new).with { |opts| opts[:file] == "/foo" } @parser.expects(:ast_context).returns :file => "/foo" @parser.ast(@class, :foo => "bar") end it "should prefer provided options over AST context" do @class.expects(:new).with { |opts| opts[:file] == "/bar" } @parser.expects(:ast_context).returns :file => "/foo" @parser.ast(@class, :file => "/bar") end it "should include docs when the AST class uses them" do @class.expects(:use_docs).returns true @class.stubs(:new) @parser.expects(:ast_context).with(true).returns({}) @parser.ast(@class, :file => "/bar") end end - describe "when creating a node" do - before :each do - @lexer = stub 'lexer' - @lexer.stubs(:getcomment) - @parser.stubs(:lexer).returns(@lexer) - @node = stub_everything 'node' - @parser.stubs(:ast_context).returns({}) - @parser.stubs(:node).returns(nil) - - @nodename = stub 'nodename', :is_a? => false, :value => "foo" - @nodename.stubs(:is_a?).with(Puppet::Parser::AST::HostName).returns(true) - end - - it "should return an array of nodes" do - @parser.newnode(@nodename).should be_instance_of(Array) - end - end - describe "when retrieving a specific node" do it "should delegate to the known_resource_types node" do @known_resource_types.expects(:node).with("node") @parser.node("node") end end describe "when retrieving a specific class" do it "should delegate to the loaded code" do @known_resource_types.expects(:hostclass).with("class") @parser.hostclass("class") end end describe "when retrieving a specific definitions" do it "should delegate to the loaded code" do @known_resource_types.expects(:definition).with("define") @parser.definition("define") end end describe "when determining the configuration version" do it "should determine it from the resource type collection" do @parser.known_resource_types.expects(:version).returns "foo" @parser.version.should == "foo" end end describe "when looking up definitions" do it "should use the known resource types to check for them by name" do @parser.known_resource_types.stubs(:find_or_load).with("namespace","name",:definition).returns(:this_value) @parser.find_definition("namespace","name").should == :this_value end end describe "when looking up hostclasses" do it "should use the known resource types to check for them by name" do @parser.known_resource_types.stubs(:find_or_load).with("namespace","name",:hostclass).returns(:this_value) @parser.find_hostclass("namespace","name").should == :this_value 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) + it "should not create new classes" do + @parser.parse("class foobar {}").code[0].should be_a(Puppet::Parser::AST::Hostclass) + @krt.hostclass("foobar").should be_nil 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" + @parser.parse("class foobar inherits yayness {}").code[0].instantiate('')[0].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" + statements = @parser.parse("class foobar inherits yayness {}\nclass boo inherits bar {}").code + statements[0].instantiate('')[0].parent.should == "yayness" + statements[1].instantiate('')[0].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 + @parser.parse("class foobar { $var = val }").code[0].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} + foobar = @parser.parse("class foobar($biz,$baz) {}").code[0].instantiate('')[0] + 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 it "should correctly mark exported resources as exported" do - @parser.parse("@@file { '/file': }") - @krt.hostclass("").code[0].exported.should be_true + @parser.parse("@@file { '/file': }").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 + @parser.parse("@file { '/file': }").code[0].virtual.should be_true + end + end + + describe "when parsing nodes" do + it "should be able to parse a node with a single name" do + node = @parser.parse("node foo { }").code[0] + node.should be_a Puppet::Parser::AST::Node + node.names.length.should == 1 + node.names[0].value.should == "foo" + end + + it "should be able to parse a node with two names" do + node = @parser.parse("node foo, bar { }").code[0] + node.should be_a Puppet::Parser::AST::Node + node.names.length.should == 2 + node.names[0].value.should == "foo" + node.names[1].value.should == "bar" + end + + it "should be able to parse a node with three names" do + node = @parser.parse("node foo, bar, baz { }").code[0] + node.should be_a Puppet::Parser::AST::Node + node.names.length.should == 3 + node.names[0].value.should == "foo" + node.names[1].value.should == "bar" + node.names[2].value.should == "baz" end end end diff --git a/spec/unit/parser/scope_spec.rb b/spec/unit/parser/scope_spec.rb index 9895f446b..2e390a53b 100755 --- a/spec/unit/parser/scope_spec.rb +++ b/spec/unit/parser/scope_spec.rb @@ -1,629 +1,628 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../spec_helper' describe Puppet::Parser::Scope do before :each do @topscope = Puppet::Parser::Scope.new # 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 it "should be able to store references to class scopes" do lambda { @scope.class_set "myname", "myscope" }.should_not raise_error end it "should be able to retrieve class scopes by name" do @scope.class_set "myname", "myscope" @scope.class_scope("myname").should == "myscope" end it "should be able to retrieve class scopes by object" do klass = mock 'ast_class' klass.expects(:name).returns("myname") @scope.class_set "myname", "myscope" @scope.class_scope(klass).should == "myscope" end it "should be able to retrieve its parent module name from the source of its parent type" do - @topscope.source = Puppet::Resource::Type.new(:hostclass, :foo) - @topscope.source.module_name = "foo" + @topscope.source = Puppet::Resource::Type.new(:hostclass, :foo, :module_name => "foo") @scope.parent_module_name.should == "foo" end it "should return a nil parent module name if it has no parent" do @topscope.parent_module_name.should be_nil end it "should return a nil parent module name if its parent has no source" do @scope.parent_module_name.should be_nil end it "should get its environment from its compiler" do env = stub 'environment' compiler = stub 'compiler', :environment => env scope = Puppet::Parser::Scope.new :compiler => compiler scope.environment.should equal(env) end it "should use the resource type collection helper to find its known resource types" do Puppet::Parser::Scope.ancestors.should include(Puppet::Resource::TypeCollectionHelper) end describe "when initializing" do it "should extend itself with its environment's Functions module as well as the default" do env = Puppet::Node::Environment.new("myenv") compiler = stub 'compiler', :environment => env mod = Module.new root_mod = Module.new Puppet::Parser::Functions.expects(:environment_module).with(Puppet::Node::Environment.root).returns root_mod Puppet::Parser::Functions.expects(:environment_module).with(env).returns mod Puppet::Parser::Scope.new(:compiler => compiler).singleton_class.ancestors.should be_include(mod) end it "should extend itself with the default Functions module if it has no environment" do mod = Module.new Puppet::Parser::Functions.expects(:environment_module).with(Puppet::Node::Environment.root).returns(mod) Puppet::Parser::Functions.expects(:environment_module).with(nil).returns mod Puppet::Parser::Scope.new.singleton_class.ancestors.should be_include(mod) end end describe "when looking up a variable" do it "should default to an empty string" do @scope.lookupvar("var").should == "" end it "should return an string when asked for a string" do @scope.lookupvar("var", true).should == "" end it "should return ':undefined' for unset variables when asked not to return a string" do @scope.lookupvar("var", false).should == :undefined end it "should be able to look up values" do @scope.setvar("var", "yep") @scope.lookupvar("var").should == "yep" end it "should be able to look up hashes" do @scope.setvar("var", {"a" => "b"}) @scope.lookupvar("var").should == {"a" => "b"} end it "should be able to look up variables in parent scopes" do @topscope.setvar("var", "parentval") @scope.lookupvar("var").should == "parentval" end it "should prefer its own values to parent values" do @topscope.setvar("var", "parentval") @scope.setvar("var", "childval") @scope.lookupvar("var").should == "childval" end describe "and the variable is qualified" do before do @compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("foonode")) @scope.compiler = @compiler @known_resource_types = @scope.known_resource_types end def newclass(name) @known_resource_types.add Puppet::Resource::Type.new(:hostclass, name) end def create_class_scope(name) klass = newclass(name) Puppet::Parser::Resource.new("class", name, :scope => @scope, :source => mock('source')).evaluate @scope.class_scope(klass) end it "should be able to look up explicitly fully qualified variables from main" do other_scope = create_class_scope("") other_scope.setvar("othervar", "otherval") @scope.lookupvar("::othervar").should == "otherval" end it "should be able to look up explicitly fully qualified variables from other scopes" do other_scope = create_class_scope("other") other_scope.setvar("var", "otherval") @scope.lookupvar("::other::var").should == "otherval" end it "should be able to look up deeply qualified variables" do other_scope = create_class_scope("other::deep::klass") other_scope.setvar("var", "otherval") @scope.lookupvar("other::deep::klass::var").should == "otherval" end it "should return an empty string for qualified variables that cannot be found in other classes" do other_scope = create_class_scope("other::deep::klass") @scope.lookupvar("other::deep::klass::var").should == "" end it "should warn and return an empty string for qualified variables whose classes have not been evaluated" do klass = newclass("other::deep::klass") @scope.expects(:warning) @scope.lookupvar("other::deep::klass::var").should == "" end it "should warn and return an empty string for qualified variables whose classes do not exist" do @scope.expects(:warning) @scope.lookupvar("other::deep::klass::var").should == "" end it "should return ':undefined' when asked for a non-string qualified variable from a class that does not exist" do @scope.stubs(:warning) @scope.lookupvar("other::deep::klass::var", false).should == :undefined end it "should return ':undefined' when asked for a non-string qualified variable from a class that has not been evaluated" do @scope.stubs(:warning) klass = newclass("other::deep::klass") @scope.lookupvar("other::deep::klass::var", false).should == :undefined end end end describe "when setvar is called with append=true" do it "should raise error if the variable is already defined in this scope" do @scope.setvar("var","1", :append => false) lambda { @scope.setvar("var","1", :append => true) }.should raise_error(Puppet::ParseError) end it "should lookup current variable value" do @scope.expects(:lookupvar).with("var").returns("2") @scope.setvar("var","1", :append => true) end it "should store the concatenated string '42'" do @topscope.setvar("var","4", :append => false) @scope.setvar("var","2", :append => true) @scope.lookupvar("var").should == "42" end it "should store the concatenated array [4,2]" do @topscope.setvar("var",[4], :append => false) @scope.setvar("var",[2], :append => true) @scope.lookupvar("var").should == [4,2] end it "should store the merged hash {a => b, c => d}" do @topscope.setvar("var",{"a" => "b"}, :append => false) @scope.setvar("var",{"c" => "d"}, :append => true) @scope.lookupvar("var").should == {"a" => "b", "c" => "d"} end it "should raise an error when appending a hash with something other than another hash" do @topscope.setvar("var",{"a" => "b"}, :append => false) lambda { @scope.setvar("var","not a hash", :append => true) }.should raise_error end end describe "when calling number?" do it "should return nil if called with anything not a number" do Puppet::Parser::Scope.number?([2]).should be_nil end it "should return a Fixnum for a Fixnum" do Puppet::Parser::Scope.number?(2).should be_an_instance_of(Fixnum) end it "should return a Float for a Float" do Puppet::Parser::Scope.number?(2.34).should be_an_instance_of(Float) end it "should return 234 for '234'" do Puppet::Parser::Scope.number?("234").should == 234 end it "should return nil for 'not a number'" do Puppet::Parser::Scope.number?("not a number").should be_nil end it "should return 23.4 for '23.4'" do Puppet::Parser::Scope.number?("23.4").should == 23.4 end it "should return 23.4e13 for '23.4e13'" do Puppet::Parser::Scope.number?("23.4e13").should == 23.4e13 end it "should understand negative numbers" do Puppet::Parser::Scope.number?("-234").should == -234 end it "should know how to convert exponential float numbers ala '23e13'" do Puppet::Parser::Scope.number?("23e13").should == 23e13 end it "should understand hexadecimal numbers" do Puppet::Parser::Scope.number?("0x234").should == 0x234 end it "should understand octal numbers" do Puppet::Parser::Scope.number?("0755").should == 0755 end it "should return nil on malformed integers" do Puppet::Parser::Scope.number?("0.24.5").should be_nil end it "should convert strings with leading 0 to integer if they are not octal" do Puppet::Parser::Scope.number?("0788").should == 788 end it "should convert strings of negative integers" do Puppet::Parser::Scope.number?("-0788").should == -788 end it "should return nil on malformed hexadecimal numbers" do Puppet::Parser::Scope.number?("0x89g").should be_nil end end describe "when using ephemeral variables" do it "should store the variable value" do @scope.setvar("1", :value, :ephemeral => true) @scope.lookupvar("1").should == :value end it "should remove the variable value when unset_ephemeral_var is called" do @scope.setvar("1", :value, :ephemeral => true) @scope.stubs(:parent).returns(nil) @scope.unset_ephemeral_var @scope.lookupvar("1", false).should == :undefined end it "should not remove classic variables when unset_ephemeral_var is called" do @scope.setvar("myvar", :value1) @scope.setvar("1", :value2, :ephemeral => true) @scope.stubs(:parent).returns(nil) @scope.unset_ephemeral_var @scope.lookupvar("myvar", false).should == :value1 end it "should raise an error when setting it again" do @scope.setvar("1", :value2, :ephemeral => true) lambda { @scope.setvar("1", :value3, :ephemeral => true) }.should raise_error end it "should declare ephemeral number only variable names" do @scope.ephemeral?("0").should be_true end it "should not declare ephemeral other variable names" do @scope.ephemeral?("abc0").should be_nil end describe "with more than one level" do it "should prefer latest ephemeral scopes" do @scope.setvar("0", :earliest, :ephemeral => true) @scope.new_ephemeral @scope.setvar("0", :latest, :ephemeral => true) @scope.lookupvar("0", false).should == :latest end it "should be able to report the current level" do @scope.ephemeral_level.should == 1 @scope.new_ephemeral @scope.ephemeral_level.should == 2 end it "should check presence of an ephemeral variable accross multiple levels" do @scope.new_ephemeral @scope.setvar("1", :value1, :ephemeral => true) @scope.new_ephemeral @scope.setvar("0", :value2, :ephemeral => true) @scope.new_ephemeral @scope.ephemeral_include?("1").should be_true end it "should return false when an ephemeral variable doesn't exist in any ephemeral scope" do @scope.new_ephemeral @scope.setvar("1", :value1, :ephemeral => true) @scope.new_ephemeral @scope.setvar("0", :value2, :ephemeral => true) @scope.new_ephemeral @scope.ephemeral_include?("2").should be_false end it "should get ephemeral values from earlier scope when not in later" do @scope.setvar("1", :value1, :ephemeral => true) @scope.new_ephemeral @scope.setvar("0", :value2, :ephemeral => true) @scope.lookupvar("1", false).should == :value1 end describe "when calling unset_ephemeral_var without a level" do it "should remove all the variables values" do @scope.setvar("1", :value1, :ephemeral => true) @scope.new_ephemeral @scope.setvar("1", :value2, :ephemeral => true) @scope.unset_ephemeral_var @scope.lookupvar("1", false).should == :undefined end end describe "when calling unset_ephemeral_var with a level" do it "should remove ephemeral scopes up to this level" do @scope.setvar("1", :value1, :ephemeral => true) @scope.new_ephemeral @scope.setvar("1", :value2, :ephemeral => true) @scope.new_ephemeral @scope.setvar("1", :value3, :ephemeral => true) @scope.unset_ephemeral_var(2) @scope.lookupvar("1", false).should == :value2 end end end end describe "when interpolating string" do (0..9).each do |n| it "should allow $#{n} to match" do @scope.setvar(n.to_s, "value", :ephemeral => true) @scope.strinterp("$#{n}").should == "value" end end (0..9).each do |n| it "should not allow $#{n} to match if not ephemeral" do @scope.setvar(n.to_s, "value", :ephemeral => false) @scope.strinterp("$#{n}").should_not == "value" end end it "should not allow $10 to match" do @scope.setvar("10", "value", :ephemeral => true) @scope.strinterp('==$10==').should_not == "==value==" end it "should not allow ${10} to match" do @scope.setvar("10", "value", :ephemeral => true) @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.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.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.class_scope(klass) scopes[name].setvar("test", "value-#{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 #{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 #{string}") logs.clear end end describe "when setting ephemeral vars from matches" do before :each do @match = stub 'match', :is_a? => true @match.stubs(:[]).with(0).returns("this is a string") @match.stubs(:captures).returns([]) @scope.stubs(:setvar) end it "should accept only MatchData" do lambda { @scope.ephemeral_from("match") }.should raise_error end it "should set $0 with the full match" do @scope.expects(:setvar).with { |*arg| arg[0] == "0" and arg[1] == "this is a string" and arg[2][:ephemeral] } @scope.ephemeral_from(@match) end it "should set every capture as ephemeral var" do @match.stubs(:captures).returns([:capture1,:capture2]) @scope.expects(:setvar).with { |*arg| arg[0] == "1" and arg[1] == :capture1 and arg[2][:ephemeral] } @scope.expects(:setvar).with { |*arg| arg[0] == "2" and arg[1] == :capture2 and arg[2][:ephemeral] } @scope.ephemeral_from(@match) end it "should create a new ephemeral level" do @scope.expects(:new_ephemeral) @scope.ephemeral_from(@match) end end describe "when unsetting variables" do it "should be able to unset normal variables" do @scope.setvar("foo", "bar") @scope.unsetvar("foo") @scope.lookupvar("foo").should == "" end it "should be able to unset ephemeral variables" do @scope.setvar("0", "bar", :ephemeral => true) @scope.unsetvar("0") @scope.lookupvar("0").should == "" end it "should not unset ephemeral variables in previous ephemeral scope" do @scope.setvar("0", "bar", :ephemeral => true) @scope.new_ephemeral @scope.unsetvar("0") @scope.lookupvar("0").should == "bar" 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/parser/type_loader_spec.rb b/spec/unit/parser/type_loader_spec.rb index 02d543b02..cfa68871d 100644 --- a/spec/unit/parser/type_loader_spec.rb +++ b/spec/unit/parser/type_loader_spec.rb @@ -1,188 +1,134 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/parser/type_loader' require 'puppet_spec/files' describe Puppet::Parser::TypeLoader do include PuppetSpec::Files before do @loader = Puppet::Parser::TypeLoader.new(:myenv) end it "should support an environment" do loader = Puppet::Parser::TypeLoader.new(:myenv) loader.environment.name.should == :myenv end it "should include the Environment Helper" do @loader.class.ancestors.should be_include(Puppet::Node::Environment::Helper) end it "should delegate its known resource types to its environment" do @loader.known_resource_types.should be_instance_of(Puppet::Resource::TypeCollection) end describe "when loading names from namespaces" do it "should do nothing if the name to import is an empty string" do @loader.expects(:name2files).never - @loader.load_until(["foo"], "") { |f| false }.should be_nil - end - - it "should turn the provided namespaces and name into a list of files" do - @loader.expects(:name2files).with(["foo"], "bar").returns [] - @loader.load_until(["foo"], "bar") { |f| false } + @loader.try_load_fqname(:hostclass, "") { |filename, modname| raise :should_not_occur }.should be_nil end it "should attempt to import each generated name" do - @loader.expects(:name2files).returns %w{foo bar} - @loader.expects(:import).with("foo",nil) - @loader.expects(:import).with("bar",nil) - @loader.load_until(["foo"], "bar") { |f| false } - end - - it "should yield after each import" do - yielded = [] - @loader.expects(:name2files).returns %w{foo bar} - @loader.expects(:import).with("foo",nil) - @loader.expects(:import).with("bar",nil) - @loader.load_until(["foo"], "bar") { |f| yielded << f; false } - yielded.should == %w{foo bar} - end - - it "should stop importing when the yielded block returns true" do - yielded = [] - @loader.expects(:name2files).returns %w{foo bar baz} - @loader.expects(:import).with("foo",nil) - @loader.expects(:import).with("bar",nil) - @loader.expects(:import).with("baz",nil).never - @loader.load_until(["foo"], "bar") { |f| true if f == "bar" } - end - - it "should return the result of the block" do - yielded = [] - @loader.expects(:name2files).returns %w{foo bar baz} - @loader.expects(:import).with("foo",nil) - @loader.expects(:import).with("bar",nil) - @loader.expects(:import).with("baz",nil).never - @loader.load_until(["foo"], "bar") { |f| 10 if f == "bar" }.should == 10 - end - - it "should return nil if the block never returns true" do - @loader.expects(:name2files).returns %w{foo bar} - @loader.expects(:import).with("foo",nil) - @loader.expects(:import).with("bar",nil) - @loader.load_until(["foo"], "bar") { |f| false }.should be_nil - end - - it "should set the module name on any created resource types" do - type = Puppet::Resource::Type.new(:hostclass, "mytype") - - Puppet::Parser::Files.expects(:find_manifests).returns ["modname", %w{one}] - @loader.stubs(:parse_file) - @loader.load_until(["foo"], "one") { |f| type } - - type.module_name.should == "modname" - end - end - - describe "when mapping names to files" do - { - [["foo"], "::bar::baz"] => %w{bar/baz}, - [[""], "foo::bar"] => %w{foo foo/bar}, - [%w{foo}, "bar"] => %w{foo foo/bar bar}, - [%w{a b}, "bar"] => %w{a a/bar b b/bar bar}, - [%w{a::b::c}, "bar"] => %w{a a/b/c/bar bar}, - [%w{a::b}, "foo::bar"] => %w{a a/b/foo/bar foo/bar} - }.each do |inputs, outputs| - it "should produce #{outputs.inspect} from the #{inputs[0].inspect} namespace and #{inputs[1]} name" do - @loader.name2files(*inputs).should == outputs - end + @loader.expects(:import).with("foo/bar",nil).returns([]) + @loader.expects(:import).with("foo",nil).returns([]) + @loader.try_load_fqname(:hostclass, "foo::bar") { |f| false } end end describe "when importing" do before do Puppet::Parser::Files.stubs(:find_manifests).returns ["modname", %w{file}] - Puppet::Parser::Parser.any_instance.stubs(:parse) + Puppet::Parser::Parser.any_instance.stubs(:parse).returns(Puppet::Parser::AST::Hostclass.new('')) Puppet::Parser::Parser.any_instance.stubs(:file=) end it "should return immediately when imports are being ignored" do Puppet::Parser::Files.expects(:find_manifests).never Puppet[:ignoreimport] = true @loader.import("foo").should be_nil end it "should find all manifests matching the file or pattern" do Puppet::Parser::Files.expects(:find_manifests).with { |pat, opts| pat == "myfile" }.returns ["modname", %w{one}] @loader.import("myfile") end it "should use the directory of the current file if one is set" do Puppet::Parser::Files.expects(:find_manifests).with { |pat, opts| opts[:cwd] == "/current" }.returns ["modname", %w{one}] @loader.import("myfile", "/current/file") end it "should pass the environment when looking for files" do Puppet::Parser::Files.expects(:find_manifests).with { |pat, opts| opts[:environment] == @loader.environment }.returns ["modname", %w{one}] @loader.import("myfile") end it "should fail if no files are found" do Puppet::Parser::Files.expects(:find_manifests).returns [nil, []] lambda { @loader.import("myfile") }.should raise_error(Puppet::ImportError) end it "should parse each found file" do Puppet::Parser::Files.expects(:find_manifests).returns ["modname", %w{/one}] - @loader.expects(:parse_file).with("/one") + @loader.expects(:parse_file).with("/one").returns(Puppet::Parser::AST::Hostclass.new('')) @loader.import("myfile") end it "should make each file qualified before attempting to parse it" do Puppet::Parser::Files.expects(:find_manifests).returns ["modname", %w{one}] - @loader.expects(:parse_file).with("/current/one") + @loader.expects(:parse_file).with("/current/one").returns(Puppet::Parser::AST::Hostclass.new('')) @loader.import("myfile", "/current/file") end it "should not attempt to import files that have already been imported" do Puppet::Parser::Files.expects(:find_manifests).returns ["modname", %w{/one}] - Puppet::Parser::Parser.any_instance.expects(:parse).once + Puppet::Parser::Parser.any_instance.expects(:parse).once.returns(Puppet::Parser::AST::Hostclass.new('')) @loader.import("myfile") # This will fail if it tries to reimport the file. @loader.import("myfile") end end describe "when parsing a file" do before do @parser = Puppet::Parser::Parser.new(@loader.environment) - @parser.stubs(:parse) + @parser.stubs(:parse).returns(Puppet::Parser::AST::Hostclass.new('')) @parser.stubs(:file=) Puppet::Parser::Parser.stubs(:new).with(@loader.environment).returns @parser end it "should create a new parser instance for each file using the current environment" do Puppet::Parser::Parser.expects(:new).with(@loader.environment).returns @parser @loader.parse_file("/my/file") end it "should assign the parser its file and parse" do @parser.expects(:file=).with("/my/file") - @parser.expects(:parse) + @parser.expects(:parse).returns(Puppet::Parser::AST::Hostclass.new('')) @loader.parse_file("/my/file") end end it "should be able to add classes to the current resource type collection" do file = tmpfile("simple_file.pp") File.open(file, "w") { |f| f.puts "class foo {}" } @loader.import(file) @loader.known_resource_types.hostclass("foo").should be_instance_of(Puppet::Resource::Type) end + + describe "when deciding where to look for files" do + { 'foo' => ['foo'], + 'foo::bar' => ['foo/bar', 'foo'], + 'foo::bar::baz' => ['foo/bar/baz', 'foo/bar', 'foo'] + }.each do |fqname, expected_paths| + it "should look for #{fqname.inspect} in #{expected_paths.inspect}" do + @loader.instance_eval { name2files(fqname) }.should == expected_paths + end + end + end end diff --git a/spec/unit/resource/type_collection_spec.rb b/spec/unit/resource/type_collection_spec.rb index 577aea42b..b8da3cf58 100644 --- a/spec/unit/resource/type_collection_spec.rb +++ b/spec/unit/resource/type_collection_spec.rb @@ -1,467 +1,447 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/resource/type_collection' require 'puppet/resource/type' describe Puppet::Resource::TypeCollection do before do @instance = Puppet::Resource::Type.new(:hostclass, "foo") @code = Puppet::Resource::TypeCollection.new("env") end it "should require an environment at initialization" do env = Puppet::Node::Environment.new("testing") Puppet::Resource::TypeCollection.new(env).environment.should equal(env) end it "should convert the environment into an environment instance if a string is provided" do env = Puppet::Node::Environment.new("testing") Puppet::Resource::TypeCollection.new("testing").environment.should equal(env) end it "should create a 'loader' at initialization" do Puppet::Resource::TypeCollection.new("testing").loader.should be_instance_of(Puppet::Parser::TypeLoader) end it "should be able to add a resource type" do Puppet::Resource::TypeCollection.new("env").should respond_to(:add) end it "should consider '<<' to be an alias to 'add' but should return self" do loader = Puppet::Resource::TypeCollection.new("env") loader.expects(:add).with "foo" loader.expects(:add).with "bar" loader << "foo" << "bar" end it "should set itself as the code collection for added resource types" do loader = Puppet::Resource::TypeCollection.new("env") node = Puppet::Resource::Type.new(:node, "foo") @code.add(node) @code.node("foo").should equal(node) node.resource_type_collection.should equal(@code) end it "should store node resource types as nodes" do node = Puppet::Resource::Type.new(:node, "foo") @code.add(node) @code.node("foo").should equal(node) end it "should store hostclasses as hostclasses" do klass = Puppet::Resource::Type.new(:hostclass, "foo") @code.add(klass) @code.hostclass("foo").should equal(klass) end it "should store definitions as definitions" do define = Puppet::Resource::Type.new(:definition, "foo") @code.add(define) @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 + describe "when resolving namespaces" do + [ ['', '::foo', ['foo']], + ['a', '::foo', ['foo']], + ['a::b', '::foo', ['foo']], + [['a::b'], '::foo', ['foo']], + [['a::b', 'c'], '::foo', ['foo']], + [['A::B', 'C'], '::Foo', ['foo']], + ['', '', ['']], + ['a', '', ['']], + ['a::b', '', ['']], + [['a::b'], '', ['']], + [['a::b', 'c'], '', ['']], + [['A::B', 'C'], '', ['']], + ['', 'foo', ['foo']], + ['a', 'foo', ['a::foo', 'foo']], + ['a::b', 'foo', ['a::b::foo', 'a::foo', 'foo']], + ['A::B', 'Foo', ['a::b::foo', 'a::foo', 'foo']], + [['a::b'], 'foo', ['a::b::foo', 'a::foo', 'foo']], + [['a', 'b'], 'foo', ['a::foo', 'foo', 'b::foo']], + [['a::b', 'c::d'], 'foo', ['a::b::foo', 'a::foo', 'foo', 'c::d::foo', 'c::foo']], + [['a::b', 'a::c'], 'foo', ['a::b::foo', 'a::foo', 'foo', 'a::c::foo']], + ].each do |namespaces, name, expected_result| + it "should resolve #{name.inspect} in namespaces #{namespaces.inspect} correctly" do + @code.instance_eval { resolve_namespaces(namespaces, name) }.should == expected_result + end + end + end + describe "when looking up names" do before do @type = Puppet::Resource::Type.new(:hostclass, "ns::klass") end it "should support looking up with multiple namespaces" do @code.add @type @code.find_hostclass(%w{boo baz ns}, "klass").should equal(@type) end it "should not attempt to import anything when the type is already defined" do @code.add @type @code.loader.expects(:import).never @code.find_hostclass(%w{ns}, "klass").should equal(@type) end describe "that need to be loaded" do it "should use the loader to load the files" do - @code.loader.expects(:load_until).with(["ns"], "klass") - @code.find_or_load(["ns"], "klass", :hostclass) + @code.loader.expects(:try_load_fqname).with(:hostclass, "ns::klass") + @code.loader.expects(:try_load_fqname).with(:hostclass, "klass") + @code.find_hostclass(["ns"], "klass") end it "should downcase the name and downcase and array-fy the namespaces before passing to the loader" do - @code.loader.expects(:load_until).with(["ns"], "klass") - @code.find_or_load("Ns", "Klass", :hostclass) + @code.loader.expects(:try_load_fqname).with(:hostclass, "ns::klass") + @code.loader.expects(:try_load_fqname).with(:hostclass, "klass") + @code.find_hostclass("Ns", "Klass") end - it "should attempt to find the type when the loader yields" do - @code.loader.expects(:load_until).yields - @code.expects(:find).with(["ns"], "klass", :hostclass).times(2).returns(false).then.returns(true) - @code.find_or_load("ns", "klass", :hostclass) + it "should use the class returned by the loader" do + @code.loader.expects(:try_load_fqname).returns(:klass) + @code.expects(:hostclass).with("ns::klass").returns(false) + @code.find_hostclass("ns", "klass").should == :klass end - it "should return the result of 'load_until'" do - @code.loader.expects(:load_until).returns "foo" - @code.find_or_load("Ns", "Klass", :hostclass).should == "foo" + it "should return nil if the name isn't found" do + @code.stubs(:try_load_fqname).returns(nil) + @code.find_hostclass("Ns", "Klass").should be_nil end - it "should return nil if the name isn't found" do - @code.stubs(:load_until).returns(nil) - @code.find_or_load("Ns", "Klass", :hostclass).should be_nil + it "already-loaded names at broader scopes should not shadow autoloaded names" do + @code.add Puppet::Resource::Type.new(:hostclass, "bar") + @code.loader.expects(:try_load_fqname).with(:hostclass, "foo::bar").returns(:foobar) + @code.find_hostclass("foo", "bar").should == :foobar end end 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 it "should use the name of the instance to add it" do loader = Puppet::Resource::TypeCollection.new("env") loader.send("add_#{data}", @instance) loader.send(data, @instance.name).should equal(@instance) end 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 loader = Puppet::Resource::TypeCollection.new("env") loader.add(@instance).should equal(@instance) end it "should be able to retrieve #{data} by name" do loader = Puppet::Resource::TypeCollection.new("env") instance = Puppet::Resource::Type.new(data, "bar") loader.add instance loader.send(data, "bar").should equal(instance) end it "should retrieve #{data} insensitive to case" do loader = Puppet::Resource::TypeCollection.new("env") instance = Puppet::Resource::Type.new(data, "Bar") loader.add instance loader.send(data, "bAr").should equal(instance) end it "should return nil when asked for a #{data} that has not been added" do Puppet::Resource::TypeCollection.new("env").send(data, "foo").should be_nil end it "should be able to retrieve all #{data}s" do plurals = { "hostclass" => "hostclasses", "node" => "nodes", "definition" => "definitions" } loader = Puppet::Resource::TypeCollection.new("env") instance = Puppet::Resource::Type.new(data, "foo") loader.add instance loader.send(plurals[data]).should == { "foo" => instance } end end describe "when finding a qualified instance" do it "should return any found instance if the instance name is fully qualified" do loader = Puppet::Resource::TypeCollection.new("env") instance = Puppet::Resource::Type.new(:hostclass, "foo::bar") loader.add instance - loader.find("namespace", "::foo::bar", :hostclass).should equal(instance) + loader.find_hostclass("namespace", "::foo::bar").should equal(instance) end it "should return nil if the instance name is fully qualified and no such instance exists" do loader = Puppet::Resource::TypeCollection.new("env") - loader.find("namespace", "::foo::bar", :hostclass).should be_nil + loader.find_hostclass("namespace", "::foo::bar").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) + loader.find_hostclass("", "foo").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") loader.add instance - loader.find("foo", "bar::baz", :hostclass).should equal(instance) + loader.find_hostclass("foo", "bar::baz").should equal(instance) end 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) + loader.find_hostclass(["nons", "foo", "otherns"], "bar::baz").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 - loader.find("foo", "bar", :hostclass).should equal(instance) + loader.find_hostclass("foo", "bar").should equal(instance) end it "should return the unqualified object if it exists in the parent namespace" do loader = Puppet::Resource::TypeCollection.new("env") instance = Puppet::Resource::Type.new(:hostclass, "foo::bar") loader.add instance - loader.find("foo::bar::baz", "bar", :hostclass).should equal(instance) + loader.find_hostclass("foo::bar::baz", "bar").should equal(instance) end it "should should return the partially qualified object if it exists in the parent namespace" do loader = Puppet::Resource::TypeCollection.new("env") instance = Puppet::Resource::Type.new(:hostclass, "foo::bar::baz") loader.add instance - loader.find("foo::bar", "bar::baz", :hostclass).should equal(instance) + loader.find_hostclass("foo::bar", "bar::baz").should equal(instance) end it "should return the qualified object if it exists in the root namespace" do loader = Puppet::Resource::TypeCollection.new("env") instance = Puppet::Resource::Type.new(:hostclass, "foo::bar::baz") loader.add instance - loader.find("foo::bar", "foo::bar::baz", :hostclass).should equal(instance) + loader.find_hostclass("foo::bar", "foo::bar::baz").should equal(instance) end it "should return nil if the object cannot be found" do loader = Puppet::Resource::TypeCollection.new("env") instance = Puppet::Resource::Type.new(:hostclass, "foo::bar::baz") loader.add instance - loader.find("foo::bar", "eh", :hostclass).should be_nil + loader.find_hostclass("foo::bar", "eh").should be_nil end describe "when topscope has a class that has the same name as a local class" do before do @loader = Puppet::Resource::TypeCollection.new("env") [ "foo::bar", "bar" ].each do |name| @loader.add Puppet::Resource::Type.new(:hostclass, name) end end it "should favor the local class, if the name is unqualified" do - @loader.find("foo", "bar", :hostclass).name.should == 'foo::bar' + @loader.find_hostclass("foo", "bar").name.should == 'foo::bar' end it "should only look in the topclass, if the name is qualified" do - @loader.find("foo", "::bar", :hostclass).name.should == 'bar' + @loader.find_hostclass("foo", "::bar").name.should == 'bar' end end it "should not look in the local scope for classes when the name is qualified" do @loader = Puppet::Resource::TypeCollection.new("env") @loader.add Puppet::Resource::Type.new(:hostclass, "foo::bar") - @loader.find("foo", "::bar", :hostclass).should == nil + @loader.find_hostclass("foo", "::bar").should == nil end end - it "should use the generic 'find' method with an empty namespace to find nodes" do + it "should be able to find nodes" do + node = Puppet::Resource::Type.new(:node, "bar") loader = Puppet::Resource::TypeCollection.new("env") - loader.expects(:find).with("", "bar", :node) - loader.find_node(stub("ignored"), "bar") + loader.add(node) + loader.find_node(stub("ignored"), "bar").should == node end it "should use the 'find_or_load' method to find hostclasses" do loader = Puppet::Resource::TypeCollection.new("env") loader.expects(:find_or_load).with("foo", "bar", :hostclass) loader.find_hostclass("foo", "bar") end it "should use the 'find_or_load' method to find definitions" do loader = Puppet::Resource::TypeCollection.new("env") loader.expects(:find_or_load).with("foo", "bar", :definition) loader.find_definition("foo", "bar") end it "should indicate whether any nodes are defined" do loader = Puppet::Resource::TypeCollection.new("env") loader.add_node(Puppet::Resource::Type.new(:node, "foo")) loader.should be_nodes end it "should indicate whether no nodes are defined" do Puppet::Resource::TypeCollection.new("env").should_not be_nodes end describe "when finding nodes" do before :each do @loader = Puppet::Resource::TypeCollection.new("env") end it "should return any node whose name exactly matches the provided node name" do node = Puppet::Resource::Type.new(:node, "foo") @loader << node @loader.node("foo").should equal(node) end it "should return the first regex node whose regex matches the provided node name" do node1 = Puppet::Resource::Type.new(:node, /\w/) node2 = Puppet::Resource::Type.new(:node, /\d/) @loader << node1 << node2 @loader.node("foo10").should equal(node1) end it "should preferentially return a node whose name is string-equal over returning a node whose regex matches a provided name" do node1 = Puppet::Resource::Type.new(:node, /\w/) node2 = Puppet::Resource::Type.new(:node, "foo") @loader << node1 << node2 @loader.node("foo").should equal(node2) end end describe "when managing files" do before do @loader = Puppet::Resource::TypeCollection.new("env") Puppet::Util::LoadedFile.stubs(:new).returns stub("watched_file") end it "should have a method for specifying a file should be watched" do @loader.should respond_to(:watch_file) end it "should have a method for determining if a file is being watched" do @loader.watch_file("/foo/bar") @loader.should be_watching_file("/foo/bar") end it "should use LoadedFile to watch files" do Puppet::Util::LoadedFile.expects(:new).with("/foo/bar").returns stub("watched_file") @loader.watch_file("/foo/bar") end it "should be considered stale if any files have changed" do file1 = stub 'file1', :changed? => false file2 = stub 'file2', :changed? => true Puppet::Util::LoadedFile.expects(:new).times(2).returns(file1).then.returns(file2) @loader.watch_file("/foo/bar") @loader.watch_file("/other/bar") @loader.should be_stale end it "should not be considered stable if no files have changed" do file1 = stub 'file1', :changed? => false file2 = stub 'file2', :changed? => false Puppet::Util::LoadedFile.expects(:new).times(2).returns(file1).then.returns(file2) @loader.watch_file("/foo/bar") @loader.watch_file("/other/bar") @loader.should_not be_stale end end - describe "when performing initial import" do - before do - @parser = stub 'parser', :file= => nil, :string => nil, :parse => nil - Puppet::Parser::Parser.stubs(:new).returns @parser - @code = Puppet::Resource::TypeCollection.new("env") - end - - it "should create a new parser instance" do - Puppet::Parser::Parser.expects(:new).returns @parser - @code.perform_initial_import - end - - it "should set the parser's string to the 'code' setting and parse if code is available" do - Puppet.settings[:code] = "my code" - @parser.expects(:string=).with "my code" - @parser.expects(:parse) - @code.perform_initial_import - end - - it "should set the parser's file to the 'manifest' setting and parse if no code is available and the manifest is available" do - File.stubs(:expand_path).with("/my/file").returns "/my/file" - File.expects(:exist?).with("/my/file").returns true - Puppet.settings[:manifest] = "/my/file" - @parser.expects(:file=).with "/my/file" - @parser.expects(:parse) - @code.perform_initial_import - end - - it "should not attempt to load a manifest if none is present" do - File.stubs(:expand_path).with("/my/file").returns "/my/file" - File.expects(:exist?).with("/my/file").returns false - Puppet.settings[:manifest] = "/my/file" - @parser.expects(:file=).never - @parser.expects(:parse).never - @code.perform_initial_import - end - - it "should fail helpfully if there is an error importing" do - File.stubs(:exist?).returns true - @parser.expects(:parse).raises ArgumentError - lambda { @code.perform_initial_import }.should raise_error(Puppet::Error) - end - - it "should not do anything if the ignore_import settings is set" do - Puppet.settings[:ignoreimport] = true - @parser.expects(:string=).never - @parser.expects(:file=).never - @parser.expects(:parse).never - @code.perform_initial_import - end - end - describe "when determining the configuration version" do before do @code = Puppet::Resource::TypeCollection.new("env") end it "should default to the current time" do time = Time.now Time.stubs(:now).returns time @code.version.should == time.to_i end it "should use the output of the environment's config_version setting if one is provided" do @code.environment.stubs(:[]).with(:config_version).returns("/my/foo") Puppet::Util.expects(:execute).with(["/my/foo"]).returns "output\n" @code.version.should == "output" end it "should raise a puppet parser error if executing config_version fails" do @code.environment.stubs(:[]).with(:config_version).returns("test") Puppet::Util.expects(:execute).raises(Puppet::ExecutionFailure.new("msg")) lambda { @code.version }.should raise_error(Puppet::ParseError) end end end diff --git a/spec/unit/resource/type_spec.rb b/spec/unit/resource/type_spec.rb index f58092ec5..7701e55d5 100755 --- a/spec/unit/resource/type_spec.rb +++ b/spec/unit/resource/type_spec.rb @@ -1,740 +1,739 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/resource/type' describe Puppet::Resource::Type do it "should have a 'name' attribute" do Puppet::Resource::Type.new(:hostclass, "foo").name.should == "foo" end [:code, :doc, :line, :file, :resource_type_collection, :ruby_code].each do |attr| it "should have a '#{attr}' attribute" do type = Puppet::Resource::Type.new(:hostclass, "foo") type.send(attr.to_s + "=", "yay") type.send(attr).should == "yay" end end [:hostclass, :node, :definition].each do |type| it "should know when it is a #{type}" do Puppet::Resource::Type.new(type, "foo").send("#{type}?").should be_true end end it "should indirect 'resource_type'" do Puppet::Resource::Type.indirection.name.should == :resource_type end it "should default to 'parser' for its terminus class" do Puppet::Resource::Type.indirection.terminus_class.should == :parser end describe "when converting to json" do before do @type = Puppet::Resource::Type.new(:hostclass, "foo") end def from_json(json) Puppet::Resource::Type.from_pson(json) end def double_convert Puppet::Resource::Type.from_pson(PSON.parse(@type.to_pson)) end it "should include the name and type" do double_convert.name.should == @type.name double_convert.type.should == @type.type end it "should include any arguments" do @type.set_arguments("one" => nil, "two" => "foo") double_convert.arguments.should == {"one" => nil, "two" => "foo"} end it "should include any extra attributes" do @type.file = "/my/file" @type.line = 50 double_convert.file.should == "/my/file" double_convert.line.should == 50 end end describe "when a node" do it "should allow a regex as its name" do lambda { Puppet::Resource::Type.new(:node, /foo/) }.should_not raise_error end it "should allow a AST::HostName instance as its name" do regex = Puppet::Parser::AST::Regex.new(:value => /foo/) name = Puppet::Parser::AST::HostName.new(:value => regex) lambda { Puppet::Resource::Type.new(:node, name) }.should_not raise_error end it "should match against the regexp in the AST::HostName when a HostName instance is provided" do regex = Puppet::Parser::AST::Regex.new(:value => /\w/) name = Puppet::Parser::AST::HostName.new(:value => regex) node = Puppet::Resource::Type.new(:node, name) node.match("foo").should be_true end it "should return the value of the hostname if provided a string-form AST::HostName instance as the name" do name = Puppet::Parser::AST::HostName.new(:value => "foo") node = Puppet::Resource::Type.new(:node, name) node.name.should == "foo" end describe "and the name is a regex" do it "should have a method that indicates that this is the case" do Puppet::Resource::Type.new(:node, /w/).should be_name_is_regex end it "should set its namespace to ''" do Puppet::Resource::Type.new(:node, /w/).namespace.should == "" end it "should return the regex converted to a string when asked for its name" do Puppet::Resource::Type.new(:node, /ww/).name.should == "ww" end it "should downcase the regex when returning the name as a string" do Puppet::Resource::Type.new(:node, /W/).name.should == "w" end it "should remove non-alpha characters when returning the name as a string" do Puppet::Resource::Type.new(:node, /w*w/).name.should_not include("*") end it "should remove leading dots when returning the name as a string" do Puppet::Resource::Type.new(:node, /.ww/).name.should_not =~ /^\./ end it "should have a method for matching its regex name against a provided name" do Puppet::Resource::Type.new(:node, /.ww/).should respond_to(:match) end it "should return true when its regex matches the provided name" do Puppet::Resource::Type.new(:node, /\w/).match("foo").should be_true end it "should return false when its regex does not match the provided name" do (!!Puppet::Resource::Type.new(:node, /\d/).match("foo")).should be_false end it "should return true when its name, as a string, is matched against an equal string" do Puppet::Resource::Type.new(:node, "foo").match("foo").should be_true end it "should return false when its name is matched against an unequal string" do Puppet::Resource::Type.new(:node, "foo").match("bar").should be_false end it "should match names insensitive to case" do Puppet::Resource::Type.new(:node, "fOo").match("foO").should be_true end end it "should return the name converted to a string when the name is not a regex" do pending "Need to define LoadedCode behaviour first" name = Puppet::Parser::AST::HostName.new(:value => "foo") Puppet::Resource::Type.new(:node, name).name.should == "foo" end it "should return the name converted to a string when the name is a regex" do pending "Need to define LoadedCode behaviour first" name = Puppet::Parser::AST::HostName.new(:value => /regex/) Puppet::Resource::Type.new(:node, name).name.should == /regex/.to_s end it "should mark any created scopes as a node scope" do pending "Need to define LoadedCode behaviour first" name = Puppet::Parser::AST::HostName.new(:value => /regex/) Puppet::Resource::Type.new(:node, name).name.should == /regex/.to_s end end describe "when initializing" do it "should require a resource super type" do Puppet::Resource::Type.new(:hostclass, "foo").type.should == :hostclass end it "should fail if provided an invalid resource super type" do lambda { Puppet::Resource::Type.new(:nope, "foo") }.should raise_error(ArgumentError) end it "should set its name to the downcased, stringified provided name" do Puppet::Resource::Type.new(:hostclass, "Foo::Bar".intern).name.should == "foo::bar" end it "should set its namespace to the downcased, stringified qualified name for classes" do Puppet::Resource::Type.new(:hostclass, "Foo::Bar::Baz".intern).namespace.should == "foo::bar::baz" end [:definition, :node].each do |type| it "should set its namespace to the downcased, stringified qualified portion of the name for #{type}s" do Puppet::Resource::Type.new(type, "Foo::Bar::Baz".intern).namespace.should == "foo::bar" end end %w{code line file doc}.each do |arg| it "should set #{arg} if provided" do type = Puppet::Resource::Type.new(:hostclass, "foo", arg.to_sym => "something") type.send(arg).should == "something" end end 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_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_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_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_valid_parameter("foo") end it "should return true if it is a metaparam" do 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_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_valid_parameter("yayness") end end describe "when creating a subscope" do before do @scope = stub 'scope', :newscope => nil @resource = stub 'resource' @type = Puppet::Resource::Type.new(:hostclass, "foo") end it "should return a new scope created with the provided scope as the parent" do @scope.expects(:newscope).returns "foo" @type.subscope(@scope, @resource).should == "foo" end it "should set the source as itself" do @scope.expects(:newscope).with { |args| args[:source] == @type } @type.subscope(@scope, @resource) end it "should set the scope's namespace to its namespace" do @type.expects(:namespace).returns "yayness" @scope.expects(:newscope).with { |args| args[:namespace] == "yayness" } @type.subscope(@scope, @resource) end it "should set the scope's resource to the provided resource" do @scope.expects(:newscope).with { |args| args[:resource] == @resource } @type.subscope(@scope, @resource) end end describe "when setting its parameters in the scope" do before do @scope = Puppet::Parser::Scope.new(:compiler => stub("compiler", :environment => Puppet::Node::Environment.new), :source => stub("source")) @resource = Puppet::Parser::Resource.new(:foo, "bar", :scope => @scope) @type = Puppet::Resource::Type.new(:hostclass, "foo") end it "should set each of the resource's parameters as variables in the scope" do @type.set_arguments :foo => nil, :boo => nil @resource[:foo] = "bar" @resource[:boo] = "baz" @type.set_resource_parameters(@resource, @scope) @scope.lookupvar("foo").should == "bar" @scope.lookupvar("boo").should == "baz" end it "should set the variables as strings" do @type.set_arguments :foo => nil @resource[:foo] = "bar" @type.set_resource_parameters(@resource, @scope) @scope.lookupvar("foo").should == "bar" end it "should fail if any of the resource's parameters are not valid attributes" do @type.set_arguments :foo => nil @resource[:boo] = "baz" lambda { @type.set_resource_parameters(@resource, @scope) }.should raise_error(Puppet::ParseError) end it "should evaluate and set its default values as variables for parameters not provided by the resource" do @type.set_arguments :foo => stub("value", :safeevaluate => "something") @type.set_resource_parameters(@resource, @scope) @scope.lookupvar("foo").should == "something" end it "should set all default values as parameters in the resource" do @type.set_arguments :foo => stub("value", :safeevaluate => "something") @type.set_resource_parameters(@resource, @scope) @resource[:foo].should == "something" end it "should fail if the resource does not provide a value for a required argument" do @type.set_arguments :foo => nil @resource.expects(:to_hash).returns({}) lambda { @type.set_resource_parameters(@resource, @scope) }.should raise_error(Puppet::ParseError) end it "should set the resource's title as a variable if not otherwise provided" do @type.set_resource_parameters(@resource, @scope) @scope.lookupvar("title").should == "bar" end it "should set the resource's name as a variable if not otherwise provided" do @type.set_resource_parameters(@resource, @scope) @scope.lookupvar("name").should == "bar" end it "should set its module name in the scope if available" do - @type.module_name = "mymod" + @type.instance_eval { @module_name = "mymod" } @type.set_resource_parameters(@resource, @scope) @scope.lookupvar("module_name").should == "mymod" end it "should set its caller module name in the scope if available" do @scope.expects(:parent_module_name).returns "mycaller" @type.set_resource_parameters(@resource, @scope) @scope.lookupvar("caller_module_name").should == "mycaller" end end describe "when describing and managing parent classes" do before do @code = Puppet::Resource::TypeCollection.new("env") @parent = Puppet::Resource::Type.new(:hostclass, "bar") @code.add @parent @child = Puppet::Resource::Type.new(:hostclass, "foo", :parent => "bar") @code.add @child @env = stub "environment", :known_resource_types => @code @scope = stub "scope", :environment => @env, :namespaces => [""] end it "should be able to define a parent" do Puppet::Resource::Type.new(:hostclass, "foo", :parent => "bar") end it "should use the code collection to find the parent resource type" do @child.parent_type(@scope).should equal(@parent) end it "should be able to find parent nodes" do parent = Puppet::Resource::Type.new(:node, "bar") @code.add parent child = Puppet::Resource::Type.new(:node, "foo", :parent => "bar") @code.add child child.parent_type(@scope).should equal(parent) end it "should cache a reference to the parent type" do @code.stubs(:hostclass).with("foo::bar").returns nil @code.expects(:hostclass).with("bar").once.returns @parent @child.parent_type(@scope) @child.parent_type end it "should correctly state when it is another type's child" do @child.parent_type(@scope) @child.should be_child_of(@parent) end it "should be considered the child of a parent's parent" do @grandchild = Puppet::Resource::Type.new(:hostclass, "baz", :parent => "foo") @code.add @grandchild @child.parent_type(@scope) @grandchild.parent_type(@scope) @grandchild.should be_child_of(@parent) end it "should correctly state when it is not another type's child" do @notchild = Puppet::Resource::Type.new(:hostclass, "baz") @code.add @notchild @notchild.should_not be_child_of(@parent) end end describe "when evaluating its code" do before do @compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("mynode")) @scope = Puppet::Parser::Scope.new :compiler => @compiler @resource = Puppet::Parser::Resource.new(:foo, "yay", :scope => @scope) # This is so the internal resource lookup works, yo. @compiler.catalog.add_resource @resource @known_resource_types = stub 'known_resource_types' @resource.stubs(:known_resource_types).returns @known_resource_types @type = Puppet::Resource::Type.new(:hostclass, "foo") end it "should add hostclass names to the classes list" do @type.evaluate_code(@resource) @compiler.catalog.classes.should be_include("foo") end it "should add node names to the classes list" do @type = Puppet::Resource::Type.new(:node, "foo") @type.evaluate_code(@resource) @compiler.catalog.classes.should be_include("foo") end it "should not add defined resource names to the classes list" do @type = Puppet::Resource::Type.new(:definition, "foo") @type.evaluate_code(@resource) @compiler.catalog.classes.should_not be_include("foo") end it "should set all of its parameters in a subscope" do subscope = stub 'subscope', :compiler => @compiler @type.expects(:subscope).with(@scope, @resource).returns subscope @type.expects(:set_resource_parameters).with(@resource, subscope) @type.evaluate_code(@resource) end it "should not create a subscope for the :main class" do @resource.stubs(:title).returns(:main) @type.expects(:subscope).never @type.expects(:set_resource_parameters).with(@resource, @scope) @type.evaluate_code(@resource) end it "should store the class scope" do @type.evaluate_code(@resource) @scope.class_scope(@type).should be_instance_of(@scope.class) end it "should still create a scope but not store it if the type is a definition" do @type = Puppet::Resource::Type.new(:definition, "foo") @type.evaluate_code(@resource) @scope.class_scope(@type).should be_nil end it "should evaluate the AST code if any is provided" do code = stub 'code' @type.stubs(:code).returns code @type.stubs(:subscope).returns stub_everything("subscope", :compiler => @compiler) code.expects(:safeevaluate).with @type.subscope @type.evaluate_code(@resource) end describe "and ruby code is provided" do it "should create a DSL Resource API and evaluate it" do @type.stubs(:ruby_code).returns(proc { "foo" }) @api = stub 'api' Puppet::DSL::ResourceAPI.expects(:new).with { |res, scope, code| code == @type.ruby_code }.returns @api @api.expects(:evaluate) @type.evaluate_code(@resource) end end it "should noop if there is no code" do @type.expects(:code).returns nil @type.evaluate_code(@resource) end describe "and it has a parent class" do before do @parent_type = Puppet::Resource::Type.new(:hostclass, "parent") @type.parent = "parent" @parent_resource = Puppet::Parser::Resource.new(:class, "parent", :scope => @scope) @compiler.add_resource @scope, @parent_resource @type.resource_type_collection = @scope.known_resource_types @type.resource_type_collection.add @parent_type end it "should evaluate the parent's resource" do @type.parent_type(@scope) @type.evaluate_code(@resource) @scope.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 @type.parent_type(@scope) @parent_resource.expects(:evaluate).never @type.evaluate_code(@resource) end it "should use the parent's scope as its base scope" do @type.parent_type(@scope) @type.evaluate_code(@resource) @scope.class_scope(@type).parent.object_id.should == @scope.class_scope(@parent_type).object_id end end describe "and it has a parent node" do before do @type = Puppet::Resource::Type.new(:node, "foo") @parent_type = Puppet::Resource::Type.new(:node, "parent") @type.parent = "parent" @parent_resource = Puppet::Parser::Resource.new(:node, "parent", :scope => @scope) @compiler.add_resource @scope, @parent_resource @type.resource_type_collection = @scope.known_resource_types - @type.resource_type_collection.stubs(:node).with("parent").returns(@parent_type) - @type.resource_type_collection.stubs(:node).with("Parent").returns(@parent_type) + @type.resource_type_collection.add(@parent_type) end it "should evaluate the parent's resource" do @type.parent_type(@scope) @type.evaluate_code(@resource) @scope.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 @type.parent_type(@scope) @parent_resource.expects(:evaluate).never @type.evaluate_code(@resource) end it "should use the parent's scope as its base scope" do @type.parent_type(@scope) @type.evaluate_code(@resource) @scope.class_scope(@type).parent.object_id.should == @scope.class_scope(@parent_type).object_id end end end describe "when creating a resource" do before do @node = Puppet::Node.new("foo", :environment => 'env') @compiler = Puppet::Parser::Compiler.new(@node) @scope = Puppet::Parser::Scope.new(:compiler => @compiler) @top = Puppet::Resource::Type.new :hostclass, "top" @middle = Puppet::Resource::Type.new :hostclass, "middle", :parent => "top" @code = Puppet::Resource::TypeCollection.new("env") @code.add @top @code.add @middle @node.environment.stubs(:known_resource_types).returns(@code) end it "should create a resource instance" do @top.mk_plain_resource(@scope).should be_instance_of(Puppet::Parser::Resource) end it "should set its resource type to 'class' when it is a hostclass" do Puppet::Resource::Type.new(:hostclass, "top").mk_plain_resource(@scope).type.should == "Class" end it "should set its resource type to 'node' when it is a node" do Puppet::Resource::Type.new(:node, "top").mk_plain_resource(@scope).type.should == "Node" end it "should fail when it is a definition" do lambda { Puppet::Resource::Type.new(:definition, "top").mk_plain_resource(@scope) }.should raise_error(ArgumentError) end it "should add the created resource to the scope's catalog" do @top.mk_plain_resource(@scope) @compiler.catalog.resource(:class, "top").should be_instance_of(Puppet::Parser::Resource) end it "should evaluate the parent class if one exists" do @middle.mk_plain_resource(@scope) @compiler.catalog.resource(:class, "top").should be_instance_of(Puppet::Parser::Resource) end it "should fail to evaluate if a parent class is defined but cannot be found" do othertop = Puppet::Resource::Type.new :hostclass, "something", :parent => "yay" @code.add othertop lambda { othertop.mk_plain_resource(@scope) }.should raise_error(Puppet::ParseError) end it "should not create a new resource if one already exists" do @compiler.catalog.expects(:resource).with(:class, "top").returns("something") @compiler.catalog.expects(:add_resource).never @top.mk_plain_resource(@scope) end it "should return the existing resource when not creating a new one" do @compiler.catalog.expects(:resource).with(:class, "top").returns("something") @compiler.catalog.expects(:add_resource).never @top.mk_plain_resource(@scope).should == "something" end it "should not create a new parent resource if one already exists and it has a parent class" do @top.mk_plain_resource(@scope) top_resource = @compiler.catalog.resource(:class, "top") @middle.mk_plain_resource(@scope) @compiler.catalog.resource(:class, "top").should equal(top_resource) end # #795 - tag before evaluation. it "should tag the catalog with the resource tags when it is evaluated" do @middle.mk_plain_resource(@scope) @compiler.catalog.should be_tagged("middle") end it "should tag the catalog with the parent class tags when it is evaluated" do @middle.mk_plain_resource(@scope) @compiler.catalog.should be_tagged("top") end end describe "when merging code from another instance" do def code(str) Puppet::Parser::AST::Leaf.new :value => str end it "should fail unless it is a class" do 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(Puppet::Error) end it "should fail if both classes have different parent classes" do code = Puppet::Resource::TypeCollection.new("env") {"a" => "b", "c" => "d"}.each do |parent, child| 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(Puppet::Error) end it "should fail if it's named 'main' and 'freeze_main' is enabled" do Puppet.settings[:freeze_main] = true code = Puppet::Resource::TypeCollection.new("env") code.add Puppet::Resource::Type.new(:hostclass, "") other = Puppet::Resource::Type.new(:hostclass, "") lambda { code.hostclass("").merge(other) }.should raise_error(Puppet::Error) end it "should copy the other class's parent if it has not parent" do dest = Puppet::Resource::Type.new(:hostclass, "bar") parent = Puppet::Resource::Type.new(:hostclass, "parent") source = Puppet::Resource::Type.new(:hostclass, "foo", :parent => "parent") dest.merge(source) dest.parent.should == "parent" end it "should copy the other class's documentation as its docs if it has no docs" do dest = Puppet::Resource::Type.new(:hostclass, "bar") source = Puppet::Resource::Type.new(:hostclass, "foo", :doc => "yayness") dest.merge(source) dest.doc.should == "yayness" end it "should append the other class's docs to its docs if it has any" do dest = Puppet::Resource::Type.new(:hostclass, "bar", :doc => "fooness") source = Puppet::Resource::Type.new(:hostclass, "foo", :doc => "yayness") dest.merge(source) dest.doc.should == "foonessyayness" end it "should turn its code into an ASTArray if necessary" do dest = Puppet::Resource::Type.new(:hostclass, "bar", :code => code("foo")) source = Puppet::Resource::Type.new(:hostclass, "foo", :code => code("bar")) dest.merge(source) dest.code.should be_instance_of(Puppet::Parser::AST::ASTArray) end it "should set the other class's code as its code if it has none" do dest = Puppet::Resource::Type.new(:hostclass, "bar") source = Puppet::Resource::Type.new(:hostclass, "foo", :code => code("bar")) dest.merge(source) dest.code.value.should == "bar" end it "should append the other class's code to its code if it has any" do dcode = Puppet::Parser::AST::ASTArray.new :children => [code("dest")] dest = Puppet::Resource::Type.new(:hostclass, "bar", :code => dcode) scode = Puppet::Parser::AST::ASTArray.new :children => [code("source")] source = Puppet::Resource::Type.new(:hostclass, "foo", :code => scode) dest.merge(source) dest.code.children.collect { |l| l.value }.should == %w{dest source} end end end diff --git a/spec/unit/util/rdoc/parser_spec.rb b/spec/unit/util/rdoc/parser_spec.rb index 28c33c295..04713f293 100755 --- a/spec/unit/util/rdoc/parser_spec.rb +++ b/spec/unit/util/rdoc/parser_spec.rb @@ -1,544 +1,550 @@ #!/usr/bin/env ruby Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") } require 'puppet/resource/type_collection' require 'puppet/util/rdoc/parser' require 'puppet/util/rdoc/code_objects' require 'rdoc/options' require 'rdoc/rdoc' describe RDoc::Parser do before :each do File.stubs(:stat).with("init.pp") @top_level = stub_everything 'toplevel', :file_relative_name => "init.pp" @parser = RDoc::Parser.new(@top_level, "module/manifests/init.pp", nil, Options.instance, RDoc::Stats.new) end describe "when scanning files" do it "should parse puppet files with the puppet parser" do @parser.stubs(:scan_top_level) parser = stub 'parser' Puppet::Parser::Parser.stubs(:new).returns(parser) - parser.expects(:parse) + parser.expects(:parse).returns(Puppet::Parser::AST::Hostclass.new('')) parser.expects(:file=).with("module/manifests/init.pp") @parser.scan end it "should scan the ast for Puppet files" do parser = stub_everything 'parser' Puppet::Parser::Parser.stubs(:new).returns(parser) + parser.expects(:parse).returns(Puppet::Parser::AST::Hostclass.new('')) @parser.expects(:scan_top_level) @parser.scan end it "should return a PuppetTopLevel to RDoc" do parser = stub_everything 'parser' Puppet::Parser::Parser.stubs(:new).returns(parser) + parser.expects(:parse).returns(Puppet::Parser::AST::Hostclass.new('')) @parser.expects(:scan_top_level) @parser.scan.should be_a(RDoc::PuppetTopLevel) end end describe "when scanning top level entities" do before :each do - @resource_type_collection = stub_everything 'resource_type_collection' - @parser.ast = @resource_type_collection + @resource_type_collection = resource_type_collection = stub_everything('resource_type_collection') + @parser.instance_eval { @known_resource_types = resource_type_collection } @parser.stubs(:split_module).returns("module") @topcontainer = stub_everything 'topcontainer' @container = stub_everything 'container' @module = stub_everything 'module' @container.stubs(:add_module).returns(@module) @parser.stubs(:get_class_or_module).returns([@container, "module"]) end it "should read any present README as module documentation" do FileTest.stubs(:readable?).returns(true) File.stubs(:open).returns("readme") @parser.stubs(:parse_elements) @module.expects(:comment=).with("readme") @parser.scan_top_level(@topcontainer) end it "should tell the container its module name" do @parser.stubs(:parse_elements) @topcontainer.expects(:module_name=).with("module") @parser.scan_top_level(@topcontainer) end it "should not document our toplevel if it isn't a valid module" do @parser.stubs(:split_module).returns(nil) @topcontainer.expects(:document_self=).with(false) @parser.expects(:parse_elements).never @parser.scan_top_level(@topcontainer) end it "should set the module as global if we parse the global manifests (ie __site__ module)" do @parser.stubs(:split_module).returns(RDoc::Parser::SITE) @parser.stubs(:parse_elements) @topcontainer.expects(:global=).with(true) @parser.scan_top_level(@topcontainer) end it "should attach this module container to the toplevel container" do @parser.stubs(:parse_elements) @container.expects(:add_module).with(RDoc::PuppetModule, "module").returns(@module) @parser.scan_top_level(@topcontainer) end it "should defer ast parsing to parse_elements for this module" do @parser.expects(:parse_elements).with(@module) @parser.scan_top_level(@topcontainer) end it "should defer plugins parsing to parse_plugins for this module" do @parser.input_file_name = "module/lib/puppet/parser/function.rb" @parser.expects(:parse_plugins).with(@module) @parser.scan_top_level(@topcontainer) end end describe "when finding modules from filepath" do before :each do Puppet::Module.stubs(:modulepath).returns("/path/to/modules") end it "should return the module name for modulized puppet manifests" do File.stubs(:expand_path).returns("/path/to/module/manifests/init.pp") File.stubs(:identical?).with("/path/to", "/path/to/modules").returns(true) @parser.split_module("/path/to/modules/mymodule/manifests/init.pp").should == "module" end it "should return for manifests not under module path" do File.stubs(:expand_path).returns("/path/to/manifests/init.pp") File.stubs(:identical?).returns(false) @parser.split_module("/path/to/manifests/init.pp").should == RDoc::Parser::SITE end end describe "when parsing AST elements" do before :each do @klass = stub_everything 'klass', :file => "module/manifests/init.pp", :name => "myclass", :type => :hostclass @definition = stub_everything 'definition', :file => "module/manifests/init.pp", :type => :definition, :name => "mydef" @node = stub_everything 'node', :file => "module/manifests/init.pp", :type => :node, :name => "mynode" - @resource_type_collection = Puppet::Resource::TypeCollection.new("env") - @parser.ast = @resource_type_collection + @resource_type_collection = resource_type_collection = Puppet::Resource::TypeCollection.new("env") + @parser.instance_eval { @known_resource_types = resource_type_collection } @container = stub_everything 'container' end it "should document classes in the parsed file" do @resource_type_collection.add_hostclass(@klass) @parser.expects(:document_class).with("myclass", @klass, @container) @parser.parse_elements(@container) end it "should not document class parsed in an other file" do @klass.stubs(:file).returns("/not/same/path/file.pp") @resource_type_collection.add_hostclass(@klass) @parser.expects(:document_class).with("myclass", @klass, @container).never @parser.parse_elements(@container) end it "should document vardefs for the main class" do @klass.stubs(:name).returns :main @resource_type_collection.add_hostclass(@klass) code = stub 'code', :is_a? => false @klass.stubs(:name).returns("") @klass.stubs(:code).returns(code) @parser.expects(:scan_for_vardef).with(@container, code) @parser.parse_elements(@container) end it "should document definitions in the parsed file" do @resource_type_collection.add_definition(@definition) @parser.expects(:document_define).with("mydef", @definition, @container) @parser.parse_elements(@container) end it "should not document definitions parsed in an other file" do @definition.stubs(:file).returns("/not/same/path/file.pp") @resource_type_collection.add_definition(@definition) @parser.expects(:document_define).with("mydef", @definition, @container).never @parser.parse_elements(@container) end it "should document nodes in the parsed file" do @resource_type_collection.add_node(@node) @parser.expects(:document_node).with("mynode", @node, @container) @parser.parse_elements(@container) end it "should not document node parsed in an other file" do @node.stubs(:file).returns("/not/same/path/file.pp") @resource_type_collection.add_node(@node) @parser.expects(:document_node).with("mynode", @node, @container).never @parser.parse_elements(@container) end end describe "when documenting definition" do before(:each) do @define = stub_everything 'define', :arguments => [], :doc => "mydoc", :file => "file", :line => 42 @class = stub_everything 'class' @parser.stubs(:get_class_or_module).returns([@class, "mydef"]) end it "should register a RDoc method to the current container" do @class.expects(:add_method).with { |m| m.name == "mydef"} @parser.document_define("mydef", @define, @class) end it "should attach the documentation to this method" do @class.expects(:add_method).with { |m| m.comment = "mydoc" } @parser.document_define("mydef", @define, @class) end it "should produce a better error message on unhandled exception" do @class.expects(:add_method).raises(ArgumentError) lambda { @parser.document_define("mydef", @define, @class) }.should raise_error(Puppet::ParseError, /in file at line 42/) end it "should convert all definition parameter to string" do arg = stub 'arg' val = stub 'val' @define.stubs(:arguments).returns({arg => val}) arg.expects(:to_s).returns("arg") val.expects(:to_s).returns("val") @parser.document_define("mydef", @define, @class) end end describe "when documenting nodes" do before :each do @code = stub_everything 'code' @node = stub_everything 'node', :doc => "mydoc", :parent => "parent", :code => @code, :file => "file", :line => 42 @rdoc_node = stub_everything 'rdocnode' @class = stub_everything 'class' @class.stubs(:add_node).returns(@rdoc_node) end it "should add a node to the current container" do @class.expects(:add_node).with("mynode", "parent").returns(@rdoc_node) @parser.document_node("mynode", @node, @class) end it "should associate the node documentation to the rdoc node" do @rdoc_node.expects(:comment=).with("mydoc") @parser.document_node("mynode", @node, @class) end it "should scan for include and require" do @parser.expects(:scan_for_include_or_require).with(@rdoc_node, @code) @parser.document_node("mynode", @node, @class) end it "should scan for variable definition" do @parser.expects(:scan_for_vardef).with(@rdoc_node, @code) @parser.document_node("mynode", @node, @class) end it "should scan for resources if needed" do Puppet.settings.stubs(:[]).with(:document_all).returns(true) @parser.expects(:scan_for_resource).with(@rdoc_node, @code) @parser.document_node("mynode", @node, @class) end it "should produce a better error message on unhandled exception" do @class.stubs(:add_node).raises(ArgumentError) lambda { @parser.document_node("mynode", @node, @class) }.should raise_error(Puppet::ParseError, /in file at line 42/) end end describe "when documenting classes" do before :each do @code = stub_everything 'code' @class = stub_everything 'class', :doc => "mydoc", :parent => "parent", :code => @code, :file => "file", :line => 42 @rdoc_class = stub_everything 'rdoc-class' @module = stub_everything 'class' @module.stubs(:add_class).returns(@rdoc_class) @parser.stubs(:get_class_or_module).returns([@module, "myclass"]) end it "should add a class to the current container" do @module.expects(:add_class).with(RDoc::PuppetClass, "myclass", "parent").returns(@rdoc_class) @parser.document_class("mynode", @class, @module) end it "should set the superclass" do @rdoc_class.expects(:superclass=).with("parent") @parser.document_class("mynode", @class, @module) end it "should associate the node documentation to the rdoc class" do @rdoc_class.expects(:comment=).with("mydoc") @parser.document_class("mynode", @class, @module) end it "should scan for include and require" do @parser.expects(:scan_for_include_or_require).with(@rdoc_class, @code) @parser.document_class("mynode", @class, @module) end it "should scan for resources if needed" do Puppet.settings.stubs(:[]).with(:document_all).returns(true) @parser.expects(:scan_for_resource).with(@rdoc_class, @code) @parser.document_class("mynode", @class, @module) end it "should produce a better error message on unhandled exception" do @module.stubs(:add_class).raises(ArgumentError) lambda { @parser.document_class("mynode", @class, @module) }.should raise_error(Puppet::ParseError, /in file at line 42/) end end describe "when scanning for includes and requires" do def create_stmt(name) stmt_value = stub "#{name}_value", :value => "myclass" Puppet::Parser::AST::Function.new( :name => name, :arguments => [stmt_value], :doc => 'mydoc' ) end before(:each) do @class = stub_everything 'class' @code = stub_everything 'code' @code.stubs(:is_a?).with(Puppet::Parser::AST::ASTArray).returns(true) end it "should also scan mono-instruction code" do @class.expects(:add_include).with { |i| i.is_a?(RDoc::Include) and i.name == "myclass" and i.comment == "mydoc" } @parser.scan_for_include_or_require(@class,create_stmt("include")) end it "should register recursively includes to the current container" do @code.stubs(:children).returns([ create_stmt("include") ]) @class.expects(:add_include).with { |i| i.is_a?(RDoc::Include) and i.name == "myclass" and i.comment == "mydoc" } @parser.scan_for_include_or_require(@class, [@code]) end it "should register requires to the current container" do @code.stubs(:children).returns([ create_stmt("require") ]) @class.expects(:add_require).with { |i| i.is_a?(RDoc::Include) and i.name == "myclass" and i.comment == "mydoc" } @parser.scan_for_include_or_require(@class, [@code]) end end describe "when scanning for realized virtual resources" do def create_stmt stmt_value = stub "resource_ref", :to_s => "File[\"/tmp/a\"]" Puppet::Parser::AST::Function.new( :name => 'realize', :arguments => [stmt_value], :doc => 'mydoc' ) end before(:each) do @class = stub_everything 'class' @code = stub_everything 'code' @code.stubs(:is_a?).with(Puppet::Parser::AST::ASTArray).returns(true) end it "should also scan mono-instruction code" do @class.expects(:add_realize).with { |i| i.is_a?(RDoc::Include) and i.name == "File[\"/tmp/a\"]" and i.comment == "mydoc" } @parser.scan_for_realize(@class,create_stmt) end it "should register recursively includes to the current container" do @code.stubs(:children).returns([ create_stmt ]) @class.expects(:add_realize).with { |i| i.is_a?(RDoc::Include) and i.name == "File[\"/tmp/a\"]" and i.comment == "mydoc" } @parser.scan_for_realize(@class, [@code]) end end describe "when scanning for variable definition" do before :each do @class = stub_everything 'class' @stmt = stub_everything 'stmt', :name => "myvar", :value => "myvalue", :doc => "mydoc" @stmt.stubs(:is_a?).with(Puppet::Parser::AST::ASTArray).returns(false) @stmt.stubs(:is_a?).with(Puppet::Parser::AST::VarDef).returns(true) @code = stub_everything 'code' @code.stubs(:is_a?).with(Puppet::Parser::AST::ASTArray).returns(true) end it "should recursively register variables to the current container" do @code.stubs(:children).returns([ @stmt ]) @class.expects(:add_constant).with { |i| i.is_a?(RDoc::Constant) and i.name == "myvar" and i.comment == "mydoc" } @parser.scan_for_vardef(@class, [ @code ]) end it "should also scan mono-instruction code" do @class.expects(:add_constant).with { |i| i.is_a?(RDoc::Constant) and i.name == "myvar" and i.comment == "mydoc" } @parser.scan_for_vardef(@class, @stmt) end end describe "when scanning for resources" do before :each do @class = stub_everything 'class' @stmt = Puppet::Parser::AST::Resource.new( :type => "File", - :title => "myfile", - :doc => 'mydoc', - :parameters => Puppet::Parser::AST::ASTArray.new(:children => []) + :instances => Puppet::Parser::AST::ASTArray.new(:children => [ + Puppet::Parser::AST::ResourceInstance.new( + :title => Puppet::Parser::AST::Name.new(:value => "myfile"), + :parameters => Puppet::Parser::AST::ASTArray.new(:children => []) + ) + ]), + :doc => 'mydoc' ) @code = stub_everything 'code' @code.stubs(:is_a?).with(Puppet::Parser::AST::ASTArray).returns(true) end it "should register a PuppetResource to the current container" do @code.stubs(:children).returns([ @stmt ]) @class.expects(:add_resource).with { |i| i.is_a?(RDoc::PuppetResource) and i.title == "myfile" and i.comment == "mydoc" } @parser.scan_for_resource(@class, [ @code ]) end it "should also scan mono-instruction code" do @class.expects(:add_resource).with { |i| i.is_a?(RDoc::PuppetResource) and i.title == "myfile" and i.comment == "mydoc" } @parser.scan_for_resource(@class, @stmt) end end describe "when parsing plugins" do before :each do @container = stub 'container' end it "should delegate parsing custom facts to parse_facts" do @parser = RDoc::Parser.new(@top_level, "module/manifests/lib/puppet/facter/test.rb", nil, Options.instance, RDoc::Stats.new) @parser.expects(:parse_fact).with(@container) @parser.parse_plugins(@container) end it "should delegate parsing plugins to parse_plugins" do @parser = RDoc::Parser.new(@top_level, "module/manifests/lib/puppet/functions/test.rb", nil, Options.instance, RDoc::Stats.new) @parser.expects(:parse_puppet_plugin).with(@container) @parser.parse_plugins(@container) end end describe "when parsing plugins" do before :each do @container = stub_everything 'container' end it "should add custom functions to the container" do File.stubs(:open).yields("# documentation module Puppet::Parser::Functions newfunction(:myfunc, :type => :rvalue) do |args| File.dirname(args[0]) end end".split("\n")) @container.expects(:add_plugin).with do |plugin| plugin.comment == "documentation\n" #and plugin.name == "myfunc" end @parser.parse_puppet_plugin(@container) end it "should add custom types to the container" do File.stubs(:open).yields("# documentation Puppet::Type.newtype(:mytype) do end".split("\n")) @container.expects(:add_plugin).with do |plugin| plugin.comment == "documentation\n" #and plugin.name == "mytype" end @parser.parse_puppet_plugin(@container) end end describe "when parsing facts" do before :each do @container = stub_everything 'container' File.stubs(:open).yields(["# documentation", "Facter.add('myfact') do", "confine :kernel => :linux", "end"]) end it "should add facts to the container" do @container.expects(:add_fact).with do |fact| fact.comment == "documentation\n" and fact.name == "myfact" end @parser.parse_fact(@container) end it "should add confine to the parsed facts" do ourfact = nil @container.expects(:add_fact).with do |fact| ourfact = fact true end @parser.parse_fact(@container) ourfact.confine.should == { :type => "kernel", :value => ":linux" } end end end diff --git a/spec/unit/util/zaml_spec.rb b/spec/unit/util/zaml_spec.rb index f2bcefe01..b223f89d4 100755 --- a/spec/unit/util/zaml_spec.rb +++ b/spec/unit/util/zaml_spec.rb @@ -1,39 +1,64 @@ #!/usr/bin/env ruby Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") } require 'puppet/util/monkey_patches' describe "Pure ruby yaml implementation" do { 7 => "--- 7", 3.14159 => "--- 3.14159", 'test' => "--- test", [] => "--- []", :symbol => "--- !ruby/sym symbol", {:a => "A"} => "--- \n !ruby/sym a: A", {:a => "x\ny"} => "--- \n !ruby/sym a: |-\n x\n y" }.each { |o,y| it "should convert the #{o.class} #{o.inspect} to yaml" do o.to_yaml.should == y end it "should produce yaml for the #{o.class} #{o.inspect} that can be reconstituted" do YAML.load(o.to_yaml).should == o end } # # Can't test for equality on raw objects { Object.new => "--- !ruby/object {}", [Object.new] => "--- \n - !ruby/object {}", {Object.new => Object.new} => "--- \n ? !ruby/object {}\n : !ruby/object {}" }.each { |o,y| it "should convert the #{o.class} #{o.inspect} to yaml" do o.to_yaml.should == y end it "should produce yaml for the #{o.class} #{o.inspect} that can be reconstituted" do lambda { YAML.load(o.to_yaml) }.should_not raise_error end } + + it "should emit proper labels and backreferences for common objects" do + # Note: this test makes assumptions about the names ZAML chooses + # for labels. + x = [1, 2] + y = [3, 4] + z = [x, y, x, y] + z.to_yaml.should == "--- \n - &id001\n - 1\n - 2\n - &id002\n - 3\n - 4\n - *id001\n - *id002" + z2 = YAML.load(z.to_yaml) + z2.should == z + z2[0].should equal(z2[2]) + z2[1].should equal(z2[3]) + end + + it "should emit proper labels and backreferences for recursive objects" do + x = [1, 2] + x << x + x.to_yaml.should == "--- &id001\n \n - 1\n - 2\n - *id001" + x2 = YAML.load(x.to_yaml) + x2.should be_a(Array) + x2.length.should == 3 + x2[0].should == 1 + x2[1].should == 2 + x2[2].should equal(x2) + end end diff --git a/test/language/functions.rb b/test/language/functions.rb index 1d4ed8241..081063e2b 100755 --- a/test/language/functions.rb +++ b/test/language/functions.rb @@ -1,543 +1,543 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../lib/puppettest' require 'puppet' require 'puppet/parser/parser' require 'puppet/network/client' require 'puppettest' require 'puppettest/resourcetesting' class TestLangFunctions < Test::Unit::TestCase include PuppetTest::ParserTesting include PuppetTest::ResourceTesting def test_functions Puppet::Node::Environment.stubs(:current).returns nil assert_nothing_raised do Puppet::Parser::AST::Function.new( :name => "fakefunction", :arguments => AST::ASTArray.new( :children => [nameobj("avalue")] ) ) end assert_raise(Puppet::ParseError) do func = Puppet::Parser::AST::Function.new( :name => "fakefunction", :arguments => AST::ASTArray.new( :children => [nameobj("avalue")] ) ) func.evaluate(mkscope) end assert_nothing_raised do Puppet::Parser::Functions.newfunction(:fakefunction, :type => :rvalue) do |input| return "output #{input[0]}" end end func = nil assert_nothing_raised do func = Puppet::Parser::AST::Function.new( :name => "fakefunction", :ftype => :rvalue, :arguments => AST::ASTArray.new( :children => [nameobj("avalue")] ) ) end scope = mkscope val = nil assert_nothing_raised do val = func.evaluate(scope) end assert_equal("output avalue", val) end def test_taggedfunction scope = mkscope scope.resource.tag("yayness") # Make sure the ast stuff does what it's supposed to {"yayness" => true, "booness" => false}.each do |tag, retval| func = taggedobj(tag, :rvalue) val = nil assert_nothing_raised do val = func.evaluate(scope) end assert_equal(retval, val, "'tagged' returned #{val} for #{tag}") end # Now make sure we correctly get tags. scope.resource.tag("resourcetag") assert(scope.function_tagged("resourcetag"), "tagged function did not catch resource tags") scope.compiler.catalog.tag("configtag") assert(scope.function_tagged("configtag"), "tagged function did not catch catalog tags") end def test_failfunction func = nil assert_nothing_raised do func = Puppet::Parser::AST::Function.new( :name => "fail", :ftype => :statement, :arguments => AST::ASTArray.new( :children => [stringobj("this is a failure"), stringobj("and another")] ) ) end scope = mkscope val = nil assert_raise(Puppet::ParseError) do val = func.evaluate(scope) end end def test_multipletemplates Dir.mkdir(Puppet[:templatedir]) onep = File.join(Puppet[:templatedir], "one") twop = File.join(Puppet[:templatedir], "two") File.open(onep, "w") do |f| f.puts "<%- if @one.nil? then raise '@one undefined' end -%>template <%= @one %>" end File.open(twop, "w") do |f| f.puts "template <%= @two %>" end func = nil assert_nothing_raised do func = Puppet::Parser::AST::Function.new( :name => "template", :ftype => :rvalue, :arguments => AST::ASTArray.new( :children => [stringobj("one"), stringobj("two")] ) ) end ast = varobj("output", func) scope = mkscope # Test that our manual exception throw fails the parse assert_raise(Puppet::ParseError) do ast.evaluate(scope) end # Test that our use of an undefined instance variable does not throw # an exception, but only safely continues. scope.setvar("one", "One") assert_nothing_raised do ast.evaluate(scope) end # Ensure that we got the output we expected from that evaluation. assert_equal("template One\ntemplate \n", scope.lookupvar("output"), "Undefined template variables do not raise exceptions") # Now, fill in the last variable and make sure the whole thing # evaluates correctly. scope.setvar("two", "Two") scope.unsetvar("output") assert_nothing_raised do ast.evaluate(scope) end assert_equal( "template One\ntemplate Two\n", scope.lookupvar("output"), "Templates were not handled correctly") end # Now make sure we can fully qualify files, and specify just one def test_singletemplates template = tempfile File.open(template, "w") do |f| f.puts "template <%= @yay.nil?() ? raise('yay undefined') : @yay %>" end func = nil assert_nothing_raised do func = Puppet::Parser::AST::Function.new( :name => "template", :ftype => :rvalue, :arguments => AST::ASTArray.new( :children => [stringobj(template)] ) ) end ast = varobj("output", func) scope = mkscope assert_raise(Puppet::ParseError) do ast.evaluate(scope) end scope.setvar("yay", "this is yay") assert_nothing_raised do ast.evaluate(scope) end assert_equal( "template this is yay\n", scope.lookupvar("output"), "Templates were not handled correctly") end # Make sure that legacy template variable access works as expected. def test_legacyvariables template = tempfile File.open(template, "w") do |f| f.puts "template <%= deprecated %>" end func = nil assert_nothing_raised do func = Puppet::Parser::AST::Function.new( :name => "template", :ftype => :rvalue, :arguments => AST::ASTArray.new( :children => [stringobj(template)] ) ) end ast = varobj("output", func) # Verify that we get an exception using old-style accessors. scope = mkscope assert_raise(Puppet::ParseError) do ast.evaluate(scope) end # Verify that we evaluate and return their value correctly. scope.setvar("deprecated", "deprecated value") assert_nothing_raised do ast.evaluate(scope) end assert_equal( "template deprecated value\n", scope.lookupvar("output"), "Deprecated template variables were not handled correctly") end # Make sure that problems with kernel method visibility still exist. def test_kernel_module_shadows_deprecated_var_lookup template = tempfile File.open(template, "w").puts("<%= binding %>") func = nil assert_nothing_raised do func = Puppet::Parser::AST::Function.new( :name => "template", :ftype => :rvalue, :arguments => AST::ASTArray.new( :children => [stringobj(template)] ) ) end ast = varobj("output", func) # Verify that Kernel methods still shadow deprecated variable lookups. scope = mkscope assert_nothing_raised("No exception for Kernel shadowed variable names") do ast.evaluate(scope) end end def test_tempatefunction_cannot_see_scopes template = tempfile File.open(template, "w") do |f| f.puts "<%= lookupvar('myvar') %>" end func = nil assert_nothing_raised do func = Puppet::Parser::AST::Function.new( :name => "template", :ftype => :rvalue, :arguments => AST::ASTArray.new( :children => [stringobj(template)] ) ) end ast = varobj("output", func) scope = mkscope scope.setvar("myvar", "this is yayness") assert_raise(Puppet::ParseError) do ast.evaluate(scope) end end def test_template_reparses template = tempfile File.open(template, "w") do |f| f.puts "original text" end file = tempfile Puppet[:code] = %{file { "#{file}": content => template("#{template}") }} Puppet[:environment] = "yay" node = mknode node.stubs(:environment).returns Puppet::Node::Environment.new Puppet[:environment] = "yay" catalog = Puppet::Parser::Compiler.new(node).compile version = catalog.version fileobj = catalog.vertices.find { |r| r.title == file } assert(fileobj, "File was not in catalog") assert_equal( "original text\n", fileobj["content"], "Template did not work") Puppet[:filetimeout] = -5 # Have to sleep because one second is the fs's time granularity. sleep(1) # Now modify the template File.open(template, "w") do |f| f.puts "new text" end newversion = Puppet::Parser::Compiler.new(node).compile.version assert(version != newversion, "Parse date did not change") end def test_template_defined_vars template = tempfile File.open(template, "w") do |f| f.puts "template <%= @yayness %>" end func = nil assert_nothing_raised do func = Puppet::Parser::AST::Function.new( :name => "template", :ftype => :rvalue, :arguments => AST::ASTArray.new( :children => [stringobj(template)] ) ) end ast = varobj("output", func) { "" => "", false => "false", }.each do |string, value| scope = mkscope scope.setvar("yayness", string) assert_equal(string, scope.lookupvar("yayness", false)) assert_nothing_raised("An empty string was not a valid variable value") do ast.evaluate(scope) end assert_equal( "template #{value}\n", scope.lookupvar("output"), "#{string.inspect} did not get evaluated correctly") end end def test_autoloading_functions #assert_equal(false, Puppet::Parser::Functions.function(:autofunc), # "Got told autofunc already exists") dir = tempfile $LOAD_PATH << dir newpath = File.join(dir, "puppet", "parser", "functions") FileUtils.mkdir_p(newpath) File.open(File.join(newpath, "autofunc.rb"), "w") { |f| f.puts %{ Puppet::Parser::Functions.newfunction(:autofunc, :type => :rvalue) do |vals| Puppet.wanring vals.inspect end } } Puppet::Node::Environment.stubs(:current).returns nil obj = nil assert_nothing_raised { obj = Puppet::Parser::Functions.function(:autofunc) } assert(obj, "Did not autoload function") assert(Puppet::Parser::Functions.environment_module.method_defined?(:function_autofunc), "Did not set function correctly") end def test_search scope = mkscope 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) scope.function_search(["foo", "yay"]) ffun = ffoo = nil assert_nothing_raised("Search path change did not work") do ffun = scope.find_definition("ness") ffoo = scope.find_definition('bar') end assert(ffun, "Could not find definition in 'fun' namespace") assert(ffoo, "Could not find definition in 'foo' namespace") end def test_include scope = mkscope parser = mkparser include = Puppet::Parser::Functions.function(:include) assert_raise(Puppet::ParseError, "did not throw error on missing class") do scope.function_include("nosuchclass") end - parser.newclass("myclass") + scope.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "myclass", {}) scope.compiler.expects(:evaluate_classes).with(%w{myclass otherclass}, scope, false).returns(%w{myclass otherclass}) assert_nothing_raised do scope.function_include(["myclass", "otherclass"]) end end def test_file parser = mkparser scope = mkscope(:parser => parser) file = Puppet::Parser::Functions.function(:file) file1 = tempfile file2 = tempfile file3 = tempfile File.open(file2, "w") { |f| f.puts "yaytest" } val = nil assert_nothing_raised("Failed to call file with one arg") do val = scope.function_file([file2]) end assert_equal("yaytest\n", val, "file() failed") assert_nothing_raised("Failed to call file with two args") do val = scope.function_file([file1, file2]) end assert_equal("yaytest\n", val, "file() failed") assert_raise(Puppet::ParseError, "did not fail when files are missing") do val = scope.function_file([file1, file3]) end end def test_generate command = tempfile sh = %x{which sh} File.open(command, "w") do |f| f.puts %{#!#{sh} if [ -n "$1" ]; then echo "yay-$1" else echo yay fi } end File.chmod(0755, command) assert_equal("yay\n", %x{#{command}}, "command did not work") assert_equal("yay-foo\n", %x{#{command} foo}, "command did not work") Puppet::Node::Environment.stubs(:current).returns nil generate = Puppet::Parser::Functions.function(:generate) scope = mkscope parser = mkparser val = nil assert_nothing_raised("Could not call generator with no args") do val = scope.function_generate([command]) end assert_equal("yay\n", val, "generator returned wrong results") assert_nothing_raised("Could not call generator with args") do val = scope.function_generate([command, "foo"]) end assert_equal("yay-foo\n", val, "generator returned wrong results") assert_raise(Puppet::ParseError, "Did not fail with an unqualified path") do val = scope.function_generate([File.basename(command), "foo"]) end assert_raise(Puppet::ParseError, "Did not fail when command failed") do val = scope.function_generate([%x{which touch}.chomp, "/this/dir/does/not/exist"]) end fake = File.join(File.dirname(command), "..") dir = File.dirname(command) dirname = File.basename(dir) bad = File.join(dir, "..", dirname, File.basename(command)) assert_raise(Puppet::ParseError, "Did not fail when command failed") do val = scope.function_generate([bad]) end end end diff --git a/test/language/parser.rb b/test/language/parser.rb index 8cda8eeb2..6f3d751c2 100755 --- a/test/language/parser.rb +++ b/test/language/parser.rb @@ -1,746 +1,739 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../lib/puppettest' require 'mocha' require 'puppet' require 'puppet/parser/parser' require 'puppettest' require 'puppettest/support/utils' class TestParser < Test::Unit::TestCase include PuppetTest include PuppetTest::ParserTesting include PuppetTest::Support::Utils def setup super Puppet[:parseonly] = true #@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 #{file}") if __FILE__ == $0 assert_nothing_raised { parser.file = file parser.parse } } end def test_failers failers { |file| parser = mkparser Puppet.debug("parsing failer #{file}") if __FILE__ == $0 - assert_raise(Puppet::ParseError, "Did not fail while parsing #{file}") { - parser.file = file - ast = parser.parse + assert_raise(Puppet::ParseError, Puppet::Error, "Did not fail while parsing #{file}") { + Puppet[:manifest] = file config = mkcompiler(parser) config.compile #ast.hostclass("").evaluate config.topscope } } end def test_arrayrvalues parser = mkparser ret = nil file = tempfile assert_nothing_raised { parser.string = "file { \"#{file}\": mode => [755, 640] }" } assert_nothing_raised { ret = parser.parse } end def test_arrayrvalueswithtrailingcomma parser = mkparser ret = nil file = tempfile assert_nothing_raised { parser.string = "file { \"#{file}\": mode => [755, 640,] }" } assert_nothing_raised { ret = parser.parse } end def mkmanifest(file) name = File.join(tmpdir, "file#{rand(100)}") @@tmpfiles << name File.open(file, "w") { |f| f.puts "file { \"%s\": ensure => file, mode => 755 }\n" % name } end def test_importglobbing basedir = File.join(tmpdir, "importesting") @@tmpfiles << basedir Dir.mkdir(basedir) subdir = "subdir" Dir.mkdir(File.join(basedir, subdir)) manifest = File.join(basedir, "manifest") File.open(manifest, "w") { |f| f.puts "import \"%s/*\"" % subdir } 4.times { |i| path = File.join(basedir, subdir, "subfile#{i}.pp") mkmanifest(path) } assert_nothing_raised("Could not parse multiple files") { parser = mkparser parser.file = manifest parser.parse } end def test_nonexistent_import basedir = File.join(tmpdir, "importesting") @@tmpfiles << basedir Dir.mkdir(basedir) manifest = File.join(basedir, "manifest") File.open(manifest, "w") do |f| f.puts "import \" no such file \"" end assert_raise(Puppet::ParseError) { parser = mkparser parser.file = manifest parser.parse } end def test_trailingcomma path = tempfile str = %{file { "#{path}": ensure => file, } } parser = mkparser parser.string = str assert_nothing_raised("Could not parse trailing comma") { parser.parse } end def test_importedclasses imported = tempfile '.pp' importer = tempfile '.pp' made = tempfile File.open(imported, "w") do |f| f.puts %{class foo { file { "#{made}": ensure => file }}} end File.open(importer, "w") do |f| f.puts %{import "#{imported}"\ninclude foo} end parser = mkparser parser.file = importer # Make sure it parses fine assert_nothing_raised { parser.parse } # Now make sure it actually does the work assert_creates(importer, made) end # Make sure fully qualified and unqualified files can be imported def test_fqfilesandlocalfiles dir = tempfile Dir.mkdir(dir) importer = File.join(dir, "site.pp") fullfile = File.join(dir, "full.pp") localfile = File.join(dir, "local.pp") files = [] File.open(importer, "w") do |f| f.puts %{import "#{fullfile}"\ninclude full\nimport "local.pp"\ninclude local} end fullmaker = tempfile files << fullmaker File.open(fullfile, "w") do |f| f.puts %{class full { file { "#{fullmaker}": ensure => file }}} end localmaker = tempfile files << localmaker File.open(localfile, "w") do |f| f.puts %{class local { file { "#{localmaker}": ensure => file }}} end parser = mkparser parser.file = importer # Make sure it parses assert_nothing_raised { parser.parse } # Now make sure it actually does the work assert_creates(importer, *files) end # Make sure the parser adds '.pp' when necessary def test_addingpp dir = tempfile Dir.mkdir(dir) importer = File.join(dir, "site.pp") localfile = File.join(dir, "local.pp") files = [] File.open(importer, "w") do |f| f.puts %{import "local"\ninclude local} end file = tempfile files << file File.open(localfile, "w") do |f| f.puts %{class local { file { "#{file}": ensure => file }}} end parser = mkparser parser.file = importer assert_nothing_raised { parser.parse } end # Make sure that file importing changes file relative names. def test_changingrelativenames dir = tempfile Dir.mkdir(dir) Dir.mkdir(File.join(dir, "subdir")) top = File.join(dir, "site.pp") subone = File.join(dir, "subdir/subone") subtwo = File.join(dir, "subdir/subtwo") files = [] file = tempfile files << file File.open(subone + ".pp", "w") do |f| f.puts %{class one { file { "#{file}": ensure => file }}} end otherfile = tempfile files << otherfile File.open(subtwo + ".pp", "w") do |f| f.puts %{import "subone"\n class two inherits one { file { "#{otherfile}": ensure => file } }} end File.open(top, "w") do |f| f.puts %{import "subdir/subtwo"} end parser = mkparser parser.file = top assert_nothing_raised { parser.parse } end # Defaults are purely syntactical, so it doesn't make sense to be able to # collect them. def test_uncollectabledefaults string = "@Port { protocols => tcp }" assert_raise(Puppet::ParseError) { mkparser.parse(string) } end # Verify that we can parse collections def test_collecting text = "Port <| |>" parser = mkparser parser.string = text ret = nil assert_nothing_raised { ret = parser.parse } - ret.hostclass("").code.each do |obj| + ret.code.each do |obj| assert_instance_of(AST::Collection, obj) end end def test_emptyfile file = tempfile File.open(file, "w") do |f| f.puts %{} end parser = mkparser parser.file = file assert_nothing_raised { parser.parse } end def test_multiple_nodes_named file = tempfile other = tempfile File.open(file, "w") do |f| f.puts %{ node nodeA, nodeB { file { "#{other}": ensure => file } } } end parser = mkparser parser.file = file ast = nil assert_nothing_raised { ast = parser.parse } end def test_emptyarrays str = %{$var = []\n} parser = mkparser parser.string = str # Make sure it parses fine assert_nothing_raised { parser.parse } end # Make sure function names aren't reserved words. def test_functionnamecollision str = %{tag yayness tag(rahness) file { "/tmp/yayness": tag => "rahness", ensure => exists } } parser = mkparser parser.string = str # Make sure it parses fine assert_nothing_raised { parser.parse } end def test_metaparams_in_definition_prototypes parser = mkparser assert_raise(Puppet::ParseError) { - parser.parse %{define mydef($schedule) {}} + parser.known_resource_types.import_ast(parser.parse(%{define mydef($schedule) {}}), '') } assert_nothing_raised { - parser.parse %{define adef($schedule = false) {}} - parser.parse %{define mydef($schedule = daily) {}} + parser.known_resource_types.import_ast(parser.parse(%{define adef($schedule = false) {}}), '') + parser.known_resource_types.import_ast(parser.parse(%{define mydef($schedule = daily) {}}), '') } end def test_parsingif parser = mkparser exec = proc do |val| %{exec { "/bin/echo #{val}": logoutput => true }} end str1 = %{if true { #{exec.call("true")} }} ret = nil assert_nothing_raised { - ret = parser.parse(str1).hostclass("").code[0] + ret = parser.parse(str1).code[0] } assert_instance_of(Puppet::Parser::AST::IfStatement, ret) parser = mkparser str2 = %{if true { #{exec.call("true")} } else { #{exec.call("false")} }} - ret = parser.parse(str2).hostclass("").code[0] + ret = parser.parse(str2).code[0] assert_instance_of(Puppet::Parser::AST::IfStatement, ret) assert_instance_of(Puppet::Parser::AST::Else, ret.else) end def test_hostclass parser = mkparser assert_nothing_raised { - parser.parse %{class myclass { class other {} }} + parser.known_resource_types.import_ast(parser.parse(%{class myclass { class other {} }}), '') } assert(parser.hostclass("myclass"), "Could not find myclass") assert(parser.hostclass("myclass::other"), "Could not find myclass::other") assert_nothing_raised { - parser.parse "class base {} + parser.known_resource_types.import_ast(parser.parse("class base {} class container { class deep::sub inherits base {} - }" + }"), '') } sub = parser.hostclass("container::deep::sub") assert(sub, "Could not find sub") # Now try it with a parent class being a fq class assert_nothing_raised { - parser.parse "class container::one inherits container::deep::sub {}" + parser.known_resource_types.import_ast(parser.parse("class container::one inherits container::deep::sub {}"), '') } sub = parser.hostclass("container::one") assert(sub, "Could not find one") assert_equal("container::deep::sub", sub.parent) # Finally, try including a qualified class assert_nothing_raised("Could not include fully qualified class") { - parser.parse "include container::deep::sub" + parser.known_resource_types.import_ast(parser.parse("include container::deep::sub"), '') } end def test_topnamespace parser = mkparser # Make sure we put the top-level code into a class called "" in # the "" namespace - assert_nothing_raised do - out = parser.parse "" - - assert_instance_of(Puppet::Resource::TypeCollection, out) - assert_nil(parser.hostclass(""), "Got a 'main' class when we had no code") - end - - # Now try something a touch more complicated parser.initvars assert_nothing_raised do - out = parser.parse "Exec { path => '/usr/bin:/usr/sbin' }" - assert_instance_of(Puppet::Resource::TypeCollection, out) - assert_equal("", parser.hostclass("").name) - assert_equal("", parser.hostclass("").namespace) + parser.known_resource_types.import_ast(parser.parse("Exec { path => '/usr/bin:/usr/sbin' }"), '') + assert_equal("", parser.known_resource_types.hostclass("").name) + assert_equal("", parser.known_resource_types.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 }") + parser.known_resource_types.import_ast(parser.parse("#{at}file { '/tmp/testing': owner => root }"), '') + ret = parser.known_resource_types 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) + assert_instance_of(AST::ASTArray, resdef.instances) + assert_equal(1, resdef.instances.children.length) + assert_equal("/tmp/testing", resdef.instances[0].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 }") + parser.known_resource_types.import_ast(parser.parse("#{at}file { ['/tmp/1', '/tmp/2']: owner => root }"), '') + ret = parser.known_resource_types end - ret.hostclass("").code.each do |res| + ret.hostclass("").code[0].each do |res| assert_instance_of(AST::Resource, res) check.call(res, "multiresource") end end ensure 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? 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| Puppet::Node::Environment.clear parser = mkparser if form == :virtual arrow = "<||>" else arrow = "<<||>>" end ret = nil assert_nothing_raised do ret = parser.parse("File #{arrow}") end - coll = ret.hostclass("").code[0] + coll = ret.code[0] assert_instance_of(AST::Collection, coll) assert_equal(form, coll.form) end ensure 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_collectionexpressions %w{== !=}.each do |oper| Puppet::Node::Environment.clear str = "File <| title #{oper} '/tmp/testing' |>" parser = mkparser res = nil assert_nothing_raised do - res = parser.parse(str).hostclass("").code[0] + res = parser.parse(str).code[0] end assert_instance_of(AST::Collection, res) query = res.query assert_instance_of(AST::CollExpr, query) assert_equal(:virtual, query.form) assert_equal("title", query.test1.value) assert_equal("/tmp/testing", query.test2.value) assert_equal(oper, query.oper) end end def test_collectionstatements %w{and or}.each do |joiner| str = "File <| title == '/tmp/testing' #{joiner} owner == root |>" parser = mkparser res = nil assert_nothing_raised do - res = parser.parse(str).hostclass("").code[0] + res = parser.parse(str).code[0] end assert_instance_of(AST::Collection, res) query = res.query assert_instance_of(AST::CollExpr, query) assert_equal(joiner, query.oper) assert_instance_of(AST::CollExpr, query.test1) assert_instance_of(AST::CollExpr, query.test2) end end def test_collectionstatements_with_parens [ "(title == '/tmp/testing' and owner == root) or owner == wheel", "(title == '/tmp/testing')" ].each do |test| str = "File <| #{test} |>" parser = mkparser res = nil assert_nothing_raised("Could not parse '#{test}'") do - res = parser.parse(str).hostclass("").code[0] + res = parser.parse(str).code[0] end assert_instance_of(AST::Collection, res) query = res.query assert_instance_of(AST::CollExpr, query) #assert_equal(joiner, query.oper) #assert_instance_of(AST::CollExpr, query.test1) #assert_instance_of(AST::CollExpr, query.test2) end end def test_fully_qualified_definitions parser = mkparser + types = parser.known_resource_types assert_nothing_raised("Could not parse fully-qualified definition") { - parser.parse %{define one::two { }} + types.import_ast(parser.parse(%{define one::two { }}), '') } assert(parser.definition("one::two"), "Could not find one::two with no namespace") - - # Now try using the definition - assert_nothing_raised("Could not parse fully-qualified definition usage") { - parser.parse %{one::two { yayness: }} - } end # #524 def test_functions_with_no_arguments parser = mkparser assert_nothing_raised("Could not parse statement function with no args") { parser.parse %{tag()} } assert_nothing_raised("Could not parse rvalue function with no args") { parser.parse %{$testing = template()} } end # #774 def test_fully_qualified_collection_statement parser = mkparser assert_nothing_raised("Could not parse fully qualified collection statement") { parser.parse %{Foo::Bar <||>} } end def test_multiple_imports_on_one_line one = tempfile '.pp' two = tempfile '.pp' base = tempfile '.pp' File.open(one, "w") { |f| f.puts "$var = value" } File.open(two, "w") { |f| f.puts "$var = value" } File.open(base, "w") { |f| f.puts "import '#{one}', '#{two}'" } parser = mkparser parser.file = base # Importing is logged at debug time. Puppet::Util::Log.level = :debug assert_nothing_raised("Parser could not import multiple files at once") do parser.parse end [one, two].each do |file| assert(@logs.detect { |l| l.message =~ /importing '#{file}'/}, "did not import #{file}") end end def test_cannot_assign_qualified_variables parser = mkparser assert_raise(Puppet::ParseError, "successfully assigned a qualified variable") do parser.parse("$one::two = yay") end end # #629 - undef keyword def test_undef parser = mkparser result = nil assert_nothing_raised("Could not parse assignment to undef") { result = parser.parse %{$variable = undef} } - main = result.hostclass("").code + main = result.code children = main.children assert_instance_of(AST::VarDef, main.children[0]) assert_instance_of(AST::Undef, main.children[0].value) end # Prompted by #729 -- parsing should not modify the interpreter. def test_parse parser = mkparser str = "file { '/tmp/yay': ensure => file }\nclass yay {}\nnode foo {}\ndefine bar {}\n" result = nil assert_nothing_raised("Could not parse") do - result = parser.parse(str) + parser.known_resource_types.import_ast(parser.parse(str), '') + result = parser.known_resource_types end assert_instance_of(Puppet::Resource::TypeCollection, result, "Did not get a ASTSet back from parsing") 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 parser = mkparser assert_nothing_raised do {"base::sub" => %w{base sub}, "main" => ["", "main"], "one::two::three::four" => ["one::two::three", "four"], }.each do |name, ary| result = parser.namesplit(name) assert_equal(ary, result, "#{name} split to #{result}") end end end # Make sure class, node, and define methods are case-insensitive def test_structure_case_insensitivity parser = mkparser result = nil assert_nothing_raised do - result = parser.newclass "Yayness" + parser.known_resource_types.import_ast(parser.parse("class yayness { }"), '') + result = parser.known_resource_types.hostclass('yayness') end assert_equal(result, parser.find_hostclass("", "yayNess")) assert_nothing_raised do - result = parser.newdefine "FunTest" + parser.known_resource_types.import_ast(parser.parse("define funtest { }"), '') + result = parser.known_resource_types.definition('funtest') end assert_equal(result, parser.find_definition("", "fUntEst"), "#{"fUntEst"} was not matched") end end diff --git a/test/language/scope.rb b/test/language/scope.rb index cb5558aec..d9c122a92 100755 --- a/test/language/scope.rb +++ b/test/language/scope.rb @@ -1,277 +1,277 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../lib/puppettest' require 'mocha' require 'puppettest' require 'puppettest/parsertesting' require 'puppettest/resourcetesting' # so, what kind of things do we want to test? # we don't need to test function, since we're confident in the # library tests. We do, however, need to test how things are actually # working in the language. # so really, we want to do things like test that our ast is correct # and test whether we've got things in the right scopes 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] } end def test_variables config = mkcompiler topscope = config.topscope midscope = config.newscope(topscope) botscope = config.newscope(midscope) scopes = {:top => topscope, :mid => midscope, :bot => botscope} # Set a variable in the top and make sure all three can get it topscope.setvar("first", "topval") scopes.each do |name, scope| assert_equal("topval", scope.lookupvar("first", false), "Could not find var in #{name}") end # Now set a var in the midscope and make sure the mid and bottom can see it but not the top midscope.setvar("second", "midval") assert_equal(:undefined, scopes[:top].lookupvar("second", false), "Found child var in top scope") [:mid, :bot].each do |name| assert_equal("midval", scopes[name].lookupvar("second", false), "Could not find var in #{name}") end # And set something in the bottom, and make sure we only find it there. botscope.setvar("third", "botval") [:top, :mid].each do |name| assert_equal(:undefined, scopes[name].lookupvar("third", false), "Found child var in top scope") end assert_equal("botval", scopes[:bot].lookupvar("third", false), "Could not find var in bottom scope") # Test that the scopes convert to hash structures correctly. # For topscope recursive vs non-recursive should be identical assert_equal(topscope.to_hash(false), topscope.to_hash(true), "Recursive and non-recursive hash is identical for topscope") # Check the variable we expect is present. assert_equal({"first" => "topval"}, topscope.to_hash, "topscope returns the expected hash of variables") # Now, check that midscope does the right thing in all cases. assert_equal( {"second" => "midval"}, midscope.to_hash(false), "midscope non-recursive hash contains only midscope variable") assert_equal( {"first" => "topval", "second" => "midval"}, midscope.to_hash(true), "midscope recursive hash contains topscope variable also") # Finally, check the ability to shadow symbols by adding a shadow to # bottomscope, then checking that we see the right stuff. botscope.setvar("first", "shadowval") assert_equal( {"third" => "botval", "first" => "shadowval"}, botscope.to_hash(false), "botscope has the right non-recursive hash") assert_equal( {"third" => "botval", "first" => "shadowval", "second" => "midval"}, botscope.to_hash(true), "botscope values shadow parent scope values") end def test_declarative # set to declarative top = mkscope sub = mkscope(:parent => top) assert_nothing_raised { top.setvar("test","value") } assert_raise(Puppet::ParseError) { top.setvar("test","other") } assert_nothing_raised { sub.setvar("test","later") } assert_raise(Puppet::ParseError) { top.setvar("test","yeehaw") } end def test_parent config = mkcompiler top = config.topscope # Make a subscope sub = config.newscope(top) assert_equal(top, sub.parent, "Did not find parent scope correctly") assert_equal(top, sub.parent, "Did not find parent scope on second call") end # Make sure we know what we consider to be truth. def test_truth assert_equal( true, Puppet::Parser::Scope.true?("a string"), "Strings not considered true") assert_equal( true, Puppet::Parser::Scope.true?(true), "True considered true") assert_equal( false, Puppet::Parser::Scope.true?(""), "Empty strings considered true") assert_equal( false, Puppet::Parser::Scope.true?(false), "false considered true") assert_equal( false, Puppet::Parser::Scope.true?(:undef), "undef considered true") end def test_virtual_definitions_do_not_get_evaluated parser = mkparser config = mkcompiler # Create a default source - parser.newclass("") + parser.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "") config.topscope.source = parser.known_resource_types.hostclass("") # And a scope resource scope_res = Puppet::Parser::Resource.new(:file, "/file", :scope => config.topscope) config.topscope.resource = scope_res args = AST::ASTArray.new( :children => [nameobj("arg")] ) # Create a top-level define - parser.newdefine "one", :arguments => [%w{arg}], + parser.known_resource_types.add Puppet::Resource::Type.new(:definition, "one", :arguments => [%w{arg}], :code => AST::ASTArray.new( :children => [ resourcedef("file", "/tmp", {"owner" => varref("arg")}) ] - ) + )) # create a resource that calls our third define obj = resourcedef("one", "boo", {"arg" => "parentfoo"}) # And mark it as virtual obj.virtual = true # And then evaluate it obj.evaluate config.topscope # And run the loop. config.send(:evaluate_generators) %w{File}.each do |type| objects = config.resources.find_all { |r| r.type == type and r.virtual } assert(objects.empty?, "Virtual define got evaluated") end end if defined? ::ActiveRecord # Verify that we can both store and collect an object in the same # run, whether it's in the same scope as a collection or a different # scope. def test_storeandcollect 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 Puppet::Rails.init sleep 1 children = [] Puppet[:code] = " class yay { @@host { myhost: ip => \"192.168.0.2\" } } include yay @@host { puppet: ip => \"192.168.0.3\" } Host <<||>>" 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.merge "hostname" => node.name 2.times { |i| catalog = Puppet::Parser::Compiler.new(node).compile assert_instance_of(Puppet::Parser::Resource, catalog.resource(:host, "puppet")) assert_instance_of(Puppet::Parser::Resource, catalog.resource(:host, "myhost")) } ensure 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 else $stderr.puts "No ActiveRecord -- skipping collection tests" end def test_namespaces scope = mkscope assert_equal( [""], scope.namespaces, "Started out with incorrect namespaces") assert_nothing_raised { scope.add_namespace("fun::test") } assert_equal(["fun::test"], scope.namespaces, "Did not add namespace correctly") assert_nothing_raised { scope.add_namespace("yay::test") } assert_equal(["fun::test", "yay::test"], scope.namespaces, "Did not add extra namespace correctly") end # #629 - undef should be "" or :undef def test_lookupvar_with_undef scope = mkscope scope.setvar("testing", :undef) assert_equal( :undef, scope.lookupvar("testing", false), "undef was not returned as :undef when not string") assert_equal( "", scope.lookupvar("testing", true), "undef was not returned as '' when string") end end diff --git a/test/lib/puppettest/parsertesting.rb b/test/lib/puppettest/parsertesting.rb index bd04c1ec5..411bad37a 100644 --- a/test/lib/puppettest/parsertesting.rb +++ b/test/lib/puppettest/parsertesting.rb @@ -1,428 +1,425 @@ require 'puppettest' require 'puppet/rails' module PuppetTest::ParserTesting include PuppetTest AST = Puppet::Parser::AST Compiler = Puppet::Parser::Compiler # A fake class that we can use for testing evaluation. class FakeAST attr_writer :evaluate def evaluated? @evaluated end def evaluate(*args) @evaluated = true @evaluate end def initialize(val = nil) @evaluate = val if val end def reset @evaluated = nil end def safeevaluate(*args) evaluate end def evaluate_match(othervalue, scope, options={}) value = evaluate othervalue == value end end def astarray(*args) AST::ASTArray.new( :children => args ) end def mkcompiler(parser = nil) node = mknode Compiler.new(node) end def mknode(name = nil) require 'puppet/node' Puppet::Node.new(name || "nodename") end def mkparser Puppet::Node::Environment.clear Puppet::Parser::Parser.new(Puppet::Node::Environment.new) end def mkscope(hash = {}) parser ||= mkparser compiler ||= mkcompiler compiler.topscope.source = (parser.find_hostclass("", "") || parser.newclass("")) raise "Could not find source for scope" unless compiler.topscope.source # Make the 'main' stuff compiler.send(:evaluate_main) compiler.topscope end def classobj(name, hash = {}) hash[:file] ||= __FILE__ hash[:line] ||= __LINE__ hash[:type] ||= name AST::HostClass.new(hash) end def tagobj(*names) args = {} newnames = names.collect do |name| if name.is_a? AST name else nameobj(name) end end args[:type] = astarray(*newnames) assert_nothing_raised("Could not create tag #{names.inspect}") { return AST::Tag.new(args) } end def resourcedef(type, title, params) title = stringobj(title) unless title.is_a?(AST) + instance = AST::ResourceInstance.new(:title => title, :parameters => resourceparams(params)) assert_nothing_raised("Could not create #{type} #{title}") { return AST::Resource.new( :file => __FILE__, :line => __LINE__, - :title => title, :type => type, - - :parameters => resourceinst(params) + :instances => AST::ASTArray.new(:children => [instance]) ) } end def virt_resourcedef(*args) res = resourcedef(*args) res.virtual = true res end def resourceoverride(type, title, params) assert_nothing_raised("Could not create #{type} #{name}") { return AST::ResourceOverride.new( :file => __FILE__, :line => __LINE__, :object => resourceref(type, title), - - :type => type, - :parameters => resourceinst(params) + :parameters => resourceparams(params) ) } end def resourceref(type, title) assert_nothing_raised("Could not create #{type} #{title}") { return AST::ResourceReference.new( :file => __FILE__, :line => __LINE__, :type => type, :title => stringobj(title) ) } end def fileobj(path, hash = {"owner" => "root"}) assert_nothing_raised("Could not create file #{path}") { return resourcedef("file", path, hash) } end def nameobj(name) assert_nothing_raised("Could not create name #{name}") { return AST::Name.new( :file => tempfile, :line => rand(100), :value => name ) } end def typeobj(name) assert_nothing_raised("Could not create type #{name}") { return AST::Type.new( :file => tempfile, :line => rand(100), :value => name ) } end def nodedef(name) assert_nothing_raised("Could not create node #{name}") { return AST::NodeDef.new( :file => tempfile, :line => rand(100), :names => nameobj(name), :code => AST::ASTArray.new( :children => [ varobj("#{name}var", "#{name}value"), fileobj("/#{name}") ] ) ) } end - def resourceinst(hash) + def resourceparams(hash) assert_nothing_raised("Could not create resource instance") { params = hash.collect { |param, value| resourceparam(param, value) } - return AST::ResourceInstance.new( + return AST::ASTArray.new( :file => tempfile, :line => rand(100), :children => params ) } end def resourceparam(param, value) # Allow them to pass non-strings in value = stringobj(value) if value.is_a?(String) assert_nothing_raised("Could not create param #{param}") { return AST::ResourceParam.new( :file => tempfile, :line => rand(100), :param => param, :value => value ) } end def stringobj(value) AST::String.new( :file => tempfile, :line => rand(100), :value => value ) end def varobj(name, value) value = stringobj(value) unless value.is_a? AST assert_nothing_raised("Could not create #{name} code") { return AST::VarDef.new( :file => tempfile, :line => rand(100), :name => nameobj(name), :value => value ) } end def varref(name) assert_nothing_raised("Could not create #{name} variable") { return AST::Variable.new( :file => __FILE__, :line => __LINE__, :value => name ) } end def argobj(name, value) assert_nothing_raised("Could not create #{name} compargument") { return AST::CompArgument.new( :children => [nameobj(name), stringobj(value)] ) } end def defaultobj(type, params) pary = [] params.each { |p,v| pary << AST::ResourceParam.new( :file => __FILE__, :line => __LINE__, :param => p, :value => stringobj(v) ) } past = AST::ASTArray.new( :file => __FILE__, :line => __LINE__, :children => pary ) assert_nothing_raised("Could not create defaults for #{type}") { return AST::ResourceDefaults.new( :file => __FILE__, :line => __LINE__, :type => type, :parameters => past ) } end def taggedobj(name, ftype = :statement) functionobj("tagged", name, ftype) end def functionobj(function, name, ftype = :statement) func = nil assert_nothing_raised do func = Puppet::Parser::AST::Function.new( :name => function, :ftype => ftype, :arguments => AST::ASTArray.new( :children => [nameobj(name)] ) ) end func end # This assumes no nodes def assert_creates(manifest, *files) oldmanifest = Puppet[:manifest] Puppet[:manifest] = manifest catalog = Puppet::Parser::Compiler.new(mknode).compile.to_ral catalog.apply files.each do |file| assert(FileTest.exists?(file), "Did not create #{file}") end ensure Puppet[:manifest] = oldmanifest end def mk_transobject(file = "/etc/passwd") obj = nil assert_nothing_raised { obj = Puppet::TransObject.new("file", file) obj["owner"] = "root" obj["mode"] = "644" } obj end def mk_transbucket(*resources) bucket = nil assert_nothing_raised { bucket = Puppet::TransBucket.new bucket.name = "yayname" bucket.type = "yaytype" } resources.each { |o| bucket << o } bucket end # Make a tree of resources, yielding if desired def mk_transtree(depth = 4, width = 2) top = nil assert_nothing_raised { top = Puppet::TransBucket.new top.name = "top" top.type = "bucket" } bucket = top file = tempfile depth.times do |i| resources = [] width.times do |j| path = tempfile + i.to_s obj = Puppet::TransObject.new("file", path) obj["owner"] = "root" obj["mode"] = "644" # Yield, if they want yield(obj, i, j) if block_given? resources << obj end newbucket = mk_transbucket(*resources) bucket.push newbucket bucket = newbucket end top end # Take a list of AST resources, evaluate them, and return the results def assert_evaluate(children) top = nil assert_nothing_raised("Could not create top object") { top = AST::ASTArray.new( :children => children ) } trans = nil scope = nil assert_nothing_raised { scope = Puppet::Parser::Scope.new trans = scope.evaluate(:ast => top) } trans end end diff --git a/test/other/report.rb b/test/other/report.rb index b3b41da19..8a909b41c 100755 --- a/test/other/report.rb +++ b/test/other/report.rb @@ -1,138 +1,135 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../lib/puppettest' require 'puppet' require 'puppet/reports' require 'puppet/transaction/report' require 'puppettest' require 'puppettest/reporttesting' class TestReports < Test::Unit::TestCase include PuppetTest include PuppetTest::Reporttesting def mkreport # First do some work objects = [] 6.times do |i| file = tempfile # Make every third file File.open(file, "w") { |f| f.puts "" } if i % 3 == 0 objects << Puppet::Type.type(:file).new( :path => file, :ensure => "file" ) end config = mk_catalog(*objects) # So the report works out. config.retrieval_duration = 0.001 trans = config.apply - report = Puppet::Transaction::Report.new - trans.add_metrics_to_report(report) - - report + trans.generate_report end # Make sure we can use reports as log destinations. def test_reports_as_log_destinations report = fakereport assert_nothing_raised { Puppet::Util::Log.newdestination(report) } # Now make a file for testing logging file = Puppet::Type.type(:file).new(:path => tempfile, :ensure => "file") file.finish log = nil assert_nothing_raised { log = file.log "This is a message, yo" } assert(report.logs.include?(log), "Report did not get log message") assert_nothing_raised { Puppet::Util::Log.close(report) } log = file.log "This is another message, yo" assert(! report.logs.include?(log), "Report got log message after close") end def test_store_report # Create a bunch of log messages in an array. report = Puppet::Transaction::Report.new # We have to reuse reporting here because of something going on in the # server/report.rb file Puppet.settings.use(:main, :master) 3.times { |i| log = Puppet.warning("Report test message #{i}") report << log } assert_nothing_raised do report.extend(Puppet::Reports.report(:store)) end yaml = YAML.dump(report) file = report.process assert(FileTest.exists?(file), "report file did not get created") assert_equal(yaml, File.read(file), "File did not get written") end - if Puppet.features.rrd? + if Puppet.features.rrd? || Puppet.features.rrd_legacy? def test_rrdgraph_report Puppet.settings.use(:main, :metrics) report = mkreport assert(! report.metrics.empty?, "Did not receive any metrics") assert_nothing_raised do report.extend(Puppet::Reports.report(:rrdgraph)) end assert_nothing_raised { report.process } hostdir = nil assert_nothing_raised do hostdir = report.hostdir end assert(hostdir, "Did not get hostdir back") assert(FileTest.directory?(hostdir), "Host rrd dir did not get created") index = File.join(hostdir, "index.html") assert(FileTest.exists?(index), "index file was not created") # Now make sure it creaets each of the rrd files %w{changes resources time}.each do |type| file = File.join(hostdir, "#{type}.rrd") assert(FileTest.exists?(file), "Did not create rrd file for #{type}") daily = file.sub ".rrd", "-daily.png" assert(FileTest.exists?(daily), "Did not make daily graph for #{type}") end end else $stderr.puts "Install RRD for metric reporting tests" end end diff --git a/test/rails/railsparameter.rb b/test/rails/railsparameter.rb index 9f6fc1c1e..77ce33912 100755 --- a/test/rails/railsparameter.rb +++ b/test/rails/railsparameter.rb @@ -1,80 +1,80 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../lib/puppettest' require 'puppet' require 'puppet/rails' require 'puppettest' require 'puppettest/railstesting' # Don't do any tests w/out this class if defined? ::ActiveRecord::Base class TestRailsParameter < Test::Unit::TestCase include PuppetTest::RailsTesting def params {"myname" => "myval", "multiple" => %w{one two three}} end # Create a resource param from a rails parameter def test_to_resourceparam railsinit # Now create a source parser = mkparser - source = parser.newclass "myclass" + source = parser.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "myclass") host = Puppet::Rails::Host.new(:name => "myhost") host.save resource = host.resources.create( :title => "/tmp/to_resource", :restype => "file", :exported => true) # Use array and non-array values, to make sure we get things back in # the same form. params.each do |name, value| param = Puppet::Rails::ParamName.find_or_create_by_name(name) if value.is_a? Array values = value else values = [value] end valueobjects = values.collect do |v| resource.param_values.create( :value => v, :param_name => param) end assert(param, "Did not create rails parameter") # The id doesn't get assigned until we save end resource.save # And try to convert our parameter params.each do |name, value| param = Puppet::Rails::ParamName.find_by_name(name) pp = nil assert_nothing_raised do pp = param.to_resourceparam(resource, source) end assert_instance_of(Puppet::Parser::Resource::Param, pp) assert_equal(name.to_sym, pp.name, "parameter name was not equal") assert_equal(value, pp.value, "value was not equal for #{value.inspect}") end end end else $stderr.puts "Install Rails for Rails and Caching tests" end diff --git a/test/ral/providers/cron/crontab.rb b/test/ral/providers/cron/crontab.rb index 0c87a5bba..be2af1e16 100755 --- a/test/ral/providers/cron/crontab.rb +++ b/test/ral/providers/cron/crontab.rb @@ -1,648 +1,651 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../../lib/puppettest' require 'puppettest' require 'mocha' require 'puppettest/fileparsing' class TestCronParsedProvider < Test::Unit::TestCase include PuppetTest include PuppetTest::FileParsing FIELDS = { :crontab => %w{command minute hour month monthday weekday}.collect { |o| o.intern }, :freebsd_special => %w{special command}.collect { |o| o.intern }, :environment => [:line], :blank => [:line], :comment => [:line], } # These are potentially multi-line records; there's no one-to-one map, but they model # a full cron job. These tests assume individual record types will always be correctly # parsed, so all they def sample_crons @sample_crons ||= YAML.load(File.read(File.join(@crondir, "crontab_collections.yaml"))) end # These are simple lines that can appear in the files; there is a one to one # mapping between records and lines. We have plenty of redundancy here because # we use these records to build up our complex, multi-line cron jobs below. def sample_records @sample_records ||= YAML.load(File.read(File.join(@crondir, "crontab_sample_records.yaml"))) end def setup super @type = Puppet::Type.type(:cron) @provider = @type.provider(:crontab) @provider.initvars @crondir = datadir(File.join(%w{providers cron})) @oldfiletype = @provider.filetype end def teardown Puppet::Util::FileType.filetype(:ram).clear @provider.clear super end # Make sure a cron job matches up. Any non-passed fields are considered absent. def assert_cron_equal(msg, cron, options) assert_instance_of(@provider, cron, "not an instance of provider in #{msg}") options.each do |param, value| assert_equal(value, cron.send(param), "#{param} was not equal in #{msg}") end %w{command environment minute hour month monthday weekday}.each do |var| assert_equal(:absent, cron.send(var), "#{var} was not parsed absent in #{msg}") unless options.include?(var.intern) end end # Make sure a cron record matches. This only works for crontab records. def assert_record_equal(msg, record, options) raise ArgumentError, "You must pass the required record type" unless options.include?(:record_type) assert_instance_of(Hash, record, "not an instance of a hash in #{msg}") options.each do |param, value| assert_equal(value, record[param], "#{param} was not equal in #{msg}") end FIELDS[record[:record_type]].each do |var| assert_equal(:absent, record[var], "#{var} was not parsed absent in #{msg}") unless options.include?(var) end end def assert_header(file) header = [] file.gsub! /^(# HEADER: .+$)\n/ do header << $1 '' end assert_equal(4, header.length, "Did not get four header lines") end # This handles parsing every possible iteration of cron records. Note that this is only # single-line stuff and doesn't include multi-line values (e.g., with names and/or envs). # Those have separate tests. def test_parse_line # First just do each sample record one by one sample_records.each do |name, options| result = nil assert_nothing_raised("Could not parse #{name}: '#{options[:text]}'") do result = @provider.parse_line(options[:text]) end assert_record_equal("record for #{name}", result, options[:record]) end # Then do them all at once. records = [] text = "" - sample_records.each do |name, options| + # Sort sample_records so that the :empty entry does not come last + # (if it does, the test will fail because the empty last line will + # be ignored) + sample_records.sort { |a, b| a.first.to_s <=> b.first.to_s }.each do |name, options| records << options[:record] text += options[:text] + "\n" end result = nil assert_nothing_raised("Could not match all records in one file") do result = @provider.parse(text) end records.zip(result).each do |should, record| assert_record_equal("record for #{should.inspect} in full match", record, should) end end # Here we test that each record generates to the correct text. def test_generate_line # First just do each sample record one by one sample_records.each do |name, options| result = nil assert_nothing_raised("Could not generate #{name}: '#{options[:record]}'") do result = @provider.to_line(options[:record]) end assert_equal(options[:text], result, "Did not generate correct text for #{name}") end # Then do them all at once. records = [] text = "" sample_records.each do |name, options| records << options[:record] text += options[:text] + "\n" end result = nil assert_nothing_raised("Could not match all records in one file") do result = @provider.to_file(records) end assert_header(result) assert_equal(text, result, "Did not generate correct full crontab") end # Test cronjobs that are made up from multiple records. def test_multi_line_cronjobs fulltext = "" all_records = [] sample_crons.each do |name, record_names| records = record_names.collect do |record_name| unless record = sample_records[record_name] raise "Could not find sample record #{record_name}" end record end text = records.collect { |r| r[:text] }.join("\n") + "\n" record_list = records.collect { |r| r[:record] } # Add it to our full collection all_records += record_list fulltext += text # First make sure we generate each one correctly result = nil assert_nothing_raised("Could not generate multi-line cronjob #{name}") do result = @provider.to_file(record_list) end assert_header(result) assert_equal(text, result, "Did not generate correct text for multi-line cronjob #{name}") # Now make sure we parse each one correctly assert_nothing_raised("Could not parse multi-line cronjob #{name}") do result = @provider.parse(text) end record_list.zip(result).each do |should, record| assert_record_equal("multiline cronjob #{name}", record, should) end end # Make sure we can generate it all correctly result = nil assert_nothing_raised("Could not generate all multi-line cronjobs") do result = @provider.to_file(all_records) end assert_header(result) assert_equal(fulltext, result, "Did not generate correct text for all multi-line cronjobs") # Now make sure we parse them all correctly assert_nothing_raised("Could not parse multi-line cronjobs") do result = @provider.parse(fulltext) end all_records.zip(result).each do |should, record| assert_record_equal("multiline cronjob %s", record, should) end end # Take our sample files, and make sure we can entirely parse them, # then that we can generate them again and we get the same data. def test_parse_and_generate_sample_files @provider.stubs(:filetype).returns(Puppet::Util::FileType.filetype(:ram)) crondir = datadir(File.join(%w{providers cron})) files = Dir.glob("#{crondir}/crontab.*") setme @provider.default_target = @me target = @provider.target_object(@me) files.each do |file| str = args = nil assert_nothing_raised("could not load #{file}") do str, args = YAML.load(File.read(file)) end # Stupid old yaml args.each do |hash| hash.each do |param, value| if param.is_a?(String) and param =~ /^:/ hash.delete(param) param = param.sub(/^:/,'').intern hash[param] = value end if value.is_a?(String) and value =~ /^:/ value = value.sub(/^:/,'').intern hash[param] = value end end end target.write(str) assert_nothing_raised("could not parse #{file}") do @provider.prefetch end records = @provider.send(:instance_variable_get, "@records") args.zip(records) do |should, sis| # Make the values a bit more equal. should[:target] = @me should[:ensure] = :present #should[:environment] ||= [] should[:on_disk] = true is = sis.dup sis.dup.each do |p,v| is.delete(p) if v == :absent end assert_equal( should, is, "Did not parse #{file} correctly") end assert_nothing_raised("could not generate #{file}") do @provider.flush_target(@me) end assert_equal(str, target.read, "#{file} changed") @provider.clear end end # A simple test to see if we can load the cron from disk. def test_load setme records = nil assert_nothing_raised { records = @provider.retrieve(@me) } assert_instance_of(Array, records, "did not get correct response") end # Test that a cron job turns out as expected, by creating one and generating # it directly def test_simple_to_cron # make the cron setme name = "yaytest" args = {:name => name, :command => "date > /dev/null", :minute => "30", :user => @me, :record_type => :crontab } # generate the text str = nil assert_nothing_raised { str = @provider.to_line(args) } assert_equal( "# Puppet Name: #{name}\n30 * * * * date > /dev/null", str, "Cron did not generate correctly") end # Test that comments are correctly retained def test_retain_comments str = "# this is a comment\n#and another comment\n" user = "fakeuser" records = nil @provider.stubs(:filetype).returns(Puppet::Util::FileType.filetype(:ram)) target = @provider.target_object(user) target.write(str) assert_nothing_raised { @provider.prefetch } assert_nothing_raised { newstr = @provider.flush_target(user) assert(target.read.include?(str), "Comments were lost") } end def test_simpleparsing @provider.stubs(:filetype).returns(Puppet::Util::FileType.filetype(:ram)) text = "5 1,2 * 1 0 /bin/echo funtest" records = nil assert_nothing_raised { records = @provider.parse(text) } should = { :minute => %w{5}, :hour => %w{1 2}, :monthday => :absent, :month => %w{1}, :weekday => %w{0}, :command => "/bin/echo funtest" } is = records.shift assert(is, "Did not get record") should.each do |p, v| assert_equal(v, is[p], "did not parse #{p} correctly") end end # Make sure we can create a cron in an empty tab. # LAK:FIXME This actually modifies the user's crontab, # which is pretty heinous. def test_mkcron_if_empty setme @provider.filetype = @oldfiletype records = @provider.retrieve(@me) target = @provider.target_object(@me) cleanup do if records.length == 0 target.remove else target.write(@provider.to_file(records)) end end # Now get rid of it assert_nothing_raised("Could not remove cron tab") do target.remove end @provider.flush :target => @me, :command => "/do/something", :record_type => :crontab created = @provider.retrieve(@me) assert(created.detect { |r| r[:command] == "/do/something" }, "Did not create cron tab") end # Make sure we correctly bidirectionally parse things. def test_records_and_strings @provider.stubs(:filetype).returns(Puppet::Util::FileType.filetype(:ram)) setme target = @provider.target_object(@me) [ "* * * * * /some/command", "0,30 * * * * /some/command", "0-30 * * * * /some/command", "# Puppet Name: name\n0-30 * * * * /some/command", "# Puppet Name: name\nVAR=VALUE\n0-30 * * * * /some/command", "# Puppet Name: name\nVAR=VALUE\nC=D\n0-30 * * * * /some/command", "0 * * * * /some/command" ].each do |str| @provider.initvars str += "\n" target.write(str) assert_equal( str, target.read, "Did not write correctly") assert_nothing_raised("Could not prefetch with #{str.inspect}") do @provider.prefetch end assert_nothing_raised("Could not flush with #{str.inspect}") do @provider.flush_target(@me) end assert_equal( str, target.read, "Changed in read/write") @provider.clear end end # Test that a specified cron job will be matched against an existing job # with no name, as long as all fields match def test_matchcron mecron = "0,30 * * * * date * * * * * funtest # a comment 0,30 * * 1 * date " youcron = "0,30 * * * * date * * * * * yaytest # a comment 0,30 * * 1 * fooness " setme @provider.stubs(:filetype).returns(Puppet::Util::FileType.filetype(:ram)) you = "you" # Write the same tab to multiple targets @provider.target_object(@me).write(mecron.gsub(/^\s+/, '')) @provider.target_object(you).write(youcron.gsub(/^\s+/, '')) # Now make some crons that should match matchers = [ @type.new( :name => "yaycron", :minute => [0, 30], :command => "date", :user => @me ), @type.new( :name => "youtest", :command => "yaytest", :user => you ) ] nonmatchers = [ @type.new( :name => "footest", :minute => [0, 30], :hour => 1, :command => "fooness", :user => @me # wrong target ), @type.new( :name => "funtest2", :command => "funtest", :user => you # wrong target for this cron ) ] # Create another cron so we prefetch two of them @type.new(:name => "testing", :minute => 30, :command => "whatever", :user => "you") assert_nothing_raised("Could not prefetch cron") do @provider.prefetch([matchers, nonmatchers].flatten.inject({}) { |crons, cron| crons[cron.name] = cron; crons }) end matchers.each do |cron| assert_equal(:present, cron.provider.ensure, "Cron #{cron.name} was not matched") if value = cron.value(:minute) and value == "*" value = :absent end assert_equal(value, cron.provider.minute, "Minutes were not retrieved, so cron was not matched") assert_equal(cron.value(:target), cron.provider.target, "Cron #{cron.name} was matched from the wrong target") end nonmatchers.each do |cron| assert_equal(:absent, cron.provider.ensure, "Cron #{cron.name} was incorrectly matched") end end def test_data setme @provider.stubs(:filetype).returns(Puppet::Util::FileType.filetype(:ram)) target = @provider.target_object(@me) fakedata("data/providers/cron/examples").each do |file| text = File.read(file) target.write(text) assert_nothing_raised("Could not parse #{file}") do @provider.prefetch end # mark the provider modified @provider.modified(@me) # and zero the text target.write("") result = nil assert_nothing_raised("Could not generate #{file}") do @provider.flush_target(@me) end # Ignore whitespace differences, since those don't affect function. modtext = text.gsub(/[ \t]+/, " ") modtarget = target.read.gsub(/[ \t]+/, " ") assert_equal(modtext, modtarget, "File was not rewritten the same") @provider.clear end end # Match freebsd's annoying @daily stuff. def test_match_freebsd_special @provider.stubs(:filetype).returns(Puppet::Util::FileType.filetype(:ram)) setme target = @provider.target_object(@me) [ "@daily /some/command", "@daily /some/command more" ].each do |str| @provider.initvars str += "\n" target.write(str) assert_nothing_raised("Could not prefetch with #{str.inspect}") do @provider.prefetch end records = @provider.send(:instance_variable_get, "@records") records.each do |r| assert_equal( :freebsd_special, r[:record_type], "Did not create lines as freebsd lines") end assert_nothing_raised("Could not flush with #{str.inspect}") do @provider.flush_target(@me) end assert_equal( str, target.read, "Changed in read/write") @provider.clear end end # #707 def test_write_freebsd_special assert_equal(@provider.to_line(:record_type => :crontab, :ensure => :present, :special => "reboot", :command => "/bin/echo something"), "@reboot /bin/echo something") end def test_prefetch cron = @type.new :command => "/bin/echo yay", :name => "test", :hour => 4 assert_nothing_raised("Could not prefetch cron") do cron.provider.class.prefetch("test" => cron) end end # Testing #669. def test_environment_settings @provider.stubs(:filetype).returns(Puppet::Util::FileType.filetype(:ram)) setme target = @provider.target_object(@me) # First with no env settings resource = @type.new :command => "/bin/echo yay", :name => "test", :hour => 4 cron = resource.provider cron.ensure = :present cron.command = "/bin/echo yay" cron.hour = %w{4} cron.flush result = target.read assert_equal("# Puppet Name: test\n* 4 * * * /bin/echo yay\n", result, "Did not write cron out correctly") # Now set the env cron.environment = "TEST=foo" cron.flush result = target.read assert_equal("# Puppet Name: test\nTEST=foo\n* 4 * * * /bin/echo yay\n", result, "Did not write out environment setting") # Modify it cron.environment = ["TEST=foo", "BLAH=yay"] cron.flush result = target.read assert_equal("# Puppet Name: test\nTEST=foo\nBLAH=yay\n* 4 * * * /bin/echo yay\n", result, "Did not write out environment setting") # And remove it cron.environment = :absent cron.flush result = target.read assert_equal("# Puppet Name: test\n* 4 * * * /bin/echo yay\n", result, "Did not write out environment setting") end # Testing #1216 def test_strange_lines @provider.stubs(:filetype).returns(Puppet::Util::FileType.filetype(:ram)) text = " 5 \t\t 1,2 * 1 0 /bin/echo funtest" records = nil assert_nothing_raised { records = @provider.parse(text) } should = { :minute => %w{5}, :hour => %w{1 2}, :monthday => :absent, :month => %w{1}, :weekday => %w{0}, :command => "/bin/echo funtest" } is = records.shift assert(is, "Did not get record") should.each do |p, v| assert_equal(v, is[p], "did not parse #{p} correctly") end end end diff --git a/test/util/metrics.rb b/test/util/metrics.rb index 1fd57f2f1..82e792d0b 100755 --- a/test/util/metrics.rb +++ b/test/util/metrics.rb @@ -1,72 +1,72 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../lib/puppettest' require 'puppet' require 'puppet/util/metric' require 'puppettest' require 'puppet/type' class TestMetric < PuppetTest::TestCase - confine "Missing RRDtool library" => Puppet.features.rrd? + confine "Missing RRDtool library" => (Puppet.features.rrd? || Puppet.features.rrd_legacy?) include PuppetTest def gendata totalmax = 1000 changemax = 1000 eventmax = 10 maxdiff = 10 types = [Puppet::Type.type(:file), Puppet::Type.type(:package), Puppet::Type.type(:package)] data = [:total, :managed, :outofsync, :changed, :totalchanges] events = [:file_changed, :package_installed, :service_started] # if this is the first set of data points... typedata = Hash.new { |typehash,type| typehash[type] = Hash.new(0) } eventdata = Hash.new(0) typedata = {} typedata[:total] = rand(totalmax) typedata[:managed] = rand(typedata[:total]) typedata[:outofsync] = rand(typedata[:managed]) typedata[:changed] = rand(typedata[:outofsync]) typedata[:totalchanges] = rand(changemax) events.each { |event| eventdata[event] = rand(eventmax) } {:typedata => typedata, :eventdata => eventdata} end def rundata(report, time) assert_nothing_raised { gendata.each do |name, data| - report.newmetric(name, data) + report.add_metric(name, data) end report.metrics.each { |n, m| m.store(time) } } end def test_fakedata report = Puppet::Transaction::Report.new time = Time.now.to_i start = time 10.times { rundata(report, time) time += 300 } rundata(report, time) report.metrics.each do |n, m| m.graph end File.open(File.join(Puppet[:rrddir],"index.html"),"w") { |of| of.puts "" report.metrics.each { |name, metric| of.puts "
" } } end end