Example #1
0
func TestCreateOpts(t *testing.T) {
	opts := CreateOpts{
		Name:       "createdserver",
		ImageRef:   "image-id",
		FlavorRef:  "flavor-id",
		KeyPair:    "mykey",
		DiskConfig: diskconfig.Manual,
	}

	expected := `
	{
		"server": {
			"name": "createdserver",
			"imageRef": "image-id",
			"flavorRef": "flavor-id",
			"flavorName": "",
			"imageName": "",
			"key_name": "mykey",
			"OS-DCF:diskConfig": "MANUAL"
		}
	}
	`
	actual, err := opts.ToServerCreateMap()
	th.AssertNoErr(t, err)
	th.CheckJSONEquals(t, expected, actual)
}
func TestCreateOpts(t *testing.T) {
	base := servers.CreateOpts{
		Name:      "createdserver",
		ImageRef:  "asdfasdfasdf",
		FlavorRef: "performance1-1",
	}

	ext := CreateOptsExt{
		CreateOptsBuilder: base,
		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)
}
func TestRebuildOpts(t *testing.T) {
	base := servers.RebuildOpts{
		Name:      "rebuiltserver",
		AdminPass: "******",
		ImageID:   "asdfasdfasdf",
	}

	ext := RebuildOptsExt{
		RebuildOptsBuilder: base,
		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)
}
Example #4
0
func TestCreateOpts(t *testing.T) {
	base := servers.CreateOpts{
		Name:      "createdserver",
		ImageRef:  "asdfasdfasdf",
		FlavorRef: "performance1-1",
	}

	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{}{">=", "$free_ram_mb", "1024"},
		TargetCell:      "foobar",
		BuildNearHostIP: "192.168.1.1/24",
	}

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

	expected := `
		{
			"server": {
				"name": "createdserver",
				"imageRef": "asdfasdfasdf",
				"flavorRef": "performance1-1",
				"flavorName": "",
				"imageName": ""
			},
			"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": [
					">=", "$free_ram_mb", "1024"
				],
				"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)
}
Example #5
0
func TestCreateOpts(t *testing.T) {
	base := servers.CreateOpts{
		Name:      "createdserver",
		ImageRef:  "asdfasdfasdf",
		FlavorRef: "performance1-1",
	}

	ext := CreateOptsExt{
		CreateOptsBuilder: base,
		BlockDevice: []BlockDevice{
			BlockDevice{
				UUID:            "123456",
				SourceType:      Image,
				DestinationType: "volume",
				VolumeSize:      10,
			},
		},
	}

	expected := `
    {
      "server": {
        "name": "createdserver",
        "imageRef": "asdfasdfasdf",
        "flavorRef": "performance1-1",
	"flavorName": "",
	"imageName": "",
        "block_device_mapping_v2":[
          {
            "uuid":"123456",
            "source_type":"image",
            "destination_type":"volume",
            "boot_index": "0",
            "delete_on_termination": "false",
            "volume_size": "10"
          }
        ]
      }
    }
  `
	actual, err := ext.ToServerCreateMap()
	th.AssertNoErr(t, err)
	th.CheckJSONEquals(t, expected, actual)
}
Example #6
0
func TestRebuildOpts(t *testing.T) {
	opts := RebuildOpts{
		Name:       "rebuiltserver",
		AdminPass:  "******",
		ImageID:    "asdfasdfasdf",
		DiskConfig: diskconfig.Auto,
	}

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

	expected := `
	{
		"rebuild": {
			"name": "rebuiltserver",
			"imageRef": "asdfasdfasdf",
			"adminPass": "******",
			"OS-DCF:diskConfig": "AUTO"
		}
	}
	`
	th.CheckJSONEquals(t, expected, actual)
}
func TestResizeOpts(t *testing.T) {
	base := servers.ResizeOpts{
		FlavorRef: "performance1-8",
	}

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

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

	expected := `
		{
			"resize": {
				"flavorRef": "performance1-8",
				"OS-DCF:diskConfig": "AUTO"
			}
		}
	`
	th.CheckJSONEquals(t, expected, actual)
}
Example #8
0
func TestCreateMultiEphemeralOpts(t *testing.T) {
	base := servers.CreateOpts{
		Name:      "createdserver",
		ImageRef:  "asdfasdfasdf",
		FlavorRef: "performance1-1",
	}

	ext := CreateOptsExt{
		CreateOptsBuilder: base,
		BlockDevice: []BlockDevice{
			BlockDevice{
				BootIndex:           0,
				DeleteOnTermination: true,
				DestinationType:     "local",
				SourceType:          Image,
				UUID:                "123456",
			},
			BlockDevice{
				BootIndex:           -1,
				DeleteOnTermination: true,
				DestinationType:     "local",
				GuestFormat:         "ext4",
				SourceType:          Blank,
				VolumeSize:          1,
			},
			BlockDevice{
				BootIndex:           -1,
				DeleteOnTermination: true,
				DestinationType:     "local",
				GuestFormat:         "ext4",
				SourceType:          Blank,
				VolumeSize:          1,
			},
		},
	}

	expected := `
    {
      "server": {
        "name": "createdserver",
        "imageRef": "asdfasdfasdf",
        "flavorRef": "performance1-1",
        "flavorName": "",
        "imageName": "",
        "block_device_mapping_v2":[
          {
            "boot_index": "0",
            "delete_on_termination": "true",
            "destination_type":"local",
            "source_type":"image",
            "uuid":"123456"
          },
          {
            "boot_index": "-1",
            "delete_on_termination": "true",
            "destination_type":"local",
            "guest_format":"ext4",
            "source_type":"blank",
            "volume_size": "1"
          },
          {
            "boot_index": "-1",
            "delete_on_termination": "true",
            "destination_type":"local",
            "guest_format":"ext4",
            "source_type":"blank",
            "volume_size": "1"
          }
        ]
      }
    }
  `
	actual, err := ext.ToServerCreateMap()
	th.AssertNoErr(t, err)
	th.CheckJSONEquals(t, expected, actual)
}