Skip to content

Commit 2b78016

Browse files
committed
libvirt: make it possible to run libvirt on the host
In some cases it may be desirable to run the libvirt daemon on the host. For example, when mixing host and container OS distributions or versions. This change makes it possible to disable the nova_libvirt container, by setting enable_nova_libvirt_container to false. The default values of some Docker mounts and other paths have been updated to point to default host directories rather than Docker volumes when using a host libvirt daemon. This change does not handle migration of existing systems from using a nova_libvirt container to libvirt on the host. Depends-On: https://review.opendev.org/c/openstack/ansible-collection-kolla/+/830504 Change-Id: Ia1239069ccee39416b20959cbabad962c56693cf (cherry picked from commit 4e41acd)
1 parent 435010e commit 2b78016

File tree

11 files changed

+181
-89
lines changed

11 files changed

+181
-89
lines changed

ansible/group_vars/all.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,7 @@ enable_neutron_trunk: "no"
691691
enable_neutron_metering: "no"
692692
enable_neutron_infoblox_ipam_agent: "no"
693693
enable_neutron_port_forwarding: "no"
694+
enable_nova_libvirt_container: "{{ nova_compute_virt_type in ['kvm', 'qemu'] }}"
694695
enable_nova_serialconsole_proxy: "no"
695696
enable_nova_ssh: "yes"
696697
enable_octavia: "no"
@@ -1026,7 +1027,7 @@ nova_backend_ceph: "no"
10261027
nova_backend: "{{ 'rbd' if nova_backend_ceph | bool else 'default' }}"
10271028
# Valid options are [ kvm, qemu, vmware ]
10281029
nova_compute_virt_type: "kvm"
1029-
nova_instance_datadir_volume: "nova_compute"
1030+
nova_instance_datadir_volume: "{{ 'nova_compute' if enable_nova_libvirt_container | bool else '/var/lib/nova' }}"
10301031
nova_safety_upgrade: "no"
10311032
# Valid options are [ none, novnc, spice ]
10321033
nova_console: "novnc"

ansible/roles/ceilometer/defaults/main.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ ceilometer_compute_default_volumes:
7878
- "/run/:/run/:shared"
7979
- "ceilometer:/var/lib/ceilometer/"
8080
- "kolla_logs:/var/log/kolla/"
81-
- "nova_libvirt:/var/lib/libvirt"
81+
- "{{ ceilometer_libvirt_volume }}:/var/lib/libvirt"
8282
- "{{ kolla_dev_repos_directory ~ '/ceilometer/ceilometer:/var/lib/kolla/venv/lib/python' ~ distro_python_version ~ '/site-packages/ceilometer' if ceilometer_dev_mode | bool else '' }}"
8383
ceilometer_ipmi_default_volumes:
8484
- "{{ node_config_directory }}/ceilometer-ipmi/:{{ container_config_directory }}/:ro"
@@ -94,6 +94,8 @@ ceilometer_central_extra_volumes: "{{ ceilometer_extra_volumes }}"
9494
ceilometer_compute_extra_volumes: "{{ ceilometer_extra_volumes }}"
9595
ceilometer_ipmi_extra_volumes: "{{ ceilometer_extra_volumes }}"
9696

97+
ceilometer_libvirt_volume: "{{ 'nova_libvirt' if enable_nova_libvirt_container | bool else '/var/lib/libvirt' }}"
98+
9799
####################
98100
# OpenStack
99101
####################

ansible/roles/common/tasks/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
- name: "conf/input/04-openstack-wsgi.conf.j2"
129129
enabled: true
130130
- name: "conf/input/05-libvirt.conf.j2"
131-
enabled: true
131+
enabled: "{{ enable_nova | bool and enable_nova_libvirt_container | bool }}"
132132
- name: "conf/input/06-zookeeper.conf.j2"
133133
enabled: true
134134
- name: "conf/input/07-kafka.conf.j2"
@@ -222,7 +222,7 @@
222222
- { name: "neutron", enabled: "{{ enable_neutron | bool }}" }
223223
- { name: "neutron-tls-proxy", enabled: "{{ neutron_enable_tls_backend | bool }}" }
224224
- { name: "nova", enabled: "{{ enable_nova | bool }}" }
225-
- { name: "nova-libvirt", enabled: "{{ enable_nova | bool and nova_compute_virt_type in ['kvm', 'qemu'] }}" }
225+
- { name: "nova-libvirt", enabled: "{{ enable_nova | bool and enable_nova_libvirt_container | bool }}" }
226226
- { name: "octavia", enabled: "{{ enable_octavia | bool }}" }
227227
- { name: "openvswitch", enabled: "{{ enable_openvswitch | bool }}" }
228228
- { name: "outward-rabbitmq", enabled: "{{ enable_outward_rabbitmq | bool }}" }

ansible/roles/nova-cell/defaults/main.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ nova_cell_services:
33
nova-libvirt:
44
container_name: nova_libvirt
55
group: "{{ nova_cell_compute_group }}"
6-
enabled: "{{ nova_compute_virt_type in ['kvm', 'qemu'] }}"
6+
enabled: "{{ enable_nova_libvirt_container }}"
77
image: "{{ nova_libvirt_image_full }}"
88
pid_mode: "host"
99
cgroupns_mode: "host"
@@ -398,7 +398,7 @@ nova_compute_default_volumes:
398398
- "/dev:/dev"
399399
- "kolla_logs:/var/log/kolla/"
400400
- "{% if enable_iscsid | bool %}iscsi_info:/etc/iscsi{% endif %}"
401-
- "libvirtd:/var/lib/libvirt"
401+
- "{{ nova_libvirt_volume }}:/var/lib/libvirt"
402402
- "{{ nova_instance_datadir_volume }}:/var/lib/nova/"
403403
- "{% if enable_shared_var_lib_nova_mnt | bool %}/var/lib/nova/mnt:/var/lib/nova/mnt:shared{% endif %}"
404404
- "{{ kolla_dev_repos_directory ~ '/nova/nova:/var/lib/kolla/venv/lib/python' ~ distro_python_version ~ '/site-packages/nova' if nova_dev_mode | bool else '' }}"
@@ -428,6 +428,8 @@ nova_compute_ironic_extra_volumes: "{{ nova_extra_volumes }}"
428428
# Used by bootstrapping containers.
429429
nova_cell_bootstrap_extra_volumes: "{{ nova_extra_volumes }}"
430430

431+
nova_libvirt_volume: "{{ 'libvirtd' if enable_nova_libvirt_container | bool else '/var/lib/libvirt' }}"
432+
431433
####################
432434
# HAProxy
433435
####################

ansible/roles/nova-cell/handlers/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@
128128
changed_when: true
129129
no_log: true
130130

131+
- name: Reload libvirtd
132+
become: true
133+
service:
134+
name: libvirtd
135+
state: reloaded
136+
131137
- name: Restart nova-compute container
132138
vars:
133139
service_name: "nova-compute"

ansible/roles/nova-cell/tasks/config-host.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
dest: "/etc/udev/rules.d/99-kolla-kvm.rules"
4040
mode: "0644"
4141
when:
42+
- enable_nova_libvirt_container | bool
4243
- nova_compute_virt_type == 'kvm'
4344
- inventory_hostname in groups[nova_cell_compute_group]
4445

@@ -51,6 +52,7 @@
5152
name: qemu-kvm.service
5253
masked: true
5354
when:
55+
- enable_nova_libvirt_container | bool
5456
- nova_compute_virt_type == 'kvm'
5557
- ansible_facts.distribution == 'Ubuntu'
5658
- inventory_hostname in groups[nova_cell_compute_group]

ansible/roles/nova-cell/tasks/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
- name: Copying over libvirt TLS keys
9595
include_tasks: config-libvirt-tls.yml
9696
when:
97+
- inventory_hostname in groups[nova_cell_compute_group]
9798
- libvirt_tls | bool
9899
- libvirt_tls_manage_certs | bool
99100

Lines changed: 121 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
11
---
2-
- name: Ensuring config directory exists
3-
file:
4-
path: "{{ node_config_directory }}/{{ item }}"
5-
state: "directory"
6-
mode: "0770"
7-
become: true
8-
with_items:
9-
- "nova-libvirt/secrets"
10-
when: inventory_hostname in groups[nova_cell_compute_group]
11-
122
- name: Check nova keyring file
133
stat:
144
path: "{{ node_custom_config }}/nova/{{ ceph_nova_keyring }}"
@@ -31,10 +21,32 @@
3121
- cinder_backend_ceph | bool
3222
- external_ceph_cephx_enabled | bool
3323

24+
- name: Extract nova key from file
25+
set_fact:
26+
nova_cephx_raw_key:
27+
"{{ lookup('template', nova_cephx_keyring_file.stat.path) | regex_search('key\\s*=.*$', multiline=True) | regex_replace('key\\s*=\\s*(.*)\\s*', '\\1') }}"
28+
changed_when: false
29+
run_once: True
30+
when:
31+
- nova_backend == "rbd"
32+
- external_ceph_cephx_enabled | bool
33+
34+
- name: Extract cinder key from file
35+
set_fact:
36+
cinder_cephx_raw_key:
37+
"{{ lookup('file', cinder_cephx_keyring_file.stat.path) | regex_search('key\\s*=.*$', multiline=True) | regex_replace('key\\s*=\\s*(.*)\\s*', '\\1') }}"
38+
changed_when: false
39+
run_once: True
40+
when:
41+
- cinder_backend_ceph | bool
42+
- external_ceph_cephx_enabled | bool
43+
3444
- name: Copy over ceph nova keyring file
3545
template:
3646
src: "{{ nova_cephx_keyring_file.stat.path }}"
3747
dest: "{{ node_config_directory }}/{{ item }}/"
48+
owner: "{{ config_owner_user }}"
49+
group: "{{ config_owner_group }}"
3850
mode: "0660"
3951
become: true
4052
with_items:
@@ -50,6 +62,8 @@
5062
template:
5163
src: "{{ cinder_cephx_keyring_file.stat.path }}"
5264
dest: "{{ node_config_directory }}/{{ item }}/"
65+
owner: "{{ config_owner_user }}"
66+
group: "{{ config_owner_group }}"
5367
mode: "0660"
5468
become: true
5569
with_items: # NOTE: nova-libvirt does not need it
@@ -62,90 +76,119 @@
6276
- Restart {{ item }} container
6377

6478
- name: Copy over ceph.conf
79+
vars:
80+
service: "{{ nova_cell_services[item] }}"
6581
template:
6682
src: "{{ node_custom_config }}/nova/ceph.conf"
6783
dest: "{{ node_config_directory }}/{{ item }}/"
84+
owner: "{{ config_owner_user }}"
85+
group: "{{ config_owner_group }}"
6886
mode: "0660"
6987
become: true
7088
with_items:
7189
- nova-compute
7290
- nova-libvirt
7391
when:
74-
- inventory_hostname in groups[nova_cell_compute_group]
92+
- inventory_hostname in groups[service.group]
93+
- service.enabled | bool
7594
- nova_backend == "rbd"
7695
notify:
7796
- Restart {{ item }} container
7897

79-
- name: Pushing nova secret xml for libvirt
80-
template:
81-
src: "secret.xml.j2"
82-
dest: "{{ node_config_directory }}/nova-libvirt/secrets/{{ item.uuid }}.xml"
83-
mode: "0600"
84-
become: true
85-
when:
86-
- inventory_hostname in groups[nova_cell_compute_group]
87-
- item.enabled | bool
88-
with_items:
89-
- uuid: "{{ rbd_secret_uuid }}"
90-
name: "client.nova secret"
91-
enabled: "{{ nova_backend == 'rbd' }}"
92-
- uuid: "{{ cinder_rbd_secret_uuid }}"
93-
name: "client.cinder secret"
94-
enabled: "{{ cinder_backend_ceph }}"
95-
notify:
96-
- Restart nova-libvirt container
98+
- block:
99+
- name: Ensure /etc/ceph directory exists (host libvirt)
100+
file:
101+
path: "/etc/ceph/"
102+
state: "directory"
103+
owner: "root"
104+
group: "root"
105+
mode: "0755"
106+
become: true
97107

98-
- name: Extract nova key from file
99-
set_fact:
100-
nova_cephx_raw_key:
101-
"{{ lookup('template', nova_cephx_keyring_file.stat.path) | regex_search('key\\s*=.*$', multiline=True) | regex_replace('key\\s*=\\s*(.*)\\s*', '\\1') }}"
102-
changed_when: false
103-
run_once: True
108+
- name: Copy over ceph.conf (host libvirt)
109+
template:
110+
src: "{{ node_custom_config }}/nova/ceph.conf"
111+
dest: "/etc/ceph/ceph.conf"
112+
owner: "root"
113+
group: "root"
114+
mode: "0644"
115+
become: true
104116
when:
117+
- not enable_nova_libvirt_container | bool
118+
- inventory_hostname in groups[nova_cell_compute_group]
105119
- nova_backend == "rbd"
106-
- external_ceph_cephx_enabled | bool
107120

108-
- name: Extract cinder key from file
109-
set_fact:
110-
cinder_cephx_raw_key:
111-
"{{ lookup('template', cinder_cephx_keyring_file.stat.path) | regex_search('key\\s*=.*$', multiline=True) | regex_replace('key\\s*=\\s*(.*)\\s*', '\\1') }}"
112-
changed_when: false
113-
run_once: True
114-
when:
115-
- cinder_backend_ceph | bool
116-
- external_ceph_cephx_enabled | bool
121+
- block:
122+
- name: Ensuring libvirt secrets directory exists
123+
vars:
124+
service: "{{ nova_cell_services['nova-libvirt'] }}"
125+
file:
126+
path: "{{ libvirt_secrets_dir }}"
127+
state: "directory"
128+
owner: "{{ config_owner_user }}"
129+
group: "{{ config_owner_group }}"
130+
mode: "0770"
131+
become: true
132+
when:
133+
- inventory_hostname in groups[service.group]
117134

118-
- name: Pushing secrets key for libvirt
119-
copy:
120-
content: "{{ item.result }}"
121-
dest: "{{ node_config_directory }}/nova-libvirt/secrets/{{ item.uuid }}.base64"
122-
mode: "0600"
123-
become: true
124-
when:
125-
- inventory_hostname in groups[nova_cell_compute_group]
126-
- item.enabled | bool
127-
- external_ceph_cephx_enabled | bool
128-
with_items:
129-
# NOTE(yoctozepto): 'default' filter required due to eager evaluation of item content
130-
# which will be undefined if the applicable condition is False
131-
- uuid: "{{ rbd_secret_uuid }}"
132-
result: "{{ nova_cephx_raw_key | default }}"
133-
enabled: "{{ nova_backend == 'rbd' }}"
134-
- uuid: "{{ cinder_rbd_secret_uuid }}"
135-
result: "{{ cinder_cephx_raw_key | default }}"
136-
enabled: "{{ cinder_backend_ceph }}"
137-
notify:
138-
- Restart nova-libvirt container
139-
no_log: True
135+
- name: Pushing nova secret xml for libvirt
136+
vars:
137+
service: "{{ nova_cell_services['nova-libvirt'] }}"
138+
template:
139+
src: "secret.xml.j2"
140+
dest: "{{ libvirt_secrets_dir }}/{{ item.uuid }}.xml"
141+
owner: "{{ config_owner_user }}"
142+
group: "{{ config_owner_group }}"
143+
mode: "0600"
144+
become: true
145+
when:
146+
- inventory_hostname in groups[service.group]
147+
- item.enabled | bool
148+
with_items:
149+
- uuid: "{{ rbd_secret_uuid }}"
150+
name: "client.nova secret"
151+
enabled: "{{ nova_backend == 'rbd' }}"
152+
- uuid: "{{ cinder_rbd_secret_uuid }}"
153+
name: "client.cinder secret"
154+
enabled: "{{ cinder_backend_ceph }}"
155+
notify: "{{ libvirt_restart_handlers }}"
140156

141-
- name: Ensuring config directory has correct owner and permission
142-
become: true
143-
file:
144-
path: "{{ node_config_directory }}/{{ item }}"
145-
recurse: yes
146-
owner: "{{ config_owner_user }}"
147-
group: "{{ config_owner_group }}"
148-
with_items:
149-
- "nova-compute"
150-
- "nova-libvirt/secrets"
151-
when: inventory_hostname in groups[nova_cell_compute_group]
157+
- name: Pushing secrets key for libvirt
158+
vars:
159+
service: "{{ nova_cell_services['nova-libvirt'] }}"
160+
copy:
161+
content: "{{ item.result }}"
162+
dest: "{{ libvirt_secrets_dir }}/{{ item.uuid }}.base64"
163+
owner: "{{ config_owner_user }}"
164+
group: "{{ config_owner_group }}"
165+
mode: "0600"
166+
become: true
167+
when:
168+
- inventory_hostname in groups[service.group]
169+
- item.enabled | bool
170+
- external_ceph_cephx_enabled | bool
171+
with_items:
172+
# NOTE(yoctozepto): 'default' filter required due to eager evaluation of item content
173+
# which will be undefined if the applicable condition is False
174+
- uuid: "{{ rbd_secret_uuid }}"
175+
result: "{{ nova_cephx_raw_key | default }}"
176+
enabled: "{{ nova_backend == 'rbd' }}"
177+
- uuid: "{{ cinder_rbd_secret_uuid }}"
178+
result: "{{ cinder_cephx_raw_key | default }}"
179+
enabled: "{{ cinder_backend_ceph }}"
180+
notify: "{{ libvirt_restart_handlers }}"
181+
no_log: True
182+
vars:
183+
libvirt_secrets_dir: >-
184+
{{ (node_config_directory ~ '/nova-libvirt/secrets')
185+
if enable_nova_libvirt_container | bool
186+
else '/etc/libvirt/secrets' }}
187+
# NOTE(mgoddard): When running libvirt as a host daemon, on CentOS it
188+
# appears to pick up secrets automatically, while on Ubuntu it requires a
189+
# reload. This may be due to differences in tested versions of libvirt
190+
# (8.0.0 vs 6.0.0). Reload should be low overhead, so do it always.
191+
libvirt_restart_handlers: >-
192+
{{ ['Restart nova-libvirt container']
193+
if enable_nova_libvirt_container | bool else
194+
['Reload libvirtd'] }}

ansible/roles/nova-cell/tasks/precheck.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,26 @@
111111
- nova_libvirt.enabled | bool
112112
- inventory_hostname in groups[nova_libvirt.group]
113113

114-
- name: Checking that libvirt is not running
114+
- name: Checking that host libvirt is not running
115115
vars:
116116
nova_libvirt: "{{ nova_cell_services['nova-libvirt'] }}"
117117
stat: path=/var/run/libvirt/libvirt-sock
118118
register: result
119119
failed_when: result.stat.exists
120120
when:
121-
- nova_compute_virt_type in ['kvm', 'qemu']
122121
- container_facts['nova_libvirt'] is not defined
122+
- nova_libvirt.enabled | bool
123+
- inventory_hostname in groups[nova_libvirt.group]
124+
125+
- name: Checking that nova_libvirt container is not running
126+
vars:
127+
nova_libvirt: "{{ nova_cell_services['nova-libvirt'] }}"
128+
fail:
129+
msg: >-
130+
The nova_libvirt container is running, however it has been disabled via
131+
the 'enable_nova_libvirt_container' flag. Stop and remove the container
132+
manually, taking care to migrate any state to the host libvirt daemon.
133+
when:
134+
- container_facts['nova_libvirt'] is defined
135+
- not nova_libvirt.enabled | bool
123136
- inventory_hostname in groups[nova_libvirt.group]

0 commit comments

Comments
 (0)