[Persist] Add persist_username & persist_password to Config::Server.

Currently there is no mechanism to pass authentication credentials to a
local or remote persistence service (such as MongoDB or PostgreSQL).
While a non-authenticated connection works out of the box with a local
MongoDB server, this is not the case with a local PostgreSQL server.

Furthermore there is no way to configure Razor to use a remote MongoDB
server protected by a username/password authentication.

As a result the PersistPlugin#connect method signature was augmented to
take `username` and `password` parameters. Each persistence
implementation is responsible for using or ignoring these additional
parameters when establishing a database connection.
[Postgres] Bugfix: uuid variable not defined in #object_doc_get_by_uuid.
[Postgres] Ensure Ruby symbols are (de)serialized.

In the MongoPlugin Ruby symbols are preserved in hash values thanks to
BSON, but in other persistence plugins symbols will be coerced to
strings (via a JSON.generate in the Postgres case) before saving. When
the object is deserialized the values that were Ruby symbols are now
strings which is not expected by the rest of the codebase.

Instead, we can "encode" the hash data structures containing symbols by
transforming any symbols to strings, for example: :symbol -> ":symbol".
When the data is read back out of the database we can "decode" these
data structures and reconstitute the symbols.
[Postgres] Allow ID of type VARCHAR only for policy_table.

A single row is inserted into this table with a "uuid" set to
"policy_table" which is not a valid UUID.
[Postgres] Insert active_model object if '@version' attr is < 0.

The object document that is persisted to the :active collection is a
PolicyTemplate and as such will have a version attribute greater than 1.
(#323) Fix final URL related bug in configuration related acceptance tests

The earlier merge was tested improperly, and wound up full of breakage that
only showed up in the "live" CI system, not on the bench.  While that sucked,
most of the issues were patched.

This one missing URI parsing issue seems to be the last real failure in our CI
system, and with that changed to not double-parse a URI, should give us a
fully functional test suite again.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Merge pull request #434 from daniel-pittman/bug/master/323-additional-acceptance-failures-after-cleanup

(#323) Fix final URL related bug in configuration related acceptance tes...
Merge PostgreSQL plugin fixes from blueboxgroup

This fixes some of the more obvious and painful bugs in the PostgreSQL storage
plugin added a little while back.  It doesn't address core issues like
application level model corruption from concurrent activity on the database,
but it makes it more practical to use PSQL during testing of the current
preview releases.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Script Broker

A simple broker that executes a script on the node. This provides a
lightweight broker with no external service dependencies. It is suitable
for one-time configuration post os install, but also flexible enough to
setup more complicated long term solutions (e.g. local puppet apply).

Features:

 * Optionally send auxillary data along with the script.
 * Sends the metadata along with the script.
 * Fully configurable where the files land on the node.

Interface:

The script will be called with one parameter: The path to the metadata file.
The metadata file contains all the node metadata (including tags) and the
configuration of the script broker (including the paths to local resources). It
is JSON 'pretty' formatted and should be amiable to parsing.

Example:

  On the Razor Server:

    # cat /root/hello_world.sh
    #!/bin/bash
    set -e
    set -u

    echo "Hello World!"
    echo "Metadata Path: $1"

    # razor broker
    Broker Targets:
     Name =>  hello_world
     Description =>  Hello
     Plugin =>  script
     UUID =>  4kp0o3tchb5NW5pdcV6pRf
     Script =>  /root/hello_world.sh
     Script Path =>  /tmp/razor_script
     Data =>
     Data Path =>  /tmp/razor_script_data
     Metadata Path =>  /tmp/razor_script_metadata
     Log Path =>  /tmp/razor_script.log

  On the Node after the script broker has run:

    # cd /tmp
    # ls
    razor_complete.log  razor_script  razor_script.log  razor_script_metadata
    # cat razor_script.log
    Hello World!
    Metadata Path: /tmp/razor_script_metadata
    # cat /tmp/razor_script_metadata
    {
      "username": "root",
      "password": "electric",
      "metadata": {
        "razor_tags": "ubuntu-precise,cpus_16,virtualbox_vm,OracleCorporation,nics_1,memsize_1015MiB",
        "razor_node_uuid": "49jbMtCv4gn0BLphWfmJ8p",
        "razor_active_model_uuid": "4IfYuiaCQ1fY9D1mQUZ0Vr",
        "razor_model_uuid": "60WqyDfq9yF3HSSpLWutpf",
        "razor_model_name": "ubuntu_precise",
        "razor_model_description": "Ubuntu Precise Model",
        "razor_model_template": "linux_deploy",
        "razor_policy_count": "27"
      },
      "uuid": "49jbMtCv4gn0BLphWfmJ8p",
      "ipaddress": "10.0.1.123",
      "script": "/vagrant/echo_script.sh",
      "script_path": "/tmp/razor_script",
      "data": "",
      "data_path": "/tmp/razor_script_data",
      "metadata_path": "/tmp/razor_script_metadata",
      "log_path": "/tmp/razor_script.log"
    }
Manual Broker Retry

Allow the broker to be invoked manually via a policy callback:

    razor policy callback <active model> broker

This will trigger the broker_agent_handoff method on the policy. It
takes no arguments and simply restarts the broker handoff process. This
may be useful for testing out brokers or retrying a failed broker.

Fixes #420
Merge pull request #437 from calebcase/master

Merge arbitrary script-based broker hand-off
Fix broker plugin listing after script broker was merged

When the script broker was merged it included a new error class, specific to
the broker, that allowed differentiation of remote script errors from other
classes of error.

Unfortunately, that error class was defined at the broker level that Razor
expected to be able to enumerate only broker plugin class children -
triggering a failure in an attempt to list all available broker plugins.

This fixes that by moving the custom error class down a level, to where it no
longer trips up the metaprogramming - and adds a spec test to ensure that this
doesn't explode again.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Additional testing for other meta-programming template code

This adds tests to the other consumers of the meta-programming
`get_child_templates` method in slices - to ensure that we don't accidentally
repeat the script broker failure in one of the other areas that make
assumptions about what class children exist under a namespace.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Merge pull request #445 from daniel-pittman/bug/master/broker-plugin-list-fails-after-437-script-broker-merged

broker plugin list fails after #437 - script broker - merged
Merge `filtering` module into the one place it is used

The `ProjectRazor::Filtering` module defined a mechanism for general subset
hash comparison, used as part of object retrieval.  This ended up with a
single consumer, the `ProjectRazor::Data` object.

That made it kind of confusing to look into a distinct file when trying to
figure out the implementation - especially because the mixin nature jumped
between the two files for what, in essence, was a single class.

This simple merges the code directly into the data object, and eliminates the
separate file.  That produces the same final result with less files and
lines overall.

It also called out that the `sanitize_hash` method was duplicated between the
utility module - and, so, all classes through the `ProjectRazor::Object` base
class that everything else is derived from - and the exact duplicate
implementation in the filtering module.

As part of the move that was simply dropped; the same code is run, but now
only a single copy exists rather than the two identical copies we had before.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Remove a reimplementation of Hash#has_key? from Razor

The `find_key_match` method in the Filtering module - and, now, the data
class - was an open-coded implementation of `Hash#has_key?`.  This eliminates
it in favour of the original method.

It also eliminates the spurious temporary that could only ever have the same
value as the key we were searching on, in favor of an `unless` statement, so
that the actual purpose of the decision point was made clear.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Simplify various data store array and hash operations

This eliminates some extra array and hash allocations, in favour of streaming
Ruby constructs like `select` and `map`.  This marginally reduces the line
count, as well as substantially improving the clarity of purpose of the code.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Eliminate unused `bson_to_hash` helper

The general utility, imported indirectly to almost every class in the project,
had a `bson_to_hash` helper that was ultimately unused.  (Well, except for a
recursive call inside itself.)

This deletes it, with no functional change, but a small reduction in line
count and missing test count.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Eliminate unused `is_valid_{type,template}?` helpers

The `is_valid_type?` helper, and the alias `is_valid_template?`, were
indirectly part of the API of pretty much every class in the codebase through
their importation into the common base class.

They were also unused.  This eliminates them, giving no functional change but
a reduction in line count and test deficit.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Inline the behaviour of `is_valid_json?` in both callsites

The general utility `is_valid_json?` would perform a full JSON parse, and then
discard the results; it treated any error of any sort as a reason to ignore
the problem and carry on.

This was called in two places in a single slice, and can easily enough be
replaced by simply adding a `rescue` block that will ignore all errors.

This cuts our JSON parsing time in half, not that it was terribly significant,
and reduces the complexity of the code overall.

It also makes obvious the somewhat untoward behaviour of that code in terms of
input sanitisation - which while it doesn't fix any problems, at least makes
it clear where they are for future attention.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>