summaryrefslogtreecommitdiffstats
path: root/test/policy-local-files/Capacity_vFW_1.json
blob: d5e80ab4e0e160ce4926f83a9cde70049b799c41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
    "service": "vim_fit",
    "policyName": "OSDF_DUBLIN.Capacity_vFW_1",
    "description": "Capacity policy for vFW",
    "templateVersion": "OpenSource.version.1",
    "version": "test1",
    "priority": "5",
    "riskType": "test",
    "riskLevel": "2",
    "guard": "False",
    "content": {
        "identity": "capacity_vFW",
        "policyScope": ["vFW", "US", "INTERNATIONAL", "ip", "vFW"],
	    "resources": ["vFW"],
        "capacityProperty": {
            "controller": "multicloud",
            "request": "{\"vCPU\": 2, \"Memory\": {\"quantity\": {\"get_param\": \"REQUIRED_MEM\"}, \"unit\": \"GB\"}, \"Storage\": {\"quantity\": {\"get_param\": \"REQUIRED_DISK\"}, \"unit\": \"GB\"}}"
        },
        "policyType": "vim_fit",
        "applicableResources": "any"
    }
}
und-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
/**
 * Copyright (c) 2018 ZTE Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and the Apache License 2.0 which both accompany this distribution,
 * and are available at http://www.eclipse.org/legal/epl-v10.html
 * and http://www.apache.org/licenses/LICENSE-2.0
 *
 * Contributors:
 *     ZTE - initial Project
 */
package pilot

import (
	"fmt"

	//	"fmt"
	//	"msb2pilot/models"
	//	"os"
	//	"reflect"
	"testing"
)

func TestList(t *testing.T) {
	res, err := List("virtualservice", "default")
	if err != nil {
		t.Errorf("List() => got %v", err)
	} else {
		fmt.Print(res)
	}
}

//func TestParseParam(t *testing.T) {
//	cases := []struct {
//		in string
//	}{
//		//		{
//		//			in: `{
//		//"apiVersion": "networking.istio.io/v1alpha3",
//		//"kind": "VirtualService",
//		//"metadata": {"name": "default-apigateway"},
//		//"spec": {"hosts":["apigateway"],"http":[{
//		//"match":{"uri": {"prefix": "/portaladmin"}},
//		//"rewrite": {"uri": "/portaladmin"},
//		//"route": [{"destination": {"host": "portaladmin"}}]
//		//},{
//		//"match":{"uri": {"prefix": "/pm_mgt/v1"}},
//		//"rewrite": {"uri": "/pm_mgt/v1"},
//		//"route": [{"destination": {"host": "pm_mgt"}}]
//		//}]}
//		//}`,
//		//		},
//		{
//			in: `{
//"apiVersion": "networking.istio.io/v1alpha3",
//"kind": "VirtualService",
//"metadata": {"name": "default-apigateway"},
//"spec": {"destination":{"service":"reviews.service.consul"},"http":[{
//"match":{"uri": {"prefix": "/portaladmin"}},
//"rewrite": {"uri": "/portaladmin"},
//}]}
//}`,
//		},
//		{
//			in: `{
//"apiVersion": "networking.istio.io/v1alpha3",
//"kind": "VirtualService",
//"metadata": {"name": "default-apigateway"},
//"spec": {"hosts":["test"],"http":[]}
//}`,
//		},
//	}

//	for _, cas := range cases {
//		res, err := ParseParam(cas.in)
//		if err != nil {
//			t.Errorf("ParseParam() => got %v", err)
//		} else {
//			fmt.Print(res)
//		}
//	}
//}

func TestCreate(t *testing.T) {
	str := `
		{
			"apiVersion": "networking.istio.io/v1alpha3",
			"kind": "VirtualService",
			"metadata":{
			  "name": "reviews"},
			"spec":{
			  "hosts":["reviews.service.consul"],
			  "http":[{
				"match":[{"uri": {"prefix": "/pm_mgt/v1"}}],
				"rewrite": {"uri": "/portaladmin"},
			 	"route":[{
			    	"destination":{
			        	"host": "reviews.service.consul",
			        	"subset": "v3"
					}}]
				}]
			}
		}
		`

	config, exist := Get("virtualservice", "default", "reviews")
	if exist {
		Delete("virtualservice", "default", "reviews")
	}
	configs, err := ParseParam(str)
	if err != nil {
		t.Errorf("ParseParam() => got %v", err)
	} else {
		fmt.Println(configs)
	}

	res, err := Create(&configs[0])
	if err != nil {
		t.Errorf("Create() => got %v", err)
	} else {
		fmt.Println(res)
	}

	if exist {
		Create(config)
	}
}

//func TestParseParam(t *testing.T) {
//	str := `
//	{
//		"apiVersion": "networking.istio.io/v1alpha3",
//		"kind": "VirtualService",
//		"metadata":{
//		  "name": "reviews"},
//		"spec":{
//		  "hosts":["reviews.service.consul"],
//		  "http":[{
//		 	"route":[{
//		    	"destination":{
//		        	"host": "reviews.service.consul",
//		        	"subset": "v3"
//				}}]
//			}]
//		}
//	}
//	`
//	res, err := ParseParam(str)
//	if err != nil {
//		t.Errorf("ParseParam() => got %v", err)
//	} else {
//		fmt.Println(res)
//	}
//}

//func TestUpdateK8sAddress(t *testing.T) {
//	cases := []struct {
//		path, addr, want, err string
//	}{
//		{
//			path: "k8s.yml222",
//			addr: "filenoteexisttest",
//			want: "",
//			err:  "*os.PathError",
//		},
//		{
//			path: configPath,
//			addr: "",
//			want: "",
//			err:  "",
//		},
//		{
//			path: configPath,
//			addr: "k8stest",
//			want: "k8stest",
//			err:  "",
//		},
//	}

//	oldEnv := os.Getenv(models.EnvK8sAddress)
//	for _, cas := range cases {
//		os.Unsetenv(models.EnvK8sAddress)
//		os.Setenv(models.EnvK8sAddress, cas.addr)

//		got, err := updateK8sAddress(cas.path)
//		if got != cas.want || (err != nil && reflect.TypeOf(err).String() != cas.err) {
//			t.Errorf("updateK8sAddress(%s, %s) => got %s %v, want %s", cas.path, cas.addr, got, reflect.TypeOf(err), cas.want)
//		}
//	}
//	os.Setenv(models.EnvK8sAddress, oldEnv)
//}