From 19614e94919525300f666846c1cdeae6feb6007f Mon Sep 17 00:00:00 2001 From: Mark Goddard Date: Fri, 17 Nov 2017 17:29:42 +0000 Subject: [PATCH] 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*. --- ansible/container-image-build.yml | 2 +- ansible/container-image-builders-check.yml | 12 +++ ansible/group_vars/all/kolla | 14 ++-- ansible/group_vars/controllers/kolla | 3 - ansible/group_vars/seed/kolla | 3 - ansible/kolla-build.yml | 2 +- ansible/kolla.yml | 6 -- etc/kayobe/inventory/groups | 16 ++++ kayobe/cli/commands.py | 16 +++- kayobe/tests/unit/cli/test_commands.py | 98 ++++++++++++++++++++++ 10 files changed, 147 insertions(+), 25 deletions(-) create mode 100644 ansible/container-image-builders-check.yml delete mode 100644 ansible/group_vars/controllers/kolla delete mode 100644 ansible/group_vars/seed/kolla delete mode 100644 ansible/kolla.yml diff --git a/ansible/container-image-build.yml b/ansible/container-image-build.yml index 532069a3c..78070e259 100644 --- a/ansible/container-image-build.yml +++ b/ansible/container-image-build.yml @@ -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 diff --git a/ansible/container-image-builders-check.yml b/ansible/container-image-builders-check.yml new file mode 100644 index 000000000..da72bbd2a --- /dev/null +++ b/ansible/container-image-builders-check.yml @@ -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 diff --git a/ansible/group_vars/all/kolla b/ansible/group_vars/all/kolla index 431323b79..b74c11130 100644 --- a/ansible/group_vars/all/kolla +++ b/ansible/group_vars/all/kolla @@ -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: {} diff --git a/ansible/group_vars/controllers/kolla b/ansible/group_vars/controllers/kolla deleted file mode 100644 index c63743f10..000000000 --- a/ansible/group_vars/controllers/kolla +++ /dev/null @@ -1,3 +0,0 @@ ---- -# List of Kolla container image sets for controllers. -container_image_sets: "{{ controller_container_image_sets }}" diff --git a/ansible/group_vars/seed/kolla b/ansible/group_vars/seed/kolla deleted file mode 100644 index d5680ce49..000000000 --- a/ansible/group_vars/seed/kolla +++ /dev/null @@ -1,3 +0,0 @@ ---- -# List of Kolla container image sets for the seed. -container_image_sets: "{{ seed_container_image_sets }}" diff --git a/ansible/kolla-build.yml b/ansible/kolla-build.yml index 0deff0c27..4a5a4aa5c 100644 --- a/ansible/kolla-build.yml +++ b/ansible/kolla-build.yml @@ -1,6 +1,6 @@ --- - name: Ensure Kolla is installed and configured - hosts: seed:controllers + hosts: container-image-builders roles: - role: kolla - role: kolla-build diff --git a/ansible/kolla.yml b/ansible/kolla.yml deleted file mode 100644 index bfd7ff66a..000000000 --- a/ansible/kolla.yml +++ /dev/null @@ -1,6 +0,0 @@ ---- -- name: Ensure Kolla is configured - hosts: config-mgmt - roles: - - role: kolla - - role: kolla-build diff --git a/etc/kayobe/inventory/groups b/etc/kayobe/inventory/groups index 2166e1b38..e50505419 100644 --- a/etc/kayobe/inventory/groups +++ b/etc/kayobe/inventory/groups @@ -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 diff --git a/kayobe/cli/commands.py b/kayobe/cli/commands.py index 577e5270d..3552c1833 100644 --- a/kayobe/cli/commands.py +++ b/kayobe/cli/commands.py @@ -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) diff --git a/kayobe/tests/unit/cli/test_commands.py b/kayobe/tests/unit/cli/test_commands.py index 66160bbe6..8baf31153 100644 --- a/kayobe/tests/unit/cli/test_commands.py +++ b/kayobe/tests/unit/cli/test_commands.py @@ -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)