Merge "Allow ansible inventory to be configurable"
This commit is contained in:
commit
67e02ce57c
|
@ -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
|
||||
|
|
|
@ -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({
|
||||
|
|
Loading…
Reference in New Issue