-
Notifications
You must be signed in to change notification settings - Fork 26
Provide a script to bootstrap mm devices #190
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
Draft
kalikiana
wants to merge
1
commit into
os-autoinst:master
Choose a base branch
from
kalikiana:prepare_mm_devices
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
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 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| #!/usr/bin/env perl | ||
| # Copyright SUSE LLC | ||
| # SPDX-License-Identifier: MIT | ||
|
|
||
| use Mojo::Base -strict, -signatures; | ||
| use Mojo::File qw(path); | ||
| use autodie ':all'; | ||
|
|
||
| sub configure_firewall ($firewall, $bridge) { | ||
| path($firewall)->spurt(qq( | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <zone target="ACCEPT"> | ||
| <short>Trusted</short> | ||
| <description>All network connections are accepted.</description> | ||
| <interface name="br$bridge"/> | ||
| <interface name="ovs-system"/> | ||
| <interface name="eth0"/> | ||
| <masquerade/> | ||
| </zone> | ||
| )); | ||
| } | ||
|
|
||
| sub provision_services () { | ||
| # bind-utils contains dig | ||
| system("zypper in -y bind-utils os-autoinst-openvswitch"); | ||
| system("systemctl enable --now openvswitch os-autoinst-openvswitch"); | ||
| system("systemctl reload firewalld"); | ||
| } | ||
|
|
||
| sub generate_bridge_configs ($etc, $bridge) { | ||
| path("$etc/sysconfig/os-autoinst-openvswitch")->spurt("OS_AUTOINST_USE_BRIDGE=br$bridge"); | ||
| # Manage services only if writing to system-wide files | ||
| system("ovs-vsctl add-br br$bridge") if $etc =~ /^\/etc/; | ||
|
|
||
| my $bridge_file = "$etc/sysconfig/network/ifcfg-br$bridge"; | ||
| my $ip = "10.0.2.2/15"; | ||
kalikiana marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| my $config = " | ||
| BOOTPROTO=static | ||
| IPADDR=$ip | ||
| STARTMODE=auto | ||
| ZONE=trusted | ||
| OVS_BRIDGE=yes | ||
| PRE_UP_SCRIPT=wicked:gre_tunnel_preup.sh | ||
| "; | ||
|
|
||
| for my $i (0..147) { | ||
kalikiana marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $config .= "OVS_BRIDGE_PORT_DEVICE_$i='tap$i'\n"; | ||
|
|
||
| path("$etc/sysconfig/network/ifcfg-tap$i")->spurt(" | ||
| BOOTPROTO='none' | ||
| IPADDR='' | ||
| NETMASK='' | ||
| PREFIXLEN='' | ||
| STARTMODE='auto' | ||
| TUNNEL='tap' | ||
| TUNNEL_SET_GROUP='nogroup' | ||
| TUNNEL_SET_OWNER='_openqa-worker' | ||
| ZONE=trusted | ||
| "); | ||
| } | ||
|
|
||
| path($bridge_file)->spurt($config); | ||
| } | ||
|
|
||
| sub generate_preup ($gre, $bridge) { | ||
| my $gre_config = ' | ||
| #!/bin/sh | ||
| action="$1" | ||
| bridge="$2" | ||
| ovs-vsctl set bridge $bridge stp_enable=true | ||
| '; | ||
|
|
||
| my @workers = qw(openqaworker1 openqaworker4 openqaworker7 openqaworker19); | ||
kalikiana marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| my $device = 0; | ||
| my $this_worker = qx(hostname -i); | ||
| chomp $this_worker; | ||
| for my $worker (@workers) { | ||
| my $ip = qx"dig +short $worker"; | ||
| next if $ip eq $this_worker; # Don't put the machine itself here | ||
| $device++; | ||
| $gre_config .= " | ||
| # $worker | ||
| ovs-vsctl --may-exist add-port $bridge gre$device -- set interface gre$device type=gre options:remote_ip=$ip"; | ||
| } | ||
|
|
||
| path($gre)->spurt($gre_config); | ||
| system("chmod +x $gre"); | ||
| } | ||
|
|
||
| my ($etc, $bridge) = @ARGV; | ||
| $etc //= '/etc'; | ||
| $bridge //= 1; | ||
|
|
||
| configure_firewall("$etc/firewalld/zones/trusted.xml", $bridge); | ||
| # Manage services only if writing to system-wide files | ||
| provision_services if $etc =~ /^\/etc/; | ||
| generate_bridge_configs($etc, $bridge); | ||
| generate_preup("$etc/wicked/scripts/gre_tunnel_preup.sh", $bridge); | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #!/usr/bin/env perl | ||
| # Copyright SUSE LLC | ||
| # SPDX-License-Identifier: MIT | ||
|
|
||
| use Test::Most; | ||
| use Test::Warnings ':report_warnings'; | ||
| use Mojo::File qw(tempdir path); | ||
| use FindBin; | ||
|
|
||
| subtest 'Verify generated config files' => sub { | ||
| is(1, 1, 'Ensure we have a check to avoid prove breaking'); # XXX | ||
| my $script = path("$FindBin::Bin/../openqa-prepare-mm-setup"); | ||
| my $etc = tempdir("/tmp/$FindBin::Script-XXXX"); | ||
| path($etc)->child('firewalld/zones')->make_path; | ||
| path($etc)->child('sysconfig/network')->make_path; | ||
| path($etc)->child('wicked/scripts')->make_path; | ||
| qx($^X $script $etc); | ||
| }; | ||
|
|
||
| done_testing; |
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.
Uh oh!
There was an error while loading. Please reload this page.