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

More complete discovery of entry point playbooks #5028

Merged
merged 1 commit into from
Aug 11, 2017

Conversation

mtnbikenc
Copy link
Member

This change scans for supported entry point playbooks based on the following conditions:

  • In the supported directory of playbooks/byo
  • Playbooks not included by any other playbooks

The previous method of discovering entry point playbooks by searching files for intialize_hosts.yml was incomplete and would only find properly formatted playbooks. This method finds all playbooks, as well as new playbooks, which are not included by other playbooks.

Note: Some playbooks which may be a documented entry point, such as byo/config.yml, are not directly identified by this method because of higher up playbooks which also include those playbooks.

  • byo/config.yml is documented as an entry point however it is just a placeholder that calls byo/openshift-cluster/config.yml.
  • byo/config.yml is also included from byo/vagrant.yml
  • byo/openshift-checks/pre-install.yml is an actual entry point, however byo/openshift-preflight/check.yml is maintained as a documented entry point

Test affected:

tox -e py27-ansible_syntax

@mtnbikenc mtnbikenc self-assigned this Aug 8, 2017
@mtnbikenc mtnbikenc requested review from ashcrow and kwoodson August 8, 2017 15:36
@kwoodson
Copy link
Contributor

kwoodson commented Aug 8, 2017

@mtnbikenc, Looking through this code I see that you tied into the syntax check. Was there a reason why you chose this and not creating a separate check?

I think for efficiency sake, we are already traversing the files, and the logic is quite similar so I think this is probably fine. If we want to expound or change anything in the future we can break this out.

Copy link
Member

@ashcrow ashcrow left a comment

Choose a reason for hiding this comment

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

LGTM. Optional nits.

setup.py Outdated
if not isinstance(task, dict):
# Skip yaml files which do not contain plays or includes
continue
if 'include' in task.keys():
Copy link
Member

Choose a reason for hiding this comment

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

nit: keys is not needed.

if 'include' in task:

Copy link
Member Author

Choose a reason for hiding this comment

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

Same situation here as in hosts below, just being specific. This will also need to be extended once we move to Ansible 2.4 and start switching over to import_playbook.

setup.py Outdated
os.path.join(os.path.dirname(yaml_file),
included_file_name))
included_playbooks.add(included_file)
elif 'hosts' in task.keys():
Copy link
Member

@ashcrow ashcrow Aug 8, 2017

Choose a reason for hiding this comment

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

nit: keys is not needed.

elif 'hosts' in task:

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, keys is needed. I ran into a case when the word hosts was merely present in the text of the dict as a whole. This generated a false positive, so I was more specific in looking at the keys of the dict and not the whole dict.

Copy link
Member

Choose a reason for hiding this comment

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

I've not seen that before, but I believe you ... though I can't reproduce it.

Python 3

In [1]: a = {'a': 'b'}

In [2]: 'a' in a
Out[2]: True

In [3]: 'b' in a
Out[3]: False

Python 2

>>> a = {'a': 'b'}
>>> 'a' in a
True
>>> 'b' in a
False
>>> 

In the end it's a nit though so 👍 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

I've unraveled the mystery. The problem was two fold and hidden by the first. What I was actually encountering was a difference in the type of object being read from the yaml file. In one instance (cluster_hosts.yml), I was presented with a str and was getting a positive on hosts in that str. When I ultimately added a check to skip the task if it was not a dict, I was able to bypass that false positive. So, I don't really need the keys as you suggested since I'm already verifying I'm working with a dict. Updated. 😃

Copy link
Member

Choose a reason for hiding this comment

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

@mtnbikenc great debugging!!

@@ -221,27 +221,43 @@ def run(self):
''' run command '''

has_errors = False
playbooks = set()
Copy link
Member

Choose a reason for hiding this comment

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

👍 for using sets!

setup.py Outdated
has_errors = True
# Break for loop, no need to continue looping lines
break
for task in yaml.safe_load(contents.read()):
Copy link
Member

Choose a reason for hiding this comment

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

nit: I realize this wasn't something added in this PR but technically contents is a file instance. It reads a bit off to me to need to read the contents to get the contents of the instance.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated

@mtnbikenc
Copy link
Member Author

@kwoodson The original syntax checking was finding playbooks to check only by the existence of 'initialize_hosts.yml` being in the playbook. This is not a reliable way of finding the actual playbooks to check. This new method finds all the playbooks that could be run and is not tied to just the inclusion of a particular file. I'm attempting to improve the completeness of our syntax checking by making this change.

@mtnbikenc mtnbikenc force-pushed the entry-point-validation branch from 9c348dc to a68dcd6 Compare August 8, 2017 17:45
This change scans for supported entry point playbooks based on the
following conditions:

* In the supported directory of playbooks/byo
* Playbooks not included by any other playbooks
@mtnbikenc mtnbikenc force-pushed the entry-point-validation branch from a68dcd6 to 3c7d816 Compare August 8, 2017 19:20
@mtnbikenc
Copy link
Member Author

aos-ci-test

@openshift-bot
Copy link

error: aos-ci-jenkins/OS_3.6_NOT_containerized for 3c7d816 (logs)

@openshift-bot
Copy link

error: aos-ci-jenkins/OS_3.6_containerized for 3c7d816 (logs)

@mtnbikenc
Copy link
Member Author

aos-ci-test

@openshift-bot
Copy link

success: "aos-ci-jenkins/OS_3.6_NOT_containerized, aos-ci-jenkins/OS_3.6_NOT_containerized_e2e_tests" for 3c7d816 (logs)

@openshift-bot
Copy link

success: "aos-ci-jenkins/OS_3.6_containerized, aos-ci-jenkins/OS_3.6_containerized_e2e_tests" for 3c7d816 (logs)

@mtnbikenc
Copy link
Member Author

[merge]

@openshift-bot
Copy link

[test]ing while waiting on the merge queue

@openshift-bot
Copy link

Evaluated for openshift ansible test up to 3c7d816

@openshift-bot
Copy link

continuous-integration/openshift-jenkins/test FAILURE (https://ci.openshift.redhat.com/jenkins/job/test_pull_request_openshift_ansible/427/) (Base Commit: 6528031) (PR Branch Commit: 3c7d816)

@mtnbikenc
Copy link
Member Author

Flake: openshift/origin#14898 yum: no mirrors to try

@mtnbikenc
Copy link
Member Author

[merge]

@kwoodson
Copy link
Contributor

flake again on yum: openshift/origin#8571

@mtnbikenc
Copy link
Member Author

[merge]

@openshift-bot
Copy link

Evaluated for openshift ansible merge up to 3c7d816

@openshift-bot
Copy link

continuous-integration/openshift-jenkins/merge FAILURE (https://ci.openshift.redhat.com/jenkins/job/merge_pull_request_openshift_ansible/833/) (Base Commit: 7c7b91c) (PR Branch Commit: 3c7d816)

@mtnbikenc mtnbikenc merged commit eb51502 into openshift:master Aug 11, 2017
@mtnbikenc mtnbikenc deleted the entry-point-validation branch August 11, 2017 02:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants