Ejemplo n.º 1
0
def ip_nonlocal_bind():
    nsname1 = "ipnonlocalbind1-" + uuidutils.generate_uuid()
    nsname2 = "ipnonlocalbind2-" + uuidutils.generate_uuid()

    ip_lib.create_network_namespace(nsname1)
    try:
        ip_lib.create_network_namespace(nsname2)
        try:
            original_value = ip_lib.get_ip_nonlocal_bind(namespace=None)
            try:
                ip_lib.set_ip_nonlocal_bind(value=0, namespace=nsname1)
                ip_lib.set_ip_nonlocal_bind(value=1, namespace=nsname2)
                ns1_value = ip_lib.get_ip_nonlocal_bind(namespace=nsname1)
            finally:
                _fix_ip_nonlocal_bind_root_value(original_value)
        except RuntimeError as e:
            LOG.debug(
                "Exception while checking ip_nonlocal_bind. "
                "Exception: %s", e)
            return False
        finally:
            ip_lib.delete_network_namespace(nsname2)
    finally:
        ip_lib.delete_network_namespace(nsname1)
    return ns1_value == 0
Ejemplo n.º 2
0
def netns_read_requires_helper():
    nsname = "netnsreadtest-" + uuidutils.generate_uuid()
    ip_lib.create_network_namespace(nsname)
    try:
        # read without root_helper. if exists, not required.
        exists = ip_lib.network_namespace_exists(nsname)
    finally:
        ip_lib.delete_network_namespace(nsname)
    return not exists
Ejemplo n.º 3
0
def netns_read_requires_helper():
    nsname = "netnsreadtest-" + uuidutils.generate_uuid()
    ip_lib.create_network_namespace(nsname)
    try:
        # read without root_helper. if exists, not required.
        exists = ip_lib.network_namespace_exists(nsname)
    finally:
        ip_lib.delete_network_namespace(nsname)
    return not exists
Ejemplo n.º 4
0
 def __exit__(self, exc_type, exc_value, exc_tb):
     if self.pm:
         self.pm.stop()
     if self.manager:
         self.manager.disable()
     if self.config_path:
         shutil.rmtree(self.config_path, ignore_errors=True)
     ip_lib.delete_network_namespace(self.nsname)
     cfg.CONF.set_override('check_child_processes_interval',
                           self.orig_interval, 'AGENT')
Ejemplo n.º 5
0
 def __exit__(self, exc_type, exc_value, exc_tb):
     if self.pm:
         self.pm.stop()
     if self.manager:
         self.manager.disable()
     if self.config_path:
         shutil.rmtree(self.config_path, ignore_errors=True)
     ip_lib.delete_network_namespace(self.nsname)
     cfg.CONF.set_override('check_child_processes_interval',
                           self.orig_interval, 'AGENT')
Ejemplo n.º 6
0
 def delete_probe(self, port_id):
     port = dhcp.DictModel(self.client.show_port(port_id)['port'])
     namespace = self._get_namespace(port)
     if ip_lib.network_namespace_exists(namespace):
         self.driver.unplug(self.driver.get_device_name(port),
                            namespace=namespace)
         try:
             ip_lib.delete_network_namespace(namespace)
         except Exception:
             LOG.warning('Failed to delete namespace %s', namespace)
     else:
         self.driver.unplug(self.driver.get_device_name(port))
     self.client.delete_port(port.id)
Ejemplo n.º 7
0
 def delete_probe(self, port_id):
     port = dhcp.DictModel(self.client.show_port(port_id)['port'])
     namespace = self._get_namespace(port)
     if ip_lib.network_namespace_exists(namespace):
         self.driver.unplug(self.driver.get_device_name(port),
                            namespace=namespace)
         try:
             ip_lib.delete_network_namespace(namespace)
         except Exception:
             LOG.warning('Failed to delete namespace %s', namespace)
     else:
         self.driver.unplug(self.driver.get_device_name(port))
     self.client.delete_port(port.id)
Ejemplo n.º 8
0
    def clean_dhcp_namespaces(self):
        """Delete all DHCP namespaces created by DHCP agent.

        In some tests for DHCP agent HA agents are killed when handling DHCP
        service for network(s). In such case DHCP namespace is not deleted by
        DHCP agent and such namespaces are found and deleted using agent's
        namespace suffix.
        """

        for namespace in ip_lib.list_network_namespaces():
            if self.dhcp_namespace_pattern.match(namespace):
                try:
                    ip_lib.delete_network_namespace(namespace)
                except RuntimeError:
                    # Continue cleaning even if namespace deletions fails
                    pass
Ejemplo n.º 9
0
    def clean_dhcp_namespaces(self):
        """Delete all DHCP namespaces created by DHCP agent.

        In some tests for DHCP agent HA agents are killed when handling DHCP
        service for network(s). In such case DHCP namespace is not deleted by
        DHCP agent and such namespaces are found and deleted using agent's
        namespace suffix.
        """

        for namespace in ip_lib.list_network_namespaces():
            if self.dhcp_namespace_pattern.match(namespace):
                try:
                    ip_lib.delete_network_namespace(namespace)
                except RuntimeError:
                    # Continue cleaning even if namespace deletions fails
                    pass
Ejemplo n.º 10
0
    def destroy(self):
        """Destroy this fake machine.

        This should simulate deletion of a vm. It doesn't call cleanUp().
        """
        self.safe_client.client.update_port(self.neutron_port['id'],
                                            {'port': {
                                                pbs.HOST_ID: ''
                                            }})
        # All associated vlan interfaces are deleted too
        # If VM is connected to Linuxbridge it hasn't got "delete_port" method
        # and it is not necessary to delete tap port connected to this bridge.
        # It is veth pair and will be removed together with VM namespace
        if hasattr(self.bridge, "delete_port"):
            self.bridge.delete_port(self.port.name)

        ip_lib.delete_network_namespace(self.namespace)
Ejemplo n.º 11
0
    def destroy(self):
        """Destroy this fake machine.

        This should simulate deletion of a vm. It doesn't call cleanUp().
        """
        self.safe_client.client.update_port(
            self.neutron_port['id'],
            {'port': {pbs.HOST_ID: ''}}
        )
        # All associated vlan interfaces are deleted too
        # If VM is connected to Linuxbridge it hasn't got "delete_port" method
        # and it is not necessary to delete tap port connected to this bridge.
        # It is veth pair and will be removed together with VM namespace
        if hasattr(self.bridge, "delete_port"):
            self.bridge.delete_port(self.port.name)

        ip_lib.delete_network_namespace(self.namespace)
Ejemplo n.º 12
0
 def delete_probe(self, port_id):
     port = dhcp.DictModel(self.client.show_port(port_id)['port'])
     network = self._get_network(port.network_id)
     bridge = None
     if network.external:
         bridge = self.conf.external_network_bridge
     namespace = self._get_namespace(port)
     if ip_lib.network_namespace_exists(namespace):
         self.driver.unplug(self.driver.get_device_name(port),
                            bridge=bridge,
                            namespace=namespace)
         try:
             ip_lib.delete_network_namespace(namespace)
         except Exception:
             LOG.warning('Failed to delete namespace %s', namespace)
     else:
         self.driver.unplug(self.driver.get_device_name(port),
                            bridge=bridge)
     self.client.delete_port(port.id)
Ejemplo n.º 13
0
def ip_nonlocal_bind():
    nsname1 = "ipnonlocalbind1-" + uuidutils.generate_uuid()
    nsname2 = "ipnonlocalbind2-" + uuidutils.generate_uuid()

    ip_lib.create_network_namespace(nsname1)
    try:
        ip_lib.create_network_namespace(nsname2)
        try:
            original_value = ip_lib.get_ip_nonlocal_bind(namespace=None)
            try:
                ip_lib.set_ip_nonlocal_bind(value=0, namespace=nsname1)
                ip_lib.set_ip_nonlocal_bind(value=1, namespace=nsname2)
                ns1_value = ip_lib.get_ip_nonlocal_bind(namespace=nsname1)
            finally:
                _fix_ip_nonlocal_bind_root_value(original_value)
        except RuntimeError as e:
            LOG.debug("Exception while checking ip_nonlocal_bind. "
                      "Exception: %s", e)
            return False
        finally:
            ip_lib.delete_network_namespace(nsname2)
    finally:
        ip_lib.delete_network_namespace(nsname1)
    return ns1_value == 0
Ejemplo n.º 14
0
 def _delete_namespace(self):
     ip_lib.delete_network_namespace(self.namespace)
Ejemplo n.º 15
0
 def _delete_namespace(self):
     ip_lib.delete_network_namespace(self.namespace)