[all] make region a single value

tempest-k8s: add region configuration option, take first from the given
list as endpoint
tempest-k8s: take first from list as endpoint
keystone-k8s: allow listing endpoints by region

Change-Id: I629a33c6a3a1579d94d3add5358a9547eebc2f9e
This commit is contained in:
Guillaume Boutry 2024-05-10 10:34:22 +02:00
parent 1175ae0b83
commit 156220293a
No known key found for this signature in database
GPG Key ID: E95E3326872E55DE
25 changed files with 54 additions and 34 deletions

View File

@ -23,7 +23,7 @@ options:
type: string
region:
default: RegionOne
description: Space delimited list of OpenStack regions
description: Name of the OpenStack region
type: string
alarm-history-time-to-live:
default: -1

View File

@ -5,5 +5,5 @@ options:
type: boolean
region:
default: RegionOne
description: Space delimited list of OpenStack regions
description: Name of the OpenStack region
type: string

View File

@ -23,5 +23,5 @@ options:
type: string
region:
default: RegionOne
description: Space delimited list of OpenStack regions
description: Name of the OpenStack region
type: string

View File

@ -23,5 +23,5 @@ options:
type: string
region:
default: RegionOne
description: Space delimited list of OpenStack regions
description: Name of the OpenStack region
type: string

View File

@ -23,7 +23,7 @@ options:
type: string
region:
default: RegionOne
description: Space delimited list of OpenStack regions
description: Name of the OpenStack region
type: string
nameservers:
type: string

View File

@ -23,7 +23,7 @@ options:
type: string
region:
default: RegionOne
description: Space delimited list of OpenStack regions
description: Name of the OpenStack region
type: string
ceph-osd-replication-count:
default: 3

View File

@ -23,7 +23,7 @@ options:
type: string
region:
default: RegionOne
description: Space delimited list of OpenStack regions
description: Name of the OpenStack region
type: string
ceph-osd-replication-count:
default: 3

View File

@ -23,5 +23,5 @@ options:
type: string
region:
default: RegionOne
description: Space delimited list of OpenStack regions
description: Name of the OpenStack region
type: string

View File

@ -44,7 +44,7 @@ options:
type: string
region:
default: RegionOne
description: Space delimited list of OpenStack regions
description: Name of the OpenStack region
type: string
catalog-cache-expiration:

View File

@ -359,12 +359,14 @@ class KeystoneClient:
self,
name: Optional[str] = None,
interface: Optional[str] = None,
region: Optional[str] = None,
) -> list:
"""List endpoints.
Returns all the endpoints by default.
If name is specified, returns the corresponding endpoints.
If interface is specified, returns the corresponding endpoints.
If region is specified, returns the corresponding endpoints.
Response is in the format
[
{
@ -382,10 +384,13 @@ class KeystoneClient:
:param type: str | None
:param interface: Endpoint interface
:param type: str | None
:param region: Endpoint region
:param type: str | None
:rtype: list
"""
options = {
"interface": interface,
"region": region,
}
if name is not None:
services = self.api.services.list(name=name)

View File

@ -115,9 +115,7 @@ class KeystoneManager(framework.Object):
@property
def regions(self):
"""List of regions required for this keystone."""
# split regions and strip out empty regions
regions = [r for r in self.charm.model.config["region"].split() if r]
return regions
return [self.charm.model.config["region"]]
def setup_keystone(self):
"""Runs the keystone setup process for first time configuration.
@ -496,7 +494,7 @@ class KeystoneManager(framework.Object):
"public": self.public_endpoint,
}
for region in self.charm.model.config["region"].split():
for region in self.regions:
if not region:
continue

View File

@ -33,5 +33,5 @@ options:
type: string
region:
default: RegionOne
description: Space delimited list of OpenStack regions
description: Name of the OpenStack region
type: string

View File

@ -32,7 +32,7 @@ options:
type: string
region:
default: RegionOne
description: Space delimited list of OpenStack regions
description: Name of the OpenStack region
type: string
vlan-ranges:
default: "physnet1:1:4094"

View File

@ -23,5 +23,5 @@ options:
type: string
region:
default: RegionOne
description: Space delimited list of OpenStack regions
description: Name of the OpenStack region
type: string

View File

@ -23,5 +23,5 @@ options:
type: string
region:
default: RegionOne
description: Space delimited list of OpenStack regions
description: Name of the OpenStack region
type: string

View File

@ -1,5 +1,5 @@
options:
region:
default: RegionOne
description: Space delimited list of OpenStack regions
description: Name of the OpenStack region
type: string

View File

@ -322,7 +322,11 @@ class OSExporterOperatorCharm(sunbeam_charm.OSBaseOperatorCharmK8S):
return [
{
"name": "list_endpoint",
"params": {"name": "keystone", "interface": "admin"},
"params": {
"name": "keystone",
"interface": "admin",
"region": self.config["region"],
},
}
]

View File

@ -68,7 +68,7 @@ config:
type: string
region:
default: RegionOne
description: Space delimited list of OpenStack regions
description: Name of the OpenStack region
type: string
containers:

View File

@ -67,7 +67,7 @@ class SyncCharmConfigContext(sunbeam_config_contexts.CharmConfigContext):
self.charm.config["architecture"].split()
),
"release": "|".join(self.charm.config["release"].split()),
"region": ", ".join(self.charm.config["region"].split()),
"region": self.charm.config["region"],
"frequency": _frequency_to_seconds(self.charm.config["frequency"]),
}
@ -178,7 +178,7 @@ class OpenstackImagesSyncK8SCharm(sunbeam_charm.OSBaseOperatorAPICharm):
@property
def service_endpoints(self):
"""Describe the openstack images sync service endpoint."""
slash_region = "/" + self.config["region"].split()[0]
slash_region = "/" + self.config["region"]
return [
{
"service_name": "image-stream",

View File

@ -23,5 +23,5 @@ options:
type: string
region:
default: RegionOne
description: Space delimited list of OpenStack regions
description: Name of the OpenStack region
type: string

View File

@ -73,6 +73,10 @@ peers:
config:
options:
region:
type: string
default: RegionOne
description: Name of the OpenStack region
schedule:
type: string
default: "0 */1 * * *"

View File

@ -183,6 +183,7 @@ class TempestOperatorCharm(sunbeam_charm.OSBaseOperatorCharmK8S):
"identity-ops",
self.configure_charm,
mandatory="identity-ops" in self.mandatory_relations,
region=self.config["region"],
)
handlers.append(self.user_id_ops)
self.loki = LoggingRelationHandler(
@ -224,7 +225,7 @@ class TempestOperatorCharm(sunbeam_charm.OSBaseOperatorCharmK8S):
logger.debug("Retrieving OpenStack credentials")
credential = self.user_id_ops.get_user_credential()
tempest_env = {
"OS_REGION_NAME": "RegionOne",
"OS_REGION_NAME": self.config["region"],
"OS_IDENTITY_API_VERSION": "3",
"OS_AUTH_VERSION": "3",
"OS_AUTH_URL": credential.get("auth-url"),

View File

@ -324,13 +324,6 @@ class TempestUserIdentityRelationHandler(sunbeam_rhandlers.RelationHandler):
},
]
list_endpoint_ops = [
{
"name": "list_endpoint",
"params": {"name": "keystone", "interface": "admin"},
},
]
resource_identifiers: FrozenSet[str] = frozenset(
{
"name",
@ -345,9 +338,11 @@ class TempestUserIdentityRelationHandler(sunbeam_rhandlers.RelationHandler):
relation_name: str,
callback_f: Callable,
mandatory: bool,
region: str,
):
super().__init__(charm, relation_name, callback_f, mandatory)
self.charm = charm
self.region = region
@property
def ready(self) -> bool:
@ -528,13 +523,26 @@ class TempestUserIdentityRelationHandler(sunbeam_rhandlers.RelationHandler):
]
return setup_ops
def list_endpoint_ops(self) -> list[dict]:
"""Operations to list keystone endpoint."""
return [
{
"name": "list_endpoint",
"params": {
"name": "keystone",
"interface": "admin",
"region": self.region,
},
},
]
def _setup_tempest_resource_request(self) -> dict:
"""Set up openstack resource for tempest."""
ops = []
# Teardown before setup to ensure it begins with a clean environment.
ops.extend(self.teardown_ops)
ops.extend(self._setup_tempest_resource_ops())
ops.extend(self.list_endpoint_ops)
ops.extend(self.list_endpoint_ops())
request = {
"id": self._hash_ops(ops),
"tag": "setup_tempest_resource",

View File

@ -22,5 +22,5 @@
type: string
region:
default: RegionOne
description: Space delimited list of OpenStack regions
description: Name of the OpenStack region
type: string

View File

@ -23,5 +23,5 @@ options:
type: string
region:
default: RegionOne
description: Space delimited list of OpenStack regions
description: Name of the OpenStack region
type: string