8da7471e5a793ad19469b652dd33f4318fb59ac9
[multicloud/k8s.git] / kud / tests / _common.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 packetgen_deployment_name=packetgen
16 sink_deployment_name=sink
17 firewall_deployment_name=firewall
18 image_name=virtlet.cloud/ubuntu/16.04
19 multus_deployment_name=multus-deployment
20 virtlet_image=virtlet.cloud/fedora
21 virtlet_deployment_name=virtlet-deployment
22 plugin_deployment_name=plugin-deployment
23 plugin_service_name=plugin-service
24 ovn4nfv_deployment_name=ovn4nfv-deployment
25 onap_private_net=onap-private-net
26 unprotected_private_net=unprotected-private-net
27 protected_private_net=protected-private-net
28 ovn_multus_network_name=ovn-networkobj
29 rbd_metadata=rbd_metatada.json
30 rbp_metadata=rbp_metatada.json
31 rbp_instance=rbp_instance.json
32
33 # vFirewall vars
34 demo_artifacts_version=1.5.0
35 vfw_private_ip_0='192.168.10.3'
36 vfw_private_ip_1='192.168.20.2'
37 vfw_private_ip_2='10.10.100.3'
38 vpg_private_ip_0='192.168.10.2'
39 vpg_private_ip_1='10.0.100.2'
40 vsn_private_ip_0='192.168.20.3'
41 vsn_private_ip_1='10.10.100.4'
42 dcae_collector_ip='10.0.4.1'
43 dcae_collector_port='8081'
44 protected_net_gw='192.168.20.100'
45 protected_net_cidr='192.168.20.0/24'
46 protected_private_net_cidr='192.168.10.0/24'
47 onap_private_net_cidr='10.10.0.0/16'
48 sink_ipaddr='192.168.20.250'
49
50 # populate_CSAR_containers_vFW() - This function creates the content of CSAR file
51 # required for vFirewal using only containers
52 function populate_CSAR_containers_vFW {
53     local csar_id=$1
54
55     _checks_args $csar_id
56     pushd ${CSAR_DIR}/${csar_id}
57
58     cat << META > metadata.yaml
59 resources:
60   network:
61     - $unprotected_private_net.yaml
62     - $protected_private_net.yaml
63     - $onap_private_net.yaml
64   deployment:
65     - $packetgen_deployment_name.yaml
66     - $firewall_deployment_name.yaml
67     - $sink_deployment_name.yaml
68 META
69
70     cat << NET > $unprotected_private_net.yaml
71 apiVersion: "k8s.cni.cncf.io/v1"
72 kind: NetworkAttachmentDefinition
73 metadata:
74   name: $unprotected_private_net
75 spec:
76   config: '{
77     "name": "unprotected",
78     "type": "bridge",
79     "ipam": {
80         "type": "host-local",
81         "subnet": "$protected_private_net_cidr"
82     }
83 }'
84 NET
85
86     cat << NET > $protected_private_net.yaml
87 apiVersion: "k8s.cni.cncf.io/v1"
88 kind: NetworkAttachmentDefinition
89 metadata:
90   name: $protected_private_net
91 spec:
92   config: '{
93     "name": "protected",
94     "type": "bridge",
95     "ipam": {
96         "type": "host-local",
97         "subnet": "$protected_net_cidr"
98     }
99 }'
100 NET
101
102     cat << NET > $onap_private_net.yaml
103 apiVersion: "k8s.cni.cncf.io/v1"
104 kind: NetworkAttachmentDefinition
105 metadata:
106   name: $onap_private_net
107 spec:
108   config: '{
109     "name": "onap",
110     "type": "bridge",
111     "ipam": {
112         "type": "host-local",
113         "subnet": "$onap_private_net_cidr"
114     }
115 }'
116 NET
117
118     cat << DEPLOYMENT > $packetgen_deployment_name.yaml
119 apiVersion: apps/v1
120 kind: Deployment
121 metadata:
122   name: $packetgen_deployment_name
123   labels:
124     app: vFirewall
125 spec:
126   replicas: 1
127   selector:
128     matchLabels:
129       app: vFirewall
130   template:
131     metadata:
132       labels:
133         app: vFirewall
134       annotations:
135         k8s.v1.cni.cncf.io/networks: '[
136             { "name": "$unprotected_private_net", "interfaceRequest": "eth1" },
137             { "name": "$onap_private_net", "interfaceRequest": "eth2" }
138         ]'
139     spec:
140       containers:
141       - name: $packetgen_deployment_name
142         image: electrocucaracha/packetgen
143         imagePullPolicy: IfNotPresent
144         tty: true
145         stdin: true
146         resources:
147           limits:
148             memory: 256Mi
149 DEPLOYMENT
150
151     cat << DEPLOYMENT > $firewall_deployment_name.yaml
152 apiVersion: apps/v1
153 kind: Deployment
154 metadata:
155   name: $firewall_deployment_name
156   labels:
157     app: vFirewall
158 spec:
159   replicas: 1
160   selector:
161     matchLabels:
162       app: vFirewall
163   template:
164     metadata:
165       labels:
166         app: vFirewall
167       annotations:
168         k8s.v1.cni.cncf.io/networks: '[
169             { "name": "$unprotected_private_net", "interfaceRequest": "eth1" },
170             { "name": "$protected_private_net", "interfaceRequest": "eth2" },
171             { "name": "$onap_private_net", "interfaceRequest": "eth3" }
172         ]'
173     spec:
174       containers:
175       - name: $firewall_deployment_name
176         image: electrocucaracha/firewall
177         imagePullPolicy: IfNotPresent
178         tty: true
179         stdin: true
180 DEPLOYMENT
181
182     cat << DEPLOYMENT > $sink_deployment_name.yaml
183 apiVersion: apps/v1
184 kind: Deployment
185 metadata:
186   name: $sink_deployment_name
187   labels:
188     app: vFirewall
189 spec:
190   replicas: 1
191   selector:
192     matchLabels:
193       app: vFirewall
194       context: darkstat
195   template:
196     metadata:
197       labels:
198         app: vFirewall
199         context: darkstat
200       annotations:
201         k8s.v1.cni.cncf.io/networks: '[
202             { "name": "$protected_private_net", "interfaceRequest": "eth1" },
203             { "name": "$onap_private_net", "interfaceRequest": "eth2" }
204         ]'
205     spec:
206       containers:
207       - name: $sink_deployment_name
208         image: electrocucaracha/sink
209         imagePullPolicy: IfNotPresent
210         tty: true
211         stdin: true
212         securityContext:
213           privileged: true
214       - name: darkstat
215         image: electrocucaracha/darkstat
216         imagePullPolicy: IfNotPresent
217         tty: true
218         stdin: true
219         ports:
220           - containerPort: 667
221 DEPLOYMENT
222     popd
223 }
224
225 # populate_CSAR_vms_containers_vFW() - This function creates the content of CSAR file
226 # required for vFirewal using an hybrid combination between virtual machines and
227 # cotainers
228 function populate_CSAR_vms_containers_vFW {
229     local csar_id=$1
230     ssh_key=$(cat $HOME/.ssh/id_rsa.pub)
231
232     _checks_args $csar_id
233     pushd ${CSAR_DIR}/${csar_id}
234
235     cat << META > metadata.yaml
236 resources:
237   network:
238     - onap-ovn4nfvk8s-network.yaml
239   onapNetwork:
240     - $unprotected_private_net.yaml
241     - $protected_private_net.yaml
242     - $onap_private_net.yaml
243   deployment:
244     - $packetgen_deployment_name.yaml
245     - $firewall_deployment_name.yaml
246     - $sink_deployment_name.yaml
247   service:
248     - sink-service.yaml
249 META
250
251     cat << SERVICE > sink-service.yaml
252 apiVersion: v1
253 kind: Service
254 metadata:
255   name: sink-service
256 spec:
257   type: NodePort
258   ports:
259   - port: 667
260     nodePort: 30667
261   selector:
262     app: vFirewall
263     context: darkstat
264 SERVICE
265
266     cat << MULTUS_NET > onap-ovn4nfvk8s-network.yaml
267 apiVersion: "k8s.cni.cncf.io/v1"
268 kind: NetworkAttachmentDefinition
269 metadata:
270   name: $ovn_multus_network_name
271 spec:
272   config: '{
273       "cniVersion": "0.3.1",
274       "name": "ovn4nfv-k8s-plugin",
275       "type": "ovn4nfvk8s-cni"
276     }'
277 MULTUS_NET
278
279     cat << NET > $unprotected_private_net.yaml
280 apiVersion: k8s.plugin.opnfv.org/v1alpha1
281 kind: Network
282
283 metadata:
284   name: $unprotected_private_net
285 spec:
286   cniType : ovn4nfv
287   ipv4Subnets:
288   - subnet: $protected_private_net_cidr
289     name: subnet1
290     gateway: 192.168.10.1/24
291 NET
292
293     cat << NET > $protected_private_net.yaml
294 apiVersion: k8s.plugin.opnfv.org/v1alpha1
295 kind: Network
296 metadata:
297   name: $protected_private_net
298 spec:
299   cniType : ovn4nfv
300   ipv4Subnets:
301   - subnet: $protected_net_cidr
302     name: subnet1
303     gateway: $protected_net_gw/24
304 NET
305
306     cat << NET > $onap_private_net.yaml
307 apiVersion: k8s.plugin.opnfv.org/v1alpha1
308 kind: Network
309 metadata:
310   name: $onap_private_net
311 spec:
312   cniType : ovn4nfv
313   ipv4Subnets:
314   - subnet: $onap_private_net_cidr
315     name: subnet1
316     gateway: 10.10.0.1/16
317 NET
318
319     proxy="apt:"
320     cloud_init_proxy="
321             - export demo_artifacts_version=$demo_artifacts_version
322             - export vfw_private_ip_0=$vfw_private_ip_0
323             - export vsn_private_ip_0=$vsn_private_ip_0
324             - export protected_net_cidr=$protected_net_cidr
325             - export dcae_collector_ip=$dcae_collector_ip
326             - export dcae_collector_port=$dcae_collector_port
327             - export protected_net_gw=$protected_net_gw
328             - export protected_private_net_cidr=$protected_private_net_cidr
329             - export sink_ipaddr=$sink_ipaddr
330 "
331     if [[ -n "${http_proxy+x}" ]]; then
332         proxy+="
333             http_proxy: $http_proxy"
334         cloud_init_proxy+="
335             - export http_proxy=$http_proxy"
336     fi
337     if [[ -n "${https_proxy+x}" ]]; then
338         proxy+="
339             https_proxy: $https_proxy"
340         cloud_init_proxy+="
341             - export https_proxy=$https_proxy"
342     fi
343     if [[ -n "${no_proxy+x}" ]]; then
344         cloud_init_proxy+="
345             - export no_proxy=$no_proxy"
346     fi
347
348     cat << DEPLOYMENT > $packetgen_deployment_name.yaml
349 apiVersion: apps/v1
350 kind: Deployment
351 metadata:
352   name: $packetgen_deployment_name
353   labels:
354     app: vFirewall
355 spec:
356   replicas: 1
357   selector:
358     matchLabels:
359       app: vFirewall
360   template:
361     metadata:
362       labels:
363         app: vFirewall
364       annotations:
365         VirtletLibvirtCPUSetting: |
366           mode: host-model
367         VirtletCloudInitUserData: |
368           ssh_pwauth: True
369           users:
370           - name: admin
371             gecos: User
372             primary-group: admin
373             groups: users
374             sudo: ALL=(ALL) NOPASSWD:ALL
375             lock_passwd: false
376             # the password is "admin"
377             passwd: "\$6\$rounds=4096\$QA5OCKHTE41\$jRACivoPMJcOjLRgxl3t.AMfU7LhCFwOWv2z66CQX.TSxBy50JoYtycJXSPr2JceG.8Tq/82QN9QYt3euYEZW/"
378             ssh_authorized_keys:
379               $ssh_key
380           $proxy
381           runcmd:
382           $cloud_init_proxy
383             - wget -O - https://git.onap.org/multicloud/k8s/plain/kud/tests/vFW/$packetgen_deployment_name | sudo -E bash
384         VirtletSSHKeys: |
385           $ssh_key
386         VirtletRootVolumeSize: 5Gi
387         k8s.v1.cni.cncf.io/networks: '[{ "name": "$ovn_multus_network_name"}]'
388         k8s.plugin.opnfv.org/nfn-network: '{ "type": "ovn4nfv", "interface": [
389             { "name": "$unprotected_private_net", "ipAddress": "$vpg_private_ip_0", "interface": "eth1" , "defaultGateway": "false"},
390             { "name": "$onap_private_net", "ipAddress": "$vpg_private_ip_1", "interface": "eth2" , "defaultGateway": "false"}
391         ]}'
392         kubernetes.io/target-runtime: virtlet.cloud
393     spec:
394       affinity:
395         nodeAffinity:
396           requiredDuringSchedulingIgnoredDuringExecution:
397             nodeSelectorTerms:
398             - matchExpressions:
399               - key: extraRuntime
400                 operator: In
401                 values:
402                 - virtlet
403       containers:
404       - name: $packetgen_deployment_name
405         image: $image_name
406         imagePullPolicy: IfNotPresent
407         tty: true
408         stdin: true
409         ports:
410           - containerPort: 8183
411         resources:
412           limits:
413             memory: 4Gi
414 DEPLOYMENT
415
416     cat << DEPLOYMENT > $firewall_deployment_name.yaml
417 apiVersion: apps/v1
418 kind: Deployment
419 metadata:
420   name: $firewall_deployment_name
421   labels:
422     app: vFirewall
423 spec:
424   replicas: 1
425   selector:
426     matchLabels:
427       app: vFirewall
428   template:
429     metadata:
430       labels:
431         app: vFirewall
432       annotations:
433         VirtletLibvirtCPUSetting: |
434           mode: host-model
435         VirtletCloudInitUserData: |
436           ssh_pwauth: True
437           users:
438           - name: admin
439             gecos: User
440             primary-group: admin
441             groups: users
442             sudo: ALL=(ALL) NOPASSWD:ALL
443             lock_passwd: false
444             # the password is "admin"
445             passwd: "\$6\$rounds=4096\$QA5OCKHTE41\$jRACivoPMJcOjLRgxl3t.AMfU7LhCFwOWv2z66CQX.TSxBy50JoYtycJXSPr2JceG.8Tq/82QN9QYt3euYEZW/"
446             ssh_authorized_keys:
447               $ssh_key
448           $proxy
449           runcmd:
450             $cloud_init_proxy
451             - wget -O - https://git.onap.org/multicloud/k8s/plain/kud/tests/vFW/$firewall_deployment_name | sudo -E bash
452         VirtletSSHKeys: |
453           $ssh_key
454         VirtletRootVolumeSize: 5Gi
455         k8s.v1.cni.cncf.io/networks: '[{ "name": "$ovn_multus_network_name"}]'
456         k8s.plugin.opnfv.org/nfn-network: '{ "type": "ovn4nfv", "interface": [
457             { "name": "$unprotected_private_net", "ipAddress": "$vfw_private_ip_0", "interface": "eth1" , "defaultGateway": "false"},
458             { "name": "$protected_private_net", "ipAddress": "$vfw_private_ip_1", "interface": "eth2", "defaultGateway": "false" },
459             { "name": "$onap_private_net", "ipAddress": "$vfw_private_ip_2", "interface": "eth3" , "defaultGateway": "false"}
460         ]}'
461         kubernetes.io/target-runtime: virtlet.cloud
462     spec:
463       affinity:
464         nodeAffinity:
465           requiredDuringSchedulingIgnoredDuringExecution:
466             nodeSelectorTerms:
467             - matchExpressions:
468               - key: extraRuntime
469                 operator: In
470                 values:
471                 - virtlet
472       containers:
473       - name: $firewall_deployment_name
474         image: $image_name
475         imagePullPolicy: IfNotPresent
476         tty: true
477         stdin: true
478         resources:
479           limits:
480             memory: 4Gi
481 DEPLOYMENT
482
483     cat << CONFIGMAP > sink_configmap.yaml
484 apiVersion: v1
485 kind: ConfigMap
486 metadata:
487   name: sink-configmap
488 data:
489   protected_net_gw: $protected_net_gw
490   protected_private_net_cidr: $protected_private_net_cidr
491 CONFIGMAP
492
493     cat << DEPLOYMENT > $sink_deployment_name.yaml
494 apiVersion: apps/v1
495 kind: Deployment
496 metadata:
497   name: $sink_deployment_name
498   labels:
499     app: vFirewall
500 spec:
501   replicas: 1
502   selector:
503     matchLabels:
504       app: vFirewall
505       context: darkstat
506   template:
507     metadata:
508       labels:
509         app: vFirewall
510         context: darkstat
511       annotations:
512         k8s.v1.cni.cncf.io/networks: '[{ "name": "$ovn_multus_network_name"}]'
513         k8s.plugin.opnfv.org/nfn-network: '{ "type": "ovn4nfv", "interface": [
514             { "name": "$protected_private_net", "ipAddress": "$vsn_private_ip_0", "interface": "eth1", "defaultGateway": "false" },
515             { "name": "$onap_private_net", "ipAddress": "$vsn_private_ip_1", "interface": "eth2" , "defaultGateway": "false"}
516         ]}'
517     spec:
518       containers:
519       - name: $sink_deployment_name
520         image: rtsood/onap-vfw-demo-sink:0.2.0
521         envFrom:
522         - configMapRef:
523             name: sink-configmap
524         imagePullPolicy: Always
525         tty: true
526         stdin: true
527         securityContext:
528           privileged: true
529
530       - name: darkstat
531         image: electrocucaracha/darkstat
532         imagePullPolicy: IfNotPresent
533         tty: true
534         stdin: true
535         ports:
536           - containerPort: 667
537 DEPLOYMENT
538     popd
539 }
540
541 # populate_CSAR_vms_vFW() - This function creates the content of CSAR file
542 # required for vFirewal using only virtual machines
543 function populate_CSAR_vms_vFW {
544     local csar_id=$1
545     ssh_key=$(cat $HOME/.ssh/id_rsa.pub)
546
547     _checks_args $csar_id
548     pushd ${CSAR_DIR}/${csar_id}
549
550     cat << META > metadata.yaml
551 resources:
552   network:
553     - $unprotected_private_net.yaml
554     - $protected_private_net.yaml
555     - $onap_private_net.yaml
556   deployment:
557     - $packetgen_deployment_name.yaml
558     - $firewall_deployment_name.yaml
559     - $sink_deployment_name.yaml
560 META
561
562     cat << NET > $unprotected_private_net.yaml
563 apiVersion: "k8s.cni.cncf.io/v1"
564 kind: NetworkAttachmentDefinition
565 metadata:
566   name: $unprotected_private_net
567 spec:
568   config: '{
569     "name": "unprotected",
570     "type": "bridge",
571     "ipam": {
572         "type": "host-local",
573         "subnet": "$protected_private_net_cidr"
574     }
575 }'
576 NET
577
578     cat << NET > $protected_private_net.yaml
579 apiVersion: "k8s.cni.cncf.io/v1"
580 kind: NetworkAttachmentDefinition
581 metadata:
582   name: $protected_private_net
583 spec:
584   config: '{
585     "name": "protected",
586     "type": "bridge",
587     "ipam": {
588         "type": "host-local",
589         "subnet": "$protected_net_cidr"
590     }
591 }'
592 NET
593
594     cat << NET > $onap_private_net.yaml
595 apiVersion: "k8s.cni.cncf.io/v1"
596 kind: NetworkAttachmentDefinition
597 metadata:
598   name: $onap_private_net
599 spec:
600   config: '{
601     "name": "onap",
602     "type": "bridge",
603     "ipam": {
604         "type": "host-local",
605         "subnet": "$onap_private_net_cidr"
606     }
607 }'
608 NET
609
610     proxy="apt:"
611     cloud_init_proxy="
612             - export demo_artifacts_version=$demo_artifacts_version
613             - export vfw_private_ip_0=$vfw_private_ip_0
614             - export vsn_private_ip_0=$vsn_private_ip_0
615             - export protected_net_cidr=$protected_net_cidr
616             - export dcae_collector_ip=$dcae_collector_ip
617             - export dcae_collector_port=$dcae_collector_port
618             - export protected_net_gw=$protected_net_gw
619             - export protected_private_net_cidr=$protected_private_net_cidr
620 "
621     if [[ -n "${http_proxy+x}" ]]; then
622         proxy+="
623             http_proxy: $http_proxy"
624         cloud_init_proxy+="
625             - export http_proxy=$http_proxy"
626     fi
627     if [[ -n "${https_proxy+x}" ]]; then
628         proxy+="
629             https_proxy: $https_proxy"
630         cloud_init_proxy+="
631             - export https_proxy=$https_proxy"
632     fi
633     if [[ -n "${no_proxy+x}" ]]; then
634         cloud_init_proxy+="
635             - export no_proxy=$no_proxy"
636     fi
637
638     cat << DEPLOYMENT > $packetgen_deployment_name.yaml
639 apiVersion: apps/v1
640 kind: Deployment
641 metadata:
642   name: $packetgen_deployment_name
643   labels:
644     app: vFirewall
645 spec:
646   replicas: 1
647   selector:
648     matchLabels:
649       app: vFirewall
650   template:
651     metadata:
652       labels:
653         app: vFirewall
654       annotations:
655         VirtletLibvirtCPUSetting: |
656           mode: host-model
657         VirtletCloudInitUserData: |
658           ssh_pwauth: True
659           users:
660           - name: admin
661             gecos: User
662             primary-group: admin
663             groups: users
664             sudo: ALL=(ALL) NOPASSWD:ALL
665             lock_passwd: false
666             # the password is "admin"
667             passwd: "\$6\$rounds=4096\$QA5OCKHTE41\$jRACivoPMJcOjLRgxl3t.AMfU7LhCFwOWv2z66CQX.TSxBy50JoYtycJXSPr2JceG.8Tq/82QN9QYt3euYEZW/"
668             ssh_authorized_keys:
669               $ssh_key
670           $proxy
671           runcmd:
672           $cloud_init_proxy
673             - wget -O - https://git.onap.org/multicloud/k8s/plain/kud/tests/vFW/$packetgen_deployment_name | sudo -E bash
674         VirtletSSHKeys: |
675           $ssh_key
676         VirtletRootVolumeSize: 5Gi
677         k8s.v1.cni.cncf.io/networks: '[
678             { "name": "$unprotected_private_net", "interfaceRequest": "eth1" },
679             { "name": "$onap_private_net", "interfaceRequest": "eth2" }
680         ]'
681         kubernetes.io/target-runtime: virtlet.cloud
682     spec:
683       affinity:
684         nodeAffinity:
685           requiredDuringSchedulingIgnoredDuringExecution:
686             nodeSelectorTerms:
687             - matchExpressions:
688               - key: extraRuntime
689                 operator: In
690                 values:
691                 - virtlet
692       containers:
693       - name: $packetgen_deployment_name
694         image: $image_name
695         imagePullPolicy: IfNotPresent
696         tty: true
697         stdin: true
698         ports:
699           - containerPort: 8183
700         resources:
701           limits:
702             memory: 4Gi
703 DEPLOYMENT
704
705     cat << DEPLOYMENT > $firewall_deployment_name.yaml
706 apiVersion: apps/v1
707 kind: Deployment
708 metadata:
709   name: $firewall_deployment_name
710   labels:
711     app: vFirewall
712 spec:
713   replicas: 1
714   selector:
715     matchLabels:
716       app: vFirewall
717   template:
718     metadata:
719       labels:
720         app: vFirewall
721       annotations:
722         VirtletLibvirtCPUSetting: |
723           mode: host-model
724         VirtletCloudInitUserData: |
725           ssh_pwauth: True
726           users:
727           - name: admin
728             gecos: User
729             primary-group: admin
730             groups: users
731             sudo: ALL=(ALL) NOPASSWD:ALL
732             lock_passwd: false
733             # the password is "admin"
734             passwd: "\$6\$rounds=4096\$QA5OCKHTE41\$jRACivoPMJcOjLRgxl3t.AMfU7LhCFwOWv2z66CQX.TSxBy50JoYtycJXSPr2JceG.8Tq/82QN9QYt3euYEZW/"
735             ssh_authorized_keys:
736               $ssh_key
737           $proxy
738           runcmd:
739             $cloud_init_proxy
740             - wget -O - https://git.onap.org/multicloud/k8s/plain/kud/tests/vFW/$firewall_deployment_name | sudo -E bash
741         VirtletSSHKeys: |
742           $ssh_key
743         VirtletRootVolumeSize: 5Gi
744         k8s.v1.cni.cncf.io/networks: '[
745             { "name": "$unprotected_private_net", "interfaceRequest": "eth1" },
746             { "name": "$protected_private_net", "interfaceRequest": "eth2" },
747             { "name": "$onap_private_net", "interfaceRequest": "eth3" }
748         ]'
749         kubernetes.io/target-runtime: virtlet.cloud
750     spec:
751       affinity:
752         nodeAffinity:
753           requiredDuringSchedulingIgnoredDuringExecution:
754             nodeSelectorTerms:
755             - matchExpressions:
756               - key: extraRuntime
757                 operator: In
758                 values:
759                 - virtlet
760       containers:
761       - name: $firewall_deployment_name
762         image: $image_name
763         imagePullPolicy: IfNotPresent
764         tty: true
765         stdin: true
766         resources:
767           limits:
768             memory: 4Gi
769 DEPLOYMENT
770
771     cat << DEPLOYMENT > $sink_deployment_name.yaml
772 apiVersion: apps/v1
773 kind: Deployment
774 metadata:
775   name: $sink_deployment_name
776   labels:
777     app: vFirewall
778 spec:
779   replicas: 1
780   selector:
781     matchLabels:
782       app: vFirewall
783   template:
784     metadata:
785       labels:
786         app: vFirewall
787       annotations:
788         VirtletLibvirtCPUSetting: |
789           mode: host-model
790         VirtletCloudInitUserData: |
791           ssh_pwauth: True
792           users:
793           - name: admin
794             gecos: User
795             primary-group: admin
796             groups: users
797             sudo: ALL=(ALL) NOPASSWD:ALL
798             lock_passwd: false
799             # the password is "admin"
800             passwd: "\$6\$rounds=4096\$QA5OCKHTE41\$jRACivoPMJcOjLRgxl3t.AMfU7LhCFwOWv2z66CQX.TSxBy50JoYtycJXSPr2JceG.8Tq/82QN9QYt3euYEZW/"
801             ssh_authorized_keys:
802               $ssh_key
803           $proxy
804           runcmd:
805             $cloud_init_proxy
806             - wget -O - https://git.onap.org/multicloud/k8s/plain/kud/tests/vFW/$sink_deployment_name | sudo -E bash
807         VirtletSSHKeys: |
808           $ssh_key
809         VirtletRootVolumeSize: 5Gi
810         k8s.v1.cni.cncf.io/networks: '[
811             { "name": "$protected_private_net", "interfaceRequest": "eth1" },
812             { "name": "$onap_private_net", "interfaceRequest": "eth2" }
813         ]'
814         kubernetes.io/target-runtime: virtlet.cloud
815     spec:
816       affinity:
817         nodeAffinity:
818           requiredDuringSchedulingIgnoredDuringExecution:
819             nodeSelectorTerms:
820             - matchExpressions:
821               - key: extraRuntime
822                 operator: In
823                 values:
824                 - virtlet
825       containers:
826       - name: $sink_deployment_name
827         image: $image_name
828         imagePullPolicy: IfNotPresent
829         tty: true
830         stdin: true
831         ports:
832           - containerPort: 667
833         resources:
834           limits:
835             memory: 4Gi
836 DEPLOYMENT
837     popd
838 }
839
840 # populate_CSAR_multus() - This function creates the content of CSAR file
841 # required for testing Multus feature
842 function populate_CSAR_multus {
843     local csar_id=$1
844
845     _checks_args $csar_id
846     pushd ${CSAR_DIR}/${csar_id}
847
848     cat << META > metadata.yaml
849 resources:
850   network:
851     - bridge-network.yaml
852   deployment:
853     - $multus_deployment_name.yaml
854 META
855
856     cat << NET > bridge-network.yaml
857 apiVersion: "k8s.cni.cncf.io/v1"
858 kind: NetworkAttachmentDefinition
859 metadata:
860   name: bridge-conf
861 spec:
862   config: '{
863     "cniVersion": "0.3.0",
864     "name": "mynet",
865     "type": "bridge",
866     "ipam": {
867         "type": "host-local",
868         "subnet": "$onap_private_net_cidr"
869     }
870 }'
871 NET
872
873     cat << DEPLOYMENT > $multus_deployment_name.yaml
874 apiVersion: apps/v1
875 kind: Deployment
876 metadata:
877   name: $multus_deployment_name
878   labels:
879     app: multus
880 spec:
881   replicas: 1
882   selector:
883     matchLabels:
884       app: multus
885   template:
886     metadata:
887       labels:
888         app: multus
889       annotations:
890         k8s.v1.cni.cncf.io/networks: '[
891           { "name": "bridge-conf", "interfaceRequest": "eth1" },
892           { "name": "bridge-conf", "interfaceRequest": "eth2" }
893         ]'
894     spec:
895       containers:
896       - name: $multus_deployment_name
897         image: "busybox"
898         command: ["top"]
899         stdin: true
900         tty: true
901 DEPLOYMENT
902     popd
903 }
904
905 # populate_CSAR_virtlet() - This function creates the content of CSAR file
906 # required for testing Virtlet feature
907 function populate_CSAR_virtlet {
908     local csar_id=$1
909
910     _checks_args $csar_id
911     pushd ${CSAR_DIR}/${csar_id}
912
913     cat << META > metadata.yaml
914 resources:
915   deployment:
916     - $virtlet_deployment_name.yaml
917 META
918
919     cat << DEPLOYMENT > $virtlet_deployment_name.yaml
920 apiVersion: apps/v1
921 kind: Deployment
922 metadata:
923   name: $virtlet_deployment_name
924   labels:
925     app: virtlet
926 spec:
927   replicas: 1
928   selector:
929     matchLabels:
930       app: virtlet
931   template:
932     metadata:
933       labels:
934         app: virtlet
935       annotations:
936         VirtletLibvirtCPUSetting: |
937           mode: host-passthrough
938         # This tells CRI Proxy that this pod belongs to Virtlet runtime
939         kubernetes.io/target-runtime: virtlet.cloud
940         VirtletCloudInitUserData: |
941           ssh_pwauth: True
942           users:
943           - name: testuser
944             gecos: User
945             primary-group: testuser
946             groups: users
947             lock_passwd: false
948             shell: /bin/bash
949             # the password is "testuser"
950             passwd: "\$6\$rounds=4096\$wPs4Hz4tfs\$a8ssMnlvH.3GX88yxXKF2cKMlVULsnydoOKgkuStTErTq2dzKZiIx9R/pPWWh5JLxzoZEx7lsSX5T2jW5WISi1"
951             sudo: ALL=(ALL) NOPASSWD:ALL
952           runcmd:
953             - echo hello world
954     spec:
955       affinity:
956         nodeAffinity:
957           requiredDuringSchedulingIgnoredDuringExecution:
958             nodeSelectorTerms:
959             - matchExpressions:
960               - key: extraRuntime
961                 operator: In
962                 values:
963                 - virtlet
964       containers:
965       - name: $virtlet_deployment_name
966         # This specifies the image to use.
967         # virtlet.cloud/ prefix is used by CRI proxy, the remaining part
968         # of the image name is prepended with https:// and used to download the image
969         image: $virtlet_image
970         imagePullPolicy: IfNotPresent
971         # tty and stdin required for "kubectl attach -t" to work
972         tty: true
973         stdin: true
974         resources:
975           limits:
976             # This memory limit is applied to the libvirt domain definition
977             memory: 160Mi
978 DEPLOYMENT
979     popd
980 }
981
982 # populate_CSAR_plugin()- Creates content used for Plugin functional tests
983 function populate_CSAR_plugin {
984     local csar_id=$1
985
986     _checks_args $csar_id
987     pushd ${CSAR_DIR}/${csar_id}
988
989     cat << META > metadata.yaml
990 resources:
991   deployment:
992     - $plugin_deployment_name.yaml
993   service:
994     - service.yaml
995 META
996
997     cat << DEPLOYMENT > $plugin_deployment_name.yaml
998 apiVersion: apps/v1
999 kind: Deployment
1000 metadata:
1001   name: $plugin_deployment_name
1002 spec:
1003   replicas: 1
1004   selector:
1005     matchLabels:
1006       app: plugin
1007   template:
1008     metadata:
1009       labels:
1010         app: plugin
1011     spec:
1012       containers:
1013       - name: $plugin_deployment_name
1014         image: "busybox"
1015         command: ["top"]
1016         stdin: true
1017         tty: true
1018 DEPLOYMENT
1019
1020     cat << SERVICE > service.yaml
1021 apiVersion: v1
1022 kind: Service
1023 metadata:
1024   name: $plugin_service_name
1025 spec:
1026   ports:
1027   - port: 80
1028     protocol: TCP
1029   selector:
1030     app: sise
1031 SERVICE
1032     popd
1033 }
1034
1035 # populate_CSAR_ovn4nfv() - Create content used for OVN4NFV functional test
1036 function populate_CSAR_ovn4nfv {
1037     local csar_id=$1
1038
1039     _checks_args $csar_id
1040     pushd ${CSAR_DIR}/${csar_id}
1041
1042     cat << META > metadata.yaml
1043 resources:
1044   onap_network:
1045     - ovn-port-net.yaml
1046     - ovn-priv-net.yaml
1047   network:
1048     - onap-ovn4nfvk8s-network.yaml
1049   deployment:
1050     - $ovn4nfv_deployment_name.yaml
1051 META
1052
1053     cat << MULTUS_NET > onap-ovn4nfvk8s-network.yaml
1054 apiVersion: "k8s.cni.cncf.io/v1"
1055 kind: NetworkAttachmentDefinition
1056 metadata:
1057   name: $ovn_multus_network_name
1058 spec:
1059   config: '{
1060       "cniVersion": "0.3.1",
1061       "name": "ovn4nfv-k8s-plugin",
1062       "type": "ovn4nfvk8s-cni"
1063     }'
1064 MULTUS_NET
1065
1066     cat << NETWORK > ovn-port-net.yaml
1067 apiVersion: k8s.plugin.opnfv.org/v1alpha1
1068 kind: Network
1069 metadata:
1070   name: ovn-port-net
1071 spec:
1072   cniType : ovn4nfv
1073   ipv4Subnets:
1074   - subnet: 172.16.33.0/24
1075     name: subnet1
1076     gateway: 172.16.33.1/24
1077 NETWORK
1078
1079     cat << NETWORK > ovn-priv-net.yaml
1080 apiVersion: k8s.plugin.opnfv.org/v1alpha1
1081 kind: Network
1082 metadata:
1083   name: ovn-priv-net
1084 spec:
1085   cniType : ovn4nfv
1086   ipv4Subnets:
1087   - subnet: 172.16.44.0/24
1088     name: subnet1
1089     gateway: 172.16.44.1/24
1090 NETWORK
1091
1092     cat << DEPLOYMENT > $ovn4nfv_deployment_name.yaml
1093 apiVersion: apps/v1
1094 kind: Deployment
1095 metadata:
1096   name: $ovn4nfv_deployment_name
1097   labels:
1098     app: ovn4nfv
1099 spec:
1100   replicas: 1
1101   selector:
1102     matchLabels:
1103       app: ovn4nfv
1104   template:
1105     metadata:
1106       labels:
1107         app: ovn4nfv
1108       annotations:
1109         k8s.v1.cni.cncf.io/networks: '[{ "name": "$ovn_multus_network_name"}]'
1110         k8s.plugin.opnfv.org/nfn-network: '{ "type": "ovn4nfv", "interface": [{ "name": "ovn-port-net", "interface": "net0" , "defaultGateway": "false"},
1111                       { "name": "ovn-priv-net", "interface": "net1" , "defaultGateway": "false"}]}'
1112     spec:
1113       containers:
1114       - name: $ovn4nfv_deployment_name
1115         image: "busybox"
1116         command: ["top"]
1117         stdin: true
1118         tty: true
1119 DEPLOYMENT
1120     popd
1121 }
1122
1123 # populate_CSAR_rbdefinition() - Function that populates CSAR folder
1124 # for testing resource bundle definition
1125 function populate_CSAR_rbdefinition {
1126     _checks_args "$1"
1127     pushd "${CSAR_DIR}/$1"
1128     print_msg "Create Helm Chart Archives"
1129     rm -f *.tar.gz
1130     tar -czf rb_profile.tar.gz -C $test_folder/vnfs/testrb/helm/profile .
1131     #Creates vault-consul-dev-0.0.0.tgz
1132     helm package $test_folder/vnfs/testrb/helm/vault-consul-dev --version 0.0.0
1133     popd
1134 }
1135
1136 # populate_CSAR_edgex_rbdefinition() - Function that populates CSAR folder
1137 # for testing resource bundle definition of edgex scenario
1138 function populate_CSAR_edgex_rbdefinition {
1139     _checks_args "$1"
1140     pushd "${CSAR_DIR}/$1"
1141     print_msg "Create Helm Chart Archives"
1142     rm -f *.tar.gz
1143     tar -czf rb_profile.tar.gz -C $test_folder/vnfs/edgex/profile .
1144     tar -czf rb_definition.tar.gz -C $test_folder/vnfs/edgex/helm edgex
1145     popd
1146 }
1147
1148 # populate_CSAR_fw_rbdefinition() - Function that populates CSAR folder
1149 # for testing resource bundle definition of firewall scenario
1150 function populate_CSAR_fw_rbdefinition {
1151     _checks_args "$1"
1152     pushd "${CSAR_DIR}/$1"
1153     print_msg "Create Helm Chart Archives for vFirewall"
1154     rm -f *.tar.gz
1155     # Reuse profile from the edgeX case as it is an empty profile
1156     tar -czf rb_profile.tar.gz -C $test_folder/vnfs/edgex/profile .
1157     tar -czf rb_definition.tar.gz -C $test_folder/../demo firewall
1158     popd
1159 }
1160
1161 # populate_CSAR_eaa_rbdefinition() - Function that populates CSAR folder
1162 # for testing resource bundle definition of openness eaa scenario
1163 function populate_CSAR_eaa_rbdefinition {
1164     _checks_args "$1"
1165     pushd "${CSAR_DIR}/$1"
1166     print_msg "Create Helm Chart Archives for Openness EAA"
1167     rm -f *.tar.gz
1168     tar -czf rb_profile.tar.gz -C $test_folder/openness/eaa/profile .
1169     tar -czf rb_definition.tar.gz -C $test_folder/openness/eaa/helm eaa
1170     popd
1171 }
1172
1173 # populate_CSAR_eaa_sample_app_rbdefinition() - Function that populates CSAR folder
1174 # for testing resource bundle definition of openness sample-app scenario
1175 function populate_CSAR_eaa_sample_app_rbdefinition {
1176     _checks_args "$1"
1177     pushd "${CSAR_DIR}/$1"
1178     print_msg "Create Helm Chart Archives for Openness EAA Sample Apps: producer and consumer"
1179     rm -f *.tar.gz
1180     tar -czf rb_profile.tar.gz -C $test_folder/openness/sample-app/profile .
1181     tar -czf rb_definition.tar.gz -C $test_folder/openness/sample-app/helm sample-app
1182     popd
1183 }
1184
1185 function populate_CSAR_composite_app_helm {
1186     _checks_args "$1"
1187     pushd "${CSAR_DIR}/$1"
1188     print_msg "Create Helm Chart Archives for compositeApp"
1189     rm -f *.tar.gz
1190     tar -czf collectd.tar.gz -C $test_folder/vnfs/comp-app/collection/app1/helm .
1191     tar -czf prometheus.tar.gz -C $test_folder/vnfs/comp-app/collection/app2/helm .
1192     tar -czf collectd_profile.tar.gz -C $test_folder/vnfs/comp-app/collection/app1/profile .
1193     tar -czf prometheus_profile.tar.gz -C $test_folder/vnfs/comp-app/collection/app2/profile .
1194     popd
1195 }
1196