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