[openstack-hypervisor] Add support for sev

* Add new config parameter reserved-host-memory-mb-for-sev
that updates snap config sev.reserved-host-memory-mb
* Add an action list-flavors to list the host flavors/
capabilities

Change-Id: I2500d1dafc0bb77dafa8a681daf833f7d1f76211
This commit is contained in:
Hemanth Nakkina 2025-02-11 10:46:25 +05:30
parent be409b3ef7
commit d65c121ee5
No known key found for this signature in database
GPG Key ID: 2E4970F7B143168E
3 changed files with 44 additions and 0 deletions

View File

@ -42,6 +42,13 @@ config:
use-data-binding:
default: false
type: boolean
reserved-host-memory-mb-for-sev:
type: string
description: |
Memory to be reserved for host for SEV enabled compute
hosts. This memory will be used for instances. The compute
usage report deducts this memory from the available
memory sent to the placement service.
actions:
set-hypervisor-local-settings:
@ -81,6 +88,9 @@ actions:
Only lists guests created by the OpenStack cloud.
additionalProperties: false
list-flavors:
description: |
List the flavors or compute host capabilities.
requires:
amqp:

View File

@ -191,6 +191,10 @@ class HypervisorOperatorCharm(sunbeam_charm.OSBaseOperatorCharm):
self.on.running_guests_action,
self._running_guests_action,
)
self.framework.observe(
self.on.list_flavors_action,
self._list_flavors_action,
)
self.framework.observe(
self.on.install,
self._on_install,
@ -422,6 +426,18 @@ class HypervisorOperatorCharm(sunbeam_charm.OSBaseOperatorCharm):
# cli returns a json list
event.set_results({"result": stdout})
def _list_flavors_action(self, event: ActionEvent):
"""List compute host capabilities."""
cache = self.get_snap_cache()
hypervisor = cache["openstack-hypervisor"]
try:
flavors = hypervisor.get("compute.flavors", typed=True)
except snap.SnapError as e:
logger.debug(e)
flavors = ""
event.set_results({"result": flavors})
def ensure_services_running(self):
"""Ensure systemd services running."""
# This should taken care of by the snap
@ -575,6 +591,9 @@ class HypervisorOperatorCharm(sunbeam_charm.OSBaseOperatorCharm):
"node.ip-address": config("ip-address") or local_ip,
"rabbitmq.url": contexts.amqp.transport_url,
"monitoring.enable": self.enable_monitoring,
"sev.reserved-host-memory-mb": config(
"reserved-host-memory-mb-for-sev"
),
}
except AttributeError as e:
raise sunbeam_guard.WaitingExceptionError(

View File

@ -174,6 +174,7 @@ class TestCharm(test_utils.CharmTestCase):
"telemetry.enable": False,
"ca.bundle": None,
"masakari.enable": False,
"sev.reserved-host-memory-mb": None,
}
hypervisor_snap_mock.set.assert_any_call(expect_settings, typed=True)
@ -287,6 +288,7 @@ class TestCharm(test_utils.CharmTestCase):
"telemetry.publisher-secret": "FAKE_SECRET",
"ca.bundle": None,
"masakari.enable": True,
"sev.reserved-host-memory-mb": None,
}
hypervisor_snap_mock.set.assert_any_call(expect_settings, typed=True)
@ -346,3 +348,16 @@ class TestCharm(test_utils.CharmTestCase):
self.subprocess.run = subprocess_run_mock
with self.assertRaises(ops.testing.ActionFailed):
self.harness.run_action("list-nics")
def test_list_flavors(self):
"""Check action return flavors."""
flavors = "flavor1,flavor2"
self.harness.begin()
hypervisor_snap_mock = MagicMock()
hypervisor_snap_mock.present = True
self.snap.SnapCache.return_value = {
"openstack-hypervisor": hypervisor_snap_mock
}
hypervisor_snap_mock.get.return_value = flavors
action_output = self.harness.run_action("list-flavors")
assert action_output.results["result"] == flavors