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.

96 lines
3.4 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. network_plugins.sort()
  34. operating_systems.sort()
  35. return template.render(
  36. container_engines=container_engines,
  37. network_plugins=network_plugins,
  38. operating_systems=operating_systems,
  39. exists=self.exists
  40. )
  41. def markdown(self):
  42. out = ''
  43. for container_manager in self.db.get_unique_ids('container_manager'):
  44. # Prepare the headers
  45. out += "# " + container_manager + "\n"
  46. headers = '|OS / CNI| '
  47. underline = '|----|'
  48. for network_plugin in self.db.get_unique_ids("network_plugin"):
  49. headers += network_plugin + ' | '
  50. underline += '----|'
  51. out += headers + "\n" + underline + "\n"
  52. for operating_system in self.db.get_unique_ids("operating_system"):
  53. out += '| ' + operating_system + ' | '
  54. for network_plugin in self.db.get_unique_ids("network_plugin"):
  55. if self.exists(container_manager, network_plugin, operating_system):
  56. emoji = ':white_check_mark:'
  57. else:
  58. emoji = ':x:'
  59. out += emoji + ' | '
  60. out += "\n"
  61. pprint(self.db.get_unique_ids('operating_system'))
  62. pprint(self.db.get_unique_ids('network_plugin'))
  63. return out
  64. if not p.is_dir():
  65. print("Path is not a directory")
  66. sys.exit(2)
  67. data = Data()
  68. files = p.glob('*.yml')
  69. for f in files:
  70. y = yaml.load(f.open(), Loader=yaml.FullLoader)
  71. container_manager = y.get('container_manager', 'containerd')
  72. network_plugin = y.get('kube_network_plugin', 'calico')
  73. x = re.match(r"^[a-z-]+_([a-z0-9]+).*", f.name)
  74. operating_system = x.group(1)
  75. data.set(container_manager=container_manager, network_plugin=network_plugin, operating_system=operating_system)
  76. #print(data.markdown())
  77. print(data.jinja())