aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog11
-rw-r--r--src/xend_internal.c47
-rw-r--r--src/xml.c13
-rw-r--r--tests/sexpr2xmldata/sexpr2xml-net-bridged.sexpr2
-rw-r--r--tests/sexpr2xmldata/sexpr2xml-net-bridged.xml27
-rw-r--r--tests/sexpr2xmldata/sexpr2xml-net-routed.sexpr2
-rw-r--r--tests/sexpr2xmldata/sexpr2xml-net-routed.xml27
-rw-r--r--tests/sexpr2xmltest.c21
-rw-r--r--tests/xml2sexprdata/xml2sexpr-net-bridged.sexpr1
-rw-r--r--tests/xml2sexprdata/xml2sexpr-net-bridged.xml29
-rw-r--r--tests/xml2sexprdata/xml2sexpr-net-routed.sexpr1
-rw-r--r--tests/xml2sexprdata/xml2sexpr-net-routed.xml30
-rw-r--r--tests/xml2sexprtest.c22
13 files changed, 207 insertions, 26 deletions
diff --git a/ChangeLog b/ChangeLog
index 255d8f0f4..0084b239d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+Tue Nov 14 18:42:01 EST 2006 Daniel Berrange <berrange@redhat.com>
+
+ * src/xend_internal.c: Added support for parsing non-bridge style
+ networking configs for guests.
+ * src/xml.c: Ensure the <ip address> element gets serialized to
+ the SEXPR for non-bridged networks.
+ * tests/xml2sexprtest.c, tests/sexpr2xmltest.c: Added new tests
+ covering different networking configs
+ * tests/xml2sexprdata/, tests/sexpr2xmldata/: Added more data
+ files for new test cases
+
Mon Nov 13 17:18:00 CET 2006 Daniel Veillard <veillard@redhat.com>
* src/xend_internal.c src/xml.c: fix for shareable drive support
diff --git a/src/xend_internal.c b/src/xend_internal.c
index 990d8a055..5fb24c4f3 100644
--- a/src/xend_internal.c
+++ b/src/xend_internal.c
@@ -1700,38 +1700,35 @@ xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root, int xendConfigVersi
if (drvType)
free(drvType);
} else if (sexpr_lookup(node, "device/vif")) {
- const char *tmp2;
-
- tmp = sexpr_node(node, "device/vif/bridge");
+ char *tmp2;
tmp2 = sexpr_node(node, "device/vif/script");
- if ((tmp != NULL) || (strstr(tmp2, "bridge"))) {
+ if (tmp2 && strstr(tmp2, "bridge")) {
virBufferVSprintf(&buf, " <interface type='bridge'>\n");
+ tmp = sexpr_node(node, "device/vif/bridge");
if (tmp != NULL)
virBufferVSprintf(&buf, " <source bridge='%s'/>\n",
tmp);
- tmp = sexpr_node(node, "device/vif/vifname");
- if (tmp != NULL)
- virBufferVSprintf(&buf, " <target dev='%s'/>\n",
- tmp);
- tmp = sexpr_node(node, "device/vif/mac");
- if (tmp != NULL)
- virBufferVSprintf(&buf, " <mac address='%s'/>\n",
- tmp);
- tmp = sexpr_node(node, "device/vif/ip");
- if (tmp != NULL)
- virBufferVSprintf(&buf, " <ip address='%s'/>\n",
- tmp);
- if (tmp2 != NULL)
- virBufferVSprintf(&buf, " <script path='%s'/>\n",
- tmp2);
- virBufferAdd(&buf, " </interface>\n", 17);
} else {
- char serial[1000];
-
- TODO sexpr2string(node, serial, 1000);
- virBufferVSprintf(&buf, "<!-- Failed to parse vif: %s -->\n",
- serial);
+ virBufferVSprintf(&buf, " <interface type='ethernet'>\n");
}
+
+ tmp = sexpr_node(node, "device/vif/vifname");
+ if (tmp)
+ virBufferVSprintf(&buf, " <target dev='%s'/>\n",
+ tmp);
+ tmp = sexpr_node(node, "device/vif/mac");
+ if (tmp)
+ virBufferVSprintf(&buf, " <mac address='%s'/>\n",
+ tmp);
+ tmp = sexpr_node(node, "device/vif/ip");
+ if (tmp)
+ virBufferVSprintf(&buf, " <ip address='%s'/>\n",
+ tmp);
+ if (tmp2)
+ virBufferVSprintf(&buf, " <script path='%s'/>\n",
+ tmp2);
+
+ virBufferAdd(&buf, " </interface>\n", 17);
}
}
diff --git a/src/xml.c b/src/xml.c
index b1ef663d7..2a7725115 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -1118,6 +1118,7 @@ virDomainParseXMLIfDesc(xmlNodePtr node, virBufferPtr buf, int hvm)
xmlChar *source = NULL;
xmlChar *mac = NULL;
xmlChar *script = NULL;
+ xmlChar *ip = NULL;
int typ = 0;
type = xmlGetProp(node, BAD_CAST "type");
@@ -1133,7 +1134,6 @@ virDomainParseXMLIfDesc(xmlNodePtr node, virBufferPtr buf, int hvm)
if (cur->type == XML_ELEMENT_NODE) {
if ((source == NULL) &&
(xmlStrEqual(cur->name, BAD_CAST "source"))) {
-
if (typ == 0)
source = xmlGetProp(cur, BAD_CAST "bridge");
else
@@ -1144,6 +1144,13 @@ virDomainParseXMLIfDesc(xmlNodePtr node, virBufferPtr buf, int hvm)
} else if ((script == NULL) &&
(xmlStrEqual(cur->name, BAD_CAST "script"))) {
script = xmlGetProp(cur, BAD_CAST "path");
+ } else if ((ip == NULL) &&
+ (xmlStrEqual(cur->name, BAD_CAST "ip"))) {
+ /* XXX in future expect to need to have > 1 ip
+ address element - eg ipv4 & ipv6. For now
+ xen only supports a single address though
+ so lets ignore that complication */
+ ip = xmlGetProp(cur, BAD_CAST "address");
}
}
cur = cur->next;
@@ -1160,6 +1167,8 @@ virDomainParseXMLIfDesc(xmlNodePtr node, virBufferPtr buf, int hvm)
}
if (script != NULL)
virBufferVSprintf(buf, "(script '%s')", script);
+ if (ip != NULL)
+ virBufferVSprintf(buf, "(ip '%s')", ip);
if (hvm)
virBufferAdd(buf, "(type ioemu)", 12);
@@ -1170,6 +1179,8 @@ virDomainParseXMLIfDesc(xmlNodePtr node, virBufferPtr buf, int hvm)
xmlFree(source);
if (script != NULL)
xmlFree(script);
+ if (ip != NULL)
+ xmlFree(ip);
return (0);
}
diff --git a/tests/sexpr2xmldata/sexpr2xml-net-bridged.sexpr b/tests/sexpr2xmldata/sexpr2xml-net-bridged.sexpr
new file mode 100644
index 000000000..7670443b8
--- /dev/null
+++ b/tests/sexpr2xmldata/sexpr2xml-net-bridged.sexpr
@@ -0,0 +1,2 @@
+(domain (domid 6)(name 'pvtest')(memory 420)(maxmem 420)(vcpus 2)(uuid '596a5d2171f48fb2e068e2386a5c413e')(on_poweroff 'destroy')(on_reboot 'destroy')(on_crash 'destroy')(image (linux (kernel '/var/lib/xen/vmlinuz.2Dn2YT')(ramdisk '/var/lib/xen/initrd.img.0u-Vhq')(args ' method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test/5.91/x86_64/os ')))(device (vbd (dev 'xvda')(uname 'file:/root/some.img')(mode 'w')))(device (vif (mac '00:11:22:33:44:55')(bridge 'xenbr2')(script 'vif-bridge'))))
+
diff --git a/tests/sexpr2xmldata/sexpr2xml-net-bridged.xml b/tests/sexpr2xmldata/sexpr2xml-net-bridged.xml
new file mode 100644
index 000000000..9ff80f40a
--- /dev/null
+++ b/tests/sexpr2xmldata/sexpr2xml-net-bridged.xml
@@ -0,0 +1,27 @@
+<domain type='xen' id='6'>
+ <name>pvtest</name>
+ <uuid>596a5d2171f48fb2e068e2386a5c413e</uuid>
+ <os>
+ <type>linux</type>
+ <kernel>/var/lib/xen/vmlinuz.2Dn2YT</kernel>
+ <initrd>/var/lib/xen/initrd.img.0u-Vhq</initrd>
+ <cmdline> method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test/5.91/x86_64/os </cmdline>
+ </os>
+ <memory>430080</memory>
+ <vcpu>2</vcpu>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>destroy</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <disk type='file' device='disk'>
+ <driver name='file'/>
+ <source file='/root/some.img'/>
+ <target dev='xvda'/>
+ </disk>
+ <interface type='bridge'>
+ <source bridge='xenbr2'/>
+ <mac address='00:11:22:33:44:55'/>
+ <script path='vif-bridge'/>
+ </interface>
+ </devices>
+</domain>
diff --git a/tests/sexpr2xmldata/sexpr2xml-net-routed.sexpr b/tests/sexpr2xmldata/sexpr2xml-net-routed.sexpr
new file mode 100644
index 000000000..b3c4ceb82
--- /dev/null
+++ b/tests/sexpr2xmldata/sexpr2xml-net-routed.sexpr
@@ -0,0 +1,2 @@
+(domain (domid 6)(name 'pvtest')(memory 420)(maxmem 420)(vcpus 2)(uuid '596a5d2171f48fb2e068e2386a5c413e')(on_poweroff 'destroy')(on_reboot 'destroy')(on_crash 'destroy')(image (linux (kernel '/var/lib/xen/vmlinuz.2Dn2YT')(ramdisk '/var/lib/xen/initrd.img.0u-Vhq')(args ' method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test/5.91/x86_64/os ')))(device (vbd (dev 'xvda')(uname 'file:/root/some.img')(mode 'w')))(device (vif (mac '00:11:22:33:44:55')(dev 'eth3')(script 'vif-routed')(ip '172.14.5.6')))
+
diff --git a/tests/sexpr2xmldata/sexpr2xml-net-routed.xml b/tests/sexpr2xmldata/sexpr2xml-net-routed.xml
new file mode 100644
index 000000000..a0ede8a48
--- /dev/null
+++ b/tests/sexpr2xmldata/sexpr2xml-net-routed.xml
@@ -0,0 +1,27 @@
+<domain type='xen' id='6'>
+ <name>pvtest</name>
+ <uuid>596a5d2171f48fb2e068e2386a5c413e</uuid>
+ <os>
+ <type>linux</type>
+ <kernel>/var/lib/xen/vmlinuz.2Dn2YT</kernel>
+ <initrd>/var/lib/xen/initrd.img.0u-Vhq</initrd>
+ <cmdline> method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test/5.91/x86_64/os </cmdline>
+ </os>
+ <memory>430080</memory>
+ <vcpu>2</vcpu>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>destroy</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <disk type='file' device='disk'>
+ <driver name='file'/>
+ <source file='/root/some.img'/>
+ <target dev='xvda'/>
+ </disk>
+ <interface type='ethernet'>
+ <mac address='00:11:22:33:44:55'/>
+ <ip address='172.14.5.6'/>
+ <script path='vif-routed'/>
+ </interface>
+ </devices>
+</domain>
diff --git a/tests/sexpr2xmltest.c b/tests/sexpr2xmltest.c
index a7b2b5ca6..3c968112c 100644
--- a/tests/sexpr2xmltest.c
+++ b/tests/sexpr2xmltest.c
@@ -97,6 +97,19 @@ static int testCompareResizedMemory(void *data ATTRIBUTE_UNUSED) {
}
+static int testCompareNetRouted(void *data ATTRIBUTE_UNUSED) {
+ return testCompareFiles("sexpr2xmldata/sexpr2xml-net-routed.xml",
+ "sexpr2xmldata/sexpr2xml-net-routed.sexpr",
+ 1);
+}
+
+static int testCompareNetBridged(void *data ATTRIBUTE_UNUSED) {
+ return testCompareFiles("sexpr2xmldata/sexpr2xml-net-bridged.xml",
+ "sexpr2xmldata/sexpr2xml-net-bridged.sexpr",
+ 1);
+}
+
+
int
main(int argc, char **argv)
{
@@ -145,5 +158,13 @@ main(int argc, char **argv)
1, testCompareResizedMemory, NULL) != 0)
ret = -1;
+ if (virtTestRun("SEXPR-2-XML net routed",
+ 1, testCompareNetRouted, NULL) != 0)
+ ret = -1;
+
+ if (virtTestRun("SEXPR-2-XML net bridged",
+ 1, testCompareNetBridged, NULL) != 0)
+ ret = -1;
+
exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
diff --git a/tests/xml2sexprdata/xml2sexpr-net-bridged.sexpr b/tests/xml2sexprdata/xml2sexpr-net-bridged.sexpr
new file mode 100644
index 000000000..93b1de31b
--- /dev/null
+++ b/tests/xml2sexprdata/xml2sexpr-net-bridged.sexpr
@@ -0,0 +1 @@
+(vm (name 'pvtest')(memory 420)(maxmem 420)(vcpus 2)(uuid '596a5d2171f48fb2e068e2386a5c413e')(on_poweroff 'destroy')(on_reboot 'destroy')(on_crash 'destroy')(image (linux (kernel '/var/lib/xen/vmlinuz.2Dn2YT')(ramdisk '/var/lib/xen/initrd.img.0u-Vhq')(args ' method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test/5.91/x86_64/os ')))(device (vbd (dev 'xvda')(uname 'file:/root/some.img')(mode 'w')))(device (vif (mac '00:11:22:33:44:55')(bridge 'xenbr2')(script 'vif-bridge')))) \ No newline at end of file
diff --git a/tests/xml2sexprdata/xml2sexpr-net-bridged.xml b/tests/xml2sexprdata/xml2sexpr-net-bridged.xml
new file mode 100644
index 000000000..7c5115c77
--- /dev/null
+++ b/tests/xml2sexprdata/xml2sexpr-net-bridged.xml
@@ -0,0 +1,29 @@
+<domain type='xen' id='15'>
+ <name>pvtest</name>
+ <uuid>596a5d2171f48fb2e068e2386a5c413e</uuid>
+ <os>
+ <type>linux</type>
+ <kernel>/var/lib/xen/vmlinuz.2Dn2YT</kernel>
+ <initrd>/var/lib/xen/initrd.img.0u-Vhq</initrd>
+ <cmdline> method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test/5.91/x86_64/os </cmdline>
+ </os>
+ <memory>430080</memory>
+ <vcpu>2</vcpu>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>destroy</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <disk type='file' device='disk'>
+ <source file='/root/some.img'/>
+ <target dev='xvda'/>
+ </disk>
+ <interface type="bridge">
+ <mac address="00:11:22:33:44:55"/>
+ <source bridge="xenbr2"/>
+ <script path="vif-bridge"/>
+ <target dev="vif4.0"/>
+ </interface>
+ <console tty='/dev/pts/4'/>
+ </devices>
+</domain>
+
diff --git a/tests/xml2sexprdata/xml2sexpr-net-routed.sexpr b/tests/xml2sexprdata/xml2sexpr-net-routed.sexpr
new file mode 100644
index 000000000..c8b5f9ffc
--- /dev/null
+++ b/tests/xml2sexprdata/xml2sexpr-net-routed.sexpr
@@ -0,0 +1 @@
+(vm (name 'pvtest')(memory 420)(maxmem 420)(vcpus 2)(uuid '596a5d2171f48fb2e068e2386a5c413e')(on_poweroff 'destroy')(on_reboot 'destroy')(on_crash 'destroy')(image (linux (kernel '/var/lib/xen/vmlinuz.2Dn2YT')(ramdisk '/var/lib/xen/initrd.img.0u-Vhq')(args ' method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test/5.91/x86_64/os ')))(device (vbd (dev 'xvda')(uname 'file:/root/some.img')(mode 'w')))(device (vif (mac '00:11:22:33:44:55')(dev 'eth3')(script 'vif-routed')(ip '172.14.5.6')))) \ No newline at end of file
diff --git a/tests/xml2sexprdata/xml2sexpr-net-routed.xml b/tests/xml2sexprdata/xml2sexpr-net-routed.xml
new file mode 100644
index 000000000..aae20806f
--- /dev/null
+++ b/tests/xml2sexprdata/xml2sexpr-net-routed.xml
@@ -0,0 +1,30 @@
+<domain type='xen' id='15'>
+ <name>pvtest</name>
+ <uuid>596a5d2171f48fb2e068e2386a5c413e</uuid>
+ <os>
+ <type>linux</type>
+ <kernel>/var/lib/xen/vmlinuz.2Dn2YT</kernel>
+ <initrd>/var/lib/xen/initrd.img.0u-Vhq</initrd>
+ <cmdline> method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test/5.91/x86_64/os </cmdline>
+ </os>
+ <memory>430080</memory>
+ <vcpu>2</vcpu>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>destroy</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <disk type='file' device='disk'>
+ <source file='/root/some.img'/>
+ <target dev='xvda'/>
+ </disk>
+ <interface type="ethernet">
+ <mac address="00:11:22:33:44:55"/>
+ <ip address="172.14.5.6"/>
+ <source dev="eth3"/>
+ <script path="vif-routed"/>
+ <target dev="vif4.0"/>
+ </interface>
+ <console tty='/dev/pts/4'/>
+ </devices>
+</domain>
+
diff --git a/tests/xml2sexprtest.c b/tests/xml2sexprtest.c
index 9ca42b973..a1c09e403 100644
--- a/tests/xml2sexprtest.c
+++ b/tests/xml2sexprtest.c
@@ -138,6 +138,21 @@ static int testCompareMemoryResize(void *data ATTRIBUTE_UNUSED) {
2);
}
+static int testCompareNetRouted(void *data ATTRIBUTE_UNUSED) {
+ return testCompareFiles("xml2sexprdata/xml2sexpr-net-routed.xml",
+ "xml2sexprdata/xml2sexpr-net-routed.sexpr",
+ "pvtest",
+ 2);
+}
+
+static int testCompareNetBridged(void *data ATTRIBUTE_UNUSED) {
+ return testCompareFiles("xml2sexprdata/xml2sexpr-net-bridged.xml",
+ "xml2sexprdata/xml2sexpr-net-bridged.sexpr",
+ "pvtest",
+ 2);
+}
+
+
int
main(int argc, char **argv)
{
@@ -202,6 +217,13 @@ main(int argc, char **argv)
1, testCompareMemoryResize, NULL) != 0)
ret = -1;
+ if (virtTestRun("XML-2-SEXPR Net Routed",
+ 1, testCompareNetRouted, NULL) != 0)
+ ret = -1;
+
+ if (virtTestRun("XML-2-SEXPR Net Bridged",
+ 1, testCompareNetBridged, NULL) != 0)
+ ret = -1;
exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
}