Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to test Azure File CSI Driver #14456

Merged
merged 8 commits into from
Sep 27, 2019
Merged
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
65 changes: 56 additions & 9 deletions kubetest/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"errors"
"flag"
"fmt"
"go/build"
"io/ioutil"
"log"
"math/rand"
Expand Down Expand Up @@ -95,6 +96,8 @@ var (
aksIdentitySystem = flag.String("aksengine-identity-system", "azure_ad", "identity system (default:`azure_ad`, `adfs`)")
aksCustomCloudURL = flag.String("aksengine-custom-cloud-url", "", "management portal URL to use in custom Azure cloud (i.e Azure Stack etc)")
testCcm = flag.Bool("test-ccm", false, "Set to True if you want kubetest to run e2e tests for ccm")
// Azure File CSI Driver flag
testAzureFileCSIDriver = flag.Bool("test-azure-file-csi-driver", false, "Set to True if you want kubetest to run e2e tests for Azure File CSI driver")
)

const (
Expand Down Expand Up @@ -907,7 +910,6 @@ func (c Cluster) GetClusterCreated(clusterName string) (time.Time, error) {
}

func (c Cluster) TestSetup() error {

// set env vars required by the ccm e2e tests
if *testCcm == true {
if err := os.Setenv("K8S_AZURE_TENANTID", c.credentials.TenantID); err != nil {
Expand All @@ -925,10 +927,18 @@ func (c Cluster) TestSetup() error {
if err := os.Setenv("K8S_AZURE_LOCATION", c.location); err != nil {
return err
}
} else if *testAzureFileCSIDriver == true {
// Set env vars required by Azure File CSI driver tests.
// tenantId, subscriptionId, aadClientId, and aadClientSecret will be obtained from AZURE_CREDENTIAL
if err := os.Setenv("resourceGroup", c.resourceGroup); err != nil {
chewong marked this conversation as resolved.
Show resolved Hide resolved
return err
}
if err := os.Setenv("location", c.location); err != nil {
return err
}
}

// Download repo-list that defines repositories for Windows test images.

downloadUrl, ok := os.LookupEnv("KUBE_TEST_REPO_LIST_DOWNLOAD_LOCATION")
if !ok {
// Env value for downloadUrl is not set, nothing to do
Expand Down Expand Up @@ -964,19 +974,21 @@ func (_ Cluster) KubectlCommand() (*exec.Cmd, error) { return nil, nil }

// BuildTester returns a standard ginkgo-script tester or a custom one if testCcm is enabled
func (c *Cluster) BuildTester(o *e2e.BuildTesterOptions) (e2e.Tester, error) {
if *testCcm != true {
return &GinkgoScriptTester{}, nil
if *testCcm == true {
return &GinkgoCCMTester{}, nil
} else if *testAzureFileCSIDriver == true {
return &GinkgoAzureFilCSIDriverTester{}, nil
}
log.Printf("running go tests directly")
return &GinkgoCustomTester{}, nil

return &GinkgoScriptTester{}, nil
}

// GinkgoCustomTester implements Tester by calling a custom ginkgo script
type GinkgoCustomTester struct {
// GinkgoCCMTester implements Tester by running E2E tests for Azure CCM
type GinkgoCCMTester struct {
}

// Run executes custom ginkgo script
func (t *GinkgoCustomTester) Run(control *process.Control, testArgs []string) error {
func (t *GinkgoCCMTester) Run(control *process.Control, testArgs []string) error {
artifactsDir, ok := os.LookupEnv("ARTIFACTS")
if !ok {
artifactsDir = filepath.Join(os.Getenv("WORKSPACE"), "_artifacts")
Expand All @@ -992,3 +1004,38 @@ func (t *GinkgoCustomTester) Run(control *process.Control, testArgs []string) er
testErr := control.FinishRunning(cmd)
return testErr
}

// GinkgoAzureFilCSIDriverTester implements Tester by running E2E tests for Azure File CSI Driver
type GinkgoAzureFilCSIDriverTester struct {
}

// Run executes custom ginkgo script
func (t *GinkgoAzureFilCSIDriverTester) Run(control *process.Control, testArgs []string) error {
cmd := exec.Command("make", "e2e-test")
projectPath := githubProjectPath("kubernetes-sigs", "azurefile-csi-driver")
cmd.Dir = projectPath
testErr := control.FinishRunning(cmd)
return testErr
}

// githubProjectPath returns $GOPATH/src/github.com/<username>/<projectName>
func githubProjectPath(username, projectName string) string {
chewong marked this conversation as resolved.
Show resolved Hide resolved
gopathList := filepath.SplitList(build.Default.GOPATH)
found := false
var githubDir string
for _, gopath := range gopathList {
githubDir = filepath.Join(gopath, "src", "github.com", username)
if _, err := os.Stat(githubDir); !os.IsNotExist(err) {
found = true
break
}
}
if !found {
// Default to the first item in GOPATH list.
githubDir = filepath.Join(gopathList[0], "src", "github.com", username)
log.Printf(
"Warning: Couldn't find directory src/github.com/%s under any of GOPATH %s, defaulting to %s",
username, build.Default.GOPATH, githubDir)
}
return filepath.Join(githubDir, projectName)
}