func()

in testworkflow.go [147:195]


func (t *TestWorkflow) addNewVMStep(disks []*compute.Disk, instanceParams *daisy.Instance) (*daisy.Step, *daisy.Instance, error) {
	stepSuffix := fmt.Sprintf("%d", t.counter)
	if len(disks) == 0 || disks[0].Name == "" {
		return nil, nil, fmt.Errorf("failed to create VM from empty boot disk")
	}
	// The boot disk is the first disk, and the VM name comes from that
	name := disks[0].Name
	if strings.Contains(name, "-") {
		return nil, nil, fmt.Errorf("dashes are disallowed in testworkflow vm names: %s", name)
	}

	isWindows := utils.HasFeature(t.Image, "WINDOWS")
	var suffix string
	if isWindows {
		suffix = ".exe"
	}

	instance := instanceParams
	if instance == nil {
		instance = &daisy.Instance{}
	}

	instance.StartupScript = fmt.Sprintf("wrapper%s", suffix)
	instance.Name = name
	instance.Scopes = append(instance.Scopes, "https://www.googleapis.com/auth/devstorage.read_write")

	for _, disk := range disks {
		currentDisk := &compute.AttachedDisk{Source: disk.Name, AutoDelete: true}
		instance.Disks = append(instance.Disks, currentDisk)
	}

	if instance.Metadata == nil {
		instance.Metadata = make(map[string]string)
	}

	t.setInstanceTestMetadata(instance, suffix)
	t.skipWindowsStagingKMS(isWindows, instance)

	createInstances := &daisy.CreateInstances{}
	createInstances.Instances = append(createInstances.Instances, instance)

	createVMsStepName := fmt.Sprintf("create-vms-%s", stepSuffix)
	createVMsStep, err := t.wf.NewStep(createVMsStepName)
	if err != nil {
		return nil, nil, err
	}
	createVMsStep.CreateInstances = createInstances
	return createVMsStep, instance, nil
}