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 | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 13 | ] |
| 14 | |
| 15 | if (!config) { |
| 16 | config = [:] |
| 17 | } |
| 18 | |
| 19 | def cfg = defaultConfig + config |
| 20 | |
Matteo Scandolo | fcfc60d | 2021-02-24 09:06:48 -0800 | [diff] [blame] | 21 | def volthaStackChart = "onf/voltha-stack" |
| 22 | |
| 23 | if (cfg.localCharts) { |
| 24 | volthaStackChart = "$WORKSPACE/voltha-helm-charts/voltha-stack" |
| 25 | |
| 26 | sh """ |
| 27 | pushd $WORKSPACE/voltha-helm-charts/voltha-stack |
| 28 | helm dep update |
| 29 | popd |
| 30 | """ |
| 31 | } |
| 32 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 33 | println "Deploying VOLTHA Stack with the following parameters: ${cfg}." |
| 34 | |
| 35 | sh """ |
Matteo Scandolo | ed1afdd | 2021-04-02 16:25:45 -0700 | [diff] [blame^] | 36 | helm upgrade --install --create-namespace -n ${cfg.volthaNamespace} ${cfg.stackName} ${volthaStackChart} \ |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 37 | --set global.stack_name=${cfg.stackName} \ |
| 38 | --set global.voltha_infra_name=voltha-infra \ |
| 39 | --set global.voltha_infra_namespace=${cfg.infraNamespace} \ |
Matteo Scandolo | ed1afdd | 2021-04-02 16:25:45 -0700 | [diff] [blame^] | 40 | ${cfg.extraHelmFlags} |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 41 | """ |
| 42 | |
| 43 | for(int i = 0;i<cfg.bbsimReplica;i++) { |
| 44 | // TODO differentiate olt_id between different stacks |
| 45 | sh """ |
Matteo Scandolo | ed1afdd | 2021-04-02 16:25:45 -0700 | [diff] [blame^] | 46 | helm upgrade --install --create-namespace -n ${cfg.volthaNamespace} bbsim${i} onf/bbsim \ |
Matteo Scandolo | 2bc660a | 2021-02-12 10:52:25 -0800 | [diff] [blame] | 47 | --set olt_id="${cfg.stackId}${i}" \ |
Matteo Scandolo | ed1afdd | 2021-04-02 16:25:45 -0700 | [diff] [blame^] | 48 | -f $WORKSPACE/voltha-helm-charts/examples/${cfg.workflow}-values.yaml \ |
| 49 | ${cfg.extraHelmFlags} |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 50 | """ |
| 51 | } |
| 52 | |
| 53 | println "Wait for VOLTHA Stack ${cfg.stackName} to start" |
| 54 | |
| 55 | sh """ |
| 56 | set +x |
| 57 | voltha=\$(kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers | grep "0/" | wc -l) |
| 58 | while [[ \$voltha != 0 ]]; do |
| 59 | sleep 5 |
| 60 | voltha=\$(kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers | grep "0/" | wc -l) |
| 61 | done |
| 62 | """ |
| 63 | |
| 64 | // also make sure that the ONOS config is loaded |
| 65 | println "Wait for ONOS Config loader to complete" |
| 66 | |
| 67 | sh """ |
| 68 | set +x |
| 69 | config=\$(kubectl get jobs.batch -n ${cfg.infraNamespace} --no-headers | grep "0/" | wc -l) |
| 70 | while [[ \$config != 0 ]]; do |
| 71 | sleep 5 |
| 72 | config=\$(kubectl get jobs.batch -n ${cfg.infraNamespace} --no-headers | grep "0/" | wc -l) |
| 73 | done |
| 74 | """ |
| 75 | } |