github.com/interconnectedcloud/qdr-operator@v0.0.0-20210826174505-576d2b33dac7/test/e2e/validation/connector.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/interconnectedcloud/qdr-operator/test/e2e/framework/qdrmanagement/entities/common"
     9  	"github.com/onsi/gomega"
    10  	"k8s.io/api/core/v1"
    11  )
    12  
    13  // ConnectorMapByPort represents a map that contains ports as keys and
    14  // keys/values that represents a Connector entity (for comparison).
    15  type ConnectorMapByPort map[string]map[string]interface{}
    16  
    17  // ValidateDefaultConnectors asserts that the inter-router connectors are defined
    18  // in [deployment plan size - 1] routers (as the initial pod only provides listeners).
    19  // It returns number of connectors found.
    20  func ValidateDefaultConnectors(interconnect *v1alpha1.Interconnect, f *framework.Framework, pods []v1.Pod) {
    21  
    22  	totalConnectors := 0
    23  	expConnectors := 0
    24  
    25  	// Expected number of connectors defined by sum of all numbers from 1 to size - 1
    26  	for i := int(interconnect.Spec.DeploymentPlan.Size) - 1; i > 0; i-- {
    27  		expConnectors += i
    28  	}
    29  
    30  	// Iterate through pods
    31  	for _, pod := range pods {
    32  		// Retrieve connectors
    33  		connectors, err := qdrmanagement.QdmanageQuery(f, pod.Name, entities.Connector{}, nil)
    34  		gomega.Expect(err).To(gomega.BeNil())
    35  
    36  		// Common connector properties
    37  		expectedPort := "55672"
    38  		expectedSslProfile := ""
    39  		if f.CertManagerPresent {
    40  			expectedPort = "55671"
    41  			expectedSslProfile = "inter-router"
    42  		}
    43  
    44  		props := map[string]interface{}{
    45  			"Role":       common.RoleInterRouter,
    46  			"Port":       expectedPort,
    47  			"SslProfile": expectedSslProfile,
    48  		}
    49  
    50  		// Validate connectors
    51  		if len(connectors) > 0 {
    52  			for _, entity := range connectors {
    53  				connector := entity.(entities.Connector)
    54  				gomega.Expect(connector.Host).NotTo(gomega.BeEmpty())
    55  				ValidateEntityValues(connector, props)
    56  			}
    57  		}
    58  
    59  		totalConnectors += len(connectors)
    60  	}
    61  
    62  	// Validate number of connectors across pods
    63  	gomega.Expect(expConnectors).To(gomega.Equal(totalConnectors))
    64  
    65  }
    66  
    67  // ValidateSpecConnector asserts that the connector models provided through the cMap
    68  // are present across all pods from the given ic instance.
    69  func ValidateSpecConnector(ic *v1alpha1.Interconnect, f *framework.Framework, cMap ConnectorMapByPort) {
    70  	// Retrieve fresh version of given Interconnect instance
    71  	icNew, err := f.GetInterconnect(ic.Name)
    72  	gomega.Expect(err).NotTo(gomega.HaveOccurred())
    73  
    74  	// Retrieve pod list
    75  	pods, err := f.GetInterconnectPods(icNew)
    76  	gomega.Expect(err).NotTo(gomega.HaveOccurred())
    77  
    78  	// Iterate through all pods and assert that connectors are available across all instances
    79  	for _, pod := range pods {
    80  		// Same amount of connectors from cMap are expected to be found
    81  		cFound := 0
    82  
    83  		// Retrieve connectors
    84  		connectors, err := qdrmanagement.QdmanageQuery(f, pod.Name, entities.Connector{}, nil)
    85  		gomega.Expect(err).NotTo(gomega.HaveOccurred())
    86  
    87  		// Loop through returned connectors
    88  		for _, e := range connectors {
    89  			connector := e.(entities.Connector)
    90  			cModel, found := cMap[connector.Port]
    91  			if !found {
    92  				continue
    93  			}
    94  			// Validating that connector exists on cMap
    95  			ValidateEntityValues(connector, cModel)
    96  			cFound++
    97  		}
    98  
    99  		// Assert that all connectors from cMap have been found
   100  		gomega.Expect(cFound).To(gomega.Equal(len(cMap)))
   101  	}
   102  }