Exemple #1
0
// SupportedProviders returns the table of supported data source providers.
func SupportedProviders() map[string]Provider {
	providers := map[string]Provider{
		"GCE":       &gce.MetadataService{gce.MetadataURL},
		"EC2":       &ec2.MetadataService{ec2.MetadataURL},
		"OpenStack": &openstack.MetadataService{openstack.MetadataURL},
	}

	// OpenStack Config-Drive overrides OpenStack meta-data service as the data provider.
	configdrivePath, err := configdrive.FindMountTarget(sys.DefaultExecutor)
	if err == nil {
		// TODO(tmrts): Decide whether config-drive should merge or
		//				override OpenStack meta-data service
		providers["OpenStack"] = &configdrive.Mount{configdrivePath}
	}

	return providers
}
func TestLocatesConfigDriveMountTarget(t *testing.T) {
	Convey("Given a mounted device with the label 'config-2'", t, func() {
		executor := sys.NewFuncExecutor(func(cmd string, args ...string) (string, error) {
			cmd = strings.Join(append([]string{cmd}, args...), " ")

			switch cmd {
			case "blkid -t LABEL='config-2' -odevice":
				return "/dev/cfg", nil
			case "findmnt --raw --noheadings --output TARGET /dev/cfg":
				return "/mnt/config", nil
			}

			return "", fmt.Errorf("unrecognized command")
		})

		Convey("It should locate where the device is mounted", func() {
			target, err := configdrive.FindMountTarget(executor)
			So(err, ShouldBeNil)

			So(target, ShouldEqual, "/mnt/config")
		})
	})
}