Merge "executor: add support for custom ansible_port" into feature/zuulv3

This commit is contained in:
Jenkins 2017-07-11 03:04:15 +00:00 committed by Gerrit Code Review
commit 26b1e68a3c
4 changed files with 35 additions and 1 deletions

27
tests/unit/test_executor.py Normal file → Executable file
View File

@ -18,6 +18,9 @@
import logging
import time
import zuul.executor.server
import zuul.model
from tests.base import ZuulTestCase, simple_layout
@ -305,3 +308,27 @@ class TestExecutorRepos(ZuulTestCase):
]
self.assertBuildStates(states, projects)
class TestAnsibleJob(ZuulTestCase):
tenant_config_file = 'config/ansible/main.yaml'
def setUp(self):
super(TestAnsibleJob, self).setUp()
job = zuul.model.Job('test')
job.unique = 'test'
self.test_job = zuul.executor.server.AnsibleJob(self.executor_server,
job)
def test_getHostList_host_keys(self):
# Test without ssh_port set
node = {'name': 'fake-host',
'host_keys': ['fake-host-key'],
'interface_ip': 'localhost'}
keys = self.test_job.getHostList({'nodes': [node]})[0]['host_keys']
self.assertEqual(keys[0], 'localhost fake-host-key')
# Test with custom ssh_port set
node['ssh_port'] = 22022
keys = self.test_job.getHostList({'nodes': [node]})[0]['host_keys']
self.assertEqual(keys[0], '[localhost]:22022 fake-host-key')

View File

@ -284,6 +284,7 @@ class ExecutorClient(object):
host_keys=node.host_keys,
provider=node.provider,
region=node.region,
ssh_port=node.ssh_port,
interface_ip=node.interface_ip,
public_ipv6=node.public_ipv6,
public_ipv4=node.public_ipv4))

View File

@ -936,9 +936,11 @@ class AnsibleJob(object):
# results in the wrong thing being in interface_ip
# TODO(jeblair): Move this notice to the docs.
ip = node.get('interface_ip')
port = node.get('ssh_port', 22)
host_vars = dict(
ansible_host=ip,
ansible_user=self.executor_server.default_username,
ansible_port=port,
nodepool=dict(
az=node.get('az'),
provider=node.get('provider'),
@ -946,7 +948,10 @@ class AnsibleJob(object):
host_keys = []
for key in node.get('host_keys'):
host_keys.append("%s %s" % (ip, key))
if port != 22:
host_keys.append("[%s]:%s %s" % (ip, port, key))
else:
host_keys.append("%s %s" % (ip, key))
hosts.append(dict(
name=node['name'],

View File

@ -361,6 +361,7 @@ class Node(object):
self.public_ipv4 = None
self.private_ipv4 = None
self.public_ipv6 = None
self.ssh_port = 22
self._keys = []
self.az = None
self.provider = None