コード例 #1
0
func (c *cloudProperties) Apply(input bftinput.Input, previousInput bftinput.Input) bftinput.Input {
	for i, subject := range input.CloudConfig.AvailabilityZones {
		prevSubject, found := previousInput.FindAzByName(subject.Name)
		input.CloudConfig.AvailabilityZones[i].CloudProperties = c.FuzzCloudProperties(found, prevSubject.CloudProperties)
	}

	for i, subject := range input.CloudConfig.VmTypes {
		prevSubject, found := previousInput.FindVmTypeByName(subject.Name)
		input.CloudConfig.VmTypes[i].CloudProperties = c.FuzzCloudProperties(found, prevSubject.CloudProperties)
	}

	for i, subject := range input.CloudConfig.PersistentDiskPools {
		prevSubject, found := previousInput.FindDiskPoolByName(subject.Name)
		input.CloudConfig.PersistentDiskPools[i].CloudProperties = c.FuzzCloudProperties(found, prevSubject.CloudProperties)
	}

	for i, subject := range input.CloudConfig.PersistentDiskTypes {
		prevSubject, found := previousInput.FindDiskPoolByName(subject.Name)
		input.CloudConfig.PersistentDiskTypes[i].CloudProperties = c.FuzzCloudProperties(found, prevSubject.CloudProperties)
	}

	for i, subject := range input.CloudConfig.ResourcePools {
		prevSubject, found := previousInput.FindResourcePoolByName(subject.Name)
		input.CloudConfig.ResourcePools[i].CloudProperties = c.FuzzCloudProperties(found, prevSubject.CloudProperties)
	}

	// we can't really detect when a previous input has used cloud properties since we could
	// validly used 0 properties
	input.CloudConfig.Compilation.CloudProperties = c.FuzzCloudProperties(true, previousInput.CloudConfig.Compilation.CloudProperties)

	for i, network := range input.CloudConfig.Networks {
		if network.Subnets != nil {
			for s, subject := range network.Subnets {
				if subject.IpPool != nil {
					// manual
					prevSubject, found := previousInput.FindSubnetByIpRange(subject.IpPool.IpRange)
					input.CloudConfig.Networks[i].Subnets[s].CloudProperties = c.FuzzCloudProperties(found, prevSubject.CloudProperties)
				} else {
					// dynamic
					input.CloudConfig.Networks[i].Subnets[s].CloudProperties = c.FuzzCloudProperties(false, map[string]string{})
				}
			}
		} else {
			// vip
			input.CloudConfig.Networks[i].CloudProperties = c.FuzzCloudProperties(false, map[string]string{})
		}
	}

	return input
}
func (n *nothingChangedComparator) nothingChanged(job bftinput.Job, currentInput bftinput.Input, previousInputs []bftinput.Input) bool {
	mostRecentInput := previousInputs[len(previousInputs)-1]

	prevJob, found := mostRecentInput.FindJobByName(job.Name)
	if !found {
		return false
	}

	if len(previousInputs) > 1 {
		inputBeforePrevious := previousInputs[len(previousInputs)-2]
		jobBeforePrevious, found := inputBeforePrevious.FindJobByName(job.Name)
		if found && jobBeforePrevious.HasPersistentDisk() && !prevJob.HasPersistentDisk() {
			return false
		}

		for _, migratedFromConfig := range prevJob.MigratedFrom {
			jobBeforePrevious, found := inputBeforePrevious.FindJobByName(migratedFromConfig.Name)
			if found && jobBeforePrevious.HasPersistentDisk() && !prevJob.HasPersistentDisk() {
				return false
			}
		}
	}

	if !prevJob.IsEqual(job) {
		return false
	}

	for _, azName := range job.AvailabilityZones {
		currentAz, _ := currentInput.FindAzByName(azName)
		prevAz, _ := mostRecentInput.FindAzByName(azName)
		if !currentAz.IsEqual(prevAz) {
			return false
		}
	}

	if job.PersistentDiskPool != "" {
		currentPersistentDiskPool, _ := currentInput.FindDiskPoolByName(job.PersistentDiskPool)
		prevPersistentDiskPool, _ := mostRecentInput.FindDiskPoolByName(job.PersistentDiskPool)
		if !currentPersistentDiskPool.IsEqual(prevPersistentDiskPool) {
			return false
		}
	}

	if job.PersistentDiskType != "" {
		currentPersistentDiskType, _ := currentInput.FindDiskTypeByName(job.PersistentDiskType)
		prevPersistentDiskType, _ := mostRecentInput.FindDiskTypeByName(job.PersistentDiskType)
		if !currentPersistentDiskType.IsEqual(prevPersistentDiskType) {
			return false
		}
	}

	if job.ResourcePool != "" {
		currentResourcePool, _ := currentInput.FindResourcePoolByName(job.ResourcePool)
		prevResourcePool, _ := mostRecentInput.FindResourcePoolByName(job.ResourcePool)
		if !currentResourcePool.IsEqual(prevResourcePool) {
			return false
		}
	}

	if job.VmType != "" {
		currentVmType, _ := currentInput.FindVmTypeByName(job.VmType)
		prevVmType, _ := mostRecentInput.FindVmTypeByName(job.VmType)
		if !currentVmType.IsEqual(prevVmType) {
			return false
		}
	}

	if job.Stemcell != "" {
		currentStemcell, _ := currentInput.FindStemcellByName(job.Stemcell)
		prevStemcell, _ := mostRecentInput.FindStemcellByName(job.Stemcell)
		if !currentStemcell.IsEqual(prevStemcell) {
			return false
		}
	}

	for _, jobNetwork := range job.Networks {
		currentNetwork, _ := currentInput.FindNetworkByName(jobNetwork.Name)
		prevNetwork, _ := mostRecentInput.FindNetworkByName(jobNetwork.Name)
		if !currentNetwork.IsEqual(prevNetwork) {
			return false
		}
	}

	return true
}