Disallow empty key name for node metadata

The key in {"": "blank"} should not be allowed in any commands (e.g. modify-node-metadata) since it is not a meaningful attribute.

Fixes https://tickets.puppetlabs.com/browse/RAZOR-121
Disallow empty key names in hash

The key in {"": "blank"} should not be allowed in any commands (e.g. modify-node-metadata) since it is not a meaningful attribute. This commit includes cases where Array holds a Hash. Also including a fix for a few error messages that reference undefined variables.

Fixes https://tickets.puppetlabs.com/browse/RAZOR-121
Fixing spec tests

Fixes https://tickets.puppetlabs.com/browse/RAZOR-121
* Rakefile(db:nuke): add IF EXISTS to DROP TYPE statements

During development, it's easy to get the database in a wonky, half-created
state when things go wrong; without IF EXISTS db:nuke will fail if the type
it is trying to drop is not there.
Schema and model class for the command log

The command log will allow us to both store an audit trail of commands
issues against the server and use those commands to report status and
errors of background jobs connected to specific commands.
Add logic for creating (starting) and finishing commands

Razor::Data::Command.start is a convenience wrapper around creating a
command; store is a convenience around setting a command's status and
finished_at if needed.
Remove trailing whitespace

No functional change
Have all commands add an entry to the command log

Any successfully submitted command will now create an entry in the command
log, and the command specs check for that. For now, all commands will
pretend to be synchronous, and report a status of 'finished' when the
corresponding request ends.
Update command status for background tasks

For ISO import, we thread a command object through to the message
processor, tkaing care to pass it along to each stage of the import
process. The import process then updates the status of the command, in
particular marks it as 'running' as soon as it starts working on it, and
marks it as 'finished' when the last step of the import saga is done.

Most of the error reporting is done by our message processor - that is
crude, and better ways to report errors from within the actual processing
is the main reason why we try to pass the command to each stage of the
saga.

We can't demand that all background tasks have a command associated with
it: changing node metadata and tag rules spawn background jobs in
Node.around_save and Tag.around_save, where they do not have access to a
command object, nor does it seem desirable from the user's POV to treat
them as async commands. There may be a case to give the user an indication that the database has settled after these changes, but that is unlikely to change the general situation that we'll have background work that is, to the user, part of their command, and some that isn't.

The way the command is threaded through all over the place is a bit clumsy;
an alternative would be to have the messaging plugin define a 'command'
method that returns the command associated with the operation if there is
one, and methods that are called during async processing can access it that
way to e.g. report errors or update the status
Add a command collection to the API

Provide the standard means for listing all commands (in descending order of
submission) and to get the details about a specific command.

This commit finishes the fix for https://tickets.puppetlabs.com/browse/RAZOR-7
* bin/razor-admin (reset-database): only drop types if they exist

reset-database would fail if one of the types it is trying to drop do not
exist. We now use 'DROP TYOE IF EXISTS' to avoid that.

This problem was introduced in commit e0b12a19
Add "friendly_name" to all Razor::Data classes

This adds a method to all Razor::Data classes to return a friendly name for
the type.  This can be used to talk about the object in, for example, error
messages elsewhere.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Improve reporting of validation errors

This extends the validation framework to pass the context of the current
attribute through the system, and report using it.  This means that we will
see messages like "broker.name must refer to an ..." rather than "name must
refer to an ..." emitted.

That should help much more effectively understand where the problem was
located, rather than guessing at one of the many identically named attributes
it could possibly match.

https://tickets.puppetlabs.com/browse/RAZOR-191

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Implement a 'size' validation check for attributes

This implement a check to validate the size of an attribute; it only makes
sense for string, object/map, and array types.  It uses a range to verify the
minimum and maximum size of the object in characters, or contained entities.

This, in turn, supports verification that inappropriate length entities are
not passed in our data.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Apply a size check to tag names, rejecting zero-length names

This applies the size validation check to tag names, to ensure that they are a
legal length matching our definition in the database.  That is, between one
and infinity characters long.

https://tickets.puppetlabs.com/browse/RAZOR-137
Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Apply size checks to all other commands, where relevant

This commit whips through all the other commands and applies a size check to
string arguments -- matching our database constraints.  This kind of shows how
incoherent those constraints are, varying wildly between infinite and
constrained, but they are our current constraints.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Add user help to all commands

This adds user-facing help to all commands, based on the existing
documentation.  This will be automatically exposed to the client through the
new command metadata API, and will permit this information to be shared with
the client automatically -- as well as future updates to help about the
commands as we improve the software.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Detect and report out-of-sync migrations via the API

When the Razor code and database migrations are out of sync, significant
problems can occur.  This adds code to detect when this situation has shown
up, report it, and refuse service to all callers.

For the client this will result in an error message to the user, including
instructions on how to fix the problem.

For MK images, etc, it will result in an error that they will observe and
retry in the near future; this is the best we can do, since we can't be sure
that the changes have not altered the behaviour they should undertake.

https://tickets.puppetlabs.com/browse/RAZOR-158
Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Add `locales` data and template to packages

The locales directory will be shipped, with both the PO file template, and any
PO files that we have included that support translations.  This supports our
translation efforts.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Fixing `create-repo` documentation