From 855218ba52c8ee083b3a01d10656fdc46de26fad Mon Sep 17 00:00:00 2001 From: Lance Bragstad Date: Fri, 13 Mar 2020 12:04:13 -0500 Subject: [PATCH] Initialize repo and integrate zuul This patch: - adds a basic skeleton role for tripleo_ipa generated from molecule - trivial additions to .gitignore - adds molecule-requirements.txt - invokes molecule using tox - adds basic plumbing so that we can invoke tests using zuul and locally with some handy scripts Each entry above was originally its own patch. We're consolidating them into a single patch so that we can introduce zuul, which needs to verify patches before we can merge them. If you want to run tests locally, you can use the `scripts/run-local-test` script: $ bash scripts/run-local-test Which will setup dependencies from zuul, install a virtualenv, and invoke tox. Change-Id: If9446f5597d0150a2694e655dbb45475ce38a426 --- .gitignore | 11 ++++ README.rst | 15 +++++ molecule-requirements.txt | 2 + playbooks/prepare-test-host.yml | 71 +++++++++++++++++++++++ scripts/run-local-test | 29 +++++++++ setup.cfg | 16 +++++ setup.py | 19 ++++++ tests/hosts.ini | 1 + tox.ini | 17 ++++++ tripleo_ipa/.travis.yml | 29 +++++++++ tripleo_ipa/.yamllint | 33 +++++++++++ tripleo_ipa/README.md | 38 ++++++++++++ tripleo_ipa/defaults/main.yml | 2 + tripleo_ipa/handlers/main.yml | 2 + tripleo_ipa/meta/main.yml | 53 +++++++++++++++++ tripleo_ipa/molecule/default/INSTALL.rst | 22 +++++++ tripleo_ipa/molecule/default/converge.yml | 7 +++ tripleo_ipa/molecule/default/molecule.yml | 13 +++++ tripleo_ipa/molecule/default/verify.yml | 9 +++ tripleo_ipa/tasks/main.yml | 2 + tripleo_ipa/tests/inventory | 2 + tripleo_ipa/tests/test.yml | 5 ++ tripleo_ipa/vars/main.yml | 2 + zuul.d/base.yaml | 14 +++++ zuul.d/layout.yaml | 8 +++ zuul.d/playbooks/pre.yml | 35 +++++++++++ zuul.d/playbooks/run-local.yml | 15 +++++ zuul.d/playbooks/run.yml | 18 ++++++ 28 files changed, 490 insertions(+) create mode 100644 .gitignore create mode 100644 README.rst create mode 100644 molecule-requirements.txt create mode 100644 playbooks/prepare-test-host.yml create mode 100644 scripts/run-local-test create mode 100644 setup.cfg create mode 100644 setup.py create mode 100644 tests/hosts.ini create mode 100644 tox.ini create mode 100644 tripleo_ipa/.travis.yml create mode 100644 tripleo_ipa/.yamllint create mode 100644 tripleo_ipa/README.md create mode 100644 tripleo_ipa/defaults/main.yml create mode 100644 tripleo_ipa/handlers/main.yml create mode 100644 tripleo_ipa/meta/main.yml create mode 100644 tripleo_ipa/molecule/default/INSTALL.rst create mode 100644 tripleo_ipa/molecule/default/converge.yml create mode 100644 tripleo_ipa/molecule/default/molecule.yml create mode 100644 tripleo_ipa/molecule/default/verify.yml create mode 100644 tripleo_ipa/tasks/main.yml create mode 100644 tripleo_ipa/tests/inventory create mode 100644 tripleo_ipa/tests/test.yml create mode 100644 tripleo_ipa/vars/main.yml create mode 100644 zuul.d/base.yaml create mode 100644 zuul.d/layout.yaml create mode 100644 zuul.d/playbooks/pre.yml create mode 100644 zuul.d/playbooks/run-local.yml create mode 100644 zuul.d/playbooks/run.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..547b7c0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +# interpreted and compiled python files +*.py[cod] + +# Virtual environments and testing +.tox +.venv +.stestr +*.swp + +tripleo_ipa.egg-info/ +.eggs/ diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..baf0fd7 --- /dev/null +++ b/README.rst @@ -0,0 +1,15 @@ +=========== +tripleo-ipa +=========== + +This repository contains Ansible for use integrating TripleO with FreeIPA. + +Contributing +============ + +You can create an environment to develop locally using the following. + +.. code-block:: bash + + $ python3.7 -m virtualenv --system-site-packages .venv + $ .venv/bin/pip3 install -r molecule-requirements.txt diff --git a/molecule-requirements.txt b/molecule-requirements.txt new file mode 100644 index 0000000..6c0cb63 --- /dev/null +++ b/molecule-requirements.txt @@ -0,0 +1,2 @@ +docker +molecule>=3.0,<3.1 diff --git a/playbooks/prepare-test-host.yml b/playbooks/prepare-test-host.yml new file mode 100644 index 0000000..c00f030 --- /dev/null +++ b/playbooks/prepare-test-host.yml @@ -0,0 +1,71 @@ +--- +# 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. + +# This playbook contains things you need if you want to run tripleo_ipa tests +# locally. Note that zuul sets some of this stuff up automatically, so we don't +# need to invoke this specifically for zuul. + +- name: pre prepare + hosts: all + gather_facts: false + tasks: + - name: set basic user fact + fail: + msg: >- + The variable `ansible_user` set this option and try again. On the + CLI this can be defined with "-e ansible_user=${USER}" + when: + - ansible_user is undefined + + - name: set basic home fact + fail: + msg: >- + The variable `ansible_user_dir` set this option and try again. On + the CLI this can be defined with "-e ansible_user_dir=${HOME}" + when: + - ansible_user_dir is undefined + + - name: Ensure the user has a .ssh directory + file: + path: "{{ ansible_user_dir }}/.ssh" + state: directory + owner: "{{ ansible_user }}" + group: "{{ ansible_user }}" + mode: "0700" + + - name: Create ssh key pair + user: + name: "{{ ansible_user }}" + generate_ssh_key: true + ssh_key_bits: 2048 + ssh_key_file: "{{ ansible_user_dir }}/.ssh/id_rsa" + + - name: Slurp pub key + slurp: + src: "{{ ansible_user_dir ~ '/.ssh/id_rsa.pub' }}" + register: pub_key + + - name: Ensure can ssh to can connect to localhost + authorized_key: + user: "{{ ansible_user }}" + key: "{{ pub_key['content'] | b64decode }}" + + - name: Get the zuul/zuul-jobs repo + git: + repo: https://opendev.org/zuul/zuul-jobs + dest: "{{ ansible_user_dir }}/zuul-jobs" + version: master + force: true diff --git a/scripts/run-local-test b/scripts/run-local-test new file mode 100644 index 0000000..a804b06 --- /dev/null +++ b/scripts/run-local-test @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +# 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. + + +set -o pipefail +set -xeo + +export ANSIBLE_ROLES_PATH="${ANSIBLE_ROLES_PATH}:${HOME}/zuul-jobs/roles" +export PROJECT_DIR="$(dirname $(readlink -f ${BASH_SOURCE[0]}))/../" + +ansible-playbook -i "${PROJECT_DIR}/tests/hosts.ini" \ + -e "tripleo_src=$(realpath --relative-to="${HOME}" "${PROJECT_DIR}")" \ + -e "ansible_user=${USER}" \ + -e "ansible_user_dir=${HOME}" \ + "${PROJECT_DIR}/playbooks/prepare-test-host.yml" \ + "${PROJECT_DIR}/zuul.d/playbooks/run-local.yml" diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..59e56c2 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,16 @@ +[metadata] +name = tripleo_ipa +summary = Ansible assets for interacting with FreeIPA on behalf of TripleO +description-file = + README.rst + +author = RedHat +home-page = https://opendev.org/x/tripleo-ipa +classifier = + License :: OSI Approved :: Apache Software License + Development Status :: 2 - Pre-Alpha + Intended Audience :: Developers + Intended Audience :: System Administrators + Intended Audience :: Information Technology + Topic :: Utilities + diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..6a931a6 --- /dev/null +++ b/setup.py @@ -0,0 +1,19 @@ +# Copyright 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 setuptools + +setuptools.setup( + setup_requires=['pbr'], + pbr=True) diff --git a/tests/hosts.ini b/tests/hosts.ini new file mode 100644 index 0000000..2828052 --- /dev/null +++ b/tests/hosts.ini @@ -0,0 +1 @@ +test ansible_connection=local ansible_host=localhost diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..a11cf20 --- /dev/null +++ b/tox.ini @@ -0,0 +1,17 @@ +[tox] +minversion = 2.0 +# add docs to the list of environments once we actually have docs to generate +envlist = molecule +skipdist = True + +[testenv] +usedevelop = True +install_command = pip install -c{env:UPPER_CONSTRAINTS_FILE:https://opendev.org/openstack/requirements/raw/branch/master/upper-constraints.txt} {opts} {packages} +passenv = * +sitepackages = True +deps = + -r {toxinidir}/molecule-requirements.txt +changedir = {toxinidir}/tripleo_ipa +commands = molecule test --all +whitelist_externals = + tox diff --git a/tripleo_ipa/.travis.yml b/tripleo_ipa/.travis.yml new file mode 100644 index 0000000..36bbf62 --- /dev/null +++ b/tripleo_ipa/.travis.yml @@ -0,0 +1,29 @@ +--- +language: python +python: "2.7" + +# Use the new container infrastructure +sudo: false + +# Install ansible +addons: + apt: + packages: + - python-pip + +install: + # Install ansible + - pip install ansible + + # Check ansible version + - ansible --version + + # Create ansible.cfg with correct roles_path + - printf '[defaults]\nroles_path=../' >ansible.cfg + +script: + # Basic role syntax check + - ansible-playbook tests/test.yml -i tests/inventory --syntax-check + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ \ No newline at end of file diff --git a/tripleo_ipa/.yamllint b/tripleo_ipa/.yamllint new file mode 100644 index 0000000..8827676 --- /dev/null +++ b/tripleo_ipa/.yamllint @@ -0,0 +1,33 @@ +--- +# Based on ansible-lint config +extends: default + +rules: + braces: + max-spaces-inside: 1 + level: error + brackets: + max-spaces-inside: 1 + level: error + colons: + max-spaces-after: -1 + level: error + commas: + max-spaces-after: -1 + level: error + comments: disable + comments-indentation: disable + document-start: disable + empty-lines: + max: 3 + level: error + hyphens: + level: error + indentation: disable + key-duplicates: enable + line-length: disable + new-line-at-end-of-file: disable + new-lines: + type: unix + trailing-spaces: disable + truthy: disable diff --git a/tripleo_ipa/README.md b/tripleo_ipa/README.md new file mode 100644 index 0000000..b2dc286 --- /dev/null +++ b/tripleo_ipa/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +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: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +Apache 2.0 + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/tripleo_ipa/defaults/main.yml b/tripleo_ipa/defaults/main.yml new file mode 100644 index 0000000..f0d7148 --- /dev/null +++ b/tripleo_ipa/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for tripleo_ipa \ No newline at end of file diff --git a/tripleo_ipa/handlers/main.yml b/tripleo_ipa/handlers/main.yml new file mode 100644 index 0000000..94606e9 --- /dev/null +++ b/tripleo_ipa/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for tripleo_ipa \ No newline at end of file diff --git a/tripleo_ipa/meta/main.yml b/tripleo_ipa/meta/main.yml new file mode 100644 index 0000000..4d371b7 --- /dev/null +++ b/tripleo_ipa/meta/main.yml @@ -0,0 +1,53 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: Apache-2.0 + + min_ansible_version: 2.9 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # 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: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. + diff --git a/tripleo_ipa/molecule/default/INSTALL.rst b/tripleo_ipa/molecule/default/INSTALL.rst new file mode 100644 index 0000000..6a44bde --- /dev/null +++ b/tripleo_ipa/molecule/default/INSTALL.rst @@ -0,0 +1,22 @@ +******* +Docker driver installation guide +******* + +Requirements +============ + +* Docker Engine + +Install +======= + +Please refer to the `Virtual environment`_ documentation for installation best +practices. If not using a virtual environment, please consider passing the +widely recommended `'--user' flag`_ when invoking ``pip``. + +.. _Virtual environment: https://virtualenv.pypa.io/en/latest/ +.. _'--user' flag: https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site + +.. code-block:: bash + + $ pip install 'molecule[docker]' diff --git a/tripleo_ipa/molecule/default/converge.yml b/tripleo_ipa/molecule/default/converge.yml new file mode 100644 index 0000000..2dda268 --- /dev/null +++ b/tripleo_ipa/molecule/default/converge.yml @@ -0,0 +1,7 @@ +--- +- name: Converge + hosts: all + tasks: + - name: "Include tripleo_ipa" + include_role: + name: "tripleo_ipa" diff --git a/tripleo_ipa/molecule/default/molecule.yml b/tripleo_ipa/molecule/default/molecule.yml new file mode 100644 index 0000000..aafdc9d --- /dev/null +++ b/tripleo_ipa/molecule/default/molecule.yml @@ -0,0 +1,13 @@ +--- +dependency: + name: galaxy +driver: + name: docker +platforms: + - name: instance + image: docker.io/pycontribs/centos:7 + pre_build_image: true +provisioner: + name: ansible +verifier: + name: ansible diff --git a/tripleo_ipa/molecule/default/verify.yml b/tripleo_ipa/molecule/default/verify.yml new file mode 100644 index 0000000..a82dd6f --- /dev/null +++ b/tripleo_ipa/molecule/default/verify.yml @@ -0,0 +1,9 @@ +--- +# This is an example playbook to execute Ansible tests. + +- name: Verify + hosts: all + tasks: + - name: Example assertion + assert: + that: true diff --git a/tripleo_ipa/tasks/main.yml b/tripleo_ipa/tasks/main.yml new file mode 100644 index 0000000..c1840e6 --- /dev/null +++ b/tripleo_ipa/tasks/main.yml @@ -0,0 +1,2 @@ +--- +# tasks file for tripleo_ipa \ No newline at end of file diff --git a/tripleo_ipa/tests/inventory b/tripleo_ipa/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/tripleo_ipa/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/tripleo_ipa/tests/test.yml b/tripleo_ipa/tests/test.yml new file mode 100644 index 0000000..6e3f673 --- /dev/null +++ b/tripleo_ipa/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - tripleo_ipa \ No newline at end of file diff --git a/tripleo_ipa/vars/main.yml b/tripleo_ipa/vars/main.yml new file mode 100644 index 0000000..1ed37c4 --- /dev/null +++ b/tripleo_ipa/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for tripleo_ipa \ No newline at end of file diff --git a/zuul.d/base.yaml b/zuul.d/base.yaml new file mode 100644 index 0000000..ab6cdef --- /dev/null +++ b/zuul.d/base.yaml @@ -0,0 +1,14 @@ +--- +- job: + description: tripleo-ipa molecule job + name: tripleo-ipa-centos-8-molecule + nodeset: centos-8 + parent: base + success-url: "reports.html" + failure-url: "reports.html" + pre-run: + - zuul.d/playbooks/pre.yml + run: + - zuul.d/playbooks/run.yml + timeout: 1800 + voting: true diff --git a/zuul.d/layout.yaml b/zuul.d/layout.yaml new file mode 100644 index 0000000..fe42d63 --- /dev/null +++ b/zuul.d/layout.yaml @@ -0,0 +1,8 @@ +--- +- project: + check: + jobs: + - tripleo-ipa-centos-8-molecule + gate: + jobs: + - tripleo-ipa-centos-8-molecule diff --git a/zuul.d/playbooks/pre.yml b/zuul.d/playbooks/pre.yml new file mode 100644 index 0000000..be0b7ab --- /dev/null +++ b/zuul.d/playbooks/pre.yml @@ -0,0 +1,35 @@ +--- + +- hosts: all + pre_tasks: + - name: Set project path fact + set_fact: + tripleo_ipa_project_path: "{{ ansible_user_dir }}/{{ zuul.projects['opendev.org/x/tripleo-ipa'].src_dir }}" + + - name: Ensure output dirs + file: + path: "{{ ansible_user_dir }}/zuul-output/logs" + state: directory + + - name: Setup test-python + pip: + requirements: "{{ tripleo_ipa_project_path }}/molecule-requirements.txt" + virtualenv: "{{ ansible_user_dir }}/test-python" + virtualenv_site_packages: true + + - name: Display test-python virtualenv package versions + shell: |- + . {{ ansible_user_dir }}/test-python/bin/activate + pip freeze + + # NOTE(cloudnull): This is being done because docker is not supported on RHEL-8 + # and tests within this repo still require docker. + - name: Manually install containerd.io + become: true + package: + name: https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm + when: + - (ansible_distribution_major_version | int) >= 8 + roles: + # docker is needed by multiple molecule scenarios + - role: install-docker diff --git a/zuul.d/playbooks/run-local.yml b/zuul.d/playbooks/run-local.yml new file mode 100644 index 0000000..678c492 --- /dev/null +++ b/zuul.d/playbooks/run-local.yml @@ -0,0 +1,15 @@ +--- + +- hosts: all + tasks: + - name: set basic zuul fact + set_fact: + zuul: + projects: + "opendev.org/x/tripleo-ipa": + src_dir: "{{ tripleo_src }}" + ansible_connection: local + +- import_playbook: pre.yml + +- import_playbook: run.yml diff --git a/zuul.d/playbooks/run.yml b/zuul.d/playbooks/run.yml new file mode 100644 index 0000000..18e0303 --- /dev/null +++ b/zuul.d/playbooks/run.yml @@ -0,0 +1,18 @@ +--- + +- hosts: all + environment: + ANSIBLE_LOG_PATH: "{{ ansible_user_dir }}/zuul-output/logs/ansible-execution.log" + pre_tasks: + - name: Set project path fact + set_fact: + tripleo_ipa_project_path: "{{ ansible_user_dir }}/{{ zuul.projects['opendev.org/x/tripleo-ipa'].src_dir }}" + + tasks: + - name: Run role test job + shell: |- + . {{ ansible_user_dir }}/test-python/bin/activate + tox + args: + chdir: "{{ tripleo_ipa_project_path }}" + executable: /bin/bash