Merge pull request #132 from Gmaker689/fix-cloud-dm-register-cluster-version
Fix cloud dm register cluster version
This commit is contained in:
@@ -2389,6 +2389,8 @@ type cloudDMDataSource struct {
|
||||
InstanceDesc string `json:"instanceDesc"`
|
||||
DSType string `json:"dsType"`
|
||||
Host string `json:"host"`
|
||||
ClusterID *uint64 `json:"cluster_id"`
|
||||
MySQLVersion string `json:"mysql_version"`
|
||||
SecurityType string `json:"securityType"`
|
||||
UserName string `json:"userName"`
|
||||
Password string `json:"password"`
|
||||
@@ -2466,6 +2468,13 @@ func buildCloudDMRegisterRequest(instance model.DeploymentResult, payload delive
|
||||
if description == "" {
|
||||
description = instance.InstanceName
|
||||
}
|
||||
mysqlVersion := strings.TrimSpace(instance.Version)
|
||||
if mysqlVersion == "" {
|
||||
mysqlVersion = strings.TrimSpace(payload.MySQLVersion)
|
||||
}
|
||||
if mysqlVersion == "" {
|
||||
mysqlVersion = "8.0"
|
||||
}
|
||||
return cloudDMRegisterRequest{
|
||||
SourceSystem: "xinfra",
|
||||
ResourceType: "MYSQL_INSTANCE",
|
||||
@@ -2475,6 +2484,8 @@ func buildCloudDMRegisterRequest(instance model.DeploymentResult, payload delive
|
||||
InstanceDesc: description,
|
||||
DSType: "MySQL",
|
||||
Host: net.JoinHostPort(instance.Host, strconv.Itoa(instance.Port)),
|
||||
ClusterID: nil,
|
||||
MySQLVersion: mysqlVersion,
|
||||
SecurityType: "USER_PASSWD",
|
||||
UserName: "root",
|
||||
Password: password,
|
||||
|
||||
@@ -147,7 +147,7 @@ func TestAllocatePort(t *testing.T) {
|
||||
|
||||
func TestBuildCloudDMRegisterRequest(t *testing.T) {
|
||||
req := buildCloudDMRegisterRequest(
|
||||
model.DeploymentResult{ID: 42, InstanceName: "mysql-payment-prod", Host: "10.0.0.10", Port: 3306},
|
||||
model.DeploymentResult{ID: 42, InstanceName: "mysql-payment-prod", Host: "10.0.0.10", Port: 3306, Version: "8.4"},
|
||||
deliveryPayload{MySQLDeliveryInput: MySQLDeliveryInput{InstanceDesc: "支付生产 MySQL", Timezone: "Asia/Shanghai"}},
|
||||
"secret",
|
||||
)
|
||||
@@ -160,6 +160,12 @@ func TestBuildCloudDMRegisterRequest(t *testing.T) {
|
||||
if req.DataSource.Host != "10.0.0.10:3306" || req.DataSource.Password != "secret" {
|
||||
t.Fatalf("unexpected data source fields: %#v", req.DataSource)
|
||||
}
|
||||
if req.DataSource.ClusterID != nil {
|
||||
t.Fatalf("cluster_id must be nullable when xinfra cannot resolve it, got %#v", req.DataSource.ClusterID)
|
||||
}
|
||||
if req.DataSource.MySQLVersion != "8.4" {
|
||||
t.Fatalf("unexpected mysql version: %#v", req.DataSource.MySQLVersion)
|
||||
}
|
||||
if req.DataSource.ClientTimeZone != "Asia/Shanghai" || req.DataSource.ConnectionCharset != "utf8" {
|
||||
t.Fatalf("unexpected time zone or charset: %#v", req.DataSource)
|
||||
}
|
||||
@@ -175,6 +181,12 @@ func TestBuildCloudDMRegisterRequest(t *testing.T) {
|
||||
if value, ok := dataSource["defaultSchema"]; !ok || value != nil {
|
||||
t.Fatalf("defaultSchema must be present as null, got %#v", dataSource["defaultSchema"])
|
||||
}
|
||||
if value, ok := dataSource["cluster_id"]; !ok || value != nil {
|
||||
t.Fatalf("cluster_id must be present as null, got %#v", dataSource["cluster_id"])
|
||||
}
|
||||
if value, ok := dataSource["mysql_version"]; !ok || value != "8.4" {
|
||||
t.Fatalf("mysql_version must be propagated from deployed instance, got %#v", value)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCloudDMDataSourceIDFromResponse(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user