Skip to content

Commit

Permalink
Merge pull request #60 from kushaldas/infojson
Browse files Browse the repository at this point in the history
Fixes #57, current_run_info.json file gets created
  • Loading branch information
kushaldas committed Jul 21, 2017
2 parents f49edb9 + 47422f0 commit 6b74c5e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
7 changes: 4 additions & 3 deletions tests.py
Expand Up @@ -138,9 +138,10 @@ def test_multihost(self, p_br, p_sc, p_kill, p_exit, p_sleep, p_system, p_usyste
with captured_output() as (out, err):
tunirmultihost.start_multihost('multihost', './testvalues/multihost.txt',
debug=False, config_dir='./testvalues/')

self.assertIn("Passed:1", out.getvalue())
self.assertIn("Job status: True", out.getvalue())
data = out.getvalue()
self.assertIn("Passed:1", data)
self.assertIn("Job status: True", data)
self.assertTrue(os.path.exists('./current_run_info.json'))


class ExecuteTests(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tunirlib/tunirmultihost.py
Expand Up @@ -258,6 +258,7 @@ def start_multihost(jobname: str, jobpath: str, debug: bool=False, oldconfig: Di
private_key, public_key = generate_sshkey()
create_user_data(seed_dir, "passw0rd")
create_ssh_metadata(seed_dir, public_key, private_key)
config.general["keypath"] = os.path.join(seed_dir, "private.pem")
create_seed_img(meta, seed_dir)
seed_image = os.path.join(seed_dir, 'seed.img')

Expand Down Expand Up @@ -329,7 +330,6 @@ def start_multihost(jobname: str, jobpath: str, debug: bool=False, oldconfig: Di
ansible_inventory_path = os.path.join(seed_dir, 'tunir_ansible')
create_ansible_inventory(config.vms, ansible_inventory_path)


# This is where we test
status = run_job(jobpath,job_name=jobname,config=config, ansible_path=seed_dir, extra_config=extra_config)
except Exception as e:
Expand Down
12 changes: 12 additions & 0 deletions tunirlib/tunirutils.py
@@ -1,6 +1,7 @@
import os
import re
import time
import json
import shutil
import paramiko
import socket
Expand Down Expand Up @@ -265,6 +266,16 @@ def update_result(result, command, negative):

return True

def write_ip_information(user: str, key: str, config: TunirConfig) -> None:
"""
Writes the vm information to a JSON file
"""
data = {"user": user, "keyfile": key}
for key in config.vms:
data[key] = config.vms[key]["ip"]
with open("./current_run_info.json", "w") as fobj:
json.dump(data, fobj)


def run_job(jobpath: str, job_name: str='', extra_config: Dict[str,str]={}, container=None,
port: str='22', config: TunirConfig = None, ansible_path: str='' ) -> bool:
Expand Down Expand Up @@ -303,6 +314,7 @@ def run_job(jobpath: str, job_name: str='', extra_config: Dict[str,str]={}, cont
else:
private_key_path = os.path.join(ansible_path, 'private.pem')

write_ip_information( config.vms["vm1"]["user"], config.general["keypath"], config)
with open(jobpath) as fobj:
commands = fobj.readlines()

Expand Down

0 comments on commit 6b74c5e

Please sign in to comment.