Skip to content

Commit 54fba50

Browse files
committed
chore: add multi VPC attachment test
Signed-off-by: Pau Capdevila <[email protected]>
1 parent f4531df commit 54fba50

File tree

3 files changed

+512
-186
lines changed

3 files changed

+512
-186
lines changed

cmd/hhfab/main.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -913,21 +913,27 @@ func Run(ctx context.Context) error {
913913
Aliases: []string{"mode"},
914914
Usage: "VPC mode: empty (l2vni) by default or l3vni, etc",
915915
},
916+
&cli.IntFlag{
917+
Name: "servers-with-multi-vpc",
918+
Usage: "number of servers that get attached to multiple VPCs (primary+next pattern)",
919+
Value: 0,
920+
},
916921
}),
917922
Before: before(false),
918923
Action: func(c *cli.Context) error {
919924
if err := hhfab.DoVLABSetupVPCs(ctx, workDir, cacheDir, hhfab.SetupVPCsOpts{
920-
WaitSwitchesReady: c.Bool("wait-switches-ready"),
921-
ForceCleanup: c.Bool("force-cleanup"),
922-
VLANNamespace: c.String("vlanns"),
923-
IPv4Namespace: c.String("ipns"),
924-
ServersPerSubnet: c.Int("servers-per-subnet"),
925-
SubnetsPerVPC: c.Int("subnets-per-vpc"),
926-
DNSServers: c.StringSlice("dns-servers"),
927-
TimeServers: c.StringSlice("time-servers"),
928-
InterfaceMTU: uint16(c.Uint("interface-mtu")), //nolint:gosec
929-
HashPolicy: c.String(FlagHashPolicy),
930-
VPCMode: vpcapi.VPCMode(handleL2VNI(c.String(FlagNameVPCMode))),
925+
WaitSwitchesReady: c.Bool("wait-switches-ready"),
926+
ForceCleanup: c.Bool("force-cleanup"),
927+
VLANNamespace: c.String("vlanns"),
928+
IPv4Namespace: c.String("ipns"),
929+
ServersPerSubnet: c.Int("servers-per-subnet"),
930+
SubnetsPerVPC: c.Int("subnets-per-vpc"),
931+
DNSServers: c.StringSlice("dns-servers"),
932+
TimeServers: c.StringSlice("time-servers"),
933+
InterfaceMTU: uint16(c.Uint("interface-mtu")), //nolint:gosec
934+
HashPolicy: c.String(FlagHashPolicy),
935+
VPCMode: vpcapi.VPCMode(handleL2VNI(c.String(FlagNameVPCMode))),
936+
ServersWithMultiVPC: c.Int("servers-with-multi-vpc"),
931937
}); err != nil {
932938
return fmt.Errorf("setup-vpcs: %w", err)
933939
}

pkg/hhfab/hhnet.sh

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ function setup_vlan() {
4444
sudo ip l s "$iface_name.$vlan_id" up
4545
}
4646

47+
function add_vlan_to_bond() {
48+
local vlan_id=$1
49+
local bond_name=$2
50+
51+
sudo ip l a link "$bond_name" name "$bond_name.$vlan_id" type vlan id "$vlan_id"
52+
sudo ip l s "$bond_name.$vlan_id" up
53+
}
54+
4755
function get_ip() {
4856
local iface_name=$1
4957
local ip=""
@@ -67,15 +75,18 @@ function get_ip() {
6775
# hhnet cleanup
6876
# hhnet bond 1000 layer2+3 enp2s1 enp2s2 enp2s3 enp2s4
6977
# hhnet vlan 1000 enp2s1
78+
# hhnet addvlan 1001 bond0
7079

7180
function usage() {
72-
echo "Usage: $0 <cleanup|bond|vlan> [<args> ...]" >&2
81+
echo "Usage: $0 <cleanup|bond|vlan|addvlan> [<args> ...]" >&2
7382
echo " Cleanup all interfaces (enp2s1-9, bond0-3, vlans 1000-1020): " >&2
7483
echo " hhnet cleanup" >&2
7584
echo " Setup bond from provided interfaces (at least one) and vlan on top of it" >&2
7685
echo " hhnet bond 1000 layer2+3 enp2s1 enp2s2 enp2s3 enp2s4" >&2
7786
echo " Setup vlan on top of provided interface (exactly one)" >&2
7887
echo " hhnet vlan 1000 enp2s1" >&2
88+
echo " Add vlan to existing bond" >&2
89+
echo " hhnet addvlan 1001 bond0" >&2
7990
}
8091

8192
if [ "$#" -lt 1 ]; then
@@ -107,6 +118,16 @@ elif [ "$1" == "vlan" ]; then
107118
setup_vlan "$3" "$2"
108119
get_ip "$3"."$2"
109120

121+
exit 0
122+
elif [ "$1" == "addvlan" ]; then
123+
if [ "$#" -ne 3 ]; then
124+
echo "Usage: $0 addvlan <vlan_id> <bond_name>" >&2
125+
exit 1
126+
fi
127+
128+
add_vlan_to_bond "$2" "$3"
129+
get_ip "$3"."$2"
130+
110131
exit 0
111132
else
112133
usage

0 commit comments

Comments
 (0)