test suite reviews and discussions
 help / color / mirror / Atom feed
* [dts] [PATCH]framework: Delete NetDevice object after virtual machine shutdown
@ 2016-03-11  9:04 Lijuan Tu
  2016-03-13 12:54 ` Liu, Yong
  0 siblings, 1 reply; 2+ messages in thread
From: Lijuan Tu @ 2016-03-11  9:04 UTC (permalink / raw)
  To: dts, yong.liu

Signed-off-by: Lijuan Tu <lijuanx.a.tu@intel.com>
---
 framework/virt_dut.py | 16 ++++++++++++++++
 nics/net_device.py    | 15 +++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/framework/virt_dut.py b/framework/virt_dut.py
index 9bf75dc..019a9f2 100644
--- a/framework/virt_dut.py
+++ b/framework/virt_dut.py
@@ -39,6 +39,7 @@ from settings import NICS, LOG_NAME_SEP, get_netdev
 from project_dpdk import DPDKdut
 from dut import Dut
 from net_device import GetNicObj
+from net_device import RemoveNicObj
 
 
 class VirtDut(DPDKdut):
@@ -75,10 +76,25 @@ class VirtDut(DPDKdut):
         self.logger.config_suite(self.host_dut.test_classname, 'virtdut')
 
     def close(self):
+        # Close ssh session
         if self.session:
             self.session.close()
+            self.session = None
         if self.alt_session:
             self.alt_session.close()
+            self.alt_session = None
+
+        # Remove Network object
+        vf_ports = self.get_vf_net_divce()
+        RemoveNicObj(self, vf_ports)
+
+    def get_vf_net_divce(self):
+        vf_port = []
+        for port_info in self.host_dut.ports_info:
+            if 'vfs_port' in port_info.keys():
+                for port in port_info['vfs_port']:
+                    vf_port.append(port)
+        return vf_port
 
     def set_nic_type(self, nic_type):
         """
diff --git a/nics/net_device.py b/nics/net_device.py
index 73750f5..8c967ae 100644
--- a/nics/net_device.py
+++ b/nics/net_device.py
@@ -830,6 +830,14 @@ def get_from_list(host, bus_id, devfun_id):
                 return nic['port']
     return None
 
+def remove_from_list(host, obj):
+    """
+    Remove network device object from global structure
+    Parameter will by host ip, netdevice object
+    """
+    for nic in NICS_LIST:
+        if host == nic['host']:
+            NICS_LIST.remove(nic)
 
 def GetNicObj(crb, bus_id, devfun_id):
     """
@@ -862,3 +870,10 @@ def GetNicObj(crb, bus_id, devfun_id):
 
     add_to_list(crb.crb['My IP'], obj)
     return obj
+
+def RemoveNicObj(crb, objs):
+    """
+    Remove network device object.
+    """
+    for obj in objs:
+        remove_from_list(crb.crb['My IP'], obj)
-- 
2.5.0

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [dts] [PATCH]framework: Delete NetDevice object after virtual machine shutdown
  2016-03-11  9:04 [dts] [PATCH]framework: Delete NetDevice object after virtual machine shutdown Lijuan Tu
@ 2016-03-13 12:54 ` Liu, Yong
  0 siblings, 0 replies; 2+ messages in thread
From: Liu, Yong @ 2016-03-13 12:54 UTC (permalink / raw)
  To: Tu, LijuanX A, dts

Hi Lijuan,

> -----Original Message-----
> From: Tu, LijuanX A
> Sent: Friday, March 11, 2016 5:05 PM
> To: dts@dpdk.org; Liu, Yong
> Cc: Tu, LijuanX A
> Subject: [dts][PATCH]framework: Delete NetDevice object after virtual
> machine shutdown
> 
> Signed-off-by: Lijuan Tu <lijuanx.a.tu@intel.com>
> ---
>  framework/virt_dut.py | 16 ++++++++++++++++
>  nics/net_device.py    | 15 +++++++++++++++
>  2 files changed, 31 insertions(+)
> 
> diff --git a/framework/virt_dut.py b/framework/virt_dut.py
> index 9bf75dc..019a9f2 100644
> --- a/framework/virt_dut.py
> +++ b/framework/virt_dut.py
> @@ -39,6 +39,7 @@ from settings import NICS, LOG_NAME_SEP, get_netdev
>  from project_dpdk import DPDKdut
>  from dut import Dut
>  from net_device import GetNicObj
> +from net_device import RemoveNicObj
> 
> 
>  class VirtDut(DPDKdut):
> @@ -75,10 +76,25 @@ class VirtDut(DPDKdut):
>          self.logger.config_suite(self.host_dut.test_classname, 'virtdut')
> 
>      def close(self):
> +        # Close ssh session
>          if self.session:
>              self.session.close()
> +            self.session = None
>          if self.alt_session:
>              self.alt_session.close()
> +            self.alt_session = None
> +
> +        # Remove Network object
> +        vf_ports = self.get_vf_net_divce()
> +        RemoveNicObj(self, vf_ports)
> +
RemoveNicObj remove all network objects from crb, there's no need to generate VF list.
Just call RemoveNicObjs(self) is enough.

> +    def get_vf_net_divce(self):
> +        vf_port = []
> +        for port_info in self.host_dut.ports_info:
> +            if 'vfs_port' in port_info.keys():
> +                for port in port_info['vfs_port']:
> +                    vf_port.append(port)
> +        return vf_port
> 
>      def set_nic_type(self, nic_type):
>          """
> diff --git a/nics/net_device.py b/nics/net_device.py
> index 73750f5..8c967ae 100644
> --- a/nics/net_device.py
> +++ b/nics/net_device.py
> @@ -830,6 +830,14 @@ def get_from_list(host, bus_id, devfun_id):
>                  return nic['port']
>      return None
> 
> +def remove_from_list(host, obj):
> +    """
> +    Remove network device object from global structure
> +    Parameter will by host ip, netdevice object
> +    """
> +    for nic in NICS_LIST:
> +        if host == nic['host']:
> +            NICS_LIST.remove(nic)
> 

In this function, parameter obj is useless. If only intend to remove all network objects of crb, only need one parameter.

>  def GetNicObj(crb, bus_id, devfun_id):
>      """
> @@ -862,3 +870,10 @@ def GetNicObj(crb, bus_id, devfun_id):
> 
>      add_to_list(crb.crb['My IP'], obj)
>      return obj
> +
> +def RemoveNicObj(crb, objs):
> +    """
> +    Remove network device object.
> +    """
> +    for obj in objs:
> +        remove_from_list(crb.crb['My IP'], obj)
> --
> 2.5.0

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-03-13 12:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-11  9:04 [dts] [PATCH]framework: Delete NetDevice object after virtual machine shutdown Lijuan Tu
2016-03-13 12:54 ` Liu, Yong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).