diff --git a/README.md b/README.md index 3b1f258e6..13f111dbf 100644 --- a/README.md +++ b/README.md @@ -378,12 +378,12 @@ For testing you can use the certificates in the `fixtures/ca` directory. Let's configure etcd to use this keypair: ```sh -./etcd -name node0 -data-dir node0 -cert-file=./fixtures/ca/server.crt -key-file=./fixtures/ca/server.key.insecure -force-config +./etcd -f -name node0 -data-dir node0 -cert-file=./fixtures/ca/server.crt -key-file=./fixtures/ca/server.key.insecure ``` There are a few new options we're using: -* `-force-config` - forces a new node configuration, even if an existing configuration is found. (WARNING: data loss!) +* `-f` - forces a new node configuration, even if an existing configuration is found. (WARNING: data loss!) * `-cert-file` and `-key-file` specify the location of the cert and key files to be used for for transport layer security between the client and server. You can now test the configuration using HTTPS: @@ -413,7 +413,7 @@ We can also do authentication using CA certs. The clients will provide their cert to the server and the server will check whether the cert is signed by the CA and decide whether to serve the request. ```sh -./etcd -name node0 -data-dir node0 -ca-file=./fixtures/ca/ca.crt -cert-file=./fixtures/ca/server.crt -key-file=./fixtures/ca/server.key.insecure -force-config +./etcd -f -name node0 -data-dir node0 -ca-file=./fixtures/ca/ca.crt -cert-file=./fixtures/ca/server.crt -key-file=./fixtures/ca/server.key.insecure ``` ```-ca-file``` is the path to the CA cert. diff --git a/server/server.go b/server/server.go index 12af34872..28ac842d8 100644 --- a/server/server.go +++ b/server/server.go @@ -162,6 +162,7 @@ func (s *Server) handleFunc(path string, f func(http.ResponseWriter, *http.Reque if err := f(w, req); err != nil { if etcdErr, ok := err.(*etcdErr.Error); ok { log.Debug("Return error: ", (*etcdErr).Error()) + w.Header().Set("Content-Type", "application/json") etcdErr.Write(w) } else { http.Error(w, err.Error(), http.StatusInternalServerError) @@ -262,6 +263,7 @@ func (s *Server) Dispatch(c raft.Command, w http.ResponseWriter, req *http.Reque e, _ := result.(*store.Event) b, _ = json.Marshal(e) + w.Header().Set("Content-Type", "application/json") // etcd index should be the same as the event index // which is also the last modified index of the node w.Header().Add("X-Etcd-Index", fmt.Sprint(e.Index)) diff --git a/server/v2/get_handler.go b/server/v2/get_handler.go index 3e8ddee64..2e9873571 100644 --- a/server/v2/get_handler.go +++ b/server/v2/get_handler.go @@ -68,6 +68,7 @@ func GetHandler(w http.ResponseWriter, req *http.Request, s Server) error { } } + w.Header().Set("Content-Type", "application/json") w.Header().Add("X-Etcd-Index", fmt.Sprint(s.Store().Index())) w.Header().Add("X-Raft-Index", fmt.Sprint(s.CommitIndex())) w.Header().Add("X-Raft-Term", fmt.Sprint(s.Term())) diff --git a/tests/functional/internal_version_test.go b/tests/functional/internal_version_test.go index 52bb69a9d..edc8fc098 100644 --- a/tests/functional/internal_version_test.go +++ b/tests/functional/internal_version_test.go @@ -31,7 +31,7 @@ func TestInternalVersion(t *testing.T) { procAttr := new(os.ProcAttr) procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr} - args := []string{"etcd", "-name=node1", "-force-config", "-data-dir=/tmp/node1", "-peers=" + fakeURL.Host} + args := []string{"etcd", "-name=node1", "-f", "-data-dir=/tmp/node1", "-peers=" + fakeURL.Host} process, err := os.StartProcess(EtcdBinPath, args, procAttr) if err != nil { diff --git a/tests/functional/node1.etcd/conf b/tests/functional/node1.etcd/conf new file mode 100644 index 000000000..d6da4d992 --- /dev/null +++ b/tests/functional/node1.etcd/conf @@ -0,0 +1 @@ +{"commitIndex":43,"peers":[{"name":"node2","connectionString":""},{"name":"node3","connectionString":""},{"name":"node4","connectionString":""},{"name":"node5","connectionString":""},{"name":"node6","connectionString":""},{"name":"node7","connectionString":""},{"name":"node9","connectionString":""},{"name":"node8","connectionString":""}]} \ No newline at end of file diff --git a/tests/functional/node1.etcd/info b/tests/functional/node1.etcd/info new file mode 100644 index 000000000..5d6ce814a --- /dev/null +++ b/tests/functional/node1.etcd/info @@ -0,0 +1 @@ +{"name":"node1","raftURL":"http://127.0.0.1:7001","etcdURL":"http://127.0.0.1:4001","raftListenHost":"127.0.0.1:7001","etcdListenHost":"127.0.0.1:4001","raftTLS":{"CertFile":"","KeyFile":"","CAFile":""},"etcdTLS":{"CertFile":"","KeyFile":"","CAFile":""}} diff --git a/tests/functional/node1.etcd/log b/tests/functional/node1.etcd/log new file mode 100644 index 000000000..8d992569c Binary files /dev/null and b/tests/functional/node1.etcd/log differ diff --git a/tests/functional/remove_node_test.go b/tests/functional/remove_node_test.go index 07263d0b1..55149cc36 100644 --- a/tests/functional/remove_node_test.go +++ b/tests/functional/remove_node_test.go @@ -50,7 +50,7 @@ func TestRemoveNode(t *testing.T) { etcds[2], err = os.StartProcess(EtcdBinPath, argGroup[2], procAttr) } else { // rejoin without log - etcds[2], err = os.StartProcess(EtcdBinPath, append(argGroup[2], "-force-config"), procAttr) + etcds[2], err = os.StartProcess(EtcdBinPath, append(argGroup[2], "-f"), procAttr) } if err != nil { @@ -93,7 +93,7 @@ func TestRemoveNode(t *testing.T) { etcds[2], err = os.StartProcess(EtcdBinPath, append(argGroup[2]), procAttr) } else { // rejoin without log - etcds[2], err = os.StartProcess(EtcdBinPath, append(argGroup[2], "-force-config"), procAttr) + etcds[2], err = os.StartProcess(EtcdBinPath, append(argGroup[2], "-f"), procAttr) } if err != nil { diff --git a/tests/functional/simple_snapshot_test.go b/tests/functional/simple_snapshot_test.go index 4e0cf5b9e..2ca14cdfe 100644 --- a/tests/functional/simple_snapshot_test.go +++ b/tests/functional/simple_snapshot_test.go @@ -16,7 +16,7 @@ func TestSimpleSnapshot(t *testing.T) { procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr} args := []string{"etcd", "-name=node1", "-data-dir=/tmp/node1", "-snapshot=true", "-snapshot-count=500"} - process, err := os.StartProcess(EtcdBinPath, append(args, "-force-config"), procAttr) + process, err := os.StartProcess(EtcdBinPath, append(args, "-f"), procAttr) if err != nil { t.Fatal("start process failed:" + err.Error()) } diff --git a/tests/functional/single_node_recovery_test.go b/tests/functional/single_node_recovery_test.go index 04b197fd4..8acf77e2f 100644 --- a/tests/functional/single_node_recovery_test.go +++ b/tests/functional/single_node_recovery_test.go @@ -15,7 +15,7 @@ func TestSingleNodeRecovery(t *testing.T) { procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr} args := []string{"etcd", "-name=node1", "-data-dir=/tmp/node1"} - process, err := os.StartProcess(EtcdBinPath, append(args, "-force-config"), procAttr) + process, err := os.StartProcess(EtcdBinPath, append(args, "-f"), procAttr) if err != nil { t.Fatal("start process failed:" + err.Error()) return diff --git a/tests/functional/single_node_test.go b/tests/functional/single_node_test.go index a747103b9..eee852d94 100644 --- a/tests/functional/single_node_test.go +++ b/tests/functional/single_node_test.go @@ -12,7 +12,7 @@ import ( func TestSingleNode(t *testing.T) { procAttr := new(os.ProcAttr) procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr} - args := []string{"etcd", "-name=node1", "-force-config", "-data-dir=/tmp/node1"} + args := []string{"etcd", "-name=node1", "-f", "-data-dir=/tmp/node1"} process, err := os.StartProcess(EtcdBinPath, args, procAttr) if err != nil { diff --git a/tests/functional/util.go b/tests/functional/util.go index bf2f1c795..791f5045c 100644 --- a/tests/functional/util.go +++ b/tests/functional/util.go @@ -102,7 +102,7 @@ func CreateCluster(size int, procAttr *os.ProcAttr, ssl bool) ([][]string, []*os for i, _ := range etcds { var err error - etcds[i], err = os.StartProcess(EtcdBinPath, append(argGroup[i], "-force-config"), procAttr) + etcds[i], err = os.StartProcess(EtcdBinPath, append(argGroup[i], "-f"), procAttr) if err != nil { return nil, nil, err } diff --git a/tests/functional/version_check_test.go b/tests/functional/version_check_test.go index fc1f38a4c..84c5cefbf 100644 --- a/tests/functional/version_check_test.go +++ b/tests/functional/version_check_test.go @@ -11,7 +11,7 @@ import ( func TestVersionCheck(t *testing.T) { procAttr := new(os.ProcAttr) procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr} - args := []string{"etcd", "-name=node1", "-force-config", "-data-dir=/tmp/version_check"} + args := []string{"etcd", "-name=node1", "-f", "-data-dir=/tmp/version_check"} process, err := os.StartProcess(EtcdBinPath, args, procAttr) if err != nil {