Commit 0b371f2b authored by Ladislav Lhotka's avatar Ladislav Lhotka

Fix doctests

parent ac13603a
Pipeline #40386 passed with stages
in 51 seconds
......@@ -42,14 +42,11 @@ If you are prompted to upgrade *pip*, you can do that, too.
The virtual environment can be entered anytime later by executing step 3. The steps preceding it need to be performed just once.
Now you can edit and install Resolvers-YANG.
============
Installation
============
===================
System Installation
===================
::
$ git clone https://gitlab.labs.nic.cz/labs/resolvers-yang
$ cd resolvers-yang
$ python3 setup.py install
**************************
*************
Library Usage
**************************
*************
.. testsetup::
>>> import os
>>> os.chdir("..")
import os
os.chdir("../examples")
For better understanding, look at the :ref:`examples` and `Yangson library <https://yangson.labs.nic.cz/quickstart.html#>`_
=============
=======
Yangson
=============
=======
`Yangson <https://yangson.labs.nic.cz/quickstart.html#>`_ is a Python3 library for working with JSON-encoded [RFC7951]_
configuration and state data modelled using the YANG [RFC7895]_
......@@ -23,36 +23,36 @@ Import necessary python modules.
.. doctest::
>>> from json import load
>>> from yangson.datamodel import DataModel
>>> from json import load
>>> from yangson.datamodel import DataModel
Initialize the YANG data model. It can be done easily
by reading YANG library data [RFC7895]_ from a file:
.. doctest::
>>> model = DataModel.from_file('yang-modules/yanglib.json')
>>> model = DataModel.from_file('../yang-modules/yanglib.json', ["../yang-modules"])
Load data from Json-encoded file [RFC7951]_
.. doctest::
>>> with open('examples/example-data.json') as infile:
... ri = load(infile)
>>> json_data = model.from_raw(ri)
>>> with open('example-data.json') as infile:
... ri = load(infile)
>>> json_data = model.from_raw(ri)
Validate data against the data model:
.. doctest::
>>> json_data.validate()
>>> json_data.validate()
Now the data is valid and you can work with it.
=================
===============
Library Modules
=================
===============
Generator module
----------------
......@@ -65,15 +65,15 @@ Import ``gen_unbound`` and ``gen_kresd`` functions to generate Unbound and Knot
.. doctest::
>>> from resolvers_yang.generator import gen_unbound, gen_kresd
>>> from resolvers_yang.generator import gen_unbound, gen_kresd
Call generator functions to generate `unbound.conf` and `kresd.conf`.
.. doctest::
>>> unbound_conf = gen_unbound(json_data)
>>> kresd_conf = gen_kresd(json_data)
>>> unbound_conf = gen_unbound(json_data)
>>> kresd_conf = gen_kresd(json_data)
``unbound_conf`` and ``kresd_conf`` are configuration strings , which can be save as text files.
......@@ -88,13 +88,13 @@ Import ``from_unbound`` function for converting Unbound configuration string to
.. doctest::
>>> from resolvers_yang.converter import from_unbound
>>> from resolvers_yang.converter import from_unbound
Input parameter of ``from_unbound`` function is string loaded from ``unbound.con`` file. Returns python dictionary.
.. doctest::
>>> json_data = from_unbound(unbound_conf)
>>> json_data = from_unbound(unbound_conf)
``json_data`` variable is python dictionary, which can be easily validate against data model by ``Yangson`` library and save to Json-encoded file.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment