changing the boolean config option does not configure the snap-openstack-hypervisor correctly

Bug #2033272 reported by Chi Wai CHAN
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Juju Charmed Operator - OpenStack Hypervisor
Fix Committed
Medium
Chi Wai CHAN

Bug Description

Currently, the config data flows from charm to snap.

In the charm, the config option for boolean type (`debug` and `enable-gateway`) will be set to a string of "true" or "false" in the snap configuration using `operator.libs.linux (snap.py)` [1,2]. Then, in the snap, the config option will be also read as a string using `snaphelper`. However, the snap is using the config option as a boolean type [3] which always return `True` for non empty string. For example, one checks the `hooks.log`:

```
# in /var/snap/openstack-hypervisor/common/hooks.log

09:58:57,671 root WARNING Context {'compute': {'cpu_mode': 'host-model', 'spice_proxy_address': '10.6.0.77', 'virt_type': 'kvm'}, 'credentials': {'ovn_metadata_proxy_shared_secret': '0JF9pzVFi0WF64YPG8erHaBLguDkJMBv'}, 'identity': {'admin_role': 'Admin', 'auth_url': 'http://10.6.0.202:80/openstack-keystone', 'password': 'RTEa5Jlfra3h', 'project_domain_id': 'c582aeb94a484553b898faa2d4d27cec', 'project_domain_name': 'service_domain', 'project_name': 'services', 'region_name': 'RegionOne', 'user_domain_id': 'c582aeb94a484553b898faa2d4d27cec', 'user_domain_name': 'service_domain', 'username': 'openstack-hypervisor'}, 'logging': {'debug': 'true'}, 'network': {'dns_domain': 'openstack.local', 'dns_servers': '8.8.8.8', 'enable_gateway': 'false', 'external_bridge': 'br-ex', 'external_bridge_address': '10.20.20.1/24', 'ip_address': '10.6.0.77', 'ovn_cacert': '<too_long>', 'ovn_cert': '<too_long>', 'ovn_key': '<too_long>', 'ovn_sb_connection': 'ssl:10.6.0.200:6642', 'physnet_name': 'physnet1'}, 'node': {'fqdn': 'sunbeam01.project.serverstack', 'ip_address': '10.6.0.77'}, 'rabbitmq': {'url': 'rabbit://hypervisor:Sbh9BxXQ1Ksr@10.6.0.201:5672/openstack'}, 'snap_common': '/var/snap/openstack-hypervisor/common', 'snap_data': '/var/snap/openstack-hypervisor/x10', 'snap': '/snap/openstack-hypervisor/x10'}
09:58:57,671 root WARNING [] are missing required config, stopping
09:58:57,833 root INFO Rendering /var/snap/openstack-hypervisor/common/etc/nova/nova.conf
09:58:57,846 root INFO Rendering /var/snap/openstack-hypervisor/common/etc/neutron/neutron.conf
09:58:57,852 root INFO Rendering /var/snap/openstack-hypervisor/common/etc/neutron/neutron_ovn_metadata_agent.ini
09:58:57,858 root INFO Rendering /var/snap/openstack-hypervisor/common/etc/libvirt/libvirtd.conf
09:58:57,860 root INFO Rendering /var/snap/openstack-hypervisor/common/etc/libvirt/qemu.conf
09:58:57,862 root INFO Rendering /var/snap/openstack-hypervisor/common/etc/libvirt/virtlogd.conf
09:58:57,863 root INFO Rendering /var/snap/openstack-hypervisor/common/etc/openvswitch/system-id.conf
09:58:58,13 root INFO Configuring Open vSwitch geneve tunnels and system id. ovn-encap-ip = 10.6.0.77, system-id = sunbeam01.project.serverstack
09:58:58,143 root INFO configuring external bridge br-ex
09:58:58,143 root DEBUG Adding ip 10.20.20.1/24 to br-ex
09:58:58,148 root DEBUG ['iptables-legacy', '--check', 'POSTROUTING', '-w', '-t', 'nat', '-s', '10.20.20.0/24', '-j', 'MASQUERADE', '-m', 'comment', '--comment', 'openstack-hypervisor external network rule']
09:58:58,152 root DEBUG Found existing postrouting rule for 10.20.20.0/24
09:58:58,165 root INFO Enabling OVS as external gateway
09:58:58,266 root INFO Checking virtualization extensions presence on the host
09:58:58,278 root INFO Hardware virtualization is supported - KVM will be used.
```

Notice that even though {'enable_gateway': 'false'}, it still outputs the "INFO Enabling OVS as external gateway".

The root cause may be related to the issue in `operator.libs.linux (snap.py)` [4]

[1] https://opendev.org/openstack/charm-openstack-hypervisor/src/branch/main/src/charm.py#L145
[2] https://opendev.org/openstack/charm-openstack-hypervisor/src/branch/main/lib/charms/operator_libs_linux/v2/snap.py#L327
[3] https://github.com/openstack-snaps/snap-openstack-hypervisor/blob/main/openstack_hypervisor/hooks.py#L740
[4] https://github.com/canonical/operator-libs-linux/issues/107

Tags: in-main
Changed in charm-openstack-hypervisor:
status: New → Triaged
Chi Wai CHAN (raychan96)
Changed in charm-openstack-hypervisor:
assignee: nobody → Chi Wai CHAN (raychan96)
Changed in charm-openstack-hypervisor:
importance: Undecided → Medium
Chi Wai CHAN (raychan96)
Changed in charm-openstack-hypervisor:
status: Triaged → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to charm-openstack-hypervisor (main)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to charm-openstack-hypervisor (main)

Reviewed: https://review.opendev.org/c/openstack/charm-openstack-hypervisor/+/893313
Committed: https://opendev.org/openstack/charm-openstack-hypervisor/commit/42ec5b1412c3fd9b90fbf256b1a054a07ec16189
Submitter: "Zuul (22348)"
Branch: main

commit 42ec5b1412c3fd9b90fbf256b1a054a07ec16189
Author: Chi Wai Chan <email address hidden>
Date: Wed Aug 30 18:08:37 2023 +0800

    Fix the typing issue in snap configs.

    Currently, setting boolean config with `Snap.set` will result in setting
    the snap config to a string of `true` or `false`, and the openstack
    hypervisor snap will read those configs as string as well. This makes
    the condition checking in openstack-hypervisor snap behaves incorrectly
    [1]. This PR is to update the snap library will proper typing support.

    - Update snap library
    - Fix the data types used in `Snap.set()`

    [1] https://github.com/openstack-snaps/snap-openstack-hypervisor/blob/main/openstack_hypervisor/hooks.py#L740

    Closes-Bug: #2033272
    Change-Id: I7bec4599b23500aaad9e008fce648793c104b642

tags: added: in-main
Chi Wai CHAN (raychan96)
Changed in charm-openstack-hypervisor:
status: In Progress → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.