Skip to content

🌱 Small refactoring in the ironic startup scripts and template#787

Merged
metal3-io-bot merged 2 commits intometal3-io:mainfrom
mchiappero:ironic-refactoring
Feb 17, 2026
Merged

🌱 Small refactoring in the ironic startup scripts and template#787
metal3-io-bot merged 2 commits intometal3-io:mainfrom
mchiappero:ironic-refactoring

Conversation

@mchiappero
Copy link
Copy Markdown
Contributor

What this PR does / why we need it:
This PR introduces a set of code refactoring, aiming at making the code more readable but extracting common logic that may become useful with future code additions. Most notably:

  • some mangling logic for IP addresses provided as input is now in its own function
  • the logic to lookup a the interface where an IP address is bound now lives in a dedicated function
    In the future a matching utility function to retrieve the (first) IP address assigned to an interface will also be added, but implies more changes and will be introduced along with other functional changes.

Checklist:

  • Integration tests have been added, if necessary.

@metal3-io-bot metal3-io-bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Nov 14, 2025
@metal3-io-bot
Copy link
Copy Markdown
Contributor

Hi @mchiappero. Thanks for your PR.

I'm waiting for a github.com member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@metal3-io-bot metal3-io-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Nov 14, 2025
@elfosardo
Copy link
Copy Markdown
Member

/ok-to-test

@metal3-io-bot metal3-io-bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 14, 2025
Copy link
Copy Markdown
Member

@Rozzii Rozzii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the refactor, I also not a fun of complex jinja templates so I support the idea but I would like to point out a few shellcheck issues and nits.

Comment thread scripts/configure-ironic.sh Outdated
Comment thread scripts/ironic-common.sh Outdated
Comment thread scripts/ironic-common.sh Outdated
Comment thread scripts/ironic-common.sh Outdated
Comment thread scripts/ironic-common.sh Outdated
Comment thread scripts/ironic-common.sh Outdated
Comment thread scripts/ironic-common.sh Outdated
Comment thread scripts/ironic-common.sh Outdated
Comment thread scripts/ironic-common.sh Outdated
Comment thread scripts/ironic-common.sh Outdated
Comment thread scripts/ironic-common.sh Outdated
@tuminoid
Copy link
Copy Markdown
Member

Same as #788 ?

Comment thread scripts/ironic-common.sh Outdated

if [[ "$#" -gt 2 ]]; then
echo "ERROR: ${FUNCNAME[0]}: too many parameters" >&2
return 1
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure we want a return here, let's just use exit ?
maybe also for the other return statements
unless you really want to capture the exit code, then use echo, but I don't see the point

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whether to exit or not is not a decision to be made at this scope. The caller could, and probably should, use exit, but there is no homogeneous error handling in general across these scripts.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I thought it was a different error test... Yes we could exit here in this case since it would be an invalid use of the function rather than invalid input. I don't mind, it's an unfortunate side effect of using the wrong tool for the job, it doesn't make much of a difference.

Comment thread scripts/ironic-common.sh Outdated
local PARSED_IP
PARSED_IP="$(parse_ip_address "${PROVISIONING_IP}")"
if [[ -z "${IRONIC_IP}" ]]; then
return 1
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably provide an error message here ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, we could wrap it in a "parse_or_die" sort of function, and avoid the test here.

Copy link
Copy Markdown
Contributor Author

@mchiappero mchiappero Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, we could wrap it in a "parse_or_die" sort of function, and avoid the test here.

E.g.:

parse_ip_address_or_die()
{
    local RESULT

    RESULT="$(parse_ip_address $@)"
    if [[ -z "${RESULT}" ]]; then
        echo "ERROR: \"$@\" is not a valid IP address, failed to start ironic"
        exit 1
    fi

    echo "${RESULT}"
}

Comment thread scripts/ironic-common.sh
@mchiappero
Copy link
Copy Markdown
Contributor Author

I think the code now is a good shape, let me know how we can unblock this, if there is any other change you would like to see.

@Rozzii
Copy link
Copy Markdown
Member

Rozzii commented Nov 25, 2025

/retest

@tuminoid
Copy link
Copy Markdown
Member

/retest
/test metal3-centos-e2e-integration-test-main metal3-ubuntu-e2e-integration-test-main

@mchiappero
Copy link
Copy Markdown
Contributor Author

Sorry, the grep bit in get_interface_of_ip is wrong for some reason, just noticing now. Let me fix it.

@mchiappero
Copy link
Copy Markdown
Contributor Author

Sorry, the grep bit in get_interface_of_ip is wrong for some reason, just noticing now. Let me fix it.

Sorry for the delay, I'll change the grep command a bit, but I have tested the current version against a number of different containers, from SUSE images to Ubuntu without any problem. Let's see...

@mchiappero
Copy link
Copy Markdown
Contributor Author

/retest

Copy link
Copy Markdown
Member

@elfosardo elfosardo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that was an oversight
please squash the commits

@metal3-io-bot metal3-io-bot removed the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 18, 2025
@dtantsur
Copy link
Copy Markdown
Member

Honestly, the commits here seem to be reasonable deliniated, I'm not sure where the requests to squash them is coming from. Unlike in gerrit, we don't have any "single PR - single commit" rule.

Comment thread scripts/configure-ironic.sh Outdated
wait_for_interface_or_ip

if [[ "$(echo "${LISTEN_ALL_INTERFACES}" | tr '[:upper:]' '[:lower:]')" == "true" ]]; then
export IRONIC_HOST_IP="::"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this one will be easy to confuse with the existing IRONIC_URL_HOST. I'm not sure what a better alternative would be, but I'm worried about this change deepening the confusion. If we cannot find an alternative, I'd rather leave the "if" condition in the template.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since IRONIC_URL_HOST can be different from the actual listening address, we could change IRONIC_HOST_IP to IRONIC_LISTEN_ADDRESS/IRONIC_BIND_ADDRESS (BTW, it could actually be a hostname too). And/or limit the scope of IRONIC_URL_HOST to ironic-common.sh, which is probably not a bad thing anyway. Along with some documentation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if you guys had the chance to have a think about it, but the more I think about it the more I believe we should address this "globally": it's not very clear from the outside what controls what when it comes to IP addresses, for instance IRONIC_IP is not even mentioned in the README file. I can drop this specific commit from the PR, but if so we should take the chance to review the root problem of ease of understanding of which variable affects what and their documentation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

@Rozzii Rozzii Jan 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say let's address the naming of the IP variable separately. At least that would be my preference @mchiappero , I agree with you that the naming has to be handled globally and I think a separate independent PR would be the way to go for the sake of clarity and ease of reviewing.

Copy link
Copy Markdown
Member

@Rozzii Rozzii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have one comment, apart from that I think the commits are reasonably separate from each other but belong to the general refactoring topic so I would not force squashing.

Comment thread scripts/configure-ironic.sh Outdated
wait_for_interface_or_ip

if [[ "$(echo "${LISTEN_ALL_INTERFACES}" | tr '[:upper:]' '[:lower:]')" == "true" ]]; then
export IRONIC_HOST_IP="::"
Copy link
Copy Markdown
Member

@Rozzii Rozzii Jan 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say let's address the naming of the IP variable separately. At least that would be my preference @mchiappero , I agree with you that the naming has to be handled globally and I think a separate independent PR would be the way to go for the sake of clarity and ease of reviewing.

@mchiappero
Copy link
Copy Markdown
Contributor Author

mchiappero commented Jan 15, 2026

I have dropped the templating related commit and squashed the last two commits.

Edit: and rebased. Sorry for the confusion but the content of the commits has not changed.

Whether IRONIC_IP or PROVISIONIG_IP is provided to ironic-image, any
such address should be checked for validity and, if needed,
properly formatted. For this reason, this commit introduces
parse_ip_address to be consumed inside wait_for_interface_or_ip.

Signed-off-by: Marco Chiappero <marco.chiappero@suse.com>
Add a new get_interface_of_ip function that returns the name of the
interface of a given IP, and use it to determine if the
PROVISIONING_IP address is actually present on a network interface.
This improves the code readability and enables additional debugging
output.

This function supersedes a similar check present in
get_provisioning_interface, hence this commit also reverts commit
2742439.

Signed-off-by: Marco Chiappero <marco.chiappero@suse.com>
@mchiappero
Copy link
Copy Markdown
Contributor Author

We should be good to merge now, let me know so that we can start closing these old MR. Thank you!

@Rozzii Rozzii self-requested a review January 29, 2026 08:03
@Rozzii
Copy link
Copy Markdown
Member

Rozzii commented Feb 3, 2026

/test metal3-centos-e2e-integration-test-main
/test metal3-ubuntu-e2e-integration-test-main

Copy link
Copy Markdown
Member

@Rozzii Rozzii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@metal3-io-bot metal3-io-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 3, 2026
@tuminoid
Copy link
Copy Markdown
Member

tuminoid commented Feb 4, 2026

/retest

@tuminoid
Copy link
Copy Markdown
Member

tuminoid commented Feb 4, 2026

/retest
Maybe CI is fixed now...

@mchiappero
Copy link
Copy Markdown
Contributor Author

I think we can now lift the block, @elfosardo?

@elfosardo
Copy link
Copy Markdown
Member

/unhold

@metal3-io-bot metal3-io-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 17, 2026
@elfosardo
Copy link
Copy Markdown
Member

/lgtm

@metal3-io-bot metal3-io-bot added the lgtm Indicates that a PR is ready to be merged. label Feb 17, 2026
@elfosardo elfosardo requested a review from tuminoid February 17, 2026 09:21
@metal3-io-bot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: elfosardo, Rozzii

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@metal3-io-bot metal3-io-bot merged commit a2ad2fc into metal3-io:main Feb 17, 2026
14 checks passed
@metal3-io-bot metal3-io-bot added this to the ironic-image - v35.0 milestone Feb 17, 2026
iurygregory pushed a commit to iurygregory/ironic-image that referenced this pull request Apr 10, 2026
…ackport

Bug OCPBUGS-76547: Bump 4.20 ironic-image to include firmware update fixes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants