Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame^] | 1 | #!/usr/bin/env groovy |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 2 | |
| 3 | def call(Map config) { |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame^] | 4 | |
| 5 | String iam = 'vars/volthaStackDeploy.groovy' |
| 6 | println("** ${iam}: ENTER") |
| 7 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 8 | // note that I can't define this outside the function as there's no global scope in Groovy |
| 9 | def defaultConfig = [ |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 10 | bbsimReplica: 1, |
| 11 | infraNamespace: "infra", |
| 12 | volthaNamespace: "voltha", |
| 13 | stackName: "voltha", |
Matteo Scandolo | 2bc660a | 2021-02-12 10:52:25 -0800 | [diff] [blame] | 14 | 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] | 15 | workflow: "att", |
Hardik Windlass | 2b16434 | 2022-02-28 03:50:48 +0000 | [diff] [blame] | 16 | withMacLearning: false, |
Hardik Windlass | c97ceae | 2022-05-13 10:12:55 +0530 | [diff] [blame] | 17 | withFttb: false, |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 18 | extraHelmFlags: "", |
Matteo Scandolo | fcfc60d | 2021-02-24 09:06:48 -0800 | [diff] [blame] | 19 | localCharts: false, |
Matteo Scandolo | 529e882 | 2021-07-21 10:20:18 -0700 | [diff] [blame] | 20 | onosReplica: 1, |
Andrea Campanella | 365ea1e | 2021-09-28 10:50:01 +0200 | [diff] [blame] | 21 | adaptersToWait: 2, |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 22 | ] |
| 23 | |
| 24 | if (!config) { |
| 25 | config = [:] |
| 26 | } |
| 27 | |
| 28 | def cfg = defaultConfig + config |
| 29 | |
Matteo Scandolo | fcfc60d | 2021-02-24 09:06:48 -0800 | [diff] [blame] | 30 | def volthaStackChart = "onf/voltha-stack" |
Matteo Scandolo | ba4b654 | 2021-06-24 12:06:07 +0200 | [diff] [blame] | 31 | def bbsimChart = "onf/bbsim" |
Matteo Scandolo | fcfc60d | 2021-02-24 09:06:48 -0800 | [diff] [blame] | 32 | |
| 33 | if (cfg.localCharts) { |
| 34 | volthaStackChart = "$WORKSPACE/voltha-helm-charts/voltha-stack" |
Matteo Scandolo | ba4b654 | 2021-06-24 12:06:07 +0200 | [diff] [blame] | 35 | bbsimChart = "$WORKSPACE/voltha-helm-charts/bbsim" |
Matteo Scandolo | fcfc60d | 2021-02-24 09:06:48 -0800 | [diff] [blame] | 36 | |
| 37 | sh """ |
| 38 | pushd $WORKSPACE/voltha-helm-charts/voltha-stack |
| 39 | helm dep update |
| 40 | popd |
| 41 | """ |
| 42 | } |
| 43 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 44 | println "Deploying VOLTHA Stack with the following parameters: ${cfg}." |
| 45 | |
| 46 | sh """ |
Matteo Scandolo | ed1afdd | 2021-04-02 16:25:45 -0700 | [diff] [blame] | 47 | helm upgrade --install --create-namespace -n ${cfg.volthaNamespace} ${cfg.stackName} ${volthaStackChart} \ |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 48 | --set global.stack_name=${cfg.stackName} \ |
| 49 | --set global.voltha_infra_name=voltha-infra \ |
Matteo Scandolo | 529e882 | 2021-07-21 10:20:18 -0700 | [diff] [blame] | 50 | --set voltha.onos_classic.replicas=${cfg.onosReplica} \ |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 51 | --set global.voltha_infra_namespace=${cfg.infraNamespace} \ |
Matteo Scandolo | ed1afdd | 2021-04-02 16:25:45 -0700 | [diff] [blame] | 52 | ${cfg.extraHelmFlags} |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 53 | """ |
| 54 | |
| 55 | for(int i = 0;i<cfg.bbsimReplica;i++) { |
Matteo Scandolo | 0ce69f1 | 2021-05-04 08:44:53 -0700 | [diff] [blame] | 56 | // NOTE we don't need to update the tag for DT |
| 57 | script { |
| 58 | sh """ |
| 59 | rm -f $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml |
| 60 | """ |
| 61 | if (cfg.workflow == "att" || cfg.workflow == "tt") { |
| 62 | def startingStag = 900 |
Hardik Windlass | 810b6cf | 2022-02-24 09:21:18 +0000 | [diff] [blame] | 63 | def serviceConfigFile = cfg.workflow |
| 64 | if (cfg.withMacLearning && cfg.workflow == 'tt') { |
| 65 | serviceConfigFile = "tt-maclearner" |
| 66 | } |
| 67 | def bbsimCfg = readYaml file: "$WORKSPACE/voltha-helm-charts/examples/${serviceConfigFile}-values.yaml" |
Matteo Scandolo | 0ce69f1 | 2021-05-04 08:44:53 -0700 | [diff] [blame] | 68 | // NOTE we assume that the only service that needs a different s_tag is the first one in the list |
| 69 | bbsimCfg["servicesConfig"]["services"][0]["s_tag"] = startingStag + i |
Matteo Scandolo | e765ee3 | 2021-07-20 16:47:19 -0700 | [diff] [blame] | 70 | println "Using BBSim Service config ${bbsimCfg['servicesConfig']}" |
Matteo Scandolo | 0ce69f1 | 2021-05-04 08:44:53 -0700 | [diff] [blame] | 71 | writeYaml file: "$WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml", data: bbsimCfg |
| 72 | } else { |
| 73 | // NOTE if it's DT just copy the file over |
| 74 | sh """ |
| 75 | cp $WORKSPACE/voltha-helm-charts/examples/${cfg.workflow}-values.yaml $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml |
| 76 | """ |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | sh """ |
Matteo Scandolo | ba4b654 | 2021-06-24 12:06:07 +0200 | [diff] [blame] | 81 | helm upgrade --install --create-namespace -n ${cfg.volthaNamespace} bbsim${i} ${bbsimChart} \ |
Matteo Scandolo | 0ce69f1 | 2021-05-04 08:44:53 -0700 | [diff] [blame] | 82 | --set olt_id="${cfg.stackId}${i}" \ |
| 83 | -f $WORKSPACE/bbsimCfg${cfg.stackId}${i}.yaml \ |
| 84 | ${cfg.extraHelmFlags} |
| 85 | """ |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | println "Wait for VOLTHA Stack ${cfg.stackName} to start" |
| 89 | |
| 90 | sh """ |
| 91 | set +x |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame^] | 92 | |
| 93 | # [joey]: debug |
| 94 | kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers |
| 95 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 96 | voltha=\$(kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers | grep "0/" | wc -l) |
| 97 | while [[ \$voltha != 0 ]]; do |
| 98 | sleep 5 |
| 99 | voltha=\$(kubectl get pods -n ${cfg.volthaNamespace} -l app.kubernetes.io/part-of=voltha --no-headers | grep "0/" | wc -l) |
| 100 | done |
| 101 | """ |
| 102 | |
Andrea Campanella | 365ea1e | 2021-09-28 10:50:01 +0200 | [diff] [blame] | 103 | waitForAdapters(cfg) |
Matteo Scandolo | 937f479 | 2021-09-24 11:05:52 -0700 | [diff] [blame] | 104 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 105 | // also make sure that the ONOS config is loaded |
Andrea Campanella | 04b393a | 2021-07-22 10:48:33 +0200 | [diff] [blame] | 106 | // NOTE that this is only required for VOLTHA-2.8 |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 107 | println "Wait for ONOS Config loader to complete" |
| 108 | |
Andrea Campanella | 04b393a | 2021-07-22 10:48:33 +0200 | [diff] [blame] | 109 | // NOTE that this is only required for VOLTHA-2.8, |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 110 | sh """ |
| 111 | set +x |
| 112 | config=\$(kubectl get jobs.batch -n ${cfg.infraNamespace} --no-headers | grep "0/" | wc -l) |
| 113 | while [[ \$config != 0 ]]; do |
| 114 | sleep 5 |
| 115 | config=\$(kubectl get jobs.batch -n ${cfg.infraNamespace} --no-headers | grep "0/" | wc -l) |
| 116 | done |
| 117 | """ |
Andrea Campanella | 04b393a | 2021-07-22 10:48:33 +0200 | [diff] [blame] | 118 | // 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] | 119 | // meaning ONOS fully deployed |
Andrea Campanella | 04b393a | 2021-07-22 10:48:33 +0200 | [diff] [blame] | 120 | sh """ |
| 121 | set +x |
Andrea Campanella | 1183251 | 2021-07-23 10:53:19 +0200 | [diff] [blame] | 122 | 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] | 123 | while [[ \$config != 0 ]]; do |
| 124 | sleep 5 |
Andrea Campanella | 1183251 | 2021-07-23 10:53:19 +0200 | [diff] [blame] | 125 | 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] | 126 | done |
| 127 | """ |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame^] | 128 | |
| 129 | println("** ${iam}: LEAVE") |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 130 | } |