aboutsummaryrefslogtreecommitdiffstats
path: root/kud/tests/sanity-check-for-v2.sh
blob: 80dc2d5ca795526da8376605f0afd5836e2affc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
#!/bin/bash

#  Copyright 2020 Intel Corporation, Inc
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
#

set -o errexit
set -o nounset
set -o pipefail

source _common_test.sh
source _functions.sh
#source _common.sh

# TODO Workaround for MULTICLOUD-1202
function delete_resource_nox {
    call_api_nox -X DELETE "$1"
    ! call_api -X GET "$1" >/dev/null
}

master_ip=$(kubectl cluster-info | grep "Kubernetes master" | \
    awk -F ":" '{print $2}' | awk -F "//" '{print $2}')
rsync_service_port=30441
rsync_service_host="$master_ip"
base_url_orchestrator=${base_url_orchestrator:-"http://$master_ip:30415/v2"}
base_url_clm=${base_url_clm:-"http://$master_ip:30461/v2"}

CSAR_DIR="/opt/csar"
csar_id="cb009bfe-bbee-11e8-9766-525400435678"

app1_helm_path="$CSAR_DIR/$csar_id/prometheus-operator.tar.gz"
app1_profile_path="$CSAR_DIR/$csar_id/prometheus-operator_profile.tar.gz"
app2_helm_path="$CSAR_DIR/$csar_id/collectd.tar.gz"
app2_profile_path="$CSAR_DIR/$csar_id/collectd_profile.tar.gz"

kubeconfig_path="$HOME/.kube/config"

function populate_CSAR_composite_app_helm {
    _checks_args "$1"
    pushd "${CSAR_DIR}/$1"
    print_msg "Create Helm Chart Archives for compositeApp"
    rm -f *.tar.gz
    tar -czf collectd.tar.gz -C $test_folder/vnfs/comp-app/collection/app1/helm .
    tar -czf prometheus-operator.tar.gz -C $test_folder/vnfs/comp-app/collection/app2/helm .
    tar -czf collectd_profile.tar.gz -C $test_folder/vnfs/comp-app/collection/app1/profile .
    tar -czf prometheus-operator_profile.tar.gz -C $test_folder/vnfs/comp-app/collection/app2/profile .
    popd
}


# ---------BEGIN: SET CLM DATA---------------

clusterprovidername="sanity-test-cluster-provider"
clusterproviderdata="$(cat<<EOF
{
  "metadata": {
    "name": "$clusterprovidername",
    "description": "description of $clusterprovidername",
    "userData1": "$clusterprovidername user data 1",
    "userData2": "$clusterprovidername user data 2"
  }
}
EOF
)"

clustername="LocalEdge1"
clusterdata="$(cat<<EOF
{
  "metadata": {
    "name": "$clustername",
    "description": "description of $clustername",
    "userData1": "$clustername user data 1",
    "userData2": "$clustername user data 2"
  }
}
EOF
)"


labelname="LocalLabel"
labeldata="$(cat<<EOF
{"label-name": "$labelname"}
EOF
)"


# add the rsync controller entry
rsynccontrollername="rsync"
rsynccontrollerdata="$(cat<<EOF
{
  "metadata": {
    "name": "rsync",
    "description": "description of $rsynccontrollername controller",
    "userData1": "user data 1 for $rsynccontrollername",
    "userData2": "user data 2 for $rsynccontrollername"
  },
  "spec": {
    "host": "$rsync_service_host",
    "port": $rsync_service_port
  }
}
EOF
)"

# ------------END: SET CLM DATA--------------


#-------------BEGIN:SET ORCH DATA------------------

# define a project
projectname="Sanity-Test-Project"
projectdata="$(cat<<EOF
{
  "metadata": {
    "name": "$projectname",
    "description": "description of $projectname controller",
    "userData1": "$projectname user data 1",
    "userData2": "$projectname user data 2"
  }
}
EOF
)"

# define a composite application
collection_compositeapp_name="CollectionCompositeApp"
compositeapp_version="v1"
compositeapp_data="$(cat <<EOF
{
  "metadata": {
    "name": "${collection_compositeapp_name}",
    "description": "description of ${collection_compositeapp_name}",
    "userData1": "user data 1 for ${collection_compositeapp_name}",
    "userData2": "user data 2 for ${collection_compositeapp_name}"
   },
   "spec":{
      "version":"${compositeapp_version}"
   }
}
EOF
)"

# add app entries for the prometheus app into
# compositeApp

prometheus_app_name="prometheus-operator"
prometheus_helm_chart=${app1_helm_path}

prometheus_app_data="$(cat <<EOF
{
  "metadata": {
    "name": "${prometheus_app_name}",
    "description": "description for app ${prometheus_app_name}",
    "userData1": "user data 2 for ${prometheus_app_name}",
    "userData2": "user data 2 for ${prometheus_app_name}"
   }
}
EOF
)"

# add app entries for the collectd app into
# compositeApp

collectd_app_name="collectd"
collectd_helm_chart=${app2_helm_path}

collectd_app_data="$(cat <<EOF
{
  "metadata": {
    "name": "${collectd_app_name}",
    "description": "description for app ${collectd_app_name}",
    "userData1": "user data 2 for ${collectd_app_name}",
    "userData2": "user data 2 for ${collectd_app_name}"
   }
}
EOF
)"


# Add the composite profile
collection_composite_profile_name="collection_composite-profile"
collection_composite_profile_data="$(cat <<EOF
{
   "metadata":{
      "name":"${collection_composite_profile_name}",
      "description":"description of ${collection_composite_profile_name}",
      "userData1":"user data 1 for ${collection_composite_profile_name}",
      "userData2":"user data 2 for ${collection_composite_profile_name}"
   }
}
EOF
)"

# Add the prometheus profile data into collection profile data
prometheus_profile_name="prometheus-profile"
prometheus_profile_file=$app1_profile_path
prometheus_profile_data="$(cat <<EOF
{
   "metadata":{
      "name":"${prometheus_profile_name}",
      "description":"description of ${prometheus_profile_name}",
      "userData1":"user data 1 for ${prometheus_profile_name}",
      "userData2":"user data 2 for ${prometheus_profile_name}"
   },
   "spec":{
      "app-name":  "${prometheus_app_name}"
   }
}
EOF
)"

# Add the collectd profile data into collection profile data
collectd_profile_name="collectd-profile"
collectd_profile_file=$app2_profile_path
collectd_profile_data="$(cat <<EOF
{
   "metadata":{
      "name":"${collectd_profile_name}",
      "description":"description of ${collectd_profile_name}",
      "userData1":"user data 1 for ${collectd_profile_name}",
      "userData2":"user data 2 for ${collectd_profile_name}"
   },
   "spec":{
      "app-name":  "${collectd_app_name}"
   }
}
EOF
)"


# define the generic placement intent
generic_placement_intent_name="test-generic-placement-intent"
generic_placement_intent_data="$(cat <<EOF
{
   "metadata":{
      "name":"${generic_placement_intent_name}",
      "description":"${generic_placement_intent_name}",
      "userData1":"${generic_placement_intent_name}",
      "userData2":"${generic_placement_intent_name}"
   },
   "spec":{
      "logical-cloud":"unused_logical_cloud"
   }
}
EOF
)"

# define app placement intent for prometheus
prometheus_placement_intent_name="prometheus-placement-intent"
prometheus_placement_intent_data="$(cat <<EOF
{
   "metadata":{
      "name":"${prometheus_placement_intent_name}",
      "description":"description of ${prometheus_placement_intent_name}",
      "userData1":"user data 1 for ${prometheus_placement_intent_name}",
      "userData2":"user data 2 for ${prometheus_placement_intent_name}"
   },
   "spec":{
      "app-name":"${prometheus_app_name}",
      "intent":{
         "allOf":[
            {  "provider-name":"${clusterprovidername}",
               "cluster-label-name":"${labelname}"
            }
         ]
      }
   }
}
EOF
)"

# define app placement intent for collectd
collectd_placement_intent_name="collectd-placement-intent"
collectd_placement_intent_data="$(cat <<EOF
{
   "metadata":{
      "name":"${collectd_placement_intent_name}",
      "description":"description of ${collectd_placement_intent_name}",
      "userData1":"user data 1 for ${collectd_placement_intent_name}",
      "userData2":"user data 2 for ${collectd_placement_intent_name}"
   },
   "spec":{
      "app-name":"${collectd_app_name}",
      "intent":{
         "allOf":[
            {  "provider-name":"${clusterprovidername}",
               "cluster-label-name":"${labelname}"
            }
         ]
      }
   }
}
EOF
)"


# define a deployment intent group
release="test-collection"
deployment_intent_group_name="collection_deployment_intent_group"
deployment_intent_group_data="$(cat <<EOF
{
   "metadata":{
      "name":"${deployment_intent_group_name}",
      "description":"descriptiont of ${deployment_intent_group_name}",
      "userData1":"user data 1 for ${deployment_intent_group_name}",
      "userData2":"user data 2 for ${deployment_intent_group_name}"
   },
   "spec":{
      "profile":"${collection_composite_profile_name}",
      "version":"${release}",
      "override-values":[]
   }
}
EOF
)"

# define the intents to be used by the group
deployment_intents_in_group_name="collection_deploy_intents"
deployment_intents_in_group_data="$(cat <<EOF
{
   "metadata":{
      "name":"${deployment_intents_in_group_name}",
      "description":"descriptionf of ${deployment_intents_in_group_name}",
      "userData1":"user data 1 for ${deployment_intents_in_group_name}",
      "userData2":"user data 2 for ${deployment_intents_in_group_name}"
   },
   "spec":{
      "intent":{
         "genericPlacementIntent":"${generic_placement_intent_name}"
      }
   }
}
EOF
)"


#---------END: SET ORCH DATA--------------------


function createOrchestratorData {

    print_msg "creating controller entries"
    call_api -d "${rsynccontrollerdata}" "${base_url_orchestrator}/controllers"
    print_msg "creating project entry"
    call_api -d "${projectdata}" "${base_url_orchestrator}/projects"

    print_msg "creating collection composite app entry"
    call_api -d "${compositeapp_data}" "${base_url_orchestrator}/projects/${projectname}/composite-apps"

    print_msg "adding prometheus app to the composite app"
    call_api -F "metadata=${prometheus_app_data}" \
             -F "file=@${prometheus_helm_chart}" \
             "${base_url_orchestrator}/projects/${projectname}/composite-apps/${collection_compositeapp_name}/${compositeapp_version}/apps"

    print_msg "adding collectd app to the composite app"
    call_api -F "metadata=${collectd_app_data}" \
             -F "file=@${collectd_helm_chart}" \
             "${base_url_orchestrator}/projects/${projectname}/composite-apps/${collection_compositeapp_name}/${compositeapp_version}/apps"

    print_msg "creating collection composite profile entry"
    call_api -d "${collection_composite_profile_data}" "${base_url_orchestrator}/projects/${projectname}/composite-apps/${collection_compositeapp_name}/${compositeapp_version}/composite-profiles"

    print_msg "adding prometheus app profiles to the composite profile"
    call_api -F "metadata=${prometheus_profile_data}" \
             -F "file=@${prometheus_profile_file}" \
             "${base_url_orchestrator}/projects/${projectname}/composite-apps/${collection_compositeapp_name}/${compositeapp_version}/composite-profiles/${collection_composite_profile_name}/profiles"

    print_msg "adding collectd app profiles to the composite profile"
    call_api -F "metadata=${collectd_profile_data}" \
             -F "file=@${collectd_profile_file}" \
             "${base_url_orchestrator}/projects/${projectname}/composite-apps/${collection_compositeapp_name}/${compositeapp_version}/composite-profiles/${collection_composite_profile_name}/profiles"

    print_msg "create the generic placement intent"
    call_api -d "${generic_placement_intent_data}" \
             "${base_url_orchestrator}/projects/${projectname}/composite-apps/${collection_compositeapp_name}/${compositeapp_version}/generic-placement-intents"

    print_msg "add the prometheus app placement intent to the generic placement intent"
    call_api -d "${prometheus_placement_intent_data}" \
             "${base_url_orchestrator}/projects/${projectname}/composite-apps/${collection_compositeapp_name}/${compositeapp_version}/generic-placement-intents/${generic_placement_intent_name}/app-intents"

    print_msg "add the collectd app placement intent to the generic placement intent"
    call_api -d "${collectd_placement_intent_data}" \
             "${base_url_orchestrator}/projects/${projectname}/composite-apps/${collection_compositeapp_name}/${compositeapp_version}/generic-placement-intents/${generic_placement_intent_name}/app-intents"


    print_msg "create the deployment intent group"
    call_api -d "${deployment_intent_group_data}" \
             "${base_url_orchestrator}/projects/${projectname}/composite-apps/${collection_compositeapp_name}/${compositeapp_version}/deployment-intent-groups"
    call_api -d "${deployment_intents_in_group_data}" \
             "${base_url_orchestrator}/projects/${projectname}/composite-apps/${collection_compositeapp_name}/${compositeapp_version}/deployment-intent-groups/${deployment_intent_group_name}/intents"

}

function deleteOrchestratorData {

    print_msg "Begin deleteOrchestratorData"

    delete_resource "${base_url_orchestrator}/controllers/${rsynccontrollername}"

    delete_resource "${base_url_orchestrator}/projects/${projectname}/composite-apps/${collection_compositeapp_name}/${compositeapp_version}/deployment-intent-groups/${deployment_intent_group_name}/intents/${deployment_intents_in_group_name}"

    delete_resource_nox "${base_url_orchestrator}/projects/${projectname}/composite-apps/${collection_compositeapp_name}/${compositeapp_version}/deployment-intent-groups/${deployment_intent_group_name}"

    delete_resource "${base_url_orchestrator}/projects/${projectname}/composite-apps/${collection_compositeapp_name}/${compositeapp_version}/generic-placement-intents/${generic_placement_intent_name}/app-intents/${prometheus_placement_intent_name}"
    delete_resource "${base_url_orchestrator}/projects/${projectname}/composite-apps/${collection_compositeapp_name}/${compositeapp_version}/generic-placement-intents/${generic_placement_intent_name}/app-intents/${collectd_placement_intent_name}"
    delete_resource "${base_url_orchestrator}/projects/${projectname}/composite-apps/${collection_compositeapp_name}/${compositeapp_version}/generic-placement-intents/${generic_placement_intent_name}"

    delete_resource "${base_url_orchestrator}/projects/${projectname}/composite-apps/${collection_compositeapp_name}/${compositeapp_version}/composite-profiles/${collection_composite_profile_name}/profiles/${prometheus_profile_name}"
    delete_resource "${base_url_orchestrator}/projects/${projectname}/composite-apps/${collection_compositeapp_name}/${compositeapp_version}/composite-profiles/${collection_composite_profile_name}/profiles/${collectd_profile_name}"


    delete_resource "${base_url_orchestrator}/projects/${projectname}/composite-apps/${collection_compositeapp_name}/${compositeapp_version}/composite-profiles/${collection_composite_profile_name}"

    delete_resource "${base_url_orchestrator}/projects/${projectname}/composite-apps/${collection_compositeapp_name}/${compositeapp_version}/apps/${prometheus_app_name}"

    delete_resource "${base_url_orchestrator}/projects/${projectname}/composite-apps/${collection_compositeapp_name}/${compositeapp_version}/apps/${collectd_app_name}"


    delete_resource "${base_url_orchestrator}/projects/${projectname}/composite-apps/${collection_compositeapp_name}/${compositeapp_version}"
    delete_resource "${base_url_orchestrator}/projects/${projectname}"

    print_msg "deleteOrchestratorData done"
}


function createClmData {
    print_msg "Creating cluster provider and cluster"
    call_api -d "${clusterproviderdata}" "${base_url_clm}/cluster-providers"

    call_api -H "Content-Type: multipart/form-data" -F "metadata=$clusterdata" -F "file=@$kubeconfig_path" "${base_url_clm}/cluster-providers/${clusterprovidername}/clusters"

    call_api -d "${labeldata}" "${base_url_clm}/cluster-providers/${clusterprovidername}/clusters/${clustername}/labels"


}

function deleteClmData {
    print_msg "begin deleteClmData"
    delete_resource "${base_url_clm}/cluster-providers/${clusterprovidername}/clusters/${clustername}/labels/${labelname}"
    delete_resource_nox "${base_url_clm}/cluster-providers/${clusterprovidername}/clusters/${clustername}"
    delete_resource "${base_url_clm}/cluster-providers/${clusterprovidername}"
    print_msg "deleteClmData done"
}

function createData {
    createClmData
    createOrchestratorData
}

function deleteData {
    deleteClmData
    deleteOrchestratorData
}

function instantiate {
    call_api -d "{ }" "${base_url_orchestrator}/projects/${projectname}/composite-apps/${collection_compositeapp_name}/${compositeapp_version}/deployment-intent-groups/${deployment_intent_group_name}/approve"
    call_api -d "{ }" "${base_url_orchestrator}/projects/${projectname}/composite-apps/${collection_compositeapp_name}/${compositeapp_version}/deployment-intent-groups/${deployment_intent_group_name}/instantiate"
}


function terminateOrchData {
    call_api -d "{ }" "${base_url_orchestrator}/projects/${projectname}/composite-apps/${collection_compositeapp_name}/${compositeapp_version}/deployment-intent-groups/${deployment_intent_group_name}/terminate"
}

function status {
    call_api "${base_url_orchestrator}/projects/${projectname}/composite-apps/${collection_compositeapp_name}/${compositeapp_version}/deployment-intent-groups/${deployment_intent_group_name}/status"
}

function waitFor {
    wait_for_deployment_status "${base_url_orchestrator}/projects/${projectname}/composite-apps/${collection_compositeapp_name}/${compositeapp_version}/deployment-intent-groups/${deployment_intent_group_name}/status" $1
}

# Setup

function setup {
    install_deps
    populate_CSAR_composite_app_helm "$csar_id"
}

function start {
    setup
    deleteData
    print_msg "Before creating, deleting the data success"
    createData
    print_msg "creating the data success"
    instantiate
    print_msg "instantiate success"
    waitFor "Instantiated"
}

function stop {
    terminateOrchData
    print_msg "terminated the resources"
    waitFor "Terminated"
    deleteData
    print_msg "deleting the data success"
}

function usage {
    echo ""
    echo "    Usage: $0  start | stop"
    echo ""
    echo "    start - creates the orchstrator and cluster management data, instantiates the resources for collectd and prometheus and then deploys them on the local cluster"
    echo ""
    echo "    stop  - terminates the resources for collectd and prometheus and uninstalls the compositeApp"
    echo ""
    exit
}

if [[ "$#" -gt 0 ]] ; then
    case "$1" in
        "start" ) start ;;
        "stop" ) stop ;;
        "create" ) createData ;;
        "instantiate" ) instantiate ;;
        "status" ) status ;;
        "terminate" ) terminateOrchData ;;
        "delete" ) deleteData ;;
        *) usage ;;
    esac
else
    start
    stop
fi