Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 1 | |
| 2 | def 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 Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 5 | bbsimReplica: 1, |
| 6 | infraNamespace: "infra", |
| 7 | volthaNamespace: "voltha", |
| 8 | stackName: "voltha", |
Matteo Scandolo | 2bc660a | 2021-02-12 10:52:25 -0800 | [diff] [blame] | 9 | 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] | 10 | workflow: "att", |
| 11 | extraHelmFlags: "", |
Matteo Scandolo | fcfc60d | 2021-02-24 09:06:48 -0800 | [diff] [blame] | 12 | localCharts: false, |
Matteo Scandolo | 529e882 | 2021-07-21 10:20:18 -0700 | [diff] [blame] | 13 | onosReplica: 1, |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 14 | ] |
| 15 | |
| 16 | if (!config) { |
| 17 | config = [:] |
| 18 | } |
| 19 | |
| 20 | def cfg = defaultConfig + config |
| 21 | |
Matteo Scandolo | fcfc60d | 2021-02-24 09:06:48 -0800 | [diff] [blame] | 22 | def volthaStackChart = "onf/voltha-stack" |
Matteo Scandolo | ba4b654 | 2021-06-24 12:06:07 +0200 | [diff] [blame] | 23 | def bbsimChart = "onf/bbsim" |
Matteo Scandolo | fcfc60d | 2021-02-24 09:06:48 -0800 | [diff] [blame] | 24 | |
| 25 | if (cfg.localCharts) { |
| 26 | volthaStackChart = "$WORKSPACE/voltha-helm-charts/voltha-stack" |
Matteo Scandolo | ba4b654 | 2021-06-24 12:06:07 +0200 | [diff] [blame] | 27 | bbsimChart = "$WORKSPACE/voltha-helm-charts/bbsim" |
Matteo Scandolo | fcfc60d | 2021-02-24 09:06:48 -0800 | [diff] [blame] | 28 | |
| 29 | sh """ |
| 30 | pushd $WORKSPACE/voltha-helm-charts/voltha-stack |
| 31 | helm dep update |
| 32 | popd |
| 33 | """ |
| 34 | } |
| 35 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 36 | println "Deploying VOLTHA Stack with the following parameters: ${cfg}." |
| 37 | |
| 38 | sh """ |
Matteo Scandolo | ed1afdd | 2021-04-02 16:25:45 -0700 | [diff] [blame] | 39 | helm upgrade --install --create-namespace -n ${cfg.volthaNamespace} ${cfg.stackName} ${volthaStackChart} \ |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 40 | --set global.stack_name=${cfg.stackName} \ |
| 41 | --set global.voltha_infra_name=voltha-infra \ |
Matteo Scandolo | 529e882 | 2021-07-21 10:20:18 -0700 | [diff] [blame] | 42 | --set voltha.onos_classic.replicas=${cfg.onosReplica} \ |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 43 | --set global.voltha_infra_namespace=${cfg.infraNamespace} \ |
Matteo Scandolo | ed1afdd | 2021-04-02 16:25:45 -0700 | [diff] [blame] | 44 | ${cfg.extraHelmFlags} |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 45 | """ |
| 46 | |
| 47 | for(int i = 0;i<cfg.bbsimReplica;i++) { |
Matteo Scandolo | 0ce69f1 | 2021-05-04 08:44:53 -0700 | [diff] [blame] | 48 | // NOTE we don't need to update the tag for DT |
| 49 | script { |
| 50 | sh """ |
| 51 | rm -f $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml |
| 52 | """ |
| 53 | if (cfg.workflow == "att" || cfg.workflow == "tt") { |
| 54 | def startingStag = 900 |
| 55 | def bbsimCfg = readYaml file: "$WORKSPACE/voltha-helm-charts/examples/${cfg.workflow}-values.yaml" |
| 56 | // NOTE we assume that the only service that needs a different s_tag is the first one in the list |
| 57 | bbsimCfg["servicesConfig"]["services"][0]["s_tag"] = startingStag + i |
Matteo Scandolo | e765ee3 | 2021-07-20 16:47:19 -0700 | [diff] [blame] | 58 | println "Using BBSim Service config ${bbsimCfg['servicesConfig']}" |
Matteo Scandolo | 0ce69f1 | 2021-05-04 08:44:53 -0700 | [diff] [blame] | 59 | writeYaml file: "$WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml", data: bbsimCfg |
| 60 | } else { |
| 61 | // NOTE if it's DT just copy the file over |
| 62 | sh """ |
| 63 | cp $WORKSPACE/voltha-helm-charts/examples/${cfg.workflow}-values.yaml $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml |
| 64 | """ |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | sh """ |
Matteo Scandolo | ba4b654 | 2021-06-24 12:06:07 +0200 | [diff] [blame] | 69 | helm upgrade --install --create-namespace -n ${cfg.volthaNamespace} bbsim${i} ${bbsimChart} \ |
Matteo Scandolo | 0ce69f1 | 2021-05-04 08:44:53 -0700 | [diff] [blame] | 70 | --set olt_id="${cfg.stackId}${i}" \ |
| 71 | -f $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml \ |
| 72 | ${cfg.extraHelmFlags} |
| 73 | """ |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | println "Wait for VOLTHA Stack ${cfg.stackName} to start" |
| 77 | |
| 78 | sh """ |
| 79 | set +x |
| 80 | voltha=\$(kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers | grep "0/" | wc -l) |
| 81 | while [[ \$voltha != 0 ]]; do |
| 82 | sleep 5 |
| 83 | voltha=\$(kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers | grep "0/" | wc -l) |
| 84 | done |
| 85 | """ |
| 86 | |
Matteo Scandolo | 937f479 | 2021-09-24 11:05:52 -0700 | [diff] [blame] | 87 | println "Wait for adapters to be registered" |
| 88 | |
| 89 | // guarantee that at least two adapters are registered with VOLTHA before proceeding |
Matteo Scandolo | d9af802 | 2021-09-28 16:21:01 -0700 | [diff] [blame] | 90 | // this is potentially prone to issues if we'll run test with multiple adapter pairs (eg: adtran + open) |
| 91 | // until then it is safe to assume we'll be ready once we have two adapters in the system |
| 92 | sh """ |
| 93 | set +x |
| 94 | _TAG="voltha-voltha-api" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n ${cfg.volthaNamespace} svc/voltha-voltha-api 55555:55555; done"& |
| 95 | """ |
Matteo Scandolo | 937f479 | 2021-09-24 11:05:52 -0700 | [diff] [blame] | 96 | sh """ |
| 97 | set +x |
Matteo Scandolo | 937f479 | 2021-09-24 11:05:52 -0700 | [diff] [blame] | 98 | adapters=\$(voltctl adapter list -q | wc -l) |
| 99 | while [[ \$adapters -lt 2 ]]; do |
| 100 | sleep 5 |
| 101 | adapters=\$(voltctl adapter list -q | wc -l) |
| 102 | done |
Matteo Scandolo | d9af802 | 2021-09-28 16:21:01 -0700 | [diff] [blame] | 103 | """ |
| 104 | |
| 105 | // NOTE that we need to wait for LastCommunication to be equal or shorter that 5s |
| 106 | // as that means the core can talk to the adapters |
| 107 | // if voltctl can't read LastCommunication we skip this check |
| 108 | def done = false; |
| 109 | |
| 110 | while (!done) { |
| 111 | sleep 1 |
| 112 | def adapters = "" |
| 113 | try { |
| 114 | adapters = sh ( |
| 115 | script: 'voltctl adapter list --format "{{gosince .LastCommunication}}"', |
| 116 | returnStdout: true, |
| 117 | ).trim() |
| 118 | } catch (err) { |
| 119 | // in some older versions of voltctl the command results in |
| 120 | // ERROR: Unexpected error while attempting to format results as table : template: output:1: function "gosince" not defined |
| 121 | // if that's the case we won't be able to check the timestamp so it's useless to wait |
| 122 | println("voltctl can't parse LastCommunication, skip waiting") |
| 123 | done = true |
| 124 | break |
| 125 | } |
| 126 | |
| 127 | def waitingOn = adapters.split( '\n' ).find{since -> |
| 128 | since = since.replaceAll('s','') //remove seconds from the string |
| 129 | |
| 130 | // it has to be a single digit |
| 131 | if (since.length() > 1) { |
| 132 | return true |
| 133 | } |
| 134 | if ((since as Integer) > 5) { |
| 135 | return true |
| 136 | } |
| 137 | return false |
| 138 | } |
| 139 | done = (waitingOn == null || waitingOn.length() == 0) |
| 140 | } |
| 141 | |
| 142 | sh """ |
| 143 | set +x |
| 144 | ps aux | grep port-forw | grep -v grep | awk '{print \$2}' | xargs --no-run-if-empty kill -9 || true |
Matteo Scandolo | 937f479 | 2021-09-24 11:05:52 -0700 | [diff] [blame] | 145 | """ |
| 146 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 147 | // also make sure that the ONOS config is loaded |
Andrea Campanella | 04b393a | 2021-07-22 10:48:33 +0200 | [diff] [blame] | 148 | // NOTE that this is only required for VOLTHA-2.8 |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 149 | println "Wait for ONOS Config loader to complete" |
| 150 | |
Andrea Campanella | 04b393a | 2021-07-22 10:48:33 +0200 | [diff] [blame] | 151 | // NOTE that this is only required for VOLTHA-2.8, |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 152 | sh """ |
| 153 | set +x |
| 154 | config=\$(kubectl get jobs.batch -n ${cfg.infraNamespace} --no-headers | grep "0/" | wc -l) |
| 155 | while [[ \$config != 0 ]]; do |
| 156 | sleep 5 |
| 157 | config=\$(kubectl get jobs.batch -n ${cfg.infraNamespace} --no-headers | grep "0/" | wc -l) |
| 158 | done |
| 159 | """ |
Andrea Campanella | 04b393a | 2021-07-22 10:48:33 +0200 | [diff] [blame] | 160 | // 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] | 161 | // meaning ONOS fully deployed |
Andrea Campanella | 04b393a | 2021-07-22 10:48:33 +0200 | [diff] [blame] | 162 | sh """ |
| 163 | set +x |
Andrea Campanella | 1183251 | 2021-07-23 10:53:19 +0200 | [diff] [blame] | 164 | 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] | 165 | while [[ \$config != 0 ]]; do |
| 166 | sleep 5 |
Andrea Campanella | 1183251 | 2021-07-23 10:53:19 +0200 | [diff] [blame] | 167 | 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] | 168 | done |
| 169 | """ |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 170 | } |