diff --git a/.dockerignore b/.dockerignore index 197c8fd96..8fd84aa56 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,5 @@ documentation dump -examples ansible-inventory.ini cluster.yaml build.sh diff --git a/Dockerfile b/Dockerfile index 74326ed96..3de6343ac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,13 +15,14 @@ WORKDIR /opt/kubemarine/ RUN apt update && apt install -y wget && \ pip3 install --no-cache-dir -r /opt/kubemarine/requirements.txt && \ + [ "$BUILD_TYPE" = "test" ] && pip3 install --no-cache-dir pytest pylint coverage || rm -r examples && \ if [ "$BUILD_TYPE" = "binary" ]; then \ apt install -y zlib1g-dev upx-ucl binutils; \ pip3 install --no-cache-dir pyinstaller; \ pyinstaller kubemarine.spec --noconfirm; \ else \ - wget -O - https://get.helm.sh/helm-v3.10.0-linux-amd64.tar.gz | tar xvz -C /usr/local/bin linux-amd64/helm --strip-components 1 && \ - [ "$BUILD_TYPE" = "test" ] && pip3 install --no-cache-dir pytest pylint coverage || true; fi && \ + wget -O - https://get.helm.sh/helm-v3.10.0-linux-amd64.tar.gz | tar xvz -C /usr/local/bin linux-amd64/helm --strip-components 1; \ + fi && \ apt autoremove -y wget zlib1g-dev upx-ucl && \ apt clean autoclean && \ rm -f /etc/apt/sources.list && \ diff --git a/test/unit/core/test_schema.py b/test/unit/core/test_schema.py index 2c3643a9e..35f3789dd 100644 --- a/test/unit/core/test_schema.py +++ b/test/unit/core/test_schema.py @@ -19,7 +19,7 @@ import yaml from kubemarine import demo, coredns, __main__ -from kubemarine.core import errors, utils +from kubemarine.core import errors, utils, schema from kubemarine.procedures import install from test.unit import utils as test_utils @@ -73,20 +73,30 @@ def test_plugins_installation_enriches_valid(self, install_plugin): class TestValidExamples(unittest.TestCase): def test_cluster_examples_valid(self): - inventories_dir = utils.get_resource_absolute_path("../examples/cluster.yaml", script_relative=True) - for inventory_filepath in Path(inventories_dir).glob('*'): + inventories_dir = Path(utils.get_resource_absolute_path("../examples/cluster.yaml", script_relative=True)) + self.assertTrue(inventories_dir.is_dir(), "Examples not found") + for inventory_filepath in inventories_dir.glob('**/*'): + if inventory_filepath.is_dir() or 'cluster' not in inventory_filepath.name: + continue with open(inventory_filepath, 'r') as stream: inventory = yaml.safe_load(stream) # check that enrichment is successful and the inventory is valid against the schema + context = demo.create_silent_context() + context['nodes'] = demo.generate_nodes_context(inventory) try: - demo.new_cluster(inventory) + cluster = demo.FakeKubernetesCluster(inventory, context=context) + schema.verify_inventory(cluster.raw_inventory, cluster) except Exception as e: self.fail(f"Enrichment of {inventory_filepath.relative_to(inventories_dir)} failed: {e}") def test_procedure_examples_valid(self): - inventories_dir = utils.get_resource_absolute_path("../examples/procedure.yaml", script_relative=True) - for inventory_filepath in Path(inventories_dir).glob('*'): + inventories_dir = Path(utils.get_resource_absolute_path("../examples/procedure.yaml", script_relative=True)) + if not inventories_dir.is_dir(): + self.skipTest("Examples not found") + for inventory_filepath in inventories_dir.glob('**/*'): + if inventory_filepath.is_dir(): + continue with open(inventory_filepath, 'r') as stream: procedure_inventory = yaml.safe_load(stream)