From 0367e5f87ed508260b70ea80cefa2f939cec022c Mon Sep 17 00:00:00 2001 From: jamesbeedy Date: Wed, 24 Apr 2024 04:11:53 +0000 Subject: [PATCH 1/2] James Longdev Changes include: * remove jinja2 and replace with `Path().write_text()` * remove `slurm-ops-manager` 3rd party dep and replace with local `slurmrestd_ops.py` * consolidate the yaml files into a single `charmcraft.yaml` * rename interface slurmrestd -> slurmctld * cleanup from PR review * remove unused code * addeded logging * simplified api * reduced code footprint * consolidated yaml files into charmcraft.yaml * added type checking --- .github/workflows/ci.yaml | 20 +- README.md | 6 +- charmcraft.yaml | 45 +- config.yaml | 15 - lib/charms/fluentbit/v0/fluentbit.py | 203 --- lib/charms/operator_libs_linux/v0/apt.py | 1361 ++++++++++++++++++ lib/charms/operator_libs_linux/v1/systemd.py | 288 ++++ metadata.yaml | 24 - pyproject.toml | 10 +- requirements.txt | 2 +- src/charm.py | 176 +-- src/constants.py | 69 + src/interface_slurmctld.py | 96 ++ src/interface_slurmrestd.py | 202 --- src/slurmrestd_ops.py | 249 ++++ tests/integration/helpers.py | 34 - tests/integration/test_charm.py | 12 +- tests/unit/test_charm.py | 139 +- tox.ini | 26 +- 19 files changed, 2188 insertions(+), 789 deletions(-) delete mode 100644 config.yaml delete mode 100644 lib/charms/fluentbit/v0/fluentbit.py create mode 100644 lib/charms/operator_libs_linux/v0/apt.py create mode 100644 lib/charms/operator_libs_linux/v1/systemd.py delete mode 100644 metadata.yaml create mode 100644 src/constants.py create mode 100644 src/interface_slurmctld.py delete mode 100644 src/interface_slurmrestd.py create mode 100644 src/slurmrestd_ops.py delete mode 100644 tests/integration/helpers.py diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b1c606d..9e2c006 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -23,7 +23,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: woke uses: get-woke/woke-action@v0 with: @@ -35,18 +35,29 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install dependencies run: python3 -m pip install tox - name: Run linters run: tox -e lint + type: + name: Type checking + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Install dependencies + run: python3 -m pip install tox + - name: Run tests + run: tox -e type + unit-test: name: Unit tests runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install dependencies run: python3 -m pip install tox - name: Run tests @@ -63,10 +74,11 @@ jobs: needs: - inclusive-naming-check - lint + - type - unit-test steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup operator environment uses: charmed-kubernetes/actions-operator@main with: diff --git a/README.md b/README.md index 2561d9b..e1fc47a 100644 --- a/README.md +++ b/README.md @@ -30,11 +30,11 @@ $ juju deploy slurmd --channel edge $ juju deploy slurmdbd --channel edge $ juju deploy mysql --channel 8.0/edge $ juju deploy mysql-router slurmdbd-mysql-router --channel dpe/edge -$ juju integrate slurmctld:slurmrestd slurmrestd:slurmrestd -$ juju integrate slurmctld:slurmd slurmd:slurmd +$ juju integrate slurmctld:slurmd slurmd:slurmctld +$ juju integrate slurmctld:slurmdbd slurmdbd:slurmctld +$ juju integrate slurmctld:slurmrestd slurmrestd:slurmctld $ juju integrate slurmdbd-mysql-router:backend-database mysql:database $ juju integrate slurmdbd:database slurmdbd-mysql-router:database -$ juju integrate slurmctld:slurmdbd slurmdbd:slurmdbd ``` ## Project & Community diff --git a/charmcraft.yaml b/charmcraft.yaml index 6a6f7d1..ab31126 100644 --- a/charmcraft.yaml +++ b/charmcraft.yaml @@ -1,6 +1,30 @@ -# Copyright 2020 Omnivector Solutions, LLC. +# Copyright 2020-2024 Omnivector, LLC. # See LICENSE file for licensing details. +name: slurmrestd +summary: | + Interface to Slurm via REST API. +description: | + This charm provides slurmrestd, munged, and the bindings to other utilities + that make lifecycle operations a breeze. + + slurmrestd is a REST API interface for SLURM. + +links: + contact: https://matrix.to/#/#hpc:ubuntu.com + source: + - https://github.com/omnivector-solutions/slurmrestd-operator + issues: + - https://github.com/omnivector-solutions/slurmrestd-operator/issues + +provides: + slurmctld: + interface: slurmrestd + limit: 1 + +assumes: + - juju + type: charm bases: - build-on: @@ -10,22 +34,3 @@ bases: - name: ubuntu channel: "22.04" architectures: [amd64] - -parts: - charm: - build-packages: [git] - charm-python-packages: [setuptools] - - # Create a version file and pack it into the charm. This is dynamically generated - # as part of the build process for a charm to ensure that the git revision of the - # charm is always recorded in this version file. - version-file: - plugin: nil - build-packages: - - git - override-build: | - VERSION=$(git -C $CRAFT_PART_SRC/../../charm/src describe --dirty --always) - echo "Setting version to $VERSION" - echo $VERSION > $CRAFT_PART_INSTALL/version - stage: - - version diff --git a/config.yaml b/config.yaml deleted file mode 100644 index 633a2d3..0000000 --- a/config.yaml +++ /dev/null @@ -1,15 +0,0 @@ -options: - custom-slurm-repo: - type: string - default: "" - description: > - Use a custom repository for Slurm installation. - - This can be set to the Organization's local mirror/cache of packages and - supersedes the Omnivector repositories. Alternatively, it can be used to - track a `testing` Slurm version, e.g. by setting to - `ppa:omnivector/osd-testing`. - - Note: The configuration `custom-slurm-repo` must be set *before* - deploying the units. Changing this value after deploying the units will - not reinstall Slurm. diff --git a/lib/charms/fluentbit/v0/fluentbit.py b/lib/charms/fluentbit/v0/fluentbit.py deleted file mode 100644 index aa68450..0000000 --- a/lib/charms/fluentbit/v0/fluentbit.py +++ /dev/null @@ -1,203 +0,0 @@ -r"""Fluentbit charm libraries. - -This library contains two main classes: `FluentbitProvider` and -`FluentbitClient`. `FluentbitProvider` class is instantiated in the Fluentbit -Server charm, and receives configuration data through a relation to other -charms. `FluentbitClient` class should be instantiated in any charm that wants -to ship logs via Fluentbit. - -## Forwarding logs using Fluentbit - -To forward logs from your charm to a centralized place using Fluentbit, -instantiate the `FluentbitClient()` class and handle the `relation_created` -event in your main charm code. In this event, your charm must pass all the -configuration parameters necessary to configure Fluentbit: the inputs, the -parsers, and the filters. - -For example: - -```python -class MyCharm(CharmBase): - def __init__(self, *args): - super().__init__(*args) - - self._fluentbit = FluentbitClient(self, "fluentbit") - - self.framework.observe(self.on.fluentbit.relation_created, - self._fluentbit_relation_created) - - def _fluentbit_relation_created(self, event): - cfg = [{"input": [("name", "tail"), - ("path", "/var/log/foo/bar.log"), - ("path_key", "filename"), - ("tag", "foo"), - ("parser", "bar")]}, - {"parser": [("name", "bar"), - ("format", "regex"), - ("regex", "^\[(?