Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test timing issue + minor code cleanup #3238

Merged
merged 5 commits into from
Oct 8, 2024
Merged

Conversation

narrieta
Copy link
Member

@narrieta narrieta commented Oct 8, 2024

The agent_firewall test may attempt to check the firewall before the Agent has set it up. For iptables, this was not an issue because the firewall is setup by the daemon, but that is not the case for nft.

Added an extra check to verify that the walinuxagent table is already created in NfTables.get_missing_rules().

The Agent may still be in the middle of setting up the table when the test runs. My next PR will add atomic updated for nft, which should take care of that condition.

The PR also includes some minor cleanup that I pointed out as comments.

@@ -72,20 +72,27 @@ def create(wire_server_address):
"""
try:
manager = IpTables(wire_server_address)
logger.info("Using iptables to manage firewall rules")
event.info(WALAEventOperation.Firewall, "Using iptables [version {0}] to manage firewall rules", manager.version)
Copy link
Member Author

Choose a reason for hiding this comment

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

added telemetry to get the version of iptables/nft/firewall-cmd

@@ -169,7 +169,8 @@ def test_it_should_restore_missing_firewall_rules(self):
test_cases = [ # Exit codes for the "-C" (check) command
{"accept_dns": 1, "accept": 0, "drop": 0, "legacy": 0},
{"accept_dns": 0, "accept": 1, "drop": 0, "legacy": 0},
{"accept_dns": 0, "accept": 0, "drop": 1, "legacy": 0},
{"accept_dns": 0, "accept": 1, "drop": 0, "legacy": 0},
{"accept_dns": 1, "accept": 1, "drop": 1, "legacy": 0},
Copy link
Member Author

Choose a reason for hiding this comment

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

added test case for all rules missing

@@ -33,9 +32,7 @@ def __init__(self, context: AgentVmTestContext):
self._ssh_client = self._context.create_ssh_client()

def run(self):
log.info("Checking firewall rules added by the agent")
Copy link
Member Author

Choose a reason for hiding this comment

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

Removed those messages; they are sort of confusing

@@ -369,18 +369,6 @@ def get_errors(self) -> List[AgentLogRecord]:
'if': lambda r: r.prefix == 'ExtHandler' and r.thread == 'ExtHandler'
},
#
# TODO: Currently Ubuntu minimal does not include the 'iptables' command. Remove this rule once this has been addressed.
Copy link
Member Author

Choose a reason for hiding this comment

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

no longer needed

@@ -264,17 +264,19 @@ def get_state(self) -> str:
}

def get_missing_rules(self) -> List[str]:
missing = []
if "table ip walinuxagent" not in shellutil.run_command(["sudo", "nft", "list", "tables"]):
Copy link
Member Author

Choose a reason for hiding this comment

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

add check for case when the table has not been created yet

@narrieta narrieta merged commit e55a98a into Azure:develop Oct 8, 2024
11 checks passed
@narrieta narrieta deleted the firewall branch October 8, 2024 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants