Skip to content
This repository was archived by the owner on May 31, 2022. It is now read-only.

Commit d02315a

Browse files
authored
Merge pull request #216 from stackhpc/dib_build_overcloud
Wallaby: Build overcloud host image directly with DIB
2 parents 1e55054 + e26a3b2 commit d02315a

File tree

11 files changed

+258
-3
lines changed

11 files changed

+258
-3
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
# Overcloud host disk image configuration.
3+
4+
###############################################################################
5+
# Diskimage-builder configuration for overcloud host disk images.
6+
7+
# Whether to build host disk images with DIB directly instead of through
8+
# Bifrost. Setting it to true disables Bifrost image build and allows images to
9+
# be built with the `kayobe overcloud host image build` command. Default value
10+
# is False. This will change in a future release.
11+
overcloud_dib_build_host_images: False
12+
13+
# DIB base OS element. Default is {{ os_distribution }}.
14+
overcloud_dib_os_element: "{{ os_distribution }}"
15+
16+
# DIB image OS release. Default is {{ os_release }}.
17+
overcloud_dib_os_release: "{{ os_release }}"
18+
19+
# List of default DIB elements. Default is ["centos", "cloud-init-datasources",
20+
# "disable-selinux", "enable-serial-console", "vm"] when
21+
# overcloud_dib_os_element is "centos", or ["ubuntu", "cloud-init-datasources",
22+
# "enable-serial-console", "vm"] when overcloud_dib_os_element is "ubuntu".
23+
overcloud_dib_elements_default:
24+
- "{{ overcloud_dib_os_element }}"
25+
- "cloud-init-datasources"
26+
- "{% if overcloud_dib_os_element == 'centos' %}disable-selinux{% endif %}"
27+
- "enable-serial-console"
28+
- "vm"
29+
30+
# List of additional DIB elements. Default is none.
31+
overcloud_dib_elements_extra: []
32+
33+
# List of DIB elements. Default is a combination of
34+
# overcloud_dib_elements_default and overcloud_dib_elements_extra.
35+
overcloud_dib_elements: "{{ overcloud_dib_elements_default | select | list + overcloud_dib_elements_extra }}"
36+
37+
# DIB default environment variables. Default is
38+
# {"DIB_BOOTLOADER_DEFAULT_CMDLINE": "nofb nomodeset gfxpayload=text
39+
# net.ifnames=1", "DIB_CLOUD_INIT_DATASOURCES": "ConfigDrive", "DIB_RELEASE":
40+
# "{{ overcloud_dib_os_release }}"}.
41+
overcloud_dib_env_vars_default:
42+
DIB_BOOTLOADER_DEFAULT_CMDLINE: "nofb nomodeset gfxpayload=text net.ifnames=1"
43+
DIB_CLOUD_INIT_DATASOURCES: "ConfigDrive"
44+
DIB_RELEASE: "{{ overcloud_dib_os_release }}"
45+
46+
# DIB additional environment variables. Default is none.
47+
overcloud_dib_env_vars_extra: {}
48+
49+
# DIB environment variables. Default is combination of
50+
# overcloud_dib_env_vars_default and overcloud_dib_env_vars_extra.
51+
overcloud_dib_env_vars: "{{ overcloud_dib_env_vars_default | combine(overcloud_dib_env_vars_extra) }}"
52+
53+
# List of DIB packages to install. Default is to install no extra packages.
54+
overcloud_dib_packages: []
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
# Build and install a overcloud host disk image for the seed host's ironic
3+
# service.
4+
5+
- name: Ensure overcloud host disk image is built and installed
6+
hosts: seed
7+
tags:
8+
- overcloud-host-image-build
9+
vars:
10+
overcloud_host_image_name: "deployment_image"
11+
overcloud_host_disk_images:
12+
- "{{ overcloud_host_image_name }}.qcow2"
13+
overcloud_host_image_force_rebuild: False
14+
tasks:
15+
- block:
16+
- name: Ensure overcloud host disk image is built
17+
include_role:
18+
name: stackhpc.os-images
19+
vars:
20+
os_images_venv: "{{ virtualenv_path }}/overcloud-host-image-dib"
21+
os_images_package_state: latest
22+
os_images_upper_constraints_file: "{{ pip_upper_constraints_file }}"
23+
os_images_cache: "{{ image_cache_path }}"
24+
os_images_common: ""
25+
os_images_list:
26+
- name: "{{ overcloud_host_image_name }}"
27+
elements: "{{ overcloud_dib_elements }}"
28+
env: "{{ overcloud_dib_env_vars }}"
29+
packages: "{{ overcloud_dib_packages }}"
30+
type: qcow2
31+
os_images_upload: False
32+
os_images_force_rebuild: "{{ overcloud_host_image_force_rebuild }}"
33+
34+
- name: Ensure overcloud host disk image is copied onto seed
35+
copy:
36+
src: "{{ image_cache_path }}/{{ overcloud_host_image_name }}/{{ item }}"
37+
dest: "/etc/kolla/bifrost/{{ item }}"
38+
remote_src: True
39+
with_items: "{{ overcloud_host_disk_images }}"
40+
become: True
41+
42+
- name: Copy overcloud host disk image into /httpboot
43+
command: >
44+
docker exec bifrost_deploy
45+
bash -c 'ansible -vvvv target
46+
-i /bifrost/playbooks/inventory/target
47+
-m copy
48+
-a "src=/etc/bifrost/{{ item }} dest=/httpboot/{{ item }}"
49+
-e "ansible_python_interpreter=/var/lib/kolla/venv/bin/python"'
50+
with_items: "{{ overcloud_host_disk_images }}"
51+
when: overcloud_dib_build_host_images | bool

ansible/roles/kolla-bifrost/templates/dib.yml.j2

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
{% if not overcloud_dib_build_host_images | bool %}
23
# Diskimage-builder element for base OS.
34
dib_os_element: "{{ kolla_bifrost_dib_os_element }}"
45

@@ -13,3 +14,9 @@ dib_elements: "{{ (kolla_bifrost_dib_elements + [kolla_bifrost_dib_init_element]
1314

1415
# List of DIB image packages.
1516
dib_packages: "{{ kolla_bifrost_dib_packages | join(',') }}"
17+
{% else %}
18+
# Stop building overcloud host image using Bifrost. This needs to be defined
19+
# here to override the default true value set in kolla-ansible in
20+
# ansible/roles/bifrost/templates/dib.yml.j2.
21+
create_image_via_dib: False
22+
{% endif %}

ansible/seed-ipa-build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353
- name: Copy Ironic Python Agent images into /httpboot
5454
command: >
5555
docker exec bifrost_deploy
56-
bash -c 'export OS_CLOUD=bifrost &&
57-
ansible -vvvv target -i /bifrost/playbooks/inventory/target
56+
bash -c 'ansible -vvvv target
57+
-i /bifrost/playbooks/inventory/target
5858
-m copy
5959
-a "src=/etc/bifrost/{{ item }} dest=/httpboot/{{ item }}"
6060
-e "ansible_python_interpreter=/var/lib/kolla/venv/bin/python"'

dev/functions

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ function is_ironic_enabled {
210210
[[ $ironic_enabled =~ ^true$ ]]
211211
}
212212

213+
function is_overcloud_host_image_built_by_dib {
214+
overcloud_dib_build_host_images=$(kayobe configuration dump --host controllers[0] --var-name overcloud_dib_build_host_images)
215+
[[ $overcloud_dib_build_host_images =~ ^true$ ]]
216+
}
217+
213218
function environment_setup {
214219
# NOTE: Virtualenv's activate script references an unbound variable.
215220
set +u
@@ -307,6 +312,13 @@ function seed_deploy {
307312
else
308313
echo "Not building seed deployment images"
309314
fi
315+
316+
if is_overcloud_host_image_built_by_dib; then
317+
echo "Building overcloud host images"
318+
run_kayobe overcloud host image build
319+
else
320+
echo "Not building overcloud host images"
321+
fi
310322
}
311323

312324
function seed_upgrade {

etc/kayobe/overcloud-dib.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
# Overcloud host disk image configuration.
3+
4+
###############################################################################
5+
# Diskimage-builder configuration for overcloud host disk images.
6+
7+
# Whether to build host disk images with DIB directly instead of through
8+
# Bifrost. Setting it to true disables Bifrost image build and allows images to
9+
# be built with the `kayobe overcloud host image build` command. Default value
10+
# is False. This will change in a future release.
11+
#overcloud_dib_build_host_images:
12+
13+
# DIB base OS element. Default is {{ os_distribution }}.
14+
#overcloud_dib_os_element:
15+
16+
# DIB image OS release. Default is {{ os_release }}.
17+
#overcloud_dib_os_release:
18+
19+
# List of default DIB elements. Default is ["centos", "cloud-init-datasources",
20+
# "disable-selinux", "enable-serial-console", "vm"] when
21+
# overcloud_dib_os_element is "centos", or ["ubuntu", "cloud-init-datasources",
22+
# "enable-serial-console", "vm"] when overcloud_dib_os_element is "ubuntu".
23+
#overcloud_dib_elements_default:
24+
25+
# List of additional DIB elements. Default is none.
26+
#overcloud_dib_elements_extra:
27+
28+
# List of DIB elements. Default is a combination of
29+
# overcloud_dib_elements_default and overcloud_dib_elements_extra.
30+
#overcloud_dib_elements:
31+
32+
# DIB default environment variables. Default is
33+
# {"DIB_BOOTLOADER_DEFAULT_CMDLINE": "nofb nomodeset gfxpayload=text
34+
# net.ifnames=1", "DIB_CLOUD_INIT_DATASOURCES": "ConfigDrive", "DIB_RELEASE":
35+
# "{{ overcloud_dib_os_release }}"}.
36+
#overcloud_dib_env_vars_default:
37+
38+
# DIB additional environment variables. Default is none.
39+
#overcloud_dib_env_vars_extra:
40+
41+
# DIB environment variables. Default is combination of
42+
# overcloud_dib_env_vars_default and overcloud_dib_env_vars_extra.
43+
#overcloud_dib_env_vars:
44+
45+
# List of DIB packages to install. Default is to install no extra packages.
46+
#overcloud_dib_packages:
47+
48+
###############################################################################
49+
# Dummy variable to allow Ansible to accept this file.
50+
workaround_ansible_issue_8743: yes

kayobe/cli/commands.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,6 +1748,31 @@ def take_action(self, parsed_args):
17481748
extra_vars=extra_vars)
17491749

17501750

1751+
class OvercloudHostImageBuild(KayobeAnsibleMixin, VaultMixin, Command):
1752+
"""Build overcloud host disk images.
1753+
1754+
Builds host disk images using Diskimage Builder (DIB) for use when
1755+
provisioning the overcloud hosts.
1756+
"""
1757+
1758+
def get_parser(self, prog_name):
1759+
parser = super(OvercloudHostImageBuild, self).get_parser(
1760+
prog_name)
1761+
group = parser.add_argument_group("Host Image Build")
1762+
group.add_argument("--force-rebuild", action="store_true",
1763+
help="whether to force rebuilding the images")
1764+
return parser
1765+
1766+
def take_action(self, parsed_args):
1767+
self.app.LOG.debug("Building overcloud host disk images")
1768+
playbooks = _build_playbook_list("overcloud-host-image-build")
1769+
extra_vars = {}
1770+
if parsed_args.force_rebuild:
1771+
extra_vars["overcloud_host_image_force_rebuild"] = True
1772+
self.run_kayobe_playbooks(parsed_args, playbooks,
1773+
extra_vars=extra_vars)
1774+
1775+
17511776
class OvercloudPostConfigure(KayobeAnsibleMixin, VaultMixin, Command):
17521777
"""Perform post-deployment configuration.
17531778

kayobe/tests/unit/cli/test_commands.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,6 +1960,50 @@ def test_overcloud_container_image_build_with_regex(self, mock_run):
19601960
]
19611961
self.assertEqual(expected_calls, mock_run.call_args_list)
19621962

1963+
@mock.patch.object(commands.KayobeAnsibleMixin,
1964+
"run_kayobe_playbooks")
1965+
def test_overcloud_host_image_build(self, mock_run):
1966+
command = commands.OvercloudHostImageBuild(TestApp(), [])
1967+
parser = command.get_parser("test")
1968+
parsed_args = parser.parse_args([])
1969+
1970+
result = command.run(parsed_args)
1971+
self.assertEqual(0, result)
1972+
1973+
expected_calls = [
1974+
mock.call(
1975+
mock.ANY,
1976+
[
1977+
utils.get_data_files_path(
1978+
"ansible", "overcloud-host-image-build.yml"),
1979+
],
1980+
extra_vars={},
1981+
),
1982+
]
1983+
self.assertEqual(expected_calls, mock_run.call_args_list)
1984+
1985+
@mock.patch.object(commands.KayobeAnsibleMixin,
1986+
"run_kayobe_playbooks")
1987+
def test_overcloud_host_image_build_force_rebuild(self, mock_run):
1988+
command = commands.OvercloudHostImageBuild(TestApp(), [])
1989+
parser = command.get_parser("test")
1990+
parsed_args = parser.parse_args(["--force-rebuild"])
1991+
1992+
result = command.run(parsed_args)
1993+
self.assertEqual(0, result)
1994+
1995+
expected_calls = [
1996+
mock.call(
1997+
mock.ANY,
1998+
[
1999+
utils.get_data_files_path(
2000+
"ansible", "overcloud-host-image-build.yml"),
2001+
],
2002+
extra_vars={"overcloud_host_image_force_rebuild": True},
2003+
),
2004+
]
2005+
self.assertEqual(expected_calls, mock_run.call_args_list)
2006+
19632007
@mock.patch.object(commands.KayobeAnsibleMixin,
19642008
"run_kayobe_playbooks")
19652009
def test_overcloud_deployment_image_build(self, mock_run):

playbooks/kayobe-seed-base/overrides.yml.j2

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,7 @@ aio_bridge_ports:
3535
# Build seed deployment images (IPA) with extra-hardware element
3636
ipa_build_images: true
3737
ipa_build_dib_elements_extra:
38-
- "extra-hardware"
38+
- "extra-hardware"
39+
40+
# Build overcloud host image
41+
overcloud_dib_build_host_images: true

roles/kayobe-diagnostics/files/get_logs.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ copy_logs() {
100100
cp /opt/kayobe/images/ipa/ipa.stderr /opt/kayobe/images/ipa/ipa.stdout ${LOG_DIR}/kayobe/
101101
fi
102102

103+
# Overcloud host image build logs
104+
if [[ -f /opt/kayobe/images/deployment_image/deployment_image.stderr ]] || [[ -f /opt/kayobe/images/deployment_image/deployment_image.stdout ]]; then
105+
mkdir -p ${LOG_DIR}/kayobe
106+
cp /opt/kayobe/images/deployment_image/deployment_image.stderr /opt/kayobe/images/deployment_image/deployment_image.stdout ${LOG_DIR}/kayobe/
107+
fi
108+
103109
# Rename files to .txt; this is so that when displayed via
104110
# logs.openstack.org clicking results in the browser shows the
105111
# files, rather than trying to send it to another app or make you

0 commit comments

Comments
 (0)