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

     1  package validation
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/interconnectedcloud/qdr-operator/pkg/apis/interconnectedcloud/v1alpha1"
     6  	"github.com/interconnectedcloud/qdr-operator/test/e2e/framework"
     7  	"github.com/interconnectedcloud/qdr-operator/test/e2e/framework/qdrmanagement"
     8  	"github.com/interconnectedcloud/qdr-operator/test/e2e/framework/qdrmanagement/entities"
     9  	"github.com/onsi/gomega"
    10  	"k8s.io/api/core/v1"
    11  )
    12  
    13  // SslProfileMapByName represents a map indexed by sslProfile Name storing
    14  // another map with the property names and respective values for the SslProfile entity
    15  // that will be validated.
    16  type SslProfileMapByName map[string]map[string]interface{}
    17  
    18  // ValidateDefaultSslProfiles asserts that the default sslProfile entities have
    19  // been defined, based on given Interconnect's role.
    20  func ValidateDefaultSslProfiles(ic *v1alpha1.Interconnect, f *framework.Framework, pods []v1.Pod) {
    21  
    22  	var expectedSslProfiles = 1
    23  	var isInterior = ic.Spec.DeploymentPlan.Role == v1alpha1.RouterRoleInterior
    24  
    25  	// Interior routers have an extra sslProfile for the inter-router listener
    26  	if isInterior {
    27  		expectedSslProfiles++
    28  	}
    29  
    30  	// Iterate through the pods to ensure sslProfiles are defined
    31  	for _, pod := range pods {
    32  		var sslProfilesFound = 0
    33  
    34  		// Retrieving sslProfile entities from router
    35  		sslProfiles, err := qdrmanagement.QdmanageQuery(f, pod.Name, entities.SslProfile{}, nil)
    36  		gomega.Expect(err).NotTo(gomega.HaveOccurred())
    37  
    38  		// Verify expected sslProfiles are defined
    39  		for _, entity := range sslProfiles {
    40  			sslProfile := entity.(entities.SslProfile)
    41  			switch sslProfile.Name {
    42  			case "inter-router":
    43  				ValidateEntityValues(sslProfile, map[string]interface{}{
    44  					"CaCertFile": fmt.Sprintf("/etc/qpid-dispatch-certs/%s/%s-%s-credentials/ca.crt", sslProfile.Name, ic.Name, sslProfile.Name),
    45  				})
    46  				fallthrough
    47  			case "default":
    48  				ValidateEntityValues(sslProfile, map[string]interface{}{
    49  					"CertFile":       fmt.Sprintf("/etc/qpid-dispatch-certs/%s/%s-%s-credentials/tls.crt", sslProfile.Name, ic.Name, sslProfile.Name),
    50  					"PrivateKeyFile": fmt.Sprintf("/etc/qpid-dispatch-certs/%s/%s-%s-credentials/tls.key", sslProfile.Name, ic.Name, sslProfile.Name),
    51  				})
    52  				sslProfilesFound++
    53  			}
    54  		}
    55  
    56  		// Assert default sslProfiles have been found
    57  		gomega.Expect(expectedSslProfiles).To(gomega.Equal(sslProfilesFound))
    58  	}
    59  
    60  }
    61  
    62  // ValidateSslProfileModels retrieves the Interconnect instance and iterates through all
    63  // its pods, querying management API for sslProfiles. Next it ensure that all sslProfile
    64  // definitions fro the sslProfMap are defined on each pod.
    65  func ValidateSslProfileModels(ic *v1alpha1.Interconnect, f *framework.Framework, sslProfMap SslProfileMapByName) {
    66  	var podNames []string
    67  
    68  	// Retrieve lastest version of given Interconnect resource
    69  	ic, err := f.GetInterconnect(ic.Name)
    70  	gomega.Expect(err).NotTo(gomega.HaveOccurred())
    71  
    72  	// Validate IC instance
    73  	gomega.Expect(ic).NotTo(gomega.BeNil())
    74  
    75  	pods, err := f.GetInterconnectPods(ic)
    76  	gomega.Expect(err).NotTo(gomega.HaveOccurred())
    77  	gomega.Expect(len(pods)).To(gomega.BeNumerically(">", 0))
    78  
    79  	for _, pod := range pods {
    80  		if pod.GetObjectMeta().GetDeletionTimestamp() == nil {
    81  			podNames = append(podNames, pod.Name)
    82  		}
    83  	}
    84  
    85  	for _, pod := range podNames {
    86  		sslProfFound := 0
    87  
    88  		sslProfiles, err := qdrmanagement.QdmanageQuery(f, pod, entities.SslProfile{}, nil)
    89  		gomega.Expect(err).NotTo(gomega.HaveOccurred())
    90  
    91  		for _, e := range sslProfiles {
    92  			sslProfile := e.(entities.SslProfile)
    93  			model, found := sslProfMap[sslProfile.Name]
    94  			if !found {
    95  				continue
    96  			}
    97  
    98  			ValidateEntityValues(sslProfile, model)
    99  			// Validating the matching sslProfile
   100  			sslProfFound++
   101  		}
   102  
   103  		// Expect all sslProfiles from map have been validated
   104  		gomega.Expect(sslProfFound).To(gomega.Equal(len(sslProfMap)))
   105  	}
   106  }