File: test_utils.h

package info (click to toggle)
netplan.io 1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 4,268 kB
  • sloc: python: 34,640; ansic: 14,096; xml: 4,989; javascript: 2,165; sh: 513; makefile: 118
file content (81 lines) | stat: -rw-r--r-- 1,916 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#pragma once

#include <stdio.h>

#include "types.h"
#include "netplan.h"
#include "parse.h"
#include "util.h"
#include "types-internal.h"

gboolean
process_document(NetplanParser*, GError**);
gboolean
load_yaml_from_fd(int, yaml_document_t*, GError**);
gboolean
load_yaml(const char*, yaml_document_t*, GError**);
const char*
normalize_ip_address(const char*, const guint);
char*
write_ovs_bond_interfaces(const NetplanState*, const NetplanNetDefinition*, GString*, GError**);
gboolean
validate_interface_name_length(const NetplanNetDefinition*);

// LCOV_EXCL_START
NetplanState *
load_fixture_to_netplan_state(const char* filename)
{

    g_autoptr(GError) error = NULL;
    g_autofree char* filepath = NULL;

    filepath = g_build_path(G_DIR_SEPARATOR_S, FIXTURESDIR, filename, NULL);

    NetplanParser *npp = netplan_parser_new();
    netplan_parser_load_yaml(npp, filepath, &error);

    NetplanState *np_state = netplan_state_new();
    netplan_state_import_parser_results(np_state, npp, &error);

    netplan_parser_clear(&npp);

    return np_state;
}

NetplanState*
load_string_to_netplan_state(const char* yaml)
{
    yaml_parser_t parser;
    yaml_document_t* doc;
    NetplanError** error = NULL;
    NetplanState* np_state = NULL;

    NetplanParser* npp = netplan_parser_new();

    doc = &npp->doc;

    yaml_parser_initialize(&parser);
    yaml_parser_set_input_string(&parser, (const unsigned char*) yaml, strlen(yaml));
    yaml_parser_load(&parser, doc);

    process_document(npp, error);

    if (error && *error) {
        netplan_error_clear(error);
    } else {
        np_state = netplan_state_new();
        netplan_state_import_parser_results(np_state, npp, error);
    }

    yaml_parser_delete(&parser);
    yaml_document_delete(doc);
    netplan_parser_clear(&npp);

    if (error && *error) {
        netplan_state_clear(&np_state);
    }

    return np_state;
}

// LCOV_EXCL_STOP