Merge "Allow ansible inventory to be configurable"

This commit is contained in:
Jenkins 2016-12-06 02:52:58 +00:00 committed by Gerrit Code Review
commit 67e02ce57c
2 changed files with 37 additions and 1 deletions

View File

@ -23,6 +23,7 @@ WORKING_DIR = os.environ.get('HEAT_ANSIBLE_WORKING',
OUTPUTS_DIR = os.environ.get('HEAT_ANSIBLE_OUTPUTS',
'/var/run/heat-config/heat-config-ansible')
ANSIBLE_CMD = os.environ.get('HEAT_ANSIBLE_CMD', 'ansible-playbook')
ANSIBLE_INVENTORY = os.environ.get('HEAT_ANSIBLE_INVENTORY', 'localhost,')
def prepare_dir(path):
@ -71,7 +72,7 @@ def main(argv=sys.argv):
cmd = [
ANSIBLE_CMD,
'-i',
'localhost,',
ANSIBLE_INVENTORY,
fn,
'--extra-vars',
'@%s' % vars_filename

View File

@ -62,6 +62,7 @@ class HookAnsibleTest(common.RunScriptTest):
self.working_dir = self.useFixture(fixtures.TempDir())
self.outputs_dir = self.useFixture(fixtures.TempDir())
self.test_state_path = self.outputs_dir.join('test_state.json')
self.test_inventory = "localhost test_var=123,"
self.env = os.environ.copy()
self.env.update({
@ -122,6 +123,40 @@ class HookAnsibleTest(common.RunScriptTest):
with open(ansible_playbook) as f:
self.assertEqual('the ansible playbook', f.read())
def test_hook_inventory(self):
self.env.update({
'HEAT_ANSIBLE_INVENTORY': self.test_inventory,
'TEST_RESPONSE': json.dumps({
'stdout': 'ansible success',
'stderr': 'thing happened',
}),
})
returncode, stdout, stderr = self.run_cmd(
[self.hook_path], self.env, json.dumps(self.data))
self.assertEqual(0, returncode, stderr)
self.assertEqual({
'deploy_stdout': 'ansible success',
'deploy_stderr': 'thing happened',
'deploy_status_code': 0,
}, json.loads(stdout))
state = self.json_from_file(self.test_state_path)
ansible_playbook = self.working_dir.join('1234_playbook.yaml')
vars_filename = self.working_dir.join('1234_variables.json')
self.assertEqual(
[
self.fake_tool_path,
'-i',
self.test_inventory,
ansible_playbook,
'--extra-vars',
'@%s' % vars_filename
],
state['args'])
def test_hook_ansible_failed(self):
self.env.update({