redhat-cop / openshift-applier

Used to apply OpenShift objects to an OpenShift Cluster
Apache License 2.0
102 stars 61 forks source link

Unable to test via molecule own role with a dependency to openshift-applier #112

Open matihost opened 5 years ago

matihost commented 5 years ago

If own role uses molecule and uses openshift-applier dependency to - the "openshift-applier" role is run with empty results.

The reason is the openshift-applier git repository equals to the name of the role "openshift-applier" So even adding :

provisioner:
  name: ansible
  log: True
  env:
    ANSIBLE_ROLES_PATH: /tmp/molecule/role-under-test/default/roles/openshift-applier/roles

does not help because molecule append ANSIBLE_ROLES_PATH to ansible rolepath at the end. Since /tmp/molecule/role-under-test/default/roles is earlier on the role path, Ansiblefinds /tmp/molecule/role-under-test/default/roles/ansible-applier directory - which is not valid Ansible role - and it assumes role is empty.

So when Ansible looks for "openshift-applier" role, it finds it earielir (and find the git repository name) and assumes empty.

The problem could be solved in various ways:

Workaround is:

Sample makefile to automate stuff:

test: clean get-dependencies ## Test own role
    molecule test

get-dependencies: clean ## download galaxy dependencies
    ansible-galaxy install -r requirements.yml -p galaxy -f

clean:
    -rm -rf galaxy

where molecule.yml is the following:

# cannot use with Ansible role where git role is in subdirectory, and role name equals git repo (for example https://github.com/redhat-cop/openshift-applier.git)
#dependency:
#  name: galaxy
#  options:
#    role-file: requirements.yml
#dependency:
#  name: shell
#  command: gilt overlay
#  options:
#    debug: True
driver:
  name: docker
lint:
  name: yamllint
  options:
    config-file: .yamllint
platforms:
  - name: instance
    image: centos:7
provisioner:
  name: ansible
  log: True
  env:
    ANSIBLE_ROLES_PATH: ../../galaxy/openshift-applier/roles
  lint:
    name: ansible-lint
    options:
      force-color: True
      c: .ansible-lint
  options:
    v: true
scenario:
  name: default
  test_sequence:
    - lint
    - destroy
    #- dependency
    - syntax
    - create
    - prepare
    - converge
    - idempotence
    - side_effect
    - verify
    - destroy

verifier:
  name: testinfra
  lint:
    name: flake8