github.com/interconnectedcloud/qdr-operator@v0.0.0-20210826174505-576d2b33dac7/test/e2e/validation/linkroute.go (about)

     1  package validation
     2  
     3  import (
     4  	"github.com/interconnectedcloud/qdr-operator/pkg/apis/interconnectedcloud/v1alpha1"
     5  	"github.com/interconnectedcloud/qdr-operator/test/e2e/framework"
     6  	"github.com/interconnectedcloud/qdr-operator/test/e2e/framework/qdrmanagement"
     7  	"github.com/interconnectedcloud/qdr-operator/test/e2e/framework/qdrmanagement/entities"
     8  	"github.com/onsi/gomega"
     9  	v1 "k8s.io/api/core/v1"
    10  )
    11  
    12  // LinkRouteMapByPrefixPattern represents a map that contains a map
    13  // of string keys that can be either a prefix or a pattern.
    14  type LinkRouteMapByPrefixPattern map[string]map[string]interface{}
    15  
    16  // getLinkRouteModel returns the map with the LinkRoute entity model
    17  // if lrMap contains a matching prefix or pattern and a bool value
    18  // that is true if key was found or false otherwise.
    19  func getLinkRouteModel(lrMap LinkRouteMapByPrefixPattern, linkRoute entities.LinkRoute) (map[string]interface{}, bool) {
    20  	emptyModel := map[string]interface{}{}
    21  	lrModel, found := lrMap[linkRoute.Prefix]
    22  	if !found {
    23  		lrModel, found = lrMap[linkRoute.Pattern]
    24  		if !found {
    25  			return emptyModel, false
    26  		}
    27  	}
    28  	return lrModel, true
    29  }
    30  
    31  // ValidateSpecLinkRoute asserts that the linkRoute models provided through the lrMap
    32  // are present across all pods from the given ic instance.
    33  func ValidateSpecLinkRoute(ic *v1alpha1.Interconnect, f *framework.Framework, lrMap LinkRouteMapByPrefixPattern) {
    34  	// Retrieving latest Interconnect
    35  	icNew, err := f.GetInterconnect(ic.Name)
    36  	gomega.Expect(err).NotTo(gomega.HaveOccurred())
    37  
    38  	// Retrieve pod list
    39  	pods, err := f.GetInterconnectPods(icNew)
    40  	gomega.Expect(err).NotTo(gomega.HaveOccurred())
    41  
    42  	// Iterate through all pods and assert that linkRoutes are available across all instances
    43  	for _, pod := range pods {
    44  		// Wait for pod to be Running
    45  		_, err := f.WaitForPodStatus(pod.Name, v1.PodRunning, framework.Timeout, framework.RetryInterval)
    46  		gomega.Expect(err).To(gomega.BeNil())
    47  
    48  		// Same amount of linkRoutes from lrMap are expected to be found
    49  		lrFound := 0
    50  
    51  		// Retrieve linkRoutes
    52  		linkRoutes, err := qdrmanagement.QdmanageQuery(f, pod.Name, entities.LinkRoute{}, nil)
    53  		gomega.Expect(err).NotTo(gomega.HaveOccurred())
    54  
    55  		// Loop through returned linkRoutes
    56  		for _, e := range linkRoutes {
    57  			linkRoute := e.(entities.LinkRoute)
    58  			lrModel, found := getLinkRouteModel(lrMap, linkRoute)
    59  			if !found {
    60  				continue
    61  			}
    62  			// Validating linkRoute that exists on lrMap
    63  			ValidateEntityValues(linkRoute, lrModel)
    64  			lrFound++
    65  		}
    66  
    67  		// Assert that all linkRoutes from lrMap have been found
    68  		gomega.Expect(lrFound).To(gomega.Equal(len(lrMap)))
    69  	}
    70  }