Kaitlin Rupert wrote:
# HG changeset patch
# User Kaitlin Rupert <karupert(a)us.ibm.com>
# Date 1236890700 25200
# Node ID ab10caadc452bc5413f7776a978214241b6ae2f9
# Parent 676a8b05baa09b69052d519c7b438b301bea849c
[TEST] #2 Make sure network pool is created with a random IP.
This will help prevent overlap with existing networks. However, this won't
completely prevent the issue. We'd need to do test to see if the IP address
is already used by a different network. If the network is in use, then another
IP address should be used.
Updates:
-Check to see if pool with the specified IP range exists, if so, return a
meaningful error
-Since the NetXML generates a random IP, creating a NetXML object in the
destroy call will generate an object with a different IP. Instead, use
the virsh call to destroy the network.
Signed-off-by: Kaitlin Rupert <karupert(a)us.ibm.com>
diff -r 676a8b05baa0 -r ab10caadc452
suites/libvirt-cim/lib/XenKvmLib/common_util.py
--- a/suites/libvirt-cim/lib/XenKvmLib/common_util.py Tue Mar 10 22:27:59 2009 -0700
+++ b/suites/libvirt-cim/lib/XenKvmLib/common_util.py Thu Mar 12 13:45:00 2009 -0700
@@ -36,7 +36,7 @@
CIM_ERROR_GETINSTANCE
from CimTest.ReturnCodes import PASS, FAIL, XFAIL_RC
from XenKvmLib.xm_virt_util import diskpool_list, virsh_version, net_list,\
- domain_list, virt2uri
+ domain_list, virt2uri, net_destroy
from XenKvmLib.vxml import PoolXML, NetXML
from VirtLib import utils
from XenKvmLib.const import default_pool_name, default_network_name
@@ -438,11 +438,9 @@
if net_name == None:
return FAIL
- netxml = NetXML(server, virt=virt, networkname=net_name)
- ret = netxml.destroy_vnet()
- if not ret:
- logger.error("Failed to destroy Virtual Network '%s'",
- net_name)
+ ret = net_destroy(net_name, server, virt)
+ if ret != 0:
+ logger.error("Failed to destroy Virtual Network '%s'",
net_name)
return FAIL
return PASS
diff -r 676a8b05baa0 -r ab10caadc452 suites/libvirt-cim/lib/XenKvmLib/vxml.py
--- a/suites/libvirt-cim/lib/XenKvmLib/vxml.py Tue Mar 10 22:27:59 2009 -0700
+++ b/suites/libvirt-cim/lib/XenKvmLib/vxml.py Thu Mar 12 13:45:00 2009 -0700
@@ -32,6 +32,7 @@
# shared by XenXML & KVMXML.
import os
import sys
+import random
import platform
import tempfile
from time import sleep
@@ -39,7 +40,8 @@
from xml.dom import minidom, Node
from xml import xpath
from VirtLib import utils, live
-from XenKvmLib.xm_virt_util import get_bridge_from_network_xml, bootloader
+from XenKvmLib.xm_virt_util import get_bridge_from_network_xml, bootloader, \
+ net_list
from XenKvmLib.test_doms import set_uuid, viruuid
from XenKvmLib import vsms
from XenKvmLib import const
@@ -182,7 +184,6 @@
def get_valid_bridge_name(server):
bridge_list = live.available_bridges(server)
if bridgename in bridge_list:
- import random
vbr = bridgename + str(random.randint(1, 100))
if vbr in bridge_list:
logger.error('Need to give different bridge name '
@@ -207,13 +208,27 @@
self.add_sub_node(network, 'name', self.net_name)
self.add_sub_node(network, 'uuid', set_uuid())
self.add_sub_node(network, 'forward')
- subnet = '192.168.122.'
+ subnet = '192.168.123.'
self.add_sub_node(network, 'bridge', name=self.vbr, stp='on',
forwardDelay='0')
- ip = self.add_sub_node(network, 'ip', address=subnet+'1',
+ ip_base = random.randint(1, 100)
+ addr = subnet+'%d' % ip_base
+ addr = subnet+'1'
+
+ n_list = net_list(server, virt)
+ for _net_name in n_list:
+ cmd = "virsh net-dumpxml %s | awk '/ip address/ {print}' | \
+ cut -d ' ' -f 4 | sed 's/address=//'" %
_net_name
+ s, in_use_addr = utils.run_remote(server, cmd)
+ in_use_addr = in_use_addr.strip("'")
+ if in_use_addr == addr:
+ logger.error("IP address is in use by a different network")
break/ return None whichever suitable here once you find the IP is
already in use.
+
+ ip = self.add_sub_node(network, 'ip', address=addr,
netmask='255.255.255.0')
dhcp = self.add_sub_node(ip, 'dhcp')
- self.add_sub_node(dhcp, 'range', start=subnet+'2',
+ range_addr = subnet+'%d' % (ip_base + 1)
+ self.add_sub_node(dhcp, 'range', start=range_addr,
end=subnet+'254')
We should not continue here with assigning dhcp and other info if the IP
that is generated is already in use?
def create_vnet(self):
diff -r 676a8b05baa0 -r ab10caadc452 suites/libvirt-cim/lib/XenKvmLib/xm_virt_util.py
--- a/suites/libvirt-cim/lib/XenKvmLib/xm_virt_util.py Tue Mar 10 22:27:59 2009 -0700
+++ b/suites/libvirt-cim/lib/XenKvmLib/xm_virt_util.py Thu Mar 12 13:45:00 2009 -0700
@@ -184,6 +184,14 @@
if len(bridge) > 1:
return bridge[1]
+def net_destroy(network, server, virt="Xen"):
+ """Function destroys a given virtual network"""
+
+ cmd = "virsh -c %s net-destroy %s" % (virt2uri(virt), network)
+ ret, out = utils.run_remote(server, cmd)
+
+ return ret
+
def network_by_bridge(bridge, server, virt="Xen"):
"""Function returns virtual network for a given
bridge"""
_______________________________________________
Libvirt-cim mailing list
Libvirt-cim(a)redhat.com
https://www.redhat.com/mailman/listinfo/libvirt-cim
--
Thanks and Regards,
Deepti B. Kalakeri
IBM Linux Technology Center
deeptik(a)linux.vnet.ibm.com