diff options
author | Zuul <zuul@review.openstack.org> | 2017-12-06 18:56:28 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2017-12-06 18:56:28 +0000 |
commit | 64fc17b58db3e71e6fc18a888a1df17854828f40 (patch) | |
tree | 2ae3e97e80829e8cee4c7b07b82467d3c3208c25 | |
parent | 9bab764dacb9457493faf437aabe6d09dd02f679 (diff) | |
parent | ecb0b84f112e87f773431197fb794a79f5c00114 (diff) | |
download | zuul-64fc17b58db3e71e6fc18a888a1df17854828f40.tar.gz |
Merge "Add support for shared ansible_host in inventory" into feature/zuulv3
-rw-r--r-- | doc/source/user/config.rst | 10 | ||||
-rwxr-xr-x | tests/base.py | 2 | ||||
-rw-r--r-- | tests/fixtures/config/inventory/git/common-config/zuul.yaml | 10 | ||||
-rw-r--r-- | tests/fixtures/config/inventory/git/org_project/.zuul.yaml | 1 | ||||
-rw-r--r-- | tests/unit/test_inventory.py | 20 | ||||
-rw-r--r-- | tests/unit/test_nodepool.py | 20 | ||||
-rw-r--r-- | zuul/configloader.py | 12 | ||||
-rw-r--r-- | zuul/executor/server.py | 3 | ||||
-rw-r--r-- | zuul/model.py | 7 |
9 files changed, 64 insertions, 21 deletions
diff --git a/doc/source/user/config.rst b/doc/source/user/config.rst index 3ea20abb4..96e55a8f0 100644 --- a/doc/source/user/config.rst +++ b/doc/source/user/config.rst @@ -1210,7 +1210,9 @@ configuration may be simplified. label: controller-label - name: compute1 label: compute-label - - name: compute2 + - name: + - compute2 + - web label: compute-label groups: - name: ceph-osd @@ -1221,6 +1223,9 @@ configuration may be simplified. - controller - compute1 - compute2 + - name: ceph-web + nodes: + - web .. attr:: nodeset @@ -1242,6 +1247,9 @@ configuration may be simplified. The name of the node. This will appear in the Ansible inventory for the job. + This can also be as a list of strings. If so, then the list of hosts in + the Ansible inventory will share a common ansible_host address. + .. attr:: label :required: diff --git a/tests/base.py b/tests/base.py index f274ed634..210f03b28 100755 --- a/tests/base.py +++ b/tests/base.py @@ -1435,7 +1435,7 @@ class RecordingAnsibleJob(zuul.executor.server.AnsibleJob): host['host_vars']['ansible_connection'] = 'local' hosts.append(dict( - name='localhost', + name=['localhost'], host_vars=dict(ansible_connection='local'), host_keys=[])) return hosts diff --git a/tests/fixtures/config/inventory/git/common-config/zuul.yaml b/tests/fixtures/config/inventory/git/common-config/zuul.yaml index 74ddf2dce..ad530a783 100644 --- a/tests/fixtures/config/inventory/git/common-config/zuul.yaml +++ b/tests/fixtures/config/inventory/git/common-config/zuul.yaml @@ -52,6 +52,16 @@ run: playbooks/single-inventory.yaml - job: + name: single-inventory-list + nodeset: + nodes: + - name: + - compute + - controller + label: ubuntu-xenial + run: playbooks/single-inventory.yaml + +- job: name: group-inventory nodeset: nodeset1 run: playbooks/group-inventory.yaml diff --git a/tests/fixtures/config/inventory/git/org_project/.zuul.yaml b/tests/fixtures/config/inventory/git/org_project/.zuul.yaml index 1a8bf5d64..6a2904979 100644 --- a/tests/fixtures/config/inventory/git/org_project/.zuul.yaml +++ b/tests/fixtures/config/inventory/git/org_project/.zuul.yaml @@ -3,5 +3,6 @@ check: jobs: - single-inventory + - single-inventory-list - group-inventory - hostvars-inventory diff --git a/tests/unit/test_inventory.py b/tests/unit/test_inventory.py index 04dcb051b..1c41f5fa5 100644 --- a/tests/unit/test_inventory.py +++ b/tests/unit/test_inventory.py @@ -57,6 +57,26 @@ class TestInventory(ZuulTestCase): self.executor_server.release() self.waitUntilSettled() + def test_single_inventory_list(self): + + inventory = self._get_build_inventory('single-inventory-list') + + all_nodes = ('compute', 'controller') + self.assertIn('all', inventory) + self.assertIn('hosts', inventory['all']) + self.assertIn('vars', inventory['all']) + for node_name in all_nodes: + self.assertIn(node_name, inventory['all']['hosts']) + self.assertIn('zuul', inventory['all']['vars']) + z_vars = inventory['all']['vars']['zuul'] + self.assertIn('executor', z_vars) + self.assertIn('src_root', z_vars['executor']) + self.assertIn('job', z_vars) + self.assertEqual(z_vars['job'], 'single-inventory-list') + + self.executor_server.release() + self.waitUntilSettled() + def test_group_inventory(self): inventory = self._get_build_inventory('group-inventory') diff --git a/tests/unit/test_nodepool.py b/tests/unit/test_nodepool.py index d3f9ddbd7..aa0f08262 100644 --- a/tests/unit/test_nodepool.py +++ b/tests/unit/test_nodepool.py @@ -67,8 +67,8 @@ class TestNodepool(BaseTestCase): # Test a simple node request nodeset = model.NodeSet() - nodeset.addNode(model.Node('controller', 'ubuntu-xenial')) - nodeset.addNode(model.Node('compute', 'ubuntu-xenial')) + nodeset.addNode(model.Node(['controller', 'foo'], 'ubuntu-xenial')) + nodeset.addNode(model.Node(['compute'], 'ubuntu-xenial')) job = model.Job('testjob') job.nodeset = nodeset request = self.nodepool.requestNodes(None, job) @@ -99,8 +99,8 @@ class TestNodepool(BaseTestCase): # Test that node requests are re-submitted after disconnect nodeset = model.NodeSet() - nodeset.addNode(model.Node('controller', 'ubuntu-xenial')) - nodeset.addNode(model.Node('compute', 'ubuntu-xenial')) + nodeset.addNode(model.Node(['controller'], 'ubuntu-xenial')) + nodeset.addNode(model.Node(['compute'], 'ubuntu-xenial')) job = model.Job('testjob') job.nodeset = nodeset self.fake_nodepool.paused = True @@ -116,8 +116,8 @@ class TestNodepool(BaseTestCase): # Test that node requests can be canceled nodeset = model.NodeSet() - nodeset.addNode(model.Node('controller', 'ubuntu-xenial')) - nodeset.addNode(model.Node('compute', 'ubuntu-xenial')) + nodeset.addNode(model.Node(['controller'], 'ubuntu-xenial')) + nodeset.addNode(model.Node(['compute'], 'ubuntu-xenial')) job = model.Job('testjob') job.nodeset = nodeset self.fake_nodepool.paused = True @@ -131,8 +131,8 @@ class TestNodepool(BaseTestCase): # Test that a resubmitted request would not lock nodes nodeset = model.NodeSet() - nodeset.addNode(model.Node('controller', 'ubuntu-xenial')) - nodeset.addNode(model.Node('compute', 'ubuntu-xenial')) + nodeset.addNode(model.Node(['controller'], 'ubuntu-xenial')) + nodeset.addNode(model.Node(['compute'], 'ubuntu-xenial')) job = model.Job('testjob') job.nodeset = nodeset request = self.nodepool.requestNodes(None, job) @@ -152,8 +152,8 @@ class TestNodepool(BaseTestCase): # Test that a lost request would not lock nodes nodeset = model.NodeSet() - nodeset.addNode(model.Node('controller', 'ubuntu-xenial')) - nodeset.addNode(model.Node('compute', 'ubuntu-xenial')) + nodeset.addNode(model.Node(['controller'], 'ubuntu-xenial')) + nodeset.addNode(model.Node(['compute'], 'ubuntu-xenial')) job = model.Job('testjob') job.nodeset = nodeset request = self.nodepool.requestNodes(None, job) diff --git a/zuul/configloader.py b/zuul/configloader.py index bcb3e49ec..fb1695c18 100644 --- a/zuul/configloader.py +++ b/zuul/configloader.py @@ -340,7 +340,7 @@ class PragmaParser(object): class NodeSetParser(object): @staticmethod def getSchema(anonymous=False): - node = {vs.Required('name'): str, + node = {vs.Required('name'): to_list(str), vs.Required('label'): str, } @@ -365,11 +365,13 @@ class NodeSetParser(object): node_names = set() group_names = set() for conf_node in as_list(conf['nodes']): - if conf_node['name'] in node_names: - raise DuplicateNodeError(conf['name'], conf_node['name']) - node = model.Node(conf_node['name'], conf_node['label']) + for name in as_list(conf_node['name']): + if name in node_names: + raise DuplicateNodeError(name, conf_node['name']) + node = model.Node(as_list(conf_node['name']), conf_node['label']) ns.addNode(node) - node_names.add(conf_node['name']) + for name in as_list(conf_node['name']): + node_names.add(name) for conf_group in as_list(conf.get('groups', [])): for node_name in as_list(conf_group['nodes']): if node_name not in node_names: diff --git a/zuul/executor/server.py b/zuul/executor/server.py index 696920111..83fdc3ce0 100644 --- a/zuul/executor/server.py +++ b/zuul/executor/server.py @@ -497,7 +497,8 @@ def make_inventory_dict(nodes, groups, all_vars): hosts = {} for node in nodes: - hosts[node['name']] = node['host_vars'] + for name in node['name']: + hosts[name] = node['host_vars'] inventory = { 'all': { diff --git a/zuul/model.py b/zuul/model.py index f3f358be2..3b49591bc 100644 --- a/zuul/model.py +++ b/zuul/model.py @@ -498,9 +498,10 @@ class NodeSet(object): return n def addNode(self, node): - if node.name in self.nodes: - raise Exception("Duplicate node in %s" % (self,)) - self.nodes[node.name] = node + for name in node.name: + if name in self.nodes: + raise Exception("Duplicate node in %s" % (self,)) + self.nodes[tuple(node.name)] = node def getNodes(self): return list(self.nodes.values()) |