Update after ops_sunbeam configure_charm changes

* Use default configure_charm and specialise init_container_services
  to remove duplicate code
* Stop using deprecated use_juju_for_storage=True
* Update identity_service library to v1.0
* Update CinderCephOperatorCharm  super class after update in
  ops_sunbeam.

Change-Id: I815cb1dd22488a7c233864d64bd61e0d742cb368
This commit is contained in:
Hemanth Nakkina
2023-03-07 07:17:41 +05:30
committed by Liam Young
parent 35953b18de
commit a20ac6df96
6 changed files with 58 additions and 36 deletions

View File

@@ -5,3 +5,7 @@
- microk8s-func-test
vars:
charm_build_name: cinder-ceph-k8s
juju_channel: 3.1/stable
juju_classic_mode: false
microk8s_channel: 1.26-strict/stable
microk8s_classic_mode: false

View File

@@ -20,5 +20,6 @@ parts:
- git
- libffi-dev
- libssl-dev
- pkg-config
- rustc
- cargo

View File

@@ -2,7 +2,7 @@
echo "INFO: Fetching libs from charmhub."
charmcraft fetch-lib charms.data_platform_libs.v0.database_requires
charmcraft fetch-lib charms.keystone_k8s.v0.identity_service
charmcraft fetch-lib charms.keystone_k8s.v1.identity_service
charmcraft fetch-lib charms.rabbitmq_k8s.v0.rabbitmq
charmcraft fetch-lib charms.observability_libs.v0.kubernetes_service_patch
charmcraft fetch-lib charms.cinder_k8s.v0.storage_backend

View File

@@ -26,7 +26,7 @@ Two events are also available to respond to:
A basic example showing the usage of this relation follows:
```
from charms.sunbeam_keystone_operator.v0.identity_service import IdentityServiceRequires
from charms.keystone_k8s.v1.identity_service import IdentityServiceRequires
class IdentityServiceClientCharm(CharmBase):
def __init__(self, *args):
@@ -85,7 +85,10 @@ from ops.framework import (
EventSource,
Object,
)
from ops.model import Relation
from ops.model import (
Relation,
SecretNotFoundError,
)
logger = logging.getLogger(__name__)
@@ -93,11 +96,11 @@ logger = logging.getLogger(__name__)
LIBID = "0fa7fe7236c14c6e9624acf232b9a3b0"
# Increment this major API version when introducing breaking changes
LIBAPI = 0
LIBAPI = 1
# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 1
LIBPATCH = 0
logger = logging.getLogger(__name__)
@@ -175,7 +178,7 @@ class IdentityServiceRequires(Object):
try:
self.service_password
self.on.ready.emit()
except AttributeError:
except (AttributeError, KeyError):
pass
def _on_identity_service_relation_broken(self, event):
@@ -273,10 +276,24 @@ class IdentityServiceRequires(Object):
"""Return the service_host."""
return self.get_remote_app_data('service-host')
@property
def service_credentials(self) -> str:
"""Return the service_credentials secret."""
return self.get_remote_app_data('service-credentials')
@property
def service_password(self) -> str:
"""Return the service_password."""
return self.get_remote_app_data('service-password')
credentials_id = self.get_remote_app_data('service-credentials')
if not credentials_id:
return None
try:
credentials = self.charm.model.get_secret(id=credentials_id)
return credentials.get_content().get("password")
except SecretNotFoundError:
logger.warning(f"Secret {credentials_id} not found")
return None
@property
def service_port(self) -> str:
@@ -301,7 +318,16 @@ class IdentityServiceRequires(Object):
@property
def service_user_name(self) -> str:
"""Return the service_user_name."""
return self.get_remote_app_data('service-user-name')
credentials_id = self.get_remote_app_data('service-credentials')
if not credentials_id:
return None
try:
credentials = self.charm.model.get_secret(id=credentials_id)
return credentials.get_content().get("username")
except SecretNotFoundError:
logger.warning(f"Secret {credentials_id} not found")
return None
@property
def service_user_id(self) -> str:
@@ -450,12 +476,12 @@ class IdentityServiceProvides(Object):
admin_project: str,
admin_user: str,
service_domain: str,
service_password: str,
service_project: str,
service_user: str,
internal_auth_url: str,
admin_auth_url: str,
public_auth_url: str):
public_auth_url: str,
service_credentials: str):
logging.debug("Setting identity_service connection information.")
_identity_service_rel = None
for relation in self.framework.model.relations[relation_name]:
@@ -485,9 +511,8 @@ class IdentityServiceProvides(Object):
app_data["service-domain-id"] = service_domain.id
app_data["service-project-name"] = service_project.name
app_data["service-project-id"] = service_project.id
app_data["service-user-name"] = service_user.name
app_data["service-user-id"] = service_user.id
app_data["service-password"] = service_password
app_data["internal-auth-url"] = internal_auth_url
app_data["admin-auth-url"] = admin_auth_url
app_data["public-auth-url"] = public_auth_url
app_data["service-credentials"] = service_credentials

View File

@@ -32,14 +32,12 @@ import ops_sunbeam.charm as charm
import ops_sunbeam.config_contexts as config_contexts
import ops_sunbeam.container_handlers as container_handlers
import ops_sunbeam.core as core
import ops_sunbeam.guard as sunbeam_guard
import ops_sunbeam.relation_handlers as relation_handlers
import ops_sunbeam.relation_handlers as sunbeam_rhandlers
from ops.main import (
main,
)
from ops.model import (
ActiveStatus,
)
logger = logging.getLogger(__name__)
@@ -172,7 +170,7 @@ class CinderVolumePebbleHandler(container_handlers.PebbleHandler):
self.start_service()
class CinderCephOperatorCharm(charm.OSBaseOperatorCharm):
class CinderCephOperatorCharm(charm.OSBaseOperatorCharmK8S):
"""Cinder/Ceph Operator charm."""
# NOTE: service_name == container_name
@@ -232,7 +230,7 @@ class CinderCephOperatorCharm(charm.OSBaseOperatorCharm):
"""Event handler for bootstrap of service when api services are ready."""
self._state.api_ready = True
self.configure_charm(event)
if self._state.bootstrapped:
if self.bootstrapped():
for handler in self.pebble_handlers:
handler.start_service()
@@ -269,12 +267,8 @@ class CinderCephOperatorCharm(charm.OSBaseOperatorCharm):
"""Provide database name for cinder services."""
return {"database": "cinder"}
def configure_charm(self, event) -> None:
"""Catchall handler to cconfigure charm services."""
if not self.relation_handlers_ready():
logging.debug("Deferring configuration, charm relations not ready")
return
def init_container_services(self):
"""Setp ceph keyring and init pebble handlers that are ready."""
for ph in self.pebble_handlers:
if ph.pebble_ready:
ph.execute(
@@ -288,18 +282,16 @@ class CinderCephOperatorCharm(charm.OSBaseOperatorCharm):
exception_on_error=True,
)
ph.init_service(self.contexts())
for ph in self.pebble_handlers:
if not ph.service_ready:
logging.debug("Deferring, container service not ready")
return
# Add healthchecks to the plan
for ph in self.pebble_handlers:
ph.add_healthchecks()
self.unit.status = ActiveStatus()
else:
logging.debug(
f"Not running init for {ph.service_name},"
" container not ready"
)
raise sunbeam_guard.WaitingExceptionError(
"Payload container not ready"
)
super().init_container_services()
if __name__ == "__main__":
main(CinderCephOperatorCharm, use_juju_for_storage=True)
main(CinderCephOperatorCharm)

View File

@@ -8,7 +8,7 @@ coverage
mock
flake8
stestr
git+https://github.com/openstack-charmers/zaza.git#egg=zaza
git+https://github.com/openstack-charmers/zaza.git@libjuju-3.1#egg=zaza
git+https://github.com/openstack-charmers/zaza-openstack-tests.git#egg=zaza.openstack
git+https://opendev.org/openstack/tempest.git#egg=tempest
ops