From a149328ae82fb3828201e047b1982fdd254354f1 Mon Sep 17 00:00:00 2001 From: Dale McDiarmid Date: Sat, 23 Jul 2016 16:41:37 +0100 Subject: [PATCH] Test fixes + ensuring node is started for templates --- handlers/shield/elasticsearch-shield-native.yml | 4 ++++ tasks/elasticsearch-templates.yml | 7 +++++-- tasks/xpack/elasticsearch-shield-file.yml | 14 ++++++++++---- tasks/xpack/elasticsearch-shield.yml | 9 ++++----- .../config-2x/serverspec/default_spec.rb | 2 +- .../integration/helpers/serverspec/package_spec.rb | 5 ++--- .../multi-2x/serverspec/default_spec.rb | 2 +- .../package-2x/serverspec/default_spec.rb | 2 +- .../standard-2x/serverspec/default_spec.rb | 2 +- test/integration/xpack.yml | 2 +- 10 files changed, 30 insertions(+), 19 deletions(-) diff --git a/handlers/shield/elasticsearch-shield-native.yml b/handlers/shield/elasticsearch-shield-native.yml index a8f0e0f..5632bd8 100644 --- a/handlers/shield/elasticsearch-shield-native.yml +++ b/handlers/shield/elasticsearch-shield-native.yml @@ -1,4 +1,8 @@ --- + +- name: Ensure elasticsearch is started + service: name={{instance_init_script | basename}} state=started enabled=yes + - name: Wait for elasticsearch to startup wait_for: port={{es_api_port}} delay=10 diff --git a/tasks/elasticsearch-templates.yml b/tasks/elasticsearch-templates.yml index 923b699..8d5aaf0 100644 --- a/tasks/elasticsearch-templates.yml +++ b/tasks/elasticsearch-templates.yml @@ -12,13 +12,16 @@ with_fileglob: - "{{ es_templates_fileglob }}" +- name: Ensure elasticsearch is started + service: name={{instance_init_script | basename}} state=started enabled=yes + - name: Wait for elasticsearch to startup wait_for: port={{es_api_port}} delay=10 -- name: Get template files +- name: Get template files shell: find . -maxdepth 1 -type f | sed "s#\./##" | sed "s/.json//" chdir=/etc/elasticsearch/templates register: resultstemplate - name: Install template(s) command: "curl -sL -XPUT http://{{es_api_host}}:{{es_api_port}}/_template/{{item}} -d @/etc/elasticsearch/templates/{{item}}.json" - with_items: "{{ resultstemplate.stdout_lines }}" + with_items: "{{ resultstemplate.stdout_lines }}" \ No newline at end of file diff --git a/tasks/xpack/elasticsearch-shield-file.yml b/tasks/xpack/elasticsearch-shield-file.yml index 4a266cc..932a2a9 100644 --- a/tasks/xpack/elasticsearch-shield-file.yml +++ b/tasks/xpack/elasticsearch-shield-file.yml @@ -10,8 +10,9 @@ shell: cat {{conf_dir}}/shield/users | awk -F':' '{print $1}' register: current_file_users when: manage_file_users + changed_when: False -- set_fact: users_to_remove={{ current_file_users.stdout_lines | difference ( es_users.file.keys() ) }} +- set_fact: users_to_remove={{ current_file_users.stdout_lines | difference (es_users.file.keys()) }} when: manage_file_users #Remove users @@ -25,12 +26,15 @@ ES_HOME: "{{es_home}}" +- set_fact: users_to_add={{ es_users.file.keys() | difference (current_file_users.stdout_lines) }} + when: manage_file_users + #Add users - name: Add Users command: > - {{es_home}}/bin/shield/esusers useradd {{item.key}} -p {{item.value.password}} - with_dict: "{{es_users.file}}" - when: manage_file_users and es_users.file.keys() | length > 0 + {{es_home}}/bin/shield/esusers useradd {{item}} -p {{es_users.file[item].password}} + with_items: "{{users_to_add}}" + when: manage_file_users and users_to_add | length > 0 environment: CONF_DIR: "{{ conf_dir }}" ES_HOME: "{{es_home}}" @@ -41,6 +45,8 @@ {{es_home}}/bin/shield/esusers passwd {{item.key}} -p {{item.value.password}} with_dict: "{{es_users.file}}" when: manage_file_users and es_users.file.keys() | length > 0 + #Currently no easy way to figure out if the password has changed or to know what it currently is so we can skip. + changed_when: False environment: CONF_DIR: "{{ conf_dir }}" ES_HOME: "{{es_home}}" diff --git a/tasks/xpack/elasticsearch-shield.yml b/tasks/xpack/elasticsearch-shield.yml index 455fa2f..7864534 100644 --- a/tasks/xpack/elasticsearch-shield.yml +++ b/tasks/xpack/elasticsearch-shield.yml @@ -26,11 +26,6 @@ #TODO: 1. Skip users with no password defined or error 2. Passwords | length > 6 - -#Ensure shield conf directory is created -- name: Ensure shield conf directory exists - file: path={{ conf_dir }}/shield state=directory owner={{ es_user }} group={{ es_group }} - #-----------------------------FILE BASED REALM---------------------------------------- - include: elasticsearch-shield-file.yml @@ -43,3 +38,7 @@ when: (es_users is defined and es_users.native is defined) or (es_roles is defined and es_roles.native is defined) +#Ensure shield conf directory is created +- name: Ensure shield conf directory exists + file: path={{ conf_dir }}/shield state=directory owner={{ es_user }} group={{ es_group }} + changed_when: False diff --git a/test/integration/config-2x/serverspec/default_spec.rb b/test/integration/config-2x/serverspec/default_spec.rb index 377fb3b..f416eed 100644 --- a/test/integration/config-2x/serverspec/default_spec.rb +++ b/test/integration/config-2x/serverspec/default_spec.rb @@ -1,6 +1,6 @@ require 'config_spec' describe 'Config Tests v 2.x' do - include_examples 'config::init', "2.2.0" + include_examples 'config::init', "2.3.4" end diff --git a/test/integration/helpers/serverspec/package_spec.rb b/test/integration/helpers/serverspec/package_spec.rb index 2d2dbbb..897135e 100644 --- a/test/integration/helpers/serverspec/package_spec.rb +++ b/test/integration/helpers/serverspec/package_spec.rb @@ -16,7 +16,6 @@ shared_examples 'package::init' do |es_version,plugins| describe file('/etc/elasticsearch/node1/elasticsearch.yml') do it { should be_file } - it { should contain 'path.plugins: /usr/share/elasticsearch/plugins/node1' } it { should contain 'http.port: 9200' } it { should contain 'transport.tcp.port: 9300' } it { should contain 'discovery.zen.ping.unicast.hosts: localhost:9300' } @@ -66,14 +65,14 @@ shared_examples 'package::init' do |es_version,plugins| end end - describe file('/usr/share/elasticsearch/plugins/node1') do + describe file('/usr/share/elasticsearch/plugins') do it { should be_directory } it { should be_owned_by 'elasticsearch' } end for plugin in plugins - describe file('/usr/share/elasticsearch/plugins/node1/'+plugin) do + describe file('/usr/share/elasticsearch/plugins/'+plugin) do it { should be_directory } it { should be_owned_by 'elasticsearch' } end diff --git a/test/integration/multi-2x/serverspec/default_spec.rb b/test/integration/multi-2x/serverspec/default_spec.rb index 17bb9c1..6aaae25 100644 --- a/test/integration/multi-2x/serverspec/default_spec.rb +++ b/test/integration/multi-2x/serverspec/default_spec.rb @@ -2,7 +2,7 @@ require 'multi_spec' describe 'Multi Tests v 2.x' do - include_examples 'multi::init', "2.2.0", ["kopf","license","marvel-agent"] + include_examples 'multi::init', "2.3.4", ["kopf","license","marvel-agent"] end diff --git a/test/integration/package-2x/serverspec/default_spec.rb b/test/integration/package-2x/serverspec/default_spec.rb index bc884cc..1a4aade 100644 --- a/test/integration/package-2x/serverspec/default_spec.rb +++ b/test/integration/package-2x/serverspec/default_spec.rb @@ -2,5 +2,5 @@ require 'package_spec' describe 'Package Tests v 2.x' do - include_examples 'package::init', "2.2.0", ["kopf","license","marvel-agent"] + include_examples 'package::init', "2.3.4", ["kopf","license","marvel-agent"] end \ No newline at end of file diff --git a/test/integration/standard-2x/serverspec/default_spec.rb b/test/integration/standard-2x/serverspec/default_spec.rb index 8f45e24..86033b3 100644 --- a/test/integration/standard-2x/serverspec/default_spec.rb +++ b/test/integration/standard-2x/serverspec/default_spec.rb @@ -2,7 +2,7 @@ require 'standard_spec' describe 'Standard Tests v 2.x' do - include_examples 'standard::init', "2.2.0" + include_examples 'standard::init', "2.3.4" end diff --git a/test/integration/xpack.yml b/test/integration/xpack.yml index 2c6dbcb..ac502bc 100644 --- a/test/integration/xpack.yml +++ b/test/integration/xpack.yml @@ -1,6 +1,6 @@ --- - name: Elasticsearch Xpack tests - hosts: localhost + hosts: localhostpost roles: - { role: elasticsearch, es_config: { "http.port": 9200, "transport.tcp.port":9300, discovery.zen.ping.unicast.hosts: "localhost:9300" }, es_instance_name: "shield_node" } vars: