-
Notifications
You must be signed in to change notification settings - Fork 299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add snabb config test functionality #1339
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,37 +73,58 @@ function parse_command_line(args, opts) | |
function handlers.s(arg) ret.schema_name = arg end | ||
function handlers.r(arg) ret.revision_date = arg end | ||
function handlers.c(arg) ret.socket = arg end | ||
function handlers.v(arg) ret.verbose = true end | ||
function handlers.f(arg) | ||
assert(arg == "yang" or arg == "xpath", "Not valid output format") | ||
ret.format = arg | ||
end | ||
handlers['print-default'] = function () | ||
ret.print_default = true | ||
end | ||
args = lib.dogetopt(args, handlers, "hs:r:c:f:", | ||
{help="h", ['schema-name']="s", schema="s", | ||
args = lib.dogetopt(args, handlers, "hvs:r:c:f:", | ||
{help="h", verbose="v", ['schema-name']="s", schema="s", | ||
['revision-date']="r", revision="r", socket="c", | ||
['print-default']=0, format="f"}) | ||
|
||
if #args == 0 then err() end | ||
ret.instance_id = table.remove(args, 1) | ||
local descr = call_leader(ret.instance_id, 'describe', {}) | ||
if not ret.schema_name then | ||
if opts.require_schema then err("missing --schema arg") end | ||
ret.schema_name = descr.default_schema | ||
|
||
if opts.command == 'test' then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dunno, I think since there's these two ways to deal with the schema -- either as provided by the user or as received from the remote -- I think it makes sense to move all argument handling to |
||
if #args > 1 then | ||
ret.instance_id = table.remove(args, 1) | ||
end | ||
else | ||
ret.instance_id = table.remove(args, 1) | ||
end | ||
require('lib.yang.schema').set_default_capabilities(descr.capability) | ||
|
||
-- If instance ID was given, then load description from instance | ||
if ret.instance_id then | ||
local descr = call_leader(ret.instance_id, 'describe', {}) | ||
-- If schema name was not explicitly passed, load from instance | ||
if not ret.schema_name then | ||
if opts.require_schema then err("missing --schema arg") end | ||
ret.schema_name = descr.default_schema | ||
end | ||
require('lib.yang.schema').set_default_capabilities(descr.capability) | ||
end | ||
|
||
if not pcall(yang.load_schema_by_name, ret.schema_name) then | ||
local response = call_leader( | ||
ret.instance_id, 'get-schema', | ||
{schema=ret.schema_name, revision=ret.revision_date}) | ||
assert(not response.error, response.error) | ||
yang.add_schema(response.source, ret.schema_name) | ||
local schema_file = S.lstat(ret.schema_name) | ||
if schema_file and schema_file.isreg then | ||
ret.schema_name = yang.add_schema_file(ret.schema_name) | ||
else | ||
if not ret.instance_id then err("no schema loaded and instance id not given") end | ||
local response = call_leader( | ||
ret.instance_id, 'get-schema', | ||
{schema=ret.schema_name, revision=ret.revision_date}) | ||
assert(not response.error, response.error) | ||
yang.add_schema(response.source, ret.schema_name) | ||
end | ||
end | ||
if opts.with_config_file then | ||
if #args == 0 then err("missing config file argument") end | ||
local file = table.remove(args, 1) | ||
local opts = {schema_name=ret.schema_name, | ||
revision_date=ret.revision_date} | ||
revision_date=ret.revision_date, verbose=ret.verbose} | ||
ret.config_file = file | ||
ret.config = yang.load_configuration(file, opts) | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Usage: | ||
snabb config test [OPTIONS] [ID] FILE | ||
|
||
Available options: | ||
-s SCHEMA-NAME-OR-FILE-PATH | ||
--schema SCHEMA-NAME-OR-FILE-PATH | ||
--schema-name SCHEMA-NAME | ||
|
||
-r REVISION | ||
--revision REVISION | ||
--revision-date REVISION | ||
|
||
-v | ||
--verbose | ||
|
||
-h | ||
--help | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Usage: | ||
snabb config test [OPTIONS] [ID] FILE | ||
|
||
Available options: | ||
-s SCHEMA-NAME-OR-FILE-PATH | ||
--schema SCHEMA-NAME-OR-FILE-PATH | ||
--schema-name SCHEMA-NAME | ||
|
||
-r REVISION | ||
--revision REVISION | ||
--revision-date REVISION | ||
|
||
-v | ||
--verbose | ||
|
||
-h | ||
--help | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
-- Use of this source code is governed by the Apache 2.0 license; see COPYING. | ||
module(..., package.seeall) | ||
|
||
local yang = require("lib.yang.yang") | ||
local common = require("program.config.common") | ||
|
||
function run(args) | ||
local opts = { command='test', with_config_file=true, is_config = false} | ||
local ret, args = common.parse_command_line(args, opts) | ||
|
||
yang.print_config_for_schema_by_name(ret.schema_name, ret.config, io.stdout) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to change the default above at line 34 to
verbose={default=true}
, to keep the current behavior for existing callers.