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
charms/openstack-hypervisor
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:
|
external-bridge-address:
|
||||||
default: "10.20.20.1/24"
|
default: "10.20.20.1/24"
|
||||||
type: string
|
type: string
|
||||||
ip-address:
|
|
||||||
default:
|
|
||||||
type: string
|
|
||||||
physnet-name:
|
physnet-name:
|
||||||
default: "physnet1"
|
default: "physnet1"
|
||||||
type: string
|
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.ovn.relation_handlers as ovn_relation_handlers
|
||||||
import ops_sunbeam.relation_handlers as sunbeam_rhandlers
|
import ops_sunbeam.relation_handlers as sunbeam_rhandlers
|
||||||
from netifaces import AF_INET, gateways, ifaddresses
|
from netifaces import AF_INET, gateways, ifaddresses
|
||||||
|
from ops.charm import ActionEvent
|
||||||
from ops.main import main
|
from ops.main import main
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -69,6 +70,10 @@ class HypervisorOperatorCharm(sunbeam_charm.OSBaseOperatorCharm):
|
|||||||
"""Run constructor."""
|
"""Run constructor."""
|
||||||
super().__init__(framework)
|
super().__init__(framework)
|
||||||
self._state.set_default(metadata_secret="")
|
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(
|
def get_relation_handlers(
|
||||||
self, handlers: List[sunbeam_rhandlers.RelationHandler] = None
|
self, handlers: List[sunbeam_rhandlers.RelationHandler] = None
|
||||||
@ -86,6 +91,21 @@ class HypervisorOperatorCharm(sunbeam_charm.OSBaseOperatorCharm):
|
|||||||
handlers = super().get_relation_handlers(handlers)
|
handlers = super().get_relation_handlers(handlers)
|
||||||
return 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):
|
def ensure_services_running(self):
|
||||||
"""Ensure systemd services running."""
|
"""Ensure systemd services running."""
|
||||||
# This should taken care of by the snap
|
# This should taken care of by the snap
|
||||||
@ -121,11 +141,8 @@ class HypervisorOperatorCharm(sunbeam_charm.OSBaseOperatorCharm):
|
|||||||
self._state.metadata_secret = secret
|
self._state.metadata_secret = secret
|
||||||
return secret
|
return secret
|
||||||
|
|
||||||
def set_snap_data(self, snap_data):
|
def set_snap_data(self, snap_data: dict):
|
||||||
"""Set snap setting if needed.
|
"""Set snap data on local snap."""
|
||||||
|
|
||||||
Update the snap with any settings that have changed.
|
|
||||||
"""
|
|
||||||
cache = snap.SnapCache()
|
cache = snap.SnapCache()
|
||||||
hypervisor = cache["openstack-hypervisor"]
|
hypervisor = cache["openstack-hypervisor"]
|
||||||
new_settings = {}
|
new_settings = {}
|
||||||
@ -195,7 +212,7 @@ class HypervisorOperatorCharm(sunbeam_charm.OSBaseOperatorCharm):
|
|||||||
).decode(),
|
).decode(),
|
||||||
"network.ovn-sb-connection": sb_connection_strs[0],
|
"network.ovn-sb-connection": sb_connection_strs[0],
|
||||||
"network.physnet-name": config("physnet-name"),
|
"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,
|
"node.ip-address": config("ip-address") or local_ip,
|
||||||
"rabbitmq.url": contexts.amqp.transport_url,
|
"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):
|
class TestCharm(test_utils.CharmTestCase):
|
||||||
PATCHES = ["socket", "snap"]
|
PATCHES = ["socket", "snap", "_get_local_ip_by_default_route"]
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""Setup OpenStack Hypervisor tests."""
|
"""Setup OpenStack Hypervisor tests."""
|
||||||
@ -50,7 +50,7 @@ class TestCharm(test_utils.CharmTestCase):
|
|||||||
def initial_setup(self):
|
def initial_setup(self):
|
||||||
rel_id = self.harness.add_relation("certificates", "vault")
|
rel_id = self.harness.add_relation("certificates", "vault")
|
||||||
self.harness.add_relation_unit(rel_id, "vault/0")
|
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()
|
self.harness.begin_with_initial_hooks()
|
||||||
csr = {"certificate_signing_request": test_utils.TEST_CSR}
|
csr = {"certificate_signing_request": test_utils.TEST_CSR}
|
||||||
self.harness.update_relation_data(
|
self.harness.update_relation_data(
|
||||||
@ -79,6 +79,7 @@ class TestCharm(test_utils.CharmTestCase):
|
|||||||
|
|
||||||
def test_all_relations(self):
|
def test_all_relations(self):
|
||||||
"""Test all the charms relations."""
|
"""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 = mock.MagicMock()
|
||||||
hypervisor_snap_mock.present = False
|
hypervisor_snap_mock.present = False
|
||||||
self.snap.SnapState.Latest = "latest"
|
self.snap.SnapState.Latest = "latest"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user