This is an automated email from the git hooks/post-receive script.
spichugi pushed a change to branch master in repository lib389.
from 33534a0 Issue 43 - Add support for Referential Integrity plugin new 3200669 Issue #77 - Add sphinx documentation
The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference.
Summary of changes: doc/Makefile | 230 ++++++++++++++++++ doc/source/conf.py | 294 ++++++++++++++++++++++ doc/source/guidelines.rst | 606 ++++++++++++++++++++++++++++++++++++++++++++++ doc/source/index.rst | 40 +++ 4 files changed, 1170 insertions(+) create mode 100644 doc/Makefile create mode 100644 doc/source/conf.py create mode 100644 doc/source/guidelines.rst create mode 100644 doc/source/index.rst
This is an automated email from the git hooks/post-receive script.
spichugi pushed a commit to branch master in repository lib389.
commit 3200669b27a69a4778720b40e8b6b9327061280c Author: Simon Pichugin spichugi@redhat.com Date: Thu Aug 24 23:05:08 2017 +0200
Issue #77 - Add sphinx documentation
Description: Add the main documentation part formatted in rST. Add sphinx directory structure and Makefile. Documentation in HTML format can be generated with 'make html'.
https://pagure.io/lib389/issue/77
Reviewed by: mreynolds (Thanks!) --- doc/Makefile | 230 ++++++++++++++++++ doc/source/conf.py | 294 ++++++++++++++++++++++ doc/source/guidelines.rst | 606 ++++++++++++++++++++++++++++++++++++++++++++++ doc/source/index.rst | 40 +++ 4 files changed, 1170 insertions(+)
diff --git a/doc/Makefile b/doc/Makefile new file mode 100644 index 0000000..e632556 --- /dev/null +++ b/doc/Makefile @@ -0,0 +1,230 @@ +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = +BUILDDIR = build + +# User-friendly check for sphinx-build +ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) + $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) +endif + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source +# the i18n builder cannot share the environment and doctrees with the others +I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source + +.PHONY: help +help: + @echo "Please use `make <target>' where <target> is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " singlehtml to make a single large HTML file" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " applehelp to make an Apple Help Book" + @echo " devhelp to make HTML files and a Devhelp project" + @echo " epub to make an epub" + @echo " epub3 to make an epub3" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " latexpdf to make LaTeX files and run them through pdflatex" + @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" + @echo " text to make text files" + @echo " man to make manual pages" + @echo " texinfo to make Texinfo files" + @echo " info to make Texinfo files and run them through makeinfo" + @echo " gettext to make PO message catalogs" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " xml to make Docutils-native XML files" + @echo " pseudoxml to make pseudoxml-XML files for display purposes" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + @echo " coverage to run coverage check of the documentation (if enabled)" + @echo " dummy to check syntax errors of document sources" + +.PHONY: clean +clean: + rm -rf $(BUILDDIR)/* + +.PHONY: html +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +.PHONY: dirhtml +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +.PHONY: singlehtml +singlehtml: + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +.PHONY: pickle +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +.PHONY: json +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +.PHONY: htmlhelp +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in $(BUILDDIR)/htmlhelp." + +.PHONY: qthelp +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in $(BUILDDIR)/qthelp, like this:" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/lib389.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/lib389.qhc" + +.PHONY: applehelp +applehelp: + $(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp + @echo + @echo "Build finished. The help book is in $(BUILDDIR)/applehelp." + @echo "N.B. You won't be able to view it unless you put it in" \ + "~/Library/Documentation/Help or install it in your application" \ + "bundle." + +.PHONY: devhelp +devhelp: + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp + @echo + @echo "Build finished." + @echo "To view the help file:" + @echo "# mkdir -p $$HOME/.local/share/devhelp/lib389" + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/lib389" + @echo "# devhelp" + +.PHONY: epub +epub: + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub + @echo + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." + +.PHONY: epub3 +epub3: + $(SPHINXBUILD) -b epub3 $(ALLSPHINXOPTS) $(BUILDDIR)/epub3 + @echo + @echo "Build finished. The epub3 file is in $(BUILDDIR)/epub3." + +.PHONY: latex +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run `make' in that directory to run these through (pdf)latex" \ + "(use `make latexpdf' here to do that automatically)." + +.PHONY: latexpdf +latexpdf: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through pdflatex..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +.PHONY: latexpdfja +latexpdfja: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through platex and dvipdfmx..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +.PHONY: text +text: + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + @echo + @echo "Build finished. The text files are in $(BUILDDIR)/text." + +.PHONY: man +man: + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man + @echo + @echo "Build finished. The manual pages are in $(BUILDDIR)/man." + +.PHONY: texinfo +texinfo: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo + @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." + @echo "Run `make' in that directory to run these through makeinfo" \ + "(use `make info' here to do that automatically)." + +.PHONY: info +info: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo "Running Texinfo files through makeinfo..." + make -C $(BUILDDIR)/texinfo info + @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." + +.PHONY: gettext +gettext: + $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale + @echo + @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." + +.PHONY: changes +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +.PHONY: linkcheck +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in $(BUILDDIR)/linkcheck/output.txt." + +.PHONY: doctest +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." + +.PHONY: coverage +coverage: + $(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage + @echo "Testing of coverage in the sources finished, look at the " \ + "results in $(BUILDDIR)/coverage/python.txt." + +.PHONY: xml +xml: + $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml + @echo + @echo "Build finished. The XML files are in $(BUILDDIR)/xml." + +.PHONY: pseudoxml +pseudoxml: + $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml + @echo + @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." + +.PHONY: dummy +dummy: + $(SPHINXBUILD) -b dummy $(ALLSPHINXOPTS) $(BUILDDIR)/dummy + @echo + @echo "Build finished. Dummy builder generates no files." diff --git a/doc/source/conf.py b/doc/source/conf.py new file mode 100644 index 0000000..62fe1a5 --- /dev/null +++ b/doc/source/conf.py @@ -0,0 +1,294 @@ +# -*- coding: utf-8 -*- +# +# lib389 documentation build configuration file, created by +# sphinx-quickstart on Wed Aug 23 18:43:30 2017. +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys +import os + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +sys.path.insert(0, os.path.abspath('../../')) + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +#needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + 'sphinx.ext.autodoc', + 'sphinx.ext.intersphinx', + 'sphinx.ext.ifconfig', +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# source_suffix = ['.rst', '.md'] +source_suffix = '.rst' + +# The encoding of source files. +#source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'lib389' +copyright = u'2017, Red Hat, Inc.' +author = u'Red Hat, Inc.' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = u'1.0.4' +# The full version, including alpha/beta/rc tags. +release = u'1.0.4' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This patterns also effect to html_static_path and html_extra_path +exclude_patterns = [] + +# The reST default role (used for this markup: `text`) to use for all +# documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +#keep_warnings = False + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = False + + +# -- Options for HTML output ---------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = 'alabaster' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +#html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +#html_theme_path = [] + +# The name for this set of Sphinx documents. +# "<project> v<release> documentation" by default. +#html_title = u'lib389 v1.0.4' + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +#html_logo = None + +# The name of an image file (relative to this directory) to use as a favicon of +# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# Add any extra paths that contain custom files (such as robots.txt or +# .htaccess) here, relative to this directory. These files are copied +# directly to the root of the documentation. +#html_extra_path = [] + +# If not None, a 'Last updated on:' timestamp is inserted at every page +# bottom, using the given strftime format. +# The empty string is equivalent to '%b %d, %Y'. +#html_last_updated_fmt = None + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_domain_indices = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +#html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +#html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +#html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a <link> tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = None + +# Language to be used for generating the HTML full-text search index. +# Sphinx supports the following languages: +# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' +# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr', 'zh' +#html_search_language = 'en' + +# A dictionary with options for the search language support, empty by default. +# 'ja' uses this config value. +# 'zh' user can custom change `jieba` dictionary path. +#html_search_options = {'type': 'default'} + +# The name of a javascript file (relative to the configuration directory) that +# implements a search results scorer. If empty, the default will be used. +#html_search_scorer = 'scorer.js' + +# Output file base name for HTML help builder. +htmlhelp_basename = 'lib389doc' + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { +# The paper size ('letterpaper' or 'a4paper'). +#'papersize': 'letterpaper', + +# The font size ('10pt', '11pt' or '12pt'). +#'pointsize': '10pt', + +# Additional stuff for the LaTeX preamble. +#'preamble': '', + +# Latex figure (float) alignment +#'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + (master_doc, 'lib389.tex', u'lib389 Documentation', + u'Red Hat, Inc.', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# If true, show page references after internal links. +#latex_show_pagerefs = False + +# If true, show URL addresses after external links. +#latex_show_urls = False + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_domain_indices = True + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + (master_doc, 'lib389', u'lib389 Documentation', + [author], 1) +] + +# If true, show URL addresses after external links. +#man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + (master_doc, 'lib389', u'lib389 Documentation', + author, 'lib389', 'One line description of project.', + 'Miscellaneous'), +] + +# Documents to append as an appendix to all manuals. +#texinfo_appendices = [] + +# If false, no module index is generated. +#texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +#texinfo_show_urls = 'footnote' + +# If true, do not generate a @detailmenu in the "Top" node's menu. +#texinfo_no_detailmenu = False + + +# Example configuration for intersphinx: refer to the Python standard library. +intersphinx_mapping = {'https://docs.python.org/': None} diff --git a/doc/source/guidelines.rst b/doc/source/guidelines.rst new file mode 100644 index 0000000..daf249b --- /dev/null +++ b/doc/source/guidelines.rst @@ -0,0 +1,606 @@ +============================================================ +Guidelines for using pytest and lib389 +============================================================ +The guide covers basic workflow with git, py.test, lib389, python-ldap +and 1minutetip CLIs. + +For a saving place purposes, I'll replace topology_m2.ms["master1"] +with master1 , etc. + + + +Basic workflow +============== + +1. Clone ds repo: + + git clone ssh://git@pagure.io/389-ds-base.git + + One can change the old repos like this in .git/config files + + For ds (dirsrv) use link - https://pagure.io/389-ds-base.git + + For lib389 use link - https://pagure.io/lib389.git + +2. Go to the cloned directory +3. Create a new branch for your work: + :: + + git checkout -b new_test_suite +4. Check out PEP8 cheat sheet: + + https://gist.github.com/RichardBronosky/454964087739a449da04 + + https://www.python.org/dev/peps/pep-0008/ + + It is not fully mandatory in our project, but let's make our code a + bit cleaner for other's sake + +5. Use ./dirsrvtests/create_test.py tool to generate new test.py file. + + Usage: + + :: + + create_ticket.py -t|--ticket <ticket number> -s|--suite <suite name> + [ i|--instances <number of standalone instances> [ -m|--masters + <number of masters> -h|--hubs <number of hubs> -c|--consumers <number + of consumers> ] -o|--outputfile] + + Create a test suite script using "-s|--suite" instead of using + "-t|–ticket". One day, all 'tickets' will be transferred to 'suites', + so try to avoid the 'tickets' and try to find the place in 'suites' + for you case. Ask around is you have doubts. + Option "-i" can add multiple standalone instances. However, you can + not mix "-i" with the replication options(-m, -h ,-c). + + + + For example: + + :: + + create_test.py -s basic -m 2 -o ./dirsrvtests/tests/suites/basic/basic_test.py + # It will create basic_test.py with two masters set up and put the file to right dir + + + + If you are creating a test suite, the script will add one test case + for you with generated ID in the docstring (and it will check it for + uniqueness) + + Please, add more ID (to new test cases) with the next command and + check if it is unique for other tests + + :: + + python -c 'import uuid; print(uuid.uuid4())' + + +6. Add some fixture(s), if needed. The purpose of test fixtures is to + provide a fixed baseline upon which tests can reliably and repeatedly + execute. + + + For example: + + :: + + @pytest.fixture + def rdn_write_setup(topology_m2): + topology_m2.ms["master1"].add_s(ENTRY) + def fin(): + topology_m2.ms["master1"].delete_s(ENTRY_DN) + request.addfinalizer(fin) + + + + + It will add some entry to the master1 in the beginning of the test + case and delete this entry after test case is finished. + +7. Add test case(s). It should be defined as function which name + starts with "test_" + + + For example: + + :: + + def test_search_limits_fail(topology, rdn_write_setup): + + + You can put any amount of created fixtures as the arguments + +8. Write some good code with encapsulations, assertions etc. +9. Commit and push your code to your repo: + + :: + + git add ./dirsrvtests/tests/suites/basic/basic_test.py + git commit + git push $(whoami) + + +10. Test your script: + + :: + + py.test -v -s /mnt/testarea/test/ds/dirsrvtests/suites/basic + + +11. If everything is alright, then create a patch file for a review: + + + Go back to ds or lib389 dir (depends on where you want to send the patch) and do: + + :: + + git checkout master + git pull + git checkout new_test_suite + git rebase master + git format-patch -1 + + + + Basic guidelines for the commit message format + + + Separate subject from body with a blank line + + Limit the subject line to 50 characters + + Capitalizethesubject line + + Do not end the subject line with a period + + Use the imperative mood in the subject line + + Wrap the body at 72 characters + + Use the body to explain *what* and *why* vs. *how* + + In the end, put a link to the ticket + + Add "Reviewed by: ?" line. Example: + + Issue 48085 - Expand the repl acceptance test suite + Description: Add 6 more test cases to the replication + test suite as a part of the TET to + pytest porting initiative. + Increase the number of seconds we wait before the results check. + + https://pagure.io/389-ds-base/issue/48085 + + Reviewed by: ? + + +12. Fixing Review Issues + + + If there are issues with your patch, git allows you to fix your + commits. + + If you're not already in that branch + + git checkout new_test_suite + + Make changes to some file + + Add changes to your commit and fix the commit message if necessary + + :: + + git commit -a --amend + + + You can also use “ git rebase -i ” to “squash” or combine several + commits into one commit. + + +A ways to make your code better in a pytest way +=============================================== + +Fixtures +-------- + +Basic info about fixtures - http://pytest.org/latest/fixture.html#fixtures + +Scope +~~~~~ + ++ the scope for which this fixture is shared, one of “function” + (default), “class”, “module”, “session” ++ Use “function”, if you want fixture to be applied for every test + case where it appears ++ Use “module”, if you want fixture to be applied for a whole test + suite (file you run) + +Parametrizing +~~~~~~~~~~~~~ + ++ Fixture functions can be parametrized in which case they will be + called multiple times, each time executing the set of dependent tests, + i. e. the tests that depend on this fixture. ++ You should put your params in list and then access it within you + fixture with request.param. For example: + + :: + + # First it will test with adding and deleting ENTRY to the first master then to the second + @pytest.fixture(params=[0, 1]) + def rdn_write_setup(topology_m2): + m_num = request.param + topology_m2.ms["master{}".format(m_num)].add_s(ENTRY) + def fin(): + topology_m2.ms["master{}".format(m_num)].delete_s(ENTRY_DN) + request.addfinalizer(fin) + + +Test cases +---------- + +Parametrizing +~~~~~~~~~~~~~ + ++ The built-in pytest.mark.parametrize decorator enables + parameterization of arguments for a test function. For example: + + :: + + ROOTDSE_DEF_ATTR_LIST = ('namingContexts', + 'supportedLDAPVersion', + 'supportedControl', + 'supportedExtension', + 'supportedSASLMechanisms', + 'vendorName', + 'vendorVersion') + @pytest.mark.parametrize("rootdse_attr_name", ROOTDSE_DEF_ATTR_LIST) + def test_def_rootdse_attr(topology_st, import_example_ldif, rootdse_attr_name): + """Tests that operational attributes + are not returned by default in rootDSE searches + """ + + log.info("Assert rootdse search hasn't {} attr".format(rootdse_attr_name)) + entries = topology_st.standalone.search_s("", ldap.SCOPE_BASE) + entry = str(entries[0]) + assert rootdse_attr_name not in entry + + ++ As you can see, unlike the fixture parametrizing, in the test case + you should first put the name of attributes, then the list (or tuple) + with values, and then put the attribute to the function declaration. ++ You can specify a few attributes for parametrizing + + :: + + @pytest.mark.parametrize("test_input,expected", [ + ("3+5", 8), + ("2+4", 6), + ("6*9", 42),]) + def test_eval(test_input, expected): + assert eval(test_input) == expected + + +Marking test functions and selecting them for a run +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ++ You can “mark” a test function with custom meta data like this: + + :: + + @pytest.mark.ssl + def test_search_sec_port(): + pass # perform some search through sec port + + ++ You can also set a module level marker in which case it will be + applied to all functions and methods defined in the module: + + :: + + import pytest + pytestmark = pytest.mark.ssl + + ++ You can then restrict a test run to only run tests marked with ssl: + + :: + + py.test -v -m ssl + ++ Or the inverse, running all tests except the ssl ones: + + :: + + py.test -v -m "not ssl" + ++ Select tests based on their node ID + + + You can provide one or more node IDs as positional arguments to + select only specified tests. This makes it easy to select tests based + on their module, class, method, or function name: + + py.test -v test_server.py::test_function1 + test_server.py::test_function2 + ++ Use -k expr to select tests based on their name + + + You can use the -k command line option to specify an expression + which implements a substring match on the test names instead of the + exact match on markers that -m provides. This makes it easy to select + tests based on their names + + :: + + py.test -v -k search + py.test -v -k "search or modify" + py.test -v -k "not modify" + +Asserting +~~~~~~~~~ + ++ pytest allows you to use the standard python assert for verifying + expectations and values in Python tests. For example, you can write + the following: + + :: + + def f(): + return 3 + def test_function(): + assert f() == 4 + + ++ You can put the message to assert , it will be shown when error + appears: + + :: + + assert a % 2 == 0, "value was odd, should be even" + + ++ In order to write assertions about raised exceptions, you can use + pytest.raises as a context manager like this: + + :: + + import pytest + def test_zero_division(): + with pytest.raises(ZeroDivisionError): + 1 / 0 + + ++ Or even like this, if you expect some particular exception: + + :: + + def test_recursion_depth(): + with pytest.raises(RuntimeError) as excinfo: + def f(): + f() + f() + assert 'maximum recursion' in str(excinfo.value) + + +lib389 and python-ldap functions +================================ + +Constants +--------- + +Basic constants +~~~~~~~~~~~~~~~ + +:: + + DEFAULT_SUFFIX = “dc=example,dc=com” + DN_DM = "cn=Directory Manager" + PW_DM = "password" + DN_CONFIG = "cn=config" + DN_SCHEMA = "cn=schema" + DN_LDBM = "cn=ldbm database,cn=plugins,cn=config" + DN_CONFIG_LDBM = "cn=config,cn=ldbm database,cn=plugins,cn=config" + DN_USERROOT_LDBM = "cn=userRoot,cn=ldbm database,cn=plugins,cn=config" + DN_MONITOR = "cn=monitor" + DN_MONITOR_SNMP = "cn=snmp,cn=monitor" + DN_MONITOR_LDBM = "cn=monitor,cn=ldbm database,cn=plugins,cn=config" + CMD_PATH_SETUP_DS = "setup-ds.pl" + CMD_PATH_REMOVE_DS = "remove-ds.pl" + CMD_PATH_SETUP_DS_ADMIN = "setup-ds-admin.pl" + CMD_PATH_REMOVE_DS_ADMIN = "remove-ds-admin.pl" + + +For more info check the source code at +https://pagure.io/lib389/blob/master/f/lib389/_constants.py . If +you need a constant, use this kind of import. +If you need a lot of constants, import with * + +:: + + from lib389._constants import CONSTANT_YOU_NEED + from lib389._constants import * + + +Add, Modify, and Delete Operations +---------------------------------- + +Please, use these methods for the operations that can't be performed +by DSLdapObjects. + +:: + + # Add an entry + USER_DN = 'cn=mreynolds,{}'.format(DEFAULT_SUFFIX) + standalone.add_s(Entry((USER_DN, { + 'objectclass': 'top person'.split(), + 'cn': 'mreynolds', + 'sn': 'reynolds', + 'userpassword': 'password' + }))) + + # Modify an entry + standalone.modify_s(USER_DN, [(ldap.MOD_REPLACE, 'cn', 'Mark Reynolds')]) + + # Delete an entry + standalone.delete_s(USER_DN) + + +Search and Bind Operations +-------------------------- + ++ By default when an instance is created and opened, it is already + authenticated as the Root DN(Directory Manager). ++ So you can just start searching without having to “bind” + +:: + + # Search + entries = standalone.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, '(cn=*)', ['cn']) + for entry in entries: + if 'Mark Reynolds' in entry.data['cn']: + log.info('Search found "Mark"') + print(entry.data['cn']) + + # Anonymous bind + bind_dn = "" + bind_pwd = "" + + # Bind as our test entry + bind_dn = USER_DN + bind_pwd = "password" + + # Bind as Directory Manager + bind_dn = DN_DM + bind_pwd = 1 + + standalone.simple_bind_s(bind_dn, bind_pwd) + + +Basic instance operations +------------------------- + +:: + + # First, create a new “instance” of a “DirSrv” object + standalone = DirSrv(verbose=False) + + # Set up the instance arguments (note - args_instance is a global dictionary + # in lib389, it contains other default values) + args_instance[SER_HOST] = HOST_STANDALONE + args_instance[SER_PORT] = PORT_STANDALONE + args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE + args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX + args_standalone = args_instance.copy() + # Allocate the instance - initialize the “DirSrv” object with our arguments + standalone.allocate(args_standalone) + # Check if the instance with the args exists + assert not standalone.exists() + # Create the instance - this runs setup-ds.pl and starts the server + standalone.create() + + # Open the instance - create a connection to the instance, + # and authenticates as the Root DN (cn=directory manager) + standalone.open() + # Done, you can start using the new instance + # While working with DirSrv object, you can set 'verbose' parameter to True in any moment + standalone.verbose = True + # To remove an instance, simply use: + standalone.delete() + # Start, Stop, and Restart the Server + standalone.start(timeout=10) + standalone.stop(timeout=10) + standalone.restart(timeout=10) + + # Returns True, if the instance was shutdowned disorderly + standalone.detectDisorderlyShutdown() + + +Setting up SSL/TLS +------------------ + +:: + + from lib389._constants import DEFAULT_SUFFIX, SECUREPORT_STANDALONE1 + + standalone.stop() + + # Re-init (create) the nss db + # pin.txt is created here and the password randomly generated + assert(standalone.nss_ssl.reinit() is True) + + # Create a self signed CA + # noise.txt is created here + assert(standalone.nss_ssl.create_rsa_ca() is True) + + # Create a key and a cert that is signed by the self signed ca + # This will use the hostname from the DS instance, and takes a list of extra names to take. + assert(standalone.nss_ssl.create_rsa_key_and_cert() is True) + + standalone.start() + + # Create "cn=RSA,cn=encryption,cn=config" with next properties: + # {'cn': 'RSA', 'nsSSLPersonalitySSL': 'Server-Cert', 'nsSSLActivation': 'on', 'nsSSLToken': 'internal (software)'} + standalone.rsa.create() + # Set the secure port and nsslapd-security + standalone.config.set('nsslapd-secureport', str(SECUREPORT_STANDALONE1)) + standalone.config.set('nsslapd-security', 'on') + standalone.sslport = SECUREPORT_STANDALONE1 + + # Restart to allow certmaps to be re-read: Note, we CAN NOT use post_open + standalone.restart(post_open=False) + + +Certification-based authentication +---------------------------------- + +You need to setup and turn on SSL first (use the previous chapter). + +:: + + from lib389.config import CertmapLegacy + + standalone.stop() + + # Create a user + assert(standalone.nss_ssl.create_rsa_user('testuser') is True) + + # Get the details of where the key and crt are + # {'ca': ca_path, 'key': key_path, 'crt': crt_path} + tls_locs = standalone.nss_ssl.get_rsa_user('testuser') + + standalone.start() + + # Create user in the directory + users = UserAccounts(standalone, DEFAULT_SUFFIX) + users.create(properties={ + 'uid': 'testuser', + 'cn' : 'testuser', + 'sn' : 'user', + 'uidNumber' : '1000', + 'gidNumber' : '2000', + 'homeDirectory' : '/home/testuser' + }) + + # Turn on the certmap + cm = CertmapLegacy(standalone) + certmaps = cm.list() + certmaps['default']['DNComps'] = '' + certmaps['default']['FilterComps'] = ['cn'] + certmaps['default']['VerifyCert'] = 'off' + cm.set(certmaps) + + # Restart to allow certmaps to be re-read: Note, we CAN NOT use post_open + standalone.restart(post_open=False) + + # Now attempt a bind with TLS external + conn = standalone.openConnection(saslmethod='EXTERNAL', connOnly=True, certdir=standalone.get_cert_dir(), userkey=tls_locs['key'], usercert=tls_locs['crt']) + + assert(conn.whoami_s() == "dn: uid=testuser,ou=People,dc=example,dc=com") + + +Replication +----------- + +Basic configuration + + ++ After the instance is created, you can enable it for replication and + set up a replication agreement. + +:: + + from lib389.replica import Replicas + + # Enable replication + replicas = Replicas(standalone) + replica = replicas.enable(suffix=DEFAULT_SUFFIX, + role=REPLICAROLE_MASTER, + replicaID=REPLICAID_MASTER_1) + # Set up replication agreement properties + properties = {RA_NAME: r'meTo_{}:{}'.format(master2.host, port=master2.port), + RA_BINDDN: defaultProperties[REPLICATION_BIND_DN], + RA_BINDPW: defaultProperties[REPLICATION_BIND_PW], + RA_METHOD: defaultProperties[REPLICATION_BIND_METHOD], + RA_TRANSPORT_PROT: defaultProperties[REPLICATION_TRANSPORT]} + + # Create the agreement + repl_agreement = standalone.agreement.create(suffix=DEFAULT_SUFFIX, + host=master2.host, + port=master2.port, + properties=properties) + # “master2” refers to another, already created, DirSrv instance(like “standalone”) + # “repl_agreement” is the “DN” of the newly created agreement - this DN is needed later to do certain tasks + + # Initialize the agreement, wait for it complete, and test that replication is really working + standalone.agreement.init(DEFAULT_SUFFIX, master2.host, master2.port) + standalone.waitForReplInit(repl_agreement) + assert standalone.testReplication(DEFAULT_SUFFIX, master2) diff --git a/doc/source/index.rst b/doc/source/index.rst new file mode 100644 index 0000000..55e10ef --- /dev/null +++ b/doc/source/index.rst @@ -0,0 +1,40 @@ +.. lib389 documentation master file, created by + sphinx-quickstart on Wed Aug 23 18:43:30 2017. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to lib389's documentation! +================================== + +Lib389 is a python base library for managing Directory servers. +It was initially created to help writing tests of DS. It can also used +to create new administration CLIs. This document is focusing on writing +tests for the Directory Server. Lib389 can be used to generate individual +testcases(tickets), and suites that test a range of functionality/feature. + + +Contents +======== + +.. toctree:: + :maxdepth: 3 + + guidelines.rst + + +Contact us +========== + +If you have any issue or a question, you have a few options: + ++ write an email to 389-devel@lists.fedoraproject.org ++ ask on irc.freenode.net channel #389 ++ check (or create a new) issues on https://pagure.io/lib389 + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` +
389-commits@lists.fedoraproject.org