Beispiel #1
0
    def test_container_ip_add_ipv6(
        self, m_netns, m_client, m_get_container_info_or_exit, m_get_pool_or_exit, m_enforce_root
    ):
        """
        Test for container_ip_add with an ipv6 ip argument

        Assert that the correct calls associated with an ipv6 address are made
        """
        # Set up mock objects
        pool_return = "pool"
        m_get_pool_or_exit.return_value = pool_return
        m_get_container_info_or_exit.return_value = {"Id": 666, "State": {"Running": 1, "Pid": "Pid_info"}}
        m_endpoint = Mock()
        m_client.get_endpoint.return_value = m_endpoint

        # Set up arguments to pass to method under test
        container_name = "container1"
        ip = "1::1"
        ip_addr = IPAddress(ip)
        interface = "interface"

        # Call method under test
        container.container_ip_add(container_name, ip, interface)

        # Assert
        m_enforce_root.assert_called_once_with()
        m_get_pool_or_exit.assert_called_once_with(ip_addr)
        m_get_container_info_or_exit.assert_called_once_with(container_name)
        m_client.get_endpoint.assert_called_once_with(
            hostname=utils.hostname, orchestrator_id=utils.ORCHESTRATOR_ID, workload_id=666
        )
        m_client.assign_address.assert_called_once_with(pool_return, ip_addr)
        m_endpoint.ipv6_nets.add.assert_called_once_with(IPNetwork(ip_addr))
        m_client.update_endpoint.assert_called_once_with(m_endpoint)
        m_netns.add_ip_to_ns_veth.assert_called_once_with("Pid_info", ip_addr, interface)
    def test_container_ip_add_ipv4_pool(
            self, m_netns, m_client, m_get_container_info_or_exit,
            m_ippool, m_enforce_root):
        """
        Test for container_ip_add with an CIDR/pool ip argument

        Assert that the correct calls associated with an ipv4 address are made
        """
        # Set up mock objects
        ip_addr = IPAddress('192.168.0.128')
        m_endpoint = Mock()
        m_namespace = Mock()
        pool_return = 'pool'

        m_client.get_endpoint.return_value = m_endpoint
        m_client.auto_assign_ips.return_value = ([ip_addr], [])
        m_ippool.return_value = pool_return
        m_get_container_info_or_exit.return_value = {
            'Id': 666,
            'State': {'Running': 1, 'Pid': 'Pid_info'}
        }
        m_netns.PidNamespace.return_value = m_namespace

        # Set up arguments to pass to method under test
        container_name = 'container1'
        ip = '192.168.0.128/25'
        interface = 'interface'

        # Call method under test
        container.container_ip_add(container_name, ip, interface)

        # Assert
        self.assertFalse(m_client.assign_address.called)
        m_enforce_root.assert_called_once_with()
        m_ippool.assert_called_once_with(ip)
        m_get_container_info_or_exit.assert_called_once_with(container_name)
        m_client.get_endpoint.assert_called_once_with(
            hostname=utils.hostname,
            orchestrator_id=utils.DOCKER_ORCHESTRATOR_ID,
            workload_id=666
        )
        m_client.auto_assign_ips.assert_called_once_with(
            1, 0, None, {}, pool=(pool_return, None))
        m_endpoint.ipv4_nets.add.assert_called_once_with(IPNetwork(ip_addr))
        m_client.update_endpoint.assert_called_once_with(m_endpoint)
        m_netns.PidNamespace.assert_called_once_with("Pid_info")
        m_netns.add_ip_to_ns_veth.assert_called_once_with(m_namespace,
                                                          ip_addr,
                                                          interface)
Beispiel #3
0
    def test_container_ip_add_ipv6(
            self, m_netns, m_client, m_get_container_info_or_exit,
            m_get_pool_or_exit, m_enforce_root):
        """
        Test for container_ip_add with an ipv6 ip argument

        Assert that the correct calls associated with an ipv6 address are made
        """
        # Set up mock objects
        pool_return = 'pool'
        m_get_pool_or_exit.return_value = pool_return
        m_get_container_info_or_exit.return_value = {
            'Id': 666,
            'State': {'Running': 1, 'Pid': 'Pid_info'}
        }
        m_endpoint = Mock()
        m_client.get_endpoint.return_value = m_endpoint
        m_namespace = Mock()
        m_netns.PidNamespace.return_value = m_namespace

        # Set up arguments to pass to method under test
        container_name = 'container1'
        ip = '1::1'
        ip_addr = IPAddress(ip)
        interface = 'interface'

        # Call method under test
        container.container_ip_add(container_name, ip, interface)

        # Assert
        m_enforce_root.assert_called_once_with()
        m_get_pool_or_exit.assert_called_once_with(ip_addr)
        m_get_container_info_or_exit.assert_called_once_with(container_name)
        m_client.get_endpoint.assert_called_once_with(
            hostname=utils.hostname,
            orchestrator_id=utils.DOCKER_ORCHESTRATOR_ID,
            workload_id=666
        )
        m_client.assign_address.assert_called_once_with(pool_return, ip_addr)
        m_endpoint.ipv6_nets.add.assert_called_once_with(IPNetwork(ip_addr))
        m_client.update_endpoint.assert_called_once_with(m_endpoint)
        m_netns.PidNamespace.assert_called_once_with("Pid_info")
        m_netns.add_ip_to_ns_veth.assert_called_once_with(m_namespace,
                                                          ip_addr,
                                                          interface)
Beispiel #4
0
    def test_container_ip_add_ipv6(
            self, m_netns, m_client, m_get_container_info_or_exit,
            m_get_pool_or_exit, m_enforce_root):
        """
        Test for container_ip_add with an ipv6 ip argument

        Assert that the correct calls associated with an ipv6 address are made
        """
        # Set up mock objects
        pool_return = 'pool'
        m_get_pool_or_exit.return_value = pool_return
        m_get_container_info_or_exit.return_value = {
            'Id': 666,
            'State': {'Running': 1, 'Pid': 'Pid_info'}
        }
        m_endpoint = Mock()
        m_client.get_endpoint.return_value = m_endpoint
        m_namespace = Mock()
        m_netns.PidNamespace.return_value = m_namespace

        # Set up arguments to pass to method under test
        container_name = 'container1'
        ip = '1::1'
        ip_addr = IPAddress(ip)
        interface = 'interface'

        # Call method under test
        container.container_ip_add(container_name, ip, interface)

        # Assert
        m_enforce_root.assert_called_once_with()
        m_get_pool_or_exit.assert_called_once_with(ip_addr)
        m_get_container_info_or_exit.assert_called_once_with(container_name)
        m_client.get_endpoint.assert_called_once_with(
            hostname=utils.hostname,
            orchestrator_id=utils.DOCKER_ORCHESTRATOR_ID,
            workload_id=666
        )
        m_client.assign_address.assert_called_once_with(pool_return, ip_addr)
        m_endpoint.ipv6_nets.add.assert_called_once_with(IPNetwork(ip_addr))
        m_client.update_endpoint.assert_called_once_with(m_endpoint)
        m_netns.PidNamespace.assert_called_once_with("Pid_info")
        m_netns.add_ip_to_ns_veth.assert_called_once_with(m_namespace,
                                                          ip_addr,
                                                          interface)