Skip to content

Commit

Permalink
Fix IEEE module name prefix expectation
Browse files Browse the repository at this point in the history
This addresses #893

Signed-off-by: Siddharth Sharma <[email protected]>
  • Loading branch information
esmasth authored and mbj4668 committed May 12, 2024
1 parent 25f69e8 commit 4f271ff
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 2 deletions.
17 changes: 15 additions & 2 deletions pyang/plugins/ieee.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def pyang_plugin_init():
class IEEEPlugin(lint.LintPlugin):
def __init__(self):
lint.LintPlugin.__init__(self)
self.modulename_prefixes = ['ieee']

def add_opts(self, optparser):
optlist = [
Expand All @@ -34,15 +33,29 @@ def setup_ctx(self, ctx):
return
self._setup_ctx(ctx)

error.add_error_code(
'IEEE_BAD_MODULENAME_PREFIX', 4,
'the module name prefix should be of the form '
'{IEEE committee}- e.g., ieee802-')

error.add_error_code(
'IEEE_BAD_NAMESPACE_VALUE', 4,
'the namespace should be on the form '
'the namespace should be of the form '
'urn:ieee:std:{IEEE standard designation}:yang:%s')

statements.add_validation_fun(
'grammar', ['module', 'submodule'],
lambda ctx, s: self.v_chk_module_name(ctx, s))

statements.add_validation_fun(
'grammar', ['namespace'],
lambda ctx, s: self.v_chk_namespace(ctx, s))

def v_chk_module_name(self, ctx, stmt):
r = '^ieee[0-9]+-.*'
if re.match(r, stmt.arg) is None:
err_add(ctx.errors, stmt.pos, 'IEEE_BAD_MODULENAME_PREFIX', ())

def v_chk_namespace(self, ctx, stmt):
r = 'urn:ieee:std:.*:yang:' + stmt.i_module.arg
if re.match(r, stmt.arg) is None:
Expand Down
15 changes: 15 additions & 0 deletions test/plugins/test_ieee/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
test: test1 test2 test3 test4

# Baseline test that a module following 3gpp guidelines is OK
test1:
$(PYANG) --ieee ieee802-dot1q-correct.yang

test2:
$(PYANG) --ieee ieee-802-dot1q-incorrect-name.yang 2>&1 | diff ieee-802-dot1q-incorrect-name.expect -

test3:
$(PYANG) --ieee ieee802-dot1q-incorrect-namespace.yang 2>&1 | diff ieee802-dot1q-incorrect-namespace.expect -

# Check help text
test4:
$(PYANG) -h | grep " --ieee Validate the module(s) according to IEEE rules."
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ieee-802-dot1q-incorrect-name.yang:1: warning: the module name prefix should be of the form {IEEE committee}- e.g., ieee802-
29 changes: 29 additions & 0 deletions test/plugins/test_ieee/ieee-802-dot1q-incorrect-name.yang
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module ieee-802-dot1q-incorrect-name {
yang-version 1.1;
namespace "urn:ieee:std:802.1Q:yang:ieee-802-dot1q-incorrect-name";
prefix dot1q-incorrect-name;

organization
"Institute of Electrical and Electronics Engineers";

contact
"WG-URL: http://www.ieee802.org/1
WG-EMail: [email protected]
Contact: IEEE 802.1 Working Group Chair
Postal: C/O IEEE 802.1 Working Group
IEEE Standards Association
445 Hoes Lane
Piscataway
NJ 08854
USA
E-mail: [email protected]";

description
"ieee-802-dot1q-incorrect-name";

revision 2024-05-10 {
reference "ieee-802-dot1q-incorrect-name";
}
}
29 changes: 29 additions & 0 deletions test/plugins/test_ieee/ieee802-dot1q-correct.yang
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module ieee802-dot1q-correct {
yang-version 1.1;
namespace "urn:ieee:std:802.1Q:yang:ieee802-dot1q-correct";
prefix dot1q-correct;

organization
"Institute of Electrical and Electronics Engineers";

contact
"WG-URL: http://www.ieee802.org/1
WG-EMail: [email protected]
Contact: IEEE 802.1 Working Group Chair
Postal: C/O IEEE 802.1 Working Group
IEEE Standards Association
445 Hoes Lane
Piscataway
NJ 08854
USA
E-mail: [email protected]";

description
"ieee802-dot1q-correct";

revision 2024-05-10 {
reference "ieee802-dot1q-correct";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ieee802-dot1q-incorrect-namespace.yang:3: warning: the namespace should be of the form urn:ieee:std:{IEEE standard designation}:yang:ieee802-dot1q-incorrect-namespace
29 changes: 29 additions & 0 deletions test/plugins/test_ieee/ieee802-dot1q-incorrect-namespace.yang
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module ieee802-dot1q-incorrect-namespace {
yang-version 1.1;
namespace "urn:ieee:std:802.1Q:yang:ieee802-dot1q-correct-namespace";
prefix dot1q-incorrect-namespace;

organization
"Institute of Electrical and Electronics Engineers";

contact
"WG-URL: http://www.ieee802.org/1
WG-EMail: [email protected]
Contact: IEEE 802.1 Working Group Chair
Postal: C/O IEEE 802.1 Working Group
IEEE Standards Association
445 Hoes Lane
Piscataway
NJ 08854
USA
E-mail: [email protected]";

description
"ieee802-dot1q-incorrect-namespace";

revision 2024-05-10 {
reference "ieee802-dot1q-incorrect-namespace";
}
}

0 comments on commit 4f271ff

Please sign in to comment.