tutorial.rst 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. .. _developing-tutorial:
  2. ========================
  3. Developing Salt Tutorial
  4. ========================
  5. This tutorial assumes you have:
  6. * a web browser
  7. * a GitHub account (``<my_account>``)
  8. * a command line (CLI)
  9. * git
  10. * a text editor
  11. ----
  12. Fork
  13. ----
  14. In your browser, navigate to the ``saltstack/salt`` `GitHub repository
  15. <https://github.com/saltstack/salt>`_.
  16. Click on ``Fork`` (https://github.com/saltstack/salt/#fork-destination-box).
  17. .. note::
  18. If you have more than one GitHub presence, for example if you are a member
  19. of a team, GitHub will ask you into which area to clone Salt. If you don't
  20. know where, then select your personal GitHub account.
  21. -----
  22. Clone
  23. -----
  24. In your CLI, navigate to the directory into which you want clone the Salt
  25. codebase and submit the following command:
  26. .. code-block:: bash
  27. $ git clone https://github.com/<my_account>/salt.git
  28. where ``<my_account>`` is the name of your GitHub account. After the clone has
  29. completed, add SaltStack as a second remote and fetch any changes from
  30. ``upstream``.
  31. .. code-block:: bash
  32. $ cd salt
  33. $ git remote add upstream https://github.com/saltstack/salt.git
  34. $ git fetch upstream
  35. For this tutorial, we will be working off from the ``|repo_primary_branch|`` branch, which is
  36. the default branch for the SaltStack GitHub project. This branch needs to
  37. track ``upstream/|repo_primary_branch|`` so that we will get all upstream changes when they
  38. happen.
  39. .. code-block:: bash
  40. $ git checkout |repo_primary_branch|
  41. $ git branch --set-upstream-to upstream/|repo_primary_branch|
  42. -----
  43. Fetch
  44. -----
  45. Fetch any ``upstream`` changes on the ``|repo_primary_branch|`` branch and sync them to your
  46. local copy of the branch with a single command:
  47. .. code-block:: bash
  48. $ git pull --rebase
  49. .. note::
  50. For an explanation on ``pull`` vs ``pull --rebase`` and other excellent
  51. points, see `this article <https://mislav.net/2013/02/merge-vs-rebase/>`_ by
  52. Mislav Marohnić.
  53. ------
  54. Branch
  55. ------
  56. Now we are ready to get to work. Consult the `sprint beginner bug list
  57. <https://github.com/saltstack/salt/wiki/December-2015-Sprint-Beginner-Bug-List>`_
  58. and select an execution module whose ``__virtual__`` function needs to be
  59. updated. I'll select the ``alternatives`` module.
  60. Create a new branch off from ``|repo_primary_branch|``. Be sure to name it something short
  61. and descriptive.
  62. .. code-block:: bash
  63. $ git checkout -b virt_ret
  64. ----
  65. Edit
  66. ----
  67. Edit the file you have selected, and verify that the changes are correct.
  68. .. code-block:: bash
  69. $ vim salt/modules/alternatives.py
  70. $ git diff
  71. .. code-block:: diff
  72. diff --git a/salt/modules/alternatives.py b/salt/modules/alternatives.py
  73. index 1653e5f..30c0a59 100644
  74. --- a/salt/modules/alternatives.py
  75. +++ b/salt/modules/alternatives.py
  76. @@ -30,7 +30,7 @@ def __virtual__():
  77. '''
  78. if os.path.isdir('/etc/alternatives'):
  79. return True
  80. - return False
  81. + return (False, 'Cannot load alternatives module: /etc/alternatives dir not found')
  82. def _get_cmd():
  83. ------
  84. Commit
  85. ------
  86. Stage and commit the changes. Write a descriptive commit summary, but try to
  87. keep it less than 50 characters. Review your commit.
  88. .. code-block:: bash
  89. $ git add salt/modules/alternatives.py
  90. $ git commit -m 'modules.alternatives: __virtual__ return err msg'
  91. $ git show
  92. .. note::
  93. If you need more room to describe the changes in your commit, run ``git
  94. commit`` (without the ``-m``, message, option) and you will be presented
  95. with an editor. The first line is the commit summary and should still be
  96. 50 characters or less. The following paragraphs you create are free form
  97. and will be preserved as part of the commit.
  98. ----
  99. Push
  100. ----
  101. Push your branch to your GitHub account. You will likely need to enter your
  102. GitHub username and password.
  103. .. code-block:: bash
  104. $ git push origin virt_ret
  105. Username for 'https://github.com': <my_account>
  106. Password for 'https://<my_account>@github.com':
  107. .. note::
  108. If authentication over https does not work, you can alternatively setup
  109. `ssh keys <https://help.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh>`_. Once
  110. you have done this, you may need add the keys to your git repository
  111. configuration
  112. .. code-block:: bash
  113. $ git config ssh.key ~/.ssh/<key_name>
  114. where ``<key_name>`` is the file name of the private key you created.
  115. -----
  116. Merge
  117. -----
  118. In your browser, navigate to the `new pull request
  119. <https://github.com/saltstack/salt/compare>`_ page on the ``saltstack/salt``
  120. GitHub repository and click on ``compare across forks``. Select
  121. ``<my_account>`` from the list of head forks and the branch you are wanting to
  122. merge into ``|repo_primary_branch|`` (``virt_ret`` in this case).
  123. When you have finished reviewing the changes, click ``Create pull request``.
  124. If your pull request contains only a single commit, the title and comment will
  125. be taken from that commit's summary and message, otherwise the branch name is
  126. used for the title. Edit these fields as necessary and click ``Create pull
  127. request``.
  128. .. note::
  129. Although these instructions seem to be the official pull request procedure
  130. on github's website, here are two alternative methods that are simpler.
  131. * If you navigate to your clone of salt,
  132. ``https://github.com/<my_account>/salt``, depending on how old your
  133. branch is or how recently you pushed updates on it, you may be presented
  134. with a button to create a pull request with your branch.
  135. * I find it easiest to edit the following URL:
  136. ``https://github.com/saltstack/salt/compare/|repo_primary_branch|...<my_account>:virt_ret``
  137. ---------
  138. Resources
  139. ---------
  140. GitHub offers many great tutorials on various aspects of the git- and
  141. GitHub-centric development workflow:
  142. https://help.github.com/
  143. There are many topics covered by the Salt Developer documentation:
  144. https://docs.saltstack.com/en/latest/topics/development/index.html
  145. The contributing documentation presents more details on specific contributing
  146. topics:
  147. https://docs.saltstack.com/en/latest/topics/development/contributing.html