Merge remote-tracking branch 'adrienverge/COUCHDB-3119'
* adrienverge/COUCHDB-3119:
add_node: Don't fail if node name != "couchdb" or "node1"
diff --git a/README.md b/README.md
index cde7aae..a6c6d18 100644
--- a/README.md
+++ b/README.md
@@ -88,7 +88,8 @@
"username":"username",
"password":"password",
"host":"192.168.1.100",
- "port": 5984
+ ["port": 5984],
+ "name": "node1" // as in “node1@hostname”, same as in vm.args
}
```
diff --git a/src/setup.erl b/src/setup.erl
index e58c32d..acbeb2d 100644
--- a/src/setup.erl
+++ b/src/setup.erl
@@ -209,13 +209,14 @@
Host = proplists:get_value(host, Options),
Port = get_port(proplists:get_value(port, Options, 5984)),
+ Name = proplists:get_value(name, Options, get_default_name(Port)),
Url = binary_to_list(<<"http://", Host/binary, ":", Port/binary, "/_cluster_setup">>),
case ibrowse:send_req(Url, Headers, post, Body, RequestOptions) of
{ok, "201", _, _} ->
% when done, PUT :5986/nodes/nodeB
- create_node_doc(Host, Port);
+ create_node_doc(Host, Name);
Else ->
couch_log:notice("send_req: ~p~n", [Else]),
Else
@@ -228,16 +229,15 @@
get_port(Port) when is_binary(Port) ->
Port.
-create_node_doc(Host, Port) ->
+create_node_doc(Host, Name) ->
{ok, Db} = couch_db:open_int(<<"_nodes">>, []),
- Name = get_name(Port),
Doc = {[{<<"_id">>, <<Name/binary, "@", Host/binary>>}]},
Options = [],
CouchDoc = couch_doc:from_json_obj(Doc),
couch_db:update_doc(Db, CouchDoc, Options).
-get_name(Port) ->
+get_default_name(Port) ->
case Port of
% shortcut for easier development
<<"15984">> ->
diff --git a/src/setup_httpd.erl b/src/setup_httpd.erl
index 73fa4ee..73ce147 100644
--- a/src/setup_httpd.erl
+++ b/src/setup_httpd.erl
@@ -88,7 +88,8 @@
{username, <<"username">>},
{password, <<"password">>},
{host, <<"host">>},
- {port, <<"port">>}
+ {port, <<"port">>},
+ {name, <<"name">>}
], Setup),
case setup:add_node(Options) of
{error, cluster_not_enabled} ->
diff --git a/test/t-frontend-setup.sh b/test/t-frontend-setup.sh
index 74743bb..52056a3 100755
--- a/test/t-frontend-setup.sh
+++ b/test/t-frontend-setup.sh
@@ -22,7 +22,7 @@
curl a:b@127.0.0.1:15984/_cluster_setup -d '{"action":"enable_cluster","remote_node":"127.0.0.1","port":"25984","remote_current_user":"a","remote_current_password":"b","username":"foo","password":"baz","bind_address":"0.0.0.0","node_count":2}' $HEADERS
# Add node B on node A
-curl a:b@127.0.0.1:15984/_cluster_setup -d '{"action":"add_node","username":"foo","password":"baz","host":"127.0.0.1","port":25984}' $HEADERS
+curl a:b@127.0.0.1:15984/_cluster_setup -d '{"action":"add_node","username":"foo","password":"baz","host":"127.0.0.1","port":25984,"name":"node2"}' $HEADERS
# Show cluster state:
curl a:b@127.0.0.1:15986/_nodes/_all_docs
diff --git a/test/t.sh b/test/t.sh
index c569caa..6bd74cd 100755
--- a/test/t.sh
+++ b/test/t.sh
@@ -22,7 +22,7 @@
curl a:b@127.0.0.1:25984/_cluster_setup -d '{"action":"enable_cluster","username":"foo","password":"baz","bind_address":"0.0.0.0","node_count":2}' $HEADERS
# Add node B on node A
-curl a:b@127.0.0.1:15984/_cluster_setup -d '{"action":"add_node","username":"foo","password":"baz","host":"127.0.0.1","port":25984}' $HEADERS
+curl a:b@127.0.0.1:15984/_cluster_setup -d '{"action":"add_node","username":"foo","password":"baz","host":"127.0.0.1","port":25984,"name":"node2"}' $HEADERS
# Show cluster state:
curl a:b@127.0.0.1:15986/_nodes/_all_docs