Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: introduce unit testing of roles with Molecule #162

Merged
merged 13 commits into from
Apr 15, 2020
Merged

ci: introduce unit testing of roles with Molecule #162

merged 13 commits into from
Apr 15, 2020

Conversation

strus38
Copy link
Contributor

@strus38 strus38 commented Apr 10, 2020

  • Start with roles time and dns_server
  • Added molecule lint/converge
  • Remove unnecessary empty lines to pass the linter phase

@btravouillon btravouillon self-requested a review April 10, 2020 21:05
Copy link
Member

@btravouillon btravouillon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @strus38,

Thank you for the PR. That's a huge work.

Almost all molecule test will failed if run automatically since roles needs some rework especially on default values, but this should be part of separated PR.

Indeed this is something I noticed a couple of days ago, most if not all of our default parameters are not defined in defaults/main.yml. PRs should come soon.

Force LF instead of CRLF

Do you mean force CRLF instead of LF? It looks like you changed line-endings from LF to CRLF. Anyway, you can't change the line-endings like that, it would need to be discussed first. :-)

Remove unecessary empty lines to pass the linter phase

Nice catch! Our static code analysis runs ansible-lint, but not yamllint. It may need a separate PR however. (check fc2f313 to see how I made ansible-lint happy before enabling static code analysis)

Overall this is very interesting and I will test this as soon as possible! I'm wondering if it could be easier to introduce support of molecule with a single role first, to see how it behaves and how we can integrate it with GitHub actions.
Also, I don't understand why the test_hosts_file(host) is defined in all the modules?

Finally, you need to configure your git (Author is root <root@LAPTOP-063FLOTR.localdomain>):

$ git commit --amend --author="Author Name <email@address.com>" --no-edit

@btravouillon
Copy link
Member

By the way, the cause of the conflicts is because your commit is not on top of master:

$ git log --oneline --no-merges --name-only strus38/feature/molecule..master 
629db3f (HEAD -> master, origin/master, origin/HEAD) [advanced_dhcp_sever] remove references to ntp_ip variable (#153)
resources/documentation/configure_bluebanquise.rst
resources/examples/multi_icebergs_cluster/inventory/group_vars/all/networks/ice1-1.yml
resources/examples/multi_icebergs_cluster/inventory/group_vars/all/networks/ice2-1.yml
resources/examples/multi_icebergs_cluster/inventory/group_vars/all/networks/ice3-1.yml
resources/examples/multi_icebergs_cluster/inventory/group_vars/all/networks/ice3-2.yml
roles/advanced-core/advanced_dhcp_server/templates/dhcpd.networks.conf.j2
3a34479 fix: install jinja2 macros in rpm
bluebanquise.spec
fed7da3 fix: require clustershell in specfile
bluebanquise.spec
f7ffaf0 Fix: Adding missing role Ansible
roles/core/ansible/readme.rst
roles/core/ansible/tasks/main.yml

@strus38
Copy link
Contributor Author

strus38 commented Apr 11, 2020 via email

@strus38
Copy link
Contributor Author

strus38 commented Apr 11, 2020

Hi

I fixed some of your requests:

  • change root to my id
  • re-sync with master to avoid conflicts
  • the dos2unix had to be passed on all for yamlint/ansible-lint to pass on the yaml files (so I did not cganged that)
  • the test_hosts_file(host) is there by default when you init molecule within a role: molecule init scenario -d docker --verifier-name testinfra, but as you can see, this part is not called yet since the 'verifier' phase is currently disabled in molecule since none of the role are currently running correctly in the converge phase because of lack of default variables. So, I want to keep that to help next people an exemple of what they have to do in such file.

If that is all, I guess you can attempt another review. Thanks.

@strus38
Copy link
Contributor Author

strus38 commented Apr 11, 2020

Note: on windows10 WSL running Ubuntu 18.04, you must define in your Ubuntu bash:
git config --global core.autocrlf input to prevent LF/CRLF issues.

So I am reworking the PR to just validate the approach on 2 roles.

@strus38 strus38 closed this Apr 11, 2020
@btravouillon btravouillon reopened this Apr 11, 2020
Copy link
Member

@btravouillon btravouillon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice change, thanks!
Until now, we were defining default values in the examples inventories. This PR demonstrates we should use Ansible Roles mechanism and define the default values in the role (defaults/main.yml). Will add some reviewers to get feedback.

roles/core/time/handlers/main.yml Outdated Show resolved Hide resolved
roles/core/time/molecule/default/converge.yml Outdated Show resolved Hide resolved
roles/core/time/molecule/default/molecule.yml Show resolved Hide resolved
roles/core/time/molecule/default/molecule.yml Show resolved Hide resolved
roles/core/time/molecule/default/molecule.yml Show resolved Hide resolved
roles/core/time/tasks/main.yml Outdated Show resolved Hide resolved
roles/core/time/tasks/main.yml Outdated Show resolved Hide resolved
roles/core/time/templates/chrony.conf.j2 Outdated Show resolved Hide resolved
roles/core/time/tasks/main.yml Outdated Show resolved Hide resolved
roles/core/time/templates/chrony.conf.j2 Outdated Show resolved Hide resolved
@btravouillon btravouillon added the enhancement New feature or request label Apr 11, 2020
@btravouillon btravouillon changed the title Added Molecule in all roles directories and fixed LF/CRLF chars ci: introduce unit testing of roles with Molecule Apr 11, 2020
.travis.yml Outdated Show resolved Hide resolved
roles/core/dns_server/vars/main.yml Outdated Show resolved Hide resolved
roles/core/time/tasks/main.yml Outdated Show resolved Hide resolved
roles/core/time/vars/main.yml Outdated Show resolved Hide resolved
roles/core/dns_server/.ansible-lint Outdated Show resolved Hide resolved
roles/core/time/.ansible-lint Outdated Show resolved Hide resolved
roles/core/time/templates/chrony.conf.j2 Outdated Show resolved Hide resolved
roles/core/time/molecule/default/verify.yml Outdated Show resolved Hide resolved
@strus38
Copy link
Contributor Author

strus38 commented Apr 12, 2020

Fixed all the remarks. Should be ok now. Thanks

@strus38
Copy link
Contributor Author

strus38 commented Apr 12, 2020

Travis result:
image

The failing ones are because of a package is not available. Please, suggest how to fix it.

Fedora31
image

Ubuntu18.04
image

Also, I cannot submit code to integrate the travis build badges because it is enabled only on my fork/github account:
image

Copy link
Member

@btravouillon btravouillon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're almost done!
I noticed an issue with the chrony.conf.j2 template (in current implementation, not introduced by this PR). Please revert your changes to this file, I will open a ticket to fix this.
Also:

  • no need to check if time_zone is defined since it now has a default value.
  • fedora is not supported

Thank you for the huge work on this.

.travis.yml Outdated Show resolved Hide resolved
roles/core/time/templates/chrony.conf.j2 Outdated Show resolved Hide resolved
roles/core/time/templates/chrony.conf.j2 Outdated Show resolved Hide resolved
…m travis build, remove the check to time_zone variable
btravouillon
btravouillon previously approved these changes Apr 12, 2020
Copy link
Member

@btravouillon btravouillon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✌️ 👍 Nice! Needs a second review before squash & merge.

@strus38
Copy link
Contributor Author

strus38 commented Apr 12, 2020

Note: I have just completed a new github projet: docker-ubi7-ansible so we will be able to update travis config with ubi7 images.
The image is available on docker hub docker pull strusfr/docker-ubi7-ansible:latest

@oxedions
Copy link
Member

Hello,

Thank you for this PR.
Please do not merge it, I wish to take time to investigate all of this.

Have a nice weekend

Ox

Copy link
Member

@oxedions oxedions left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this PR. Many nice quality improvement. :-)
Please have a look on my comments regarding defaults.

roles/core/dns_server/defaults/main.yml Outdated Show resolved Hide resolved
roles/core/dns_server/defaults/main.yml Outdated Show resolved Hide resolved
roles/core/time/defaults/main.yml Outdated Show resolved Hide resolved
@strus38
Copy link
Contributor Author

strus38 commented Apr 14, 2020

Fixed the PR as suggested by comments. Please review again.

.travis.yml Outdated Show resolved Hide resolved
roles/core/time/molecule/default/prepare.yml Outdated Show resolved Hide resolved
Copy link
Member

@btravouillon btravouillon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good for me.

roles/core/time/defaults/main.yml Outdated Show resolved Hide resolved
@strus38
Copy link
Contributor Author

strus38 commented Apr 14, 2020

all fixed I guess.

Copy link
Member

@btravouillon btravouillon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good.

Copy link
Member

@oxedions oxedions left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok for me, many thanks for this huge work.

@oxedions oxedions merged commit 5c98528 into bluebanquise:master Apr 15, 2020
@strus38 strus38 deleted the feature/molecule branch April 19, 2020 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants