Skip to content

Commit 38b0b2c

Browse files
jennifer-richardsNGPixel
authored andcommitted
feat: get tool versions without VersionInfo model (ietf-tools#7393) (ietf-tools#7403)
* chore: remove update_external_command_info call * feat: get tool version without VersionInfo * chore: Remove VersionInfo model * chore: Migration to remove VersionInfo * fix: handle errors better; ignore stderr
1 parent b744f2b commit 38b0b2c

12 files changed

Lines changed: 66 additions & 137 deletions

File tree

bin/daily

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ $DTDIR/bin/hourly
2424
source $DTDIR/env/bin/activate
2525

2626

27-
# Update our information about the current version of some commands we use
28-
$DTDIR/ietf/manage.py update_external_command_info
29-
3027
# Get IANA-registered yang models
3128
#YANG_IANA_DIR=$(python -c 'import ietf.settings; print ietf.settings.SUBMIT_YANG_IANA_MODEL_DIR')
3229
# Hardcode the rsync target to avoid any unwanted deletes:

bin/dump-to-names-json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
set -x
1212
ietf/manage.py dumpdata --indent 1 doc.State doc.BallotType doc.StateType \
13-
mailtrigger.MailTrigger mailtrigger.Recipient name utils.VersionInfo \
13+
mailtrigger.MailTrigger mailtrigger.Recipient name \
1414
group.GroupFeatures stats.CountryAlias dbtemplate.DBTemplate \
1515
| jq --sort-keys "sort_by(.model, .pk)" \
1616
| jq '[.[] | select(.model!="dbtemplate.dbtemplate" or .pk==354)]' > ietf/name/fixtures/names.json

ietf/name/fixtures/names.json

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16789,49 +16789,5 @@
1678916789
},
1679016790
"model": "stats.countryalias",
1679116791
"pk": 303
16792-
},
16793-
{
16794-
"fields": {
16795-
"command": "xym",
16796-
"switch": "--version",
16797-
"time": "2024-03-21T07:06:23.405Z",
16798-
"used": true,
16799-
"version": "xym 0.7.0"
16800-
},
16801-
"model": "utils.versioninfo",
16802-
"pk": 1
16803-
},
16804-
{
16805-
"fields": {
16806-
"command": "pyang",
16807-
"switch": "--version",
16808-
"time": "2024-03-21T07:06:23.755Z",
16809-
"used": true,
16810-
"version": "pyang 2.6.0"
16811-
},
16812-
"model": "utils.versioninfo",
16813-
"pk": 2
16814-
},
16815-
{
16816-
"fields": {
16817-
"command": "yanglint",
16818-
"switch": "--version",
16819-
"time": "2024-03-21T07:06:23.773Z",
16820-
"used": true,
16821-
"version": "yanglint SO 1.9.2"
16822-
},
16823-
"model": "utils.versioninfo",
16824-
"pk": 3
16825-
},
16826-
{
16827-
"fields": {
16828-
"command": "xml2rfc",
16829-
"switch": "--version",
16830-
"time": "2024-03-21T07:06:24.609Z",
16831-
"used": true,
16832-
"version": "xml2rfc 3.20.1"
16833-
},
16834-
"model": "utils.versioninfo",
16835-
"pk": 4
1683616792
}
1683716793
]

ietf/name/management/commands/generate_name_fixture.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ def output(seq):
7777
from ietf.mailtrigger.models import MailTrigger, Recipient
7878
from ietf.meeting.models import BusinessConstraint
7979
from ietf.stats.models import CountryAlias
80-
from ietf.utils.models import VersionInfo
8180

8281
# Grab all ietf.name.models
8382
for n in dir(ietf.name.models):
@@ -87,7 +86,7 @@ def output(seq):
8786
model_objects[model_name(item)] = list(item.objects.all().order_by('pk'))
8887

8988
for m in ( BallotType, State, StateType, GroupFeatures, MailTrigger, Recipient,
90-
CountryAlias, VersionInfo, BusinessConstraint ):
89+
CountryAlias, BusinessConstraint ):
9190
model_objects[model_name(m)] = list(m.objects.all().order_by('pk'))
9291

9392
for m in ( DBTemplate, ):

ietf/submit/checkers.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
import debug # pyflakes:ignore
1616

17+
from ietf.utils import tool_version
1718
from ietf.utils.log import log, assertion
18-
from ietf.utils.models import VersionInfo
1919
from ietf.utils.pipe import pipe
2020
from ietf.utils.test_runner import set_coverage_checking
2121

@@ -177,8 +177,10 @@ def check_file_txt(self, path):
177177
model_list = list(set(model_list))
178178

179179
command = "xym"
180-
cmd_version = VersionInfo.objects.get(command=command).version
181-
message = "%s:\n%s\n\n" % (cmd_version, out.replace('\n\n','\n').strip() if code == 0 else err)
180+
message = "{version}:\n{output}\n\n".format(
181+
version=tool_version[command],
182+
output=out.replace('\n\n', '\n').strip() if code == 0 else err,
183+
)
182184

183185
results.append({
184186
"name": name,
@@ -209,7 +211,6 @@ def check_file_txt(self, path):
209211
# pyang
210212
cmd_template = settings.SUBMIT_PYANG_COMMAND
211213
command = [ w for w in cmd_template.split() if not '=' in w ][0]
212-
cmd_version = VersionInfo.objects.get(command=command).version
213214
cmd = cmd_template.format(libs=modpath, model=path)
214215
venv_path = os.environ.get('VIRTUAL_ENV') or os.path.join(os.getcwd(), 'env')
215216
venv_bin = os.path.join(venv_path, 'bin')
@@ -238,14 +239,17 @@ def check_file_txt(self, path):
238239
except ValueError:
239240
pass
240241
#passed = passed and code == 0 # For the submission tool. Yang checks always pass
241-
message += "%s: %s:\n%s\n" % (cmd_version, cmd_template, out+"No validation errors\n" if (code == 0 and len(err) == 0) else out+err)
242+
message += "{version}: {template}:\n{output}\n".format(
243+
version=tool_version[command],
244+
template=cmd_template,
245+
output=out + "No validation errors\n" if (code == 0 and len(err) == 0) else out + err,
246+
)
242247

243248
# yanglint
244249
set_coverage_checking(False) # we can't count the following as it may or may not be run, depending on setup
245250
if settings.SUBMIT_YANGLINT_COMMAND and os.path.exists(settings.YANGLINT_BINARY):
246251
cmd_template = settings.SUBMIT_YANGLINT_COMMAND
247252
command = [ w for w in cmd_template.split() if not '=' in w ][0]
248-
cmd_version = VersionInfo.objects.get(command=command).version
249253
cmd = cmd_template.format(model=path, rfclib=settings.SUBMIT_YANG_RFC_MODEL_DIR, tmplib=workdir,
250254
draftlib=settings.SUBMIT_YANG_DRAFT_MODEL_DIR, ianalib=settings.SUBMIT_YANG_IANA_MODEL_DIR,
251255
cataloglib=settings.SUBMIT_YANG_CATALOG_MODEL_DIR, )
@@ -264,7 +268,11 @@ def check_file_txt(self, path):
264268
except ValueError:
265269
pass
266270
#passed = passed and code == 0 # For the submission tool. Yang checks always pass
267-
message += "%s: %s:\n%s\n" % (cmd_version, cmd_template, out+"No validation errors\n" if (code == 0 and len(err) == 0) else out+err)
271+
message += "{version}: {template}:\n{output}\n".format(
272+
version=tool_version[command],
273+
template=cmd_template,
274+
output=out + "No validation errors\n" if (code == 0 and len(err) == 0) else out + err,
275+
)
268276
set_coverage_checking(True)
269277
else:
270278
errors += 1
@@ -293,4 +301,4 @@ def check_file_txt(self, path):
293301
items = [ e for res in results for e in res["items"] ]
294302
info['items'] = items
295303
info['code']['yang'] = model_list
296-
return passed, message, errors, warnings, info
304+
return passed, message, errors, warnings, info

ietf/submit/tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@
4949
from ietf.submit.forms import SubmissionBaseUploadForm, SubmissionAutoUploadForm
5050
from ietf.submit.models import Submission, Preapproval, SubmissionExtResource
5151
from ietf.submit.tasks import cancel_stale_submissions, process_and_accept_uploaded_submission_task
52+
from ietf.utils import tool_version
5253
from ietf.utils.accesstoken import generate_access_token
5354
from ietf.utils.mail import outbox, get_payload_text
54-
from ietf.utils.models import VersionInfo
5555
from ietf.utils.test_utils import login_testing_unauthorized, TestCase
5656
from ietf.utils.timezone import date_today
5757
from ietf.utils.draft import PlaintextDraft
@@ -1854,7 +1854,7 @@ def test_submit_invalid_yang(self):
18541854
#
18551855
m = q('#yang-validation-message').text()
18561856
for command in ['xym', 'pyang', 'yanglint']:
1857-
version = VersionInfo.objects.get(command=command).version
1857+
version = tool_version[command]
18581858
if command != 'yanglint' or (settings.SUBMIT_YANGLINT_COMMAND and os.path.exists(settings.YANGLINT_BINARY)):
18591859
self.assertIn(version, m)
18601860
self.assertIn("draft-yang-testing-invalid-00.txt", m)

ietf/utils/__init__.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,29 @@
1-
# Copyright The IETF Trust 2007, All Rights Reserved
1+
# Copyright The IETF Trust 2007-2024, All Rights Reserved
2+
import subprocess
3+
4+
5+
class _ToolVersionManager:
6+
_known = [
7+
"pyang",
8+
"xml2rfc",
9+
"xym",
10+
"yanglint",
11+
]
12+
_versions = dict()
13+
14+
def __getitem__(self, item):
15+
if item not in self._known:
16+
return "Unknown"
17+
elif item not in self._versions:
18+
try:
19+
self._versions[item] = subprocess.run(
20+
[item, "--version"],
21+
capture_output=True,
22+
check=True,
23+
).stdout.decode().strip()
24+
except subprocess.CalledProcessError:
25+
return "Unknown"
26+
return self._versions[item]
27+
28+
29+
tool_version = _ToolVersionManager()

ietf/utils/admin.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
from django.contrib import admin
66
from django.utils.encoding import force_str
77

8-
from ietf.utils.models import VersionInfo
9-
108
def name(obj):
119
if hasattr(obj, 'abbrev'):
1210
return obj.abbrev()
@@ -58,8 +56,3 @@ class DumpInfoAdmin(admin.ModelAdmin):
5856
list_display = ['date', 'host', 'tz']
5957
list_filter = ['date']
6058
admin.site.register(DumpInfo, DumpInfoAdmin)
61-
62-
class VersionInfoAdmin(admin.ModelAdmin):
63-
list_display = ['command', 'switch', 'version', 'time', ]
64-
admin.site.register(VersionInfo, VersionInfoAdmin)
65-

ietf/utils/management/commands/update_external_command_info.py

Lines changed: 0 additions & 41 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Generated by Django 4.2.11 on 2024-05-03 21:03
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("utils", "0001_initial"),
10+
]
11+
12+
operations = [
13+
migrations.DeleteModel(
14+
name="VersionInfo",
15+
),
16+
]

0 commit comments

Comments
 (0)