예제 #1
0
func TestInstanceList(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	fixture.SetupHandler(t, "/instances", "GET", "", listInstancesResp, 200)

	opts := &ListOpts{
		IncludeHA:       false,
		IncludeReplicas: false,
	}

	pages := 0
	err := List(fake.ServiceClient(), opts).EachPage(func(page pagination.Page) (bool, error) {
		pages++

		actual, err := ExtractInstances(page)
		if err != nil {
			return false, err
		}

		th.CheckDeepEquals(t, []Instance{*expectedInstance}, actual)
		return true, nil
	})

	th.AssertNoErr(t, err)
	th.AssertEquals(t, 1, pages)
}
예제 #2
0
func TestListBackups(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, resURL+"/backups", "GET", "", listBackupsResp, 200)

	pages := 0

	err := ListBackups(fake.ServiceClient(), instanceID).EachPage(func(page pagination.Page) (bool, error) {
		pages++
		actual, err := backups.ExtractBackups(page)
		th.AssertNoErr(t, err)

		expected := []backups.Backup{
			backups.Backup{
				Created:     timeVal,
				Description: "Backup from Restored Instance",
				ID:          "87972694-4be2-40f5-83f8-501656e0032a",
				InstanceID:  "29af2cd9-0674-48ab-b87a-b160f00208e6",
				LocationRef: "http://localhost/path/to/backup",
				Name:        "restored_backup",
				ParentID:    "",
				Size:        0.141026,
				Status:      "COMPLETED",
				Updated:     timeVal,
				Datastore:   datastores.DatastorePartial{Version: "5.1", Type: "MySQL", VersionID: "20000000-0000-0000-0000-000000000002"},
			},
		}

		th.AssertDeepEquals(t, expected, actual)
		return true, nil
	})

	th.AssertNoErr(t, err)
	th.AssertEquals(t, 1, pages)
}
예제 #3
0
func TestGet(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, resURL, "GET", "", getResp, 200)

	instance, err := Get(fake.ServiceClient(), backupID).Extract()
	th.AssertNoErr(t, err)

	expected := &Backup{
		Created:     timeVal,
		Description: "My Backup",
		ID:          "61f12fef-edb1-4561-8122-e7c00ef26a82",
		InstanceID:  "d4603f69-ec7e-4e9b-803f-600b9205576f",
		LocationRef: "",
		Name:        "snapshot",
		ParentID:    "",
		Size:        100,
		Status:      "NEW",
		Updated:     timeVal,
		Datastore: datastores.DatastorePartial{
			Version:   "5.1",
			Type:      "MySQL",
			VersionID: "20000000-0000-0000-0000-000000000002",
		},
	}

	th.AssertDeepEquals(t, expected, instance)
}
예제 #4
0
func TestUserAccessList(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, _userURL+"/databases", "GET", "", listUserAccessResp, 200)

	expectedDBs := []db.Database{
		db.Database{Name: "databaseE"},
	}

	pages := 0
	err := ListAccess(fake.ServiceClient(), instanceID, userName).EachPage(func(page pagination.Page) (bool, error) {
		pages++

		actual, err := ExtractDBs(page)
		if err != nil {
			return false, err
		}

		th.CheckDeepEquals(t, expectedDBs, actual)

		return true, nil
	})

	th.AssertNoErr(t, err)
	th.AssertEquals(t, 1, pages)
}
예제 #5
0
func TestCreate(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, _rootURL, "POST", createReq, createResp, 200)

	opts := CreateOpts{
		Name:      "json_rack_instance",
		FlavorRef: "1",
		Databases: osDBs.BatchCreateOpts{
			osDBs.CreateOpts{CharSet: "utf8", Collate: "utf8_general_ci", Name: "sampledb"},
			osDBs.CreateOpts{Name: "nextround"},
		},
		Users: osUsers.BatchCreateOpts{
			osUsers.CreateOpts{
				Name:     "demouser",
				Password: "******",
				Databases: osDBs.BatchCreateOpts{
					osDBs.CreateOpts{Name: "sampledb"},
				},
			},
		},
		Size:         2,
		RestorePoint: "1234567890",
	}

	instance, err := Create(fake.ServiceClient(), opts).Extract()

	th.AssertNoErr(t, err)
	th.AssertDeepEquals(t, expectedInstance, instance)
}
예제 #6
0
func TestListInstances(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, resURL+"/instances", "GET", "", ListInstancesJSON, 200)

	expectedInstance := instances.Instance{
		ID:   "d4603f69-ec7e-4e9b-803f-600b9205576f",
		Name: "json_rack_instance",
	}

	pages := 0
	err := ListInstances(fake.ServiceClient(), configID).EachPage(func(page pagination.Page) (bool, error) {
		pages++

		actual, err := instances.ExtractInstances(page)
		if err != nil {
			return false, err
		}

		th.AssertDeepEquals(t, actual, []instances.Instance{expectedInstance})

		return true, nil
	})

	th.AssertNoErr(t, err)
	th.AssertEquals(t, 1, pages)
}
예제 #7
0
func TestListGlobalParams(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, globalParamListURL, "GET", "", ListParamsJSON, 200)

	pages := 0
	err := ListGlobalParams(fake.ServiceClient(), versionID).EachPage(func(page pagination.Page) (bool, error) {
		pages++

		actual, err := ExtractParams(page)
		if err != nil {
			return false, err
		}

		expected := []Param{
			Param{Max: 1, Min: 0, Name: "innodb_file_per_table", RestartRequired: true, Type: "integer"},
			Param{Max: 4294967296, Min: 0, Name: "key_buffer_size", RestartRequired: false, Type: "integer"},
			Param{Max: 65535, Min: 2, Name: "connect_timeout", RestartRequired: false, Type: "integer"},
			Param{Max: 4294967296, Min: 0, Name: "join_buffer_size", RestartRequired: false, Type: "integer"},
		}

		th.AssertDeepEquals(t, actual, expected)

		return true, nil
	})

	th.AssertNoErr(t, err)
	th.AssertEquals(t, 1, pages)
}
예제 #8
0
func TestGetReplica(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, resURL, "GET", "", getReplicaResp, 200)

	replica, err := Get(fake.ServiceClient(), instanceID).Extract()
	th.AssertNoErr(t, err)

	expectedReplica := &Instance{
		Status:  "ACTIVE",
		Updated: timeVal,
		Name:    "t1_ALT_GUEST",
		Created: timeVal,
		IP: []string{
			"10.0.0.2",
		},
		Replicas: []Instance{
			Instance{ID: "3c691f06-bf9a-4618-b7ec-2817ce0cf254"},
		},
		ID: "8b499b45-52d6-402d-b398-f9d8f279c69a",
		Volume: os.Volume{
			Used: 0.54,
			Size: 1,
		},
		Flavor: flavors.Flavor{ID: "9"},
		Datastore: datastores.DatastorePartial{
			Version: "5.6",
			Type:    "mysql",
		},
	}

	th.AssertDeepEquals(t, replica, expectedReplica)
}
예제 #9
0
func TestDetachReplica(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, resURL, "PATCH", detachReq, "", 202)

	err := DetachReplica(fake.ServiceClient(), instanceID).ExtractErr()
	th.AssertNoErr(t, err)
}
예제 #10
0
func TestRevokeAccess(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, _dbURL+"/{dbName}", "DELETE", "", "", 202)

	err := RevokeAccess(fake.ServiceClient(), instanceID, userName, "{dbName}").ExtractErr()
	th.AssertNoErr(t, err)
}
예제 #11
0
func TestAssociateWithConfigGroup(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, resURL, "PUT", associateReq, associateResp, 202)

	res := AssociateWithConfigGroup(fake.ServiceClient(), instanceID, "{configGroupID}")
	th.AssertNoErr(t, res.Err)
}
예제 #12
0
func TestDelete(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, resURL, "DELETE", "", "", 202)

	err := Delete(fake.ServiceClient(), configID).ExtractErr()
	th.AssertNoErr(t, err)
}
예제 #13
0
func TestGetVersion(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, "/datastores/{dsID}/versions/{versionID}", "GET", "", GetVersionResp, 200)

	ds, err := GetVersion(fake.ServiceClient(), "{dsID}", "{versionID}").Extract()
	th.AssertNoErr(t, err)
	th.AssertDeepEquals(t, &ExampleVersion1, ds)
}
예제 #14
0
func TestGrantAccess(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, _dbURL, "PUT", grantUserAccessReq, "", 202)

	opts := db.BatchCreateOpts{db.CreateOpts{Name: "databaseE"}}
	err := GrantAccess(fake.ServiceClient(), instanceID, userName, opts).ExtractErr()
	th.AssertNoErr(t, err)
}
예제 #15
0
func TestGet(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, resURL, "GET", "", GetConfigJSON, 200)

	config, err := Get(fake.ServiceClient(), configID).Extract()
	th.AssertNoErr(t, err)
	th.AssertDeepEquals(t, &ExampleConfig, config)
}
예제 #16
0
func TestGet(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, "/datastores/{dsID}", "GET", "", os.GetDSResp, 200)

	ds, err := Get(fake.ServiceClient(), "{dsID}").Extract()
	th.AssertNoErr(t, err)
	th.AssertDeepEquals(t, &os.ExampleDatastore, ds)
}
예제 #17
0
func TestGet(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, resURL, "GET", "", getResp, 200)

	instance, err := Get(fake.ServiceClient(), instanceID).Extract()

	th.AssertNoErr(t, err)
	th.AssertDeepEquals(t, expectedInstance, instance)
}
예제 #18
0
func TestGetConfig(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, resURL+"/configuration", "GET", "", getConfigResp, 200)

	config, err := GetDefaultConfig(fake.ServiceClient(), instanceID).Extract()

	expected := map[string]string{
		"basedir":                      "/usr",
		"connect_timeout":              "15",
		"datadir":                      "/var/lib/mysql",
		"default_storage_engine":       "innodb",
		"innodb_buffer_pool_instances": "1",
		"innodb_buffer_pool_size":      "175M",
		"innodb_checksum_algorithm":    "crc32",
		"innodb_data_file_path":        "ibdata1:10M:autoextend",
		"innodb_file_per_table":        "1",
		"innodb_io_capacity":           "200",
		"innodb_log_file_size":         "256M",
		"innodb_log_files_in_group":    "2",
		"innodb_open_files":            "8192",
		"innodb_thread_concurrency":    "0",
		"join_buffer_size":             "1M",
		"key_buffer_size":              "50M",
		"local-infile":                 "0",
		"log-error":                    "/var/log/mysql/mysqld.log",
		"max_allowed_packet":           "16M",
		"max_connect_errors":           "10000",
		"max_connections":              "40",
		"max_heap_table_size":          "16M",
		"myisam-recover":               "BACKUP",
		"open_files_limit":             "8192",
		"performance_schema":           "off",
		"pid_file":                     "/var/run/mysqld/mysqld.pid",
		"port":                         "3306",
		"query_cache_limit":            "1M",
		"query_cache_size":             "8M",
		"query_cache_type":             "1",
		"read_buffer_size":             "256K",
		"read_rnd_buffer_size":         "1M",
		"server_id":                    "1",
		"skip-external-locking":        "1",
		"skip_name_resolve":            "1",
		"sort_buffer_size":             "256K",
		"table_open_cache":             "4096",
		"thread_stack":                 "192K",
		"tmp_table_size":               "16M",
		"tmpdir":                       "/var/tmp",
		"user":                         "******",
		"wait_timeout":                 "3600",
	}

	th.AssertNoErr(t, err)
	th.AssertDeepEquals(t, expected, config)
}
예제 #19
0
func TestChangeUserPassword(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, _rootURL, "PUT", changePwdReq, "", 202)

	opts := os.BatchCreateOpts{
		os.CreateOpts{Name: "dbuser1", Password: "******"},
		os.CreateOpts{Name: "dbuser2", Password: "******"},
	}

	err := ChangePassword(fake.ServiceClient(), instanceID, opts).ExtractErr()
	th.AssertNoErr(t, err)
}
예제 #20
0
func TestUpdateUser(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, _userURL, "PUT", updateReq, "", 202)

	opts := UpdateOpts{
		Name:     "new_username",
		Password: "******",
	}

	err := Update(fake.ServiceClient(), instanceID, userName, opts).ExtractErr()
	th.AssertNoErr(t, err)
}
예제 #21
0
func TestReplace(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, resURL, "PUT", UpdateReq, "", 202)

	opts := UpdateOpts{
		Values: map[string]interface{}{
			"connect_timeout": 300,
		},
	}

	err := Replace(fake.ServiceClient(), configID, opts).ExtractErr()
	th.AssertNoErr(t, err)
}
예제 #22
0
func TestGetGlobalParam(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, globalParamGetURL, "GET", "", GetParamJSON, 200)

	param, err := GetGlobalParam(fake.ServiceClient(), versionID, paramID).Extract()
	th.AssertNoErr(t, err)

	expected := &Param{
		Max: 1, Min: 0, Name: "innodb_file_per_table", RestartRequired: true, Type: "integer",
	}

	th.AssertDeepEquals(t, expected, param)
}
예제 #23
0
func TestCreateReplica(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, _rootURL, "POST", createReplicaReq, createReplicaResp, 200)

	opts := CreateOpts{
		Name:      "t2s1_ALT_GUEST",
		FlavorRef: "9",
		Size:      1,
		ReplicaOf: "6bdca2fc-418e-40bd-a595-62abda61862d",
	}

	replica, err := Create(fake.ServiceClient(), opts).Extract()
	th.AssertNoErr(t, err)
	th.AssertDeepEquals(t, expectedReplica, replica)
}
예제 #24
0
func TestList(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, _baseURL, "GET", "", ListConfigsJSON, 200)

	count := 0
	err := List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
		count++
		actual, err := ExtractConfigs(page)
		th.AssertNoErr(t, err)

		expected := []Config{ExampleConfig}
		th.AssertDeepEquals(t, expected, actual)

		return true, nil
	})

	th.AssertEquals(t, 1, count)
	th.AssertNoErr(t, err)
}
예제 #25
0
func TestGetUser(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, _userURL, "GET", "", getResp, 200)

	user, err := Get(fake.ServiceClient(), instanceID, userName).Extract()

	th.AssertNoErr(t, err)

	expected := &User{
		Name: "exampleuser",
		Host: "foo",
		Databases: []db.Database{
			db.Database{Name: "databaseA"},
			db.Database{Name: "databaseB"},
		},
	}

	th.AssertDeepEquals(t, expected, user)
}
예제 #26
0
func TestUserList(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	fixture.SetupHandler(t, "/instances/"+instanceID+"/users", "GET", "", listResp, 200)

	expectedUsers := []User{
		User{
			Databases: []db.Database{
				db.Database{Name: "databaseA"},
			},
			Name: "dbuser1",
			Host: "localhost",
		},
		User{
			Databases: []db.Database{
				db.Database{Name: "databaseB"},
				db.Database{Name: "databaseC"},
			},
			Name: "dbuser2",
			Host: "localhost",
		},
	}

	pages := 0
	err := List(fake.ServiceClient(), instanceID).EachPage(func(page pagination.Page) (bool, error) {
		pages++

		actual, err := ExtractUsers(page)
		if err != nil {
			return false, err
		}

		th.CheckDeepEquals(t, expectedUsers, actual)

		return true, nil
	})

	th.AssertNoErr(t, err)
	th.AssertEquals(t, 1, pages)
}
예제 #27
0
func TestListReplicas(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, _rootURL, "GET", "", listReplicasResp, 200)

	pages := 0
	err := List(fake.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) {
		pages++

		actual, err := ExtractInstances(page)
		if err != nil {
			return false, err
		}

		expected := []Instance{
			Instance{
				Status: "ACTIVE",
				Name:   "t1s1_ALT_GUEST",
				Links: []gophercloud.Link{
					gophercloud.Link{Rel: "self", Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/instances/3c691f06-bf9a-4618-b7ec-2817ce0cf254"},
					gophercloud.Link{Rel: "bookmark", Href: "https://ord.databases.api.rackspacecloud.com/instances/3c691f06-bf9a-4618-b7ec-2817ce0cf254"},
				},
				ID:        "3c691f06-bf9a-4618-b7ec-2817ce0cf254",
				IP:        []string{"10.0.0.3"},
				Volume:    os.Volume{Size: 1},
				Flavor:    flavors.Flavor{ID: "9"},
				Datastore: datastores.DatastorePartial{Version: "5.6", Type: "mysql"},
				ReplicaOf: &Instance{
					ID: "8b499b45-52d6-402d-b398-f9d8f279c69a",
				},
			},
		}

		th.CheckDeepEquals(t, expected, actual)

		return true, nil
	})

	th.AssertNoErr(t, err)
	th.AssertEquals(t, 1, pages)
}
예제 #28
0
func TestCreate(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, _baseURL, "POST", CreateReq, CreateConfigJSON, 200)

	opts := CreateOpts{
		Datastore: &DatastoreOpts{
			Type:    "a00000a0-00a0-0a00-00a0-000a000000aa",
			Version: "b00000b0-00b0-0b00-00b0-000b000000bb",
		},
		Description: "example description",
		Name:        "example-configuration-name",
		Values: map[string]interface{}{
			"collation_server": "latin1_swedish_ci",
			"connect_timeout":  120,
		},
	}

	config, err := Create(fake.ServiceClient(), opts).Extract()
	th.AssertNoErr(t, err)
	th.AssertDeepEquals(t, &ExampleConfigWithValues, config)
}
예제 #29
0
func TestListVersions(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, "/datastores/{dsID}/versions", "GET", "", ListVersionsResp, 200)

	pages := 0

	err := ListVersions(fake.ServiceClient(), "{dsID}").EachPage(func(page pagination.Page) (bool, error) {
		pages++

		actual, err := ExtractVersions(page)
		if err != nil {
			return false, err
		}

		th.CheckDeepEquals(t, ExampleVersions, actual)

		return true, nil
	})

	th.AssertNoErr(t, err)
	th.AssertEquals(t, 1, pages)
}
예제 #30
0
func TestList(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	fixture.SetupHandler(t, "/datastores", "GET", "", os.ListDSResp, 200)

	pages := 0

	err := List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
		pages++

		actual, err := os.ExtractDatastores(page)
		if err != nil {
			return false, err
		}

		th.CheckDeepEquals(t, []os.Datastore{os.ExampleDatastore}, actual)

		return true, nil
	})

	th.AssertNoErr(t, err)
	th.AssertEquals(t, 1, pages)
}