Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 1 | #!/usr/bin/env groovy |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 2 | // ----------------------------------------------------------------------- |
| 3 | // ----------------------------------------------------------------------- |
| 4 | def getIam(String func) |
| 5 | { |
| 6 | // Cannot rely on a stack trace due to jenkins manipulation |
| 7 | String src = 'vars/volthaStackDeploy.groovy' |
| 8 | String iam = [src, func].join('::') |
| 9 | return iam |
| 10 | } |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 11 | |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 12 | // ----------------------------------------------------------------------- |
| 13 | // ----------------------------------------------------------------------- |
| 14 | def process(Map config) |
| 15 | { |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 16 | // note that I can't define this outside the function as there's no global scope in Groovy |
| 17 | def defaultConfig = [ |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 18 | bbsimReplica: 1, |
| 19 | infraNamespace: "infra", |
| 20 | volthaNamespace: "voltha", |
| 21 | stackName: "voltha", |
Matteo Scandolo | 2bc660a | 2021-02-12 10:52:25 -0800 | [diff] [blame] | 22 | stackId: 1, // NOTE this is used to differentiate between BBSims across multiple stacks |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 23 | workflow: "att", |
Hardik Windlass | 2b16434 | 2022-02-28 03:50:48 +0000 | [diff] [blame] | 24 | withMacLearning: false, |
Hardik Windlass | c97ceae | 2022-05-13 10:12:55 +0530 | [diff] [blame] | 25 | withFttb: false, |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 26 | extraHelmFlags: "", |
Matteo Scandolo | fcfc60d | 2021-02-24 09:06:48 -0800 | [diff] [blame] | 27 | localCharts: false, |
Matteo Scandolo | 529e882 | 2021-07-21 10:20:18 -0700 | [diff] [blame] | 28 | onosReplica: 1, |
Andrea Campanella | 365ea1e | 2021-09-28 10:50:01 +0200 | [diff] [blame] | 29 | adaptersToWait: 2, |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 30 | ] |
| 31 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 32 | def cfg = defaultConfig + config |
| 33 | |
Matteo Scandolo | fcfc60d | 2021-02-24 09:06:48 -0800 | [diff] [blame] | 34 | def volthaStackChart = "onf/voltha-stack" |
Matteo Scandolo | ba4b654 | 2021-06-24 12:06:07 +0200 | [diff] [blame] | 35 | def bbsimChart = "onf/bbsim" |
Matteo Scandolo | fcfc60d | 2021-02-24 09:06:48 -0800 | [diff] [blame] | 36 | |
| 37 | if (cfg.localCharts) { |
| 38 | volthaStackChart = "$WORKSPACE/voltha-helm-charts/voltha-stack" |
Matteo Scandolo | ba4b654 | 2021-06-24 12:06:07 +0200 | [diff] [blame] | 39 | bbsimChart = "$WORKSPACE/voltha-helm-charts/bbsim" |
Matteo Scandolo | fcfc60d | 2021-02-24 09:06:48 -0800 | [diff] [blame] | 40 | |
| 41 | sh """ |
| 42 | pushd $WORKSPACE/voltha-helm-charts/voltha-stack |
| 43 | helm dep update |
| 44 | popd |
| 45 | """ |
| 46 | } |
| 47 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 48 | println "Deploying VOLTHA Stack with the following parameters: ${cfg}." |
| 49 | |
| 50 | sh """ |
Matteo Scandolo | ed1afdd | 2021-04-02 16:25:45 -0700 | [diff] [blame] | 51 | helm upgrade --install --create-namespace -n ${cfg.volthaNamespace} ${cfg.stackName} ${volthaStackChart} \ |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 52 | --set global.stack_name=${cfg.stackName} \ |
| 53 | --set global.voltha_infra_name=voltha-infra \ |
Matteo Scandolo | 529e882 | 2021-07-21 10:20:18 -0700 | [diff] [blame] | 54 | --set voltha.onos_classic.replicas=${cfg.onosReplica} \ |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 55 | --set global.voltha_infra_namespace=${cfg.infraNamespace} \ |
Matteo Scandolo | ed1afdd | 2021-04-02 16:25:45 -0700 | [diff] [blame] | 56 | ${cfg.extraHelmFlags} |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 57 | """ |
| 58 | |
| 59 | for(int i = 0;i<cfg.bbsimReplica;i++) { |
Matteo Scandolo | 0ce69f1 | 2021-05-04 08:44:53 -0700 | [diff] [blame] | 60 | // NOTE we don't need to update the tag for DT |
| 61 | script { |
| 62 | sh """ |
| 63 | rm -f $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml |
| 64 | """ |
| 65 | if (cfg.workflow == "att" || cfg.workflow == "tt") { |
| 66 | def startingStag = 900 |
Hardik Windlass | 810b6cf | 2022-02-24 09:21:18 +0000 | [diff] [blame] | 67 | def serviceConfigFile = cfg.workflow |
| 68 | if (cfg.withMacLearning && cfg.workflow == 'tt') { |
| 69 | serviceConfigFile = "tt-maclearner" |
| 70 | } |
| 71 | def bbsimCfg = readYaml file: "$WORKSPACE/voltha-helm-charts/examples/${serviceConfigFile}-values.yaml" |
Matteo Scandolo | 0ce69f1 | 2021-05-04 08:44:53 -0700 | [diff] [blame] | 72 | // NOTE we assume that the only service that needs a different s_tag is the first one in the list |
| 73 | bbsimCfg["servicesConfig"]["services"][0]["s_tag"] = startingStag + i |
Matteo Scandolo | e765ee3 | 2021-07-20 16:47:19 -0700 | [diff] [blame] | 74 | println "Using BBSim Service config ${bbsimCfg['servicesConfig']}" |
Matteo Scandolo | 0ce69f1 | 2021-05-04 08:44:53 -0700 | [diff] [blame] | 75 | writeYaml file: "$WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml", data: bbsimCfg |
| 76 | } else { |
| 77 | // NOTE if it's DT just copy the file over |
| 78 | sh """ |
| 79 | cp $WORKSPACE/voltha-helm-charts/examples/${cfg.workflow}-values.yaml $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml |
| 80 | """ |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | sh """ |
Matteo Scandolo | ba4b654 | 2021-06-24 12:06:07 +0200 | [diff] [blame] | 85 | helm upgrade --install --create-namespace -n ${cfg.volthaNamespace} bbsim${i} ${bbsimChart} \ |
Matteo Scandolo | 0ce69f1 | 2021-05-04 08:44:53 -0700 | [diff] [blame] | 86 | --set olt_id="${cfg.stackId}${i}" \ |
| 87 | -f $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml \ |
| 88 | ${cfg.extraHelmFlags} |
| 89 | """ |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | println "Wait for VOLTHA Stack ${cfg.stackName} to start" |
| 93 | |
| 94 | sh """ |
| 95 | set +x |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 96 | |
| 97 | # [joey]: debug |
| 98 | kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers |
| 99 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 100 | voltha=\$(kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers | grep "0/" | wc -l) |
| 101 | while [[ \$voltha != 0 ]]; do |
| 102 | sleep 5 |
| 103 | voltha=\$(kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers | grep "0/" | wc -l) |
| 104 | done |
| 105 | """ |
| 106 | |
Andrea Campanella | 365ea1e | 2021-09-28 10:50:01 +0200 | [diff] [blame] | 107 | waitForAdapters(cfg) |
Matteo Scandolo | 937f479 | 2021-09-24 11:05:52 -0700 | [diff] [blame] | 108 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 109 | // also make sure that the ONOS config is loaded |
Andrea Campanella | 04b393a | 2021-07-22 10:48:33 +0200 | [diff] [blame] | 110 | // NOTE that this is only required for VOLTHA-2.8 |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 111 | println "Wait for ONOS Config loader to complete" |
| 112 | |
Andrea Campanella | 04b393a | 2021-07-22 10:48:33 +0200 | [diff] [blame] | 113 | // NOTE that this is only required for VOLTHA-2.8, |
Joey Armstrong | 7adbfb0 | 2023-01-24 17:02:37 -0500 | [diff] [blame] | 114 | // [TODO]: Release cleanup |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 115 | sh """ |
| 116 | set +x |
| 117 | config=\$(kubectl get jobs.batch -n ${cfg.infraNamespace} --no-headers | grep "0/" | wc -l) |
| 118 | while [[ \$config != 0 ]]; do |
| 119 | sleep 5 |
| 120 | config=\$(kubectl get jobs.batch -n ${cfg.infraNamespace} --no-headers | grep "0/" | wc -l) |
| 121 | done |
| 122 | """ |
Joey Armstrong | 7adbfb0 | 2023-01-24 17:02:37 -0500 | [diff] [blame] | 123 | |
Andrea Campanella | 04b393a | 2021-07-22 10:48:33 +0200 | [diff] [blame] | 124 | // NOTE that this is only required for VOLTHA-2.9 onwards, to wait until the pod completed, |
Matteo Scandolo | 937f479 | 2021-09-24 11:05:52 -0700 | [diff] [blame] | 125 | // meaning ONOS fully deployed |
Andrea Campanella | 04b393a | 2021-07-22 10:48:33 +0200 | [diff] [blame] | 126 | sh """ |
| 127 | set +x |
Andrea Campanella | 1183251 | 2021-07-23 10:53:19 +0200 | [diff] [blame] | 128 | config=\$(kubectl get pods -l app=onos-config-loader -n ${cfg.infraNamespace} --no-headers --field-selector=status.phase=Running | grep "0/" | wc -l) |
Andrea Campanella | 04b393a | 2021-07-22 10:48:33 +0200 | [diff] [blame] | 129 | while [[ \$config != 0 ]]; do |
| 130 | sleep 5 |
Andrea Campanella | 1183251 | 2021-07-23 10:53:19 +0200 | [diff] [blame] | 131 | config=\$(kubectl get pods -l app=onos-config-loader -n ${cfg.infraNamespace} --no-headers --field-selector=status.phase=Running | grep "0/" | wc -l) |
Andrea Campanella | 04b393a | 2021-07-22 10:48:33 +0200 | [diff] [blame] | 132 | done |
| 133 | """ |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 134 | |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 135 | return |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 136 | } |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 137 | |
| 138 | // ----------------------------------------------------------------------- |
| 139 | // ----------------------------------------------------------------------- |
| 140 | def call(Map config) |
| 141 | { |
| 142 | String iam = getIam('main') |
| 143 | println("** ${iam}: ENTER") |
| 144 | |
| 145 | if (!config) { |
| 146 | config = [:] |
| 147 | } |
| 148 | |
| 149 | try |
| 150 | { |
| 151 | process(config) |
| 152 | } |
| 153 | catch (Exception err) |
| 154 | { |
| 155 | println("** ${iam}: EXCEPTION ${err}") |
Joey Armstrong | 8a3c13b | 2022-12-06 09:27:44 -0500 | [diff] [blame] | 156 | // Cannot re-throw ATM: too many potential shell errors. |
| 157 | // throw err |
Joey Armstrong | 7987c11 | 2022-12-05 12:42:43 -0500 | [diff] [blame] | 158 | } |
| 159 | finally |
| 160 | { |
| 161 | println("** ${iam}: LEAVE") |
| 162 | } |
| 163 | return |
| 164 | } |
| 165 | |
| 166 | // [EOF] |