Skip to content

Commit a6419b6

Browse files
authored
Merge pull request #962 from DW2022511/danna/944
Add flags to specify zone/machine-type/OS image
2 parents 8f36015 + ff84622 commit a6419b6

File tree

3 files changed

+20
-23
lines changed

3 files changed

+20
-23
lines changed

test/e2e/tests/setup_e2e_test.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"flag"
2020
"fmt"
2121
"math/rand"
22+
"strings"
2223
"testing"
2324
"time"
2425

@@ -35,6 +36,9 @@ import (
3536
var (
3637
project = flag.String("project", "", "Project to run tests in")
3738
serviceAccount = flag.String("service-account", "", "Service account to bring up instance with")
39+
zones = flag.String("zones", "us-central1-c,us-central1-b", "Zones to run tests in. If there are multiple zones, separate each by comma")
40+
machineType = flag.String("machine-type", "n1-standard-1", "Type of machine to provision instance on")
41+
imageURL = flag.String("image-url", "projects/debian-cloud/global/images/family/debian-11", "OS image url to get image from")
3842
runInProw = flag.Bool("run-in-prow", false, "If true, use a Boskos loaned project and special CI service accounts and ssh keys")
3943
deleteInstances = flag.Bool("delete-instances", false, "Delete the instances after tests run")
4044

@@ -60,7 +64,7 @@ var _ = BeforeSuite(func() {
6064
tcc := make(chan *remote.TestContext)
6165
defer close(tcc)
6266

63-
zones := []string{"us-central1-c", "us-central1-b"}
67+
zones := strings.Split(*zones, ",")
6468

6569
rand.Seed(time.Now().UnixNano())
6670

@@ -89,7 +93,7 @@ var _ = BeforeSuite(func() {
8993
nodeID := fmt.Sprintf("gce-pd-csi-e2e-%s", curZone)
9094
klog.Infof("Setting up node %s\n", nodeID)
9195

92-
i, err := remote.SetupInstance(*project, curZone, nodeID, *serviceAccount, computeService)
96+
i, err := remote.SetupInstance(*project, curZone, nodeID, *machineType, *serviceAccount, *imageURL, computeService)
9397
if err != nil {
9498
klog.Fatalf("Failed to setup instance %v: %v", nodeID, err)
9599
}

test/remote/instance.go

+11-18
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ import (
3838
)
3939

4040
const (
41-
defaultMachine = "n1-standard-1"
4241
defaultFirewallRule = "default-allow-ssh"
4342

4443
// timestampFormat is the timestamp format used in the e2e directory name.
4544
timestampFormat = "20060102T150405"
4645
)
4746

4847
type InstanceInfo struct {
49-
project string
50-
zone string
51-
name string
48+
project string
49+
zone string
50+
name string
51+
machineType string
5252

5353
// External IP is filled in after instance creation
5454
externalIP string
@@ -68,18 +68,19 @@ func (i *InstanceInfo) GetNodeID() string {
6868
return common.CreateNodeID(i.project, i.zone, i.name)
6969
}
7070

71-
func CreateInstanceInfo(project, instanceZone, name string, cs *compute.Service) (*InstanceInfo, error) {
71+
func CreateInstanceInfo(project, instanceZone, name, machineType string, cs *compute.Service) (*InstanceInfo, error) {
7272
return &InstanceInfo{
73-
project: project,
74-
zone: instanceZone,
75-
name: name,
73+
project: project,
74+
zone: instanceZone,
75+
name: name,
76+
machineType: machineType,
7677

7778
computeService: cs,
7879
}, nil
7980
}
8081

8182
// Provision a gce instance using image
82-
func (i *InstanceInfo) CreateOrGetInstance(serviceAccount string) error {
83+
func (i *InstanceInfo) CreateOrGetInstance(imageURL, serviceAccount string) error {
8384
var err error
8485
var instance *compute.Instance
8586
klog.V(4).Infof("Creating instance: %v", i.name)
@@ -91,10 +92,9 @@ func (i *InstanceInfo) CreateOrGetInstance(serviceAccount string) error {
9192
return fmt.Errorf("Failed to create firewall rule: %v", err)
9293
}
9394

94-
imageURL := "projects/debian-cloud/global/images/family/debian-11"
9595
inst := &compute.Instance{
9696
Name: i.name,
97-
MachineType: machineType(i.zone, ""),
97+
MachineType: fmt.Sprintf("zones/%s/machineTypes/%s", i.zone, i.machineType),
9898
NetworkInterfaces: []*compute.NetworkInterface{
9999
{
100100
AccessConfigs: []*compute.AccessConfig{
@@ -215,13 +215,6 @@ func getTimestamp() string {
215215
return fmt.Sprintf(time.Now().Format(timestampFormat))
216216
}
217217

218-
func machineType(zone, machine string) string {
219-
if machine == "" {
220-
machine = defaultMachine
221-
}
222-
return fmt.Sprintf("zones/%s/machineTypes/%s", zone, machine)
223-
}
224-
225218
// Create default SSH filewall rule if it does not exist
226219
func (i *InstanceInfo) createDefaultFirewallRule() error {
227220
var err error

test/remote/setup-teardown.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ type processes struct {
5454
}
5555

5656
// SetupInstance sets up the specified GCE Instance for E2E testing and returns a handle to the instance object for future use.
57-
func SetupInstance(instanceProject, instanceZone, instanceName, instanceServiceAccount string, cs *compute.Service) (*InstanceInfo, error) {
57+
func SetupInstance(instanceProject, instanceZone, instanceName, instanceMachineType, instanceServiceAccount, instanceImageURL string, cs *compute.Service) (*InstanceInfo, error) {
5858
// Create the instance in the requisite zone
59-
instance, err := CreateInstanceInfo(instanceProject, instanceZone, instanceName, cs)
59+
instance, err := CreateInstanceInfo(instanceProject, instanceZone, instanceName, instanceMachineType, cs)
6060
if err != nil {
6161
return nil, err
6262
}
6363

64-
err = instance.CreateOrGetInstance(instanceServiceAccount)
64+
err = instance.CreateOrGetInstance(instanceImageURL, instanceServiceAccount)
6565
if err != nil {
6666
return nil, err
6767
}

0 commit comments

Comments
 (0)