You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
3.5 KiB

  1. #!/usr/bin/env python
  2. import argparse
  3. import sys
  4. import glob
  5. from pathlib import Path
  6. import yaml
  7. from pydblite import Base
  8. import re
  9. import jinja2
  10. import sys
  11. from pprint import pprint
  12. parser = argparse.ArgumentParser(description='Generate a Markdown table representing the CI test coverage')
  13. parser.add_argument('--dir', default='tests/files/', help='folder with test yml files')
  14. args = parser.parse_args()
  15. p = Path(args.dir)
  16. env = jinja2.Environment(loader=jinja2.FileSystemLoader(searchpath=sys.path[0]))
  17. # Data represents CI coverage data matrix
  18. class Data:
  19. def __init__(self):
  20. self.db = Base(':memory:')
  21. self.db.create('container_manager', 'network_plugin', 'operating_system')
  22. def set(self, container_manager, network_plugin, operating_system):
  23. self.db.insert(container_manager=container_manager, network_plugin=network_plugin, operating_system=operating_system)
  24. self.db.commit()
  25. def exists(self, container_manager, network_plugin, operating_system):
  26. return len((self.db("container_manager") == container_manager) & (self.db("network_plugin") == network_plugin) & (self.db("operating_system") == operating_system)) > 0
  27. def jinja(self):
  28. template = env.get_template('table.md.j2')
  29. container_engines = list(self.db.get_unique_ids('container_manager'))
  30. network_plugins = list(self.db.get_unique_ids("network_plugin"))
  31. operating_systems = list(self.db.get_unique_ids("operating_system"))
  32. container_engines.sort()
  33. container_engines.reverse() # reverse sort container_engines to get Docker first in the list
  34. network_plugins.sort()
  35. operating_systems.sort()
  36. return template.render(
  37. container_engines=container_engines,
  38. network_plugins=network_plugins,
  39. operating_systems=operating_systems,
  40. exists=self.exists
  41. )
  42. def markdown(self):
  43. out = ''
  44. for container_manager in self.db.get_unique_ids('container_manager'):
  45. # Prepare the headers
  46. out += "# " + container_manager + "\n"
  47. headers = '|OS / CNI| '
  48. underline = '|----|'
  49. for network_plugin in self.db.get_unique_ids("network_plugin"):
  50. headers += network_plugin + ' | '
  51. underline += '----|'
  52. out += headers + "\n" + underline + "\n"
  53. for operating_system in self.db.get_unique_ids("operating_system"):
  54. out += '| ' + operating_system + ' | '
  55. for network_plugin in self.db.get_unique_ids("network_plugin"):
  56. if self.exists(container_manager, network_plugin, operating_system):
  57. emoji = ':white_check_mark:'
  58. else:
  59. emoji = ':x:'
  60. out += emoji + ' | '
  61. out += "\n"
  62. pprint(self.db.get_unique_ids('operating_system'))
  63. pprint(self.db.get_unique_ids('network_plugin'))
  64. return out
  65. if not p.is_dir():
  66. print("Path is not a directory")
  67. sys.exit(2)
  68. data = Data()
  69. files = p.glob('*.yml')
  70. for f in files:
  71. y = yaml.load(f.open(), Loader=yaml.FullLoader)
  72. container_manager = y.get('container_manager', 'docker')
  73. network_plugin = y.get('kube_network_plugin', 'calico')
  74. x = re.match(r"^[a-z-]+_([a-z0-9]+).*", f.name)
  75. operating_system = x.group(1)
  76. data.set(container_manager=container_manager, network_plugin=network_plugin, operating_system=operating_system)
  77. #print(data.markdown())
  78. print(data.jinja())