Skip to content

Commit

Permalink
Update CI/CD
Browse files Browse the repository at this point in the history
Updates CI/CD to account for updates for new serialized data interface.
Also updates CI/CD to bring it in line with results of bikeshedding
discussions.
  • Loading branch information
knkski committed Apr 7, 2021
1 parent 9298244 commit 204ef0a
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ on:
- pull_request

jobs:
check-formatting:
name: Check Formatting
lint:
name: Lint Check
runs-on: ubuntu-latest

steps:
Expand All @@ -15,17 +15,28 @@ jobs:

- name: Install dependencies
run: |
sudo apt-get install python3-setuptools
sudo pip3 install black flake8
sudo apt-get install python3-pip tox
- name: Check black
run: black --check .
- name: Lint code
run: tox -e lint

- name: Check flake8
run: flake8 . --max-line-length 100
unit:
name: Unit Test
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v2

- name: Install dependencies
run: |
sudo apt-get install python3-pip tox
- name: Run unit tests
run: tox -e unit

test:
name: Test
deploy:
name: Deploy Test
runs-on: ubuntu-latest

steps:
Expand All @@ -42,6 +53,7 @@ jobs:
sudo pip3 install charmcraft
sudo snap install juju --classic
sudo snap install juju-wait --classic
sudo snap install yq
- name: Bootstrap Juju
run: |
Expand All @@ -52,10 +64,10 @@ jobs:
- name: Deploy MinIO
run: |
set -eux
charmcraft build
charmcraft build -v
juju deploy ./minio.charm \
--config secret-key=minio-secret-key \
--resource oci-image=minio/minio:RELEASE.2021-02-07T01-31-02Z
--resource oci-image=$(yq eval '.resources.oci-image.upstream-source' metadata.yaml)
juju wait -wvt 300
- name: Test MinIO
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ resources:
provides:
object-storage:
interface: object-storage
schema: https://gist.githubusercontent.com/knkski/386af79a681326fb1c2a8cb69e5b02d2/raw/6b6856aabce4cdc7c6a3dff990dce7e106a5fd7b/object-storage.yaml
schema: https://gist.githubusercontent.com/knkski/386af79a681326fb1c2a8cb69e5b02d2/raw/1e089582c43df711e8c08a4af2199f4a2edc43d4/object-storage.yaml
versions: [v1]
storage:
minio-data:
type: filesystem
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ops==1.1.0
git+https://github.com/juju-solutions/resource-oci-image@1964d748022b762b9dce6e8bb7bdf12835102c72
git+https://github.com/canonical/serialized-data-interface.git
serialized-data-interface==0.2.0
39 changes: 26 additions & 13 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
from ops.charm import CharmBase
from ops.framework import StoredState
from ops.main import main
from ops.model import ActiveStatus, MaintenanceStatus
from ops.model import ActiveStatus, MaintenanceStatus, WaitingStatus, BlockedStatus

from serialized_data_interface import get_interfaces
from serialized_data_interface import (
get_interfaces,
NoVersionsListed,
NoCompatibleVersions,
)
from oci_image import OCIImageResource, OCIImageResourceError

log = logging.getLogger()
Expand All @@ -30,7 +34,15 @@ def __init__(self, *args):
return

self._stored.set_default(secret_key=gen_pass())
self.interfaces = get_interfaces(self)
try:
self.interfaces = get_interfaces(self)
except NoVersionsListed as err:
self.model.unit.status = WaitingStatus(str(err))
return
except NoCompatibleVersions as err:
self.model.unit.status = BlockedStatus(str(err))
return

self.image = OCIImageResource(self, "oci-image")

self.framework.observe(self.on.install, self.set_pod_spec)
Expand All @@ -48,16 +60,17 @@ def __init__(self, *args):
def send_info(self, event):
secret_key = self.model.config["secret-key"] or self._stored.secret_key

self.interfaces["object-storage"]["v1"].update_relation_data(
{
"access-key": self.model.config["access-key"],
"namespace": self.model.name,
"port": self.model.config["port"],
"secret-key": secret_key,
"secure": True,
"service": self.model.app.name,
}
)
if self.interfaces["object-storage"]:
self.interfaces["object-storage"].send_data(
{
"access-key": self.model.config["access-key"],
"namespace": self.model.name,
"port": self.model.config["port"],
"secret-key": secret_key,
"secure": True,
"service": self.model.app.name,
}
)

def set_pod_spec(self, event):
try:
Expand Down
67 changes: 63 additions & 4 deletions tests/test_charm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
import yaml
from ops.model import ActiveStatus, BlockedStatus
from ops.model import ActiveStatus, BlockedStatus, WaitingStatus
from ops.testing import Harness

from charm import Operator
Expand Down Expand Up @@ -43,6 +43,47 @@ def test_main_no_relation(harness):
assert harness.charm.model.unit.status == ActiveStatus("")


def test_incompatible_version(harness):
harness.set_leader(True)
harness.add_oci_resource(
"oci-image",
{
"registrypath": "ci-test",
"username": "",
"password": "",
},
)
rel_id = harness.add_relation("object-storage", "argo-controller")
harness.add_relation_unit(rel_id, "argo-controller/0")
harness.update_relation_data(
rel_id,
"argo-controller",
{"_supported_versions": yaml.dump(["v2"])},
)
harness.begin_with_initial_hooks()
assert harness.charm.model.unit.status == BlockedStatus(
"No compatible object-storage versions found for apps: argo-controller"
)


def test_unversioned(harness):
harness.set_leader(True)
harness.add_oci_resource(
"oci-image",
{
"registrypath": "ci-test",
"username": "",
"password": "",
},
)
rel_id = harness.add_relation("object-storage", "argo-controller")
harness.add_relation_unit(rel_id, "argo-controller/0")
harness.begin_with_initial_hooks()
assert harness.charm.model.unit.status == WaitingStatus(
"List of object-storage versions not found for apps: argo-controller"
)


def test_main_with_relation(harness):
harness.set_leader(True)
harness.add_oci_resource(
Expand All @@ -53,10 +94,22 @@ def test_main_with_relation(harness):
"password": "",
},
)
rel_id = harness.add_relation("object-storage", "object-storage")
rel_id = harness.add_relation("object-storage", "argo-controller")
harness.add_relation_unit(rel_id, "argo-controller/0")
harness.update_relation_data(
rel_id,
"argo-controller",
{"_supported_versions": yaml.dump(["v1"])},
)
rel_id = harness.add_relation("object-storage", "foobar")
harness.add_relation_unit(rel_id, "foobar/0")
harness.update_relation_data(
rel_id,
"foobar",
{"_supported_versions": yaml.dump(["v1"])},
)
harness.begin_with_initial_hooks()
assert harness.charm.model.unit.status == ActiveStatus("")
harness.add_relation_unit(rel_id, "argo-controller/0")

data = yaml.safe_load(harness.get_relation_data(rel_id, "minio")["data"])
assert data["access-key"] == "minio"
Expand All @@ -77,7 +130,13 @@ def test_main_with_manual_secret(harness):
"password": "",
},
)
rel_id = harness.add_relation("object-storage", "object-storage")
rel_id = harness.add_relation("object-storage", "argo-controller")
harness.add_relation_unit(rel_id, "argo-controller/0")
harness.update_relation_data(
rel_id,
"argo-controller",
{"_supported_versions": yaml.dump(["v1"])},
)
harness.begin_with_initial_hooks()
assert harness.charm.model.unit.status == ActiveStatus("")

Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ deps =

[testenv:unit]
commands =
pytest -v tests
pytest -v tests

[testenv:lint]
commands =
flake8 {toxinidir}/src {toxinidir}/tests
black --check {toxinidir}/src {toxinidir}/tests
black --check {toxinidir}/src {toxinidir}/tests

0 comments on commit 204ef0a

Please sign in to comment.