From 0494be4d2eda5ba3b84aed5de725aa2934068029 Mon Sep 17 00:00:00 2001 From: Nishes Joshi Date: Thu, 9 Jan 2014 19:10:31 +0100 Subject: [PATCH] Change JSON library from JSON:PP to JSON::XS --- tools/cf-sketch/cf-dc-api.pl | 2 +- tools/cf-sketch/constdata.conf | 268 +++++++++++------------ tools/cf-sketch/perl-lib/DCAPI.pm | 2 +- tools/cf-sketch/perl-lib/DCAPI/Result.pm | 2 +- 4 files changed, 137 insertions(+), 137 deletions(-) diff --git a/tools/cf-sketch/cf-dc-api.pl b/tools/cf-sketch/cf-dc-api.pl index 3e49042b..aeddc04c 100755 --- a/tools/cf-sketch/cf-dc-api.pl +++ b/tools/cf-sketch/cf-dc-api.pl @@ -2,7 +2,7 @@ BEGIN { - $ENV{PERL_JSON_BACKEND} = 'JSON::backportPP'; + $ENV{PERL_JSON_BACKEND} = 'JSON::XS'; if (-l $0) { diff --git a/tools/cf-sketch/constdata.conf b/tools/cf-sketch/constdata.conf index d4afb2f4..ea12b6ed 100644 --- a/tools/cf-sketch/constdata.conf +++ b/tools/cf-sketch/constdata.conf @@ -20,7 +20,7 @@ "vmware" ] }, - "DIGITS": { valid_regex: "^[0-9]+$" }, + "DIGITS": { "valid_regex": "^[0-9]+$" }, "HASH_ALGORITHM" : { "description" : "Hash algorithm", "choice" : [ @@ -120,103 +120,103 @@ }, }, - selftests: + "selftests": [ { - name: "deactivate all activations", + "name": "deactivate all activations", - subtests: + "subtests": [ { - command: { deactivate: true }, - expected: { success: true } + "command": { "deactivate": true }, + "expected": { "success": true } }, { - command: { deactivate: true }, - expected: { success: true, data: {} } + "command": { "deactivate": true }, + "expected": { "success": true, "data": {} } }, { - command: { activations: true }, - expected: { success: true, data: { activations: {} } } + "command": { "activations": true }, + "expected": { "success": true, "data": { "activations": {} } } } ], }, { - name: "define strict array validation and test it against some data", + "name": "define strict array validation and test it against some data", - subtests: + "subtests": [ { - command: { undefine_validation: "AWS_S3_VALIDATION" }, - expected: { success: true }, + "command": { "undefine_validation": "AWS_S3_VALIDATION" }, + "expected": { "success": true }, }, { - command: + "command": { - define_validation: + "define_validation": { - AWS_S3_VALIDATION: + "AWS_S3_VALIDATION": { - array_k: ["STRING_NONEMPTY"], - array_v: ["STRING_NONEMPTY"], - array_map_strict: + "array_k": ["STRING_NONEMPTY"], + "array_v": ["STRING_NONEMPTY"], + "array_map_strict": { - security_group: "STRING_NONEMPTY", - block_device_mapping: "STRING_NONEMPTY", - ssh_pub_key: "PATH_ABSOLUTE_UNIX", - netrc: "PATH_ABSOLUTE_UNIX" + "security_group": "STRING_NONEMPTY", + "block_device_mapping": "STRING_NONEMPTY", + "ssh_pub_key": "PATH_ABSOLUTE_UNIX", + "netrc": "PATH_ABSOLUTE_UNIX" }, }, }, }, - expected: { success: true }, + "expected": { "success": true }, }, { - command: { validate: { validation: "AWS_S3_VALIDATION", data: "string me along" } }, - expected: { success: false, errors: ["The 'array_k' validation can't take a scalar_value"], }, + "command": { "validate": { "validation": "AWS_S3_VALIDATION", "data": "string me along" } }, + "expected": { "success": false, "errors": ["The 'array_k' validation can't take a scalar_value"], }, }, { - command: { validate: { validation: "AWS_S3_VALIDATION", data: { security_group: "any group", netrc: [ "an array", "two elements" ] } } }, - expected: { success: false, errors: ["Could not validate any of the allowed array_v types [STRING_NONEMPTY]"] }, + "command": { "validate": { "validation": "AWS_S3_VALIDATION", "data": { "security_group": "any group", "netrc": [ "an array", "two elements" ] } } }, + "expected": { "success": false, "errors": ["Could not validate any of the allowed array_v types [STRING_NONEMPTY]"] }, }, { - command: { validate: { validation: "AWS_S3_VALIDATION", data: { unknown_key: "any thing" } } }, - expected: { success: false, errors: ["The key 'unknown_key' is not valid."] }, + "command": { "validate": { "validation": "AWS_S3_VALIDATION", "data": { "unknown_key": "any thing" } } }, + "expected": { "success": false, "errors": ["The key 'unknown_key' is not valid."] }, }, { - command: { validate: { validation: "AWS_S3_VALIDATION", data: { security_group: "any group", netrc: "/other/path/here", ssh_pub_key: "/the/key/location" } } }, - expected: { success: true, errors: [] } + "command": { "validate": { "validation": "AWS_S3_VALIDATION", "data": { "security_group": "any group", "netrc": "/other/path/here", "ssh_pub_key": "/the/key/location" } } }, + "expected": { "success": true, "errors": [] } }, ], }, { - name: "clear all environments and then define two environments", + "name": "clear all environments and then define two environments", - subtests: + "subtests": [ { - command: { undefine_environment: true }, - expected: { success: true }, + "command": { "undefine_environment": true }, + "expected": { "success": true }, }, { - command: { define_environment: { path_override: { activated: true, test: true, verbose: true, qa: true, path_prefix: "/tmp/contain" } } }, - expected: { success: true, data: { define_environment: { path_override: 1 } } }, + "command": { "define_environment": { "path_override": { "activated": true, "test": true, "verbose": true, "qa": true, "path_prefix": "/tmp/contain" } } }, + "expected": { "success": true, "data": { "define_environment": { "path_override": 1 } } }, }, { - command: { define_environment: { default: { activated: true, test: false, verbose: false } } }, - expected: { success: true, data: { define_environment: { default: 1 } } }, + "command": { "define_environment": { "default": { "activated": true, "test": false, "verbose": false } } }, + "expected": { "success": true, "data": { "define_environment": { "default": 1 } } }, }, { - command: { environments: true }, - expected: + "command": { "environments": true }, + "expected": { - success: true, - data: + "success": true, + "data": { - environments: + "environments": { - path_override: { activated: "1", test: "1", verbose: "1", qa: "1", path_prefix: "/tmp/contain" }, - default: { activated: "1", test: "", verbose: "" } + "path_override": { "activated": "1", "test": "1", "verbose": "1", "qa": "1", "path_prefix": "/tmp/contain" }, + "default": { "activated": "1", "test": "", "verbose": "" } } } } @@ -224,134 +224,134 @@ ], }, { - name: "install and activate two sketches", + "name": "install and activate two sketches", - subtests: + "subtests": [ { - command: {define_environment: { testing: { activated: true, test: true, verbose: true } } }, - expected: { success: true, data: { define_environment: { testing: 1 } } }, + "command": {"define_environment": { "testing": { "activated": true, "test": true, "verbose": true } } }, + "expected": { "success": true, "data": { "define_environment": { "testing": 1 } } }, }, { - command: { install: { sketch: "Packages::installed", force: true } }, - expected: { success: true }, + "command": { "install": { "sketch": "Packages::installed", "force": true } }, + "expected": { "success": true }, }, { - command: { install: { sketch: "Packages::installed" } }, - expected: { success: true, log: ["Sketch Packages::installed is already in target repo; you must uninstall it first"] }, + "command": { "install": { "sketch": "Packages::installed" } }, + "expected": { "success": true, "log": ["Sketch Packages::installed is already in target repo; you must uninstall it first"] }, }, { - command: { install: { sketch: "VCS::vcs_mirror", force: true } }, - expected: { success: true }, + "command": { "install": { "sketch": "VCS::vcs_mirror", "force": true } }, + "expected": { "success": true }, }, { - command: + "command": { - define: + "define": { - vcs_base: { "VCS::vcs_mirror": + "vcs_base": { "VCS::vcs_mirror": { - options: + "options": { - parent_dir: + "parent_dir": { - owner: { function: "getenv", args: ["LOGNAME", "128"] }, - group: { function: "getenv", args: ["LOGNAME", "128"] }, - perms: "755", - ensure: true + "owner": { "function": "getenv", "args": ["LOGNAME", "128"] }, + "group": { "function": "getenv", "args": ["LOGNAME", "128"] }, + "perms": "755", + "ensure": true }, - nowipe: true, - vcs: + "nowipe": true, + "vcs": { - runas: { function: "getenv", args: ["LOGNAME", "128"] }, - umask: "000" + "runas": { "function": "getenv", "args": ["LOGNAME", "128"] }, + "umask": "000" } } } }, }, }, - expected: { success: true, data: { define: { vcs_base: 1 } } }, + "expected": { "success": true, "data": { "define": { "vcs_base": 1 } } }, }, { - command: + "command": { - define: + "define": { - git_mirror_core: { "VCS::vcs_mirror": + "git_mirror_core": { "VCS::vcs_mirror": { - vcs: "/usr/bin/git", - path: "/tmp/q/cfengine-core", - branch: "master", - origin: "https://github.com/cfengine/core.git" + "vcs": "/usr/bin/git", + "path": "/tmp/q/cfengine-core", + "branch": "master", + "origin": "https://github.com/cfengine/core.git" }, }, }, }, - expected: { success: true, data: { define: { git_mirror_core: 1 } } }, + "expected": { "success": true, "data": { "define": { "git_mirror_core": 1 } } }, }, { - command: + "command": { - define: + "define": { - svn_mirror_thrift: { "VCS::vcs_mirror": + "svn_mirror_thrift": { "VCS::vcs_mirror": { - vcs: "/usr/bin/svn", - path: "/tmp/thrift-perl-lib", - branch: "", - origin: "http://svn.apache.org/repos/asf/thrift/attic/trunk/lib/perl", - options: { parent_dir: { ensure: false } }, + "vcs": "/usr/bin/svn", + "path": "/tmp/thrift-perl-lib", + "branch": "", + "origin": "http://svn.apache.org/repos/asf/thrift/attic/trunk/lib/perl", + "options": { "parent_dir": { "ensure": false } }, }, }, } }, - expected: { success: true, data: { define: { svn_mirror_thrift: 1 } } }, + "expected": { "success": true, "data": { "define": { "svn_mirror_thrift": 1 } } }, }, { - command: + "command": { - deactivate: true, + "deactivate": true, }, - expected: { success: true }, + "expected": { "success": true }, }, { - command: + "command": { - activate: { "VCS::vcs_mirror": { environment: "testing", params: [ "vcs_base", "git_mirror_core" ] } }, + "activate": { "VCS::vcs_mirror": { "environment": "testing", "params": [ "vcs_base", "git_mirror_core" ] } }, }, - expected: + "expected": { - success: true, - data: + "success": true, + "data": { - activate: + "activate": { "VCS::vcs_mirror": { - params: ["vcs_base", "git_mirror_core"], - environment: "testing" + "params": ["vcs_base", "git_mirror_core"], + "environment": "testing" } } }, }, }, { - command: + "command": { - activate: { "VCS::vcs_mirror": { environment: "testing", params: [ "vcs_base", "svn_mirror_thrift" ] } }, + "activate": { "VCS::vcs_mirror": { "environment": "testing", "params": [ "vcs_base", "svn_mirror_thrift" ] } }, }, - expected: + "expected": { - success: true, - data: + "success": true, + "data": { - activate: + "activate": { "VCS::vcs_mirror": { - params: ["vcs_base", "svn_mirror_thrift"], - environment: "testing" + "params": ["vcs_base", "svn_mirror_thrift"], + "environment": "testing" } } }, @@ -360,62 +360,62 @@ ], }, { - name: "search and list sketches, existing and missing", + "name": "search and list sketches, existing and missing", - subtests: + "subtests": [ { - command: { search: "VCS::vcs_mirror", count_only: true }, - expected: { success: true, data: { count: 1 } }, + "command": { "search": "VCS::vcs_mirror", "count_only": true }, + "expected": { "success": true, "data": { "count": 1 } }, }, { - command: { install: { sketch: "VCS::vcs_mirror", force: true } }, - expected: { success: true }, + "command": { "install": { "sketch": "VCS::vcs_mirror", "force": true } }, + "expected": { "success": true }, }, { - command: { list: "VCS::vcs_mirror", count_only: true }, - expected: { success: true, data: { count: 1 } }, + "command": { "list": "VCS::vcs_mirror", "count_only": true }, + "expected": { "success": true, "data": { "count": 1 } }, }, { - command: { search: "VCS::vcs_mirror::nosuchmatch", count_only: true }, - expected: { success: true, data: { count: 0 } }, + "command": { "search": "VCS::vcs_mirror::nosuchmatch", "count_only": true }, + "expected": { "success": true, "data": { "count": 0 } }, }, { - command: { search: "VCS::vcs_mirror::nosuchmatch", count_only: true }, - expected: { success: true, data: { count: 0 } }, + "command": { "search": "VCS::vcs_mirror_", "count_only": true }, + "expected": { "success": true, "data": { "count": 0 } }, }, { - command: { list: "VCS::vcs_mirror", describe: "README" }, - expected: { success: true }, - expected_match: "Check out and update a VCS repository", + "command": { "list": "VCS::vcs_mirror", "describe": "README" }, + "expected": { "success": true }, + "expected_match": "Check out and update a VCS repository", }, { - command: { list: "VCS::vcs_mirror", describe: 1 }, - expected: { success: true }, - expected_match: "Sample parameters to use Git to check out", + "command": { "list": "VCS::vcs_mirror", "describe": 1 }, + "expected": { "success": true }, + "expected_match": "Sample parameters to use Git to check out", }, ], }, { - name: "generate runfile", + "name": "generate runfile", - subtests: + "subtests": [ { - command: { regenerate: { } }, - expected: { success: true, data: { } }, + "command": { "regenerate": { } }, + "expected": { "success": true, "data": { } }, }, ], }, { - name: "generate cfsketches.json", + "name": "generate cfsketches.json", - subtests: + "subtests": [ { - command: { regenerate_index: "/tmp/nosuchdir" }, - expected: { success: false, data: { } }, + "command": { "regenerate_index": "/tmp/nosuchdir" }, + "expected": { "success": false, "data": { } }, }, ], }, diff --git a/tools/cf-sketch/perl-lib/DCAPI.pm b/tools/cf-sketch/perl-lib/DCAPI.pm index 08f09a58..1e009c5f 100644 --- a/tools/cf-sketch/perl-lib/DCAPI.pm +++ b/tools/cf-sketch/perl-lib/DCAPI.pm @@ -14,7 +14,7 @@ use DCAPI::Result; use DCAPI::Validation; use constant API_VERSION => '0.0.1'; -use constant CODER => JSON->new()->allow_barekey()->relaxed()->utf8()->allow_nonref(); +use constant CODER => JSON->new()->relaxed()->utf8()->allow_nonref(); use constant CAN_CODER => JSON->new()->canonical()->utf8()->allow_nonref(); use Mo qw/build default builder coerce is required/; diff --git a/tools/cf-sketch/perl-lib/DCAPI/Result.pm b/tools/cf-sketch/perl-lib/DCAPI/Result.pm index 769bb505..6095fa6a 100644 --- a/tools/cf-sketch/perl-lib/DCAPI/Result.pm +++ b/tools/cf-sketch/perl-lib/DCAPI/Result.pm @@ -25,7 +25,7 @@ sub data_dump return { $top_key => { - success => ($self->success() ? JSON::PP::true : JSON::PP::false), + success => ($self->success() ? JSON::true : JSON::false), warnings => $self->warnings(), errors => $self->errors(), log => $self->log(),