diff --git a/doc/source/roles/role-tripleo_nvdimm.rst b/doc/source/roles/role-tripleo_nvdimm.rst new file mode 100644 index 000000000..3c039616c --- /dev/null +++ b/doc/source/roles/role-tripleo_nvdimm.rst @@ -0,0 +1,6 @@ +===================== +Role - tripleo_nvdimm +===================== + +.. ansibleautoplugin:: + :role: tripleo_ansible/roles/tripleo_nvdimm diff --git a/tripleo_ansible/roles/tripleo_nvdimm/defaults/main.yml b/tripleo_ansible/roles/tripleo_nvdimm/defaults/main.yml new file mode 100644 index 000000000..8a62375eb --- /dev/null +++ b/tripleo_ansible/roles/tripleo_nvdimm/defaults/main.yml @@ -0,0 +1,21 @@ +--- +# Copyright 2020 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 be placed in this file. + +# All variables within this role should have a prefix of "tripleo_tripleo_nvdimm" +tripleo_tripleo_nvdimm_debug: false diff --git a/tripleo_ansible/roles/tripleo_nvdimm/files/.gitkeep b/tripleo_ansible/roles/tripleo_nvdimm/files/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/tripleo_ansible/roles/tripleo_nvdimm/handlers/main.yml b/tripleo_ansible/roles/tripleo_nvdimm/handlers/main.yml new file mode 100644 index 000000000..ede65b54e --- /dev/null +++ b/tripleo_ansible/roles/tripleo_nvdimm/handlers/main.yml @@ -0,0 +1,15 @@ +--- +# Copyright 2020 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/tripleo_nvdimm/meta/main.yml b/tripleo_ansible/roles/tripleo_nvdimm/meta/main.yml new file mode 100644 index 000000000..346e002c1 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_nvdimm/meta/main.yml @@ -0,0 +1,42 @@ +--- +# Copyright 2020 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 -- tripleo_nvdimm + 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: CentOS + versions: + - 7 + - 8 + + galaxy_tags: + - tripleo + + +# 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/tripleo_nvdimm/molecule/default/Dockerfile b/tripleo_ansible/roles/tripleo_nvdimm/molecule/default/Dockerfile new file mode 100644 index 000000000..8fc73a838 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_nvdimm/molecule/default/Dockerfile @@ -0,0 +1,37 @@ +# Molecule managed +# Copyright 2020 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 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"] diff --git a/tripleo_ansible/roles/tripleo_nvdimm/molecule/default/converge.yml b/tripleo_ansible/roles/tripleo_nvdimm/molecule/default/converge.yml new file mode 100644 index 000000000..55b2d2021 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_nvdimm/molecule/default/converge.yml @@ -0,0 +1,23 @@ +--- +# Copyright 2020 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: "tripleo_nvdimm" + vars: + tripleo_nvdimm_pmem_namespaces: "12G:ns12g,12G:ns12g" diff --git a/tripleo_ansible/roles/tripleo_nvdimm/molecule/default/molecule.yml b/tripleo_ansible/roles/tripleo_nvdimm/molecule/default/molecule.yml new file mode 100644 index 000000000..f27c41d88 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_nvdimm/molecule/default/molecule.yml @@ -0,0 +1,50 @@ +--- +driver: + name: docker + +log: true + +platforms: + - name: centos7 + hostname: centos7 + image: centos:7 + dockerfile: Dockerfile + pkg_extras: python-setuptools + volumes: + - /etc/ci/mirror_info.sh:/etc/ci/mirror_info.sh:ro + easy_install: + - pip + environment: &env + http_proxy: "{{ lookup('env', 'http_proxy') }}" + https_proxy: "{{ lookup('env', 'https_proxy') }}" + + - name: centos8 + hostname: centos8 + image: centos:8 + dockerfile: Dockerfile + pkg_extras: python*-setuptools + volumes: + - /etc/ci/mirror_info.sh:/etc/ci/mirror_info.sh:ro + environment: + <<: *env + +provisioner: + name: ansible + log: true + env: + ANSIBLE_STDOUT_CALLBACK: yaml + +scenario: + test_sequence: + - destroy + - create + - prepare + - converge + - check + - verify + - destroy + +verifier: + name: testinfra + env: + TRIPLEO_NVDIMM_PMEM_NAMESPACES: "12G:ns12g,12G:ns12g" diff --git a/tripleo_ansible/roles/tripleo_nvdimm/molecule/default/prepare.yml b/tripleo_ansible/roles/tripleo_nvdimm/molecule/default/prepare.yml new file mode 100644 index 000000000..27e23e495 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_nvdimm/molecule/default/prepare.yml @@ -0,0 +1,21 @@ +--- +# Copyright 2020 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/tripleo_nvdimm/molecule/default/tests/test_default.py b/tripleo_ansible/roles/tripleo_nvdimm/molecule/default/tests/test_default.py new file mode 100644 index 000000000..53b33d122 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_nvdimm/molecule/default/tests/test_default.py @@ -0,0 +1,40 @@ +# Copyright 2020 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. + + +import os +import json +import pytest +import testinfra.utils.ansible_runner + + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +def test_ndctl_is_installed(host): + ndctl = host.package("ndctl") + assert ndctl.is_installed + + +def test_namespace_is_created(host): + if not host.check_output('lsmod | grep libnvdimm | cut -d " " -f 1'): + pytest.skip("Skipping because this needs NVDIMM hardware") + pmem_ns = os.environ['TRIPLEO_NVDIMM_PMEM_NAMESPACES'] + ndctl_list_output = host.check_output('ndctl list') + namespaces = {ns.get('name') for ns in json.loads(ndctl_list_output)} + wanted_ns = [ns_name.split(':')[1] for ns_name in pmem_ns.split(',')] + for ns in wanted_ns: + assert ns in namespaces diff --git a/tripleo_ansible/roles/tripleo_nvdimm/molecule/default/verify.yml b/tripleo_ansible/roles/tripleo_nvdimm/molecule/default/verify.yml new file mode 100644 index 000000000..ede65b54e --- /dev/null +++ b/tripleo_ansible/roles/tripleo_nvdimm/molecule/default/verify.yml @@ -0,0 +1,15 @@ +--- +# Copyright 2020 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/tripleo_nvdimm/tasks/create_namespaces.yml b/tripleo_ansible/roles/tripleo_nvdimm/tasks/create_namespaces.yml new file mode 100644 index 000000000..795fcb01b --- /dev/null +++ b/tripleo_ansible/roles/tripleo_nvdimm/tasks/create_namespaces.yml @@ -0,0 +1,29 @@ +--- +# Copyright 2020 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: list current namespaces + shell: >- + ndctl list -X | jq ".[].name" + register: namespaces + changed_when: false +- name: create namespace + command: >- + ndctl create-namespace -s {{ input[0] }} -m devdax -M mem -n {{ input[1] }} + when: + - namespaces.stdout is defined + - input[1] not in namespaces.stdout + register: ret + changed_when: ret.rc == 0 diff --git a/tripleo_ansible/roles/tripleo_nvdimm/tasks/main.yml b/tripleo_ansible/roles/tripleo_nvdimm/tasks/main.yml new file mode 100644 index 000000000..698ea6df3 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_nvdimm/tasks/main.yml @@ -0,0 +1,57 @@ +--- +# Copyright 2020 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. + + +# "tripleo_nvdimm" will search for and load any operating system variable file + +- 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 + +- name: install dependencies + package: + name: "{{ pkgs }}" + state: present + vars: + pkgs: + - ndctl + - jq + +- name: look for libnvdimm kernel module + shell: | + lsmod | grep -q libnvdimm + register: nvdimm_kernel_mod + check_mode: false + failed_when: false + +- name: create namespaces + include_tasks: create_namespaces.yml + loop: "{{ tripleo_nvdimm_pmem_namespaces.split(',') }}" + vars: + input: "{{ item.split(':') }}" + when: + - nvdimm_kernel_mod.rc is defined + - nvdimm_kernel_mod.rc == 0 diff --git a/tripleo_ansible/roles/tripleo_nvdimm/vars/.gitkeep b/tripleo_ansible/roles/tripleo_nvdimm/vars/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/zuul.d/molecule.yaml b/zuul.d/molecule.yaml index 8afe8beec..39826025e 100644 --- a/zuul.d/molecule.yaml +++ b/zuul.d/molecule.yaml @@ -29,6 +29,7 @@ - tripleo-ansible-centos-8-molecule-tripleo_keystone_resources - tripleo-ansible-centos-8-molecule-tripleo_module_load - tripleo-ansible-centos-8-molecule-tripleo_nova_image_cache + - tripleo-ansible-centos-8-molecule-tripleo_nvdimm - tripleo-ansible-centos-8-molecule-tripleo_ovs_dpdk - tripleo-ansible-centos-8-molecule-tripleo_packages - tripleo-ansible-centos-8-molecule-tripleo_persist @@ -72,6 +73,7 @@ - tripleo-ansible-centos-8-molecule-tripleo_keystone_resources - tripleo-ansible-centos-8-molecule-tripleo_module_load - tripleo-ansible-centos-8-molecule-tripleo_nova_image_cache + - tripleo-ansible-centos-8-molecule-tripleo_nvdimm - tripleo-ansible-centos-8-molecule-tripleo_ovs_dpdk - tripleo-ansible-centos-8-molecule-tripleo_packages - tripleo-ansible-centos-8-molecule-tripleo_persist @@ -320,6 +322,13 @@ parent: tripleo-ansible-centos-8-base vars: tripleo_role_name: tripleo_nova_image_cache +- job: + files: + - ^tripleo_ansible/roles/tripleo_nvdimm/.* + name: tripleo-ansible-centos-8-molecule-tripleo_nvdimm + parent: tripleo-ansible-centos-8-base + vars: + tripleo_role_name: tripleo_nvdimm - job: files: - ^tripleo_ansible/roles/tripleo_ovs_dpdk/.*