summaryrefslogtreecommitdiffstats
path: root/src/k8splugin/csar
diff options
context:
space:
mode:
authorVictor Morales <victor.morales@intel.com>2018-09-18 17:19:00 -0700
committerVictor Morales <victor.morales@intel.com>2018-09-18 17:19:00 -0700
commit05274b1b149139d91445ca10a73defe41f14824a (patch)
tree2ad5e9169a521d29d0c909a271f1ff23b35d2dac /src/k8splugin/csar
parentb368dfe25337494060eb8cd85a5becaf7a465643 (diff)
Add UTs to plugins
Deployment, service and namespace are plugins which offers CRUD operations to manage their resources. They haven't implemented Unit Tests which makes fragile to change/refactor the source code. This change adds their corresponding Unit Tests and defines a standard interface. Change-Id: I1e1eb40f1a18ba33c74069a117462c8df17767ac Signed-off-by: Victor Morales <victor.morales@intel.com> Issue-ID: MULTICLOUD-301
Diffstat (limited to 'src/k8splugin/csar')
-rw-r--r--src/k8splugin/csar/parser.go30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/k8splugin/csar/parser.go b/src/k8splugin/csar/parser.go
index af4546c6..6cb07fc2 100644
--- a/src/k8splugin/csar/parser.go
+++ b/src/k8splugin/csar/parser.go
@@ -34,31 +34,31 @@ func generateExternalVNFID() string {
return hex.EncodeToString(b)
}
-func ensuresNamespace(namespace string, kubeclient *kubernetes.Clientset) error {
+func ensuresNamespace(namespace string, kubeclient kubernetes.Interface) error {
namespacePlugin, ok := krd.LoadedPlugins["namespace"]
if !ok {
return pkgerrors.New("No plugin for namespace resource found")
}
- symGetNamespaceFunc, err := namespacePlugin.Lookup("GetResource")
+ symGetNamespaceFunc, err := namespacePlugin.Lookup("Get")
if err != nil {
return pkgerrors.Wrap(err, "Error fetching get namespace function")
}
- exists, err := symGetNamespaceFunc.(func(string, *kubernetes.Clientset) (bool, error))(
- namespace, kubeclient)
+ ns, err := symGetNamespaceFunc.(func(string, string, kubernetes.Interface) (string, error))(
+ namespace, "", kubeclient)
if err != nil {
return pkgerrors.Wrap(err, "An error ocurred during the get namespace execution")
}
- if !exists {
+ if ns == "" {
log.Println("Creating " + namespace + " namespace")
- symGetNamespaceFunc, err := namespacePlugin.Lookup("CreateResource")
+ symGetNamespaceFunc, err := namespacePlugin.Lookup("Create")
if err != nil {
return pkgerrors.Wrap(err, "Error fetching create namespace plugin")
}
- err = symGetNamespaceFunc.(func(string, *kubernetes.Clientset) error)(
+ err = symGetNamespaceFunc.(func(string, kubernetes.Interface) error)(
namespace, kubeclient)
if err != nil {
return pkgerrors.Wrap(err, "Error creating "+namespace+" namespace")
@@ -99,10 +99,10 @@ var CreateVNF = func(csarID string, cloudRegionID string, namespace string, kube
}
log.Println("Processing file: " + path)
- genericKubeData := &krd.GenericKubeResourceData{
- YamlFilePath: path,
- Namespace: namespace,
- InternalVNFID: internalVNFID,
+ genericKubeData := &krd.ResourceData{
+ YamlFilePath: path,
+ Namespace: namespace,
+ VnfId: internalVNFID,
}
typePlugin, ok := krd.LoadedPlugins[resource]
@@ -110,12 +110,12 @@ var CreateVNF = func(csarID string, cloudRegionID string, namespace string, kube
return "", nil, pkgerrors.New("No plugin for resource " + resource + " found")
}
- symCreateResourceFunc, err := typePlugin.Lookup("CreateResource")
+ symCreateResourceFunc, err := typePlugin.Lookup("Create")
if err != nil {
return "", nil, pkgerrors.Wrap(err, "Error fetching "+resource+" plugin")
}
- internalResourceName, err := symCreateResourceFunc.(func(*krd.GenericKubeResourceData, *kubernetes.Clientset) (string, error))(
+ internalResourceName, err := symCreateResourceFunc.(func(*krd.ResourceData, kubernetes.Interface) (string, error))(
genericKubeData, kubeclient)
if err != nil {
return "", nil, pkgerrors.Wrap(err, "Error in plugin "+resource+" plugin")
@@ -144,7 +144,7 @@ var DestroyVNF = func(data map[string][]string, namespace string, kubeclient *ku
return pkgerrors.New("No plugin for resource " + resourceName + " found")
}
- symDeleteResourceFunc, err := typePlugin.Lookup("DeleteResource")
+ symDeleteResourceFunc, err := typePlugin.Lookup("Delete")
if err != nil {
return pkgerrors.Wrap(err, "Error fetching "+resourceName+" plugin")
}
@@ -153,7 +153,7 @@ var DestroyVNF = func(data map[string][]string, namespace string, kubeclient *ku
log.Println("Deleting resource: " + resourceName)
- err = symDeleteResourceFunc.(func(string, string, *kubernetes.Clientset) error)(
+ err = symDeleteResourceFunc.(func(string, string, kubernetes.Interface) error)(
resourceName, namespace, kubeclient)
if err != nil {
return pkgerrors.Wrap(err, "Error destroying "+resourceName)