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
|
#!/bin/bash
# SPDX-license-identifier: Apache-2.0
##############################################################################
# Copyright (c) 2018
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
set -o errexit
set -o nounset
set -o pipefail
#set -o xtrace
source _common.sh
source _common_test.sh
source _functions.sh
base_url="http://localhost:9015/v1"
kubeconfig_path="$HOME/.kube/config"
#Will resolve to file $KUBE_CONFIG_DIR/kud
cloud_region_id="kud"
cloud_region_owner="test_owner"
namespace="testns"
csar_id="94e414f6-9ca4-11e8-bb6a-52540067263b"
rb_name="test-rbdef"
rb_version="v1"
profile_name="profile1"
release_name="testrelease"
vnf_customization_uuid="ebe353d2-30b7-11e9-9515-525400277b3d"
# _build_generic_sim() - Creates a generic simulator image in case that doesn't exist
function _build_generic_sim {
if [[ -n $(docker images -q generic_sim) ]]; then
return
fi
BUILD_ARGS="--no-cache"
if [ ${HTTP_PROXY:-} ]; then
BUILD_ARGS+=" --build-arg HTTP_PROXY=${HTTP_PROXY}"
fi
if [ ${HTTPS_PROXY:-} ]; then
BUILD_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}"
fi
pushd generic_simulator
echo "Building generic simulator image..."
docker build ${BUILD_ARGS} -t generic_sim:latest .
popd
}
# start_aai_service() - Starts a simulator for AAI service
function start_aai_service {
_build_generic_sim
if [[ $(docker ps -q --all --filter "name=aai") ]]; then
docker rm aai -f
fi
echo "Start AAI simulator.."
docker run --name aai -v $(mktemp):/tmp/generic_sim/ -v $(pwd)/generic_simulator/aai/:/etc/generic_sim/ -p 8443:8080 -d generic_sim
}
# Setup
install_deps
destroy_deployment $plugin_deployment_name
#start_aai_service
populate_CSAR_plugin $csar_id
populate_CSAR_rbdefinition $csar_id
# Test
print_msg "Create Resource Bundle Definition Metadata"
payload="
{
\"rb-name\": \"${rb_name}\",
\"rb-version\": \"${rb_version}\",
\"chart-name\": \"vault-consul-dev\",
\"description\": \"testing resource bundle definition api\",
\"labels\": {
\"vnf_customization_uuid\": \"${vnf_customization_uuid}\"
}
}
"
call_api -d "$payload" "${base_url}/rb/definition"
print_msg "Upload Resource Bundle Definition Content"
call_api --data-binary "@${CSAR_DIR}/${csar_id}/vault-consul-dev-0.0.0.tgz" "${base_url}/rb/definition/$rb_name/$rb_version/content"
print_msg "Listing Resource Bundle Definitions"
rb_list=$(call_api "${base_url}/rb/definition/$rb_name")
if [[ "$rb_list" != *"${rb_name}"* ]]; then
echo $rb_list
echo "Resource Bundle Definition not stored"
exit 1
fi
print_msg "Create Resource Bundle Profile Metadata"
kubeversion=$(kubectl version | grep 'Server Version' | awk -F '"' '{print $6}')
payload="
{
\"profile-name\": \"${profile_name}\",
\"rb-name\": \"${rb_name}\",
\"rb-version\": \"${rb_version}\",
\"release-name\": \"${release_name}\",
\"namespace\": \"$namespace\",
\"kubernetesversion\": \"$kubeversion\",
\"labels\": {
\"vnf_customization_uuid\": \"${vnf_customization_uuid}\"
}
}
"
call_api -d "$payload" "${base_url}/rb/definition/$rb_name/$rb_version/profile"
print_msg "Upload Resource Bundle Profile Content"
call_api --data-binary "@${CSAR_DIR}/${csar_id}/rb_profile.tar.gz" "${base_url}/rb/definition/$rb_name/$rb_version/profile/$profile_name/content"
print_msg "Getting Resource Bundle Profile"
rbp_ret=$(call_api "${base_url}/rb/definition/$rb_name/$rb_version/profile/$profile_name")
if [[ "$rbp_ret" != *"${profile_name}"* ]]; then
echo $rbp_ret
echo "Resource Bundle Profile not stored"
exit 1
fi
print_msg "Setup cloud data"
payload="$(cat <<EOF
{
"cloud-region": "$cloud_region_id",
"cloud-owner": "$cloud_region_owner"
}
EOF
)"
call_api -F "metadata=$payload" \
-F "file=@$kubeconfig_path" \
"${base_url}/connectivity-info" >/dev/null
print_msg "Instantiate Profile"
payload="
{
\"cloud-region\": \"$cloud_region_id\",
\"rb-name\":\"$rb_name\",
\"rb-version\":\"$rb_version\",
\"profile-name\":\"$profile_name\"
}
"
inst_id=$(call_api -d "$payload" "${base_url}/instance")
echo "$inst_id"
inst_id=$(jq -r '.id' <<< "$inst_id")
print_msg "Validating Kubernetes"
kubectl get --no-headers=true --namespace=${namespace} deployment ${release_name}-vault-consul-dev
kubectl get --no-headers=true --namespace=${namespace} service override-vault-consul
echo "VNF Instance created succesfully with id: $inst_id"
print_msg "Getting $inst_id VNF Instance information"
call_api "${base_url}/instance/${inst_id}"
# Teardown
print_msg "Deleting $rb_name/$rb_version Resource Bundle Definition"
# TODO: Change the HTTP code for 404 when the resource is not found in the API
delete_resource "${base_url}/rb/definition/$rb_name/$rb_version"
print_msg "Deleting $profile_name Resource Bundle Profile"
# TODO: Change the HTTP code for 404 when the resource is not found in the API
delete_resource "${base_url}/rb/definition/$rb_name/$rb_version/profile/$profile_name"
print_msg "Deleting $inst_id VNF Instance"
delete_resource "${base_url}/instance/${inst_id}"
print_msg "Deleting ${cloud_region_id} cloud region connection"
delete_resource "${base_url}/connectivity-info/${cloud_region_id}"
teardown $plugin_deployment_name
|