diff --git a/elk_metrics_6x/readme.rst b/elk_metrics_6x/README.rst similarity index 93% rename from elk_metrics_6x/readme.rst rename to elk_metrics_6x/README.rst index 76ade69c..2d30d837 100644 --- a/elk_metrics_6x/readme.rst +++ b/elk_metrics_6x/README.rst @@ -25,7 +25,7 @@ OpenStack-Ansible Integration These playbooks can be used as standalone inventory or as an integrated part of an OpenStack-Ansible deployment. For a simple example of standalone inventory, -see ``inventory.example.yml``. +see [test-inventory.yml](tests/inventory/test-inventory.yml). Optional | Load balancer configuration @@ -528,3 +528,36 @@ If everything goes bad, you can clean up with the following command openstack-ansible /opt/openstack-ansible-ops/elk_metrics_6x/site.yml -e 'elk_package_state="absent"' --tags package_install openstack-ansible /opt/openstack-ansible/playbooks/lxc-containers-destroy.yml --limit elk_all + + +Local testing +------------- + +To test these playbooks within a local environment you will need a single server +with at leasts 8GiB of RAM and 40GiB of storage on root. Running an `m1.medium` +(openstack) flavor size is generally enough to get an environment online. + +To run the local functional tests execute the `run-tests.sh` script out of the +tests directory. This will create a 4 node elasaticsearch cluster, 1 kibana node +with an elasticsearch coordination process, and 1 APM node. The beats will be +deployed to the environment as if this was a production installation. + +.. code-block:: bash + + tests/run-tests.sh + + +After the test build is completed the cluster will test it's layout and ensure +processes are functioning normally. Logs for the cluster can be found at +`/tmp/elk-metrics-6x-logs`. + +To rerun the playbooks after a test build, source the `tests/manual-test.rc` +file and follow the onscreen instructions. + +To clean-up a test environment and start from a bare server slate the +`run-cleanup.sh` script can be used. This script is distructive and will purge +all `elk_metrics_6x` related services within the local test environment. + +.. code-block:: bash + + tests/run-cleanup.sh diff --git a/elk_metrics_6x/bootstrap-embedded-ansible.sh b/elk_metrics_6x/bootstrap-embedded-ansible.sh old mode 100644 new mode 100755 diff --git a/elk_metrics_6x/common_task_data_node_hosts.yml b/elk_metrics_6x/common_task_data_node_hosts.yml index b9c5e8cb..10fe3cb3 100644 --- a/elk_metrics_6x/common_task_data_node_hosts.yml +++ b/elk_metrics_6x/common_task_data_node_hosts.yml @@ -1,5 +1,9 @@ --- +- name: Refresh minimal facts + setup: + gather_subset: '!all,!any,network,virtual' + # storage node count is equal to the cluster size - name: Node count fact set_fact: diff --git a/elk_metrics_6x/installElastic.yml b/elk_metrics_6x/installElastic.yml index 39f228d7..c5aeda6e 100644 --- a/elk_metrics_6x/installElastic.yml +++ b/elk_metrics_6x/installElastic.yml @@ -20,6 +20,8 @@ - name: Set memory fact to half set_fact: h_mem: "{{ (ansible_memtotal_mb | int) // 2 }}" + when: + - h_mem is not defined tags: - always diff --git a/elk_metrics_6x/installJournalbeat.yml b/elk_metrics_6x/installJournalbeat.yml index 3d62c129..db71546b 100644 --- a/elk_metrics_6x/installJournalbeat.yml +++ b/elk_metrics_6x/installJournalbeat.yml @@ -73,6 +73,7 @@ retries: 3 delay: 2 with_items: + - gcc - git - libsystemd-dev tags: diff --git a/elk_metrics_6x/installLogstash.yml b/elk_metrics_6x/installLogstash.yml index 0d941d6e..6c228b49 100644 --- a/elk_metrics_6x/installLogstash.yml +++ b/elk_metrics_6x/installLogstash.yml @@ -14,11 +14,21 @@ - include_tasks: common_task_data_node_hosts.yml tags: - always + tasks: - name: Set quarter memory fact set_fact: q_mem: "{{ (ansible_memtotal_mb | int) // 4 }}" + when: + - q_mem is not defined + tags: + - always + + - name: Set processor cores fact + set_fact: q_storage: "{{ ansible_processor_cores }}" + when: + - q_storage is not defined tags: - always diff --git a/elk_metrics_6x/inventory.example.yml b/elk_metrics_6x/inventory.example.yml deleted file mode 100644 index 86fa8a8d..00000000 --- a/elk_metrics_6x/inventory.example.yml +++ /dev/null @@ -1,51 +0,0 @@ ---- - -################################## ALL HOSTS ################################## -all: - hosts: - # Local host - localhost: - ansible_connection: local - -################################## REQUIRED ################################### - logging01: - ansible_host: 172.16.27.100 - ansible_user: root - -############################## OPTIONAL TARGETS ############################### - target1: - ansible_host: 172.16.27.200 - ansible_user: root - - vars: {} - - -################################### GROUPS #################################### - -# The hosts group is used to target physical host machines. Enter all physical -# host machines here. -hosts: - hosts: - target1: - -# This is the location where elasticsearch(s) and logstash(s) will live. -elastic-logstash: - hosts: - logging01: - -# This is the location where kibana(s) will live -kibana: - hosts: - logging01: - -# These groups are all optional groups used within the stack to agment the data -# collection in an OpenStack environment. -ceph-mon: {} -galera_all: {} -nova_compute: {} -haproxy_all: {} -horizon_all: {} -memcached_all: {} -rabbitmq_all: {} -shared-infra_hosts: {} -utility_all: {} diff --git a/elk_metrics_6x/setupAPMserver.yml b/elk_metrics_6x/setupAPMserver.yml index 5f7408de..c2767fd3 100644 --- a/elk_metrics_6x/setupAPMserver.yml +++ b/elk_metrics_6x/setupAPMserver.yml @@ -24,8 +24,8 @@ - "--dashboards" register: templates until: templates is success - retries: 3 - delay: 2 + retries: 5 + delay: 5 tags: - beat-setup diff --git a/elk_metrics_6x/setupAuditbeat.yml b/elk_metrics_6x/setupAuditbeat.yml index 8656f69d..b7c171a7 100644 --- a/elk_metrics_6x/setupAuditbeat.yml +++ b/elk_metrics_6x/setupAuditbeat.yml @@ -24,8 +24,8 @@ - "--dashboards" register: templates until: templates is success - retries: 3 - delay: 2 + retries: 5 + delay: 5 tags: - beat-setup diff --git a/elk_metrics_6x/setupFilebeat.yml b/elk_metrics_6x/setupFilebeat.yml index 8f0739ad..feb020a8 100644 --- a/elk_metrics_6x/setupFilebeat.yml +++ b/elk_metrics_6x/setupFilebeat.yml @@ -24,8 +24,8 @@ - "--dashboards" register: templates until: templates is success - retries: 3 - delay: 2 + retries: 5 + delay: 5 tags: - beat-setup diff --git a/elk_metrics_6x/setupHeartbeat.yml b/elk_metrics_6x/setupHeartbeat.yml index 018d8b40..e26301a8 100644 --- a/elk_metrics_6x/setupHeartbeat.yml +++ b/elk_metrics_6x/setupHeartbeat.yml @@ -24,8 +24,8 @@ - "--dashboards" register: templates until: templates is success - retries: 3 - delay: 2 + retries: 5 + delay: 5 tags: - beat-setup diff --git a/elk_metrics_6x/setupJournalbeat.yml b/elk_metrics_6x/setupJournalbeat.yml index 9c5d6bfd..52248af3 100644 --- a/elk_metrics_6x/setupJournalbeat.yml +++ b/elk_metrics_6x/setupJournalbeat.yml @@ -40,8 +40,8 @@ -e -v register: templates until: templates is success - retries: 3 - delay: 2 + retries: 5 + delay: 5 tags: - beat-setup diff --git a/elk_metrics_6x/setupMetricbeat.yml b/elk_metrics_6x/setupMetricbeat.yml index e91e47e8..47741192 100644 --- a/elk_metrics_6x/setupMetricbeat.yml +++ b/elk_metrics_6x/setupMetricbeat.yml @@ -24,8 +24,8 @@ - "--dashboards" register: templates until: templates is success - retries: 3 - delay: 2 + retries: 5 + delay: 5 tags: - beat-setup diff --git a/elk_metrics_6x/setupPacketbeat.yml b/elk_metrics_6x/setupPacketbeat.yml index e18fc2d9..03440a48 100644 --- a/elk_metrics_6x/setupPacketbeat.yml +++ b/elk_metrics_6x/setupPacketbeat.yml @@ -24,8 +24,8 @@ - "--dashboards" register: templates until: templates is success - retries: 3 - delay: 2 + retries: 5 + delay: 5 tags: - beat-setup diff --git a/elk_metrics_6x/templates/filebeat.yml.j2 b/elk_metrics_6x/templates/filebeat.yml.j2 index 763790e1..bd1d7c66 100644 --- a/elk_metrics_6x/templates/filebeat.yml.j2 +++ b/elk_metrics_6x/templates/filebeat.yml.j2 @@ -258,7 +258,8 @@ filebeat.modules: # If true, all fields created by this module are prefixed with # `osquery.result`. Set to false to copy the fields in the root # of the document. The default is true. - var.use_namespace: true + # NOTE(cloudull): This option is commented out because it is broken + #var.use_namespace: true #----------------------------- PostgreSQL Module ----------------------------- #- module: postgresql diff --git a/elk_metrics_6x/tests/_container-setup.yml b/elk_metrics_6x/tests/_container-setup.yml new file mode 100644 index 00000000..c3815a25 --- /dev/null +++ b/elk_metrics_6x/tests/_container-setup.yml @@ -0,0 +1,101 @@ +--- +# Copyright 2018, Rackspace US, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: Setup host for nspawn + hosts: physical_hosts + connection: local + become: true + vars: + nspawn_networks: + nspawn_address: + bridge: "nspawn0" + private_device: true + enable_dhcp: true + dhcp_range: 10.100.101.2,10.100.101.129 + address: 10.100.101.1 + netmask: 255.255.255.0 + macvlan_mode: bridge + + pre_tasks: + - name: Show host facts + debug: + var: hostvars + + - name: First ensure apt cache is always refreshed + apt: + update_cache: yes + when: + - ansible_pkg_mgr == 'apt' + + - name: Ensure root ssh key + user: + name: "{{ ansible_env.USER | default('root') }}" + generate_ssh_key: "yes" + ssh_key_bits: 2048 + ssh_key_file: ".ssh/id_rsa" + + - name: Get root ssh key + slurp: + src: '~/.ssh/id_rsa.pub' + register: _root_ssh_key + + - name: Prepare container ssh key fact + set_fact: + nspawn_container_ssh_key: "{{ _root_ssh_key['content'] | b64decode }}" + + - name: Ensure public ssh key is in authorized_keys + authorized_key: + user: "{{ ansible_env.USER | default('root') }}" + key: "{{ nspawn_container_ssh_key }}" + manage_dir: no + + roles: + - role: "systemd_networkd" + systemd_networkd_prefix: "elk_metrics_6x" + systemd_interface_cleanup: true + systemd_run_networkd: true + systemd_netdevs: + - NetDev: + Name: dummy0 + Kind: dummy + - NetDev: + Name: br-mgmt + Kind: bridge + systemd_networks: + - interface: "dummy0" + bridge: "br-mgmt" + - interface: "br-mgmt" + address: "172.29.236.1" + netmask: "255.255.255.0" + + - role: "nspawn_hosts" + + +- name: Create container(s) + hosts: all_containers + gather_facts: false + become: true + pre_tasks: + - name: Show container facts + debug: + var: hostvars + + roles: + - role: "nspawn_container_create" + + post_tasks: + - name: Rescan quotas + command: "btrfs quota rescan -w /var/lib/machines" + delegate_to: "{{ physical_host }}" diff --git a/elk_metrics_6x/tests/ansible-role-requirements.yml b/elk_metrics_6x/tests/ansible-role-requirements.yml new file mode 100644 index 00000000..85ba806d --- /dev/null +++ b/elk_metrics_6x/tests/ansible-role-requirements.yml @@ -0,0 +1,33 @@ +--- +- name: apt_package_pinning + scm: git + src: https://git.openstack.org/openstack/openstack-ansible-apt_package_pinning + version: master +- name: config_template + scm: git + src: https://git.openstack.org/openstack/ansible-config_template + version: master +- name: nspawn_container_create + scm: git + src: https://git.openstack.org/openstack/openstack-ansible-nspawn_container_create + version: master +- name: nspawn_hosts + scm: git + src: https://git.openstack.org/openstack/openstack-ansible-nspawn_hosts + version: master +- name: plugins + scm: git + src: https://git.openstack.org/openstack/openstack-ansible-plugins + version: master +- name: systemd_mount + scm: git + src: https://git.openstack.org/openstack/ansible-role-systemd_mount + version: master +- name: systemd_networkd + scm: git + src: https://git.openstack.org/openstack/ansible-role-systemd_networkd + version: master +- name: systemd_service + scm: git + src: https://git.openstack.org/openstack/ansible-role-systemd_service + version: master diff --git a/elk_metrics_6x/tests/functional.yml b/elk_metrics_6x/tests/functional.yml new file mode 100644 index 00000000..bce66905 --- /dev/null +++ b/elk_metrics_6x/tests/functional.yml @@ -0,0 +1,140 @@ +--- +# Copyright 2018, Rackspace US, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- import_playbook: run-setup.yml + +- name: Basic setup + hosts: "all" + become: true + + environment: + # ZUUL_PROJECT is used by tests/get-ansible-role-requirements to + # determine when CI provided repos should be used. + ZUUL_PROJECT: "{{ zuul.project.short_name }}" + ANSIBLE_PACKAGE: "{{ ansible_package | default('') }}" + ANSIBLE_HOST_KEY_CHECKING: "False" + ANSIBLE_LOG_PATH: "/tmp/elk-metrics-6x-logs/ansible-elk-test.log" + + pre_tasks: + - name: Create swap file + command: "dd if=/dev/zero of=/swap.img bs=1M count=4096" + args: + creates: /swap.img + register: swap_create + + - name: Format the swap file + command: mkswap /swap.img + when: + - swap_create is changed + tags: + - swap-format + - skip_ansible_lint + + - name: Enable swap file + command: swapon /swap.img + failed_when: false + tags: + - swap-format + - skip_ansible_lint + + - name: Set system swappiness + sysctl: + name: vm.swappiness + value: 10 + state: present + + - name: Flush iptables rules + command: "{{ item }}" + args: + creates: "/tmp/elk-metrics-6x-logs/iptables.flushed" + with_items: + - "iptables -F" + - "iptables -X" + - "iptables -t nat -F" + - "iptables -t nat -X" + - "iptables -t mangle -F" + - "iptables -t mangle -X" + - "iptables -P INPUT ACCEPT" + - "iptables -P FORWARD ACCEPT" + - "iptables -P OUTPUT ACCEPT" + - "touch /tmp/elk-metrics-6x-logs/iptables.flushed" + + tasks: + - name: Run embedded ansible installation + become: yes + become_user: root + command: "./bootstrap-embedded-ansible.sh" + args: + chdir: "src/{{ current_test_repo }}/elk_metrics_6x" + + - name: Run ansible-galaxy + become: yes + become_user: root + command: "/root/ansible25/bin/ansible-galaxy install --force -r ansible-role-requirements.yml" + args: + chdir: "src/{{ current_test_repo }}/elk_metrics_6x/tests" + + - name: Install netaddr + pip: + name: netaddr + virtualenv: "/root/ansible25" + + - name: Run environment setup + become: yes + become_user: root + command: "/root/ansible25/bin/ansible-playbook -i inventory/test-inventory.yml -e @test-vars.yml _container-setup.yml" + environment: + ANSIBLE_ACTION_PLUGINS: "/root/ansible25/repositories/ansible-config_template/action" + ANSIBLE_CONNECTION_PLUGINS: "/root/ansible25/repositories/openstack-ansible-plugins/connection" + ANSIBLE_LOG_PATH: "/tmp/elk-metrics-6x-logs/ansible-elk-test-container-setup.log" + args: + chdir: "src/{{ current_test_repo }}/elk_metrics_6x/tests" + + - name: Wait 15 seconds + command: "sleep 15" + changed_when: false + + - name: Log all facts + become: yes + become_user: root + command: "/root/ansible25/bin/ansible -m setup -i tests/inventory/test-inventory.yml all" + environment: + ANSIBLE_ACTION_PLUGINS: "/root/ansible25/repositories/ansible-config_template/action" + ANSIBLE_CONNECTION_PLUGINS: "/root/ansible25/repositories/openstack-ansible-plugins/connection" + ANSIBLE_LOG_PATH: "/tmp/elk-metrics-6x-logs/ansible-elk-test-facts.log" + args: + chdir: "src/{{ current_test_repo }}/elk_metrics_6x" + + - name: Run functional test + become: yes + become_user: root + command: "/root/ansible25/bin/ansible-playbook -i tests/inventory/test-inventory.yml -e @tests/test-vars.yml site.yml" + environment: + ANSIBLE_ACTION_PLUGINS: "/root/ansible25/repositories/ansible-config_template/action" + ANSIBLE_CONNECTION_PLUGINS: "/root/ansible25/repositories/openstack-ansible-plugins/connection" + ANSIBLE_LOG_PATH: "/tmp/elk-metrics-6x-logs/ansible-elk-test-deployment.log" + args: + chdir: "src/{{ current_test_repo }}/elk_metrics_6x" + + - name: Show cluster state + become: yes + become_user: root + command: "/root/ansible25/bin/ansible-playbook -i tests/inventory/test-inventory.yml -e @tests/test-vars.yml showElasticCluster.yml" + environment: + ANSIBLE_ACTION_PLUGINS: "/root/ansible25/repositories/ansible-config_template/action" + ANSIBLE_CONNECTION_PLUGINS: "/root/ansible25/repositories/openstack-ansible-plugins/connection" + ANSIBLE_LOG_PATH: "/tmp/elk-metrics-6x-logs/ansible-elk-test-show-cluster.log" + args: + chdir: "src/{{ current_test_repo }}/elk_metrics_6x" diff --git a/elk_metrics_6x/tests/inventory/test-inventory.yml b/elk_metrics_6x/tests/inventory/test-inventory.yml new file mode 100644 index 00000000..41e8e5a3 --- /dev/null +++ b/elk_metrics_6x/tests/inventory/test-inventory.yml @@ -0,0 +1,59 @@ +--- +# The hosts group is used to target physical host machines. Enter all physical +# host machines here. +hosts: + children: + physical_hosts: + hosts: + localhost: + ansible_host: 127.0.0.1 + ansible_user: root + vars: + physical_host: localhost + container_networks: + management_address: + address: "172.29.236.1" + netmask: "255.255.255.0" + bridge: "br-mgmt" + + +all_containers: + vars: + physical_host: localhost + container_tech: nspawn + container_networks: + management_address: + address: "{{ ansible_host }}" + netmask: "255.255.255.0" + bridge: "br-mgmt" + + children: + elastic-logstash: + hosts: + elastic0: + ansible_host: 172.29.236.100 + ansible_user: root + + elastic1: + ansible_host: 172.29.236.101 + ansible_user: root + + elastic2: + ansible_host: 172.29.236.102 + ansible_user: root + + elastic3: + ansible_host: 172.29.236.103 + ansible_user: root + + kibana: + hosts: + kibana0: + ansible_host: 172.29.236.110 + ansible_user: root + + apm-server: + hosts: + apm0: + ansible_host: 172.29.236.120 + ansible_user: root diff --git a/elk_metrics_6x/tests/manual-test.rc b/elk_metrics_6x/tests/manual-test.rc new file mode 100644 index 00000000..ecd52e52 --- /dev/null +++ b/elk_metrics_6x/tests/manual-test.rc @@ -0,0 +1,16 @@ +export ANSIBLE_HOST_KEY_CHECKING="False" +export ANSIBLE_ROLES_PATH="${HOME}/ansible25/repositories/roles" +export ANSIBLE_ACTION_PLUGINS="${HOME}/ansible25/repositories/roles/config_template/action" +export ANSIBLE_CONNECTION_PLUGINS="${HOME}/ansible25/repositories/roles/plugins/connection" +export ANSIBLE_LOG_PATH="/tmp/elk-metrics-6x-logs/ansible-elk-test.log" + +if [[ ! -d "/tmp/elk-metrics-6x-logs" ]]; then + mkdir -pv "/tmp/elk-metrics-6x-logs" + chmod 0777 "/tmp/elk-metrics-6x-logs" +fi + +echo "To build a test environment run the following:" +echo -e "# /root/ansible25/bin/ansible-playbook -i tests/inventory/test-inventory.yml tests/test.yml --limit localhost\n" + +echo "Run manual functional tests by executing the following:" +echo -e "# /root/ansible25/bin/ansible-playbook -i tests/inventory/test-inventory.yml site.yml\n" diff --git a/elk_metrics_6x/tests/post-run.yml b/elk_metrics_6x/tests/post-run.yml new file mode 100644 index 00000000..a50c3539 --- /dev/null +++ b/elk_metrics_6x/tests/post-run.yml @@ -0,0 +1,27 @@ +--- +# Copyright 2018, Rackspace US, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- import_playbook: run-setup.yml + +- name: Run post tasks + hosts: "all" + tasks: + - name: Copy logs back to the executor + synchronize: + src: "/tmp/elk-metrics-6x-logs" + dest: "{{ zuul.executor.log_root }}/" + mode: pull + rsync_opts: + - "--quiet" diff --git a/elk_metrics_6x/tests/run-cleanup.sh b/elk_metrics_6x/tests/run-cleanup.sh new file mode 100755 index 00000000..478b4abb --- /dev/null +++ b/elk_metrics_6x/tests/run-cleanup.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash +# Copyright 2018, Rackspace US, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -e + +export TEST_DIR="$(readlink -f $(dirname ${0})/../../)" + +# Stop beat processes +pushd "${TEST_DIR}/elk_metrics_6x" + for i in $(ls -1 install*beat.yml); do + LOWER_BEAT="$(echo "${i}" | tr '[:upper:]' '[:lower:]')" + BEAT_PARTIAL="$(echo ${LOWER_BEAT} | awk -F'.' '{print $1}')" + BEAT="$(echo ${BEAT_PARTIAL} | awk -F'install' '{print $2}')" + echo "Stopping ${BEAT}" + (systemctl stop "${BEAT}" || true) & + apt remove --purge -y "${BEAT}" || true + if [[ -d "/etc/${BEAT}" ]]; then + rm -rf "/etc/${BEAT}" + fi + if [[ -d "/var/lib/${BEAT}" ]]; then + rm -rf "/var/lib/${BEAT}" + fi + if [[ -d "/etc/systemd/system/${BEAT}.service.d" ]]; then + rm -rf "/etc/systemd/system/${BEAT}.service.d" + fi + done +popd + +for i in $(grep -lri elastic /etc/apt/sources.list.d/); do + rm "${i}" +done + +# Stop and remove containers +for i in {1..3}; do + if machinectl list-images | grep -v ubuntu | awk '/sub/ {print $1}' | xargs -n 1 machinectl kill; then + sleep 1 + fi +done + +for i in {1..3}; do + if machinectl list-images | grep -v ubuntu | awk '/sub/ {print $1}' | xargs -n 1 machinectl remove; then + sleep 1 + fi +done diff --git a/elk_metrics_6x/tests/run-setup.yml b/elk_metrics_6x/tests/run-setup.yml new file mode 100644 index 00000000..60cd8406 --- /dev/null +++ b/elk_metrics_6x/tests/run-setup.yml @@ -0,0 +1,49 @@ +--- +# Copyright 2018, Rackspace US, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: Zuul facts + hosts: "all" + tasks: + - name: Set zuul fact + set_fact: + zuul: + project: + canonical_name: "openstack-ansible-ops" + short_name: "ops" + executor: + log_root: "{{ ansible_env.HOME }}/elk-test-logs" + when: + - zuul is not defined + + - name: Print zuul fact + debug: var=zuul + + - name: Set current test repo (cross-repo) + set_fact: + current_test_repo: "git.openstack.org/{{ osa_test_repo }}" + when: + - osa_test_repo is defined + + - name: Set current test repo (non-cross-repo) + set_fact: + current_test_repo: "{{ zuul.project.canonical_name }}" + when: + - osa_test_repo is not defined + + post_tasks: + - name: Ensure the log directory exists + file: + path: "/tmp/elk-metrics-6x-logs" + state: directory diff --git a/elk_metrics_6x/tests/run-tests.sh b/elk_metrics_6x/tests/run-tests.sh new file mode 100755 index 00000000..6bf0b4fd --- /dev/null +++ b/elk_metrics_6x/tests/run-tests.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +# Copyright 2018, Rackspace US, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -ve + +export TEST_DIR="$(readlink -f $(dirname ${0})/../../)" + +pushd "${HOME}" + if [[ ! -d "src" ]]; then + mkdir src + fi + pushd src + ln -sf "${TEST_DIR}" + popd +popd + +source ${TEST_DIR}/elk_metrics_6x/tests/manual-test.rc + +bash -v "${TEST_DIR}/elk_metrics_6x/bootstrap-embedded-ansible.sh" + +${HOME}/ansible25/bin/ansible-galaxy install --force \ + --roles-path="${HOME}/ansible25/repositories/roles" \ + --role-file="${TEST_DIR}/elk_metrics_6x/tests/ansible-role-requirements.yml" + +${HOME}/ansible25/bin/ansible-playbook -i 'localhost,' \ + -vv \ + ${TEST_DIR}/elk_metrics_6x/tests/test.yml diff --git a/elk_metrics_6x/tests/test-vars.yml b/elk_metrics_6x/tests/test-vars.yml new file mode 100644 index 00000000..aa736896 --- /dev/null +++ b/elk_metrics_6x/tests/test-vars.yml @@ -0,0 +1,27 @@ +--- +# Copyright 2018, Rackspace US, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +physical_host: localhost + +# NOTE(cloudnull): Test configs used to minimize the impact of a +# multi-node install with limited resources. +q_storage: 1 +q_mem: 128 +h_mem: 512 + +osa_test_repo: "openstack/openstack-ansible-ops" + +# Set the data interface to a known value +elastic_data_interface: "{{ (inventory_hostname == 'localhost') | ternary('mv-mgmt', 'mv-mv-mgmt') }}" diff --git a/elk_metrics_6x/tests/test.yml b/elk_metrics_6x/tests/test.yml new file mode 100644 index 00000000..d7cd3314 --- /dev/null +++ b/elk_metrics_6x/tests/test.yml @@ -0,0 +1,17 @@ +--- +# Copyright 2018, Rackspace US, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- import_playbook: functional.yml +- import_playbook: testLayout.yml diff --git a/elk_metrics_6x/tests/testLayout.yml b/elk_metrics_6x/tests/testLayout.yml index 0839d3f4..629381c9 100644 --- a/elk_metrics_6x/tests/testLayout.yml +++ b/elk_metrics_6x/tests/testLayout.yml @@ -1,8 +1,14 @@ --- + +- import_playbook: run-setup.yml + - name: Test host layout hosts: localhost become: true + environment: + ANSIBLE_LOG_PATH: "/tmp/elk-metrics-6x-logs/ansible-elk-test.log" + vars: storage_node_count: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] expected_masters: [1, 1, 3, 3, 3, 3, 3, 5, 5, 5, 5, 7, 7, 7, 7, 9, 9, 9, 9, 11] diff --git a/zuul.d/jobs.yaml b/zuul.d/jobs.yaml new file mode 100644 index 00000000..9218647d --- /dev/null +++ b/zuul.d/jobs.yaml @@ -0,0 +1,25 @@ +--- +# Copyright 2018, Rackspace US, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- job: + name: "openstack-ansible-ops:elk_metrics_6x" + parent: base + description: "Runs a gate test on the elk_metrics_6x project." + run: "elk_metrics_6x/tests/test.yml" + post-run: "elk_metrics_6x/tests/post-run.yml" + files: + - ^elk_metrics_6x/.* + vars: + osa_test_repo: "openstack/openstack-ansible-ops" diff --git a/zuul.d/project.yaml b/zuul.d/project.yaml index 4e2c3ee8..74920d9c 100644 --- a/zuul.d/project.yaml +++ b/zuul.d/project.yaml @@ -15,3 +15,9 @@ - project: templates: - openstack-ansible-role-jobs + check: + jobs: + - "openstack-ansible-ops:elk_metrics_6x" + gate: + jobs: + - "openstack-ansible-ops:elk_metrics_6x"