From 43b7772c17b9bdc90fdae32f34222cb8aa755cc2 Mon Sep 17 00:00:00 2001 From: jgoutin Date: Mon, 4 Nov 2019 15:27:04 +0100 Subject: [PATCH] Add source installation + requirements installation --- .ansible-lint | 2 + .yamllint | 11 - README.md | 35 ++- defaults/main.yml | 26 ++- meta/main.yml | 3 +- molecule/default/Dockerfile.j2 | 12 +- molecule/default/molecule.yml | 46 +++- molecule/default/tests/test_default.py | 21 +- tasks/main.yml | 299 +++++++++++++++++++++++-- 9 files changed, 397 insertions(+), 58 deletions(-) create mode 100644 .ansible-lint delete mode 100644 .yamllint diff --git a/.ansible-lint b/.ansible-lint new file mode 100644 index 0000000..670d097 --- /dev/null +++ b/.ansible-lint @@ -0,0 +1,2 @@ +skip_list: + - '304' # Detect CMake option "-DPYTHON3=ON" and environment variable. diff --git a/.yamllint b/.yamllint deleted file mode 100644 index ad0be76..0000000 --- a/.yamllint +++ /dev/null @@ -1,11 +0,0 @@ -extends: default - -rules: - braces: - max-spaces-inside: 1 - level: error - brackets: - max-spaces-inside: 1 - level: error - line-length: disable - truthy: disable diff --git a/README.md b/README.md index c783a99..5f1d7f1 100644 --- a/README.md +++ b/README.md @@ -15,22 +15,43 @@ The role requires to be run as root on the target host. Role Variables -------------- +Installation: +Accelize DRM installation. +* **accelize_drm_python**: If `true`, install the Python library and systemd service. Default to `true`. +* **accelize_drm_devel**: If `true`, install the development C/C++ headers. Default to `false`. +* **accelize_repository_channel**: Accelize Repository channel to use: `stable` or `prerelease`. Default to `stable`. +* **accelize_drm_from_source**: If `true`, install from sources instead of from package. Default to `false`. + +DRM Service: +Accelize DRM systemd service configuration. +* **accelize_drm_service_started**: If `true`, start the DRM service and enable it at boot (Require *accelize_drm_python* to `true`). Default to `true`. +* **accelize_drm_disabled**: If `true`, do not license the FPGA, only program FPGA at service start. Default to `false`. * **fpga_slots**: List of FPGA slots to manage. Default to `[0]`. * **fpga_image**: List of image to program on FPGA slots. Default to `[]`. -* **accelize_drm_service_started**: If `true`, start the DRM service and enable it at boot. Default to `true`. -* **accelize_drm_disabled**: If `true`, do not license the FPGA, only program FPGA at service start. Default to `false`. * **accelize_drm_driver_name**: FPGA driver name to use with the Accelize DRM service. Default to `aws_f1`. + +DRM Configuration: +Accelize DRM configuration files. * **accelize_drm_cred_src**: Path to the local `cred.json` file to transfer to the host. Default to `cred.json`. -* **accelize_drm_cred_dst**: Destination path og the `cred.json` file on the target host. Default to `/root/.accelize_drm/cred.json`. +* **accelize_drm_cred_dst**: Destination path of the `cred.json` file on the target host. Default to `/root/.accelize_drm/cred.json`. * **accelize_drm_conf_src**: Path to the local `conf.json` file to transfer to the host. Default to `conf.json`. -* **accelize_drm_conf_dst**: Destination path og the `conf.json` file on the target host. Default to `/etc/accelize_drm/conf.json`. -* **accelize_repository_channel**: Accelize Repository channel to use: `stable` or `prerelease`. Default to `stable`. +* **accelize_drm_conf_dst**: Destination path of the `conf.json` file on the target host. Default to `/etc/accelize_drm/conf.json`. + +Source installation, test & build requirements: +Installation of Accelize DRM build and testing dependencies. Mainly intended to DRM library developers. +* **accelize_drm_git_clone**: If specified, Git clone Accelize DRM to the specified path. Default to `''`. +* **accelize_drm_git_ref**: branch, tag or commit ID to use for source installation and git clone. Default to `master`. +* **accelize_drm_test**: If `true`, install tests dependencies. Default to `false`. +* **accelize_drm_coverage**: If `true`, install coverage dependencies. Default to `false`. +* **accelize_drm_abi_check**: If `true`, install ABI check dependencies. Default to `false`. +* **accelize_drm_build**: If `true`, install build dependencies. Default to `false`. +* **accelize_drm_build_doc**: If `true`, install documentation build dependencies. Default to `false`. +* **accelize_drm_build_package**: If `true`, install packages build & signature dependencies. Default to `false`. +* **accelize_drm_no_install**: If `true`, does not install Accelize DRM, only prepare the environment. Default to `false`. Example Playbook ---------------- -Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: - ```yaml - hosts: servers become: true diff --git a/defaults/main.yml b/defaults/main.yml index a9d892f..10719a6 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,6 +1,11 @@ --- -# Accelize repository configuration +# Accelize DRM packages +accelize_drm_python: true +accelize_drm_devel: false + +# Accelize repository or source configuration accelize_repository_channel: stable +accelize_drm_from_source: false # Accelize DRM credential and configuration files accelize_drm_cred_src: cred.json @@ -20,3 +25,22 @@ accelize_drm_disabled: false # FPGA configuration: fpga_image: [] fpga_slots: [0] + +# Accelize DRM build configuration +accelize_drm_git_ref: 'master' +accelize_drm_no_install: false +accelize_drm_test: false +accelize_drm_build: false +accelize_drm_build_doc: false +accelize_drm_build_package: false +accelize_drm_coverage: false +accelize_drm_abi_check: false + +# Internal variables +_python3: "{{ (ansible_os_family == 'RedHat' and + ansible_distribution_major_version == '7' ) | + ternary('python36', 'python3') }}" +_devel: "{{ (ansible_os_family == 'RedHat') | ternary('devel', 'dev') }}" +_pip_args: "--no-cache-dir --disable-pip-version-check{{ + (ansible_distribution_major_version == '7' ) | + ternary(' --prefix /usr', '') }}" diff --git a/meta/main.yml b/meta/main.yml index 21d402f..3276629 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -10,6 +10,7 @@ galaxy_info: - name: EL versions: - 7 + - 8 - name: Ubuntu versions: - xenial @@ -20,8 +21,8 @@ galaxy_info: - buster - name: Fedora versions: - - 29 - 30 + - 31 galaxy_tags: - system - fpga diff --git a/molecule/default/Dockerfile.j2 b/molecule/default/Dockerfile.j2 index e6aa95d..dbf9b13 100644 --- a/molecule/default/Dockerfile.j2 +++ b/molecule/default/Dockerfile.j2 @@ -1,14 +1,10 @@ -# Molecule managed - {% 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 && dnf clean all; \ - elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash && 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 && zypper clean -a; \ - elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \ - elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python python-setuptools sudo bash ca-certificates && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python3 python3-setuptools sudo python3-devel python3-dnf bash && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python python-setuptools sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ +fi diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 2a6174c..b3e6e02 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -11,14 +11,8 @@ platforms: - name: ubuntu_bionic image: ubuntu:bionic privileged: true - - name: ubuntu_xenial - image: ubuntu:xenial - privileged: true - - name: debian_stretch - image: debian:stretch - privileged: true - - name: debian_buster - image: debian:buster + - name: ubuntu_bionic_deps + image: ubuntu:bionic privileged: true - name: ubuntu_latest image: ubuntu:latest @@ -26,13 +20,45 @@ platforms: - name: centos_7 image: centos:7 privileged: true - - name: fedora_29 - image: fedora:29 + - name: centos_7_from_src + image: centos:7 + privileged: true + - name: centos_7_deps + image: centos:7 + privileged: true + - name: fedora_30 + image: fedora:30 privileged: true + provisioner: name: ansible lint: name: ansible-lint + inventory: + host_vars: + centos_7: + accelize_drm_devel: true + centos_7_from_src: + accelize_drm_from_source: true + accelize_drm_git_clone: /opt + centos_7_deps: + accelize_drm_no_install: true + accelize_drm_test: true + accelize_drm_build: true + accelize_drm_build_doc: true + accelize_drm_build_package: true + accelize_drm_coverage: true + accelize_drm_abi_check: true + ubuntu_bionic: + accelize_drm_devel: true + ubuntu_bionic_deps: + accelize_drm_no_install: true + accelize_drm_test: true + accelize_drm_build: true + accelize_drm_build_doc: true + accelize_drm_build_package: true + accelize_drm_coverage: true + accelize_drm_abi_check: true verifier: name: testinfra lint: diff --git a/molecule/default/tests/test_default.py b/molecule/default/tests/test_default.py index 52c4fe5..35d2e7a 100644 --- a/molecule/default/tests/test_default.py +++ b/molecule/default/tests/test_default.py @@ -1,5 +1,6 @@ +"""Test Ansible""" import os - +import pytest import testinfra.utils.ansible_runner testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( @@ -10,15 +11,33 @@ def test_packages_installed(host): """ Test that packages are installed """ + if (host.ansible.get_variables().get('accelize_drm_no_install') or + host.ansible.get_variables().get('accelize_drm_from_source')): + pytest.skip('No packages installed') + assert host.package("libaccelize-drm").is_installed assert (host.package("python3-accelize-drm").is_installed or host.package("python36-accelize-drm").is_installed) +def test_include_installed(host): + """ + Test that includes are installed + """ + if (not host.ansible.get_variables().get('accelize_drm_devel') and + not host.ansible.get_variables().get('accelize_drm_from_source')): + pytest.skip('No headers installed') + + assert host.file("/usr/include/accelize/drm.h").exists + + def test_service_configuration_installed(host): """ Test that service configuration file is installed """ + if not host.ansible.get_variables().get('accelize_drm_python'): + pytest.skip('No service installed') + conf = host.file( '/etc/systemd/system/accelize_drm.service.d/accelize_drm.conf') assert conf.exists diff --git a/tasks/main.yml b/tasks/main.yml index 9eba7ec..8037d40 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -3,18 +3,19 @@ - name: Ensure minimal APT dependencies are installed apt: - name: "{{ packages }}" - state: present - install_recommends: false - update_cache: true - vars: - packages: + name: - apt-transport-https - gnupg - software-properties-common + state: present + install_recommends: false + update_cache: true retries: 10 delay: 1 - when: ansible_os_family == "Debian" + when: + - ansible_os_family == "Debian" + - not (accelize_drm_from_source | bool) + - not (accelize_drm_no_install | bool) - name: Add Accelize DEB repository key apt_key: @@ -24,7 +25,10 @@ register: add_repository_key retries: 10 delay: 1 - when: ansible_os_family == "Debian" + when: + - ansible_os_family == "Debian" + - not (accelize_drm_from_source | bool) + - not (accelize_drm_no_install | bool) - name: Add Accelize DEB repository apt_repository: @@ -34,34 +38,287 @@ update_cache: true retries: 10 delay: 1 - when: ansible_os_family == "Debian" + when: + - ansible_os_family == "Debian" + - not (accelize_drm_from_source | bool) + - not (accelize_drm_no_install | bool) - name: Add Accelize RPM repository get_url: - url: "https://accelize.s3.amazonaws.com/rpm/accelize_{{ accelize_repository_channel }}.repo" + url: "https://accelize.s3.amazonaws.com/rpm/\ + accelize_{{ accelize_repository_channel }}.repo" dest: "/etc/yum.repos.d/accelize_{{ accelize_repository_channel }}.repo" - when: ansible_os_family == "RedHat" retries: 10 delay: 1 + when: + - ansible_os_family == "RedHat" + - not (accelize_drm_from_source | bool) + - not (accelize_drm_no_install | bool) -- name: Ensure Accelize EPEL repository is installed on CentOS/RHEL 7 +- name: Ensure Accelize EPEL repository is installed on CentOS/RHEL package: name: epel-release state: present - when: ansible_os_family == "RedHat" and ansible_distribution_major_version == "7" retries: 10 delay: 1 + when: + - ansible_os_family == "RedHat" + - ansible_distribution_major_version | int <= 8 - name: Ensure Accelize DRM library is installed package: - name: "{{ packages }}" + name: libaccelize-drm state: present - vars: - packages: - - libaccelize-drm - - "{{ (ansible_os_family == 'RedHat' and ansible_distribution_major_version == '7' )| ternary('python36-accelize-drm', 'python3-accelize-drm') }}" retries: 10 delay: 1 + when: + - not (accelize_drm_from_source | bool) + - not (accelize_drm_no_install | bool) + +- name: Ensure Accelize DRM Python library is installed + package: + name: "{{ _python3 }}-accelize-drm" + state: present + retries: 10 + delay: 1 + when: + - accelize_drm_python | bool + - not (accelize_drm_from_source | bool) + - not (accelize_drm_no_install | bool) + +- name: Ensure Accelize DRM developpement package is installed + package: + name: "libaccelize-drm-{{ _devel }}" + state: present + retries: 10 + delay: 1 + when: + - accelize_drm_devel | bool + - not (accelize_drm_from_source | bool) + - not (accelize_drm_no_install | bool) + +- name: Ensure minimal build dependencies are installed + apt: + name: + - git + - g++ + - libcurl4-openssl-dev + - libjsoncpp-dev + - make + - pkg-config + - python3-pip + state: present + install_recommends: false + retries: 10 + delay: 1 + when: + - ansible_os_family == "Debian" + - (accelize_drm_from_source | bool) or (accelize_drm_build | bool) + +- name: Ensure minimal build dependencies are installed + package: + name: + - git + - gcc + - gcc-c++ + - jsoncpp-devel + - libcurl-devel + - make + - "{{ _python3 }}-pip" + state: present + retries: 10 + delay: 1 + when: + - ansible_os_family == "RedHat" + - (accelize_drm_from_source | bool) or (accelize_drm_build | bool) + +- name: Ensure CMake is installed + pip: + name: cmake + executable: pip3 + extra_args: "{{ _pip_args }}" + retries: 10 + delay: 1 + when: (accelize_drm_from_source | bool) or (accelize_drm_build | bool) + +- name: Ensure Python build dependencies are installed + package: + name: "{{ _python3 }}-{{ _devel }}" + state: present + retries: 10 + delay: 1 + when: + - (accelize_drm_from_source | bool) or (accelize_drm_build | bool) + - accelize_drm_python | bool + +- name: Ensure Python build dependencies are installed from PIP + pip: + name: + - setuptools + - wheel + - cython + executable: pip3 + extra_args: "{{ _pip_args }}" + retries: 10 + delay: 1 + when: + - (accelize_drm_from_source | bool) or (accelize_drm_build | bool) + - accelize_drm_python | bool + +- name: Ensure packaging dependencies are installed + apt: + name: + - dpkg-dev + - file + - dpkg-sig + - gnupg + state: present + install_recommends: false + retries: 10 + delay: 1 + when: + - ansible_os_family == "Debian" + - accelize_drm_build_package | bool + +- name: Ensure packaging dependencies are installed + package: + name: + - rpm-build + - rpm-sign + - gnupg + state: present + retries: 10 + delay: 1 + when: + - ansible_os_family == "RedHat" + - accelize_drm_build_package | bool + +- name: Ensure Doxygen is installed + package: + name: doxygen + state: present + retries: 10 + delay: 1 + when: + - accelize_drm_build_doc | bool + - ansible_distribution_major_version != '8' + +- name: Ensure Doxygen is installed + dnf: + name: doxygen + state: present + enablerepo: PowerTools + retries: 10 + delay: 1 + when: + - accelize_drm_build_doc | bool + - ansible_os_family == "RedHat" + - ansible_distribution_major_version == '8' + +- name: Ensure Sphinx is installed + pip: + name: + - sphinx + - breathe + - sphinx_rtd_theme + executable: pip3 + extra_args: "{{ _pip_args }}" + retries: 10 + delay: 1 + when: accelize_drm_build_doc | bool + +- name: Ensure test dependencies are installed + pip: + name: + - pytest + - tox + executable: pip3 + extra_args: "{{ _pip_args }}" + retries: 10 + delay: 1 + when: accelize_drm_test | bool + +- name: Ensure C/C++ coverage dependencies are installed + package: + name: lcov + retries: 10 + delay: 1 + when: accelize_drm_coverage | bool + +- name: Ensure Python coverage dependencies are installed + pip: + name: pytest-cov + executable: pip3 + extra_args: "{{ _pip_args }}" + retries: 10 + delay: 1 + when: accelize_drm_coverage | bool + +- name: Ensure ABI check dependencies are installed + package: + name: + - abi-dumper + - abi-compliance-checker + retries: 10 + delay: 1 + when: accelize_drm_abi_check | bool + +- name: Create Accelize DRM temporary Git clone directory + tempfile: + state: directory + prefix: accelize_drm_ + register: accelize_drm_tmp + when: + - accelize_drm_git_clone is not defined + - accelize_drm_from_source | bool + changed_when: false + +- name: Update Accelize DRM Git clone directory path + set_fact: accelize_drm_git_clone="{{ accelize_drm_tmp.path }}" + when: + - accelize_drm_git_clone is not defined + - accelize_drm_tmp.path is defined + +- name: Ensure Accelize DRM Git repository is cloned + git: + repo: 'https://github.com/Accelize/drmlib.git' + dest: "{{ accelize_drm_git_clone }}" + version: "{{ accelize_drm_git_ref }}" + depth: 1 + recursive: true + retries: 10 + delay: 1 + when: accelize_drm_git_clone is defined + +- name: Ensure Accelize DRM build directory exists + file: + path: "{{ accelize_drm_git_clone }}/build" + state: directory + when: accelize_drm_from_source | bool + +- name: Ensure Accelize DRM is installed from sources + command: "{{ item.command }}" + with_items: + # Use "/usr" prefix to install in same path as packages + - command: "cmake {{ accelize_drm_python | bool | + ternary('-DPYTHON3=ON ', '') }}\ + -Wno-dev -DCMAKE_INSTALL_PREFIX:PATH=/usr .." + creates: "{{ accelize_drm_git_clone }}/build/Makefile" + - command: make -j + creates: "{{ accelize_drm_git_clone }}/build/libaccelize_drm.so" + - command: make install + creates: /usr/include/accelize/drm.h + args: + chdir: "{{ accelize_drm_git_clone }}/build" + creates: "{{ item.creates }}" + when: accelize_drm_from_source | bool + +- name: Clean up Accelize DRM temporary clone directory + file: + path: "{{ accelize_drm_tmp.path }}" + state: absent + when: accelize_drm_tmp.path is defined + changed_when: false - name: Ensure Accelize DRM credentials parent directory exists file: @@ -87,15 +344,19 @@ file: path: /etc/systemd/system/accelize_drm.service.d state: directory + when: accelize_drm_python | bool - name: Configure Accelize DRM service template: src: accelize_drm.conf.j2 dest: /etc/systemd/system/accelize_drm.service.d/accelize_drm.conf + when: accelize_drm_python | bool - name: Ensure Accelize DRM service is started and enabled at boot service: name: accelize_drm state: started enabled: true - when: accelize_drm_service_started | bool + when: + - accelize_drm_service_started | bool + - accelize_drm_python | bool