Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
wallyworld committed Jan 8, 2021
0 parents commit 79d68da
Show file tree
Hide file tree
Showing 13 changed files with 821 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[flake8]
max-line-length = 99
select: E,W,F,C,N
exclude:
venv
.git
build
dist
*.egg_info
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.py[cod]
*.charm
*~
.tox
.coverage
__pycache__
build
venv
3 changes: 3 additions & 0 deletions .jujuignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/venv
*.py[cod]
*.charm
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# juju-controller

## Description

The Juju controller hosts and manages Juju models.

## Usage

The controller provides an endpoint to integrate with a dashboard.

## Developing

Create and activate a virtualenv with the development requirements:

virtualenv -p python3 venv
source venv/bin/activate
pip install -r requirements-dev.txt

## Testing

The Python operator framework includes a very nice harness for testing
operator behaviour without full deployment. Just `run_tests`:

./run_tests
20 changes: 20 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2021 Canonical Ltd.
# Licensed under the GPLv3, see LICENSE file for details.

options:
controller-url:
default: ""
description: The URL used to access the controller API.
type: string
model-url-template:
default: ""
description: The URL template used to access a model API.
type: string
identity-provider-url:
default: ""
description: The URL used to access an external identity provider.
type: string
is-juju:
default: true
description: Whether this is a standalone Juju controller
type: boolean
15 changes: 15 additions & 0 deletions metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2021 Canonical Ltd.
# Licensed under the GPLv3, see LICENSE file for details.
name: juju-controller
description: |
The Juju controller charm is used to expose various pieces
of functionality of a Juju controller.
summary: |
The Juju controller.
series:
- xenial
- bionic
- focal
provides:
dashboard:
interface: juju-dashboard
3 changes: 3 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-r requirements.txt
coverage
flake8
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ops
17 changes: 17 additions & 0 deletions run_tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh -e
# Copyright 2021 Canonical Ltd.
# Licensed under the GPLv3, see LICENSE file for details.

if [ -z "$VIRTUAL_ENV" -a -d venv/ ]; then
. venv/bin/activate
fi

if [ -z "$PYTHONPATH" ]; then
export PYTHONPATH=src
else
export PYTHONPATH="src:$PYTHONPATH"
fi

flake8
coverage run --source=src -m unittest -v "$@"
coverage report -m
30 changes: 30 additions & 0 deletions src/charm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python3
# Copyright 2021 Canonical Ltd.
# Licensed under the GPLv3, see LICENSE file for details.

import logging

from ops.charm import CharmBase
from ops.main import main
from ops.framework import StoredState

logger = logging.getLogger(__name__)


class JujuControllerCharm(CharmBase):
_stored = StoredState()

def __init__(self, *args):
super().__init__(*args)
self.framework.observe(self.on.config_changed, self._on_config_changed)
self._stored.set_default(things=[])

def _on_config_changed(self, _):
current = self.config["controller-url"]
if current not in self._stored.things:
logger.critical("got a new controller-url: %r", current)
self._stored.things.append(current)


if __name__ == "__main__":
main(JujuControllerCharm)
Empty file added tests/__init__.py
Empty file.
17 changes: 17 additions & 0 deletions tests/test_charm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2021 Canonical Ltd.
# Licensed under the GPLv3, see LICENSE file for details.

import unittest

from ops.testing import Harness
from charm import JujuControllerCharm


class TestCharm(unittest.TestCase):
def test_config_changed(self):
harness = Harness(JujuControllerCharm)
self.addCleanup(harness.cleanup)
harness.begin()
self.assertEqual(list(harness.charm._stored.things), [])
harness.update_config({"controller-url": "https://controller"})
self.assertEqual(list(harness.charm._stored.things), ["https://controller"])

0 comments on commit 79d68da

Please sign in to comment.