-
Notifications
You must be signed in to change notification settings - Fork 267
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
Test for firewalld container in ALP product #18198
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
name: Firewalld in a Container | ||
description: > | ||
Install and test firewalld container | ||
conditional_schedule: | ||
firewalld_container: | ||
HOSTNAME: | ||
'client': | ||
- microos/workloads/firewalld-container/firewalld_client | ||
'server': | ||
- microos/workloads/firewalld-container/firewalld_server | ||
schedule: | ||
- microos/disk_boot | ||
- '{{firewalld_container}}' |
46 changes: 46 additions & 0 deletions
46
tests/microos/workloads/firewalld-container/firewalld_client.pm
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# SUSE"s openQA tests | ||
# | ||
# Copyright 2023 SUSE LLC | ||
# SPDX-License-Identifier: FSFAP | ||
# | ||
# Package: podman firewalld-container | ||
# Summary: install and verify firewalld container. | ||
# Maintainer: QE Core <qe-core@suse.de> | ||
|
||
use base 'consoletest'; | ||
use warnings; | ||
use strict; | ||
use testapi; | ||
use lockapi; | ||
use utils qw(set_hostname script_retry); | ||
use mm_network 'setup_static_mm_network'; | ||
|
||
# MM network check: try to ping the gateway, and the server | ||
sub ensure_server_reachable { | ||
assert_script_run('ping -c 1 10.0.2.2'); | ||
assert_script_run('ping -c 1 10.0.2.101'); | ||
} | ||
|
||
sub run { | ||
my ($self) = @_; | ||
select_console 'root-console'; | ||
set_hostname(get_var('HOSTNAME') // 'client'); | ||
# 101 = server, 102 = client | ||
setup_static_mm_network('10.0.2.102/24'); | ||
mutex_wait 'barrier_setup_done'; | ||
barrier_wait 'FIREWALLD_CLIENT_READY'; | ||
barrier_wait 'FIREWALLD_SERVER_READY'; | ||
ensure_server_reachable(); | ||
barrier_wait 'FIREWALLD_SERVER_PORT_OPEN'; | ||
# ensure the port is open on the server | ||
my $network_probe = 'curl http://10.0.2.101:8080/'; | ||
script_retry($network_probe, retry => 3, delay => 30); | ||
# wait for port being closed by firewall | ||
barrier_wait 'FIREWALLD_SERVER_PORT_CLOSED'; | ||
# the next command should fail because port 8080 is closed | ||
die if (script_run($network_probe) == 0); | ||
barrier_wait 'FIREWALLD_TEST_FINISHED'; | ||
} | ||
|
||
1; | ||
|
85 changes: 85 additions & 0 deletions
85
tests/microos/workloads/firewalld-container/firewalld_server.pm
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# SUSE"s openQA tests | ||
# | ||
# Copyright 2023 SUSE LLC | ||
# SPDX-License-Identifier: FSFAP | ||
# | ||
# Package: podman firewalld-container | ||
# Summary: install and verify firewalld container. | ||
# Maintainer: QE Core <qe-core@suse.de> | ||
|
||
use base 'consoletest'; | ||
use warnings; | ||
use strict; | ||
use testapi; | ||
use lockapi; | ||
use mmapi; | ||
use utils qw(set_hostname); | ||
use transactional qw(trup_call check_reboot_changes); | ||
use mm_network 'setup_static_mm_network'; | ||
use Utils::Systemd qw(disable_and_stop_service systemctl check_unit_file); | ||
|
||
|
||
sub remove_builtin_pkg_firewalld { | ||
record_info("SERVER DEBUG", "removing firewalld and reboot if needed"); | ||
trup_call('pkg remove firewalld'); | ||
check_reboot_changes; | ||
} | ||
|
||
sub start_firewalld_container { | ||
record_info("SERVER DEBUG", "installing firewalld container"); | ||
my $containerpath = 'registry.opensuse.org/suse/alp/workloads/tumbleweed_images/suse/alp/workloads/firewalld'; | ||
assert_script_run 'podman search firewalld'; | ||
assert_script_run "podman container runlabel install $containerpath"; | ||
assert_script_run "podman container runlabel run $containerpath"; | ||
} | ||
|
||
sub firewall_port { | ||
my $arg = shift; | ||
record_info("SERVER DEBUG", "$arg firewall port"); | ||
my $podman_prefix = "podman exec firewalld firewall-cmd "; | ||
my $options = '--zone=public --permanent '; | ||
if ($arg eq 'open') { $options .= '--add-port=8080/tcp'; } | ||
elsif ($arg eq 'close') { $options .= '--remove-port=8080/tcp'; } | ||
else { die "invalid command for firewalld action"; } | ||
assert_script_run $podman_prefix . $options; | ||
assert_script_run $podman_prefix . '--reload'; | ||
} | ||
|
||
# MM network check: try to ping the gateway, the client and the internet | ||
sub ensure_client_reachable { | ||
assert_script_run('ping -c 1 10.0.2.2'); | ||
assert_script_run('ping -c 1 10.0.2.102'); | ||
assert_script_run('curl conncheck.opensuse.org'); | ||
} | ||
|
||
sub run { | ||
my ($self) = @_; | ||
select_console 'root-console'; | ||
disable_and_stop_service($self->firewall) if check_unit_file($self->firewall); | ||
remove_builtin_pkg_firewalld(); # on ALP this needs a reboot | ||
set_hostname(get_var('HOSTNAME') // 'server'); | ||
barrier_create($_, 2) for ('FIREWALLD_SERVER_READY', 'FIREWALLD_CLIENT_READY', 'FIREWALLD_SERVER_PORT_OPEN', | ||
'FIREWALLD_SERVER_PORT_CLOSED', 'FIREWALLD_TEST_FINISHED'); | ||
mutex_create 'barrier_setup_done'; | ||
setup_static_mm_network('10.0.2.101/24'); | ||
barrier_wait 'FIREWALLD_CLIENT_READY'; | ||
ensure_client_reachable(); | ||
barrier_wait 'FIREWALLD_SERVER_READY'; | ||
start_firewalld_container(); | ||
# start a basic python http server | ||
my $python_pid = background_script_run("python3 -m http.server 8080"); | ||
firewall_port('open'); | ||
barrier_wait 'FIREWALLD_SERVER_PORT_OPEN'; | ||
# tells the client server is ready so can probe the port | ||
# client is checking the server port | ||
firewall_port('close'); | ||
barrier_wait 'FIREWALLD_SERVER_PORT_CLOSED'; | ||
# here client is checking the port | ||
barrier_wait 'FIREWALLD_TEST_FINISHED'; | ||
assert_script_run "kill $python_pid"; | ||
assert_script_run "podman stop firewalld"; | ||
wait_for_children(); | ||
} | ||
|
||
1; | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could even do that on the perl side, but we can leave that for a follow up ticket, same for the ones earlier