Skip to content

Commit 25e8334

Browse files
committed
Added a check for duplicate Yang model names after xym extraction. This prevents running pyang and yanglint on one module, moving it to the module libs, and then failing to run the checks on a second module with the same name, because the file has been moved after the first check.
- Legacy-Id: 13770
1 parent 1063a74 commit 25e8334

1 file changed

Lines changed: 45 additions & 37 deletions

File tree

ietf/submit/checkers.py

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ def check_file_txt(self, path):
171171
if not re.search(model_name_re, m):
172172
code += 1
173173
err += "Error: Bad extracted model name: '%s'\n" % m
174+
if len(set(model_list)) != len(model_list):
175+
code += 1
176+
err += "Error: Multiple models with the same name:\n %s\n" % ("\n ".join(model_list))
174177

175178
command = "xym"
176179
cmd_version = VersionInfo.objects.get(command=command).version
@@ -185,7 +188,7 @@ def check_file_txt(self, path):
185188
"items": [],
186189
})
187190

188-
for model in model_list:
191+
for model in set(model_list):
189192
path = os.path.join(workdir, model)
190193
message = ""
191194
modpath = ':'.join([
@@ -194,57 +197,62 @@ def check_file_txt(self, path):
194197
settings.SUBMIT_YANG_DRAFT_MODEL_DIR,
195198
settings.SUBMIT_YANG_INVAL_MODEL_DIR,
196199
])
197-
with open(path) as file:
198-
text = file.readlines()
199-
# pyang
200-
cmd_template = settings.SUBMIT_PYANG_COMMAND
201-
command = cmd_template.split()[0]
202-
cmd_version = VersionInfo.objects.get(command=command).version
203-
cmd = cmd_template.format(libs=modpath, model=path)
204-
code, out, err = pipe(cmd)
205-
items = []
206-
if code > 0:
207-
error_lines = err.splitlines()
208-
for line in error_lines:
209-
if line.strip():
210-
try:
211-
fn, lnum, msg = line.split(':', 2)
212-
lnum = int(lnum)
213-
if fn == model and (lnum-1) in range(len(text)):
214-
line = text[lnum-1].rstrip()
215-
else:
216-
line = None
217-
items.append((lnum, line, msg))
218-
if 'error: ' in msg:
219-
errors += 1
220-
if 'warning: ' in msg:
221-
warnings += 1
222-
except ValueError:
223-
pass
224-
#passed = passed and code == 0 # For the submission tool. Yang checks always pass
225-
message += "%s: %s:\n%s\n" % (cmd_version, cmd_template, out+"No validation errors\n" if code == 0 else err)
226-
227-
# yanglint
228-
if settings.SUBMIT_YANGLINT_COMMAND:
229-
cmd_template = settings.SUBMIT_YANGLINT_COMMAND
200+
if os.path.exists(path):
201+
with open(path) as file:
202+
text = file.readlines()
203+
# pyang
204+
cmd_template = settings.SUBMIT_PYANG_COMMAND
230205
command = cmd_template.split()[0]
231206
cmd_version = VersionInfo.objects.get(command=command).version
232-
cmd = cmd_template.format(model=path, rfclib=settings.SUBMIT_YANG_RFC_MODEL_DIR, draftlib=settings.SUBMIT_YANG_DRAFT_MODEL_DIR, tmplib=workdir)
207+
cmd = cmd_template.format(libs=modpath, model=path)
233208
code, out, err = pipe(cmd)
209+
items = []
234210
if code > 0:
235211
error_lines = err.splitlines()
236212
for line in error_lines:
237213
if line.strip():
238214
try:
239-
if 'err : ' in line:
215+
fn, lnum, msg = line.split(':', 2)
216+
lnum = int(lnum)
217+
if fn == model and (lnum-1) in range(len(text)):
218+
line = text[lnum-1].rstrip()
219+
else:
220+
line = None
221+
items.append((lnum, line, msg))
222+
if 'error: ' in msg:
240223
errors += 1
241-
if 'warn: ' in line:
224+
if 'warning: ' in msg:
242225
warnings += 1
243226
except ValueError:
244227
pass
245228
#passed = passed and code == 0 # For the submission tool. Yang checks always pass
246229
message += "%s: %s:\n%s\n" % (cmd_version, cmd_template, out+"No validation errors\n" if code == 0 else err)
247230

231+
# yanglint
232+
if settings.SUBMIT_YANGLINT_COMMAND:
233+
cmd_template = settings.SUBMIT_YANGLINT_COMMAND
234+
command = cmd_template.split()[0]
235+
cmd_version = VersionInfo.objects.get(command=command).version
236+
cmd = cmd_template.format(model=path, rfclib=settings.SUBMIT_YANG_RFC_MODEL_DIR, draftlib=settings.SUBMIT_YANG_DRAFT_MODEL_DIR, tmplib=workdir)
237+
code, out, err = pipe(cmd)
238+
if code > 0:
239+
error_lines = err.splitlines()
240+
for line in error_lines:
241+
if line.strip():
242+
try:
243+
if 'err : ' in line:
244+
errors += 1
245+
if 'warn: ' in line:
246+
warnings += 1
247+
except ValueError:
248+
pass
249+
#passed = passed and code == 0 # For the submission tool. Yang checks always pass
250+
message += "%s: %s:\n%s\n" % (cmd_version, cmd_template, out+"No validation errors\n" if code == 0 else err)
251+
else:
252+
errors += 1
253+
message += "No such file: %s\nPossible mismatch between extracted xym file name and returned module name?\n" % (path)
254+
255+
248256
if errors==0 and warnings==0:
249257
dest = os.path.join(settings.SUBMIT_YANG_DRAFT_MODEL_DIR, model)
250258
shutil.move(path, dest)

0 commit comments

Comments
 (0)