blob: 37a00d2e13f570c55e7a29e3ab6327faccb74af7 [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
Hardik Windlass810b6cf2022-02-24 09:21:18 +000056 def serviceConfigFile = cfg.workflow
57 if (cfg.withMacLearning && cfg.workflow == 'tt') {
58 serviceConfigFile = "tt-maclearner"
59 }
60 def bbsimCfg = readYaml file: "$WORKSPACE/voltha-helm-charts/examples/${serviceConfigFile}-values.yaml"
Matteo Scandolo0ce69f12021-05-04 08:44:53 -070061 // NOTE we assume that the only service that needs a different s_tag is the first one in the list
62 bbsimCfg["servicesConfig"]["services"][0]["s_tag"] = startingStag + i
Matteo Scandoloe765ee32021-07-20 16:47:19 -070063 println "Using BBSim Service config ${bbsimCfg['servicesConfig']}"
Matteo Scandolo0ce69f12021-05-04 08:44:53 -070064 writeYaml file: "$WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml", data: bbsimCfg
65 } else {
66 // NOTE if it's DT just copy the file over
67 sh """
68 cp $WORKSPACE/voltha-helm-charts/examples/${cfg.workflow}-values.yaml $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml
69 """
70 }
71 }
72
73 sh """
Matteo Scandoloba4b6542021-06-24 12:06:07 +020074 helm upgrade --install --create-namespace -n ${cfg.volthaNamespace} bbsim${i} ${bbsimChart} \
Matteo Scandolo0ce69f12021-05-04 08:44:53 -070075 --set olt_id="${cfg.stackId}${i}" \
76 -f $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml \
77 ${cfg.extraHelmFlags}
78 """
Matteo Scandolo42f6e572021-01-25 15:11:34 -080079 }
80
81 println "Wait for VOLTHA Stack ${cfg.stackName} to start"
82
83 sh """
84 set +x
85 voltha=\$(kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers | grep "0/" | wc -l)
86 while [[ \$voltha != 0 ]]; do
87 sleep 5
88 voltha=\$(kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers | grep "0/" | wc -l)
89 done
90 """
91
Andrea Campanella365ea1e2021-09-28 10:50:01 +020092 waitForAdapters(cfg)
Matteo Scandolo937f4792021-09-24 11:05:52 -070093
Matteo Scandolo42f6e572021-01-25 15:11:34 -080094 // also make sure that the ONOS config is loaded
Andrea Campanella04b393a2021-07-22 10:48:33 +020095 // NOTE that this is only required for VOLTHA-2.8
Matteo Scandolo42f6e572021-01-25 15:11:34 -080096 println "Wait for ONOS Config loader to complete"
97
Andrea Campanella04b393a2021-07-22 10:48:33 +020098 // NOTE that this is only required for VOLTHA-2.8,
Matteo Scandolo42f6e572021-01-25 15:11:34 -080099 sh """
100 set +x
101 config=\$(kubectl get jobs.batch -n ${cfg.infraNamespace} --no-headers | grep "0/" | wc -l)
102 while [[ \$config != 0 ]]; do
103 sleep 5
104 config=\$(kubectl get jobs.batch -n ${cfg.infraNamespace} --no-headers | grep "0/" | wc -l)
105 done
106 """
Andrea Campanella04b393a2021-07-22 10:48:33 +0200107 // NOTE that this is only required for VOLTHA-2.9 onwards, to wait until the pod completed,
Matteo Scandolo937f4792021-09-24 11:05:52 -0700108 // meaning ONOS fully deployed
Andrea Campanella04b393a2021-07-22 10:48:33 +0200109 sh """
110 set +x
Andrea Campanella11832512021-07-23 10:53:19 +0200111 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 +0200112 while [[ \$config != 0 ]]; do
113 sleep 5
Andrea Campanella11832512021-07-23 10:53:19 +0200114 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 +0200115 done
116 """
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800117}