예제 #1
0
파일: test_config.py 프로젝트: opencord/xos
 def test_get_config_file(self):
     """
     [XOS-Config] Should return the config file in use
     """
     Config.init(sample_conf)
     res = Config.get_config_file()
     self.assertEqual(res, sample_conf)
예제 #2
0
 def test_get_config_file(self):
     """
     [XOS-Config] Should return the config file in use
     """
     Config.init(sample_conf)
     res = Config.get_config_file()
     self.assertEqual(res, sample_conf)
예제 #3
0
def run_playbook(ansible_hosts, ansible_config, fqp, opts):
    args = {"ansible_hosts": ansible_hosts,
            "ansible_config": ansible_config,
            "fqp": fqp,
            "opts": opts,
            "config_file": Config.get_config_file()}

    keep_temp_files = Config.get("keep_temp_files")

    dir = tempfile.mkdtemp()
    args_fn = None
    result_fn = None
    try:
        log.info("creating args file",dir = dir)

        args_fn = os.path.join(dir, "args")
        result_fn = os.path.join(dir, "result")

        open(args_fn, "w").write(pickle.dumps(args))

        ansible_main_fn = os.path.join(os.path.dirname(__file__), "ansible_main.py")

        os.system("python %s %s %s" % (ansible_main_fn, args_fn, result_fn))

        result = pickle.loads(open(result_fn).read())

        if hasattr(result, "exception"):
            log.error("Exception in playbook",exception = result["exception"])

        stats = result.get("stats", None)
        aresults = result.get("aresults", None)
    except Exception,e:
        log.exception("Exception running ansible_main")
        stats = None
        aresults = None
예제 #4
0
def run_playbook(ansible_hosts, ansible_config, fqp, opts):
    args = {
        "ansible_hosts": ansible_hosts,
        "ansible_config": ansible_config,
        "fqp": fqp,
        "opts": opts,
        "config_file": Config.get_config_file()
    }

    keep_temp_files = Config.get("keep_temp_files")

    dir = tempfile.mkdtemp()
    args_fn = None
    result_fn = None
    try:
        logger.info("creating args file in %s" % dir)

        args_fn = os.path.join(dir, "args")
        result_fn = os.path.join(dir, "result")

        open(args_fn, "w").write(pickle.dumps(args))

        ansible_main_fn = os.path.join(os.path.dirname(__file__),
                                       "ansible_main.py")

        os.system("python %s %s %s" % (ansible_main_fn, args_fn, result_fn))

        result = pickle.loads(open(result_fn).read())

        if hasattr(result, "exception"):
            logger.log_error("Exception in playbook: %s" % result["exception"])

        stats = result.get("stats", None)
        aresults = result.get("aresults", None)
    except:
        logger.log_exc("Exception running ansible_main")
        stats = None
        aresults = None
    finally:
        if not keep_temp_files:
            if args_fn and os.path.exists(args_fn):
                os.remove(args_fn)
            if result_fn and os.path.exists(result_fn):
                os.remove(result_fn)
            os.rmdir(dir)

    return (stats, aresults)
예제 #5
0
def run_playbook(ansible_hosts, ansible_config, fqp, opts):
    args = {
        "ansible_hosts": ansible_hosts,
        "ansible_config": ansible_config,
        "fqp": fqp,
        "opts": opts,
        "config_file": Config.get_config_file()
    }

    keep_temp_files = Config.get("keep_temp_files")

    dir = tempfile.mkdtemp()
    args_fn = None
    result_fn = None
    try:
        log.info("creating args file", dir=dir)

        args_fn = os.path.join(dir, "args")
        result_fn = os.path.join(dir, "result")

        open(args_fn, "w").write(pickle.dumps(args))

        ansible_main_fn = os.path.join(os.path.dirname(__file__),
                                       "ansible_main.py")

        os.system("python %s %s %s" % (ansible_main_fn, args_fn, result_fn))

        result = pickle.loads(open(result_fn).read())

        if hasattr(result, "exception"):
            log.error("Exception in playbook", exception=result["exception"])

        stats = result.get("stats", None)
        aresults = result.get("aresults", None)
    except Exception, e:
        log.exception("Exception running ansible_main")
        stats = None
        aresults = None