Skip to content
This repository was archived by the owner on Aug 1, 2019. It is now read-only.

Commit 4abd0a3

Browse files
committed
yamlgroup: add regex match; exclude puppet4 for arm64 mirrors
Two related changes that need to go together because we test with the production groups.yaml. Confusingly, there are arm64 PC1 puppet repos, and it contains a bunch of things that it turns out are the common java parts only. The puppet-agent package is not available, and it doesn't seem like it will be [1]. I think this means we can not run puppet4 on our arm64 xenial ci hosts. The problem is the mirrors have been updated to puppet4 -- runs are now breaking on the arm mirrors because they don't have puppet-agent packages. It seems all we can really do at this point is contine to run them on puppet3. This is hard (impossible?) to express with a fnmatch in the existing yamlgroups syntax. We could do something like list all the mirror hosts and use anchors etc, but we have to keep that maintained. Add an feature to the inventory plugin that if the list entry starts with a ^ it is considered a full regex and passed to re.match. This allows us to write more complex matchers where required -- in this case the arm64 ci mirror hosts are excluded from the puppet4 group. Testing is updated. [1] https://groups.google.com/forum/#!msg/puppet-dev/iBMYJpvhaWM/WTGmJvXxAgAJ Change-Id: I828e0c524f8d5ca866786978486bc04829464b47
1 parent 8e4cd58 commit 4abd0a3

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

inventory/groups.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ groups:
175175
- logstash-worker[0-9]*.open*.org
176176
- logstash[0-9]*.open*.org
177177
- mirror-update[0-9]*.open*.org
178-
- mirror[0-9]*.*.*.open*.org
178+
- ^mirror[0-9].*\..*\.(?!linaro|linaro-london|arm64ci).*\.open.*\.org
179179
- openstackid[0-9]*.openstack.org
180180
- openstackid-dev[0-9]*.openstack.org
181181
- paste[0-9]*.open*.org

playbooks/roles/install-ansible/files/inventory_plugins/test-fixtures/results.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ results:
3939
- puppet
4040
- puppet4
4141

42+
mirror01.lon1.linaro-london.openstack.org:
43+
- afs-client
44+
- mirror
45+
- puppet
46+
4247
mirror-update01.openstack.org:
4348
- afsadmin
4449
- puppet

playbooks/roles/install-ansible/files/inventory_plugins/test_yamlgroup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_yaml_groups(self):
3737

3838
results_yaml = os.path.join(FIXTURE_DIR, 'results.yaml')
3939
with open(results_yaml) as f:
40-
results = yaml.load(f)
40+
results = yaml.load(f, Loader=yaml.FullLoader)
4141
results = results['results']
4242

4343
# Build the inventory list. This is a list of Host objects
@@ -65,7 +65,7 @@ def add_child(group, host):
6565
# real-life, which gets the groups into the config object
6666
path = os.path.join(FIXTURE_DIR, 'groups.yaml')
6767
with open(path) as f:
68-
config_groups = yaml.load(f)
68+
config_groups = yaml.load(f, Loader=yaml.FullLoader)
6969
config_groups = config_groups['groups']
7070
im = InventoryModule()
7171
im._read_config_data = mock.MagicMock()

playbooks/roles/install-ansible/files/inventory_plugins/yamlgroup.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import fnmatch
55
import os
6+
import re
67

78
from ansible.parsing.yaml.objects import AnsibleMapping
89
from ansible.plugins.inventory import BaseFileInventoryPlugin
@@ -28,7 +29,10 @@
2829
- section: inventory_plugin_yaml
2930
key: yaml_valid_extensions
3031
groups:
31-
description: dict with group name as key and list of fnmatch patterns
32+
description: |
33+
dict with group name as key. If the list item starts with a
34+
^ it will be considered a regex pattern (i.e. passed to
35+
re.match), otherwise it is considered a fnmatch pattern.
3236
type: dict
3337
default: {}
3438
'''
@@ -38,6 +42,7 @@
3842
amazing:
3943
- fullhost.example.com
4044
- amazing*
45+
- ^regex.*pattern
4146
'''
4247

4348

@@ -75,8 +80,16 @@ def parse(self, inventory, loader, path, cache=True):
7580
# failing.
7681
if isinstance(candidate, AnsibleMapping):
7782
candidate = list(candidate.keys())[0]
83+
84+
# Starts with ^ means it is already a regex.
85+
# Otherwise it's a fnmatch compatible string; use it's
86+
# helper to turn that into a regex so we have a common
87+
# match below.
88+
if not candidate.startswith('^'):
89+
candidate = fnmatch.translate(candidate)
90+
7891
for existing in self.inventory.hosts.values():
79-
if fnmatch.fnmatch(existing.get_name(), candidate):
92+
if re.match(candidate, existing.get_name()):
8093
found_groups.setdefault(group, [])
8194
found_groups[group].append(existing)
8295

0 commit comments

Comments
 (0)