Add an ansible group for container image builders

Hosts in this group are used to build container images for both the seed and
overcloud hosts.

We also rename various overcloud image related variables from controller* to
overcloud*.
This commit is contained in:
Mark Goddard 2017-11-17 17:29:42 +00:00
parent 0daf298502
commit 19614e9491
10 changed files with 147 additions and 25 deletions

View File

@ -1,6 +1,6 @@
---
- name: Ensure Kolla container images are built
hosts: seed:controllers
hosts: container-image-builders
vars:
# Set this to True to push images to the registry when built.
push_images: False

View File

@ -0,0 +1,12 @@
---
- name: Ensure the container-image-builders group exists
hosts: localhost
gather_facts: False
tasks:
- name: Ensure the container-image-builders group exists
fail:
msg: >
Container images are now built by hosts in the
container-image-builders group. Ensure that this group is present in
your inventory.
when: groups.get('container-image-builders', []) | length == 0

View File

@ -104,8 +104,8 @@ seed_container_image_sets:
regexes: "{{ seed_container_image_regexes | join(' ') }}"
# List of regular expressions matching names of container images to build for
# controllers.
controller_container_image_regex_map:
# overcloud hosts.
overcloud_container_image_regex_map:
- regex: aodh
enabled: "{{ kolla_enable_aodh | bool }}"
- regex: barbican
@ -175,13 +175,13 @@ controller_container_image_regex_map:
enabled: True
# List of regular expressions matching names of container images to build for
# controllers.
controller_container_image_regexes: "{{ controller_container_image_regex_map | selectattr('enabled') | map(attribute='regex') | list }}"
# overcloud hosts.
overcloud_container_image_regexes: "{{ overcloud_container_image_regex_map | selectattr('enabled') | map(attribute='regex') | list }}"
# List of container image sets for controllers. This is used when building
# List of container image sets for overcloud hosts. This is used when building
# container images to determine which images to build.
controller_container_image_sets:
- regexes: "{{ controller_container_image_regexes | join(' ') }}"
overcloud_container_image_sets:
- regexes: "{{ overcloud_container_image_regexes | join(' ') }}"
# Dict mapping Jinja2 block names in kolla's Docker images to their contents.
kolla_build_blocks: {}

View File

@ -1,3 +0,0 @@
---
# List of Kolla container image sets for controllers.
container_image_sets: "{{ controller_container_image_sets }}"

View File

@ -1,3 +0,0 @@
---
# List of Kolla container image sets for the seed.
container_image_sets: "{{ seed_container_image_sets }}"

View File

@ -1,6 +1,6 @@
---
- name: Ensure Kolla is installed and configured
hosts: seed:controllers
hosts: container-image-builders
roles:
- role: kolla
- role: kolla-build

View File

@ -1,6 +0,0 @@
---
- name: Ensure Kolla is configured
hosts: config-mgmt
roles:
- role: kolla
- role: kolla-build

View File

@ -1,9 +1,22 @@
# Kayobe groups inventory file. This file should generally not be modified.
# If declares the top-level groups and sub-groups.
###############################################################################
# Seed groups.
[seed]
# Empty group to provide declaration of seed group.
[seed-hypervisor]
# Empty group to provide declaration of seed-hypervisor group.
[container-image-builders:children]
# Build container images on the seed by default.
seed
###############################################################################
# Overcloud groups.
[controllers]
# Empty group to provide declaration of controllers group.
@ -24,6 +37,9 @@ network
monitoring
compute
###############################################################################
# Docker groups.
[docker:children]
# Hosts in this group will have Docker installed.
seed

View File

@ -414,12 +414,16 @@ class SeedContainerImageBuild(KayobeAnsibleMixin, VaultMixin, Command):
def take_action(self, parsed_args):
self.app.LOG.debug("Building seed container images")
playbooks = _build_playbook_list(
"kolla-build", "container-image-build")
"container-image-builders-check", "kolla-build",
"container-image-build")
extra_vars = {"push_images": parsed_args.push}
if parsed_args.regex:
regexes = "'%s'" % " ".join(parsed_args.regex)
extra_vars["container_image_regexes"] = regexes
self.run_kayobe_playbooks(parsed_args, playbooks, limit="seed",
else:
extra_vars["container_image_sets"] = (
"{{ seed_container_image_sets }}")
self.run_kayobe_playbooks(parsed_args, playbooks,
extra_vars=extra_vars)
@ -940,12 +944,16 @@ class OvercloudContainerImageBuild(KayobeAnsibleMixin, VaultMixin, Command):
def take_action(self, parsed_args):
self.app.LOG.debug("Building overcloud container images")
playbooks = _build_playbook_list(
"kolla-build", "container-image-build")
"container-image-builders-check", "kolla-build",
"container-image-build")
extra_vars = {"push_images": parsed_args.push}
if parsed_args.regex:
regexes = "'%s'" % " ".join(parsed_args.regex)
extra_vars["container_image_regexes"] = regexes
self.run_kayobe_playbooks(parsed_args, playbooks, limit="controllers",
else:
extra_vars["container_image_sets"] = (
"{{ overcloud_container_image_sets }}")
self.run_kayobe_playbooks(parsed_args, playbooks,
extra_vars=extra_vars)

View File

@ -81,3 +81,101 @@ class TestCase(unittest.TestCase):
mock.call(mock.ANY, ["ansible/network-connectivity.yml"]),
]
self.assertEqual(expected_calls, mock_run.call_args_list)
@mock.patch.object(commands.KayobeAnsibleMixin,
"run_kayobe_playbooks")
def test_seed_container_image_build(self, mock_run):
command = commands.SeedContainerImageBuild(TestApp(), [])
parser = command.get_parser("test")
parsed_args = parser.parse_args([])
result = command.run(parsed_args)
self.assertEqual(0, result)
expected_calls = [
mock.call(
mock.ANY,
[
"ansible/container-image-builders-check.yml",
"ansible/kolla-build.yml",
"ansible/container-image-build.yml"
],
extra_vars={
"container_image_sets": (
"{{ seed_container_image_sets }}"),
"push_images": False,
}
),
]
self.assertEqual(expected_calls, mock_run.call_args_list)
@mock.patch.object(commands.KayobeAnsibleMixin,
"run_kayobe_playbooks")
def test_seed_container_image_build_with_regex(self, mock_run):
command = commands.SeedContainerImageBuild(TestApp(), [])
parser = command.get_parser("test")
parsed_args = parser.parse_args(["--push", "^regex1$", "^regex2$"])
result = command.run(parsed_args)
self.assertEqual(0, result)
expected_calls = [
mock.call(
mock.ANY,
[
"ansible/container-image-builders-check.yml",
"ansible/kolla-build.yml",
"ansible/container-image-build.yml"
],
extra_vars={
"container_image_regexes": "'^regex1$ ^regex2$'",
"push_images": True,
}
),
]
self.assertEqual(expected_calls, mock_run.call_args_list)
@mock.patch.object(commands.KayobeAnsibleMixin,
"run_kayobe_playbooks")
def test_overcloud_container_image_build(self, mock_run):
command = commands.OvercloudContainerImageBuild(TestApp(), [])
parser = command.get_parser("test")
parsed_args = parser.parse_args([])
result = command.run(parsed_args)
self.assertEqual(0, result)
expected_calls = [
mock.call(
mock.ANY,
[
"ansible/container-image-builders-check.yml",
"ansible/kolla-build.yml",
"ansible/container-image-build.yml"
],
extra_vars={
"container_image_sets": (
"{{ overcloud_container_image_sets }}"),
"push_images": False,
}
),
]
self.assertEqual(expected_calls, mock_run.call_args_list)
@mock.patch.object(commands.KayobeAnsibleMixin,
"run_kayobe_playbooks")
def test_overcloud_container_image_build_with_regex(self, mock_run):
command = commands.OvercloudContainerImageBuild(TestApp(), [])
parser = command.get_parser("test")
parsed_args = parser.parse_args(["--push", "^regex1$", "^regex2$"])
result = command.run(parsed_args)
self.assertEqual(0, result)
expected_calls = [
mock.call(
mock.ANY,
[
"ansible/container-image-builders-check.yml",
"ansible/kolla-build.yml",
"ansible/container-image-build.yml"
],
extra_vars={
"container_image_regexes": "'^regex1$ ^regex2$'",
"push_images": True,
}
),
]
self.assertEqual(expected_calls, mock_run.call_args_list)