Skip to content

Commit

Permalink
DPE-2183 operator disable (#409)
Browse files Browse the repository at this point in the history
* pause operator support

* message tweak

* s/pause/disable
  • Loading branch information
paulomach authored Mar 22, 2024
1 parent e93dcca commit 0d434ea
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/charms/mysql/v0/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,13 @@ def wait_until_mysql_connection(self) -> None:
import io
import json
import logging
import os
import re
import socket
import sys
import time
from abc import ABC, abstractmethod
from pathlib import Path
from typing import Any, Dict, Iterable, List, Optional, Tuple, Union, get_args

import ops
Expand Down Expand Up @@ -111,7 +114,7 @@ def wait_until_mysql_connection(self) -> None:

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 55
LIBPATCH = 56

UNIT_TEARDOWN_LOCKNAME = "unit-teardown"
UNIT_ADD_LOCKNAME = "unit-add"
Expand Down Expand Up @@ -376,6 +379,18 @@ class MySQLCharmBase(CharmBase, ABC):
def __init__(self, *args):
super().__init__(*args)

# disable support
disable_file = Path(
f"{os.environ.get('CHARM_DIR')}/disable"
) # pyright: ignore [reportArgumentType]
if disable_file.exists():
logger.warning(
f"\n\tDisable file `{disable_file.resolve()}` found, the charm will skip all events."
"\n\tTo resume normal operations, please remove the file."
)
self.unit.status = ops.BlockedStatus("Disabled")
sys.exit(0)

self.secrets = SecretCache(self)
self.peer_relation_app = DataPeer(
self,
Expand Down

0 comments on commit 0d434ea

Please sign in to comment.