Add action for applying local settings
Add action to apply snap setting specific to the local unit. Change-Id: I6ab63de753046c07934a6f923206ff5179599e39
This commit is contained in:
parent
123b9af8f2
commit
1a63fa2fdf
15
charms/openstack-hypervisor/actions.yaml
Normal file
15
charms/openstack-hypervisor/actions.yaml
Normal file
@ -0,0 +1,15 @@
|
||||
set-hypervisor-local-settings:
|
||||
description: |
|
||||
Apply settings specific to this hypervisor unit
|
||||
params:
|
||||
external-nic:
|
||||
type: string
|
||||
description: NIC that hypervisor will configure for North/South traffic
|
||||
spice-proxy-address:
|
||||
type: string
|
||||
description: IP address to use for configuration of SPICE consoles in instances.
|
||||
ip-address:
|
||||
type: string
|
||||
description: IP address to use for service configuration
|
||||
additionalProperties: false
|
||||
|
@ -20,9 +20,6 @@ options:
|
||||
external-bridge-address:
|
||||
default: "10.20.20.1/24"
|
||||
type: string
|
||||
ip-address:
|
||||
default:
|
||||
type: string
|
||||
physnet-name:
|
||||
default: "physnet1"
|
||||
type: string
|
||||
|
@ -36,6 +36,7 @@ import ops_sunbeam.guard as sunbeam_guard
|
||||
import ops_sunbeam.ovn.relation_handlers as ovn_relation_handlers
|
||||
import ops_sunbeam.relation_handlers as sunbeam_rhandlers
|
||||
from netifaces import AF_INET, gateways, ifaddresses
|
||||
from ops.charm import ActionEvent
|
||||
from ops.main import main
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -69,6 +70,10 @@ class HypervisorOperatorCharm(sunbeam_charm.OSBaseOperatorCharm):
|
||||
"""Run constructor."""
|
||||
super().__init__(framework)
|
||||
self._state.set_default(metadata_secret="")
|
||||
self.framework.observe(
|
||||
self.on.set_hypervisor_local_settings_action,
|
||||
self._set_hypervisor_local_settings_action,
|
||||
)
|
||||
|
||||
def get_relation_handlers(
|
||||
self, handlers: List[sunbeam_rhandlers.RelationHandler] = None
|
||||
@ -86,6 +91,21 @@ class HypervisorOperatorCharm(sunbeam_charm.OSBaseOperatorCharm):
|
||||
handlers = super().get_relation_handlers(handlers)
|
||||
return handlers
|
||||
|
||||
def _set_hypervisor_local_settings_action(self, event: ActionEvent):
|
||||
"""Run set_hypervisor_local_settings action."""
|
||||
local_settings = [
|
||||
"network.external-nic",
|
||||
"compute.spice-proxy-address",
|
||||
"network.ip-address",
|
||||
]
|
||||
new_snap_settings = {}
|
||||
for setting in local_settings:
|
||||
action_param = setting.split(".")[1]
|
||||
if event.params.get(action_param):
|
||||
new_snap_settings[setting] = event.params.get(action_param)
|
||||
if new_snap_settings:
|
||||
self.set_snap_data(new_snap_settings)
|
||||
|
||||
def ensure_services_running(self):
|
||||
"""Ensure systemd services running."""
|
||||
# This should taken care of by the snap
|
||||
@ -121,11 +141,8 @@ class HypervisorOperatorCharm(sunbeam_charm.OSBaseOperatorCharm):
|
||||
self._state.metadata_secret = secret
|
||||
return secret
|
||||
|
||||
def set_snap_data(self, snap_data):
|
||||
"""Set snap setting if needed.
|
||||
|
||||
Update the snap with any settings that have changed.
|
||||
"""
|
||||
def set_snap_data(self, snap_data: dict):
|
||||
"""Set snap data on local snap."""
|
||||
cache = snap.SnapCache()
|
||||
hypervisor = cache["openstack-hypervisor"]
|
||||
new_settings = {}
|
||||
@ -195,7 +212,7 @@ class HypervisorOperatorCharm(sunbeam_charm.OSBaseOperatorCharm):
|
||||
).decode(),
|
||||
"network.ovn-sb-connection": sb_connection_strs[0],
|
||||
"network.physnet-name": config("physnet-name"),
|
||||
"node.fqdn": config("fqdn") or socket.getfqdn(),
|
||||
"node.fqdn": socket.getfqdn(),
|
||||
"node.ip-address": config("ip-address") or local_ip,
|
||||
"rabbitmq.url": contexts.amqp.transport_url,
|
||||
}
|
||||
|
1
charms/openstack-hypervisor/tests/actions.yaml
Symbolic link
1
charms/openstack-hypervisor/tests/actions.yaml
Symbolic link
@ -0,0 +1 @@
|
||||
../actions.yaml
|
@ -33,7 +33,7 @@ class _HypervisorOperatorCharm(charm.HypervisorOperatorCharm):
|
||||
|
||||
|
||||
class TestCharm(test_utils.CharmTestCase):
|
||||
PATCHES = ["socket", "snap"]
|
||||
PATCHES = ["socket", "snap", "_get_local_ip_by_default_route"]
|
||||
|
||||
def setUp(self):
|
||||
"""Setup OpenStack Hypervisor tests."""
|
||||
@ -50,7 +50,7 @@ class TestCharm(test_utils.CharmTestCase):
|
||||
def initial_setup(self):
|
||||
rel_id = self.harness.add_relation("certificates", "vault")
|
||||
self.harness.add_relation_unit(rel_id, "vault/0")
|
||||
self.harness.update_config({"snap-channel": "essex/stable", "ip-address": "10.0.0.10"})
|
||||
self.harness.update_config({"snap-channel": "essex/stable"})
|
||||
self.harness.begin_with_initial_hooks()
|
||||
csr = {"certificate_signing_request": test_utils.TEST_CSR}
|
||||
self.harness.update_relation_data(
|
||||
@ -79,6 +79,7 @@ class TestCharm(test_utils.CharmTestCase):
|
||||
|
||||
def test_all_relations(self):
|
||||
"""Test all the charms relations."""
|
||||
self._get_local_ip_by_default_route.return_value = "10.0.0.10"
|
||||
hypervisor_snap_mock = mock.MagicMock()
|
||||
hypervisor_snap_mock.present = False
|
||||
self.snap.SnapState.Latest = "latest"
|
||||
|
Loading…
Reference in New Issue
Block a user