blob: 0f967965532f6add7c30dee8effe259a99865355 [file] [log] [blame]
Matteo Scandolo42f6e572021-01-25 15:11:34 -08001
2def call(Map config) {
3 // note that I can't define this outside the function as there's no global scope in Groovy
4 def defaultConfig = [
Matteo Scandolo42f6e572021-01-25 15:11:34 -08005 bbsimReplica: 1,
6 infraNamespace: "infra",
7 volthaNamespace: "voltha",
8 stackName: "voltha",
Matteo Scandolo2bc660a2021-02-12 10:52:25 -08009 stackId: 1, // NOTE this is used to differentiate between BBSims across multiple stacks
Matteo Scandolo42f6e572021-01-25 15:11:34 -080010 workflow: "att",
11 extraHelmFlags: "",
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080012 localCharts: false,
Matteo Scandolo529e8822021-07-21 10:20:18 -070013 onosReplica: 1,
Andrea Campanella365ea1e2021-09-28 10:50:01 +020014 adaptersToWait: 2,
Matteo Scandolo42f6e572021-01-25 15:11:34 -080015 ]
16
17 if (!config) {
18 config = [:]
19 }
20
21 def cfg = defaultConfig + config
22
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080023 def volthaStackChart = "onf/voltha-stack"
Matteo Scandoloba4b6542021-06-24 12:06:07 +020024 def bbsimChart = "onf/bbsim"
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080025
26 if (cfg.localCharts) {
27 volthaStackChart = "$WORKSPACE/voltha-helm-charts/voltha-stack"
Matteo Scandoloba4b6542021-06-24 12:06:07 +020028 bbsimChart = "$WORKSPACE/voltha-helm-charts/bbsim"
Matteo Scandolofcfc60d2021-02-24 09:06:48 -080029
30 sh """
31 pushd $WORKSPACE/voltha-helm-charts/voltha-stack
32 helm dep update
33 popd
34 """
35 }
36
Matteo Scandolo42f6e572021-01-25 15:11:34 -080037 println "Deploying VOLTHA Stack with the following parameters: ${cfg}."
38
39 sh """
Matteo Scandoloed1afdd2021-04-02 16:25:45 -070040 helm upgrade --install --create-namespace -n ${cfg.volthaNamespace} ${cfg.stackName} ${volthaStackChart} \
Matteo Scandolo42f6e572021-01-25 15:11:34 -080041 --set global.stack_name=${cfg.stackName} \
42 --set global.voltha_infra_name=voltha-infra \
Matteo Scandolo529e8822021-07-21 10:20:18 -070043 --set voltha.onos_classic.replicas=${cfg.onosReplica} \
Matteo Scandolo42f6e572021-01-25 15:11:34 -080044 --set global.voltha_infra_namespace=${cfg.infraNamespace} \
Matteo Scandoloed1afdd2021-04-02 16:25:45 -070045 ${cfg.extraHelmFlags}
Matteo Scandolo42f6e572021-01-25 15:11:34 -080046 """
47
48 for(int i = 0;i<cfg.bbsimReplica;i++) {
Matteo Scandolo0ce69f12021-05-04 08:44:53 -070049 // NOTE we don't need to update the tag for DT
50 script {
51 sh """
52 rm -f $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml
53 """
54 if (cfg.workflow == "att" || cfg.workflow == "tt") {
55 def startingStag = 900
56 def bbsimCfg = readYaml file: "$WORKSPACE/voltha-helm-charts/examples/${cfg.workflow}-values.yaml"
57 // NOTE we assume that the only service that needs a different s_tag is the first one in the list
58 bbsimCfg["servicesConfig"]["services"][0]["s_tag"] = startingStag + i
Matteo Scandoloe765ee32021-07-20 16:47:19 -070059 println "Using BBSim Service config ${bbsimCfg['servicesConfig']}"
Matteo Scandolo0ce69f12021-05-04 08:44:53 -070060 writeYaml file: "$WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml", data: bbsimCfg
61 } else {
62 // NOTE if it's DT just copy the file over
63 sh """
64 cp $WORKSPACE/voltha-helm-charts/examples/${cfg.workflow}-values.yaml $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml
65 """
66 }
67 }
68
69 sh """
Matteo Scandoloba4b6542021-06-24 12:06:07 +020070 helm upgrade --install --create-namespace -n ${cfg.volthaNamespace} bbsim${i} ${bbsimChart} \
Matteo Scandolo0ce69f12021-05-04 08:44:53 -070071 --set olt_id="${cfg.stackId}${i}" \
72 -f $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml \
73 ${cfg.extraHelmFlags}
74 """
Matteo Scandolo42f6e572021-01-25 15:11:34 -080075 }
76
77 println "Wait for VOLTHA Stack ${cfg.stackName} to start"
78
79 sh """
80 set +x
81 voltha=\$(kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers | grep "0/" | wc -l)
82 while [[ \$voltha != 0 ]]; do
83 sleep 5
84 voltha=\$(kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers | grep "0/" | wc -l)
85 done
86 """
87
Andrea Campanella365ea1e2021-09-28 10:50:01 +020088 waitForAdapters(cfg)
Matteo Scandolo937f4792021-09-24 11:05:52 -070089
Matteo Scandolo42f6e572021-01-25 15:11:34 -080090 // also make sure that the ONOS config is loaded
Andrea Campanella04b393a2021-07-22 10:48:33 +020091 // NOTE that this is only required for VOLTHA-2.8
Matteo Scandolo42f6e572021-01-25 15:11:34 -080092 println "Wait for ONOS Config loader to complete"
93
Andrea Campanella04b393a2021-07-22 10:48:33 +020094 // NOTE that this is only required for VOLTHA-2.8,
Matteo Scandolo42f6e572021-01-25 15:11:34 -080095 sh """
96 set +x
97 config=\$(kubectl get jobs.batch -n ${cfg.infraNamespace} --no-headers | grep "0/" | wc -l)
98 while [[ \$config != 0 ]]; do
99 sleep 5
100 config=\$(kubectl get jobs.batch -n ${cfg.infraNamespace} --no-headers | grep "0/" | wc -l)
101 done
102 """
Andrea Campanella04b393a2021-07-22 10:48:33 +0200103 // NOTE that this is only required for VOLTHA-2.9 onwards, to wait until the pod completed,
Matteo Scandolo937f4792021-09-24 11:05:52 -0700104 // meaning ONOS fully deployed
Andrea Campanella04b393a2021-07-22 10:48:33 +0200105 sh """
106 set +x
Andrea Campanella11832512021-07-23 10:53:19 +0200107 config=\$(kubectl get pods -l app=onos-config-loader -n ${cfg.infraNamespace} --no-headers --field-selector=status.phase=Running | grep "0/" | wc -l)
Andrea Campanella04b393a2021-07-22 10:48:33 +0200108 while [[ \$config != 0 ]]; do
109 sleep 5
Andrea Campanella11832512021-07-23 10:53:19 +0200110 config=\$(kubectl get pods -l app=onos-config-loader -n ${cfg.infraNamespace} --no-headers --field-selector=status.phase=Running | grep "0/" | wc -l)
Andrea Campanella04b393a2021-07-22 10:48:33 +0200111 done
112 """
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800113}