[libvirt] [PATCH 0/6] lxc: Add suport to network indexes for LXC 3.X.

This series implement support for network syntax settings for LXC 3.X. Now, indexes are part of the settings to define network interfaces. Each interface has its own index. The old style uses 'type' tag to differentiate each interface. Old: lxc.network.type = veth lxc.network.flags = up lxc.network.link = virbr0 New: lxc.net.0.type = veth lxc.net.0.flags = up lxc.net.0.link = virbr0 Julio Faracco (6): lxc: Rebase lxcNetworkParseData struct to support indexes. lxc: Rebase lxcNetworkParseData pointers to use new structures. lxc: Introduce lxcNetworkGetParseDataLegacy() method. lxc: Introduce lxcNetworkGetParseData() for 'lxc.net.' entry. tests: Change network settings of V3 testcase set. tests: Introduce random network settings to test indexes. src/lxc/lxc_native.c | 192 ++++++++++++------ .../lxcconf2xml-ethernet-v3.config | 16 +- .../lxcconf2xml-fstab-v3.config | 10 +- .../lxcconf2xml-macvlannetwork-v3.config | 10 +- .../lxcconf2xml-miscnetwork-v3.config | 38 ++-- .../lxcconf2xml-nonenetwork-v3.config | 2 +- .../lxcconf2xml-physnetwork-v3.config | 14 +- .../lxcconf2xml-randomnetwork-v3.config | 21 ++ .../lxcconf2xml-randomnetwork.xml | 45 ++++ .../lxcconf2xml-simple-v3.config | 18 +- .../lxcconf2xmldata/lxcconf2xml-simple.config | 18 +- .../lxcconf2xml-vlannetwork-v3.config | 10 +- tests/lxcconf2xmltest.c | 1 + 13 files changed, 268 insertions(+), 127 deletions(-) create mode 100644 tests/lxcconf2xmldata/lxcconf2xml-randomnetwork-v3.config create mode 100644 tests/lxcconf2xmldata/lxcconf2xml-randomnetwork.xml -- 2.19.1

The current logic of lxcNetworkParseData uses one single structure to record data over the network definitions inside config files. The logic consider the entry 'type' as a new network definition, every time that algorithm find this tag. This new structure was designed to consider network definitions as an array of network structures. Signed-off-by: Julio Faracco <jcfaracco@gmail.com> --- src/lxc/lxc_native.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index 2fd349ac1d..bf82cd1e98 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -423,8 +423,9 @@ lxcCreateHostdevDef(int mode, int type, const char *data) return hostdev; } -typedef struct { - virDomainDefPtr def; +typedef struct _lxcNetworkParseData lxcNetworkParseData; +typedef lxcNetworkParseData *lxcNetworkParseDataPtr; +struct _lxcNetworkParseData { char *type; char *link; char *mac; @@ -436,9 +437,14 @@ typedef struct { size_t nips; char *gateway_ipv4; char *gateway_ipv6; - bool privnet; - size_t networks; -} lxcNetworkParseData; + size_t index; +}; + +typedef struct { + lxcNetworkParseDataPtr *data; + size_t nnetworks; +} lxcNetworkParseArray; + static int lxcAddNetworkRouteDefinition(const char *address, -- 2.19.1

This commit refactor the code logic to introduce new array structures instead of single lxcNetworkParseData struct. Signed-off-by: Julio Faracco <jcfaracco@gmail.com> --- src/lxc/lxc_native.c | 94 +++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 62 deletions(-) diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index bf82cd1e98..7200743da7 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -484,7 +484,7 @@ lxcAddNetworkRouteDefinition(const char *address, } static int -lxcAddNetworkDefinition(lxcNetworkParseData *data) +lxcAddNetworkDefinition(virDomainDefPtr def, lxcNetworkParseDataPtr data) { virDomainNetDefPtr net = NULL; virDomainHostdevDefPtr hostdev = NULL; @@ -532,9 +532,9 @@ lxcAddNetworkDefinition(lxcNetworkParseData *data) &hostdev->source.caps.u.net.ip.nroutes) < 0) goto error; - if (VIR_EXPAND_N(data->def->hostdevs, data->def->nhostdevs, 1) < 0) + if (VIR_EXPAND_N(def->hostdevs, def->nhostdevs, 1) < 0) goto error; - data->def->hostdevs[data->def->nhostdevs - 1] = hostdev; + def->hostdevs[def->nhostdevs - 1] = hostdev; } else { if (!(net = lxcCreateNetDef(data->type, data->link, data->mac, data->flag, data->macvlanmode, @@ -556,9 +556,9 @@ lxcAddNetworkDefinition(lxcNetworkParseData *data) &net->guestIP.nroutes) < 0) goto error; - if (VIR_EXPAND_N(data->def->nets, data->def->nnets, 1) < 0) + if (VIR_EXPAND_N(def->nets, def->nnets, 1) < 0) goto error; - data->def->nets[data->def->nnets - 1] = net; + def->nets[def->nnets - 1] = net; } return 1; @@ -572,44 +572,10 @@ lxcAddNetworkDefinition(lxcNetworkParseData *data) return -1; } - -static int -lxcNetworkParseDataType(virConfValuePtr value, - lxcNetworkParseData *parseData) -{ - virDomainDefPtr def = parseData->def; - size_t networks = parseData->networks; - bool privnet = parseData->privnet; - int status; - - /* Store the previous NIC */ - status = lxcAddNetworkDefinition(parseData); - - if (status < 0) - return -1; - else if (status > 0) - networks++; - else if (parseData->type != NULL && STREQ(parseData->type, "none")) - privnet = false; - - /* clean NIC to store a new one */ - memset(parseData, 0, sizeof(*parseData)); - - parseData->def = def; - parseData->networks = networks; - parseData->privnet = privnet; - - /* Keep the new value */ - parseData->type = value->str; - - return 0; -} - - static int lxcNetworkParseDataIPs(const char *name, virConfValuePtr value, - lxcNetworkParseData *parseData) + lxcNetworkParseDataPtr parseData) { int family = AF_INET; char **ipparts = NULL; @@ -648,14 +614,13 @@ lxcNetworkParseDataIPs(const char *name, static int lxcNetworkParseDataSuffix(const char *entry, virConfValuePtr value, - lxcNetworkParseData *parseData) + lxcNetworkParseDataPtr parseData) { int elem = virLXCNetworkConfigEntryTypeFromString(entry); switch (elem) { case VIR_LXC_NETWORK_CONFIG_TYPE: - if (lxcNetworkParseDataType(value, parseData) < 0) - return -1; + parseData->type = value->str; break; case VIR_LXC_NETWORK_CONFIG_LINK: parseData->link = value->str; @@ -700,7 +665,7 @@ lxcNetworkParseDataSuffix(const char *entry, static int lxcNetworkParseDataEntry(const char *name, virConfValuePtr value, - lxcNetworkParseData *parseData) + lxcNetworkParseDataPtr parseData) { const char *suffix = STRSKIP(name, "lxc.network."); @@ -711,7 +676,8 @@ lxcNetworkParseDataEntry(const char *name, static int lxcNetworkWalkCallback(const char *name, virConfValuePtr value, void *data) { - lxcNetworkParseData *parseData = data; + lxcNetworkParseArray *networks = data; + lxcNetworkParseDataPtr parseData = NULL; if (STRPREFIX(name, "lxc.network.")) return lxcNetworkParseDataEntry(name, value, parseData); @@ -724,26 +690,26 @@ lxcConvertNetworkSettings(virDomainDefPtr def, virConfPtr properties) { int status; int result = -1; - size_t i; - lxcNetworkParseData data = {def, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, 0, - NULL, NULL, true, 0}; + size_t i, j; + bool privnet = true; + lxcNetworkParseArray nets = {NULL, 0}; - if (virConfWalk(properties, lxcNetworkWalkCallback, &data) < 0) + if (virConfWalk(properties, lxcNetworkWalkCallback, &nets) < 0) goto error; + for (i = 0; i < nets.nnetworks; i++) { + lxcNetworkParseDataPtr data = nets.data[i]; - /* Add the last network definition found */ - status = lxcAddNetworkDefinition(&data); + /* Add network definitions */ + status = lxcAddNetworkDefinition(def, data); - if (status < 0) - goto error; - else if (status > 0) - data.networks++; - else if (data.type != NULL && STREQ(data.type, "none")) - data.privnet = false; + if (status < 0) + goto error; + else if (data->type != NULL && STREQ(data->type, "none")) + privnet = false; + } - if (data.networks == 0 && data.privnet) { + if (nets.nnetworks == 0 && privnet) { /* When no network type is provided LXC only adds loopback */ def->features[VIR_DOMAIN_FEATURE_PRIVNET] = VIR_TRISTATE_SWITCH_ON; } @@ -752,9 +718,13 @@ lxcConvertNetworkSettings(virDomainDefPtr def, virConfPtr properties) return result; error: - for (i = 0; i < data.nips; i++) - VIR_FREE(data.ips[i]); - VIR_FREE(data.ips); + for (i = 0; i < nets.nnetworks; i++) { + for (j = 0; i < nets.data[i]->nips; i++) + VIR_FREE(nets.data[i]->ips[j]); + VIR_FREE(nets.data[i]->ips); + } + for (i = 0; i < nets.nnetworks; i++) + VIR_FREE(nets.data[i]); return -1; } -- 2.19.1

This function was introduced to fetch/alloc new data for legacy entries inside config file: 'lxc.network.foo'. Libvirt still need to support both versions. So, this function can be easy to remove in the future. Signed-off-by: Julio Faracco <jcfaracco@gmail.com> --- src/lxc/lxc_native.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index 7200743da7..4d26d1a20b 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -572,6 +572,37 @@ lxcAddNetworkDefinition(virDomainDefPtr def, lxcNetworkParseDataPtr data) return -1; } +static lxcNetworkParseDataPtr +lxcNetworkGetParseDataLegacy(lxcNetworkParseArray *networks, + const char *name) +{ + const char *suffix = STRSKIP(name, "lxc.network."); + int elem = virLXCNetworkConfigEntryTypeFromString(suffix); + size_t index = networks->nnetworks; + + if (elem == VIR_LXC_NETWORK_CONFIG_TYPE) { + if (!networks->data) { + if (VIR_ALLOC_N(networks->data, index + 1) < 0) + return NULL; + } else { + if (VIR_REALLOC_N(networks->data, index + 1) < 0) + return NULL; + } + + if (VIR_ALLOC(networks->data[index]) < 0) + return NULL; + + networks->data[index]->index = index; + networks->nnetworks++; + + /* Return a new network. */ + return networks->data[index]; + } + + /* Return the last network. */ + return networks->data[index-1]; +} + static int lxcNetworkParseDataIPs(const char *name, virConfValuePtr value, @@ -679,8 +710,12 @@ lxcNetworkWalkCallback(const char *name, virConfValuePtr value, void *data) lxcNetworkParseArray *networks = data; lxcNetworkParseDataPtr parseData = NULL; - if (STRPREFIX(name, "lxc.network.")) + if (STRPREFIX(name, "lxc.network.")) { + if (!(parseData = lxcNetworkGetParseDataLegacy(networks, name))) + return -1; + return lxcNetworkParseDataEntry(name, value, parseData); + } return 0; } -- 2.19.1

This commit moves old lxcNetworkGetParseData() to lxcNetworkGetParseDataLegacy() and create a new method for LXC version 3.X called lxcNetworkGetParseData(). This is same idea of method lxcNetworkGetParseDataLegacy(). In the future, it can be easy to remove or rebase, in case of deprecate 'lxc.network.foo' style. Signed-off-by: Julio Faracco <jcfaracco@gmail.com> --- src/lxc/lxc_native.c | 65 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index 4d26d1a20b..de7145ef1b 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -603,6 +603,53 @@ lxcNetworkGetParseDataLegacy(lxcNetworkParseArray *networks, return networks->data[index-1]; } +static lxcNetworkParseDataPtr +lxcNetworkGetParseData(lxcNetworkParseArray *networks, + const char *name) +{ + size_t index, nnetworks = networks->nnetworks; + size_t i; + + sscanf(name, "lxc.net.%zu", &index); + + if (!nnetworks) { + if (VIR_ALLOC_N(networks->data, 1) < 0) + return NULL; + + if (VIR_ALLOC(networks->data[0]) < 0) + return NULL; + + networks->data[0]->index = index; + networks->nnetworks++; + + return networks->data[0]; + } + + for (i = 0; i < nnetworks; i++) { + if (networks->data[i]->index == index) + return networks->data[i]; + } + + /* This is a new element in an existing array. */ + if (VIR_REALLOC_N(networks->data, nnetworks + 1) < 0) + return NULL; + + if (VIR_ALLOC(networks->data[nnetworks]) < 0) + return NULL; + + networks->nnetworks++; + + for (i = nnetworks; i > 0; i--) { + if (networks->data[i-1]->index < index) { + networks->data[i]->index = index; + return networks->data[i]; + } + memcpy(networks->data[i], networks->data[i-1], sizeof(lxcNetworkParseData)); + } + + return NULL; +} + static int lxcNetworkParseDataIPs(const char *name, virConfValuePtr value, @@ -692,14 +739,25 @@ lxcNetworkParseDataSuffix(const char *entry, return 0; } +static int +lxcNetworkParseDataEntryLegacy(const char *name, + virConfValuePtr value, + lxcNetworkParseData *parseData) +{ + const char *suffix = STRSKIP(name, "lxc.network."); + + return lxcNetworkParseDataSuffix(suffix, value, parseData); +} static int lxcNetworkParseDataEntry(const char *name, virConfValuePtr value, lxcNetworkParseDataPtr parseData) { - const char *suffix = STRSKIP(name, "lxc.network."); + const char *suffix = STRSKIP(name, "lxc.net."); + suffix = strchr(suffix, '.'); + suffix = STRSKIP(suffix, "."); return lxcNetworkParseDataSuffix(suffix, value, parseData); } @@ -714,6 +772,11 @@ lxcNetworkWalkCallback(const char *name, virConfValuePtr value, void *data) if (!(parseData = lxcNetworkGetParseDataLegacy(networks, name))) return -1; + return lxcNetworkParseDataEntryLegacy(name, value, parseData); + } else if (STRPREFIX(name, "lxc.net.")) { + if (!(parseData = lxcNetworkGetParseData(networks, name))) + return -1; + return lxcNetworkParseDataEntry(name, value, parseData); } -- 2.19.1

Now, it is time to use the new pattern for LXC 3.X inside config test cases. In the past, we kept the old style to keep all functionalities. Now, it is possible to use indexes properly. Signed-off-by: Julio Faracco <jcfaracco@gmail.com> --- .../lxcconf2xml-ethernet-v3.config | 16 ++++---- .../lxcconf2xml-fstab-v3.config | 10 ++--- .../lxcconf2xml-macvlannetwork-v3.config | 10 ++--- .../lxcconf2xml-miscnetwork-v3.config | 38 +++++++++---------- .../lxcconf2xml-nonenetwork-v3.config | 2 +- .../lxcconf2xml-physnetwork-v3.config | 14 +++---- .../lxcconf2xml-simple-v3.config | 18 ++++----- .../lxcconf2xmldata/lxcconf2xml-simple.config | 18 ++++----- .../lxcconf2xml-vlannetwork-v3.config | 10 ++--- 9 files changed, 68 insertions(+), 68 deletions(-) diff --git a/tests/lxcconf2xmldata/lxcconf2xml-ethernet-v3.config b/tests/lxcconf2xmldata/lxcconf2xml-ethernet-v3.config index 630cb2ebb6..0a641549f3 100644 --- a/tests/lxcconf2xmldata/lxcconf2xml-ethernet-v3.config +++ b/tests/lxcconf2xmldata/lxcconf2xml-ethernet-v3.config @@ -1,14 +1,14 @@ # Template used to create this container: opensuse # Template script checksum (SHA-1): 27307e0a95bd81b2c0bd82d6f87fdbe83be075ef -lxc.network.type = veth -lxc.network.flags = up -lxc.network.hwaddr = 02:00:15:8f:05:c1 -lxc.network.name = eth0 -lxc.network.ipv4 = 192.168.122.2/24 -lxc.network.ipv4.gateway = 192.168.122.1 -lxc.network.ipv6 = 2003:db8:1:0:214:1234:fe0b:3596/64 -lxc.network.ipv6.gateway = 2003:db8:1:0:214:1234:fe0b:3595 +lxc.net.0.type = veth +lxc.net.0.flags = up +lxc.net.0.hwaddr = 02:00:15:8f:05:c1 +lxc.net.0.name = eth0 +lxc.net.0.ipv4 = 192.168.122.2/24 +lxc.net.0.ipv4.gateway = 192.168.122.1 +lxc.net.0.ipv6 = 2003:db8:1:0:214:1234:fe0b:3596/64 +lxc.net.0.ipv6.gateway = 2003:db8:1:0:214:1234:fe0b:3595 #remove next line if host DNS configuration should not be available to container lxc.mount.entry = proc proc proc nodev,noexec,nosuid 0 0 diff --git a/tests/lxcconf2xmldata/lxcconf2xml-fstab-v3.config b/tests/lxcconf2xmldata/lxcconf2xml-fstab-v3.config index 8b62818657..315ad45ad1 100644 --- a/tests/lxcconf2xmldata/lxcconf2xml-fstab-v3.config +++ b/tests/lxcconf2xmldata/lxcconf2xml-fstab-v3.config @@ -1,11 +1,11 @@ # Template used to create this container: opensuse # Template script checksum (SHA-1): 27307e0a95bd81b2c0bd82d6f87fdbe83be075ef -lxc.network.type = veth -lxc.network.flags = up -lxc.network.link = virbr0 -lxc.network.hwaddr = 02:00:15:8f:05:c1 -lxc.network.name = eth0 +lxc.net.1.type = veth +lxc.net.1.flags = up +lxc.net.1.link = virbr0 +lxc.net.1.hwaddr = 02:00:15:8f:05:c1 +lxc.net.1.name = eth0 #remove next line if host DNS configuration should not be available to container lxc.mount.fstab = /var/lib/lxc/migrate_test/fstab diff --git a/tests/lxcconf2xmldata/lxcconf2xml-macvlannetwork-v3.config b/tests/lxcconf2xmldata/lxcconf2xml-macvlannetwork-v3.config index 631f07ecca..ab8d85361f 100644 --- a/tests/lxcconf2xmldata/lxcconf2xml-macvlannetwork-v3.config +++ b/tests/lxcconf2xmldata/lxcconf2xml-macvlannetwork-v3.config @@ -1,11 +1,11 @@ # Template used to create this container: opensuse # Template script checksum (SHA-1): 27307e0a95bd81b2c0bd82d6f87fdbe83be075ef -lxc.network.type = macvlan -lxc.network.flags = up -lxc.network.link = eth0 -lxc.network.hwaddr = 02:00:15:8f:05:c1 -lxc.network.macvlan.mode = vepa +lxc.net.0.type = macvlan +lxc.net.0.flags = up +lxc.net.0.link = eth0 +lxc.net.0.hwaddr = 02:00:15:8f:05:c1 +lxc.net.0.macvlan.mode = vepa #remove next line if host DNS configuration should not be available to container lxc.rootfs.path = /var/lib/lxc/migrate_test/rootfs diff --git a/tests/lxcconf2xmldata/lxcconf2xml-miscnetwork-v3.config b/tests/lxcconf2xmldata/lxcconf2xml-miscnetwork-v3.config index b46cb3ee7d..9be8cf95ea 100644 --- a/tests/lxcconf2xmldata/lxcconf2xml-miscnetwork-v3.config +++ b/tests/lxcconf2xmldata/lxcconf2xml-miscnetwork-v3.config @@ -1,23 +1,23 @@ -lxc.network.type = phys -lxc.network.link = eth0 -lxc.network.name = eth1 -lxc.network.ipv4 = 192.168.122.2/24 -lxc.network.ipv4.gateway = 192.168.122.1 -lxc.network.ipv6 = 2003:db8:1:0:214:1234:fe0b:3596/64 -lxc.network.ipv6.gateway = 2003:db8:1:0:214:1234:fe0b:3595 +lxc.net.0.type = phys +lxc.net.0.link = eth0 +lxc.net.0.name = eth1 +lxc.net.0.ipv4 = 192.168.122.2/24 +lxc.net.0.ipv4.gateway = 192.168.122.1 +lxc.net.0.ipv6 = 2003:db8:1:0:214:1234:fe0b:3596/64 +lxc.net.0.ipv6.gateway = 2003:db8:1:0:214:1234:fe0b:3595 -lxc.network.type = vlan -lxc.network.flags = up -lxc.network.link = eth0 -lxc.network.hwaddr = 02:00:15:8f:05:c1 -lxc.network.vlan.id = 2 +lxc.net.1.type = vlan +lxc.net.1.flags = up +lxc.net.1.link = eth0 +lxc.net.1.hwaddr = 02:00:15:8f:05:c1 +lxc.net.1.vlan.id = 2 -lxc.network.type = macvlan -lxc.network.flags = up -lxc.network.link = eth0 -lxc.network.hwaddr = 02:00:15:8f:05:c1 -lxc.network.macvlan.mode = vepa +lxc.net.2.type = macvlan +lxc.net.2.flags = up +lxc.net.2.link = eth0 +lxc.net.2.hwaddr = 02:00:15:8f:05:c1 +lxc.net.2.macvlan.mode = vepa -lxc.rootfs = /var/lib/lxc/migrate_test/rootfs -lxc.utsname = migrate_test +lxc.rootfs.path = /var/lib/lxc/migrate_test/rootfs +lxc.uts.name = migrate_test lxc.autodev=1 diff --git a/tests/lxcconf2xmldata/lxcconf2xml-nonenetwork-v3.config b/tests/lxcconf2xmldata/lxcconf2xml-nonenetwork-v3.config index f81a786f1e..2402723d9e 100644 --- a/tests/lxcconf2xmldata/lxcconf2xml-nonenetwork-v3.config +++ b/tests/lxcconf2xmldata/lxcconf2xml-nonenetwork-v3.config @@ -1,4 +1,4 @@ lxc.rootfs.path = /var/lib/lxc/migrate_test/rootfs lxc.uts.name = migrate_test lxc.autodev=1 -lxc.network.type = none +lxc.net.0.type = none diff --git a/tests/lxcconf2xmldata/lxcconf2xml-physnetwork-v3.config b/tests/lxcconf2xmldata/lxcconf2xml-physnetwork-v3.config index 92729841d7..23f9d78dbd 100644 --- a/tests/lxcconf2xmldata/lxcconf2xml-physnetwork-v3.config +++ b/tests/lxcconf2xmldata/lxcconf2xml-physnetwork-v3.config @@ -1,10 +1,10 @@ -lxc.network.type = phys -lxc.network.link = eth0 -lxc.network.name = eth1 -lxc.network.ipv4 = 192.168.122.2/24 -lxc.network.ipv4.gateway = 192.168.122.1 -lxc.network.ipv6 = 2003:db8:1:0:214:1234:fe0b:3596/64 -lxc.network.ipv6.gateway = 2003:db8:1:0:214:1234:fe0b:3595 +lxc.net.1.type = phys +lxc.net.1.link = eth0 +lxc.net.1.name = eth1 +lxc.net.1.ipv4 = 192.168.122.2/24 +lxc.net.1.ipv4.gateway = 192.168.122.1 +lxc.net.1.ipv6 = 2003:db8:1:0:214:1234:fe0b:3596/64 +lxc.net.1.ipv6.gateway = 2003:db8:1:0:214:1234:fe0b:3595 lxc.rootfs.path = /var/lib/lxc/migrate_test/rootfs lxc.uts.name = migrate_test diff --git a/tests/lxcconf2xmldata/lxcconf2xml-simple-v3.config b/tests/lxcconf2xmldata/lxcconf2xml-simple-v3.config index a0036a482e..b0656571b2 100644 --- a/tests/lxcconf2xmldata/lxcconf2xml-simple-v3.config +++ b/tests/lxcconf2xmldata/lxcconf2xml-simple-v3.config @@ -1,15 +1,15 @@ # Template used to create this container: opensuse # Template script checksum (SHA-1): 27307e0a95bd81b2c0bd82d6f87fdbe83be075ef -lxc.network.type = veth -lxc.network.flags = up -lxc.network.link = virbr0 -lxc.network.hwaddr = 02:00:15:8f:05:c1 -lxc.network.name = eth0 -lxc.network.ipv4 = 192.168.122.2/24 -lxc.network.ipv4.gateway = 192.168.122.1 -lxc.network.ipv6 = 2003:db8:1:0:214:1234:fe0b:3596/64 -lxc.network.ipv6.gateway = 2003:db8:1:0:214:1234:fe0b:3595 +lxc.net.0.type = veth +lxc.net.0.flags = up +lxc.net.0.link = virbr0 +lxc.net.0.hwaddr = 02:00:15:8f:05:c1 +lxc.net.0.name = eth0 +lxc.net.0.ipv4 = 192.168.122.2/24 +lxc.net.0.ipv4.gateway = 192.168.122.1 +lxc.net.0.ipv6 = 2003:db8:1:0:214:1234:fe0b:3596/64 +lxc.net.0.ipv6.gateway = 2003:db8:1:0:214:1234:fe0b:3595 #remove next line if host DNS configuration should not be available to container lxc.mount.entry = proc proc proc nodev,noexec,nosuid 0 0 diff --git a/tests/lxcconf2xmldata/lxcconf2xml-simple.config b/tests/lxcconf2xmldata/lxcconf2xml-simple.config index 50a44bba95..a8429e4657 100644 --- a/tests/lxcconf2xmldata/lxcconf2xml-simple.config +++ b/tests/lxcconf2xmldata/lxcconf2xml-simple.config @@ -1,15 +1,15 @@ # Template used to create this container: opensuse # Template script checksum (SHA-1): 27307e0a95bd81b2c0bd82d6f87fdbe83be075ef -lxc.network.type = veth -lxc.network.flags = up -lxc.network.link = virbr0 -lxc.network.hwaddr = 02:00:15:8f:05:c1 -lxc.network.name = eth0 -lxc.network.ipv4 = 192.168.122.2/24 -lxc.network.ipv4.gateway = 192.168.122.1 -lxc.network.ipv6 = 2003:db8:1:0:214:1234:fe0b:3596/64 -lxc.network.ipv6.gateway = 2003:db8:1:0:214:1234:fe0b:3595 +lxc.net.0.type = veth +lxc.net.0.flags = up +lxc.net.0.link = virbr0 +lxc.net.0.hwaddr = 02:00:15:8f:05:c1 +lxc.net.0.name = eth0 +lxc.net.0.ipv4 = 192.168.122.2/24 +lxc.net.0.ipv4.gateway = 192.168.122.1 +lxc.net.0.ipv6 = 2003:db8:1:0:214:1234:fe0b:3596/64 +lxc.net.0.ipv6.gateway = 2003:db8:1:0:214:1234:fe0b:3595 #remove next line if host DNS configuration should not be available to container lxc.mount.entry = proc proc proc nodev,noexec,nosuid 0 0 diff --git a/tests/lxcconf2xmldata/lxcconf2xml-vlannetwork-v3.config b/tests/lxcconf2xmldata/lxcconf2xml-vlannetwork-v3.config index 31e26997dd..fb4539261f 100644 --- a/tests/lxcconf2xmldata/lxcconf2xml-vlannetwork-v3.config +++ b/tests/lxcconf2xmldata/lxcconf2xml-vlannetwork-v3.config @@ -1,11 +1,11 @@ # Template used to create this container: opensuse # Template script checksum (SHA-1): 27307e0a95bd81b2c0bd82d6f87fdbe83be075ef -lxc.network.type = vlan -lxc.network.flags = up -lxc.network.link = eth0 -lxc.network.hwaddr = 02:00:15:8f:05:c1 -lxc.network.vlan.id = 2 +lxc.net.1.type = vlan +lxc.net.1.flags = up +lxc.net.1.link = eth0 +lxc.net.1.hwaddr = 02:00:15:8f:05:c1 +lxc.net.1.vlan.id = 2 lxc.rootfs.path = /var/lib/lxc/migrate_test/rootfs lxc.uts.name = migrate_test -- 2.19.1

This is the same test of miscnetwork. The XML output needs to be the same. It contains random networks entries separated by indexes and it needs to produce the order XML definition. Signed-off-by: Julio Faracco <jcfaracco@gmail.com> --- .../lxcconf2xml-randomnetwork-v3.config | 21 +++++++++ .../lxcconf2xml-randomnetwork.xml | 45 +++++++++++++++++++ tests/lxcconf2xmltest.c | 1 + 3 files changed, 67 insertions(+) create mode 100644 tests/lxcconf2xmldata/lxcconf2xml-randomnetwork-v3.config create mode 100644 tests/lxcconf2xmldata/lxcconf2xml-randomnetwork.xml diff --git a/tests/lxcconf2xmldata/lxcconf2xml-randomnetwork-v3.config b/tests/lxcconf2xmldata/lxcconf2xml-randomnetwork-v3.config new file mode 100644 index 0000000000..8d898fa6e0 --- /dev/null +++ b/tests/lxcconf2xmldata/lxcconf2xml-randomnetwork-v3.config @@ -0,0 +1,21 @@ +lxc.net.0.type = phys +lxc.net.1.flags = up +lxc.net.0.link = eth0 +lxc.net.2.link = eth0 +lxc.net.1.hwaddr = 02:00:15:8f:05:c1 +lxc.net.1.link = eth0 +lxc.net.0.name = eth1 +lxc.net.2.macvlan.mode = vepa +lxc.net.2.type = macvlan +lxc.net.1.type = vlan +lxc.net.0.ipv4 = 192.168.122.2/24 +lxc.net.0.ipv4.gateway = 192.168.122.1 +lxc.net.1.vlan.id = 2 +lxc.net.0.ipv6 = 2003:db8:1:0:214:1234:fe0b:3596/64 +lxc.net.2.flags = up +lxc.net.2.hwaddr = 02:00:15:8f:05:c1 +lxc.net.0.ipv6.gateway = 2003:db8:1:0:214:1234:fe0b:3595 + +lxc.rootfs.path = /var/lib/lxc/migrate_test/rootfs +lxc.uts.name = migrate_test +lxc.autodev=1 diff --git a/tests/lxcconf2xmldata/lxcconf2xml-randomnetwork.xml b/tests/lxcconf2xmldata/lxcconf2xml-randomnetwork.xml new file mode 100644 index 0000000000..63189cfaec --- /dev/null +++ b/tests/lxcconf2xmldata/lxcconf2xml-randomnetwork.xml @@ -0,0 +1,45 @@ +<domain type='lxc'> + <name>migrate_test</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>65536</memory> + <currentMemory unit='KiB'>65536</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type>exe</type> + <init>/sbin/init</init> + </os> + <features> + <capabilities policy='allow'> + </capabilities> + </features> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/libexec/libvirt_lxc</emulator> + <filesystem type='mount' accessmode='passthrough'> + <source dir='/var/lib/lxc/migrate_test/rootfs'/> + <target dir='/'/> + </filesystem> + <interface type='direct'> + <mac address='02:00:15:8f:05:c1'/> + <source dev='eth0' mode='vepa'/> + <link state='up'/> + </interface> + <hostdev mode='capabilities' type='net'> + <source> + <interface>eth0</interface> + </source> + <ip address='192.168.122.2' family='ipv4' prefix='24'/> + <ip address='2003:db8:1:0:214:1234:fe0b:3596' family='ipv6' prefix='64'/> + <route family='ipv4' address='0.0.0.0' gateway='192.168.122.1'/> + <route family='ipv6' address='::' gateway='2003:db8:1:0:214:1234:fe0b:3595'/> + </hostdev> + <hostdev mode='capabilities' type='net'> + <source> + <interface>eth0.2</interface> + </source> + </hostdev> + </devices> +</domain> diff --git a/tests/lxcconf2xmltest.c b/tests/lxcconf2xmltest.c index 2a277042ce..78927d29b1 100644 --- a/tests/lxcconf2xmltest.c +++ b/tests/lxcconf2xmltest.c @@ -163,6 +163,7 @@ mymain(void) DO_TEST3("macvlannetwork", false); DO_TEST3("vlannetwork", false); DO_TEST3("miscnetwork", false); + DO_TEST3("randomnetwork", false); DO_TEST3("idmap", false); DO_TEST3("memtune", false); DO_TEST3("cputune", false); -- 2.19.1
participants (1)
-
Julio Faracco