Skip to content

Stop reporting changes for configured alias (#51068) - #63113

Open
lvinagre wants to merge 2 commits into
saltstack:masterfrom
lvinagre:master
Open

Stop reporting changes for configured alias (#51068)#63113
lvinagre wants to merge 2 commits into
saltstack:masterfrom
lvinagre:master

Conversation

@lvinagre

@lvinagre lvinagre commented Nov 24, 2022

Copy link
Copy Markdown

What does this PR do?

This fixes an issue where Salt is reporting changes for networking aliases when they are already configured as expected and no changes are done.

What issues does this PR fix or reference?

Fixes: #51068

Previous Behavior

Thu Nov 24 10:00:01 EST 2022
local:
----------
          ID: pub_eth_alias
    Function: network.managed
        Name: eno1:11
      Result: True
     Comment: Interface eno1:11 is up to date.
     Started: 10:01:47.468357
    Duration: 53.915 ms
     Changes:   
              ----------
              status:
                  Interface eno1:11 is up

New Behavior

Thu Nov 24 15:25:32 EST 2022
local:
----------
          ID: pub_eth_alias
    Function: network.managed
        Name: eno1:11
      Result: True
     Comment: Interface eno1:11 is up to date.
     Started: 15:27:14.110393
    Duration: 48.243 ms
     Changes:   

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

I am not good at writing tests, but at least the current ones are passing:

==================================================================================== test session starts ====================================================================================
platform linux -- Python 3.9.2, pytest-7.2.0, pluggy-0.13.0                       
tempdir: /tmp/stsuite                                                                         
max open files; soft: 3072; hard: 1048576                                                     
rootdir: /home/vagrant/salt, configfile: pytest.ini                                                                                                                                          plugins: subtests-0.4.0, skip-markers-1.2.0, custom-exit-code-0.3.0, helpers-namespace-2021.4.29, shell-utilities-1.6.0, system-statistics-1.0.2, timeout-1.4.2, flaky-3.7.0, httpserver-1.0.
4, tempdir-2019.10.12, salt-factories-1.0.0rc21                                                                                                                                              
collected 3 items                                                                                                                                                                           
                                                                                              
tests/unit/states/test_network.py ...                                                         
                                                                                                                                                                                             
===================================================================================== warnings summary ======================================================================================
tests/conftest.py:229                                                                                                                                                                        
  /home/vagrant/salt/tests/conftest.py:229: PytestDeprecationWarning: The hookimpl pytest_configure uses old-style configuration options (marks or attributes).
  Please use the pytest.hookimpl(trylast=True) decorator instead
   to configure the hooks.                                                                                                                                                                   
   See https://docs.pytest.org/en/latest/deprecations.html#configuring-hook-specs-impls-using-markers
    @pytest.mark.trylast         
                                                                                              
tests/unit/states/test_network.py::NetworkTestCase::test_managed                                                                                                                               /home/vagrant/salt/.nox/test-parametrized-3-crypto-pycryptodome-transport-tcp-coverage-false/lib/python3.9/site-packages/napalm/base/helpers.py:8: DeprecationWarning: Using or importing t
he ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.10 it will stop working
    from collections import Iterable       
                                                                                              
tests/unit/states/test_network.py::NetworkTestCase::test_managed                                                                                                                               /home/vagrant/salt/.nox/test-parametrized-3-crypto-pycryptodome-transport-tcp-coverage-false/lib/python3.9/site-packages/jnpr/junos/factcache.py:10: DeprecationWarning: Using or importing
 the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.10 it will stop working
    class _FactCache(collections.MutableMapping):          
                                                                                              
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html                                                                                                                      
=============================================================================== 3 passed, 3 warnings in 1.01s ===============================================================================
nox > Session test-parametrized-3(crypto='pycryptodome', transport='tcp', coverage=False) was successful.                                                                                    

Commits signed with GPG?

No

@lvinagre
lvinagre requested a review from a team as a code owner November 24, 2022 20:30
@lvinagre
lvinagre requested review from waynew and removed request for a team November 24, 2022 20:30
@lvinagre

lvinagre commented Mar 1, 2023

Copy link
Copy Markdown
Author

Hey @waynew , just want to check if there's anything missing in that PR for review.

@lvinagre
lvinagre force-pushed the master branch 2 times, most recently from bedfbdc to fbf16c4 Compare March 2, 2023 16:06
@Ch3LL
Ch3LL requested review from Ch3LL and removed request for waynew May 4, 2023 19:51

@Ch3LL Ch3LL left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This will also require test coverage

Comment thread changelog/51068.fixed
Comment thread salt/states/network.py

@Ch3LL Ch3LL left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We actually are migrating all of our tests to pytests in tests/pytests. Any chance you would be willing to add these new tests there instead?

Comment thread tests/integration/states/test_network.py Outdated
@lvinagre
lvinagre temporarily deployed to ci May 17, 2023 21:03 — with GitHub Actions Inactive
@lvinagre
lvinagre temporarily deployed to ci May 17, 2023 21:03 — with GitHub Actions Inactive
@lvinagre
lvinagre temporarily deployed to ci May 17, 2023 21:03 — with GitHub Actions Inactive
@lvinagre
lvinagre temporarily deployed to ci May 17, 2023 22:19 — with GitHub Actions Inactive
@lvinagre
lvinagre temporarily deployed to ci May 17, 2023 22:19 — with GitHub Actions Inactive
@lvinagre
lvinagre temporarily deployed to ci May 17, 2023 22:19 — with GitHub Actions Inactive
@lvinagre
lvinagre requested a review from Ch3LL June 1, 2023 20:20
Ch3LL
Ch3LL previously approved these changes Jun 5, 2023
twangboy
twangboy previously approved these changes Jun 5, 2023
@lvinagre
lvinagre temporarily deployed to ci June 5, 2023 23:05 — with GitHub Actions Inactive
@lvinagre
lvinagre temporarily deployed to ci June 5, 2023 23:09 — with GitHub Actions Inactive
@lvinagre
lvinagre temporarily deployed to ci June 6, 2023 00:03 — with GitHub Actions Inactive
@lvinagre
lvinagre temporarily deployed to ci June 6, 2023 08:01 — with GitHub Actions Inactive
@lvinagre
lvinagre temporarily deployed to ci June 6, 2023 08:01 — with GitHub Actions Inactive
@lvinagre
lvinagre temporarily deployed to ci June 6, 2023 08:01 — with GitHub Actions Inactive
@Ch3LL

Ch3LL commented Jun 6, 2023

Copy link
Copy Markdown
Contributor

@lvinagre looks like there are some failing tests related to your changes.

twangboy
twangboy previously approved these changes Mar 27, 2025
@lvinagre

Copy link
Copy Markdown
Author

Hey @twangboy, I've seen movement here a few times now. Please let me know if anything is required from my part for this to be merged.

@twangboy

Copy link
Copy Markdown
Contributor

Looks like you have some failing tests.

@lvinagre

Copy link
Copy Markdown
Author

Looks like you have some failing tests.

@twangboy, I tried including the management of the packages missing in the integration tests. I did comment in the past that those failures were related to the underlying modules and not to the state itself. Let's see if those test pass now.

twangboy
twangboy previously approved these changes Aug 15, 2025
@lvinagre

Copy link
Copy Markdown
Author

@twangboy, I spent a bit more time on this now and was able to find some stuff that was actually broken. I've put all into a single commit, rebased and put it through pre-commit and it looks good. I've also tested the final thing in in the distros that were failing (debian 11/12 and rocky 8/9) and all tests passed. Hopefully now we are good to go, my apologies for the previous/broken stuff.

twangboy
twangboy previously approved these changes Sep 15, 2025
@lvinagre

Copy link
Copy Markdown
Author

@twangboy , can you please check the failed tests results when you have a moment? It seems they are unrelated to my change now and got dragged by rebasing. All the "Test Salt" tests completed successfully, which, from what I understood, is where my changes are tested.

@twangboy

Copy link
Copy Markdown
Contributor

We'll need to wait until tests are passing on the master branch, then rebase this and see what happens.

twangboy
twangboy previously approved these changes Oct 1, 2025
@twangboy

Copy link
Copy Markdown
Contributor

Please resolve the conflicts

@lvinagre

Copy link
Copy Markdown
Author

Please resolve the conflicts

done

@dwoz

dwoz commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

@lvinagre Thank you

@twangboy twangboy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should be created on the earliest supported branch where the bug exists. Probably 3006.x

Comment thread salt/states/network.py
interface_status = True
interface_status = False

# Handle interface as desired

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Unconditionally splitting the interface string on a colon breaks support for complex interface naming conventions (like VLAN tags and sub-interfaces) and incorrectly conflates a parent interface's status with its un-validated alias configurations.

By completely deleting that section and substituting the raw split(":"), the code now blindly conflates the parent interface's operational status with the status of the alias itself. If the parent interface (eth0) is up, Salt will now automatically assume the alias (eth0:1) is up and up-to-date—even if the virtual IP allocation for that alias completely failed to bind on the host.

That deleted code was the only mechanism verifying that the specific label (second.get("label") == name) was genuinely active in the system's runtime network state.

Instead of an unconditional split(":"), Salt should use a targeted regex match to separate a true legacy sub-interface/alias label from a standard interface name. Then, it needs to query the actual nested secondary data structure to confirm that the specific virtual label is bound and active.

    # Bring up/shutdown interface
    try:
        # Get Interfaces information
        interfaces = salt.utils.network.interfaces()
        interface_status = False

        # 1. Check if the exact interface name exists directly
        if name in interfaces:
            interface_status = interfaces[name].get("up", False)
        
        # 2. Safely check for legacy alias structures (e.g., eth0:1, bond0:vlan1)
        else:
            import re
            # Match standard interface naming followed by a numeric or label alias
            match = re.match(r"^([a-zA-Z0-9.\-_]+):([a-zA-Z0-9_\-]+)$", name)
            if match:
                parent_iface = match.group(1)
                if parent_iface in interfaces:
                    # Look for the explicit alias label in the secondary IP data structures
                    for family in ("secondary", "inet", "inet6"):
                        if family in interfaces[parent_iface]:
                            for data in interfaces[parent_iface][family]:
                                if data.get("label") == name:
                                    interface_status = True
                                    break
                        if interface_status:
                            break

        interface_status = interface_status or False

        # Handle interface as desired
        if enabled:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

network.managed reports changes to alias interface when nothing changed

4 participants