Create nodepool inventory variables

Because we want jobs to know something about the provider they are
running on, expose nodepool variables in the inventory file.

Change-Id: I18c8b414b1bbb114d55d21c5ae77d6348b3e9080
Signed-off-by: Paul Belanger <pabelanger@redhat.com>
diff --git a/tests/base.py b/tests/base.py
index a2a70c2..2729233 100755
--- a/tests/base.py
+++ b/tests/base.py
@@ -981,7 +981,7 @@
         data = dict(type=node_type,
                     provider='test-provider',
                     region='test-region',
-                    az=None,
+                    az='test-az',
                     public_ipv4='127.0.0.1',
                     private_ipv4=None,
                     public_ipv6=None,
diff --git a/tests/fixtures/config/ansible/git/common-config/playbooks/nodepool.yaml b/tests/fixtures/config/ansible/git/common-config/playbooks/nodepool.yaml
new file mode 100644
index 0000000..9970dd7
--- /dev/null
+++ b/tests/fixtures/config/ansible/git/common-config/playbooks/nodepool.yaml
@@ -0,0 +1,8 @@
+- hosts: ubuntu-xenial
+  tasks:
+    - name: Assert nodepool variables are valid.
+      assert:
+        that:
+          - nodepool_az == 'test-az'
+          - nodepool_region == 'test-region'
+          - nodepool_provider == 'test-provider'
diff --git a/tests/fixtures/config/ansible/git/common-config/zuul.yaml b/tests/fixtures/config/ansible/git/common-config/zuul.yaml
index 30148f0..aa70054 100644
--- a/tests/fixtures/config/ansible/git/common-config/zuul.yaml
+++ b/tests/fixtures/config/ansible/git/common-config/zuul.yaml
@@ -49,3 +49,10 @@
     parent: python27
     name: timeout
     timeout: 1
+
+- job:
+    parent: python27
+    name: nodepool
+    nodes:
+      - name: ubuntu-xenial
+        image: ubuntu-xenial
diff --git a/tests/fixtures/config/ansible/git/org_project/.zuul.yaml b/tests/fixtures/config/ansible/git/org_project/.zuul.yaml
index c76ba70..b38f88e 100644
--- a/tests/fixtures/config/ansible/git/org_project/.zuul.yaml
+++ b/tests/fixtures/config/ansible/git/org_project/.zuul.yaml
@@ -9,4 +9,5 @@
       jobs:
         - python27
         - faillocal
+        - nodepool
         - timeout
diff --git a/tests/unit/test_v3.py b/tests/unit/test_v3.py
index 3d83ea5..5c0679d 100644
--- a/tests/unit/test_v3.py
+++ b/tests/unit/test_v3.py
@@ -266,6 +266,8 @@
         self.assertEqual(build.result, 'ABORTED')
         build = self.getJobFromHistory('faillocal')
         self.assertEqual(build.result, 'FAILURE')
+        build = self.getJobFromHistory('nodepool')
+        self.assertEqual(build.result, 'SUCCESS')
         build = self.getJobFromHistory('python27')
         self.assertEqual(build.result, 'SUCCESS')
         flag_path = os.path.join(self.test_root, build.uuid + '.flag')
diff --git a/zuul/executor/client.py b/zuul/executor/client.py
index aa32517..31646f8 100644
--- a/zuul/executor/client.py
+++ b/zuul/executor/client.py
@@ -311,6 +311,9 @@
         nodes = []
         for node in item.current_build_set.getJobNodeSet(job.name).getNodes():
             nodes.append(dict(name=node.name, image=node.image,
+                              az=node.az,
+                              provider=node.provider,
+                              region=node.region,
                               public_ipv6=node.public_ipv6,
                               public_ipv4=node.public_ipv4))
         params['nodes'] = nodes
diff --git a/zuul/executor/server.py b/zuul/executor/server.py
index 3995b1a..d0741bb 100644
--- a/zuul/executor/server.py
+++ b/zuul/executor/server.py
@@ -641,7 +641,11 @@
             ip = node.get('public_ipv4')
             if not ip:
                 ip = node.get('public_ipv6')
-            hosts.append((node['name'], dict(ansible_host=ip)))
+            hosts.append((node['name'], dict(
+                ansible_host=ip,
+                nodepool_az=node.get('az'),
+                nodepool_provider=node.get('provider'),
+                nodepool_region=node.get('region'))))
         return hosts
 
     def _blockPluginDirs(self, path):
@@ -805,9 +809,8 @@
         with open(self.jobdir.inventory, 'w') as inventory:
             for host_name, host_vars in self.getHostList(args):
                 inventory.write(host_name)
-                inventory.write(' ')
                 for k, v in host_vars.items():
-                    inventory.write('%s=%s' % (k, v))
+                    inventory.write(' %s=%s' % (k, v))
                 inventory.write('\n')
                 if 'ansible_host' in host_vars:
                     os.system("ssh-keyscan %s >> %s" % (
diff --git a/zuul/model.py b/zuul/model.py
index 136a830..b57eef8 100644
--- a/zuul/model.py
+++ b/zuul/model.py
@@ -375,6 +375,9 @@
         self.private_ipv4 = None
         self.public_ipv6 = None
         self._keys = []
+        self.az = None
+        self.provider = None
+        self.region = None
 
     @property
     def state(self):