def test_ip_xml(self): """ Test network ip xml """ dhcp_range = {"start": "192.168.122.100", "end": "192.168.122.254"} params = {} dhcp = nxml._get_dhcp_elem(**params) self.assertEquals(None, dhcp) params["net"] = "192.168.122.0/255.255.255.0" params["dhcp"] = {'range': dhcp_range} xml = ET.tostring(nxml._get_ip_elem(**params)) start = xpath_get_text(xml, "/ip/dhcp/range/@start")[0] end = xpath_get_text(xml, "/ip/dhcp/range/@end")[0] self.assertEquals(dhcp_range['start'], start) self.assertEquals(dhcp_range['end'], end) address = xpath_get_text(xml, "/ip/@address")[0] netmask = xpath_get_text(xml, "/ip/@netmask")[0] self.assertEquals(address, params["net"].split("/")[0]) self.assertEquals(netmask, params["net"].split("/")[1]) # test _get_ip_xml can accepts strings: '192.168.122.0/24', # which is same as "192.168.122.0/255.255.255.0" params["net"] = "192.168.122.0/24" xml = ET.tostring(nxml._get_ip_elem(**params)) netmask = xpath_get_text(xml, "/ip/@netmask")[0] self.assertEquals(netmask, str(ipaddr.IPNetwork(params["net"]).netmask))
def test_ip_xml(self): """ Test network ip xml """ dhcp_range = {'start': '192.168.122.100', 'end': '192.168.122.254'} params = {} dhcp = nxml._get_dhcp_elem(**params) self.assertEqual(None, dhcp) params['net'] = '192.168.122.0/255.255.255.0' params['dhcp'] = {'range': dhcp_range} xml = ET.tostring(nxml._get_ip_elem(**params), encoding='unicode') start = xpath_get_text(xml, '/ip/dhcp/range/@start')[0] end = xpath_get_text(xml, '/ip/dhcp/range/@end')[0] self.assertEqual(dhcp_range['start'], start) self.assertEqual(dhcp_range['end'], end) address = xpath_get_text(xml, '/ip/@address')[0] netmask = xpath_get_text(xml, '/ip/@netmask')[0] self.assertEqual(address, params['net'].split('/')[0]) self.assertEqual(netmask, params['net'].split('/')[1]) # test _get_ip_xml can accepts strings: '192.168.122.0/24', # which is same as "192.168.122.0/255.255.255.0" params['net'] = '192.168.122.0/24' xml = ET.tostring(nxml._get_ip_elem(**params), encoding='unicode') netmask = xpath_get_text(xml, '/ip/@netmask')[0] self.assertEqual(netmask, str(ipaddr.IPNetwork(params['net']).netmask))
def test_ip_xml(self): """ Test network ip xml """ dhcp_range = {'start': '192.168.122.100', 'end': '192.168.122.254'} params = {} dhcp = nxml._get_dhcp_elem(**params) self.assertEqual(None, dhcp) params['net'] = '192.168.122.0/255.255.255.0' params['dhcp'] = {'range': dhcp_range} xml = ET.tostring(nxml._get_ip_elem(**params)) start = xpath_get_text(xml, '/ip/dhcp/range/@start')[0] end = xpath_get_text(xml, '/ip/dhcp/range/@end')[0] self.assertEqual(dhcp_range['start'], start) self.assertEqual(dhcp_range['end'], end) address = xpath_get_text(xml, '/ip/@address')[0] netmask = xpath_get_text(xml, '/ip/@netmask')[0] self.assertEqual(address, params['net'].split('/')[0]) self.assertEqual(netmask, params['net'].split('/')[1]) # test _get_ip_xml can accepts strings: '192.168.122.0/24', # which is same as "192.168.122.0/255.255.255.0" params['net'] = '192.168.122.0/24' xml = ET.tostring(nxml._get_ip_elem(**params)) netmask = xpath_get_text(xml, '/ip/@netmask')[0] self.assertEqual(netmask, str(ipaddr.IPNetwork(params['net']).netmask))