Пример #1
0
 def test_convert_ns_to_vpnid(self):
     cfg.CONF.register_opts(OPTS, 'cisco_pnr')
     relay = DhcpRelayAgent()
     namespace = 'qdhcp-a207e329-9476-4746-91a7-fb1cce171a81'
     vpnid = relay._convert_ns_to_vpnid(namespace)
     expected = 'a7fb1cce171a81'
     self.assertEqual(expected, vpnid)
Пример #2
0
    def test_open_dhcp_int_socket(self, mock_socket, mock_netns):
        cfg.CONF.register_opts(OPTS, 'cisco_pnr')
        relay = DhcpRelayAgent()

        mock_netns.iflist.return_value = []
        mock_netns.iflist.return_value.append(
            ('eth0', '10.1.1.7', '255.255.255.0'))
        recv_s, send_s, addr = relay._open_dhcp_int_socket()

        self.assertTrue(mock_netns.iflist.called, "Failed to call iflist.")

        mock_socket.assert_has_calls([
            mock.call(socket.AF_INET, socket.SOCK_DGRAM),
            mock.call().setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1),
            mock.call().setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1),
            mock.call().bind(('0.0.0.0', 67)),
            mock.call(socket.AF_INET, socket.SOCK_DGRAM),
            mock.call().setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1),
            mock.call().setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1),
            mock.call().bind(('10.1.1.7', 67))
        ])

        # check exception thrown if no interfaces
        with self.assertRaises(UnexpectedError):
            mock_netns.iflist.return_value = []
            recv_s, send_s, addr = relay._open_dhcp_int_socket()
 def test_convert_ns_to_vpnid(self):
     cfg.CONF.register_opts(OPTS, 'cisco_pnr')
     relay = DhcpRelayAgent()
     namespace = 'qdhcp-a207e329-9476-4746-91a7-fb1cce171a81'
     vpnid = relay._convert_ns_to_vpnid(namespace)
     expected = 'a7fb1cce171a81'
     self.assertEqual(expected, vpnid)
    def test_open_dhcp_int_socket(self, mock_socket, mock_netns):
        cfg.CONF.register_opts(OPTS, 'cisco_pnr')
        relay = DhcpRelayAgent()

        mock_netns.iflist.return_value = []
        mock_netns.iflist.return_value.append(('eth0', '10.1.1.7',
                                               '255.255.255.0'))
        recv_s, send_s, addr = relay._open_dhcp_int_socket()

        self.assertTrue(mock_netns.iflist.called, "Failed to call iflist.")

        mock_socket.assert_has_calls([
            mock.call(socket.AF_INET, socket.SOCK_DGRAM),
            mock.call().setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1),
            mock.call().setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1),
            mock.call().bind(('0.0.0.0', 67)),
            mock.call(socket.AF_INET, socket.SOCK_DGRAM),
            mock.call().setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1),
            mock.call().setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1),
            mock.call().bind(('10.1.1.7', 67))]
        )

        # check exception thrown if no interfaces
        with self.assertRaises(UnexpectedError):
            mock_netns.iflist.return_value = []
            recv_s, send_s, addr = relay._open_dhcp_int_socket()
    def test_open_dhcp_ext_socket(self, mock_socket, mock_netns):
        cfg.CONF.register_opts(OPTS, 'cisco_pnr')
        relay = DhcpRelayAgent()
        mock_netns.iflist.return_value = []
        mock_netns.iflist.return_value.append(('lo', '127.0.0.1',
                                               '255.0.0.0'))
        sock, addr = relay._open_dhcp_ext_socket()

        self.assertTrue(mock_netns.iflist.called, "Failed to call iflist.")

        mock_socket.assert_has_calls([
            mock.call(socket.AF_INET, socket.SOCK_DGRAM),
            mock.call().bind(('127.0.0.1', 67)),
            mock.call().connect(('127.0.0.1', 67))]
        )

        # check exception thrown if no interfaces
        with self.assertRaises(UnexpectedError):
            mock_netns.iflist.return_value = []
            sock, addr = relay._open_dhcp_ext_socket()

        # check exception thrown if no matching interfaces
        with self.assertRaises(UnexpectedError):
            mock_netns.iflist.return_value = []
            mock_netns.iflist.return_value.append(('eth1', '10.0.1.3',
                                                   '255.255.255.0'))
            sock, addr = relay._open_dhcp_ext_socket()

        # check matching interface found if not first in list
        mock_netns.iflist.return_value.append(('eth0', '10.0.0.10',
                                               '255.255.255.0'))
        mock_netns.iflist.return_value.append(('lo', '127.0.0.1',
                                               '255.0.0.0'))
        sock, addr = relay._open_dhcp_ext_socket()
Пример #6
0
    def test_open_dhcp_ext_socket(self, mock_socket, mock_netns):
        cfg.CONF.register_opts(OPTS, 'cisco_pnr')
        relay = DhcpRelayAgent()
        mock_netns.iflist.return_value = []
        mock_netns.iflist.return_value.append(('lo', '127.0.0.1', '255.0.0.0'))
        sock, addr = relay._open_dhcp_ext_socket()

        self.assertTrue(mock_netns.iflist.called, "Failed to call iflist.")

        mock_socket.assert_has_calls([
            mock.call(socket.AF_INET, socket.SOCK_DGRAM),
            mock.call().bind(('127.0.0.1', 67)),
            mock.call().connect(('127.0.0.1', 67))
        ])

        # check exception thrown if no interfaces
        with self.assertRaises(UnexpectedError):
            mock_netns.iflist.return_value = []
            sock, addr = relay._open_dhcp_ext_socket()

        # check exception thrown if no matching interfaces
        with self.assertRaises(UnexpectedError):
            mock_netns.iflist.return_value = []
            mock_netns.iflist.return_value.append(
                ('eth1', '10.0.1.3', '255.255.255.0'))
            sock, addr = relay._open_dhcp_ext_socket()

        # check matching interface found if not first in list
        mock_netns.iflist.return_value.append(
            ('eth0', '10.0.0.10', '255.255.255.0'))
        mock_netns.iflist.return_value.append(('lo', '127.0.0.1', '255.0.0.0'))
        sock, addr = relay._open_dhcp_ext_socket()