def _clear_vlans(self, vfab_id, ports, config, port_type=_EP,
                    vlan_type='untag', lag_id=None, commit=False):
        """Clear all VLAN definitions with specified ports.

        @param self  CFABdriver's instance
        @param vfab_id  the string of VFAB ID
        @param ports  a string of the ports which is separated by ','
        @param config a string of a candidate-config
        @return None or string of the modified ifgroups separated by ','
        """

        # (yushiro): ifgroup won't delete because it can not determine
        #            whether ifgroup is created by plugin or not.
        indices = search_ifgroup_indices(ports, config, lag_id=lag_id)
        vlan_ifgs = _get_all_vfab_vlans_and_ifgroups(vfab_id, config,
                                                     vlan_type='untag')
        updated_vlan_ifgs = copy.deepcopy(vlan_ifgs)
        cmds = []
        for vlanid in sorted(vlan_ifgs.keys()):
            vlan = str(vlanid)
            is_delete = False
            # Target ifgroup_ids exists but vfab vlan definition does not exist
            # or ifgroup_id doesn't exist but vfab vlan definition exists.
            if None in [vlan_ifgs[vlan]] or not indices:
                LOG.debug(_("ifgroup with %(p)s for VLAN(%(v)s)has already"
                            "deleted. Skip clear_vlan."), dict(p=ports,
                                                               v=vlanid))
                continue
            eliminated = fj_util.eliminate_val(vlan_ifgs[vlan], indices)
            updated_vlan_ifgs[vlan] = eliminated
            # VLAN is configured with the only ifgroup_id
            if not eliminated:
                is_delete = True

            common_def = "vfab {vfab} vlan {vlan} {port_type} {vlan_type}"
            # Delete VFAB VLAN definition
            if is_delete:
                command = "no" + " " + common_def
                cmds.append(command.format(vfab=vfab_id, vlan=vlanid,
                                           port_type=port_type,
                                           vlan_type=vlan_type))
            # Reject ifgroup_id from VFAB VLAN definition
            else:
                command = common_def + " " + "{ifgroup}"
                cmds.append(command.format(vfab=vfab_id, vlan=vlanid,
                                           port_type=port_type,
                                           vlan_type=vlan_type,
                                           ifgroup=eliminated))
        self.mgr.configure(cmds, commit=commit)
        return updated_vlan_ifgs
 def test_found_between_ranges_next_to_the_lowest_and_highest(self):
     definition = "1-3"
     target = [2]
     result = fj_util.eliminate_val(definition, target)
     self.assertEqual("1,3", result)
 def test_found_between_ranges_next_to_the_highest(self):
     definition = "1-10"
     target = [9]
     result = fj_util.eliminate_val(definition, target)
     self.assertEqual("10,1-8", result)
 def test_found_between_ranges(self):
     definition = "1-10"
     target = [5]
     result = fj_util.eliminate_val(definition, target)
     self.assertEqual("1-4,6-10", result)
 def test_found_range_of_high(self):
     definition = "1-10"
     target = [10]
     result = fj_util.eliminate_val(definition, target)
     self.assertEqual("1-9", result)
 def test_found_range_of_lowest_next_to_highest(self):
     definition = "1-2"
     target = [1]
     result = fj_util.eliminate_val(definition, target)
     self.assertEqual("2", result)
 def test_found_the_highest(self):
     definition = "1,2,3"
     target = [3]
     result = fj_util.eliminate_val(definition, target)
     self.assertEqual("1,2", result)
 def test_definition_is_None(self):
     definition = None
     target = [1]
     result = fj_util.eliminate_val(definition, target)
     self.assertIsNone(result)
 def test_specify_target_with_list_and_include_2(self):
     definition = "1-5"
     target = [1, 2]
     result = fj_util.eliminate_val(definition, target)
     self.assertEqual("3-5", result)
 def test_no_matched_with_boundary(self):
     definition = "1-10"
     target = [100]
     result = fj_util.eliminate_val(definition, target)
     self.assertEqual("1-10", result)
 def test_no_matched(self):
     definition = "10,11"
     target = [100]
     result = fj_util.eliminate_val(definition, target)
     self.assertEqual("10,11", result)
 def test_matches_only_one(self):
     definition = "100"
     target = [100]
     result = fj_util.eliminate_val(definition, target)
     self.assertEqual("", result)