-
Notifications
You must be signed in to change notification settings - Fork 3
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: add more tests #13
Open
macno
wants to merge
8
commits into
master
Choose a base branch
from
macno/tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+649
−90
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ed4aee2
CI: Add wrapper to execute molecule
macno a75d5a7
CI: refactor tests, factorisation of common pre_task
macno 8417312
CI: add new scenario 'custom-bin-file'
macno aff9cf9
CI: add new scenario 'custom-config-file'
macno d833afa
CI: add new scenario 'custom-config-dir'
macno 936cbd3
CI: add new scenario 'custom-all'
macno 936b2b8
CI: add comment to runMolecule.sh
macno 9fb320d
CI: yaml files:
macno File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
dependency: | ||
name: galaxy | ||
driver: | ||
name: docker | ||
lint: | ||
name: yamllint | ||
platforms: | ||
- name: instance | ||
image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest" | ||
command: ${MOLECULE_DOCKER_COMMAND:-""} | ||
volumes: | ||
- /sys/fs/cgroup:/sys/fs/cgroup:ro | ||
privileged: true | ||
pre_build_image: true | ||
provisioner: | ||
name: ansible | ||
lint: | ||
name: ansible-lint | ||
verifier: | ||
name: testinfra | ||
lint: | ||
name: flake8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
- name: Converge | ||
hosts: all | ||
vars: | ||
- theo_url: "https://theo.example.com" | ||
- theo_client_token: "zdOPNza4jjtceH5F2rU0iOkIJ2xlV4hGUauKT4cNe8HAp+AMnzYEzSc0EIBGM+MJuqL7gLd6bwIP" | ||
- theo_agent_path: /usr/local/bin/theo | ||
- theo_agent_user: theo | ||
- theo_agent_cache_dir: /var/cache/theo | ||
- theo_agent_config_dir: /var/lib/theo | ||
- theo_agent_config_path: /var/lib/theo/theo.yml | ||
- theo_agent_verify_signature: true | ||
- theo_agent_public_key: | | ||
-----BEGIN PUBLIC KEY----- | ||
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAwVhHEBTVqEpBOpguARtg | ||
//WyDBEoCT2F2OjnHB6fxJ9oopYJZB2Y4jj5cxo1O41r65XmMRT4lqeHWS6Iovde | ||
kzlJ0bH91gl7/iNziUMN4ONiIR0SU3PiBGQ0XKq6rUxpsOhe+tFPfBQYhkkAiQeG | ||
WC1GYQynYjZ/MTEDIPnd5YjSl0agzm7BMRujEcjWyYqEBuZjtDqP6AICz8nkFo9i | ||
CWBONYbCujDl+1sei3WUfeGcUdGiPNwQGU/TW4sfcRWQzayw3XQEl3ERNRMihVsb | ||
in2529O4+JMKdKn22mzTmWsraP/ZakVeti0VtpGZEe1YSTW8+SCz7DnTadnuUZAO | ||
5JFVTmFcbF7/d/H0atKVVAeTC5nqYNeDrW4jtIQalUZeaHrBkWK7i/yxDYFlC2AW | ||
ZEu4IQZtGfNJCaZFuYSiN96yzlnMWRp1nUGaBxoax4K8rBwX8EWxT4EAyN1mtan0 | ||
ZQITjiZTqDvnhr8iSIvn9hy3942GYi3upOsBeqfb90vzS7BAmoplyWPS0D+UWweB | ||
+sjv96Gtb4BFpc96qwptLCnVFFOVlq0bq0u1FN6sZ4RApl2IaSJV9JGsJjeeJowh | ||
GCK9sSDVI5XY3wy6UYMo9SZQGIglyRPrnd3R82O277lAyOVC/NNp1vq5WH/Mi1Mu | ||
JK85kX7Atut+tgWgwuwT5vcCAwEAAQ== | ||
-----END PUBLIC KEY----- | ||
pre_tasks: | ||
- name: Import common tasks | ||
import_tasks: ../resources/playbooks/pre-tasks.yml | ||
roles: | ||
- role: ansible-theo-agent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import os | ||
|
||
import testinfra.utils.ansible_runner | ||
|
||
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( | ||
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') | ||
|
||
|
||
def test_theo_binary_file(host): | ||
f = host.file('/usr/local/bin/theo') | ||
assert f.exists | ||
assert f.is_file | ||
assert f.user == 'root' | ||
assert f.group == 'root' | ||
print("{} vs {}".format(f.mode, oct(f.mode))) | ||
assert oct(f.mode) == '0o755' | ||
|
||
|
||
def test_theo_cache_dir(host): | ||
f = host.file('/var/cache/theo') | ||
assert f.exists | ||
assert f.is_directory | ||
assert f.user == 'theo' | ||
assert f.group == 'root' | ||
|
||
|
||
def test_theo_config_file(host): | ||
f = host.file('/var/lib/theo/theo.yml') | ||
assert f.exists | ||
assert f.is_file | ||
assert f.user == 'root' | ||
assert f.group == 'root' | ||
conf = f.content | ||
''' | ||
url: https://theo.example.com | ||
token: \ | ||
zdOPNza4jjtceH5F2rU0iOkIJ2xlV4hGUauKT4cNe8HAp+AMnzYEzSc0EIBGM+MJuqL7gLd6bwIP | ||
cachedir: /var/cache/theo | ||
verify: True | ||
public_key: /var/lib/theo/public.pem | ||
''' | ||
expected = [ | ||
b'url: https://theo.example.com', | ||
b'token: zdOPNza4jjtceH5F2rU0iOkIJ2xlV4hGUauKT4cNe8HAp' | ||
b'+AMnzYEzSc0EIBGM+MJuqL7gLd6bwIP', | ||
b'cachedir: /var/cache/theo', | ||
b'verify: True', | ||
b'public_key: /var/lib/theo/public.pem' | ||
] | ||
for line in expected: | ||
assert line in conf | ||
|
||
|
||
def test_theo_public_key_file(host): | ||
f = host.file('/var/lib/theo/public.pem') | ||
assert f.exists | ||
assert f.is_file | ||
assert f.user == 'root' | ||
assert f.group == 'root' | ||
|
||
|
||
def test_sshd_config(host): | ||
distro = os.getenv('MOLECULE_DISTRO', 'centos7') | ||
if distro == 'debian8': | ||
expected = get_sshd_config_pre_v69() | ||
elif distro == 'ubuntu1404': | ||
expected = get_sshd_config_pre_v69() | ||
else: | ||
expected = get_sshd_config_v69() | ||
f = host.file('/etc/ssh/sshd_config') | ||
config = f.content | ||
configlines = [] | ||
for line in config.splitlines(): | ||
if not line.startswith(b'#'): | ||
configlines.append(line) | ||
''' | ||
I don't want to use something like: | ||
assert set(expected).issubset(configlines) | ||
Because there's no detail of the missing line(s) | ||
''' | ||
errors = [] | ||
for line in expected: | ||
if line not in configlines: | ||
errors.append(line) | ||
|
||
if len(errors): | ||
print('Failed test_sshd_config, missing line(s)') | ||
for error in errors: | ||
print(error) | ||
assert False | ||
|
||
|
||
def get_sshd_config_pre_v69(): | ||
return [ | ||
b'AuthorizedKeysCommandUser theo', | ||
b'AuthorizedKeysCommand /usr/local/bin/theo ' | ||
b'-config-file /var/lib/theo/theo.yml %u', | ||
b'AuthorizedKeysFile /var/cache/theo/%u' | ||
] | ||
|
||
|
||
def get_sshd_config_v69(): | ||
return [ | ||
b'AuthorizedKeysCommandUser theo', | ||
b'AuthorizedKeysCommand /usr/local/bin/theo ' | ||
b'-config-file /var/lib/theo/theo.yml -fingerprint %f %u', | ||
b'AuthorizedKeysFile /var/cache/theo/%u' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
dependency: | ||
name: galaxy | ||
driver: | ||
name: docker | ||
lint: | ||
name: yamllint | ||
platforms: | ||
- name: instance | ||
image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest" | ||
command: ${MOLECULE_DOCKER_COMMAND:-""} | ||
volumes: | ||
- /sys/fs/cgroup:/sys/fs/cgroup:ro | ||
privileged: true | ||
pre_build_image: true | ||
provisioner: | ||
name: ansible | ||
lint: | ||
name: ansible-lint | ||
verifier: | ||
name: testinfra | ||
lint: | ||
name: flake8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
- name: Converge | ||
hosts: all | ||
vars: | ||
- theo_url: "https://theo.example.com" | ||
- theo_client_token: "zdOPNza4jjtceH5F2rU0iOkIJ2xlV4hGUauKT4cNe8HAp+AMnzYEzSc0EIBGM+MJuqL7gLd6bwIP" | ||
- theo_agent_path: /usr/local/bin/theo | ||
- theo_agent_verify_signature: true | ||
- theo_agent_public_key: | | ||
-----BEGIN PUBLIC KEY----- | ||
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAwVhHEBTVqEpBOpguARtg | ||
//WyDBEoCT2F2OjnHB6fxJ9oopYJZB2Y4jj5cxo1O41r65XmMRT4lqeHWS6Iovde | ||
kzlJ0bH91gl7/iNziUMN4ONiIR0SU3PiBGQ0XKq6rUxpsOhe+tFPfBQYhkkAiQeG | ||
WC1GYQynYjZ/MTEDIPnd5YjSl0agzm7BMRujEcjWyYqEBuZjtDqP6AICz8nkFo9i | ||
CWBONYbCujDl+1sei3WUfeGcUdGiPNwQGU/TW4sfcRWQzayw3XQEl3ERNRMihVsb | ||
in2529O4+JMKdKn22mzTmWsraP/ZakVeti0VtpGZEe1YSTW8+SCz7DnTadnuUZAO | ||
5JFVTmFcbF7/d/H0atKVVAeTC5nqYNeDrW4jtIQalUZeaHrBkWK7i/yxDYFlC2AW | ||
ZEu4IQZtGfNJCaZFuYSiN96yzlnMWRp1nUGaBxoax4K8rBwX8EWxT4EAyN1mtan0 | ||
ZQITjiZTqDvnhr8iSIvn9hy3942GYi3upOsBeqfb90vzS7BAmoplyWPS0D+UWweB | ||
+sjv96Gtb4BFpc96qwptLCnVFFOVlq0bq0u1FN6sZ4RApl2IaSJV9JGsJjeeJowh | ||
GCK9sSDVI5XY3wy6UYMo9SZQGIglyRPrnd3R82O277lAyOVC/NNp1vq5WH/Mi1Mu | ||
JK85kX7Atut+tgWgwuwT5vcCAwEAAQ== | ||
-----END PUBLIC KEY----- | ||
pre_tasks: | ||
- name: Import common tasks | ||
import_tasks: ../resources/playbooks/pre-tasks.yml | ||
roles: | ||
- role: ansible-theo-agent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import os | ||
|
||
import testinfra.utils.ansible_runner | ||
|
||
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( | ||
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') | ||
|
||
|
||
def test_theo_binary_file(host): | ||
f = host.file('/usr/local/bin/theo') | ||
assert f.exists | ||
assert f.user == 'root' | ||
assert f.group == 'root' | ||
|
||
|
||
def test_sshd_config(host): | ||
distro = os.getenv('MOLECULE_DISTRO', 'centos7') | ||
if distro == 'centos6': | ||
expected = get_sshd_config_centos6() | ||
elif distro == 'debian8': | ||
expected = get_sshd_config_pre_v69() | ||
elif distro == 'ubuntu1404': | ||
expected = get_sshd_config_pre_v69() | ||
else: | ||
expected = get_sshd_config_v69() | ||
f = host.file('/etc/ssh/sshd_config') | ||
config = f.content | ||
configlines = [] | ||
for line in config.splitlines(): | ||
if not line.startswith(b'#'): | ||
configlines.append(line) | ||
''' | ||
I don't want to use something like: | ||
assert set(expected).issubset(configlines) | ||
Because there's no detail of the missing line(s) | ||
''' | ||
errors = [] | ||
for line in expected: | ||
if line not in configlines: | ||
errors.append(line) | ||
|
||
if len(errors): | ||
print('Failed test_sshd_config, missing line(s)') | ||
for error in errors: | ||
print(error) | ||
assert False | ||
|
||
|
||
def get_sshd_config_centos6(): | ||
return [ | ||
b'AuthorizedKeysCommandRunAs theo-agent', | ||
b'AuthorizedKeysCommand /usr/local/bin/theo', | ||
b'AuthorizedKeysFile /var/cache/theo-agent/%u' | ||
] | ||
|
||
|
||
def get_sshd_config_pre_v69(): | ||
return [ | ||
b'AuthorizedKeysCommandUser theo-agent', | ||
b'AuthorizedKeysCommand /usr/local/bin/theo', | ||
b'AuthorizedKeysFile /var/cache/theo-agent/%u' | ||
] | ||
|
||
|
||
def get_sshd_config_v69(): | ||
return [ | ||
b'AuthorizedKeysCommandUser theo-agent', | ||
b'AuthorizedKeysCommand /usr/local/bin/theo -fingerprint %f %u', | ||
b'AuthorizedKeysFile /var/cache/theo-agent/%u' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
dependency: | ||
name: galaxy | ||
driver: | ||
name: docker | ||
lint: | ||
name: yamllint | ||
platforms: | ||
- name: instance | ||
image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest" | ||
command: ${MOLECULE_DOCKER_COMMAND:-""} | ||
volumes: | ||
- /sys/fs/cgroup:/sys/fs/cgroup:ro | ||
privileged: true | ||
pre_build_image: true | ||
provisioner: | ||
name: ansible | ||
lint: | ||
name: ansible-lint | ||
verifier: | ||
name: testinfra | ||
lint: | ||
name: flake8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
- name: Converge | ||
hosts: all | ||
vars: | ||
- theo_url: "https://theo.example.com" | ||
- theo_client_token: "zdOPNza4jjtceH5F2rU0iOkIJ2xlV4hGUauKT4cNe8HAp+AMnzYEzSc0EIBGM+MJuqL7gLd6bwIP" | ||
- theo_agent_config_dir: /var/lib/theo | ||
- theo_agent_verify_signature: true | ||
- theo_agent_public_key: | | ||
-----BEGIN PUBLIC KEY----- | ||
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAwVhHEBTVqEpBOpguARtg | ||
//WyDBEoCT2F2OjnHB6fxJ9oopYJZB2Y4jj5cxo1O41r65XmMRT4lqeHWS6Iovde | ||
kzlJ0bH91gl7/iNziUMN4ONiIR0SU3PiBGQ0XKq6rUxpsOhe+tFPfBQYhkkAiQeG | ||
WC1GYQynYjZ/MTEDIPnd5YjSl0agzm7BMRujEcjWyYqEBuZjtDqP6AICz8nkFo9i | ||
CWBONYbCujDl+1sei3WUfeGcUdGiPNwQGU/TW4sfcRWQzayw3XQEl3ERNRMihVsb | ||
in2529O4+JMKdKn22mzTmWsraP/ZakVeti0VtpGZEe1YSTW8+SCz7DnTadnuUZAO | ||
5JFVTmFcbF7/d/H0atKVVAeTC5nqYNeDrW4jtIQalUZeaHrBkWK7i/yxDYFlC2AW | ||
ZEu4IQZtGfNJCaZFuYSiN96yzlnMWRp1nUGaBxoax4K8rBwX8EWxT4EAyN1mtan0 | ||
ZQITjiZTqDvnhr8iSIvn9hy3942GYi3upOsBeqfb90vzS7BAmoplyWPS0D+UWweB | ||
+sjv96Gtb4BFpc96qwptLCnVFFOVlq0bq0u1FN6sZ4RApl2IaSJV9JGsJjeeJowh | ||
GCK9sSDVI5XY3wy6UYMo9SZQGIglyRPrnd3R82O277lAyOVC/NNp1vq5WH/Mi1Mu | ||
JK85kX7Atut+tgWgwuwT5vcCAwEAAQ== | ||
-----END PUBLIC KEY----- | ||
pre_tasks: | ||
- name: Import common tasks | ||
import_tasks: ../resources/playbooks/pre-tasks.yml | ||
roles: | ||
- role: ansible-theo-agent |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you added double newline between
pre_tasks
androles
, maybe adding single line betweenvars
andpre_tasks
could help visually here aswell?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, but I think I prefer to remove the empty lines