Example #1
0
def run_test(name, template_path, json_path, match_path):
    template_path = os.path.join(TEMPLATE_PATH, template_path)
    json_path = os.path.join(DATA_PATH, json_path)
    cfggen = os.path.abspath("../sonic-config-engine/sonic-cfggen")
    command = [
        '/usr/bin/python2.7', cfggen, "-T", TEMPLATE_PATH, "-t", template_path,
        "-y", json_path
    ]
    p = subprocess.Popen(command,
                         shell=False,
                         stdout=subprocess.PIPE,
                         stderr=subprocess.PIPE,
                         env={"PYTHONPATH": "."})
    stdout, stderr = p.communicate()
    assert p.returncode == 0, "sonic-cfggen for %s test returned %d code. stderr='%s'" % (
        name, p.returncode, stderr)
    raw_generated_result = stdout.decode("ascii")
    assert "None" not in raw_generated_result, "Test %s" % name
    canonical_generated_result = ConfigMgr.to_canonical(raw_generated_result)
    match_path = os.path.join(DATA_PATH, match_path)
    # only for development write_result(match_path, raw_generated_result)
    with open(match_path) as result_fp:
        raw_saved_result = result_fp.read()
    canonical_saved_result = ConfigMgr.to_canonical(raw_saved_result)
    assert canonical_saved_result == canonical_generated_result, "Test %s" % name
def run_tests(test_name, template_fname, tests):
    tf = TemplateFabric(TEMPLATE_PATH)
    template = tf.from_file(template_fname)
    for case_name, param_fname, result_fname in tests:
        params = load_json(param_fname)
        raw_generated_result = str(template.render(params))
        assert "None" not in raw_generated_result, "Test %s.%s" % (test_name,
                                                                   case_name)
        # this is used only for initial generation write_result(result_fname, raw_generated_result)
        canonical_generated_result = ConfigMgr.to_canonical(
            raw_generated_result)
        with open(result_fname) as result_fp:
            raw_saved_result = result_fp.read()
        canonical_saved_result = ConfigMgr.to_canonical(raw_saved_result)
        assert canonical_saved_result == canonical_generated_result, "Test %s.%s" % (
            test_name, case_name)
Example #3
0
def to_canonical_common(raw_text, expected_canonical):
    frr = MagicMock()
    c = ConfigMgr(frr)
    assert c.to_canonical(raw_text) == expected_canonical