Skip to content

Commit

Permalink
Fix unit tests verifying examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ilia1243 committed Jan 13, 2023
1 parent f751710 commit 6db87e3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
documentation
dump
examples
ansible-inventory.ini
cluster.yaml
build.sh
Expand Down
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand Down
22 changes: 16 additions & 6 deletions test/unit/core/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 6db87e3

Please sign in to comment.