1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
|
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Debug and logging — pyroute2 0.5.14 documentation</title>
<link rel="stylesheet" href="_static/classic.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="_static/graphviz.css" />
<link rel="stylesheet" type="text/css" href="_static/custom.css" />
<script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/language_data.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Authorization plugins" href="ndb_auth.html" />
<link rel="prev" title="RTNL sources" href="ndb_sources.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="ndb_auth.html" title="Authorization plugins"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="ndb_sources.html" title="RTNL sources"
accesskey="P">previous</a> |</li>
<li class="nav-item"><a href="http://pyroute2.org">Project home</a> »</li>
<li class="nav-item nav-item-0"><a href="index.html">pyroute2 0.5.14 documentation</a> »</li>
<li class="nav-item nav-item-1"><a href="ndb.html" accesskey="U">NDB module</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="debug-and-logging">
<span id="ndbdebug"></span><h1>Debug and logging<a class="headerlink" href="#debug-and-logging" title="Permalink to this headline">¶</a></h1>
<div class="section" id="logging">
<h2>Logging<a class="headerlink" href="#logging" title="Permalink to this headline">¶</a></h2>
<p>A simple way to set up stderr logging:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># to start logging on the DB init</span>
<span class="n">ndb</span> <span class="o">=</span> <span class="n">NDB</span><span class="p">(</span><span class="n">log</span><span class="o">=</span><span class="s1">'on'</span><span class="p">)</span>
<span class="c1"># ... or to start it in run time</span>
<span class="n">ndb</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="s1">'on'</span><span class="p">)</span>
<span class="c1"># ... the same as above, another syntax</span>
<span class="n">ndb</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">on</span>
<span class="c1"># ... turn logging off</span>
<span class="n">ndb</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="s1">'off'</span><span class="p">)</span>
<span class="c1"># ... or</span>
<span class="n">ndb</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">off</span>
</pre></div>
</div>
<p>It is possible also to set up logging to a file or to a syslog server:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1">#</span>
<span class="n">ndb</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="s1">'file_name.log'</span><span class="p">)</span>
<span class="c1">#</span>
<span class="n">ndb</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="s1">'syslog://server:port'</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="fetching-db-data">
<h2>Fetching DB data<a class="headerlink" href="#fetching-db-data" title="Permalink to this headline">¶</a></h2>
<p>By default, NDB starts with an in-memory SQLite3 database. In order to
perform post mortem analysis it may be more useful to start the DB with
a file DB or a PostgreSQL as the backend.</p>
<p>See more: <a class="reference internal" href="ndb_schema.html#ndbschema"><span class="std std-ref">Database</span></a></p>
<p>It is possible to dump all the DB data with <cite>schema.export()</cite>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">NDB</span><span class="p">()</span> <span class="k">as</span> <span class="n">ndb</span><span class="p">:</span>
<span class="n">ndb</span><span class="o">.</span><span class="n">schema</span><span class="o">.</span><span class="n">export</span><span class="p">(</span><span class="s1">'stderr'</span><span class="p">)</span> <span class="c1"># dump the DB to stderr</span>
<span class="o">...</span>
<span class="n">ndb</span><span class="o">.</span><span class="n">schema</span><span class="o">.</span><span class="n">export</span><span class="p">(</span><span class="s1">'pr2_debug'</span><span class="p">)</span> <span class="c1"># dump the DB to a file</span>
</pre></div>
</div>
</div>
<div class="section" id="rtnl-events">
<h2>RTNL events<a class="headerlink" href="#rtnl-events" title="Permalink to this headline">¶</a></h2>
<p>All the loaded RTNL events may be stored in the DB. To turn that feature
on, one should start NDB with the <cite>debug</cite> option:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ndb</span> <span class="o">=</span> <span class="n">NDB</span><span class="p">(</span><span class="n">rtnl_debug</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
<p>The events may be exported with the same <cite>schema.export()</cite>.</p>
<p>Unlike ordinary table, limited with the number of network objects in the
system, the events log tables are not limited. Do not enable the events
logging in production, it may exhaust all the memory.</p>
</div>
<div class="section" id="rtnl-objects">
<h2>RTNL objects<a class="headerlink" href="#rtnl-objects" title="Permalink to this headline">¶</a></h2>
<p>NDB creates RTNL objects on demand, it doesn’t keep them all the time.
References to created objects are linked to the <cite>ndb.<view>.cache</cite> set:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">ndb</span><span class="o">.</span><span class="n">interfaces</span><span class="o">.</span><span class="n">cache</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>
<span class="go">[(('target', u'localhost'), ('index', 2)),</span>
<span class="go"> (('target', u'localhost'), ('index', 39615))]</span>
<span class="gp">>>> </span><span class="p">[</span><span class="n">x</span><span class="p">[</span><span class="s1">'ifname'</span><span class="p">]</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">ndb</span><span class="o">.</span><span class="n">interfaces</span><span class="o">.</span><span class="n">cache</span><span class="o">.</span><span class="n">values</span><span class="p">()]</span>
<span class="go">[u'eth0', u't2']</span>
</pre></div>
</div>
</div>
<div class="section" id="object-states">
<h2>Object states<a class="headerlink" href="#object-states" title="Permalink to this headline">¶</a></h2>
<p>RTNL objects may be in several states:</p>
<blockquote>
<div><ul class="simple">
<li><p>invalid: the object does not exist in the system</p></li>
<li><p>system: the object exists both in the system and in NDB</p></li>
<li><p>setns: the existing object should be moved to another network namespace</p></li>
<li><p>remove: the existing object must be deleted from the system</p></li>
</ul>
</div></blockquote>
<p>The state transitions are logged in the state log:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">pyroute2</span> <span class="k">import</span> <span class="n">NDB</span>
<span class="gp">>>> </span><span class="n">ndb</span> <span class="o">=</span> <span class="n">NDB</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">c</span> <span class="o">=</span> <span class="n">ndb</span><span class="o">.</span><span class="n">interfaces</span><span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="n">ifname</span><span class="o">=</span><span class="s1">'t0'</span><span class="p">,</span> <span class="n">kind</span><span class="o">=</span><span class="s1">'dummy'</span><span class="p">)</span><span class="o">.</span><span class="n">commit</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">c</span><span class="o">.</span><span class="n">state</span><span class="o">.</span><span class="n">events</span>
<span class="go">[</span>
<span class="go"> (1557752212.6703758, 'invalid'),</span>
<span class="go"> (1557752212.6821117, 'system')</span>
<span class="go">]</span>
</pre></div>
</div>
<p>The timestamps allow to correlate the state transitions with the
NDB log and the RTNL events log, in the case it was enabled.</p>
</div>
<div class="section" id="object-snapshots">
<h2>Object snapshots<a class="headerlink" href="#object-snapshots" title="Permalink to this headline">¶</a></h2>
<p>Before running any commit, NDB marks all the related records in the DB
with a random value in the <cite>f_tflags</cite> DB field (<cite>tflags</cite> object field),
and stores all the marked records in the snapshot tables. Shortly, the
<cite>commit()</cite> is a <cite>snapshot() + apply() + revert() if failed</cite>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">nic</span> <span class="o">=</span> <span class="n">ndb</span><span class="o">.</span><span class="n">interfaces</span><span class="p">[</span><span class="s1">'t0'</span><span class="p">]</span>
<span class="gp">>>> </span><span class="n">nic</span><span class="p">[</span><span class="s1">'state'</span><span class="p">]</span>
<span class="go">'down'</span>
<span class="gp">>>> </span><span class="n">nic</span><span class="p">[</span><span class="s1">'state'</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'up'</span>
<span class="gp">>>> </span><span class="n">snapshot</span> <span class="o">=</span> <span class="n">nic</span><span class="o">.</span><span class="n">snapshot</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">ndb</span><span class="o">.</span><span class="n">schema</span><span class="o">.</span><span class="n">snapshots</span>
<span class="go">{</span>
<span class="go"> 'addresses_139736119707256': <weakref at 0x7f16d8391a98; to 'Interface' at 0x7f16d9c708e0>,</span>
<span class="go"> 'neighbours_139736119707256': <weakref at 0x7f16d8391a98; to 'Interface' at 0x7f16d9c708e0>,</span>
<span class="go"> 'routes_139736119707256': <weakref at 0x7f16d8391a98; to 'Interface' at 0x7f16d9c708e0>,</span>
<span class="go"> 'nh_139736119707256': <weakref at 0x7f16d8391a98; to 'Interface' at 0x7f16d9c708e0>,</span>
<span class="go"> 'p2p_139736119707256': <weakref at 0x7f16d8391a98; to 'Interface' at 0x7f16d9c708e0>,</span>
<span class="go"> 'ifinfo_bridge_139736119707256': <weakref at 0x7f16d8391a98; to 'Interface' at 0x7f16d9c708e0>,</span>
<span class="go"> 'ifinfo_bond_139736119707256': <weakref at 0x7f16d8391a98; to 'Interface' at 0x7f16d9c708e0>,</span>
<span class="go"> 'ifinfo_vlan_139736119707256': <weakref at 0x7f16d8391a98; to 'Interface' at 0x7f16d9c708e0>,</span>
<span class="go"> 'ifinfo_vxlan_139736119707256': <weakref at 0x7f16d8391a98; to 'Interface' at 0x7f16d9c708e0>,</span>
<span class="go"> 'ifinfo_gre_139736119707256': <weakref at 0x7f16d8391a98; to 'Interface' at 0x7f16d9c708e0>,</span>
<span class="go"> 'ifinfo_vrf_139736119707256': <weakref at 0x7f16d8391a98; to 'Interface' at 0x7f16d9c708e0>,</span>
<span class="go"> 'ifinfo_vti_139736119707256': <weakref at 0x7f16d8391a98; to 'Interface' at 0x7f16d9c708e0>,</span>
<span class="go"> 'ifinfo_vti6_139736119707256': <weakref at 0x7f16d8391a98; to 'Interface' at 0x7f16d9c708e0>,</span>
<span class="go"> 'interfaces_139736119707256': <weakref at 0x7f16d8391a98; to 'Interface' at 0x7f16d9c708e0></span>
<span class="go">}</span>
<span class="gp">>>> </span><span class="n">nic</span><span class="o">.</span><span class="n">apply</span><span class="p">()</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">nic</span><span class="p">[</span><span class="s1">'state'</span><span class="p">]</span>
<span class="go">'up'</span>
<span class="gp">>>> </span><span class="n">snapshot</span><span class="o">.</span><span class="n">apply</span><span class="p">(</span><span class="n">rollback</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">nic</span><span class="p">[</span><span class="s1">'state'</span><span class="p">]</span>
<span class="go">'down'</span>
</pre></div>
</div>
<p>Or same:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">nic</span> <span class="o">=</span> <span class="n">ndb</span><span class="o">.</span><span class="n">interfaces</span><span class="p">[</span><span class="s1">'t0'</span><span class="p">]</span>
<span class="gp">>>> </span><span class="n">nic</span><span class="p">[</span><span class="s1">'state'</span><span class="p">]</span>
<span class="go">'down'</span>
<span class="gp">>>> </span><span class="n">nic</span><span class="p">[</span><span class="s1">'state'</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'up'</span>
<span class="gp">>>> </span><span class="n">nic</span><span class="o">.</span><span class="n">commit</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">nic</span><span class="p">[</span><span class="s1">'state'</span><span class="p">]</span>
<span class="go">'up'</span>
<span class="gp">>>> </span><span class="n">nic</span><span class="o">.</span><span class="n">rollback</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">nic</span><span class="p">[</span><span class="s1">'state'</span><span class="p">]</span>
<span class="go">'down'</span>
</pre></div>
</div>
<p>These snapshot tables are the objects’ state before the changes were applied.</p>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Debug and logging</a><ul>
<li><a class="reference internal" href="#logging">Logging</a></li>
<li><a class="reference internal" href="#fetching-db-data">Fetching DB data</a></li>
<li><a class="reference internal" href="#rtnl-events">RTNL events</a></li>
<li><a class="reference internal" href="#rtnl-objects">RTNL objects</a></li>
<li><a class="reference internal" href="#object-states">Object states</a></li>
<li><a class="reference internal" href="#object-snapshots">Object snapshots</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="ndb_sources.html"
title="previous chapter">RTNL sources</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="ndb_auth.html"
title="next chapter">Authorization plugins</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/ndb_debug.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="ndb_auth.html" title="Authorization plugins"
>next</a> |</li>
<li class="right" >
<a href="ndb_sources.html" title="RTNL sources"
>previous</a> |</li>
<li class="nav-item"><a href="http://pyroute2.org">Project home</a> »</li>
<li class="nav-item nav-item-0"><a href="index.html">pyroute2 0.5.14 documentation</a> »</li>
<li class="nav-item nav-item-1"><a href="ndb.html" >NDB module</a> »</li>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2013, Peter V. Saveliev.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 2.1.2.
</div>
</body>
</html>
|