Пример #1
0
 def plug_interface(self, tenant_id, net_id, port_id,
                    remote_interface_id):
     """
     Provides connectivity to a remote interface to the
     specified Virtual Network.
     """
     LOG.debug("plug_interface() called\n")
     network = db.network_get(net_id)
     port = db.port_get(net_id, port_id)
     attachment_id = port[const.INTERFACEID]
     if attachment_id == None:
         raise cexc.InvalidAttach(port_id=port_id, net_id=net_id,
                                 att_id=remote_interface_id)
     attachment_id = attachment_id[:const.UUID_LENGTH]
     remote_interface_id = remote_interface_id[:const.UUID_LENGTH]
     if remote_interface_id != attachment_id:
         LOG.debug("Existing attachment_id:%s, remote_interface_id:%s" % \
                   (attachment_id, remote_interface_id))
         raise exc.PortInUse(port_id=port_id, net_id=net_id,
                             att_id=attachment_id)
     self._invoke_device_plugins(self._func_name(), [tenant_id,
                                                     net_id, port_id,
                                                     attachment_id])
     db.port_unset_attachment(net_id, port_id)
     db.port_set_attachment(net_id, port_id, attachment_id)
Пример #2
0
 def get_port_details(self, tenant_id, net_id, port_id):
     """
     This method allows the user to retrieve a remote interface
     that is attached to this particular port.
     """
     LOG.debug("get_port_details() called\n")
     network = db.network_get(net_id)
     self._invoke_device_plugins(self._func_name(), [tenant_id, net_id, port_id])
     port = db.port_get(net_id, port_id)
     new_port_dict = cutil.make_port_dict(
         port[const.UUID], port[const.PORTSTATE], port[const.NETWORKID], port[const.INTERFACEID]
     )
     return new_port_dict
Пример #3
0
 def get_port(self, net_id, port_id):
     """Get a port"""
     port_list = []
     port = db.port_get(net_id, port_id)
     try:
         LOG.debug("Getting port: %s" % port.uuid)
         port_dict = {}
         port_dict["port-id"] = str(port.uuid)
         port_dict["net-id"] = str(port.network_id)
         port_dict["int-id"] = port.interface_id
         port_dict["state"] = port.state
         port_list.append(port_dict)
         return port_list
     except Exception, exc:
         LOG.error("Failed to get port: %s" % str(exc))
Пример #4
0
 def unplug_interface(self, tenant_id, net_id, port_id):
     """
     Removes connectivity of a remote interface to the
     specified Virtual Network.
     """
     LOG.debug("unplug_interface() called\n")
     network = db.network_get(net_id)
     port = db.port_get(net_id, port_id)
     attachment_id = port[const.INTERFACEID]
     if attachment_id == None:
         raise exc.InvalidDetach(port_id=port_id, net_id=net_id, att_id=remote_interface_id)
     self._invoke_device_plugins(self._func_name(), [tenant_id, net_id, port_id])
     attachment_id = attachment_id[: const.UUID_LENGTH]
     attachment_id = attachment_id + const.UNPLUGGED
     db.port_unset_attachment(net_id, port_id)
     db.port_set_attachment(net_id, port_id, attachment_id)
Пример #5
0
    def test_unplug_interface(self, tenant_id='test_tenant',
                              instance_tenant_id='nova',
                              nova_user_id='novaadmin', instance_id=10,
                              vif_id='fe701ddf-26a2-42ea-b9e6-7313d1c522cc'):
        """
        Tests detaachment of an interface to a port
        """
        LOG.debug("test_unplug_interface - START")
        new_net_dict = self._l2network_plugin.create_network(tenant_id,
                                                             self.network_name)
        port_dict = self._l2network_plugin.create_port(
            tenant_id, new_net_dict[const.NET_ID], self.state)
        instance_desc = {'project_id': tenant_id,
                         'user_id': nova_user_id}
        host_list = self._l2network_plugin.schedule_host(instance_tenant_id,
                                                         instance_id,
                                                         instance_desc)
        instance_vif_desc = {'project_id': tenant_id, 'user_id': nova_user_id,
                             'vif_id': vif_id}

        if conf.PLUGINS[const.PLUGINS].keys():
            vif_description = self._l2network_plugin. associate_port(
                instance_tenant_id,
                instance_id,
                instance_vif_desc)
        else:
            db.port_set_attachment_by_id(port_dict[const.PORT_ID],
                                         instance_vif_desc['vif_id'] +
                                         const.UNPLUGGED)

        self._l2network_plugin.plug_interface(tenant_id,
                                              new_net_dict[const.NET_ID],
                                              port_dict[const.PORT_ID], vif_id)
        self._l2network_plugin.unplug_interface(tenant_id,
                                                new_net_dict[const.NET_ID],
                                                port_dict[const.PORT_ID])
        port = db.port_get(new_net_dict[const.NET_ID],
                           port_dict[const.PORT_ID])
        vif_id_unplugged = vif_id + '(detached)'
        self.assertEqual(port[const.INTERFACEID], vif_id_unplugged)
        self.tearDownNetworkPortInterface(tenant_id, instance_tenant_id,
                                          instance_id, instance_vif_desc,
                                          new_net_dict[const.NET_ID],
                                          port_dict[const.PORT_ID])

        LOG.debug("test_unplug_interface - END")
Пример #6
0
 def delete_port(self, tenant_id, net_id, port_id):
     """
     Deletes a port on a specified Virtual Network,
     if the port contains a remote interface attachment,
     the remote interface should first be un-plugged and
     then the port can be deleted.
     """
     LOG.debug("delete_port() called\n")
     network = db.network_get(net_id)
     port = db.port_get(net_id, port_id)
     attachment_id = port[const.INTERFACEID]
     if not attachment_id:
         self._invoke_device_plugins(self._func_name(), [tenant_id, net_id, port_id])
         db.port_destroy(net_id, port_id)
         new_port_dict = cutil.make_port_dict(port_id, None, None, None)
         return new_port_dict
     else:
         raise exc.PortInUse(port_id=port_id, net_id=net_id, att_id=attachment_id)
Пример #7
0
 def plug_interface(self, tenant_id, net_id, port_id,
                    remote_interface_id):
     """
     Attaches a remote interface to the specified port on the
     specified Virtual Network.
     """
     LOG.debug("plug_interface() called\n")
     network = db.network_get(net_id)
     port = db.port_get(net_id, port_id)
     attachment_id = port[const.INTERFACEID]
     if attachment_id and remote_interface_id != attachment_id:
         raise exc.PortInUse(port_id=port_id, net_id=net_id,
                             att_id=attachment_id)
     self._invoke_device_plugins(self._func_name(), [tenant_id,
                                                     net_id, port_id,
                                                     remote_interface_id])
     if attachment_id == None:
         db.port_set_attachment(net_id, port_id, remote_interface_id)
    def tearDown(self):
        """Tear down our tests"""
        try:
            port = db.port_get(self.net_id, self.port_id)
            self._l2network_multiblade.delete_port([tenant_id, self.net_id, self.port_id])
        except exc.NetworkNotFound:
            # We won't always have a port to remove
            pass
        except exc.PortNotFound:
            # We won't always have a port to remove
            pass

        try:
            net = db.network_get(self.net_id)
            self._l2network_multiblade.delete_network([tenant_id, self.net_id])
        except exc.NetworkNotFound:
            # We won't always have a network to remove
            pass
        db.clear_db()
Пример #9
0
    def test_unplug_interface(self,
                              tenant_id='test_tenant',
                              instance_tenant_id='nova',
                              nova_user_id='novaadmin',
                              instance_id=10,
                              vif_id='fe701ddf-26a2-42ea-b9e6-7313d1c522cc'):
        """
        Tests detaachment of an interface to a port
        """

        LOG.debug("test_unplug_interface - START")
        new_net_dict = self._l2network_plugin.create_network(
            tenant_id, self.network_name)
        port_dict = self._l2network_plugin.create_port(
            tenant_id, new_net_dict[const.NET_ID], self.state)
        instance_desc = {'project_id': tenant_id, 'user_id': nova_user_id}
        host_list = self._l2network_plugin.schedule_host(
            instance_tenant_id, instance_id, instance_desc)
        instance_vif_desc = {
            'project_id': tenant_id,
            'user_id': nova_user_id,
            'vif_id': vif_id
        }
        vif_description = self._l2network_plugin.associate_port(
            instance_tenant_id, instance_id, instance_vif_desc)

        self._l2network_plugin.plug_interface(tenant_id,
                                              new_net_dict[const.NET_ID],
                                              port_dict[const.PORT_ID], vif_id)
        self._l2network_plugin.unplug_interface(tenant_id,
                                                new_net_dict[const.NET_ID],
                                                port_dict[const.PORT_ID])
        port = db.port_get(new_net_dict[const.NET_ID],
                           port_dict[const.PORT_ID])
        vif_id_unplugged = vif_id + '(detached)'
        self.assertEqual(port[const.INTERFACEID], vif_id_unplugged)
        self.tearDownNetworkPortInterface(tenant_id, instance_tenant_id,
                                          instance_id, instance_vif_desc,
                                          new_net_dict[const.NET_ID],
                                          port_dict[const.PORT_ID])

        LOG.debug("test_unplug_interface - END")
    def test_create_port(self, tenant_id='test_network',
                         state=const.PORT_UP):
        """
        Tests creation of Ports.
        """

        LOG.debug("test_create_port - START")
        new_net_dict = self._l2network_plugin.create_network(
                                tenant_id, self.network_name)
        port_dict = self._l2network_plugin.create_port(
                tenant_id, new_net_dict[const.NET_ID], state)
        port = db.port_get(new_net_dict[const.NET_ID],
                           port_dict[const.PORT_ID])
        self.assertEqual(port_dict[const.PORT_STATE], state)
        self.assertEqual(port_dict[const.NET_ID], new_net_dict[const.NET_ID])
        self.assertEqual(port[const.PORTSTATE], state)
        self.assertEqual(port[const.NETWORKID], new_net_dict[const.NET_ID])
        self.tearDownNetworkPort(tenant_id, new_net_dict[const.NET_ID],
                                 port_dict[const.PORT_ID])
        LOG.debug("test_create_port - END")
Пример #11
0
    def tearDown(self):
        """Tear down our tests"""
        try:
            port = db.port_get(self.net_id, self.port_id)
            self._l2network_multiblade.delete_port(
                [tenant_id, self.net_id, self.port_id])
        except exc.NetworkNotFound:
            # We won't always have a port to remove
            pass
        except exc.PortNotFound:
            # We won't always have a port to remove
            pass

        try:
            net = db.network_get(self.net_id)
            self._l2network_multiblade.delete_network([tenant_id, self.net_id])
        except exc.NetworkNotFound:
            # We won't always have a network to remove
            pass
        db.clear_db()
Пример #12
0
    def test_show_port(self, tenant_id='test_tenant'):
        """
        Tests display of Ports
        """

        LOG.debug("test_show_port - START")
        new_net_dict = self._l2network_plugin.create_network(
                                tenant_id, self.network_name)
        port_dict = self._l2network_plugin.create_port(
                        tenant_id, new_net_dict[const.NET_ID], self.port_state)
        get_port_dict = self._l2network_plugin.get_port_details(
                        tenant_id, new_net_dict[const.NET_ID],
                        port_dict[const.PORT_ID])
        port = db.port_get(new_net_dict[const.NET_ID],
                           port_dict[const.PORT_ID])
        self.assertEqual(port[const.PORTSTATE], self.port_state)
        self.assertEqual(get_port_dict[const.PORT_STATE], self.port_state)
        self.tearDownNetworkPort(tenant_id, new_net_dict[const.NET_ID],
                                 port_dict[const.PORT_ID])
        LOG.debug("test_show_port - END")
Пример #13
0
 def delete_port(self, tenant_id, net_id, port_id):
     """
     Deletes a port on a specified Virtual Network,
     if the port contains a remote interface attachment,
     the remote interface should first be un-plugged and
     then the port can be deleted.
     """
     LOG.debug("delete_port() called\n")
     network = db.network_get(net_id)
     port = db.port_get(net_id, port_id)
     attachment_id = port[const.INTERFACEID]
     if not attachment_id:
         self._invoke_device_plugins(self._func_name(), [tenant_id,
                                                         net_id,
                                                         port_id])
         db.port_destroy(net_id, port_id)
         new_port_dict = cutil.make_port_dict(port_id, None, None, None)
         return new_port_dict
     else:
         raise exc.PortInUse(port_id=port_id, net_id=net_id,
                             att_id=attachment_id)
Пример #14
0
    def test_plug_interface(self, tenant_id='test_tenant',
                            remote_interface='new_interface'):
        """
        Tests attachment of interface to the port
        """

        LOG.debug("test_plug_interface - START")
        new_net_dict = self._l2network_plugin.create_network(
                                tenant_id, self.network_name)
        port_dict = self._l2network_plugin.create_port(
                        tenant_id, new_net_dict[const.NET_ID], self.port_state)
        self._l2network_plugin.plug_interface(
                        tenant_id, new_net_dict[const.NET_ID],
                        port_dict[const.PORT_ID], remote_interface)
        port = db.port_get(new_net_dict[const.NET_ID],
                           port_dict[const.PORT_ID])
        self.assertEqual(port[const.INTERFACEID], remote_interface)
        self.tearDownNetworkPortInterface(
                        tenant_id, new_net_dict[const.NET_ID],
                        port_dict[const.PORT_ID])
        LOG.debug("test_plug_interface - END")
Пример #15
0
    def test_update_port(self, tenant_id='test_tenant', state=const.PORT_DOWN):
        """
        Tests updation of Ports.
        """

        LOG.debug("test_update_port - START")
        new_net_dict = self._l2network_plugin.create_network(
            tenant_id, self.network_name)
        port_dict = self._l2network_plugin.create_port(
            tenant_id, new_net_dict[const.NET_ID], self.state)
        update_port_dict = self._l2network_plugin.update_port(
            tenant_id,
            new_net_dict[const.NET_ID],
            port_dict[const.PORT_ID],
            state=state)
        new_port = db.port_get(new_net_dict[const.NET_ID],
                               port_dict[const.PORT_ID])
        self.assertEqual(new_port[const.PORTSTATE], state)
        self.assertEqual(update_port_dict[const.PORT_STATE], state)
        self.tearDownNetworkPort(tenant_id, new_net_dict[const.NET_ID],
                                 port_dict[const.PORT_ID])
        LOG.debug("test_update_port - END")
Пример #16
0
    def test_plug_interface(self,
                            tenant_id='test_tenant',
                            instance_tenant_id='nova',
                            nova_user_id='novaadmin',
                            instance_id=10,
                            vif_id='fe701ddf-26a2-42ea-b9e6-7313d1c522cc'):
        """
        Tests attachment of interface to the port
        """

        LOG.debug("test_plug_interface - START")
        new_net_dict = self._l2network_plugin.create_network(tenant_id,
                                                             self.network_name)
        port_dict = self._l2network_plugin.create_port(tenant_id,
                                                       new_net_dict[const.
                                                       NET_ID], self.state)
        instance_desc = {'project_id': tenant_id,
                         'user_id': nova_user_id}
        host_list = self._l2network_plugin.schedule_host(instance_tenant_id,
                                                         instance_id,
                                                         instance_desc)
        instance_vif_desc = {'project_id': tenant_id,
                             'user_id': nova_user_id,
                             'vif_id': vif_id}
        vif_description = self._l2network_plugin.associate_port(
            instance_tenant_id, instance_id,
            instance_vif_desc)

        self._l2network_plugin.plug_interface(
            tenant_id, new_net_dict[const.NET_ID],
            port_dict[const.PORT_ID], vif_id)
        port = db.port_get(new_net_dict[const.NET_ID],
                           port_dict[const.PORT_ID])
        self.assertEqual(port[const.INTERFACEID], vif_id)
        self.tearDownNetworkPortInterface(
            tenant_id, instance_tenant_id, instance_id, instance_vif_desc,
            new_net_dict[const.NET_ID], port_dict[const.PORT_ID])

        LOG.debug("test_plug_interface - END")