From 2c8ce3bb2d27f8980636092ab0af2085bb994af5 Mon Sep 17 00:00:00 2001 From: Michael Russell Date: Fri, 15 Jun 2018 17:22:18 +0200 Subject: [PATCH 1/4] Add test for upgrading from previous version of oss to current --- .kitchen.yml | 10 ++++--- tasks/elasticsearch-config.yml | 26 ++++++++++++++++--- .../helpers/serverspec/oss_upgrade_spec.rb | 9 +++++++ test/integration/oss-upgrade.yml | 21 +++++++++++++++ test/integration/oss-upgrade/oss-upgrade.yml | 2 ++ .../oss-upgrade/serverspec/default_spec.rb | 7 +++++ test/matrix.yml | 1 + 7 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 test/integration/helpers/serverspec/oss_upgrade_spec.rb create mode 100644 test/integration/oss-upgrade.yml create mode 100644 test/integration/oss-upgrade/oss-upgrade.yml create mode 100644 test/integration/oss-upgrade/serverspec/default_spec.rb diff --git a/.kitchen.yml b/.kitchen.yml index a67fcd4f..5087feff 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -41,7 +41,6 @@ platforms: use_sudo: false volume: - <%=ENV['ES_XPACK_LICENSE_FILE']%>:/tmp/license.json - - /etc/elasticsearch - name: ubuntu-16.04 driver_config: image: dliappis/ubuntu-devopsci:16.04 @@ -55,7 +54,6 @@ platforms: use_sudo: false volume: - <%=ENV['ES_XPACK_LICENSE_FILE']%>:/tmp/license.json - - /etc/elasticsearch run_command: "/sbin/init" - name: debian-8 driver_config: @@ -71,7 +69,6 @@ platforms: - pip uninstall -y ansible volume: - <%=ENV['ES_XPACK_LICENSE_FILE']%>:/tmp/license.json - - /etc/elasticsearch use_sudo: false run_command: "/sbin/init" - name: centos-7 @@ -88,7 +85,6 @@ platforms: - pip install jmespath volume: - <%=ENV['ES_XPACK_LICENSE_FILE']%>:/tmp/license.json - - /etc/elasticsearch run_command: "/usr/sbin/init" privileged: true use_sudo: false @@ -133,3 +129,9 @@ suites: provisioner: playbook: test/integration/issue-test.yml idempotency_test: false + - name: oss-upgrade + run_list: + attributes: + provisioner: + playbook: test/integration/oss-upgrade.yml + idempotency_test: false diff --git a/tasks/elasticsearch-config.yml b/tasks/elasticsearch-config.yml index 987de718..57e68265 100644 --- a/tasks/elasticsearch-config.yml +++ b/tasks/elasticsearch-config.yml @@ -86,9 +86,29 @@ content: '' when: ansible_os_family == 'RedHat' -- name: Delete Default Sysconfig File - become: yes - file: dest="{{ sysd_script }}" state=absent +- name: Check if default systemd file exists + stat: + path: "{{ sysd_script }}" + register: sysd_stat_result + +- name: Remove if it is a normal file + file: + path: "{{ sysd_script }}" + state: absent + when: not sysd_stat_result.stat.islnk + +- name: Create a symbolic link to the default systemd location to the first instance running on this host + become: yes + file: + state: link + src: "{{ instance_sysd_script }}" + path: "{{ sysd_script }}" + when: + - use_system_d + - not sysd_stat_result.stat.islnk + notify: + - reload systemd configuration + - restart elasticsearch - name: Delete Default Configuration File become: yes diff --git a/test/integration/helpers/serverspec/oss_upgrade_spec.rb b/test/integration/helpers/serverspec/oss_upgrade_spec.rb new file mode 100644 index 00000000..db0ea059 --- /dev/null +++ b/test/integration/helpers/serverspec/oss_upgrade_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' + +shared_examples 'oss_upgrade::init' do |vars| + describe 'version check' do + it 'should be reported as version '+vars['es_version'] do + expect(curl_json('http://localhost:9200')['version']['number']).to eq(vars['es_version']) + end + end +end diff --git a/test/integration/oss-upgrade.yml b/test/integration/oss-upgrade.yml new file mode 100644 index 00000000..cc3f5301 --- /dev/null +++ b/test/integration/oss-upgrade.yml @@ -0,0 +1,21 @@ +--- +- name: Standard test for single node setup. Tests idempotence. + hosts: localhost + tasks: + - include: elasticsearch/test/integration/debug.yml + roles: + - { role: elasticsearch, es_instance_name: "node1" } + vars: + es_version: "{{ '6.2.4' if es_major_version == '6.x' else '5.6.9' }}" # This is set to an older version than the current default to force an upgrade + es_enable_xpack: false + es_heap_size: "1g" + +- name: Standard test for single node setup. Tests idempotence. + hosts: localhost + tasks: + - include: elasticsearch/test/integration/debug.yml + roles: + - { role: elasticsearch, es_instance_name: "node1" } + vars: + es_enable_xpack: false + es_heap_size: "1g" diff --git a/test/integration/oss-upgrade/oss-upgrade.yml b/test/integration/oss-upgrade/oss-upgrade.yml new file mode 100644 index 00000000..a3c37e19 --- /dev/null +++ b/test/integration/oss-upgrade/oss-upgrade.yml @@ -0,0 +1,2 @@ +--- +- host: test-kitchen diff --git a/test/integration/oss-upgrade/serverspec/default_spec.rb b/test/integration/oss-upgrade/serverspec/default_spec.rb new file mode 100644 index 00000000..ee360e74 --- /dev/null +++ b/test/integration/oss-upgrade/serverspec/default_spec.rb @@ -0,0 +1,7 @@ +require 'oss_upgrade_spec' +require 'json' +vars = JSON.parse(File.read('/tmp/vars.json')) + +describe 'oss upgrade Tests' do + include_examples 'oss_upgrade::init', vars +end diff --git a/test/matrix.yml b/test/matrix.yml index 201ace6f..56740704 100644 --- a/test/matrix.yml +++ b/test/matrix.yml @@ -14,3 +14,4 @@ TEST_TYPE: - xpack - xpack-standard - issue-test + - oss-upgrade From 23e336833a762517fb2d4e1b4c89431e2f25889c Mon Sep 17 00:00:00 2001 From: Michael Russell Date: Fri, 15 Jun 2018 17:37:53 +0200 Subject: [PATCH 2/4] This file should now be a symbolic link, temporarily removing to let the other tests run --- test/integration/helpers/serverspec/standard_spec.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/integration/helpers/serverspec/standard_spec.rb b/test/integration/helpers/serverspec/standard_spec.rb index 5a01cd4c..1fd6c11d 100644 --- a/test/integration/helpers/serverspec/standard_spec.rb +++ b/test/integration/helpers/serverspec/standard_spec.rb @@ -72,10 +72,6 @@ end end - describe file('/usr/lib/systemd/system/elasticsearch.service') do - it { should_not exist } - end - describe file('/etc/elasticsearch/elasticsearch.yml') do it { should_not exist } end From d451d277239a75c71841a6ff233763c34e5b360b Mon Sep 17 00:00:00 2001 From: Michael Russell Date: Mon, 18 Jun 2018 07:37:51 +0200 Subject: [PATCH 3/4] Only symlink systemd file for systemd systems --- tasks/elasticsearch-config.yml | 47 ++++++++++--------- .../helpers/serverspec/config_spec.rb | 4 -- .../helpers/serverspec/multi_spec.rb | 17 ------- .../helpers/serverspec/package_spec.rb | 4 -- .../helpers/serverspec/xpack_spec.rb | 4 -- .../helpers/serverspec/xpack_standard_spec.rb | 4 -- 6 files changed, 24 insertions(+), 56 deletions(-) diff --git a/tasks/elasticsearch-config.yml b/tasks/elasticsearch-config.yml index 57e68265..d7bb095e 100644 --- a/tasks/elasticsearch-config.yml +++ b/tasks/elasticsearch-config.yml @@ -86,29 +86,30 @@ content: '' when: ansible_os_family == 'RedHat' -- name: Check if default systemd file exists - stat: - path: "{{ sysd_script }}" - register: sysd_stat_result - -- name: Remove if it is a normal file - file: - path: "{{ sysd_script }}" - state: absent - when: not sysd_stat_result.stat.islnk - -- name: Create a symbolic link to the default systemd location to the first instance running on this host - become: yes - file: - state: link - src: "{{ instance_sysd_script }}" - path: "{{ sysd_script }}" - when: - - use_system_d - - not sysd_stat_result.stat.islnk - notify: - - reload systemd configuration - - restart elasticsearch +- name: Symlink default systemd service to first instance of elasticsearch + when: use_system_d + block: + - name: Check if default systemd file exists + stat: + path: "{{ sysd_script }}" + register: sysd_stat_result + + - name: Remove if it is a normal file + file: + path: "{{ sysd_script }}" + state: absent + when: not sysd_stat_result.stat.islnk + + - name: Create a symbolic link to the default systemd location to the first instance running on this host + become: yes + file: + state: link + src: "{{ instance_sysd_script }}" + path: "{{ sysd_script }}" + when: not sysd_stat_result.stat.islnk + notify: + - reload systemd configuration + - restart elasticsearch - name: Delete Default Configuration File become: yes diff --git a/test/integration/helpers/serverspec/config_spec.rb b/test/integration/helpers/serverspec/config_spec.rb index 933dc5ff..d84a280e 100644 --- a/test/integration/helpers/serverspec/config_spec.rb +++ b/test/integration/helpers/serverspec/config_spec.rb @@ -125,10 +125,6 @@ end end - describe file('/usr/lib/systemd/system/elasticsearch.service') do - it { should_not exist } - end - describe file('/etc/elasticsearch/elasticsearch.yml') do it { should_not exist } end diff --git a/test/integration/helpers/serverspec/multi_spec.rb b/test/integration/helpers/serverspec/multi_spec.rb index b3ec77a8..da6daf0a 100644 --- a/test/integration/helpers/serverspec/multi_spec.rb +++ b/test/integration/helpers/serverspec/multi_spec.rb @@ -212,10 +212,6 @@ end end - describe file('/usr/lib/systemd/system/elasticsearch.service') do - it { should_not exist } - end - describe file('/etc/elasticsearch/elasticsearch.yml') do it { should_not exist } end @@ -223,18 +219,5 @@ describe file('/etc/elasticsearch/logging.yml') do it { should_not exist } end - - - #Test server spec file has been created and modified - currently not possible as not copied for debian 8 - #describe file('/usr/lib/systemd/system/master_elasticsearch.service') do - # it { should be_file } - # it { should contain 'LimitMEMLOCK=infinity' } - #end - - #describe file('/usr/lib/systemd/system/node1_elasticsearch.service') do - # it { should be_file } - # it { should_not contain 'LimitMEMLOCK=infinity' } - #end - end diff --git a/test/integration/helpers/serverspec/package_spec.rb b/test/integration/helpers/serverspec/package_spec.rb index ab37b0d9..788cd93a 100644 --- a/test/integration/helpers/serverspec/package_spec.rb +++ b/test/integration/helpers/serverspec/package_spec.rb @@ -100,10 +100,6 @@ end end - describe file('/usr/lib/systemd/system/elasticsearch.service') do - it { should_not exist } - end - describe file('/etc/elasticsearch/elasticsearch.yml') do it { should_not exist } end diff --git a/test/integration/helpers/serverspec/xpack_spec.rb b/test/integration/helpers/serverspec/xpack_spec.rb index aacf9495..d3548acb 100644 --- a/test/integration/helpers/serverspec/xpack_spec.rb +++ b/test/integration/helpers/serverspec/xpack_spec.rb @@ -68,10 +68,6 @@ end end - describe file('/usr/lib/systemd/system/elasticsearch.service') do - it { should_not exist } - end - describe file('/etc/elasticsearch/elasticsearch.yml') do it { should_not exist } end diff --git a/test/integration/helpers/serverspec/xpack_standard_spec.rb b/test/integration/helpers/serverspec/xpack_standard_spec.rb index c6d046a8..9c35ae5e 100644 --- a/test/integration/helpers/serverspec/xpack_standard_spec.rb +++ b/test/integration/helpers/serverspec/xpack_standard_spec.rb @@ -69,10 +69,6 @@ end end - describe file('/usr/lib/systemd/system/elasticsearch.service') do - it { should_not exist } - end - describe file('/etc/elasticsearch/elasticsearch.yml') do it { should_not exist } end From 6d6fc3a7cbeae76e9376d1f651cf1dbcd9db05b9 Mon Sep 17 00:00:00 2001 From: Michael Russell Date: Mon, 18 Jun 2018 12:01:45 +0200 Subject: [PATCH 4/4] Gracefully remove default elasticsearch package when upgrading to the oss version --- tasks/elasticsearch-Debian.yml | 25 +++++++++++++++++++++++++ tasks/elasticsearch-RedHat.yml | 7 +++++++ 2 files changed, 32 insertions(+) diff --git a/tasks/elasticsearch-Debian.yml b/tasks/elasticsearch-Debian.yml index ff75a0d8..eec8be81 100644 --- a/tasks/elasticsearch-Debian.yml +++ b/tasks/elasticsearch-Debian.yml @@ -25,6 +25,31 @@ - { repo: "{{ es_apt_url }}", state: "present" } when: es_use_repository + +- name: Gracefully stop and remove elasticsearch if we are switching to the oss version + when: + - es_package_name == 'elasticsearch-oss' + block: + - name: Check if the elasticsearch package is installed + shell: dpkg-query -W -f'${Status}' elasticsearch + register: elasticsearch_package + failed_when: False + changed_when: False + + - name: stop elasticsearch + become: yes + service: + name: '{{ instance_init_script | basename }}' + state: stopped + when: elasticsearch_package.stdout == 'install ok installed' + + - name: Debian - Remove elasticsearch package if we are installing the oss package + become: yes + apt: + name: 'elasticsearch' + state: absent + when: elasticsearch_package.stdout == 'install ok installed' + - name: Debian - Ensure elasticsearch is installed become: yes apt: diff --git a/tasks/elasticsearch-RedHat.yml b/tasks/elasticsearch-RedHat.yml index 990bf597..caca6f45 100644 --- a/tasks/elasticsearch-RedHat.yml +++ b/tasks/elasticsearch-RedHat.yml @@ -13,6 +13,13 @@ include: elasticsearch-RedHat-version-lock.yml when: es_version_lock +- name: RedHat - Remove non oss package if the old elasticsearch package is installed + become: yes + yum: + name: 'elasticsearch' + state: 'absent' + when: es_package_name == 'elasticsearch-oss' + - name: RedHat - Install Elasticsearch become: yes yum: