コード例 #1
0
ファイル: test_networkxml.py プロジェクト: alinefm/kimchi
    def test_dhcp_xml(self):
        """
        Test network dhcp xml
        """
        dhcp_range = {'start': '192.168.122.100', 'end': '192.168.122.254'}
        host1 = {
            'mac': '00:16:3e:77:e2:ed',
            'name': 'foo.example.com',
            'ip': '192.168.122.10',
        }
        host2 = {
            'mac': '00:16:3e:3e:a9:1a',
            'name': 'bar.example.com',
            'ip': '192.168.122.11',
        }
        params = {}

        dhcp = nxml._get_dhcp_elem(**params)
        self.assertEqual(None, dhcp)

        params['range'] = dhcp_range
        xml = ET.tostring(nxml._get_dhcp_elem(**params))
        start = xpath_get_text(xml, '/dhcp/range/@start')
        end = xpath_get_text(xml, '/dhcp/range/@end')
        self.assertEqual(dhcp_range['start'], start[0])
        self.assertEqual(dhcp_range['end'], end[0])

        params['hosts'] = [host1, host2]
        xml = ET.tostring(nxml._get_dhcp_elem(**params))
        ip = xpath_get_text(xml, '/dhcp/host/@ip')
        self.assertEqual(ip, [host1['ip'], host2['ip']])
コード例 #2
0
    def test_dhcp_xml(self):
        """
        Test network dhcp xml
        """
        dhcp_range = {"start": "192.168.122.100", "end": "192.168.122.254"}
        host1 = {
            "mac": "00:16:3e:77:e2:ed",
            "name": "foo.example.com",
            "ip": "192.168.122.10"
        }
        host2 = {
            "mac": "00:16:3e:3e:a9:1a",
            "name": "bar.example.com",
            "ip": "192.168.122.11"
        }
        params = {}

        dhcp = nxml._get_dhcp_elem(**params)
        self.assertEquals(None, dhcp)

        params["range"] = dhcp_range
        xml = ET.tostring(nxml._get_dhcp_elem(**params))
        start = xpath_get_text(xml, "/dhcp/range/@start")
        end = xpath_get_text(xml, "/dhcp/range/@end")
        self.assertEquals(dhcp_range['start'], start[0])
        self.assertEquals(dhcp_range['end'], end[0])

        params["hosts"] = [host1, host2]
        xml = ET.tostring(nxml._get_dhcp_elem(**params))
        ip = xpath_get_text(xml, "/dhcp/host/@ip")
        self.assertEquals(ip, [host1['ip'], host2['ip']])
コード例 #3
0
ファイル: test_networkxml.py プロジェクト: zhangy0gg/kimchi
    def test_dhcp_xml(self):
        """
        Test network dhcp xml
        """
        dhcp_range = {'start': '192.168.122.100', 'end': '192.168.122.254'}
        host1 = {
            'mac': '00:16:3e:77:e2:ed',
            'name': 'foo.example.com',
            'ip': '192.168.122.10',
        }
        host2 = {
            'mac': '00:16:3e:3e:a9:1a',
            'name': 'bar.example.com',
            'ip': '192.168.122.11',
        }
        params = {}

        dhcp = nxml._get_dhcp_elem(**params)
        self.assertEqual(None, dhcp)

        params['range'] = dhcp_range
        xml = ET.tostring(nxml._get_dhcp_elem(**params), encoding='unicode')
        start = xpath_get_text(xml, '/dhcp/range/@start')
        end = xpath_get_text(xml, '/dhcp/range/@end')
        self.assertEqual(dhcp_range['start'], start[0])
        self.assertEqual(dhcp_range['end'], end[0])

        params['hosts'] = [host1, host2]
        xml = ET.tostring(nxml._get_dhcp_elem(**params), encoding='unicode')
        ip = xpath_get_text(xml, '/dhcp/host/@ip')
        self.assertEqual(ip, [host1['ip'], host2['ip']])
コード例 #4
0
ファイル: test_networkxml.py プロジェクト: madhawa/kimchi
    def test_dhcp_xml(self):
        """
        Test network dhcp xml
        """
        dhcp_range = {"start": "192.168.122.100", "end": "192.168.122.254"}
        host1 = {"mac": "00:16:3e:77:e2:ed",
                 "name": "foo.example.com",
                 "ip": "192.168.122.10"}
        host2 = {"mac": "00:16:3e:3e:a9:1a",
                 "name": "bar.example.com",
                 "ip": "192.168.122.11"}
        params = {}

        dhcp = nxml._get_dhcp_elem(**params)
        self.assertEquals(None, dhcp)

        params["range"] = dhcp_range
        xml = ET.tostring(nxml._get_dhcp_elem(**params))
        start = xpath_get_text(xml, "/dhcp/range/@start")
        end = xpath_get_text(xml, "/dhcp/range/@end")
        self.assertEquals(dhcp_range['start'], start[0])
        self.assertEquals(dhcp_range['end'], end[0])

        params["hosts"] = [host1, host2]
        xml = ET.tostring(nxml._get_dhcp_elem(**params))
        ip = xpath_get_text(xml, "/dhcp/host/@ip")
        self.assertEquals(ip, [host1['ip'], host2['ip']])
コード例 #5
0
    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))
コード例 #6
0
ファイル: test_networkxml.py プロジェクト: alinefm/kimchi
    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))
コード例 #7
0
ファイル: test_networkxml.py プロジェクト: zhangy0gg/kimchi
    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))
コード例 #8
0
ファイル: test_networkxml.py プロジェクト: madhawa/kimchi
    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))