Skip to content

Commit

Permalink
Deployed e4688e1 to main with MkDocs 1.6.0 and mike 2.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed May 15, 2024
1 parent 8a49146 commit 2d18c7f
Show file tree
Hide file tree
Showing 63 changed files with 3,861 additions and 5,081 deletions.
16 changes: 8 additions & 8 deletions main/advanced_usages/as-python-lib/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2320,23 +2320,23 @@ <h1>ANTA as a Python Library</h1>
<p class="admonition-title">Tip</p>
<p>If you are unfamiliar with asyncio, refer to the Python documentation relevant to your Python version - <a href="https://docs.python.org/3/library/asyncio.html">https://docs.python.org/3/library/asyncio.html</a></p>
</div>
<h4 id="antadevice-abstract-class"><a href="../../api/device/#anta.device.AntaDevice">AntaDevice</a> Abstract Class<a class="headerlink" href="#antadevice-abstract-class" title="Permanent link">&para;</a></h4>
<h2 id="antadevice-abstract-class"><a href="../../api/device/#anta.device.AntaDevice">AntaDevice</a> Abstract Class<a class="headerlink" href="#antadevice-abstract-class" title="Permanent link">&para;</a></h2>
<p>A device is represented in ANTA as a instance of a subclass of the <a href="../../api/device/### ::: anta.device.AntaDevice">AntaDevice</a> abstract class.
There are few abstract methods that needs to be implemented by child classes:</p>
<ul>
<li>The <a href="../../api/device/#anta.device.AntaDevice.collect">collect()</a> coroutine is in charge of collecting outputs of <a href="../../api/models/#anta.models.AntaCommand">AntaCommand</a> instances.</li>
<li>The <a href="../../api/device/#anta.device.AntaDevice.refresh">refresh()</a> coroutine is in charge of updating attributes of the <a href="../../api/device/### ::: anta.device.AntaDevice">AntaDevice</a> instance. These attributes are used by <a href="../../api/inventory/#anta.inventory.AntaInventory">AntaInventory</a> to filter out unreachable devices or by <a href="../../api/models/#anta.models.AntaTest">AntaTest</a> to skip devices based on their hardware models.</li>
</ul>
<p>The <a href="../../api/device/#anta.device.AntaDevice.copy">copy()</a> coroutine is used to copy files to and from the device. It does not need to be implemented if tests are not using it.</p>
<h5 id="asynceosdevice-class"><a href="../../api/device/#anta.device.AsyncEOSDevice">AsyncEOSDevice</a> Class<a class="headerlink" href="#asynceosdevice-class" title="Permanent link">&para;</a></h5>
<h3 id="asynceosdevice-class"><a href="../../api/device/#anta.device.AsyncEOSDevice">AsyncEOSDevice</a> Class<a class="headerlink" href="#asynceosdevice-class" title="Permanent link">&para;</a></h3>
<p>The <a href="../../api/device/#anta.device.AsyncEOSDevice">AsyncEOSDevice</a> class is an implementation of <a href="../../api/device/#anta.device.AntaDevice">AntaDevice</a> for Arista EOS.
It uses the <a href="https://github.com/jeremyschulman/aio-eapi">aio-eapi</a> eAPI client and the <a href="https://github.com/ronf/asyncssh">AsyncSSH</a> library.</p>
<ul>
<li>The <a href="../../api/device/#anta.device.AsyncEOSDevice.collect">collect()</a> coroutine collects <a href="../../api/models/#anta.models.AntaCommand">AntaCommand</a> outputs using eAPI.</li>
<li>The <a href="../../api/device/#anta.device.AsyncEOSDevice.refresh">refresh()</a> coroutine tries to open a TCP connection on the eAPI port and update the <code>is_online</code> attribute accordingly. If the TCP connection succeeds, it sends a <code>show version</code> command to gather the hardware model of the device and updates the <code>established</code> and <code>hw_model</code> attributes.</li>
<li>The <a href="../../api/device/#anta.device.AsyncEOSDevice.copy">copy()</a> coroutine copies files to and from the device using the SCP protocol.</li>
</ul>
<h4 id="antainventory-class"><a href="../../api/inventory/#anta.inventory.AntaInventory">AntaInventory</a> Class<a class="headerlink" href="#antainventory-class" title="Permanent link">&para;</a></h4>
<h2 id="antainventory-class"><a href="../../api/inventory/#anta.inventory.AntaInventory">AntaInventory</a> Class<a class="headerlink" href="#antainventory-class" title="Permanent link">&para;</a></h2>
<p>The <a href="../../api/inventory/#anta.inventory.AntaInventory">AntaInventory</a> class is a subclass of the standard Python type <a href="https://docs.python.org/3/library/stdtypes.html#dict">dict</a>. The keys of this dictionary are the device names, the values are <a href="../../api/device/#anta.device.AntaDevice">AntaDevice</a> instances.</p>
<p><a href="../../api/inventory/#anta.inventory.AntaInventory">AntaInventory</a> provides methods to interact with the ANTA inventory:</p>
<ul>
Expand Down Expand Up @@ -2439,9 +2439,9 @@ <h4 id="antainventory-class"><a href="../../api/inventory/#anta.inventory.AntaIn

<span class="n">pprint</span><span class="p">(</span><span class="n">res</span><span class="p">)</span>
</code></pre></div></p>
<h4 id="use-tests-from-anta">Use tests from ANTA<a class="headerlink" href="#use-tests-from-anta" title="Permanent link">&para;</a></h4>
<h2 id="use-tests-from-anta">Use tests from ANTA<a class="headerlink" href="#use-tests-from-anta" title="Permanent link">&para;</a></h2>
<p>All the test classes inherit from the same abstract Base Class AntaTest. The Class definition indicates which commands are required for the test and the user should focus only on writing the <code>test</code> function with optional keywords argument. The instance of the class upon creation instantiates a TestResult object that can be accessed later on to check the status of the test ([unset, skipped, success, failure, error]).</p>
<h5 id="test-structure">Test structure<a class="headerlink" href="#test-structure" title="Permanent link">&para;</a></h5>
<h3 id="test-structure">Test structure<a class="headerlink" href="#test-structure" title="Permanent link">&para;</a></h3>
<p>All tests are built on a class named <code>AntaTest</code> which provides a complete toolset for a test:</p>
<ul>
<li>Object creation</li>
Expand Down Expand Up @@ -2530,9 +2530,9 @@ <h5 id="test-structure">Test structure<a class="headerlink" href="#test-structur
<span class="n">asyncio</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">test</span><span class="o">.</span><span class="n">test</span><span class="p">())</span>
<span class="k">assert</span> <span class="n">test</span><span class="o">.</span><span class="n">result</span><span class="o">.</span><span class="n">result</span> <span class="o">==</span> <span class="s2">&quot;success&quot;</span>
</code></pre></div>
<h5 id="classes-for-commands">Classes for commands<a class="headerlink" href="#classes-for-commands" title="Permanent link">&para;</a></h5>
<h3 id="classes-for-commands">Classes for commands<a class="headerlink" href="#classes-for-commands" title="Permanent link">&para;</a></h3>
<p>To make it easier to get data, ANTA defines 2 different classes to manage commands to send to devices:</p>
<h6 id="antacommand-class"><a href="../../api/models/#anta.models.AntaCommand">AntaCommand</a> Class<a class="headerlink" href="#antacommand-class" title="Permanent link">&para;</a></h6>
<h4 id="antacommand-class"><a href="../../api/models/#anta.models.AntaCommand">AntaCommand</a> Class<a class="headerlink" href="#antacommand-class" title="Permanent link">&para;</a></h4>
<p>Represent a command with following information:</p>
<ul>
<li>Command to run</li>
Expand Down Expand Up @@ -2561,7 +2561,7 @@ <h6 id="antacommand-class"><a href="../../api/models/#anta.models.AntaCommand">A
commands = [AntaCommand(command=&quot;show bfd peers&quot;, revision=1)]
</code></pre></div>
</div>
<h6 id="antatemplate-class"><a href="../../api/models/#anta.models.AntaTemplate">AntaTemplate</a> Class<a class="headerlink" href="#antatemplate-class" title="Permanent link">&para;</a></h6>
<h4 id="antatemplate-class"><a href="../../api/models/#anta.models.AntaTemplate">AntaTemplate</a> Class<a class="headerlink" href="#antatemplate-class" title="Permanent link">&para;</a></h4>
<p>Because some command can require more dynamic than just a command with no parameter provided by user, ANTA supports command template: you define a template in your test class and user provide parameters when creating test object.</p>
<div class="highlight"><pre><span></span><code><span class="k">class</span> <span class="nc">RunArbitraryTemplateCommand</span><span class="p">(</span><span class="n">AntaTest</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
Expand Down
10 changes: 5 additions & 5 deletions main/advanced_usages/caching/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2204,7 +2204,7 @@ <h1>Caching in ANTA</h1>
-->

<p>ANTA is a streamlined Python framework designed for efficient interaction with network devices. This section outlines how ANTA incorporates caching mechanisms to collect command outputs from network devices.</p>
<h4 id="configuration">Configuration<a class="headerlink" href="#configuration" title="Permanent link">&para;</a></h4>
<h2 id="configuration">Configuration<a class="headerlink" href="#configuration" title="Permanent link">&para;</a></h2>
<p>By default, ANTA utilizes <a href="https://github.com/aio-libs/aiocache">aiocache</a>&rsquo;s memory cache backend, also called <a href="https://aiocache.aio-libs.org/en/v0.12.2/caches.html#simplememorycache"><code>SimpleMemoryCache</code></a>. This library aims for simplicity and supports asynchronous operations to go along with Python <code>asyncio</code> used in ANTA.</p>
<p>The <code>_init_cache()</code> method of the <a href="../as-python-lib/#antadevice-abstract-class">AntaDevice</a> abstract class initializes the cache. Child classes can override this method to tweak the cache configuration:</p>
<div class="highlight"><pre><span></span><code><span class="k">def</span> <span class="nf">_init_cache</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
Expand All @@ -2215,14 +2215,14 @@ <h4 id="configuration">Configuration<a class="headerlink" href="#configuration"
<span class="bp">self</span><span class="o">.</span><span class="n">cache_locks</span> <span class="o">=</span> <span class="n">defaultdict</span><span class="p">(</span><span class="n">asyncio</span><span class="o">.</span><span class="n">Lock</span><span class="p">)</span>
</code></pre></div>
<p>The cache is also configured with <code>aiocache</code>&rsquo;s <a href="https://aiocache.aio-libs.org/en/v0.12.2/plugins.html#hitmissratioplugin"><code>HitMissRatioPlugin</code></a> plugin to calculate the ratio of hits the cache has and give useful statistics for logging purposes in ANTA.</p>
<h4 id="cache-key-design">Cache key design<a class="headerlink" href="#cache-key-design" title="Permanent link">&para;</a></h4>
<h2 id="cache-key-design">Cache key design<a class="headerlink" href="#cache-key-design" title="Permanent link">&para;</a></h2>
<p>The cache is initialized per <code>AntaDevice</code> and uses the following cache key design:</p>
<p><code>&lt;device_name&gt;:&lt;uid&gt;</code></p>
<p>The <code>uid</code> is an attribute of <a href="../as-python-lib/#antacommand-class">AntaCommand</a>, which is a unique identifier generated from the command, version, revision and output format.</p>
<p>Each UID has its own asyncio lock. This design allows coroutines that need to access the cache for different UIDs to do so concurrently. The locks are managed by the <code>self.cache_locks</code> dictionary.</p>
<h4 id="mechanisms">Mechanisms<a class="headerlink" href="#mechanisms" title="Permanent link">&para;</a></h4>
<h2 id="mechanisms">Mechanisms<a class="headerlink" href="#mechanisms" title="Permanent link">&para;</a></h2>
<p>By default, once the cache is initialized, it is used in the <code>collect()</code> method of <code>AntaDevice</code>. The <code>collect()</code> method prioritizes retrieving the output of the command from the cache. If the output is not in the cache, the private <code>_collect()</code> method will retrieve and then store it for future access.</p>
<h4 id="how-to-disable-caching">How to disable caching<a class="headerlink" href="#how-to-disable-caching" title="Permanent link">&para;</a></h4>
<h2 id="how-to-disable-caching">How to disable caching<a class="headerlink" href="#how-to-disable-caching" title="Permanent link">&para;</a></h2>
<p>Caching is enabled by default in ANTA following the previous configuration and mechanisms.</p>
<p>There might be scenarios where caching is not wanted. You can disable caching in multiple ways in ANTA:</p>
<ol>
Expand Down Expand Up @@ -2257,7 +2257,7 @@ <h4 id="how-to-disable-caching">How to disable caching<a class="headerlink" href
<p>For tests developers, caching can be disabled for a specific <a href="../as-python-lib/#antacommand-class"><code>AntaCommand</code></a> or <a href="../as-python-lib/#antatemplate-class"><code>AntaTemplate</code></a> by setting the <code>use_cache</code> attribute to <code>False</code>. That means the command output will always be collected on the device and therefore, never use caching.</p>
</li>
</ol>
<h5 id="disable-caching-in-a-child-class-of-antadevice">Disable caching in a child class of <code>AntaDevice</code><a class="headerlink" href="#disable-caching-in-a-child-class-of-antadevice" title="Permanent link">&para;</a></h5>
<h3 id="disable-caching-in-a-child-class-of-antadevice">Disable caching in a child class of <code>AntaDevice</code><a class="headerlink" href="#disable-caching-in-a-child-class-of-antadevice" title="Permanent link">&para;</a></h3>
<p>Since caching is implemented at the <code>AntaDevice</code> abstract class level, all subclasses will inherit that default behavior. As a result, if you need to disable caching in any custom implementation of <code>AntaDevice</code> outside of the ANTA framework, you must initialize <code>AntaDevice</code> with <code>disable_cache</code> set to <code>True</code>:</p>
<div class="highlight"><pre><span></span><code><span class="k">class</span> <span class="nc">AnsibleEOSDevice</span><span class="p">(</span><span class="n">AntaDevice</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
Expand Down
Loading

0 comments on commit 2d18c7f

Please sign in to comment.