Refactor check_configure_sriov to prevent dublicate adding sriov_pfs
Cuurent implementation of adding objects is dublicating adding
objects that have sriov_pf members.
The patch refactors check_configure_sriov to check if the object
itself or any of its tree members are sriov_pf so adding that object
will happen once
Closes-Bug: #2020100
Change-Id: I3895a5200bc97a294a8b5774c24972f1f58b40bf
(cherry picked from commit 7996a2e79e)
			
			
This commit is contained in:
		| @@ -124,10 +124,14 @@ def parse_opts(argv): | |||||||
|  |  | ||||||
| def check_configure_sriov(obj): | def check_configure_sriov(obj): | ||||||
|     configure_sriov = False |     configure_sriov = False | ||||||
|  |     if isinstance(obj, objects.SriovPF): | ||||||
|  |         configure_sriov = True | ||||||
|  |     elif hasattr(obj, 'members') and obj.members is not None: | ||||||
|         for member in obj.members: |         for member in obj.members: | ||||||
|             if isinstance(member, objects.SriovPF): |             if isinstance(member, objects.SriovPF): | ||||||
|                 configure_sriov = True |                 configure_sriov = True | ||||||
|         elif hasattr(member, "members") and member.members is not None: |                 break | ||||||
|  |             else: | ||||||
|                 configure_sriov = check_configure_sriov(member) |                 configure_sriov = check_configure_sriov(member) | ||||||
|     return configure_sriov |     return configure_sriov | ||||||
|  |  | ||||||
| @@ -282,14 +286,11 @@ def main(argv=sys.argv, main_logger=None): | |||||||
|             obj = objects.object_from_json(iface_json) |             obj = objects.object_from_json(iface_json) | ||||||
|         except utils.SriovVfNotFoundException: |         except utils.SriovVfNotFoundException: | ||||||
|             continue |             continue | ||||||
|         if isinstance(obj, objects.SriovPF): |  | ||||||
|             configure_sriov = True |  | ||||||
|             provider.add_object(obj) |  | ||||||
|         elif hasattr(obj, 'members') and obj.members is not None: |  | ||||||
|         if check_configure_sriov(obj): |         if check_configure_sriov(obj): | ||||||
|             configure_sriov = True |             configure_sriov = True | ||||||
|             provider.add_object(obj) |             provider.add_object(obj) | ||||||
|  |             # Look for the presence of SriovPF as members of LinuxBond and that | ||||||
|  |             # LinuxBond is member of OvsBridge | ||||||
|             sriovpf_member_of_bond_ovs_port_list.extend( |             sriovpf_member_of_bond_ovs_port_list.extend( | ||||||
|                 get_sriovpf_member_of_bond_ovs_port(obj)) |                 get_sriovpf_member_of_bond_ovs_port(obj)) | ||||||
|  |  | ||||||
| @@ -323,7 +324,8 @@ def main(argv=sys.argv, main_logger=None): | |||||||
|                 restart_openvswitch=restart_ovs) |                 restart_openvswitch=restart_ovs) | ||||||
|  |  | ||||||
|     for iface_json in iface_array: |     for iface_json in iface_array: | ||||||
|         # All objects other than the sriov_pf will be added here. |         # All sriov_pfs at top level or at any member level will be | ||||||
|  |         # ignored and all other objects are parsed will be added here. | ||||||
|         # The VFs are expected to be available now and an exception |         # The VFs are expected to be available now and an exception | ||||||
|         # SriovVfNotFoundException shall be raised if not available. |         # SriovVfNotFoundException shall be raised if not available. | ||||||
|         try: |         try: | ||||||
| @@ -331,7 +333,7 @@ def main(argv=sys.argv, main_logger=None): | |||||||
|         except utils.SriovVfNotFoundException: |         except utils.SriovVfNotFoundException: | ||||||
|             if not opts.noop: |             if not opts.noop: | ||||||
|                 raise |                 raise | ||||||
|         if not isinstance(obj, objects.SriovPF): |         if not check_configure_sriov(obj): | ||||||
|             provider.add_object(obj) |             provider.add_object(obj) | ||||||
|  |  | ||||||
|     if configure_sriov and not opts.noop: |     if configure_sriov and not opts.noop: | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 waleedm
					waleedm