Skip to content

Commit

Permalink
Add assertions to 002 and 003 e2e test scripts (#216)
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Morales <v.morales@samsung.com>
  • Loading branch information
electrocucaracha committed Nov 16, 2023
1 parent e50bda7 commit 0dea816
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 59 deletions.
5 changes: 5 additions & 0 deletions e2e/provision/hacks/inter-connect_workers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
##

set -o pipefail
set -o errexit
set -o nounset
[[ ${DEBUG:-false} != "true" ]] || set -o xtrace

export HOME=${HOME:-/home/ubuntu/}
export E2EDIR=${E2EDIR:-$HOME/test-infra/e2e}
export TESTDIR=${TESTDIR:-$E2EDIR/tests}
export LIBDIR=${LIBDIR:-$E2EDIR/lib}

# shellcheck source=e2e/lib/k8s.sh
source "${LIBDIR}/k8s.sh"

kubeconfig="$HOME/.kube/config"

workers=""
Expand Down
6 changes: 4 additions & 2 deletions e2e/provision/hacks/network-topo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
##

set -o pipefail
set -o errexit
set -o nounset
[[ ${DEBUG:-false} != "true" ]] || set -o xtrace

export HOME=${HOME:-/home/ubuntu/}
export E2EDIR=${E2EDIR:-$HOME/test-infra/e2e}
export TESTDIR=${TESTDIR:-$E2EDIR/tests}
export LIBDIR=${LIBDIR:-$E2EDIR/lib}

export LEAF_IP=$(docker inspect net-free5gc-net-leaf -f '{{.NetworkSettings.Networks.kind.IPAddress}}')
kubeconfig="$HOME/.kube/config"

envsubst <"$TESTDIR/003-network-topo.tmpl" >"$TESTDIR/003-network-topo.yaml"
envsubst <"$TESTDIR/002-network-topo.tmpl" | kubectl --kubeconfig $kubeconfig apply -f -
20 changes: 7 additions & 13 deletions e2e/provision/hacks/vlan-interfaces.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,17 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
##

set -o pipefail
set -o errexit
set -o nounset
[[ ${DEBUG:-false} != "true" ]] || set -o xtrace
export HOME=${HOME:-/home/ubuntu/}
export E2EDIR=${E2EDIR:-$HOME/test-infra/e2e}
export TESTDIR=${TESTDIR:-$E2EDIR/tests}
export LIBDIR=${LIBDIR:-$E2EDIR/lib}
source "${LIBDIR}/k8s.sh"

kubeconfig="$HOME/.kube/config"
for cluster in $(kubectl get clusters.cluster.x-k8s.io -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' --sort-by=.metadata.name --kubeconfig "$kubeconfig"); do
_kubeconfig=$(k8s_get_capi_kubeconfig "$cluster")
workers=$(kubectl get nodes -l node-role.kubernetes.io/control-plane!= -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' --kubeconfig "$_kubeconfig")
for worker in $workers; do
for i in {2..4}; do
docker exec "$worker" ip link add link eth1 name "eth1.$i" type vlan id "$i"
docker exec "$worker" ip link set up "eth1.$i"
done

for worker in $(kubectl get machines -l cluster.x-k8s.io/control-plane!= -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' --kubeconfig "$kubeconfig"); do
for i in {2..4}; do
docker exec "$worker" ip link add link eth1 name "eth1.$i" type vlan id "$i"
docker exec "$worker" ip link set up "eth1.$i"
done
done
10 changes: 10 additions & 0 deletions e2e/tests/002-edge-clusters.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
---
# SPDX-license-identifier: Apache-2.0
##############################################################################
# Copyright (c) 2023 The Nephio Authors.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

apiVersion: config.porch.kpt.dev/v1alpha2
kind: PackageVariantSet
metadata:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,41 @@
---
# SPDX-license-identifier: Apache-2.0
##############################################################################
# Copyright (c) 2023 The Nephio Authors.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

apiVersion: topo.nephio.org/v1alpha1
kind: RawTopology
metadata:
name: nephio
spec:
nodes:
srl:
srl:
address: $LEAF_IP:57400
provider: srl.nokia.com
mgmt:
mgmt:
provider: docker.io
regional:
regional:
provider: docker.io
labels:
nephio.org/cluster-name: regional
edge01:
edge01:
provider: docker.io
labels:
nephio.org/cluster-name: edge01
edge02:
edge02:
provider: docker.io
labels:
nephio.org/cluster-name: edge02
links:
- endpoints:
- endpoints:
- { nodeName: srl, interfaceName: e1-1}
- { nodeName: edge01, interfaceName: eth1}
- endpoints:
- endpoints:
- { nodeName: srl, interfaceName: e1-2}
- { nodeName: edge02, interfaceName: eth1}
- endpoints:
Expand Down
24 changes: 24 additions & 0 deletions e2e/tests/002-network.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
# SPDX-license-identifier: Apache-2.0
##############################################################################
# Copyright (c) 2023 The Nephio Authors.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

apiVersion: config.porch.kpt.dev/v1alpha1
kind: PackageVariant
metadata:
name: network
spec:
upstream:
repo: nephio-example-packages
package: network
revision: v1
downstream:
repo: mgmt
package: network
annotations:
approval.nephio.org/policy: initial
19 changes: 19 additions & 0 deletions e2e/tests/002-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
# SPDX-license-identifier: Apache-2.0
##############################################################################
# Copyright (c) 2023 The Nephio Authors.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

apiVersion: v1
kind: Secret
metadata:
name: srl.nokia.com
namespace: default
type: kubernetes.io/basic-auth
stringData:
username: admin
password: NokiaSrl1!
24 changes: 20 additions & 4 deletions e2e/tests/002.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,41 @@ export LIBDIR=${LIBDIR:-$E2EDIR/lib}
# shellcheck source=e2e/lib/k8s.sh
source "${LIBDIR}/k8s.sh"

# shellcheck source=e2e/lib/kpt.sh
source "${LIBDIR}/kpt.sh"

# shellcheck source=e2e/lib/capi.sh
source "${LIBDIR}/capi.sh"

k8s_apply "$TESTDIR/002-edge-clusters.yaml"

# Wait for cluster resources creation
for cluster in edge01 edge02; do
k8s_wait_exists "workloadcluster" "$cluster"
k8s_wait_exists "packagevariant" "edge-clusters-mgmt-$cluster"
k8s_wait_exists "cl" "$cluster"
done

# Wait for cluster readiness
kubeconfig="$HOME/.kube/config"
for cluster in $(kubectl get cl -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' --kubeconfig "$kubeconfig"); do
k8s_wait_ready "cl" "$cluster"
for machineset in $(kubectl get machineset -l cluster.x-k8s.io/cluster-name="$cluster" -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' --kubeconfig "$kubeconfig"); do
k8s_wait_ready "machineset" "$machineset"
done
capi_cluster_ready "$cluster"
done

# Inter-connect worker nodes
"$E2EDIR/provision/hacks/inter-connect_workers.sh"

# Configure VLAN interfaces
"$E2EDIR/provision/hacks/vlan-interfaces.sh"

# Create network package variant
k8s_apply "$TESTDIR/002-network.yaml"

# Provide a secret for external backend connection
k8s_apply "$TESTDIR/002-secret.yaml"

k8s_wait_ready "packagevariant" "network"
kpt_wait_pkg "mgmt" "network"

# Generate a RawTopology to interconnect clusters
"$E2EDIR/provision/hacks/network-topo.sh"
14 changes: 0 additions & 14 deletions e2e/tests/003-network.yaml

This file was deleted.

9 changes: 0 additions & 9 deletions e2e/tests/003-secret.yaml

This file was deleted.

30 changes: 20 additions & 10 deletions e2e/tests/003.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,32 @@ export LIBDIR=${LIBDIR:-$E2EDIR/lib}
# shellcheck source=e2e/lib/k8s.sh
source "${LIBDIR}/k8s.sh"

k8s_apply "$TESTDIR/003-network.yaml"
# shellcheck source=e2e/lib/kpt.sh
source "${LIBDIR}/kpt.sh"

k8s_wait_ready "packagevariant" "network"
# shellcheck source=e2e/lib/porch.sh
source "${LIBDIR}/porch.sh"

## Apply the network topology
k8s_apply "$TESTDIR/003-secret.yaml"
# shellcheck source=e2e/lib/_assertions.sh
source "${LIBDIR}/_assertions.sh"

"$E2EDIR/provision/hacks/network-topo.sh"

k8s_apply "$TESTDIR/003-network-topo.yaml"
pkg_rev=$(kpt alpha rpkg clone -n default https://github.com/nephio-project/free5gc-packages.git/free5gc-cp@v1 --repository regional free5gc-cp | cut -f 1 -d ' ')
k8s_wait_exists "packagerev" "$pkg_rev"

upstream_pkg_rev=$(kpt alpha rpkg get --name free5gc-cp --revision v1 -o jsonpath='{.metadata.name}')
pkg_rev=$(kpt alpha rpkg clone -n default "$upstream_pkg_rev" --repository regional free5gc-cp | cut -f 1 -d ' ')
porch_wait_log_entry "Creating packagerev default/regional-"
assert_lifecycle_equals "$pkg_rev" "Draft"
assert_branch_exists "drafts/free5gc-cp/v1" "nephio/regional"
assert_commit_msg_in_branch "Intermediate commit" "drafts/free5gc-cp/v1" "nephio/regional"

kpt alpha rpkg propose -n default "$pkg_rev"
k8s_wait_exists "packagerev" "$pkg_rev"
porch_wait_log_entry "Update.*packagerevisions/${pkg_rev},"
assert_lifecycle_equals "$pkg_rev" "Proposed"
assert_branch_exists "proposed/free5gc-cp/v1" "nephio/regional"
assert_commit_msg_in_branch "Intermediate commit" "proposed/free5gc-cp/v1" "nephio/regional"

kpt alpha rpkg approve -n default "$pkg_rev"
porch_wait_log_entry "Update.*/${pkg_rev}.*/approval"
assert_lifecycle_equals "$pkg_rev" "Published"

kpt_wait_pkg "regional" "free5gc-cp"
k8s_wait_ready_replicas "statefulset" "mongodb" "$(k8s_get_capi_kubeconfig "regional")" "free5gc-cp"

0 comments on commit 0dea816

Please sign in to comment.