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" |
Matteo Scandolo | ba4b654 | 2021-06-24 12:06:07 +0200 | [diff] [blame] | 22 | def bbsimChart = "onf/bbsim" |
Matteo Scandolo | fcfc60d | 2021-02-24 09:06:48 -0800 | [diff] [blame] | 23 | |
| 24 | if (cfg.localCharts) { |
| 25 | volthaStackChart = "$WORKSPACE/voltha-helm-charts/voltha-stack" |
Matteo Scandolo | ba4b654 | 2021-06-24 12:06:07 +0200 | [diff] [blame] | 26 | bbsimChart = "$WORKSPACE/voltha-helm-charts/bbsim" |
Matteo Scandolo | fcfc60d | 2021-02-24 09:06:48 -0800 | [diff] [blame] | 27 | |
| 28 | sh """ |
| 29 | pushd $WORKSPACE/voltha-helm-charts/voltha-stack |
| 30 | helm dep update |
| 31 | popd |
| 32 | """ |
| 33 | } |
| 34 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 35 | println "Deploying VOLTHA Stack with the following parameters: ${cfg}." |
| 36 | |
| 37 | sh """ |
Matteo Scandolo | ed1afdd | 2021-04-02 16:25:45 -0700 | [diff] [blame] | 38 | helm upgrade --install --create-namespace -n ${cfg.volthaNamespace} ${cfg.stackName} ${volthaStackChart} \ |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 39 | --set global.stack_name=${cfg.stackName} \ |
| 40 | --set global.voltha_infra_name=voltha-infra \ |
| 41 | --set global.voltha_infra_namespace=${cfg.infraNamespace} \ |
Matteo Scandolo | ed1afdd | 2021-04-02 16:25:45 -0700 | [diff] [blame] | 42 | ${cfg.extraHelmFlags} |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 43 | """ |
| 44 | |
| 45 | for(int i = 0;i<cfg.bbsimReplica;i++) { |
Matteo Scandolo | 0ce69f1 | 2021-05-04 08:44:53 -0700 | [diff] [blame] | 46 | // NOTE we don't need to update the tag for DT |
| 47 | script { |
| 48 | sh """ |
| 49 | rm -f $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml |
| 50 | """ |
| 51 | if (cfg.workflow == "att" || cfg.workflow == "tt") { |
| 52 | def startingStag = 900 |
| 53 | def bbsimCfg = readYaml file: "$WORKSPACE/voltha-helm-charts/examples/${cfg.workflow}-values.yaml" |
| 54 | // NOTE we assume that the only service that needs a different s_tag is the first one in the list |
| 55 | bbsimCfg["servicesConfig"]["services"][0]["s_tag"] = startingStag + i |
| 56 | println "Using BBSim Service config ${bbsimCfg}" |
| 57 | writeYaml file: "$WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml", data: bbsimCfg |
| 58 | } else { |
| 59 | // NOTE if it's DT just copy the file over |
| 60 | sh """ |
| 61 | cp $WORKSPACE/voltha-helm-charts/examples/${cfg.workflow}-values.yaml $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml |
| 62 | """ |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | sh """ |
Matteo Scandolo | ba4b654 | 2021-06-24 12:06:07 +0200 | [diff] [blame] | 67 | helm upgrade --install --create-namespace -n ${cfg.volthaNamespace} bbsim${i} ${bbsimChart} \ |
Matteo Scandolo | 0ce69f1 | 2021-05-04 08:44:53 -0700 | [diff] [blame] | 68 | --set olt_id="${cfg.stackId}${i}" \ |
| 69 | -f $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml \ |
| 70 | ${cfg.extraHelmFlags} |
| 71 | """ |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | println "Wait for VOLTHA Stack ${cfg.stackName} to start" |
| 75 | |
| 76 | sh """ |
| 77 | set +x |
| 78 | voltha=\$(kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers | grep "0/" | wc -l) |
| 79 | while [[ \$voltha != 0 ]]; do |
| 80 | sleep 5 |
| 81 | voltha=\$(kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers | grep "0/" | wc -l) |
| 82 | done |
| 83 | """ |
| 84 | |
| 85 | // also make sure that the ONOS config is loaded |
| 86 | println "Wait for ONOS Config loader to complete" |
| 87 | |
| 88 | sh """ |
| 89 | set +x |
| 90 | config=\$(kubectl get jobs.batch -n ${cfg.infraNamespace} --no-headers | grep "0/" | wc -l) |
| 91 | while [[ \$config != 0 ]]; do |
| 92 | sleep 5 |
| 93 | config=\$(kubectl get jobs.batch -n ${cfg.infraNamespace} --no-headers | grep "0/" | wc -l) |
| 94 | done |
| 95 | """ |
| 96 | } |