[error]
root@taishan200-2280-2s64p-256g--a9 /c/compass-ci/container/register-accounts# ./start
register-accounts
register-accounts
/c/compass-ci/container/register-accounts # ./register-accounts
awk: /etc/compass-ci/defaults/*.yaml: No such file or directory
"option: {\"my_email\"=>\"\", \"my_name\"=>\"\", \"lab\"=>\"\"}"
Traceback (most recent call last):
10: from ./register-accounts:8:in `<main>'
9: from ./register-accounts:8:in `require_relative'
8: from /c/compass-ci/sbin/build-my-info.rb:57:in `<top (required)>'
7: from /c/compass-ci/sbin/build-my-info.rb:48:in `build_my_info'
6: from /c/compass-ci/lib/build_my_info_client.rb:30:in `search_my_info'
5: from /c/compass-ci/lib/es_query.rb:58:in `query_by_id'
4: from /usr/lib/ruby/gems/2.7.0/gems/elasticsearch-api-7.10.1/lib/elasticsearch/api/actions/search.rb:103:in `search'
3: from /usr/lib/ruby/gems/2.7.0/gems/elasticsearch-transport-7.10.1/lib/elasticsearch/transport/client.rb:182:in `perform_request'
2: from /usr/lib/ruby/gems/2.7.0/gems/elasticsearch-transport-7.10.1/lib/elasticsearch/transport/transport/http/faraday.rb:37:in `perform_request'
1: from /usr/lib/ruby/gems/2.7.0/gems/elasticsearch-transport-7.10.1/lib/elasticsearch/transport/transport/base.rb:347:in `perform_request'
/usr/lib/ruby/gems/2.7.0/gems/elasticsearch-transport-7.10.1/lib/elasticsearch/transport/transport/base.rb:218:in `__raise_transport_error': [400] {"error":{"root_cause":[{"type":"query_shard_exception","reason":"failed to create query: {\\n \\"bool\\" : {\\n \\"must\\" : [\\n {\\n \\"term\\" : {\\n \\"_id\\" : {\\n \\"value\\" : \\"\\",\\n \\"boost\\" : 1.0\\n }\\n }\\n }\\n ],\\n \\"adjust_pure_negative\\" : true,\\n \\"boost\\" : 1.0\\n }\\n}","index_uuid":"MH_AlDBvTYa9sQhwsESXgQ","index":"accounts"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"accounts","node":"I1usO2axQ9-XZhzcX3oHxw","reason":{"type":"query_shard_exception","reason":"failed to create query: {\\n \\"bool\\" : {\\n \\"must\\" : [\\n {\\n \\"term\\" : {\\n \\"_id\\" : {\\n \\"value\\" : \\"\\",\\n \\"boost\\" : 1.0\\n }\\n }\\n }\\n ],\\n \\"adjust_pure_negative\\" : true,\\n \\"boost\\" : 1.0\\n }\\n}","index_uuid":"MH_AlDBvTYa9sQhwsESXgQ","index":"accounts","caused_by":{"type":"illegal_argument_exception","reason":"Ids can't be empty"}}}]},"status":400} (Elasticsearch::Transport::Transport::Errors::BadRequest)
refer code: /c/compass-ci/sbin/build-my-info.rb:
...
option = {
'my_email' => `git config --global user.email`.chomp,
'my_name' => `git config --global user.name`.chomp,
'lab' => `awk '/^lab:\s/ {print $2; exit}' /etc/compass-ci/defaults/*.yaml`.chomp
}
...
build_my_info(option)
...
[why]
when call build-my-info.rb, we just want call function build_my_info(),
no need to execute option, in caller script already define option values
[how]
use `if $PROGRAM_NAME == __FILE__`,
when sbin/build-my-info.rb is not executed independently but invoked by other files,
avoid to execute some part code.
Signed-off-by: Liu Yinsi <liuyinsi(a)163.com>
---
sbin/build-my-info.rb | 72 ++++++++++++++++++++++---------------------
1 file changed, 37 insertions(+), 35 deletions(-)
diff --git a/sbin/build-my-info.rb b/sbin/build-my-info.rb
index dbe093d..c7a7798 100755
--- a/sbin/build-my-info.rb
+++ b/sbin/build-my-info.rb
@@ -7,49 +7,51 @@ require_relative '../lib/es_client'
require_relative '../lib/build_my_info_client'
require 'optparse'
-option = {
- 'my_email' => `git config --global user.email`.chomp,
- 'my_name' => `git config --global user.name`.chomp,
- 'lab' => `awk '/^lab:\s/ {print $2; exit}' /etc/compass-ci/defaults/*.yaml`.chomp
-}
+def build_my_info(option)
+ build_my_info = BuildMyInfo.new(option['my_email'])
+ info_es = build_my_info.search_my_info
+ info_es.update option
+ info_es['my_token'] = %x(uuidgen).chomp if info_es['my_token'].nil?
-options = OptionParser.new do |opts|
- opts.banner = "Usage: build-my-info [-e email] [-n name] [-l lab] [-t]\n"
+ build_my_info.config_my_info(info_es)
+end
- opts.separator ''
- opts.separator 'options:'
+if $PROGRAM_NAME == __FILE__
+ option = {
+ 'my_email' => `git config --global user.email`.chomp,
+ 'my_name' => `git config --global user.name`.chomp,
+ 'lab' => `awk '/^lab:\s/ {print $2; exit}' /etc/compass-ci/defaults/*.yaml`.chomp
+ }
- opts.on('-e email', 'my_email') do |email|
- option['my_email'] = email
- end
+ options = OptionParser.new do |opts|
+ opts.banner = "Usage: build-my-info [-e email] [-n name] [-l lab] [-t]\n"
- opts.on('-n name', 'my_name') do |name|
- option['my_name'] = name
- end
+ opts.separator ''
+ opts.separator 'options:'
- opts.on('-l lab', 'lab') do |lab|
- option['lab'] = lab
- end
+ opts.on('-e email', 'my_email') do |email|
+ option['my_email'] = email
+ end
- opts.on('-t', 'my_token') do
- option['my_token'] = %x(uuidgen).chomp
- end
+ opts.on('-n name', 'my_name') do |name|
+ option['my_name'] = name
+ end
- opts.on_tail('-h', 'show this message') do
- puts opts
- exit
- end
-end
+ opts.on('-l lab', 'lab') do |lab|
+ option['lab'] = lab
+ end
-options.parse!
+ opts.on('-t', 'my_token') do
+ option['my_token'] = %x(uuidgen).chomp
+ end
-def build_my_info(option)
- build_my_info = BuildMyInfo.new(option['my_email'])
- info_es = build_my_info.search_my_info
- info_es.update option
- info_es['my_token'] = %x(uuidgen).chomp if info_es['my_token'].nil?
+ opts.on_tail('-h', 'show this message') do
+ puts opts
+ exit
+ end
+ end
- build_my_info.config_my_info(info_es)
-end
+ options.parse!
-build_my_info(option)
+ build_my_info(option)
+end
--
2.23.0