summaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorThomas Wiest <twiest@users.noreply.github.com>2015-05-22 19:42:27 -0400
committerThomas Wiest <twiest@users.noreply.github.com>2015-05-22 19:42:27 -0400
commitce6a15b62755e10cfa31628e5c9e430ef876c1ff (patch)
tree232a01701b4f9dd5bbc703919ec5b22186ecdc63 /docs
parentbee09c914d8acbf0f5ad5e56f068c2362d84084e (diff)
parent51309266b3ae3800f82b2be8fd57ede9d27aaba5 (diff)
downloadopenshift-ce6a15b62755e10cfa31628e5c9e430ef876c1ff.tar.gz
openshift-ce6a15b62755e10cfa31628e5c9e430ef876c1ff.tar.bz2
openshift-ce6a15b62755e10cfa31628e5c9e430ef876c1ff.tar.xz
openshift-ce6a15b62755e10cfa31628e5c9e430ef876c1ff.zip
Merge pull request #243 from twiest/pr
Added style and best practices guides
Diffstat (limited to 'docs')
-rw-r--r--docs/best_practices.adoc122
-rw-r--r--docs/style_guide.adoc107
2 files changed, 229 insertions, 0 deletions
diff --git a/docs/best_practices.adoc b/docs/best_practices.adoc
new file mode 100644
index 000000000..938b6b46a
--- /dev/null
+++ b/docs/best_practices.adoc
@@ -0,0 +1,122 @@
+// vim: ft=asciidoc
+
+= Openshift-Ansible Best Practices Guide
+
+The purpose of this guide is to describe the preferred patterns and best practices used in this repository (both in ansible and python).
+
+It is important to note that this repository may not currently comply with all best practices, but our intention is that it will.
+
+All new pull requests created against this repository MUST comply with this guide.
+
+This guide complies with https://www.ietf.org/rfc/rfc2119.txt[RFC2119].
+
+
+== Pull Requests
+
+[cols="2v,v"]
+|===
+| **Rule**
+| All pull requests MUST pass the build bot *before* they are merged.
+|===
+
+
+The purpose of this rule is to avoid cases where the build bot will fail pull requests for code modified in a previous pull request.
+
+Our tooling is flexible enough that exceptions can be made so that the tool the build bot is running will ignore certain areas or certain checks, but the build bot itself must pass for the pull request to be merged.
+
+
+
+== Python
+
+=== PyLint
+We use http://www.pylint.org/[PyLint] in an attempt to keep our python code as clean and as managable as possible. Our build bot runs each pull request through PyLint and any warnings or errors cause the build bot to fail the pull request.
+
+'''
+[cols="2v,v"]
+|===
+| **Rule**
+| PyLint rules MUST NOT be disabled on a whole file.
+|===
+
+Instead, http://docs.pylint.org/faq.html#is-it-possible-to-locally-disable-a-particular-message[disable the PyLint check on the line where PyLint is complaining].
+
+'''
+[cols="2v,v"]
+|===
+| **Rule**
+| PyLint rules MUST NOT be disabled unless they meet one of the following exceptions
+|===
+
+.Exceptions:
+1. When PyLint fails because of a dependency that can't be installed on the build bot
+1. When PyLint fails because we are including a module that is outside of our control (like Ansible)
+
+'''
+[cols="2v,v"]
+|===
+| **Rule**
+| All PyLint rule disables MUST be documented in the code.
+|===
+
+The purpose of this rule is to inform future developers about the disable.
+
+.Specifically, the following MUST accompany every PyLint disable:
+1. Why is the check being disabled?
+1. Is disabling this check meant to be permanent or temporary?
+
+.Example:
+[source,python]
+----
+# Reason: disable pylint maybe-no-member because overloaded use of
+# the module name causes pylint to not detect that 'results'
+# is an array or hash
+# Status: permanently disabled unless we can find a way to fix this.
+# pylint: disable=maybe-no-member
+metadata[line] = results.pop()
+----
+
+
+== Ansible
+
+=== Filters
+.Context:
+* https://docs.ansible.com/playbooks_filters.html[Ansible Playbook Filters]
+* http://jinja.pocoo.org/docs/dev/templates/#builtin-filters[Jinja2 Builtin Filters]
+
+'''
+[cols="2v,v"]
+|===
+| **Rule**
+| The `default` filter SHOULD replace empty strings, lists, etc.
+|===
+
+When using the jinja2 `default` filter, unless the variable is a boolean, specify `true` as the second parameter. This will cause the default filter to replace empty strings, lists, etc with the provided default.
+
+This is because we would prefer to either have a sane default set than to have an empty string, list, etc. We don't, for example, want config values set to an empty string.
+
+.From the http://jinja.pocoo.org/docs/dev/templates/[Jinja2 Docs]:
+[quote]
+If you want to use default with variables that evaluate to false you have to set the second parameter to true
+
+.Example:
+[source,yaml]
+----
+---
+- hosts: localhost
+ gather_facts: no
+ vars:
+ somevar: ''
+ tasks:
+ - debug: var=somevar
+
+ - name: "Will output 'somevar: []'"
+ debug: "msg='somevar: [{{ somevar | default('the string was empty') }}]'"
+
+ - name: "Will output 'somevar: [the string was empty]'"
+ debug: "msg='somevar: [{{ somevar | default('the string was empty', true) }}]'"
+----
+
+
+In other words, normally the `default` filter will only replace the value if it's undefined. By setting the second parameter to `true`, it will also replace the value if it defaults to a false value in python, so None, empty list, empty string, etc.
+
+We almost always want this instead of the empty list, string, etc.
diff --git a/docs/style_guide.adoc b/docs/style_guide.adoc
new file mode 100644
index 000000000..26a8c4636
--- /dev/null
+++ b/docs/style_guide.adoc
@@ -0,0 +1,107 @@
+// vim: ft=asciidoc
+
+= Openshift-Ansible Style Guide
+-----------------------------
+The purpose of this guide is to describe the preferred coding conventions used in this repository (both in ansible and python).
+
+It is important to note that this repository may not currently comply with all style guide rules, but our intention is that it will.
+
+All new pull requests created against this repository MUST comply with this guide.
+
+This style guide complies with https://www.ietf.org/rfc/rfc2119.txt[RFC2119].
+
+== Ansible Variable Naming
+
+=== Global Variables
+We define Ansible global variables as any variables outside of ansible roles. Examples include playbook variables, variables passed in on the cli, etc.
+
+'''
+[cols="2v,v"]
+|===
+| **Rule**
+| Global variables MUST have a prefix of g_
+|===
+
+
+Example:
+[source]
+----
+g_environment: someval
+----
+
+==== Role Variables
+We define Ansible role variables as variables contained in (or passed into) a role.
+
+'''
+[cols="2v,v"]
+|===
+| **Rule**
+| Role variables MUST have a prefix of atleast 3 characters. See below for specific naming rules.
+|===
+
+===== Role with 3 (or more) words in the name
+
+Take the first letter of each of the words.
+
+.3 word example:
+* Role name: made_up_role
+* Prefix: mur
+[source]
+----
+mur_var1: value_one
+----
+
+.4 word example:
+* Role name: totally_made_up_role
+* Prefix: tmur
+[source]
+----
+tmur_var1: value_one
+----
+
+
+
+===== Role with 2 (or less) words in the name
+
+Make up a prefix that makes sense.
+
+.1 word example:
+* Role name: ansible
+* Prefix: ans
+[source]
+----
+ans_var1: value_one
+----
+
+.2 word example:
+* Role name: ansible_tower
+* Prefix: tow
+[source]
+----
+tow_var1: value_one
+----
+
+
+===== Role name prefix conflicts
+If two role names contain words that start with the same letters, it will seem like their prefixes would conflict.
+
+Role variables are confined to the roles themselves, so this is actually only a problem if one of the roles depends on the other role (or uses includes into the other role).
+
+.Same prefix example:
+* First Role Name: made_up_role
+* First Role Prefix: mur
+* Second Role Name: my_uber_role
+* Second Role Prefix: mur
+[source]
+----
+- hosts: localhost
+ roles:
+ - { role: made_up_role, mur_var1: val1 }
+ - { role: my_uber_role, mur_var1: val2 }
+----
+
+Even though both roles have the same prefix (mur), and even though both roles have a variable named mur_var1, these two variables never exist outside of their respective roles. This means that this is not a problem.
+
+This would only be a problem if my_uber_role depended on made_up_role, or vice versa. Or if either of these two roles included things from the other.
+
+We think this is enough of a corner case that it is unlikely to happen. If it does, we will address it on a case by case basis.