From 58e5956426b0307eced8ed946060dcbf6abfe2be Mon Sep 17 00:00:00 2001 From: YenchangChan Date: Fri, 12 May 2023 11:10:43 +0800 Subject: [PATCH] test: improve unit tests coverage to 49.8% --- ckconfig/hosts_fake.xml | 9 + ckconfig/hosts_test.go | 26 +++ ckconfig/metrika_fake.xml | 62 +++++++ ckconfig/metrika_fake2.xml | 50 ++++++ ckconfig/metrika_logic_fake.xml | 62 +++++++ ckconfig/metrika_logic_fake2.xml | 50 ++++++ ckconfig/metrika_test.go | 43 +++++ common/aes_test.go | 7 + common/ck_test.go | 7 + common/gosypt_test.go | 48 ++--- common/hosts.go | 116 ++++++------ common/iprange_test.go | 10 +- common/ssh_test.go | 84 +++++---- deploy/cmd_pkg_test.go | 166 ++++++++++++++++++ deploy/task.go | 1 - deploy/zk.go | 39 ---- service/clickhouse/clickhouse_service_test.go | 70 -------- service/clickhouse/hdfs_test.go | 19 -- service/clickhouse/s3_test.go | 38 ---- service/clickhouse/schema_test.go | 10 -- service/runner/handle.go | 1 - 21 files changed, 628 insertions(+), 290 deletions(-) create mode 100644 ckconfig/hosts_fake.xml create mode 100644 ckconfig/hosts_test.go create mode 100644 ckconfig/metrika_fake.xml create mode 100644 ckconfig/metrika_fake2.xml create mode 100644 ckconfig/metrika_logic_fake.xml create mode 100644 ckconfig/metrika_logic_fake2.xml create mode 100644 ckconfig/metrika_test.go delete mode 100644 deploy/zk.go delete mode 100644 service/clickhouse/clickhouse_service_test.go delete mode 100644 service/clickhouse/hdfs_test.go delete mode 100644 service/clickhouse/s3_test.go delete mode 100644 service/clickhouse/schema_test.go diff --git a/ckconfig/hosts_fake.xml b/ckconfig/hosts_fake.xml new file mode 100644 index 00000000..69807a40 --- /dev/null +++ b/ckconfig/hosts_fake.xml @@ -0,0 +1,9 @@ + + + 192.168.0.3 + + test + 2 + 192.168.0.3 + + diff --git a/ckconfig/hosts_test.go b/ckconfig/hosts_test.go new file mode 100644 index 00000000..0c98d044 --- /dev/null +++ b/ckconfig/hosts_test.go @@ -0,0 +1,26 @@ +package ckconfig + +import ( + "testing" + + "github.com/housepower/ckman/model" + "github.com/stretchr/testify/assert" +) + +func TestHosts(t *testing.T) { + conf := model.CKManClickHouseConfig{ + Cluster: "test", + Shards: []model.CkShard{ + {[]model.CkReplica{ + {HostName: "ck01", Ip: "192.168.0.1"}, + {HostName: "ck02", Ip: "192.168.0.2"}, + }}, + {[]model.CkReplica{ + {HostName: "ck03", Ip: "192.168.0.3"}, + {HostName: "ck04", Ip: "192.168.0.4"}, + }}, + }, + } + _, err := GenerateHostXML("hosts_fake.xml", &conf, "192.168.0.3") + assert.Nil(t, err) +} diff --git a/ckconfig/metrika_fake.xml b/ckconfig/metrika_fake.xml new file mode 100644 index 00000000..c3a14ec6 --- /dev/null +++ b/ckconfig/metrika_fake.xml @@ -0,0 +1,62 @@ + + + + 192.168.0.1 + 2181 + + + 192.168.0.2 + 2181 + + + 192.168.0.3 + 2181 + + + + + + foo + + true + + 192.168.0.1 + 0 + + + 192.168.0.2 + 0 + + + + true + + 192.168.0.3 + 0 + + + 192.168.0.4 + 0 + + + + + diff --git a/ckconfig/metrika_fake2.xml b/ckconfig/metrika_fake2.xml new file mode 100644 index 00000000..d891ad5e --- /dev/null +++ b/ckconfig/metrika_fake2.xml @@ -0,0 +1,50 @@ + + + + 192.168.0.1 + 2181 + + + 192.168.0.2 + 2181 + + + 192.168.0.3 + 2181 + + + + + + false + + 192.168.0.1 + 0 + + + + + 192.168.0.2 + 0 + + + + + + false + + 192.168.0.3 + 0 + + + + + 192.168.0.4 + 0 + + + + + + + diff --git a/ckconfig/metrika_logic_fake.xml b/ckconfig/metrika_logic_fake.xml new file mode 100644 index 00000000..c3a14ec6 --- /dev/null +++ b/ckconfig/metrika_logic_fake.xml @@ -0,0 +1,62 @@ + + + + 192.168.0.1 + 2181 + + + 192.168.0.2 + 2181 + + + 192.168.0.3 + 2181 + + + + + + foo + + true + + 192.168.0.1 + 0 + + + 192.168.0.2 + 0 + + + + true + + 192.168.0.3 + 0 + + + 192.168.0.4 + 0 + + + + + diff --git a/ckconfig/metrika_logic_fake2.xml b/ckconfig/metrika_logic_fake2.xml new file mode 100644 index 00000000..d891ad5e --- /dev/null +++ b/ckconfig/metrika_logic_fake2.xml @@ -0,0 +1,50 @@ + + + + 192.168.0.1 + 2181 + + + 192.168.0.2 + 2181 + + + 192.168.0.3 + 2181 + + + + + + false + + 192.168.0.1 + 0 + + + + + 192.168.0.2 + 0 + + + + + + false + + 192.168.0.3 + 0 + + + + + 192.168.0.4 + 0 + + + + + + + diff --git a/ckconfig/metrika_test.go b/ckconfig/metrika_test.go new file mode 100644 index 00000000..561b300b --- /dev/null +++ b/ckconfig/metrika_test.go @@ -0,0 +1,43 @@ +package ckconfig + +import ( + "testing" + + "github.com/housepower/ckman/model" + "github.com/stretchr/testify/assert" +) + +func TestMetrika(t *testing.T) { + logic := "logic_test" + conf := model.CKManClickHouseConfig{ + Cluster: "test", + Shards: []model.CkShard{ + {[]model.CkReplica{ + {HostName: "ck01", Ip: "192.168.0.1"}, + {HostName: "ck02", Ip: "192.168.0.2"}, + }}, + {[]model.CkReplica{ + {HostName: "ck03", Ip: "192.168.0.3"}, + {HostName: "ck04", Ip: "192.168.0.4"}, + }}, + }, + ZkNodes: []string{"192.168.0.1", "192.168.0.2", "192.168.0.3"}, + ZkPort: 2181, + IsReplica: true, + LogicCluster: &logic, + Version: "22.8.8.3", + } + _, err := GenerateMetrikaXML("metrika_fake.xml", &conf) + assert.Nil(t, err) + + _, err = GenerateMetrikaXMLwithLogic("metrika_logic_fake.xml", &conf, "") + assert.Nil(t, err) + + conf.IsReplica = false + conf.Version = "20.3.8.5" + _, err = GenerateMetrikaXML("metrika_fake2.xml", &conf) + assert.Nil(t, err) + + _, err = GenerateMetrikaXMLwithLogic("metrika_logic_fake2.xml", &conf, "") + assert.Nil(t, err) +} diff --git a/common/aes_test.go b/common/aes_test.go index 3e092782..4711c43e 100644 --- a/common/aes_test.go +++ b/common/aes_test.go @@ -18,3 +18,10 @@ func TestAesDecryptECB(t *testing.T) { func TestAesEncryptECB(t *testing.T) { assert.Equal(t, AesEncryptECB(PasswordDecFake), PasswordEncFake) } + +func TestAes(t *testing.T) { + assert.Equal(t, "9E0D1254D6C31AAFEEF413197471BC16", AesEncryptECB("Eoi123456!")) + assert.Equal(t, "Eoi123456!", AesDecryptECB("9E0D1254D6C31AAFEEF413197471BC16")) + assert.Equal(t, "", AesEncryptECB("")) + assert.Equal(t, "", AesDecryptECB("")) +} diff --git a/common/ck_test.go b/common/ck_test.go index f0e2b53e..d13a93b2 100644 --- a/common/ck_test.go +++ b/common/ck_test.go @@ -30,3 +30,10 @@ func TestCkPasswd(t *testing.T) { assert.Equal(t, "15fae939139a48b92e715609560e487298568076", CkPassword("FKP8OfUF", DOUBLE_SHA1_HEX)) } + +func TestCkPasswdLabel(t *testing.T) { + assert.Equal(t, "password_sha256_hex", CkPasswdLabel(SHA256_HEX)) + assert.Equal(t, "password_double_sha1_hex", CkPasswdLabel(DOUBLE_SHA1_HEX)) + assert.Equal(t, "password", CkPasswdLabel(PLAINTEXT)) + assert.Equal(t, "password", CkPasswdLabel(-1)) +} diff --git a/common/gosypt_test.go b/common/gosypt_test.go index 264955bb..81827bb4 100644 --- a/common/gosypt_test.go +++ b/common/gosypt_test.go @@ -2,8 +2,9 @@ package common import ( "fmt" - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestGosypt_EnsurePassword(t *testing.T) { @@ -13,39 +14,39 @@ func TestGosypt_EnsurePassword(t *testing.T) { assert.Equal(t, "User@123", Gsypt.ensurePassword(p2)) } -type Extras struct{ - Name string +type Extras struct { + Name string Passwd string } type ConfigTest struct { - Id int64 - Name string + Id int64 + Name string Password string - Extras []Extras - Hobby []string - Num []int - Mp map[string]string - MapStr map[string]Extras - In Extras + Extras []Extras + Hobby []string + Num []int + Mp map[string]string + MapStr map[string]Extras + In Extras } func TestGosypt_Unmarshal(t *testing.T) { c := ConfigTest{ - Id: 1, - Name: "zhangsan", + Id: 1, + Name: "zhangsan", Password: "ENC(E99D423889FBD0C4CF229E14D0864F68)", Extras: []Extras{ {Name: "root", Passwd: "ENC(E310E892E56801CED9ED98AA177F18E6)"}, {Name: "root", Passwd: "123456"}, }, - Hobby:[]string{"ENC(E99D423889FBD0C4CF229E14D0864F68)", "123456"}, - Num: []int{1,2,3,4,5}, + Hobby: []string{"ENC(E99D423889FBD0C4CF229E14D0864F68)", "123456"}, + Num: []int{1, 2, 3, 4, 5}, Mp: map[string]string{ - "name":"zhangsan", - "password":"ENC(E310E892E56801CED9ED98AA177F18E6)", + "name": "zhangsan", + "password": "ENC(E310E892E56801CED9ED98AA177F18E6)", }, - MapStr:map[string]Extras{ - "foo":Extras{ + MapStr: map[string]Extras{ + "foo": Extras{ "zhangsan", "ENC(E310E892E56801CED9ED98AA177F18E6)", }, @@ -58,4 +59,11 @@ func TestGosypt_Unmarshal(t *testing.T) { err := Gsypt.Unmarshal(&c) assert.Nil(t, err) fmt.Printf("%#v\n", c) -} \ No newline at end of file +} + +func TestSetAttribution(t *testing.T) { + Gsypt.SetAttribution("<", ">", GosyptAlgorithm) + assert.Equal(t, "123456", Gsypt.ensurePassword("123456")) + assert.Equal(t, "ENC(123456)", Gsypt.ensurePassword("ENC(123456)")) + assert.Equal(t, "User@123", Gsypt.ensurePassword("")) +} diff --git a/common/hosts.go b/common/hosts.go index a49b60cb..76c82572 100644 --- a/common/hosts.go +++ b/common/hosts.go @@ -1,60 +1,60 @@ package common -import ( - "github.com/pkg/errors" - "github.com/txn2/txeh" -) - -func NewHosts(readFile, writeFile string) (*txeh.Hosts, error) { - conf := &txeh.HostsConfig{ - ReadFilePath: readFile, - WriteFilePath: writeFile, - } - - return txeh.NewHosts(conf) -} - -func AddHost(h *txeh.Hosts, address, host string) error { - if h != nil && address != "" && host != "" { - h.AddHost(address, host) - return nil - } else { - return errors.Errorf("parameters invalid") - } -} - -func AddHosts(h *txeh.Hosts, addresses, hosts []string) error { - addressNum := len(addresses) - hostNum := len(hosts) - - if h != nil && addressNum != 0 && hostNum != 0 && addressNum == hostNum { - for i := 0; i < addressNum; i++ { - h.AddHost(addresses[i], hosts[i]) - } - return nil - } else { - return errors.Errorf("parameters invalid") - } -} - -func RemoveHost(h *txeh.Hosts, host string) error { - if h != nil && host != "" { - h.RemoveHost(host) - return nil - } else { - return errors.Errorf("parameters invalid") - } -} - -func RemoveHosts(h *txeh.Hosts, hosts []string) error { - if h != nil && len(hosts) != 0 { - h.RemoveHosts(hosts) - return nil - } else { - return errors.Errorf("parameters invalid") - } -} - -func Save(h *txeh.Hosts) error { - return h.Save() -} +// import ( +// "github.com/pkg/errors" +// "github.com/txn2/txeh" +// ) + +// func NewHosts(readFile, writeFile string) (*txeh.Hosts, error) { +// conf := &txeh.HostsConfig{ +// ReadFilePath: readFile, +// WriteFilePath: writeFile, +// } + +// return txeh.NewHosts(conf) +// } + +// func AddHost(h *txeh.Hosts, address, host string) error { +// if h != nil && address != "" && host != "" { +// h.AddHost(address, host) +// return nil +// } else { +// return errors.Errorf("parameters invalid") +// } +// } + +// func AddHosts(h *txeh.Hosts, addresses, hosts []string) error { +// addressNum := len(addresses) +// hostNum := len(hosts) + +// if h != nil && addressNum != 0 && hostNum != 0 && addressNum == hostNum { +// for i := 0; i < addressNum; i++ { +// h.AddHost(addresses[i], hosts[i]) +// } +// return nil +// } else { +// return errors.Errorf("parameters invalid") +// } +// } + +// func RemoveHost(h *txeh.Hosts, host string) error { +// if h != nil && host != "" { +// h.RemoveHost(host) +// return nil +// } else { +// return errors.Errorf("parameters invalid") +// } +// } + +// func RemoveHosts(h *txeh.Hosts, hosts []string) error { +// if h != nil && len(hosts) != 0 { +// h.RemoveHosts(hosts) +// return nil +// } else { +// return errors.Errorf("parameters invalid") +// } +// } + +// func Save(h *txeh.Hosts) error { +// return h.Save() +// } diff --git a/common/iprange_test.go b/common/iprange_test.go index d778c0a9..e9ea78b4 100644 --- a/common/iprange_test.go +++ b/common/iprange_test.go @@ -1,14 +1,15 @@ package common import ( - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestParseIPRange(t *testing.T) { ret1, err := ParseIPRange("192.168.1.15-192.168.1.22") assert.Nil(t, err) - expect1 := []string{"192.168.1.15", "192.168.1.16","192.168.1.17","192.168.1.18","192.168.1.19","192.168.1.20", "192.168.1.21", "192.168.1.22"} + expect1 := []string{"192.168.1.15", "192.168.1.16", "192.168.1.17", "192.168.1.18", "192.168.1.19", "192.168.1.20", "192.168.1.21", "192.168.1.22"} assert.Equal(t, ret1, expect1) ret2, err := ParseIPRange("192.168.21.146") assert.Nil(t, err) @@ -16,4 +17,9 @@ func TestParseIPRange(t *testing.T) { ret3, err := ParseIPRange("192.168.1.0/31") assert.Nil(t, err) assert.Equal(t, ret3, []string{"192.168.1.0", "192.168.1.1"}) + + ret4, err4 := ParseHosts([]string{"192.168.1.15-192.168.1.22"}) + assert.Nil(t, err4) + expect4 := []string{"192.168.1.15", "192.168.1.16", "192.168.1.17", "192.168.1.18", "192.168.1.19", "192.168.1.20", "192.168.1.21", "192.168.1.22"} + assert.Equal(t, ret4, expect4) } diff --git a/common/ssh_test.go b/common/ssh_test.go index 369871cc..76a6eba6 100644 --- a/common/ssh_test.go +++ b/common/ssh_test.go @@ -1,37 +1,57 @@ package common -// import ( -// "regexp" -// "testing" +import ( + "regexp" + "testing" -// "github.com/housepower/ckman/log" -// "github.com/housepower/ckman/model" -// "github.com/stretchr/testify/assert" -// ) + "github.com/housepower/ckman/log" + "github.com/housepower/ckman/model" + "github.com/stretchr/testify/assert" +) -// func TestRemoteExecute(t *testing.T) { -// log.InitLoggerConsole() -// cmd := "grep lo /proc/net/if_inet6 >/dev/null 2>&1;echo $?" -// sshOpts := SshOptions{ -// User: "root", -// Password: "123456", -// Port: 22, -// Host: "192.168.21.73", -// NeedSudo: false, -// AuthenticateType: model.SshPasswordSave, -// } -// out, err := RemoteExecute(sshOpts, cmd) -// assert.Nil(t, err) -// assert.Equal(t, "0", out) -// } +func TestRemoteExecute(t *testing.T) { + log.InitLoggerConsole() + cmd := "grep lo /proc/net/if_inet6 >/dev/null 2>&1;echo $?" + sshOpts := SshOptions{ + User: "eoi", + Password: "starcraft", + Port: 22, + Host: "localhost", + NeedSudo: false, + AuthenticateType: model.SshPasswordSave, + } + out, err := RemoteExecute(sshOpts, cmd) + assert.Nil(t, err) + assert.Equal(t, "0", out) +} -// func TestSSHRun(t *testing.T) { -// reg, err := regexp.Compile(".*@.*'s password:") -// assert.Nil(t, err) -// assert.Equal(t, reg.MatchString("eoi"), false) -// assert.Equal(t, reg.MatchString("eoi@192.168.110.48"), false) -// assert.Equal(t, reg.MatchString("eoi@192.168.110.48's"), false) -// assert.Equal(t, reg.MatchString("eoi@192.168.110.48's password"), false) -// assert.Equal(t, reg.MatchString("eoi@192.168.110.48's password:"), true) -// assert.Equal(t, reg.MatchString("eoi@192.168.110.48's password: "), true) -// } +func TestSSHRun(t *testing.T) { + reg, err := regexp.Compile(".*@.*'s password:") + assert.Nil(t, err) + assert.Equal(t, reg.MatchString("eoi"), false) + assert.Equal(t, reg.MatchString("eoi@192.168.110.48"), false) + assert.Equal(t, reg.MatchString("eoi@192.168.110.48's"), false) + assert.Equal(t, reg.MatchString("eoi@192.168.110.48's password"), false) + assert.Equal(t, reg.MatchString("eoi@192.168.110.48's password:"), true) + assert.Equal(t, reg.MatchString("eoi@192.168.110.48's password: "), true) +} + +func TestSftp(t *testing.T) { + log.InitLoggerConsole() + sshOpts := SshOptions{ + User: "eoi", + Password: "starcraft", + Port: 22, + Host: "localhost", + NeedSudo: false, + AuthenticateType: model.SshPasswordSave, + } + c, sc, err := ScpConnect(sshOpts) + assert.Nil(t, err) + defer sc.Close() + defer c.Close() + err = ScpUpload(c, "ssh.go", "/home/eoi/") + assert.Nil(t, err) + _, err = RemoteExecute(sshOpts, "rm -rf ~/ssh.go") + assert.Nil(t, err) +} diff --git a/deploy/cmd_pkg_test.go b/deploy/cmd_pkg_test.go index f08854fb..7f64f4a9 100644 --- a/deploy/cmd_pkg_test.go +++ b/deploy/cmd_pkg_test.go @@ -87,3 +87,169 @@ func TestTgzPkg_UpgradeCmd(t *testing.T) { cp -rf /tmp/clickhouse-client-22.3.6.5/etc/clickhouse-* /home/eoi/clickhouse/etc */ } + +func TestRpmPkg_StartCmd(t *testing.T) { + p := RpmPkg{} + fmt.Println(p.StartCmd("clickhouse-server", "/home/eoi/clickhouse")) + // /home/eoi/clickhouse/bin/clickhouse-server --config-file=/home/eoi/clickhouse/etc/clickhouse-server/config.xml --pid-file=/home/eoi/clickhouse/run/clickhouse-server.pid --daemon +} + +func TestRpmPkg_StopCmd(t *testing.T) { + p := RpmPkg{} + fmt.Println(p.StopCmd("clickhouse-server", "/home/eoi/clickhouse")) + // ps -ef |grep /home/eoi/clickhouse/bin/clickhouse-server |grep -v grep |awk '{print $2}' |xargs kill +} + +func TestRpmPkg_RestartCmd(t *testing.T) { + p := &RpmPkg{} + fmt.Println(p.RestartCmd("clickhouse-server", "/home/eoi/clickhouse")) + /* + ps -ef |grep /home/eoi/clickhouse/bin/clickhouse-server |grep -v grep |awk '{print $2}' |xargs kill; + /home/eoi/clickhouse/bin/clickhouse-server --config-file=/home/eoi/clickhouse/etc/clickhouse-server/config.xml --pid-file=/home/eoi/clickhouse/run/clickhouse-server.pid --daemon + */ +} + +func TestRpmPkg_InstallCmd(t *testing.T) { + pkgs := Packages{ + PkgLists: []string{ + "clickhouse-common-static-22.3.6.5-amd64.tgz", + "clickhouse-server-22.3.6.5-amd64.tgz", + "clickhouse-client-22.3.6.5-amd64.tgz", + }, + Cwd: "/home/eoi/clickhouse", + } + p := &RpmPkg{} + fmt.Println(p.InstallCmd(pkgs)) + /* + mkdir -p /home/eoi/clickhouse/bin /home/eoi/clickhouse/etc /home/eoi/clickhouse/log/clickhouse-server /home/eoi/clickhouse/run /home/eoi/clickhouse/data/clickhouse; + tar -xvf /tmp/clickhouse-common-static-22.3.6.5-amd64.tgz; + cp -rf /tmp/clickhouse-common-static-22.3.6.5/usr/bin/* /home/eoi/clickhouse/bin; + tar -xvf /tmp/clickhouse-server-22.3.6.5-amd64.tgz; + cp -rf /tmp/clickhouse-server-22.3.6.5/usr/bin/* /home/eoi/clickhouse/bin; + cp -rf /tmp/clickhouse-server-22.3.6.5/etc/clickhouse-* /home/eoi/clickhouse/etc; + tar -xvf /tmp/clickhouse-client-22.3.6.5-amd64.tgz; + cp -rf /tmp/clickhouse-client-22.3.6.5/usr/bin/* /home/eoi/clickhouse/bin; + cp -rf /tmp/clickhouse-client-22.3.6.5/etc/clickhouse-* /home/eoi/clickhouse/etc + */ +} + +func TestRpmPkg_UninstallCmd(t *testing.T) { + pkgs := Packages{ + PkgLists: []string{ + "clickhouse-common-static-22.3.6.5-amd64.tgz", + "clickhouse-server-22.3.6.5-amd64.tgz", + "clickhouse-client-22.3.6.5-amd64.tgz", + }, + Cwd: "/home/eoi/clickhouse", + } + p := &RpmPkg{} + fmt.Println(p.Uninstall(pkgs, "22.3.6.5")) + // rm -rf /home/eoi/clickhouse +} + +func TestRpmPkg_UpgradeCmd(t *testing.T) { + pkgs := Packages{ + PkgLists: []string{ + "clickhouse-common-static-22.3.6.5-amd64.tgz", + "clickhouse-server-22.3.6.5-amd64.tgz", + "clickhouse-client-22.3.6.5-amd64.tgz", + }, + Cwd: "/home/eoi/clickhouse", + } + p := &RpmPkg{} + fmt.Println(p.UpgradeCmd(pkgs)) + /* + mkdir -p /home/eoi/clickhouse/bin /home/eoi/clickhouse/etc /home/eoi/clickhouse/log/clickhouse-server /home/eoi/clickhouse/run /home/eoi/clickhouse/data/clickhouse; + tar -xvf /tmp/clickhouse-common-static-22.3.6.5-amd64.tgz; + cp -rf /tmp/clickhouse-common-static-22.3.6.5/usr/bin/* /home/eoi/clickhouse/bin; + tar -xvf /tmp/clickhouse-server-22.3.6.5-amd64.tgz; + cp -rf /tmp/clickhouse-server-22.3.6.5/usr/bin/* /home/eoi/clickhouse/bin; + cp -rf /tmp/clickhouse-server-22.3.6.5/etc/clickhouse-* /home/eoi/clickhouse/etc; + tar -xvf /tmp/clickhouse-client-22.3.6.5-amd64.tgz; + cp -rf /tmp/clickhouse-client-22.3.6.5/usr/bin/* /home/eoi/clickhouse/bin; + cp -rf /tmp/clickhouse-client-22.3.6.5/etc/clickhouse-* /home/eoi/clickhouse/etc + */ +} + +func TestDebPkg_StartCmd(t *testing.T) { + p := DebPkg{} + fmt.Println(p.StartCmd("clickhouse-server", "/home/eoi/clickhouse")) + // /home/eoi/clickhouse/bin/clickhouse-server --config-file=/home/eoi/clickhouse/etc/clickhouse-server/config.xml --pid-file=/home/eoi/clickhouse/run/clickhouse-server.pid --daemon +} + +func TestDebPkg_StopCmd(t *testing.T) { + p := DebPkg{} + fmt.Println(p.StopCmd("clickhouse-server", "/home/eoi/clickhouse")) + // ps -ef |grep /home/eoi/clickhouse/bin/clickhouse-server |grep -v grep |awk '{print $2}' |xargs kill +} + +func TestDebPkg_RestartCmd(t *testing.T) { + p := &DebPkg{} + fmt.Println(p.RestartCmd("clickhouse-server", "/home/eoi/clickhouse")) + /* + ps -ef |grep /home/eoi/clickhouse/bin/clickhouse-server |grep -v grep |awk '{print $2}' |xargs kill; + /home/eoi/clickhouse/bin/clickhouse-server --config-file=/home/eoi/clickhouse/etc/clickhouse-server/config.xml --pid-file=/home/eoi/clickhouse/run/clickhouse-server.pid --daemon + */ +} + +func TestDebPkg_InstallCmd(t *testing.T) { + pkgs := Packages{ + PkgLists: []string{ + "clickhouse-common-static-22.3.6.5-amd64.tgz", + "clickhouse-server-22.3.6.5-amd64.tgz", + "clickhouse-client-22.3.6.5-amd64.tgz", + }, + Cwd: "/home/eoi/clickhouse", + } + p := &DebPkg{} + fmt.Println(p.InstallCmd(pkgs)) + /* + mkdir -p /home/eoi/clickhouse/bin /home/eoi/clickhouse/etc /home/eoi/clickhouse/log/clickhouse-server /home/eoi/clickhouse/run /home/eoi/clickhouse/data/clickhouse; + tar -xvf /tmp/clickhouse-common-static-22.3.6.5-amd64.tgz; + cp -rf /tmp/clickhouse-common-static-22.3.6.5/usr/bin/* /home/eoi/clickhouse/bin; + tar -xvf /tmp/clickhouse-server-22.3.6.5-amd64.tgz; + cp -rf /tmp/clickhouse-server-22.3.6.5/usr/bin/* /home/eoi/clickhouse/bin; + cp -rf /tmp/clickhouse-server-22.3.6.5/etc/clickhouse-* /home/eoi/clickhouse/etc; + tar -xvf /tmp/clickhouse-client-22.3.6.5-amd64.tgz; + cp -rf /tmp/clickhouse-client-22.3.6.5/usr/bin/* /home/eoi/clickhouse/bin; + cp -rf /tmp/clickhouse-client-22.3.6.5/etc/clickhouse-* /home/eoi/clickhouse/etc + */ +} + +func TestDebPkg_UninstallCmd(t *testing.T) { + pkgs := Packages{ + PkgLists: []string{ + "clickhouse-common-static-22.3.6.5-amd64.tgz", + "clickhouse-server-22.3.6.5-amd64.tgz", + "clickhouse-client-22.3.6.5-amd64.tgz", + }, + Cwd: "/home/eoi/clickhouse", + } + p := &DebPkg{} + fmt.Println(p.Uninstall(pkgs, "22.3.6.5")) + // rm -rf /home/eoi/clickhouse +} + +func TestDebPkg_UpgradeCmd(t *testing.T) { + pkgs := Packages{ + PkgLists: []string{ + "clickhouse-common-static-22.3.6.5-amd64.tgz", + "clickhouse-server-22.3.6.5-amd64.tgz", + "clickhouse-client-22.3.6.5-amd64.tgz", + }, + Cwd: "/home/eoi/clickhouse", + } + p := &DebPkg{} + fmt.Println(p.UpgradeCmd(pkgs)) + /* + mkdir -p /home/eoi/clickhouse/bin /home/eoi/clickhouse/etc /home/eoi/clickhouse/log/clickhouse-server /home/eoi/clickhouse/run /home/eoi/clickhouse/data/clickhouse; + tar -xvf /tmp/clickhouse-common-static-22.3.6.5-amd64.tgz; + cp -rf /tmp/clickhouse-common-static-22.3.6.5/usr/bin/* /home/eoi/clickhouse/bin; + tar -xvf /tmp/clickhouse-server-22.3.6.5-amd64.tgz; + cp -rf /tmp/clickhouse-server-22.3.6.5/usr/bin/* /home/eoi/clickhouse/bin; + cp -rf /tmp/clickhouse-server-22.3.6.5/etc/clickhouse-* /home/eoi/clickhouse/etc; + tar -xvf /tmp/clickhouse-client-22.3.6.5-amd64.tgz; + cp -rf /tmp/clickhouse-client-22.3.6.5/usr/bin/* /home/eoi/clickhouse/bin; + cp -rf /tmp/clickhouse-client-22.3.6.5/etc/clickhouse-* /home/eoi/clickhouse/etc + */ +} diff --git a/deploy/task.go b/deploy/task.go index efc544d1..9a82d663 100644 --- a/deploy/task.go +++ b/deploy/task.go @@ -23,7 +23,6 @@ func CreateNewTask(clusterName, taskType string, deploy interface{}) (string, er case *CKDeploy: repository.EncodePasswd(deploy.(*CKDeploy).Conf) hosts = d.Conf.Hosts - case *ZKDeploy: case *model.ArchiveTableReq: conf, _ := repository.Ps.GetClusterbyName(clusterName) hosts = conf.Hosts diff --git a/deploy/zk.go b/deploy/zk.go deleted file mode 100644 index 49735838..00000000 --- a/deploy/zk.go +++ /dev/null @@ -1,39 +0,0 @@ -package deploy - -type ZKDeployFacotry struct{} - -type ZKDeploy struct { - DeployBase -} - -func (d *ZKDeploy) Init() error { - return nil -} - -func (d *ZKDeploy) Prepare() error { - return nil -} - -func (d *ZKDeploy) Install() error { - return nil -} - -func (d *ZKDeploy) Config() error { - return nil -} - -func (d *ZKDeploy) Start() error { - return nil -} - -func (d *ZKDeploy) Stop() error { - return nil -} - -func (d *ZKDeploy) Restart() error { - return nil -} - -func (d *ZKDeploy) Check(timeout int) error { - return nil -} diff --git a/service/clickhouse/clickhouse_service_test.go b/service/clickhouse/clickhouse_service_test.go deleted file mode 100644 index 060934d6..00000000 --- a/service/clickhouse/clickhouse_service_test.go +++ /dev/null @@ -1,70 +0,0 @@ -package clickhouse - -import ( - "testing" - - "github.com/housepower/ckman/log" - "github.com/housepower/ckman/model" - "github.com/stretchr/testify/assert" -) - -func TestGetReplicaZkPath(t *testing.T) { - log.InitLoggerConsole() - conf := &model.CKManClickHouseConfig{ - Hosts: []string{"192.168.101.40", "192.168.101.41", "192.168.101.42"}, - Port: 9000, - User: "default", - Password: "", - Cluster: "test", - Shards: []model.CkShard{ - { - []model.CkReplica{ - { - Ip: "192.168.101.40", - }, - { - Ip: "192.168.101.41", - }, - }, - }, - { - []model.CkReplica{ - { - Ip: "192.168.101.42", - }, - }, - }, - }, - } - err := GetReplicaZkPath(conf) - assert.Nil(t, err) - log.Logger.Infof("paths: %v", conf.ZooPath) -} - -// func TestPaddingkeys(t *testing.T) { -// log.InitLoggerConsole() -// keys := []model.RebalanceShardingkey{ -// { -// Database: "default", -// Table: "prom_metric", -// ShardingKey: "__series_id", -// }, -// } - -// conf := model.CKManClickHouseConfig{ -// Cluster: "abc", -// Port: 19000, -// IsReplica: true, -// Hosts: []string{"192.168.110.6", "192.168.110.8"}, -// User: "default", -// Password: "123456", -// } - -// svc := NewCkService(&conf) -// err := svc.InitCkService() -// assert.Nil(t, err) - -// keys, err = paddingKeys(keys, svc, false) -// assert.Nil(t, err) -// assert.Equal(t, "dist_prom_metric", keys[0].DistTable) -// } diff --git a/service/clickhouse/hdfs_test.go b/service/clickhouse/hdfs_test.go deleted file mode 100644 index 52e7a3b1..00000000 --- a/service/clickhouse/hdfs_test.go +++ /dev/null @@ -1,19 +0,0 @@ -package clickhouse_test - -import ( - _ "github.com/ClickHouse/clickhouse-go" -) - -// func TestHDFS(t *testing.T) { -// ops := hdfs.ClientOptions{ -// Addresses: []string{"sea.hub:8020"}, -// User: "hdfs", -// } -// hc, err := hdfs.NewClient(ops) -// assert.Nil(t, err) -// entry, err := hc.ReadDir("/") -// assert.Nil(t, err) -// for _, e := range entry { -// fmt.Println(e.Mode(), e.Name(), e.Size()) -// } -// } diff --git a/service/clickhouse/s3_test.go b/service/clickhouse/s3_test.go deleted file mode 100644 index 5da719df..00000000 --- a/service/clickhouse/s3_test.go +++ /dev/null @@ -1,38 +0,0 @@ -package clickhouse_test - -// func TestS3(t *testing.T) { -// sc, err := session.NewSession(&aws.Config{ -// Credentials: credentials.NewStaticCredentials("KZOqVTra982w51MK", "7Zsdaywu7i5C2AyvLkbupSyVlIzP8qJ0", ""), -// Endpoint: aws.String("http://192.168.110.8:49000"), -// Region: aws.String("zh-west-1"), -// DisableSSL: aws.Bool(true), -// S3ForcePathStyle: aws.Bool(true), //virtual-host style方式,不要修改 -// }) -// assert.Nil(t, err) -// svc := s3.New(sc) - -// //查看bucket -// results, err := svc.ListBuckets(nil) -// assert.Nil(t, err) -// for _, bucket := range results.Buckets { -// fmt.Printf("bucket:[%s] created on %s\n", -// aws.StringValue(bucket.Name), aws.TimeValue(bucket.CreationDate)) -// } - -// params := &s3.ListObjectsInput{ -// Bucket: aws.String("ckman.backup"), -// } -// resp, err := svc.ListObjects(params) -// assert.Nil(t, err) -// for _, item := range resp.Contents { -// name := path.Base(*item.Key) -// dir := path.Dir(*item.Key) -// fmt.Printf("name: %v, dir: %v\n", name, dir) -// slot := strings.Split(name, "_")[3] //shard_%d_host_slot.suffix -// idx := strings.Index(slot, ".") -// slot = slot[:idx] -// slotTime, err := time.Parse("20060102150405", slot) -// assert.Nil(t, err) -// fmt.Println(slotTime) -// } -// } diff --git a/service/clickhouse/schema_test.go b/service/clickhouse/schema_test.go deleted file mode 100644 index 66c999a0..00000000 --- a/service/clickhouse/schema_test.go +++ /dev/null @@ -1,10 +0,0 @@ -package clickhouse - -// func TestGetLogicSchema(t *testing.T) { -// log.InitLoggerConsole() -// db, err := common.ConnectClickHouse("192.168.21.73", 9000, "default", "ck", "123456") -// assert.Nil(t, err) -// sqls, err := GetLogicSchema(db, "bench", "shanghai", true) -// assert.Nil(t, err) -// fmt.Printf("sqls:%#v\n", sqls) -// } diff --git a/service/runner/handle.go b/service/runner/handle.go index eb69b470..805d1f08 100644 --- a/service/runner/handle.go +++ b/service/runner/handle.go @@ -34,7 +34,6 @@ func UnmarshalConfig(config interface{}, v interface{}) error { case *deploy.CKDeploy: repository.DecodePasswd(v.Conf) case *model.ArchiveTableReq: - case *deploy.ZKDeploy: } return nil }