diff --git a/tox.ini b/tox.ini index 840d5ed6d..90cead2b1 100644 --- a/tox.ini +++ b/tox.ini @@ -113,3 +113,10 @@ changedir = {toxinidir}/tripleo_ansible/roles/test_deps envdir = {toxworkdir}/mol commands = python -m pytest --color=yes --html={envlogdir}/reports.html --self-contained-html {tty:-s} {toxinidir}/tests/test_molecule.py + +[testenv:mol-tuned] +basepython={[testenv:mol]basepython} +deps={[testenv:mol]deps} +changedir = {toxinidir}/tripleo_ansible/roles/tuned +commands = + python -m pytest --color=yes --html={envlogdir}/reports.html --self-contained-html {tty:-s} {toxinidir}/tests/test_molecule.py diff --git a/tripleo_ansible/roles/tuned/README.md b/tripleo_ansible/roles/tuned/README.md new file mode 100644 index 000000000..738035296 --- /dev/null +++ b/tripleo_ansible/roles/tuned/README.md @@ -0,0 +1,4 @@ +Tuned +===== + +Ansible role to install and manage tuned profiles. diff --git a/tripleo_ansible/roles/tuned/defaults/main.yml b/tripleo_ansible/roles/tuned/defaults/main.yml new file mode 100644 index 000000000..5270c88ad --- /dev/null +++ b/tripleo_ansible/roles/tuned/defaults/main.yml @@ -0,0 +1,28 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +# All variables intended for modification should place placed in this file. + +# All variables within this role should have a prefix of "tuned" +tuned_debug: false + +tuned_profile: "throughput-performance" +tuned_custom_profile: "" + +# Packages installed on the local system. Allows user to define this list +# otherwise it will inherit from the OS specific variable file(s). +tuned_system_packages: "{{ _tuned_system_packages | default([]) }}" diff --git a/tripleo_ansible/roles/tuned/handlers/main.yml b/tripleo_ansible/roles/tuned/handlers/main.yml new file mode 100644 index 000000000..ffbe6cb44 --- /dev/null +++ b/tripleo_ansible/roles/tuned/handlers/main.yml @@ -0,0 +1,21 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# 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: Restart tuned + systemd: + name: tuned + state: restarted + enabled: true diff --git a/tripleo_ansible/roles/tuned/meta/main.yml b/tripleo_ansible/roles/tuned/meta/main.yml new file mode 100644 index 000000000..a61ecd962 --- /dev/null +++ b/tripleo_ansible/roles/tuned/meta/main.yml @@ -0,0 +1,45 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +galaxy_info: + author: OpenStack + description: TripleO OpenStack Role -- tuned + company: Red Hat + license: Apache-2.0 + min_ansible_version: 2.7 + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + platforms: + - name: Fedora + versions: + - 28 + - name: CentOS + versions: + - 7 + + galaxy_tags: + - tripleo + - tuned + + +# List your role dependencies here, one per line. Be sure to remove the '[]' above, +# if you add dependencies to this list. +dependencies: [] diff --git a/tripleo_ansible/roles/tuned/molecule/default/Dockerfile b/tripleo_ansible/roles/tuned/molecule/default/Dockerfile new file mode 100644 index 000000000..a3ab1ecc8 --- /dev/null +++ b/tripleo_ansible/roles/tuned/molecule/default/Dockerfile @@ -0,0 +1,36 @@ +# Molecule managed +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash {{ item.pkg_extras | default('') }} && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl python-setuptools bash {{ item.pkg_extras | default('') }} && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml {{ item.pkg_extras | default('') }} && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates {{ item.pkg_extras | default('') }}; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates {{ item.pkg_extras | default('') }} && xbps-remove -O; fi + +{% for pkg in item.easy_install | default([]) %} +# install pip for centos where there is no python-pip rpm in default repos +RUN easy_install {{ pkg }} +{% endfor %} + +CMD ["sh", "-c", "while true; do sleep 10000; done"] \ No newline at end of file diff --git a/tripleo_ansible/roles/tuned/molecule/default/molecule.yml b/tripleo_ansible/roles/tuned/molecule/default/molecule.yml new file mode 100644 index 000000000..c5b487da9 --- /dev/null +++ b/tripleo_ansible/roles/tuned/molecule/default/molecule.yml @@ -0,0 +1,68 @@ +--- +driver: + name: docker + +log: true + +platforms: + - name: centos7 + hostname: centos7 + image: centos:7 + dockerfile: Dockerfile + pkg_extras: python-setuptools + easy_install: + - pip + environment: &env + http_proxy: "{{ lookup('env', 'http_proxy') }}" + https_proxy: "{{ lookup('env', 'https_proxy') }}" + command: /sbin/init + tmpfs: + - /run + - /tmp + capabilities: + - ALL # CENT7 requires all due to the age of the software + volumes: + - /run/udev:/run/udev:ro + - /sys/fs/cgroup:/sys/fs/cgroup:ro + + - name: fedora28 + hostname: fedora28 + image: fedora:28 + dockerfile: Dockerfile + pkg_extras: python*-setuptools + environment: + http_proxy: "{{ lookup('env', 'http_proxy') }}" + https_proxy: "{{ lookup('env', 'https_proxy') }}" + command: /sbin/init + privileged: true + tmpfs: + - /run + - /tmp + capabilities: + - SYS_ADMIN + volumes: + - /run/udev:/run/udev:ro + - /sys/fs/cgroup:/sys/fs/cgroup:ro + +provisioner: + name: ansible + log: true + env: + ANSIBLE_STDOUT_CALLBACK: yaml + +scenario: + test_sequence: + - destroy + - create + - prepare + - converge + - verify + - destroy + +lint: + enabled: false + +verifier: + name: testinfra + lint: + name: flake8 diff --git a/tripleo_ansible/roles/tuned/molecule/default/playbook.yml b/tripleo_ansible/roles/tuned/molecule/default/playbook.yml new file mode 100644 index 000000000..6f35fd6cf --- /dev/null +++ b/tripleo_ansible/roles/tuned/molecule/default/playbook.yml @@ -0,0 +1,21 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# 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: Converge + hosts: all + roles: + - role: "tuned" diff --git a/tripleo_ansible/roles/tuned/molecule/default/prepare.yml b/tripleo_ansible/roles/tuned/molecule/default/prepare.yml new file mode 100644 index 000000000..ef85c3128 --- /dev/null +++ b/tripleo_ansible/roles/tuned/molecule/default/prepare.yml @@ -0,0 +1,21 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# 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: Prepare + hosts: all + roles: + - role: test_deps diff --git a/tripleo_ansible/roles/tuned/molecule/default/verify.yml b/tripleo_ansible/roles/tuned/molecule/default/verify.yml new file mode 100644 index 000000000..dfd4c7352 --- /dev/null +++ b/tripleo_ansible/roles/tuned/molecule/default/verify.yml @@ -0,0 +1,15 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# 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. diff --git a/tripleo_ansible/roles/tuned/tasks/main.yml b/tripleo_ansible/roles/tuned/tasks/main.yml new file mode 100644 index 000000000..5ec0e0bdd --- /dev/null +++ b/tripleo_ansible/roles/tuned/tasks/main.yml @@ -0,0 +1,49 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +# "{{ role_name }}" will search for and load any operating system variable file +# found within the "vars/" path. If no OS files are found the task will skip. +- name: Gather variables for each operating system + include_vars: "{{ item }}" + with_first_found: + - skip: true + files: + - "{{ ansible_distribution | lower }}-{{ ansible_distribution_version | lower }}.yml" + - "{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version | lower }}.yml" + - "{{ ansible_os_family | lower }}-{{ ansible_distribution_major_version | lower }}.yml" + - "{{ ansible_distribution | lower }}.yml" + - "{{ ansible_os_family | lower }}-{{ ansible_distribution_version.split('.')[0] }}.yml" + - "{{ ansible_os_family | lower }}.yml" + tags: + - always + +- include_tasks: tuned_install.yml + when: + - (tuned_system_packages | length) > 0 + +- name: Check for tuned-adm + command: >- + which tuned-adm + environment: + PATH: "/bin:/usr/bin:/sbin:/usr/sbin" + changed_when: false + failed_when: false + register: tuned_check + +- include_tasks: tuned_config.yml + when: + - tuned_check.rc == 0 diff --git a/tripleo_ansible/roles/tuned/tasks/tuned_config.yml b/tripleo_ansible/roles/tuned/tasks/tuned_config.yml new file mode 100644 index 000000000..d25c46beb --- /dev/null +++ b/tripleo_ansible/roles/tuned/tasks/tuned_config.yml @@ -0,0 +1,43 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# 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: Ensure profile directory exists + file: + path: "/etc/tuned/{{ tuned_profile }}" + state: directory + when: + - (custom_profile is defined) and ((custom_profile | length) > 0) + +- name: Create custom tuned profile + copy: + content: "{{ custom_profile }}" + dest: "/etc/tuned/{{ tuned_profile }}/tuned.conf" + when: + - (custom_profile is defined) and ((custom_profile | length) > 0) + +- name: Check tuned active profile + slurp: + src: "/etc/tuned/active_profile" + register: tuned_active_profile + +- name: Enable tuned profile + command: >- + tuned-adm profile {{ tuned_profile }} + environment: + PATH: "/bin:/usr/bin:/sbin:/usr/sbin" + when: + - ((tuned_active_profile['content'] | b64decode).strip()) != tuned_profile diff --git a/tripleo_ansible/roles/tuned/tasks/tuned_install.yml b/tripleo_ansible/roles/tuned/tasks/tuned_install.yml new file mode 100644 index 000000000..a22c9c477 --- /dev/null +++ b/tripleo_ansible/roles/tuned/tasks/tuned_install.yml @@ -0,0 +1,25 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# 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: Install tuned + package: + name: "{{ tuned_system_packages }}" + state: present + notify: Restart tuned + +- name: Flush handlers + meta: flush_handlers diff --git a/tripleo_ansible/roles/tuned/vars/main.yml b/tripleo_ansible/roles/tuned/vars/main.yml new file mode 100644 index 000000000..d4719abd0 --- /dev/null +++ b/tripleo_ansible/roles/tuned/vars/main.yml @@ -0,0 +1,22 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +# While options found within the vars/ path can be overridden using extra +# vars, items within this path are considered part of the role and not +# intended to be modified. + +# All variables within this role should have a prefix of "{{ role_name }}" diff --git a/tripleo_ansible/roles/tuned/vars/redhat.yml b/tripleo_ansible/roles/tuned/vars/redhat.yml new file mode 100644 index 000000000..d7b80e48c --- /dev/null +++ b/tripleo_ansible/roles/tuned/vars/redhat.yml @@ -0,0 +1,18 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + +_tuned_system_packages: + - tuned diff --git a/zuul.d/jobs.yaml b/zuul.d/jobs.yaml index 75a487d6c..e8f6015d7 100644 --- a/zuul.d/jobs.yaml +++ b/zuul.d/jobs.yaml @@ -14,3 +14,14 @@ - ^tripleo_ansible/roles/test_deps/.* vars: tox_envlist: mol-test_deps + +- job: + name: tripleo-ansible-centos-7-molecule-tuned + parent: tripleo-ansible-centos + description: | + Run molecule tests. Uses tox with the ``mol-tuned`` environment. + voting: true + files: + - ^tripleo_ansible/roles/tuned/.* + vars: + tox_envlist: mol-tuned diff --git a/zuul.d/layout.yaml b/zuul.d/layout.yaml index af5958d37..a7e711cc8 100644 --- a/zuul.d/layout.yaml +++ b/zuul.d/layout.yaml @@ -4,6 +4,7 @@ jobs: - openstack-tox-linters - tripleo-ansible-centos-7-molecule-test_deps + - tripleo-ansible-centos-7-molecule-tuned gate: jobs: - openstack-tox-linters