Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion roles/nvidia-dgx-firmware/files/parse_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json

from collections import OrderedDict
from sys import argv
from sys import argv, exit


def return_json(payload):
Expand Down Expand Up @@ -173,6 +173,11 @@ def return_json(payload):
manifest_json = json.loads(line)
except ValueError:
pass

if not isinstance(manifest_json, dict):
print('No JSON could be loaded, is the container already running?')
exit(1)
Comment thread
github-code-quality[bot] marked this conversation as resolved.
Fixed
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed

try:
if manifest_json['ErrorWritingVersioning']:
print('No JSON could be loaded, is the container already running?')
Expand Down
34 changes: 34 additions & 0 deletions roles/nvidia-dgx-firmware/tests/test_parse_manifest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import subprocess
import sys
import tempfile
import unittest

from pathlib import Path


SCRIPT = Path(__file__).resolve().parents[1] / 'files' / 'parse_manifest.py'


class ParseManifestTest(unittest.TestCase):
def test_parse_versioning_rejects_non_dict_json(self):
with tempfile.TemporaryDirectory() as temp_dir:
manifest = Path(temp_dir) / 'versioning.json'
manifest.write_text('[1,2,3]\n')

result = subprocess.run(
[sys.executable, str(SCRIPT), 'parse_versioning', str(manifest)],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
)

self.assertEqual(result.returncode, 1)
self.assertEqual(
result.stdout,
'No JSON could be loaded, is the container already running?\n',
)
self.assertEqual(result.stderr, '')


if __name__ == '__main__':
unittest.main()
Loading