diff options
-rw-r--r-- | kud/deployment_infra/playbooks/configure-istio.yml | 6 | ||||
-rw-r--r-- | kud/deployment_infra/playbooks/configure-kud.yml | 17 | ||||
-rwxr-xr-x | kud/tests/_common.sh | 12 | ||||
-rwxr-xr-x | kud/tests/_functions.sh | 38 | ||||
-rwxr-xr-x | kud/tests/plugin_edgex.sh | 135 | ||||
-rw-r--r-- | kud/tests/vnfs/edgex/profile/manifest.yaml | 4 | ||||
-rw-r--r-- | kud/tests/vnfs/edgex/profile/override_values.yaml | 1 | ||||
-rw-r--r-- | src/k8splugin/Makefile | 2 | ||||
-rw-r--r-- | src/k8splugin/internal/connection/connection.go | 45 | ||||
-rw-r--r-- | src/k8splugin/internal/helm/helm.go | 14 | ||||
-rw-r--r-- | src/k8splugin/internal/rb/archive.go | 7 | ||||
-rw-r--r-- | src/k8splugin/internal/utils.go | 12 |
12 files changed, 228 insertions, 65 deletions
diff --git a/kud/deployment_infra/playbooks/configure-istio.yml b/kud/deployment_infra/playbooks/configure-istio.yml index 3a1ca8ed..f975e309 100644 --- a/kud/deployment_infra/playbooks/configure-istio.yml +++ b/kud/deployment_infra/playbooks/configure-istio.yml @@ -9,14 +9,10 @@ ############################################################################## - hosts: localhost - pre_tasks: + tasks: - name: Load kud variables include_vars: file: kud-vars.yml - roles: - - role: andrewrothstein.kubernetes-helm - kubernetes_helm_ver: "v{{ helm_client_version }}" - tasks: - name: create istio folder file: state: directory diff --git a/kud/deployment_infra/playbooks/configure-kud.yml b/kud/deployment_infra/playbooks/configure-kud.yml index 9dcf6f39..0e32e69d 100644 --- a/kud/deployment_infra/playbooks/configure-kud.yml +++ b/kud/deployment_infra/playbooks/configure-kud.yml @@ -7,6 +7,23 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +- hosts: localhost + pre_tasks: + - name: Load kud variables + include_vars: + file: kud-vars.yml + - name: Check if helm client is already installed #It is in single node deployment + command: helm version -c + register: helm_client + failed_when: False + changed_when: False + check_mode: False + roles: + - name: andrewrothstein.kubernetes-helm + when: helm_client.rc != 0 + vars: + kubernetes_helm_ver: "v{{ helm_client_version }}" + - hosts: kube-node become: yes tasks: diff --git a/kud/tests/_common.sh b/kud/tests/_common.sh index 3120dad7..bfb6ec4b 100755 --- a/kud/tests/_common.sh +++ b/kud/tests/_common.sh @@ -1132,3 +1132,15 @@ function populate_CSAR_rbdefinition { gzip $rbd_content_tarball popd } + +# populate_CSAR_edgex_rbdefinition() - Function that populates CSAR folder +# for testing resource bundle definition of edgex scenario +function populate_CSAR_edgex_rbdefinition { + _checks_args "$1" + pushd "${CSAR_DIR}/$1" + print_msg "Create Helm Chart Archives" + rm -f *.tar.gz + tar -czf rb_profile.tar.gz -C $test_folder/vnfs/edgex/profile . + tar -czf rb_definition.tar.gz -C $test_folder/vnfs/edgex/helm edgex + popd +} diff --git a/kud/tests/_functions.sh b/kud/tests/_functions.sh index a885bc50..483aed5c 100755 --- a/kud/tests/_functions.sh +++ b/kud/tests/_functions.sh @@ -33,6 +33,44 @@ function get_ovn_central_address { echo "$(echo ${ansible_ifconfig#*>>} | tr '\n' ':')6641" } +function call_api { + #Runs curl with passed flags and provides + #additional error handling and debug information + + #Function outputs server response body + #and performs validation of http_code + + local status + local curl_response_file="$(mktemp -p /tmp)" + local curl_common_flags=(-s -w "%{http_code}" -o "${curl_response_file}") + local command=(curl "${curl_common_flags[@]}" "$@") + + echo "[INFO] Running '${command[@]}'" >&2 + if ! status="$("${command[@]}")"; then + echo "[ERROR] Internal curl error! '$status'" >&2 + cat "${curl_response_file}" + rm "${curl_response_file}" + return 2 + else + echo "[INFO] Server replied with status: ${status}" >&2 + cat "${curl_response_file}" + rm "${curl_response_file}" + if [[ "${status:0:1}" =~ [45] ]]; then + return 1 + else + return 0 + fi + fi +} + +function delete_resource { + #Issues DELETE http call to provided endpoint + #and further validates by following GET request + + call_api -X DELETE "$1" + ! call_api -X GET "$1" >/dev/null +} + # init_network() - This function creates the OVN resouces required by the test function init_network { local fname=$1 diff --git a/kud/tests/plugin_edgex.sh b/kud/tests/plugin_edgex.sh index 4e806e6f..929961c0 100755 --- a/kud/tests/plugin_edgex.sh +++ b/kud/tests/plugin_edgex.sh @@ -15,57 +15,100 @@ set -o pipefail source _common_test.sh source _functions.sh +source _common.sh -base_url="http://localhost:8081/v1/vnf_instances/" -cloud_region_id="kud" -namespace="default" +base_url="http://localhost:9015/v1" +kubeconfig_path="$HOME/.kube/config" csar_id=cb009bfe-bbee-11e8-9766-525400435678 +rb_name="edgex" +rb_version="plugin_test" +chart_name="edgex" +profile_name="test_profile" +release_name="test-release" +namespace="plugin-tests-namespace" +cloud_region_id="kud" +cloud_region_owner="localhost" # Setup install_deps -_checks_args ${csar_id} -cp -R ./edgex/* ${CSAR_DIR}/${csar_id}/ +populate_CSAR_edgex_rbdefinition "$csar_id" + +print_msg "Registering resource bundle" +payload="$(cat <<EOF +{ + "rb-name": "${rb_name}", + "rb-version": "${rb_version}", + "chart-name": "${chart_name}" +} +EOF +)" +call_api -d "${payload}" "${base_url}/rb/definition" + +print_msg "Uploading resource bundle content" +call_api --data-binary "@${CSAR_DIR}/${csar_id}/rb_definition.tar.gz" \ + "${base_url}/rb/definition/${rb_name}/${rb_version}/content" + +print_msg "Registering rb's profile" +payload="$(cat <<EOF +{ + "rb-name": "${rb_name}", + "rb-version": "${rb_version}", + "profile-name": "${profile_name}", + "release-name": "${release_name}", + "namespace": "${namespace}" +} +EOF +)" +call_api -d "${payload}" "${base_url}/rb/definition/${rb_name}/${rb_version}/profile" + +print_msg "Uploading profile data" +call_api --data-binary "@${CSAR_DIR}/${csar_id}/rb_profile.tar.gz" \ + "${base_url}/rb/definition/${rb_name}/${rb_version}/profile/${profile_name}/content" -# Test -payload_raw=" +print_msg "Setup cloud data" +payload="$(cat <<EOF { - \"cloud_region_id\": \"$cloud_region_id\", - \"namespace\": \"$namespace\", - \"csar_id\": \"$csar_id\" + "cloud-region": "$cloud_region_id", + "cloud-owner": "$cloud_region_owner" } -" -payload=$(echo $payload_raw | tr '\n' ' ') - -echo "Creating EdgeX VNF Instance" - -vnf_id=$(curl -s -d "$payload" "${base_url}" | jq -r '.vnf_id') - -echo "=== Validating Kubernetes ===" -kubectl get --no-headers=true --namespace=${namespace} deployment ${cloud_region_id}-${namespace}-${vnf_id}-edgex-core-command -kubectl get --no-headers=true --namespace=${namespace} service ${cloud_region_id}-${namespace}-${vnf_id}-edgex-core-command -echo "VNF Instance created succesfully with id: $vnf_id" - -# TODO: Add heath checks to verify EdgeX services - -vnf_id_list=$(curl -s -X GET "${base_url}${cloud_region_id}/${namespace}" | jq -r '.vnf_id_list') -if [[ "$vnf_id_list" != *"${vnf_id}"* ]]; then - echo $vnf_id_list - echo "VNF Instance not stored" - exit 1 -fi - -vnf_details=$(curl -s -X GET "${base_url}${cloud_region_id}/${namespace}/${vnf_id}") -if [[ -z "$vnf_details" ]]; then - echo "Cannot retrieved VNF Instance details" - exit 1 -fi -echo "VNF details $vnf_details" - -echo "Deleting $vnf_id VNF Instance" -curl -X DELETE "${base_url}${cloud_region_id}/${namespace}/${vnf_id}" -if [[ -n $(curl -s -X GET "${base_url}${cloud_region_id}/${namespace}/${vnf_id}") ]]; then - echo "VNF Instance not deleted" - exit 1 -fi - -# Teardown +EOF +)" +call_api -F "metadata=$payload" \ + -F "file=@$kubeconfig_path" \ + "${base_url}/connectivity-info" >/dev/null #massive output + +print_msg "Creating EdgeX VNF Instance" +payload="$(cat <<EOF +{ + "rb-name": "${rb_name}", + "rb-version": "${rb_version}", + "profile-name": "${profile_name}", + "cloud-region": "${cloud_region_id}" +} +EOF +)" +response="$(call_api -d "${payload}" "${base_url}/instance")" +echo "$response" +vnf_id="$(jq -r '.id' <<< "${response}")" + +print_msg "Validating Kubernetes" +kubectl get --no-headers=true --namespace=${namespace} deployment edgex-core-command +kubectl get --no-headers=true --namespace=${namespace} service edgex-core-command +# TODO: Add health checks to verify EdgeX services + +print_msg "Retrieving VNF details" +call_api "${base_url}/instance/${vnf_id}" + + +#Teardown +print_msg "Deleting VNF Instance" +delete_resource "${base_url}/instance/${vnf_id}" + +print_msg "Deleting Profile" +delete_resource "${base_url}/rb/definition/${rb_name}/${rb_version}/profile/${profile_name}" + +print_msg "Deleting Resource Bundle" +delete_resource "${base_url}/rb/definition/${rb_name}/${rb_version}" + +print_msg "Deleting ${cloud_region_id} cloud region connection" +delete_resource "${base_url}/connectivity-info/${cloud_region_id}" diff --git a/kud/tests/vnfs/edgex/profile/manifest.yaml b/kud/tests/vnfs/edgex/profile/manifest.yaml new file mode 100644 index 00000000..4d381d02 --- /dev/null +++ b/kud/tests/vnfs/edgex/profile/manifest.yaml @@ -0,0 +1,4 @@ +--- +version: v1 +type: + values: "override_values.yaml" diff --git a/kud/tests/vnfs/edgex/profile/override_values.yaml b/kud/tests/vnfs/edgex/profile/override_values.yaml new file mode 100644 index 00000000..60232e14 --- /dev/null +++ b/kud/tests/vnfs/edgex/profile/override_values.yaml @@ -0,0 +1 @@ +test_value: 7 diff --git a/src/k8splugin/Makefile b/src/k8splugin/Makefile index d5bdb6fc..55449947 100644 --- a/src/k8splugin/Makefile +++ b/src/k8splugin/Makefile @@ -44,5 +44,5 @@ clean: .PHONY: cover cover: - @go test ./... -coverprofile=coverage.out + @go test -p 2 ./... -coverprofile=coverage.out @go tool cover -html=coverage.out -o coverage.html diff --git a/src/k8splugin/internal/connection/connection.go b/src/k8splugin/internal/connection/connection.go index d110c221..adb1e992 100644 --- a/src/k8splugin/internal/connection/connection.go +++ b/src/k8splugin/internal/connection/connection.go @@ -20,6 +20,7 @@ import ( "encoding/base64" "encoding/json" "io/ioutil" + "log" "path/filepath" "github.com/onap/multicloud-k8s/src/k8splugin/internal/db" @@ -32,7 +33,13 @@ type Connection struct { CloudRegion string `json:"cloud-region"` CloudOwner string `json:"cloud-owner"` Kubeconfig string `json:"kubeconfig"` - OtherConnectivityList map[string]interface{} `json:"other-connectivity-list"` + OtherConnectivityList ConnectivityRecordList `json:"other-connectivity-list"` +} + +// ConnectivityRecordList covers lists of connectivity records +// and any other data that needs to be stored +type ConnectivityRecordList struct { + ConnectivityRecords []map[string]string `json:"connectivity-records"` } // ConnectionKey is the key structure that is used in the database @@ -56,6 +63,7 @@ type ConnectionManager interface { Create(c Connection) (Connection, error) Get(name string) (Connection, error) Delete(name string) error + GetConnectivityRecordByName(connname string, name string) (map[string]string, error) } // ConnectionClient implements the ConnectionManager @@ -65,7 +73,7 @@ type ConnectionClient struct { tagMeta string } -// New ConnectionClient returns an instance of the ConnectionClient +// NewConnectionClient returns an instance of the ConnectionClient // which implements the ConnectionManager func NewConnectionClient() *ConnectionClient { return &ConnectionClient{ @@ -117,6 +125,39 @@ func (v *ConnectionClient) Get(name string) (Connection, error) { return Connection{}, pkgerrors.New("Error getting Connection") } +// GetConnectivityRecordByName returns Connection for corresponding to name +// JSON example: +// "connectivity-records" : +// [ +// { +// “connectivity-record-name” : “<name>”, // example: OVN +// “FQDN-or-ip” : “<fqdn>”, +// “ca-cert-to-verify-server” : “<contents of CA certificate to validate the OVN server>”, +// “ssl-initiator” : “<true/false”>, +// “user-name”: “<user name>”, //valid if ssl-initator is false +// “password” : “<password>”, // valid if ssl-initiator is false +// “private-key” : “<contents of private key in PEM>”, // valid if ssl-initiator is true +// “cert-to-present” : “<contents of certificate to present to server>” , //valid if ssl-initiator is true +// }, +// ] +func (v *ConnectionClient) GetConnectivityRecordByName(connectionName string, + connectivityRecordName string) (map[string]string, error) { + + conn, err := v.Get(connectionName) + if err != nil { + return nil, pkgerrors.Wrap(err, "Error getting connection") + } + + for _, value := range conn.OtherConnectivityList.ConnectivityRecords { + log.Println(value) + if connectivityRecordName == value["connectivity-record-name"] { + return value, nil + } + } + + return nil, pkgerrors.New("Connectivity record " + connectivityRecordName + " not found") +} + // Delete the Connection from database func (v *ConnectionClient) Delete(name string) error { diff --git a/src/k8splugin/internal/helm/helm.go b/src/k8splugin/internal/helm/helm.go index 1ab701ae..2150758b 100644 --- a/src/k8splugin/internal/helm/helm.go +++ b/src/k8splugin/internal/helm/helm.go @@ -21,11 +21,12 @@ import ( "io/ioutil" "k8s.io/helm/pkg/strvals" "os" - "path" "path/filepath" "regexp" "strings" + utils "github.com/onap/multicloud-k8s/src/k8splugin/internal" + "github.com/ghodss/yaml" pkgerrors "github.com/pkg/errors" "k8s.io/apimachinery/pkg/runtime/schema" @@ -135,15 +136,6 @@ func (h *TemplateClient) mergeValues(dest map[string]interface{}, src map[string return dest } -func (h *TemplateClient) ensureDirectory(f string) error { - base := path.Dir(f) - _, err := os.Stat(base) - if err != nil && !os.IsNotExist(err) { - return err - } - return os.MkdirAll(base, 0755) -} - // GenerateKubernetesArtifacts a mapping of type to fully evaluated helm template func (h *TemplateClient) GenerateKubernetesArtifacts(inputPath string, valueFiles []string, values []string) ([]KubernetesResourceTemplate, error) { @@ -245,7 +237,7 @@ func (h *TemplateClient) GenerateKubernetesArtifacts(inputPath string, valueFile } mfilePath := filepath.Join(outputDir, m.Name) - h.ensureDirectory(mfilePath) + utils.EnsureDirectory(mfilePath) err = ioutil.WriteFile(mfilePath, []byte(data), 0666) if err != nil { return retData, err diff --git a/src/k8splugin/internal/rb/archive.go b/src/k8splugin/internal/rb/archive.go index 624adfba..c0753134 100644 --- a/src/k8splugin/internal/rb/archive.go +++ b/src/k8splugin/internal/rb/archive.go @@ -24,6 +24,8 @@ import ( "io/ioutil" "os" "path/filepath" + + utils "github.com/onap/multicloud-k8s/src/k8splugin/internal" ) func isTarGz(r io.Reader) error { @@ -113,6 +115,11 @@ func ExtractTarBall(r io.Reader) (string, error) { } } case tar.TypeReg: + err = utils.EnsureDirectory(target) + if err != nil { + return "", pkgerrors.Wrap(err, "Creating Directory") + } + f, err := os.OpenFile(target, os.O_CREATE|os.O_RDWR, os.FileMode(header.Mode)) if err != nil { return "", pkgerrors.Wrap(err, "Creating file") diff --git a/src/k8splugin/internal/utils.go b/src/k8splugin/internal/utils.go index 627fb305..47a236c2 100644 --- a/src/k8splugin/internal/utils.go +++ b/src/k8splugin/internal/utils.go @@ -18,6 +18,7 @@ import ( "log" "os" "path/filepath" + "path" "plugin" "strings" @@ -128,3 +129,14 @@ func CheckInitialSettings() error { return nil } + +//EnsureDirectory makes sure that the directories specified in the path exist +//If not, it will create them, if possible. +func EnsureDirectory(f string) error { + base := path.Dir(f) + _, err := os.Stat(base) + if err != nil && !os.IsNotExist(err) { + return err + } + return os.MkdirAll(base, 0755) +} |