improve coverage with all real vyos commands exported from iso

This commit is contained in:
rebortg 2022-05-31 21:16:48 +02:00
parent 336b4498b8
commit 68a335a086
4 changed files with 120142 additions and 21 deletions

View File

@ -1,14 +1,13 @@
''' '''
generate json with all commands from xml for vyos documentation coverage generate json with all commands from xml for vyos documentation coverage
''' '''
import sys import sys
import os import os
import json import json
import re import re
import logging import logging
import datetime
from io import BytesIO from io import BytesIO
from lxml import etree as ET from lxml import etree as ET
@ -33,11 +32,32 @@ input_data = [
} }
] ]
vyos_commands_dir = "_include/coverage"
node_data = { node_data = {
'cfgcmd': {}, 'cfgcmd': {},
'opcmd': {}, 'opcmd': {},
} }
def get_vyos_commands():
return_data = None
for (dirpath, dirnames, filenames) in os.walk(vyos_commands_dir):
for file in filenames:
with open(f"{vyos_commands_dir}/{file}") as f:
data = json.load(f)
if not return_data:
return_data = data
# find latestes export
if datetime.datetime.fromisoformat(return_data['date']) < datetime.datetime.fromisoformat(data['date']):
return_data = data
return return_data
def get_properties(p): def get_properties(p):
props = {} props = {}
props['valueless'] = False props['valueless'] = False
@ -378,6 +398,4 @@ def override_element(l: list):
el.getparent().remove(el) el.getparent().remove(el)
if __name__ == "__main__": if __name__ == "__main__":
res = get_working_commands() get_vyos_commands()
print(json.dumps(res))
#print(res['cfgcmd'][0])

View File

@ -8,7 +8,7 @@ from docutils.parsers.rst import Directive, directives, states
from sphinx.util.docutils import SphinxDirective from sphinx.util.docutils import SphinxDirective
from testcoverage import get_working_commands from testcoverage import get_working_commands, get_vyos_commands
from sphinx.util import logging from sphinx.util import logging
@ -28,6 +28,11 @@ def setup(app):
#{"cfgcmd": [], "opcmd": []}, #{"cfgcmd": [], "opcmd": []},
'html' 'html'
) )
app.add_config_value(
'vyos_commands',
get_vyos_commands(),
'html'
)
app.add_config_value( app.add_config_value(
'vyos_coverage', 'vyos_coverage',
{ {
@ -550,17 +555,20 @@ def build_row(app, fromdocname, rowdata):
def process_coverage(app, fromdocname, doccmd, xmlcmd, cli_type): def process_coverage(app, fromdocname, doccmd, xmlcmd, vyoscmd, cli_type):
coverage_list = {} coverage_list = {}
strip_true_list = [] strip_true_list = []
for cmd in doccmd: for cmd in doccmd:
coverage_item = { coverage_item = {
'doccmd': None, 'doccmd': None,
'xmlcmd': None, 'xmlcmd': None,
'vyoscmd': None,
'doccmd_item': None, 'doccmd_item': None,
'xmlcmd_item': None, 'xmlcmd_item': None,
'vyoscmd_item': None,
'indocs': False, 'indocs': False,
'inxml': False, 'inxml': False,
'invyos': False,
'xmlfilename': None 'xmlfilename': None
} }
coverage_item['doccmd'] = cmd['cmd'] coverage_item['doccmd'] = cmd['cmd']
@ -576,10 +584,13 @@ def process_coverage(app, fromdocname, doccmd, xmlcmd, cli_type):
coverage_item = { coverage_item = {
'doccmd': None, 'doccmd': None,
'xmlcmd': None, 'xmlcmd': None,
'vyoscmd': None,
'doccmd_item': None, 'doccmd_item': None,
'xmlcmd_item': None, 'xmlcmd_item': None,
'vyoscmd_item': None,
'indocs': False, 'indocs': False,
'inxml': False, 'inxml': False,
'invyos': False,
'xmlfilename': None 'xmlfilename': None
} }
coverage_item['xmlcmd'] = cmd['cmd'] coverage_item['xmlcmd'] = cmd['cmd']
@ -592,7 +603,33 @@ def process_coverage(app, fromdocname, doccmd, xmlcmd, cli_type):
coverage_list[strip]['xmlcmd_item'] = cmd coverage_list[strip]['xmlcmd_item'] = cmd
coverage_list[strip]['inxml'] = True coverage_list[strip]['inxml'] = True
coverage_list[strip]['xmlfilename'] = cmd['filename'] coverage_list[strip]['xmlfilename'] = cmd['filename']
strip_true_list.append(strip)
for item in vyoscmd[cli_type]:
cmd = ' '.join(item['cmd'])
strip = strip_cmd(cmd)
if strip not in coverage_list.keys():
coverage_item = {
'doccmd': None,
'xmlcmd': None,
'vyoscmd': None,
'doccmd_item': None,
'xmlcmd_item': None,
'vyoscmd_item': None,
'indocs': False,
'inxml': False,
'invyos': False,
'xmlfilename': None
}
coverage_item['vyoscmd'] = cmd
coverage_item['invyos'] = True
coverage_list[strip] = dict(coverage_item)
else:
coverage_list[strip]['vyoscmd'] = cmd
coverage_list[strip]['invyos'] = True
if coverage_list[strip]['indocs'] and coverage_list[strip]['inxml']:
strip_true_list.append(strip)
strip_true_list = list(set(strip_true_list)) strip_true_list = list(set(strip_true_list))
@ -605,11 +642,11 @@ def process_coverage(app, fromdocname, doccmd, xmlcmd, cli_type):
table = nodes.table() table = nodes.table()
tgroup = nodes.tgroup(cols=3) tgroup = nodes.tgroup(cols=4)
table += tgroup table += tgroup
header = (f'Status {len(strip_true_list)}/{len(coverage_list)}', 'Documentaion', 'XML') header = (f'Status {len(strip_true_list)}/{len(coverage_list)}', 'Documentation', 'XML', f'in VyOS {vyoscmd["os"]}')
colwidths = (5, 50 , 50) colwidths = (5, 33 , 33, 33)
table = nodes.table() table = nodes.table()
tgroup = nodes.tgroup(cols=len(header)) tgroup = nodes.tgroup(cols=len(header))
table += tgroup table += tgroup
@ -623,6 +660,7 @@ def process_coverage(app, fromdocname, doccmd, xmlcmd, cli_type):
for entry in sorted(coverage_list): for entry in sorted(coverage_list):
doc_cmd_text = [] doc_cmd_text = []
doc_xml_text = [] doc_xml_text = []
doc_vyos_text = []
if coverage_list[entry]['indocs']: if coverage_list[entry]['indocs']:
doc_cmd_text.append(coverage_list[entry]['doccmd_item']) doc_cmd_text.append(coverage_list[entry]['doccmd_item'])
else: else:
@ -633,8 +671,14 @@ def process_coverage(app, fromdocname, doccmd, xmlcmd, cli_type):
doc_xml_text.append(coverage_list[entry]['xmlcmd']) doc_xml_text.append(coverage_list[entry]['xmlcmd'])
else: else:
doc_xml_text.append('Nothing found in XML Definitions') doc_xml_text.append('Nothing found in XML Definitions')
if coverage_list[entry]['invyos']:
doc_vyos_text.append(coverage_list[entry]['vyoscmd'])
else:
doc_vyos_text.append('Nothing found in VyOS')
if not coverage_list[entry]['indocs'] or not coverage_list[entry]['inxml']:
if not coverage_list[entry]['indocs'] or not coverage_list[entry]['inxml'] or not coverage_list[entry]['invyos']:
status = False status = False
else: else:
status = True status = True
@ -643,7 +687,8 @@ def process_coverage(app, fromdocname, doccmd, xmlcmd, cli_type):
( (
status, status,
doc_cmd_text, doc_cmd_text,
doc_xml_text doc_xml_text,
doc_vyos_text
) )
) )
@ -678,6 +723,7 @@ def process_cmd_nodes(app, doctree, fromdocname):
fromdocname, fromdocname,
env.vyos_cfgcmd, env.vyos_cfgcmd,
app.config.vyos_working_commands['cfgcmd'], app.config.vyos_working_commands['cfgcmd'],
app.config.vyos_commands,
'cfgcmd' 'cfgcmd'
) )
) )
@ -695,6 +741,7 @@ def process_cmd_nodes(app, doctree, fromdocname):
fromdocname, fromdocname,
env.vyos_opcmd, env.vyos_opcmd,
app.config.vyos_working_commands['opcmd'], app.config.vyos_working_commands['opcmd'],
app.config.vyos_commands,
'opcmd' 'opcmd'
) )
) )

File diff suppressed because it is too large Load Diff

View File

@ -6,21 +6,23 @@ Overview over all commands, which are documented in the
``.. cfgcmd::`` or ``.. opcmd::`` Directives. ``.. cfgcmd::`` or ``.. opcmd::`` Directives.
The build process take all xml definition files The build process take all xml definition files
from `vyos-1x <https://github.com/vyos/vyos-1x>`_ and extract each leaf from `vyos-1x <https://github.com/vyos/vyos-1x>`_ and a periodical export of
command or executable command. After this the commands are compare and shown in all VyOS commands and extract each leaf command or executable command.
After this the commands are compare and shown in
the following two tables. The script compare only the fixed part of a command. the following two tables. The script compare only the fixed part of a command.
All varables or values will be erase and then compare: All varables or values will be erase and then compare:
for example there are these two commands: for example there are these two commands:
* documentation: ``interfaces ethernet <interface> address * documentation: ``interfaces ethernet <interface> address
<address | dhcp | dhcpv6>``` <address | dhcp | dhcpv6>``
* xml: ``interface ethernet <ethernet> address <address>`` * xml: ``interfaces ethernet <ethernet> address <address>``
* VyOS: ``interfaces ethernet <text> address <value>``
Now the script earse all in between ``<`` and ``>`` and simply compare Now the script earse all in between ``<`` and ``>`` and simply compare
the strings. the strings.
**There are 2 kind of problems:** **There are 3 kind of problems:**
``Not documented yet`` ``Not documented yet``
@ -30,9 +32,14 @@ the strings.
``Nothing found in XML Definitions`` ``Nothing found in XML Definitions``
* ``.. cfgcmd::`` or ``.. opcmd::`` Command are not found in a XML command * ``.. cfgcmd::`` or ``.. opcmd::`` Command are not found in a XML command
* Maybe the command where changed in the XML Definition, or the feature is * Maybe the command where changed in the XML Definition, the feature is
not anymore in VyOS not anymore in VyOS, or there is a typo
* Some commands are not yet translated to XML
``Nothing found in VyOS``
* ``.. cfgcmd::`` or ``.. opcmd::`` Command are not found in a VyOS command
* Maybe the command where changed, the feature is
not anymore in VyOS, or there is a typo
Configuration Commands Configuration Commands