Merge "Update host_providers/vagrant/setup.sh for virtualbox"
[multicloud/k8s.git] / kud / tests / ovn_provider_nw_test.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2018
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 set -o errexit
12 set -o nounset
13 set -o pipefail
14
15 source _common.sh
16 source _common_test.sh
17 source _functions.sh
18
19 # populate_CSAR_ovn4nfv() - Create content used for OVN4NFV functional test
20 function populate_CSAR_provider_network {
21     local csar_id=$1
22
23     _checks_args $csar_id
24     pushd ${CSAR_DIR}/${csar_id}
25
26     cat << MULTUS_NET > onap-ovn4nfvk8s-network.yaml
27 apiVersion: "k8s.cni.cncf.io/v1"
28 kind: NetworkAttachmentDefinition
29 metadata:
30   name: $ovn_multus_network_name
31 spec:
32   config: '{
33       "cniVersion": "0.3.1",
34       "name": "ovn4nfv-k8s-plugin",
35       "type": "ovn4nfvk8s-cni"
36     }'
37 MULTUS_NET
38
39     cat << NETWORK > ovn-virt-net1.yaml
40 apiVersion: v1
41 kind: onapNetwork
42 metadata:
43   name: ovn-virt-net1
44   cnitype : ovn4nfvk8s
45 spec:
46   name: ovn-virt-net1
47   subnet: 10.1.20.0/24
48   gateway: 10.1.20.1/24
49 NETWORK
50
51     cat << NETWORK > ovn-virt-net2.yaml
52 apiVersion: v1
53 kind: onapNetwork
54 metadata:
55   name: ovn-virt-net2
56   cnitype : ovn4nfvk8s
57 spec:
58   name: ovn-virt-net2
59   subnet: 10.1.21.0/24
60   gateway: 10.1.21.1/24
61 NETWORK
62
63     cat << DEPLOYMENT > firewall.yaml
64 apiVersion: apps/v1
65 kind: Deployment
66 metadata:
67   name: firewall
68   labels:
69     app: ovn4nfv
70 spec:
71   replicas: 1
72   selector:
73     matchLabels:
74       app: ovn4nfv
75   template:
76     metadata:
77       labels:
78         app: ovn4nfv
79       annotations:
80         k8s.v1.cni.cncf.io/networks: '[{ "name": "$ovn_multus_network_name"}]'
81         ovnNetwork: '[ { "name": ""ovn-virt-net1"", "interface": "net0" , "defaultGateway": "false", "ipAddress":"10.1.20.2"},
82                       { "name": "prod-net1", "interface": "net1", "defaultGateway": "false", "ipAddress":"10.1.5.1/24"}]'
83         ovnNetworkRoutes: '[{ "dst": "0.0.0.0/0", "gw": "10.1.20.3", "dev": "net0" }]'
84
85     spec:
86       containers:
87       - name: firewall
88         image: "busybox"
89         command: ["top"]
90         stdin: true
91         tty: true
92 DEPLOYMENT
93
94     cat << DEPLOYMENT > webcache.yaml
95 apiVersion: apps/v1
96 kind: Deployment
97 metadata:
98   name: webcache
99   labels:
100     app: ovn4nfv
101 spec:
102   replicas: 1
103   selector:
104     matchLabels:
105       app: ovn4nfv
106   template:
107     metadata:
108       labels:
109         app: ovn4nfv
110       annotations:
111         k8s.v1.cni.cncf.io/networks: '[{ "name": "$ovn_multus_network_name"}]'
112         ovnNetwork: '[{ "name": "ovn-virt-net1", "interface": "net0" , "defaultGateway": "false", "ipAddress":"10.1.20.3"},
113                       { "name": "ovn-virt-net2", "interface": "net1" , "defaultGateway": "false", "ipAddress":"10.1.21.2"}]'
114         ovnNetworkRoutes: '[{ "dst": "10.1.5.0/24", "gw": "10.1.20.2", "dev": "net0" },
115                             { "dst": "0.0.0.0/0", "gw": "10.1.21.3", "dev": "net1" }]'
116
117     spec:
118       containers:
119       - name: webcache
120         image: "busybox"
121         command: ["top"]
122         stdin: true
123         tty: true
124 DEPLOYMENT
125
126     cat << DEPLOYMENT > sdwan.yaml
127 apiVersion: apps/v1
128 kind: Deployment
129 metadata:
130   name: sdwan
131   labels:
132     app: ovn4nfv
133 spec:
134   replicas: 1
135   selector:
136     matchLabels:
137       app: ovn4nfv
138   template:
139     metadata:
140       labels:
141         app: ovn4nfv
142       annotations:
143         k8s.v1.cni.cncf.io/networks: '[{ "name": "$ovn_multus_network_name"}]'
144         ovnNetwork: '[ { "name": ""ovn-virt-net2"", "interface": "net0" , "defaultGateway": "false", "ipAddress":"10.1.21.3"},
145                       { "name": "prod-net2", "interface": "net1", "defaultGateway": "false", "ipAddress":"10.1.10.2/24"}]'
146         ovnNetworkRoutes: '[{ "dst": "0.0.0.0/0", "gw": "10.1.10.1", "dev": "net1" },
147                             { "dst": "10.1.5.0/24", "gw": "10.1.21.2", "dev": "net0" },
148                             { "dst": "10.1.20.0/24", "gw": "10.1.21.2", "dev": "net0" }]'
149
150     spec:
151       containers:
152       - name: sdwan
153         image: "busybox"
154         command: ["top"]
155         stdin: true
156         tty: true
157 DEPLOYMENT
158     popd
159 }
160
161 csar_id=d5718572-3b9a-11e9-b210-d663bd873dda
162 # Setup
163 install_ovn_deps
164 populate_CSAR_provider_network $csar_id
165
166 pushd ${CSAR_DIR}/${csar_id}
167 for net in ovn-virt-net1 ovn-virt-net2; do
168     cleanup_network $net.yaml
169     echo "Create OVN Network $net network"
170     init_network $net.yaml
171 done
172 kubectl apply -f onap-ovn4nfvk8s-network.yaml
173 setup firewall webcache sdwan
174
175 # Test
176 deployment_pod=$(kubectl get pods | grep  firewall | awk '{print $1}')
177 echo "===== $deployment_pod details ====="
178 kubectl exec -it $deployment_pod -- ip a
179 multus_nic=$(kubectl exec -it $deployment_pod -- ifconfig | grep "net1")
180 if [ -z "$multus_nic" ]; then
181     echo "The $deployment_pod pod doesn't contain the net1 nic"
182     exit 1
183 fi
184
185 # Teardown
186 teardown firewall webcache sdwan
187 cleanup_network ovn-virt-net1.yaml
188 cleanup_network ovn-virt-net2.yaml
189 popd
190
191
192