コード例 #1
0
func TestCreateOpts(t *testing.T) {
	base := servers.CreateOpts{
		Name:      "createdserver",
		ImageRef:  "asdfasdfasdf",
		FlavorRef: "performance1-1",
	}

	ext := diskconfig.CreateOptsExt{
		CreateOptsBuilder: base,
		DiskConfig:        diskconfig.Manual,
	}

	expected := `
		{
			"server": {
				"name": "createdserver",
				"imageRef": "asdfasdfasdf",
				"flavorRef": "performance1-1",
				"OS-DCF:diskConfig": "MANUAL"
			}
		}
	`
	actual, err := ext.ToServerCreateMap()
	th.AssertNoErr(t, err)
	th.CheckJSONEquals(t, expected, actual)
}
コード例 #2
0
func TestRebuildOpts(t *testing.T) {
	base := servers.RebuildOpts{
		Name:      "rebuiltserver",
		AdminPass: "******",
		ImageID:   "asdfasdfasdf",
	}

	ext := diskconfig.RebuildOptsExt{
		RebuildOptsBuilder: base,
		DiskConfig:         diskconfig.Auto,
	}

	actual, err := ext.ToServerRebuildMap()
	th.AssertNoErr(t, err)

	expected := `
		{
			"rebuild": {
				"name": "rebuiltserver",
				"imageRef": "asdfasdfasdf",
				"adminPass": "******",
				"OS-DCF:diskConfig": "AUTO"
			}
		}
	`
	th.CheckJSONEquals(t, expected, actual)
}
コード例 #3
0
func TestCreateOptsWithComplexQuery(t *testing.T) {
	base := servers.CreateOpts{
		Name:      "createdserver",
		ImageRef:  "asdfasdfasdf",
		FlavorRef: "performance1-1",
	}

	schedulerHints := schedulerhints.SchedulerHints{
		Group: "101aed42-22d9-4a3e-9ba1-21103b0d1aba",
		DifferentHost: []string{
			"a0cf03a5-d921-4877-bb5c-86d26cf818e1",
			"8c19174f-4220-44f0-824a-cd1eeef10287",
		},
		SameHost: []string{
			"a0cf03a5-d921-4877-bb5c-86d26cf818e1",
			"8c19174f-4220-44f0-824a-cd1eeef10287",
		},
		Query:           []interface{}{"and", []string{">=", "$free_ram_mb", "1024"}, []string{">=", "$free_disk_mb", "204800"}},
		TargetCell:      "foobar",
		BuildNearHostIP: "192.168.1.1/24",
	}

	ext := schedulerhints.CreateOptsExt{
		CreateOptsBuilder: base,
		SchedulerHints:    schedulerHints,
	}

	expected := `
		{
			"server": {
				"name": "createdserver",
				"imageRef": "asdfasdfasdf",
				"flavorRef": "performance1-1"
			},
			"os:scheduler_hints": {
				"group": "101aed42-22d9-4a3e-9ba1-21103b0d1aba",
				"different_host": [
					"a0cf03a5-d921-4877-bb5c-86d26cf818e1",
					"8c19174f-4220-44f0-824a-cd1eeef10287"
				],
				"same_host": [
					"a0cf03a5-d921-4877-bb5c-86d26cf818e1",
					"8c19174f-4220-44f0-824a-cd1eeef10287"
				],
				"query": [
					"and",
					[">=", "$free_ram_mb", "1024"],
					[">=", "$free_disk_mb", "204800"]
				],
				"target_cell": "foobar",
				"build_near_host_ip": "192.168.1.1",
				"cidr": "/24"
			}
		}
	`
	actual, err := ext.ToServerCreateMap()
	th.AssertNoErr(t, err)
	th.CheckJSONEquals(t, expected, actual)
}
コード例 #4
0
func TestAttachExistingVolume(t *testing.T) {
	base := servers.CreateOpts{
		Name:      "createdserver",
		ImageRef:  "asdfasdfasdf",
		FlavorRef: "performance1-1",
	}

	ext := bootfromvolume.CreateOptsExt{
		CreateOptsBuilder: base,
		BlockDevice: []bootfromvolume.BlockDevice{
			{
				BootIndex:           0,
				DeleteOnTermination: true,
				DestinationType:     bootfromvolume.DestinationLocal,
				SourceType:          bootfromvolume.SourceImage,
				UUID:                "asdfasdfasdf",
			},
			{
				BootIndex:           1,
				DeleteOnTermination: true,
				DestinationType:     bootfromvolume.DestinationVolume,
				SourceType:          bootfromvolume.SourceVolume,
				UUID:                "123456",
				VolumeSize:          1,
			},
		},
	}

	expected := `
    {
      "server": {
        "name": "createdserver",
        "imageRef": "asdfasdfasdf",
        "flavorRef": "performance1-1",
        "block_device_mapping_v2":[
          {
            "boot_index": 0,
            "delete_on_termination": true,
            "destination_type":"local",
            "source_type":"image",
            "uuid":"asdfasdfasdf"
          },
          {
            "boot_index": 1,
            "delete_on_termination": true,
            "destination_type":"volume",
            "source_type":"volume",
            "uuid":"123456",
            "volume_size": 1
          }
        ]
      }
    }
  `
	actual, err := ext.ToServerCreateMap()
	th.AssertNoErr(t, err)
	th.CheckJSONEquals(t, expected, actual)
}
コード例 #5
0
func TestResizeOpts(t *testing.T) {
	base := servers.ResizeOpts{
		FlavorRef: "performance1-8",
	}

	ext := diskconfig.ResizeOptsExt{
		ResizeOptsBuilder: base,
		DiskConfig:        diskconfig.Auto,
	}

	actual, err := ext.ToServerResizeMap()
	th.AssertNoErr(t, err)

	expected := `
		{
			"resize": {
				"flavorRef": "performance1-8",
				"OS-DCF:diskConfig": "AUTO"
			}
		}
	`
	th.CheckJSONEquals(t, expected, actual)
}