ENT-11346: Added the 'cfbs render-input' command - #326
Merged
Conversation
larsewi
force-pushed
the
cfbs-render-input
branch
from
July 28, 2026 15:03
3f1169f to
9cae354
Compare
The _compare_dict() / _compare_list() helpers in set_input_command() are moved to validate.py as input_data_matches_spec(), so the same check can be reused by the render-input command which will later be implemented in ticket ENT-11346. Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
Moved _generate_augment() to cfbs/augments.py so that it can be reused by the render-input command which will later be implemented in ticket ENT-11346. Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
Generalized the logic in 'get-input' and 'set-input' for opening a file and conditionally returning the stdin/stdout file descriptors. This function will be reused by the render-input command implement in ticket ENT-11346. Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
larsewi
force-pushed
the
cfbs-render-input
branch
from
July 28, 2026 15:25
9cae354 to
e9362b4
Compare
larsewi
marked this pull request as ready for review
July 28, 2026 15:48
olehermanse
reviewed
Jul 29, 2026
get_module_from_build() looked up the "build" key unconditionally, raising an exception for a project that uses "provides" instead. Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
The get_module_object() function now takes a "default" argument, returned when the module or the requested version is not in the index, defaulting to None. Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
input_data_matches_spec() zipped the input definition and the input data together without checking that they are lists. Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
Converts input data for a module into an augments file (def.json). This is the same conversion the 'input' build step performs during 'cfbs build', except that the input data is read from an infile instead of <module-name>/input.json, and nothing is stored in the project. Mission Portal needs this to render the augment for module input which is entered per host group, and thus stored in its database rather than in the project. Ticket: ENT-11346 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
larsewi
force-pushed
the
cfbs-render-input
branch
from
July 29, 2026 12:26
e9362b4 to
e28ead6
Compare
olehermanse
reviewed
Jul 29, 2026
olehermanse
approved these changes
Jul 29, 2026
olehermanse
reviewed
Jul 29, 2026
olehermanse
reviewed
Jul 29, 2026
Comment on lines
+258
to
+273
| # ExitStack rather than a plain with statement, so that the OSError | ||
| # handling only covers opening the file, not running the command: | ||
| with contextlib.ExitStack() as stack: | ||
| # Open the infile first, so that a mistyped infile doesn't truncate | ||
| # the outfile: | ||
| try: | ||
| infile = stack.enter_context(open_file_arg(infilename, "r")) | ||
| except OSError as e: | ||
| log.error("Can't open '%s': %s" % (infilename, e)) | ||
| return 1 | ||
| try: | ||
| outfile = stack.enter_context(open_file_arg(outfilename, "w")) | ||
| except OSError as e: | ||
| log.error("Can't open '%s': %s" % (outfilename, e)) | ||
| return 1 | ||
| return commands.render_input_command(module, infile, outfile) |
Member
There was a problem hiding this comment.
Looks a bit unnecessarily complicated IMO, don't know exactly what's the best way.
Something like this feels more natural for me;
Suggested change
| # ExitStack rather than a plain with statement, so that the OSError | |
| # handling only covers opening the file, not running the command: | |
| with contextlib.ExitStack() as stack: | |
| # Open the infile first, so that a mistyped infile doesn't truncate | |
| # the outfile: | |
| try: | |
| infile = stack.enter_context(open_file_arg(infilename, "r")) | |
| except OSError as e: | |
| log.error("Can't open '%s': %s" % (infilename, e)) | |
| return 1 | |
| try: | |
| outfile = stack.enter_context(open_file_arg(outfilename, "w")) | |
| except OSError as e: | |
| log.error("Can't open '%s': %s" % (outfilename, e)) | |
| return 1 | |
| return commands.render_input_command(module, infile, outfile) | |
| unexpected = None | |
| try: | |
| with open(inp, "r") as infile: | |
| with open(out, "w") as outfile: | |
| try: | |
| commands.render_input_command(module, infile, outfile) | |
| except Exception as e: | |
| unexpected = e | |
| except OSError as e: | |
| log.error("Can't open '%s': %s" % (outfilename, e)) | |
| return 1 | |
| if unexpected: | |
| raise unexpected |
Contributor
Author
There was a problem hiding this comment.
Yeah, I think both versions looks complicated
olehermanse
approved these changes
Jul 29, 2026
Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-authored-by: Ole Herman Schumacher Elgesem <4048546+olehermanse@users.noreply.github.com>
larsewi
force-pushed
the
cfbs-render-input
branch
from
July 29, 2026 14:19
2ac21f6 to
c588d1f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Converts input data for a module into an augments file (
def.json). It does the same conversion as theinputbuild step performs duringcfbs build, except that the input data is read from an infile and nothing is stored in the built project.Mission Portal needs this to render the augment for module input which is entered per host group, and thus stored in its database rather than in the project.
The first 3 commits are preparatory refactoring, with no functional change. The next 3 fix pre-existing crashes found while implementing this, each with a shell test which fails without its fix.
Ticket: ENT-11346
🤖 Generated with Claude Code