Skip to content
Snippets Groups Projects
Commit a1c62db7 authored by lavado's avatar lavado
Browse files

moving squid NS/KNF to magma folder

parent fd7b74ee
No related branches found
No related tags found
2 merge requests!11Hackfest9,!10Hackfest9
Showing
with 0 additions and 287 deletions
series: bionic
applications:
squid:
charm: ../../../../
num_units: 1
series: xenial
applications:
squid:
charm: ../../../../
num_units: 1
tests:
# - bionic_model:
# - zaza.charm_tests.noop.tests.NoopTestBionic
# - xenial_model:
# - zaza.charm_tests.noop.tests.NoopTestXenial
- zaza.charm_tests.noop.tests.NoopTest
configure:
# - bionic_model:
# - zaza.charm_tests.noop.setup.basic_setup_bionic
# - xenial_model:
# - zaza.charm_tests.noop.setup.basic_setup_xenial
- zaza.charm_tests.noop.setup.basic_setup
gate_bundles:
- xenial
- bionic
smoke_bundles:
- focal
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
# Copyright © 2020 Dominik Fleischmann dominik.fleischmann@canonical.com
# Distributed under terms of the GPL license.
"""Operator Charm test fixtures."""
import os
import tempfile
import unittest
import setuppath # noqa:F401
import mock
import ops
import ops.main
from src.charm import Squid-K8SCharm
class OperatorTestCase(unittest.TestCase):
"""Fixtures for unit testing operator charms."""
@classmethod
def setUpClass(cls):
"""Setup class fixture."""
# Setup a tmpdir
cls.tmpdir = tempfile.TemporaryDirectory()
# Store patchers for test cases that want them
cls.patchers = {}
# Prevent framwork from trying to call subprocesses
run_patcher = mock.patch("ops.model.ModelBackend._run")
cls.patchers["ops.model.ModelBackend._run"] = run_patcher.start()
# Stop unit test from calling fchown
fchown_patcher = mock.patch("os.fchown")
cls.patchers["os.fchown"] = fchown_patcher.start()
chown_patcher = mock.patch("os.chown")
cls.patchers["os.chown"] = chown_patcher.start()
# Setup mock JUJU Environment variables
os.environ["JUJU_UNIT_NAME"] = "mock/0"
os.environ["JUJU_CHARM_DIR"] = "."
@classmethod
def tearDownClass(cls):
"""Tear down class fixture."""
mock.patch.stopall()
cls.tmpdir.cleanup()
def setUp(self):
"""Setup test fixture."""
# Create a charm instance
model_backend = ops.model.ModelBackend()
ops.main.setup_root_logging(model_backend)
charm_dir = ops.main._get_charm_dir()
metadata, actions_metadata = ops.main._load_metadata(charm_dir)
meta = ops.charm.CharmMeta(metadata, actions_metadata)
unit_name = os.environ["JUJU_UNIT_NAME"]
model = ops.model.Model(unit_name, meta, model_backend)
framework = ops.framework.Framework(":memory:", charm_dir, meta, model)
charm = Squid-K8SCharm(framework, None)
self.charm = charm
def tearDown(self):
"""Clean up test fixture."""
# Remove runtime class attributes to avoid error on next setUp
for relation_name in self.charm.framework.meta.relations:
relation_name = relation_name.replace("-", "_")
delattr(ops.charm.CharmEvents, relation_name + "_relation_joined")
delattr(ops.charm.CharmEvents, relation_name + "_relation_changed")
delattr(ops.charm.CharmEvents, relation_name + "_relation_departed")
delattr(ops.charm.CharmEvents, relation_name + "_relation_broken")
for storage_name in self.charm.framework.meta.storages:
storage_name = storage_name.replace("-", "_")
delattr(ops.charm.CharmEvents, storage_name + "_storage_attached")
delattr(ops.charm.CharmEvents, storage_name + "_storage_detaching")
for action_name in self.charm.framework.meta.actions:
action_name = action_name.replace("-", "_")
delattr(ops.charm.CharmEvents, action_name + "_action")
def emit(self, event):
"""Emit the named hook on the charm."""
self.charm.framework.reemit()
if "_relation_" in event:
relation_name = event.split("_relation")[0].replace("_", "-")
with mock.patch.dict(
"os.environ",
{
"JUJU_RELATION": relation_name,
"JUJU_RELATION_ID": "1",
"JUJU_REMOTE_APP": "mock",
"JUJU_REMOTE_UNIT": "mock/0",
},
):
ops.main._emit_charm_event(self.charm, event)
else:
ops.main._emit_charm_event(self.charm, event)
def get_notice_count(self, hook):
"""Return the notice count for a given charm hook."""
notice_count = 0
handle = "Squid-K8SCharm/on/{}".format(hook)
for event_path, _, _ in self.charm.framework._storage.notices(None):
if event_path.startswith(handle):
notice_count += 1
return notice_count
mock
pyyaml
coverage
import sys
sys.path.append('lib')
import unittest
import setuppath # noqa:F401
from operator_fixtures import OperatorTestCase
class TestCharm(OperatorTestCase):
def test_create_charm(self):
"""Verify fixtures and create a charm."""
self.assertEqual(self.charm.state.installed, False)
def test_install(self):
"""Test emitting an install hook."""
self.emit("install")
self.assertEqual(self.charm.state.installed, True)
if __name__ == "__main__":
unittest.main()
[tox]
skipsdist = True
envlist = unit, functional
skip_missing_interpreters = True
[testenv]
basepython = python3
setenv =
PYTHONPATH = {toxinidir}/lib/:{toxinidir}
passenv = HOME
[testenv:unit]
commands =
coverage run -m unittest discover -s {toxinidir}/tests/unit -v
coverage report \
--omit tests/*,mod/*,.tox/*
coverage html \
--omit tests/*,mod/*,.tox/*
deps = -r{toxinidir}/tests/unit/requirements.txt
[testenv:functional]
changedir = {toxinidir}/tests/functional
commands = functest-run-suite {posargs}
deps = -r{toxinidir}/tests/functional/requirements.txt
[testenv:lint]
commands = flake8
deps =
flake8
flake8-docstrings
flake8-import-order
pep8-naming
flake8-colors
[flake8]
exclude =
.git,
__pycache__,
.tox,
mod,
max-line-length = 120
max-complexity = 10
import-order-style = google
[isort]
force_to_top=setuppath
description: Squid Bundle
bundle: kubernetes
applications:
squid:
charm: '../charms/squid'
scale: 1
# storage:
# docker: 50M
# spool: 50M
vnfd-catalog:
vnfd:
- id: squid-vnf
name: squid-vnf
connection-point:
- name: mgmtnet
mgmt-interface:
cp: mgmt
kdu:
- name: squid-kdu
juju-bundle: bundle.yaml
kdu-configuration:
config-primitive:
- name: restart
parameter:
- name: application-name
data-type: STRING
default-value: squid
- name: start
parameter:
- name: application-name
data-type: STRING
default-value: squid
- name: stop
parameter:
- name: application-name
data-type: STRING
default-value: squid
- name: addurl
parameter:
- name: application-name
data-type: STRING
default-value: squid
- name: url
data-type: STRING
default-value: ""
k8s-cluster:
nets:
- id: mgmtnet
external-connection-point-ref: mgmt
nsd:nsd-catalog:
nsd:
- id: squid-cnf-ns
name: squid-cnf-ns
short-name: squid-cnf-ns
description: NS with 1 KDU connected to the mgmtnet VL
version: '1.0'
logo: osm.png
constituent-vnfd:
- vnfd-id-ref: squid-vnf
member-vnf-index: squid-vnf
vld:
- id: mgmtnet
name: mgmtnet
short-name: mgmtnet
type: ELAN
mgmt-network: 'true'
vim-network-name: mgmt
vnfd-connection-point-ref:
- member-vnf-index-ref: squid-vnf
vnfd-id-ref: squid-vnf
vnfd-connection-point-ref: mgmtnet
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment