require nodecount on setup

when setting up a node, require the nodecount from the user. when
setting up a cluster, they will probably know it, if not the ui
other interfaces can count it easily for them. this will remove
the warning for a non matching nodecount for the user, and it
is easy to implement in uis and cli clients (e.g. a wizard for
fauxton or cli client like nmo).

once clusterwide setup lands this gets obviously superfluous.

COUCHDB-2598

This closes COUCHDB-2594
diff --git a/src/setup.erl b/src/setup.erl
index 2118349..4816309 100644
--- a/src/setup.erl
+++ b/src/setup.erl
@@ -24,6 +24,11 @@
 require_admins(_,_) ->
     ok.
 
+require_clustersize(undefined) ->
+    throw({error, "Cluster setup requires node_count to be configured"});
+require_clustersize(_) ->
+    ok.
+
 error_bind_address() ->
     throw({error, "Cluster setup requires bind_addres != 127.0.0.1"}).
 
@@ -83,7 +88,8 @@
         {<<"username">>, couch_util:get_value(username, Options)},
         {<<"password">>, couch_util:get_value(password, Options)},
         {<<"bind_address">>, couch_util:get_value(bind_address, Options)},
-        {<<"port">>, couch_util:get_value(port, Options)}
+        {<<"port">>, couch_util:get_value(port, Options)},
+        {<<"node_count">>, couch_util:get_value(node_count, Options)}
     ]}),
 
     Headers = [
@@ -134,6 +140,10 @@
             config:set("httpd", "bind_address", binary_to_list(NewBindAddress))
     end,
 
+    NodeCount = couch_util:get_value(node_count, Options),
+    ok = require_clustersize(NodeCount),
+    config:set("cluster", "n", integer_to_list(NodeCount)),
+
     Port = proplists:get_value(port, Options),
     case Port of
         undefined ->
@@ -142,7 +152,6 @@
             config:set("httpd", "port", integer_to_list(Port))
     end,
     couch_log:notice("Enable Cluster: ~p~n", [Options]).
-    %cluster_state:set(enabled).
 
 maybe_set_admin(Username, Password) ->
     case couch_auth_cache:get_admin(Username) of
diff --git a/src/setup_httpd.erl b/src/setup_httpd.erl
index f84112b..21e81cd 100644
--- a/src/setup_httpd.erl
+++ b/src/setup_httpd.erl
@@ -58,7 +58,8 @@
         {port, <<"port">>},
         {remote_node, <<"remote_node">>},
         {remote_current_user, <<"remote_current_user">>},
-        {remote_current_password, <<"remote_current_password">>}
+        {remote_current_password, <<"remote_current_password">>},
+        {node_count, <<"node_count">>}
     ], Setup),
     case setup:enable_cluster(Options) of
         {error, cluster_enabled} ->
diff --git a/test/t-frontend-setup.sh b/test/t-frontend-setup.sh
index 1c610b6..74743bb 100755
--- a/test/t-frontend-setup.sh
+++ b/test/t-frontend-setup.sh
@@ -16,10 +16,10 @@
 curl a:b@127.0.0.1:15986/_nodes/_all_docs
 
 # Enable Cluster on node A
-curl a:b@127.0.0.1:15984/_cluster_setup -d '{"action":"enable_cluster","username":"foo","password":"baz","bind_address":"0.0.0.0"}' $HEADERS
+curl a:b@127.0.0.1:15984/_cluster_setup -d '{"action":"enable_cluster","username":"foo","password":"baz","bind_address":"0.0.0.0","node_count":2}' $HEADERS
 
 # Enable Cluster on node B
-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"}' $HEADERS
+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
@@ -57,4 +57,7 @@
 curl a:b@127.0.0.1:25984/_metadata
 curl a:b@127.0.0.1:25984/_global_changes
 
+# Number of nodes is set to 2
+curl a:b@127.0.0.1:25984/_node/node2@127.0.0.1/_config/cluster/n
+
 echo "YAY ALL GOOD"
diff --git a/test/t.sh b/test/t.sh
index 62abb61..c569caa 100755
--- a/test/t.sh
+++ b/test/t.sh
@@ -16,10 +16,10 @@
 curl a:b@127.0.0.1:15986/_nodes/_all_docs
 
 # Enable Cluster on node A
-curl a:b@127.0.0.1:15984/_cluster_setup -d '{"action":"enable_cluster","username":"foo","password":"baz","bind_address":"0.0.0.0"}' $HEADERS
+curl a:b@127.0.0.1:15984/_cluster_setup -d '{"action":"enable_cluster","username":"foo","password":"baz","bind_address":"0.0.0.0","node_count":2}' $HEADERS
 
 # Enable Cluster on node B
-curl a:b@127.0.0.1:25984/_cluster_setup -d '{"action":"enable_cluster","username":"foo","password":"baz","bind_address":"0.0.0.0"}' $HEADERS
+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
@@ -57,4 +57,7 @@
 curl a:b@127.0.0.1:25984/_metadata
 curl a:b@127.0.0.1:25984/_global_changes
 
+# Number of nodes is set to 2
+curl a:b@127.0.0.1:25984/_node/node2@127.0.0.1/_config/cluster/n
+
 echo "YAY ALL GOOD"