mirror of
				https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
				synced 2025-11-03 20:27:54 +00:00 
			
		
		
		
	lf_cleanup.py: modify while loop logic in functions
Signed-off-by: Scott Wedge <scott.wedge@candelatech.com>
This commit is contained in:
		@@ -56,16 +56,17 @@ class lf_clean(Realm):
 | 
			
		||||
 | 
			
		||||
    def cxs_clean(self):
 | 
			
		||||
        still_looking_cxs = True
 | 
			
		||||
        iterations_cxs = 1
 | 
			
		||||
        while still_looking_cxs and iterations_cxs <= 10:
 | 
			
		||||
            iterations_cxs += 1
 | 
			
		||||
            logger.info("cxs_clean: iterations_cxs: {iterations_cxs}".format(iterations_cxs=iterations_cxs))
 | 
			
		||||
        # iterations_cxs = 1
 | 
			
		||||
        # while still_looking_cxs and iterations_cxs <= 10:
 | 
			
		||||
        while still_looking_cxs:
 | 
			
		||||
            # iterations_cxs += 1
 | 
			
		||||
            # logger.info("cxs_clean: iterations_cxs: {iterations_cxs}".format(iterations_cxs=iterations_cxs))
 | 
			
		||||
            cx_json = super().json_get("cx")
 | 
			
		||||
            if cx_json is not None:
 | 
			
		||||
                logger.info("Removing old cross connects")
 | 
			
		||||
                for name in list(cx_json):
 | 
			
		||||
                    if name != 'handler' and name != 'uri' and name != 'empty':
 | 
			
		||||
                        logger.info(name)
 | 
			
		||||
                        # logger.info(name)
 | 
			
		||||
                        req_url = "cli-json/rm_cx"
 | 
			
		||||
                        data = {
 | 
			
		||||
                            "test_mgr": "default_tm",
 | 
			
		||||
@@ -84,23 +85,24 @@ class lf_clean(Realm):
 | 
			
		||||
 | 
			
		||||
    def endp_clean(self):
 | 
			
		||||
        still_looking_endp = True
 | 
			
		||||
        iterations_endp = 0
 | 
			
		||||
        while still_looking_endp and iterations_endp <= 10:
 | 
			
		||||
            iterations_endp += 1
 | 
			
		||||
            logger.info("endp_clean: iterations_endp: {iterations_endp}".format(iterations_endp=iterations_endp))
 | 
			
		||||
        # iterations_endp = 0
 | 
			
		||||
        # while still_looking_endp and iterations_endp <= 10:
 | 
			
		||||
        while still_looking_endp:
 | 
			
		||||
            # iterations_endp += 1
 | 
			
		||||
            # logger.info("endp_clean: iterations_endp: {iterations_endp}".format(iterations_endp=iterations_endp))
 | 
			
		||||
            # get and remove current endps
 | 
			
		||||
            endp_json = super().json_get("endp")
 | 
			
		||||
            if endp_json is not None:
 | 
			
		||||
                logger.info("Removing old endpoints")
 | 
			
		||||
                for name in list(endp_json['endpoint']):
 | 
			
		||||
                    logger.info(list(name)[0])
 | 
			
		||||
                    # logger.info(list(name)[0])
 | 
			
		||||
                    if name[list(name)[0]]["name"] == '':
 | 
			
		||||
                        continue
 | 
			
		||||
                    req_url = "cli-json/rm_endp"
 | 
			
		||||
                    data = {
 | 
			
		||||
                        "endp_name": list(name)[0]
 | 
			
		||||
                    }
 | 
			
		||||
                    logger.info(data)
 | 
			
		||||
                    # logger.info(data)
 | 
			
		||||
                    super().json_post(req_url, data)
 | 
			
		||||
                    time.sleep(.5)
 | 
			
		||||
                time.sleep(1)
 | 
			
		||||
@@ -114,30 +116,24 @@ class lf_clean(Realm):
 | 
			
		||||
 | 
			
		||||
    def sta_clean(self):
 | 
			
		||||
        still_looking_sta = True
 | 
			
		||||
        iterations_sta = 0
 | 
			
		||||
        # TODO: change <=10 to non-static variable
 | 
			
		||||
        while still_looking_sta and iterations_sta <= 10:
 | 
			
		||||
            iterations_sta += 1
 | 
			
		||||
            logger.info("sta_clean: iterations_sta: {iterations_sta}".format(iterations_sta=iterations_sta))
 | 
			
		||||
        # iterations_sta = 0
 | 
			
		||||
        # while still_looking_sta and iterations_sta <= 10:
 | 
			
		||||
        while still_looking_sta:
 | 
			
		||||
            # iterations_sta += 1
 | 
			
		||||
            # logger.info("sta_clean: iterations_sta: {iterations_sta}".format(iterations_sta=iterations_sta))
 | 
			
		||||
            try:
 | 
			
		||||
                #sta_json = super().json_get("/port/?fields=alias".format(resource=self.resource))['interfaces']
 | 
			
		||||
                sta_json = super().json_get("/port/?fields=port+type,alias".format(resource=self.resource))['interfaces']
 | 
			
		||||
                logger.info(sta_json)
 | 
			
		||||
                sta_json = super().json_get("/port/?fields=alias".format(resource=self.resource))['interfaces']
 | 
			
		||||
                # logger.info(sta_json)
 | 
			
		||||
            except TypeError:
 | 
			
		||||
                sta_json = None
 | 
			
		||||
                logger.info("sta_json set to None")
 | 
			
		||||
 | 
			
		||||
            # get and remove current stations
 | 
			
		||||
            if sta_json is not None:
 | 
			
		||||
                logger.info(sta_json)
 | 
			
		||||
                logger.info("Removing old stations ")
 | 
			
		||||
                for name in list(sta_json):
 | 
			
		||||
                    for alias in list(name):
 | 
			
		||||
                        # logger.info("alias {alias}".format(alias=alias))
 | 
			
		||||
                        # if 'sta' in alias:
 | 
			
		||||
                        # this is expecting '1.x.eth0'. everything hits this if statment. hints why the whiphy's are deleted
 | 
			
		||||
                        #if alias != 'eth0':
 | 
			
		||||
                        # if port_type != 'Ethernet' or port_type != 'WIFI-Radio':
 | 
			
		||||
                        if 'sta' in alias:
 | 
			
		||||
                            info = self.name_to_eid(alias)
 | 
			
		||||
                            req_url = "cli-json/rm_vlan"
 | 
			
		||||
@@ -146,7 +142,7 @@ class lf_clean(Realm):
 | 
			
		||||
                                "resource": info[1],
 | 
			
		||||
                                "port": info[2]
 | 
			
		||||
                            }
 | 
			
		||||
                            logger.info(data)
 | 
			
		||||
                            # logger.info(data)
 | 
			
		||||
                            super().json_post(req_url, data)
 | 
			
		||||
                            time.sleep(.5)
 | 
			
		||||
                        if 'wlan' in alias:
 | 
			
		||||
@@ -185,23 +181,21 @@ class lf_clean(Realm):
 | 
			
		||||
                time.sleep(1)
 | 
			
		||||
            else:
 | 
			
		||||
                logger.info("No stations found to cleanup")
 | 
			
		||||
        still_looking_sta = False
 | 
			
		||||
        logger.info("clean_sta still_looking_sta {sta_looking}".format(sta_looking=still_looking_sta))
 | 
			
		||||
        if not still_looking_sta:
 | 
			
		||||
            self.sta_done = True
 | 
			
		||||
        return still_looking_sta
 | 
			
		||||
                still_looking_sta = False
 | 
			
		||||
                logger.info("clean_sta still_looking_sta {sta_looking}".format(sta_looking=still_looking_sta))
 | 
			
		||||
            if not still_looking_sta:
 | 
			
		||||
                self.sta_done = True
 | 
			
		||||
            return still_looking_sta
 | 
			
		||||
 | 
			
		||||
    # cleans all gui or script created objects from Port Mgr tab
 | 
			
		||||
    def clean_all(self):
 | 
			
		||||
        still_looking_sta = True
 | 
			
		||||
        iterations_sta = 0
 | 
			
		||||
        # TODO: change <=10 to non-static variable
 | 
			
		||||
        while still_looking_sta and iterations_sta <= 10:
 | 
			
		||||
            iterations_sta += 1
 | 
			
		||||
            logger.info("sta_clean: iterations_sta: {iterations_sta}".format(iterations_sta=iterations_sta))
 | 
			
		||||
 | 
			
		||||
        while still_looking_sta:
 | 
			
		||||
            try:
 | 
			
		||||
                sta_json = super().json_get("/port/?fields=port+type,alias".format(resource=self.resource))['interfaces']
 | 
			
		||||
                logger.info(sta_json)
 | 
			
		||||
                # logger.info(sta_json)
 | 
			
		||||
                # logger.info(len(sta_json))
 | 
			
		||||
            except TypeError:
 | 
			
		||||
                sta_json = None
 | 
			
		||||
                logger.info("sta_json set to None")
 | 
			
		||||
@@ -209,10 +203,14 @@ class lf_clean(Realm):
 | 
			
		||||
            # get and remove LF Port Mgr objects
 | 
			
		||||
            if sta_json is not None:
 | 
			
		||||
                logger.info("Removing old stations ")
 | 
			
		||||
                # [if LF system is an APU2/CT521a]: if wiphy radios are deleted run the following command and reboot: 
 | 
			
		||||
                # /root/lf_kinstall.pl --lfver 5.4.5 --do_sys_reconfig
 | 
			
		||||
                '''
 | 
			
		||||
                NOTE: [LF system - APU2/CT521a]: if wiphy radios are deleted
 | 
			
		||||
                      run the following command and reboot to fix: 
 | 
			
		||||
                      /root/lf_kinstall.pl --lfver 5.4.5 --do_sys_reconfig
 | 
			
		||||
                '''
 | 
			
		||||
                for name in list(sta_json):
 | 
			
		||||
                    # logger.info(name)
 | 
			
		||||
                    # alias is the eid (ex: 1.1.eth0)
 | 
			
		||||
                    for alias in list(name):
 | 
			
		||||
                        # logger.info(alias)
 | 
			
		||||
                        port_type = name[alias]['port type']
 | 
			
		||||
@@ -225,7 +223,7 @@ class lf_clean(Realm):
 | 
			
		||||
                                "resource": info[1],
 | 
			
		||||
                                "port": info[2]
 | 
			
		||||
                            }
 | 
			
		||||
                            #logger.info(data)
 | 
			
		||||
                            # logger.info(data)
 | 
			
		||||
                            logger.info("Removing {alias}...".format(alias=alias))
 | 
			
		||||
                            super().json_post(req_url, data)
 | 
			
		||||
                            time.sleep(.5)
 | 
			
		||||
@@ -233,21 +231,22 @@ class lf_clean(Realm):
 | 
			
		||||
            else:
 | 
			
		||||
                logger.info("No stations found to cleanup")
 | 
			
		||||
                still_looking_sta = False
 | 
			
		||||
                logger.info("clean_sta still_looking_sta {sta_looking}".format(sta_looking=still_looking_sta))
 | 
			
		||||
                logger.info("clean_all still_looking_sta {sta_looking}".format(sta_looking=still_looking_sta))
 | 
			
		||||
            if not still_looking_sta:
 | 
			
		||||
                self.sta_done = True
 | 
			
		||||
                self.sanitize_done = True
 | 
			
		||||
            return still_looking_sta
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    def bridge_clean(self):
 | 
			
		||||
        still_looking_br = True
 | 
			
		||||
        iterations_br = 0
 | 
			
		||||
        while still_looking_br and iterations_br <= 10:
 | 
			
		||||
            iterations_br += 1
 | 
			
		||||
            logger.info("bridge_clean: iterations_br: {iterations_br}".format(iterations_br=iterations_br))
 | 
			
		||||
        # iterations_br = 0
 | 
			
		||||
        # while still_looking_br and iterations_br <= 10:
 | 
			
		||||
        while still_looking_br:
 | 
			
		||||
            # iterations_br += 1
 | 
			
		||||
            # logger.info("bridge_clean: iterations_br: {iterations_br}".format(iterations_br=iterations_br))
 | 
			
		||||
            try:
 | 
			
		||||
                br_json = super().json_get(
 | 
			
		||||
                    "port/1/1/list?field=alias")['interfaces']
 | 
			
		||||
                # br_json = super().json_get("port/1/1/list?field=alias")['interfaces']
 | 
			
		||||
                br_json = super().json_get("/port/?fields=alias".format(resource=self.resource))['interfaces']
 | 
			
		||||
            except TypeError:
 | 
			
		||||
                br_json = None
 | 
			
		||||
 | 
			
		||||
@@ -258,7 +257,7 @@ class lf_clean(Realm):
 | 
			
		||||
                for name in list(br_json):
 | 
			
		||||
                    for alias in list(name):
 | 
			
		||||
                        if 'br' in alias:
 | 
			
		||||
                            logger.info(alias)
 | 
			
		||||
                            # logger.info(alias)
 | 
			
		||||
                            info = self.name_to_eid(alias)
 | 
			
		||||
                            req_url = "cli-json/rm_vlan"
 | 
			
		||||
                            data = {
 | 
			
		||||
@@ -270,20 +269,20 @@ class lf_clean(Realm):
 | 
			
		||||
                            super().json_post(req_url, data)
 | 
			
		||||
                            time.sleep(.5)
 | 
			
		||||
                time.sleep(1)
 | 
			
		||||
 | 
			
		||||
            else:
 | 
			
		||||
                logger.info("No bridges found to cleanup")
 | 
			
		||||
                still_looking_br = False
 | 
			
		||||
        logger.info("clean_bridge still_looking_br {br_looking}".format(br_looking=still_looking_br))
 | 
			
		||||
        if not still_looking_br:
 | 
			
		||||
            self.br_done = True
 | 
			
		||||
        return still_looking_br
 | 
			
		||||
            logger.info("clean_bridge still_looking_br {br_looking}".format(br_looking=still_looking_br))
 | 
			
		||||
            if not still_looking_br:
 | 
			
		||||
                self.br_done = True
 | 
			
		||||
            return still_looking_br
 | 
			
		||||
 | 
			
		||||
    # Some test have various station names or a station named 1.1.eth2
 | 
			
		||||
    def misc_clean(self):
 | 
			
		||||
        still_looking_misc = True
 | 
			
		||||
        iterations_misc = 0
 | 
			
		||||
        while still_looking_misc and iterations_misc <= 10:
 | 
			
		||||
        # while still_looking_misc and iterations_misc <= 10:
 | 
			
		||||
        while still_looking_misc:
 | 
			
		||||
            iterations_misc += 1
 | 
			
		||||
            logger.info("misc_clean: iterations_misc: {iterations_misc}".format(iterations_misc=iterations_misc))
 | 
			
		||||
            try:
 | 
			
		||||
@@ -294,12 +293,12 @@ class lf_clean(Realm):
 | 
			
		||||
 | 
			
		||||
            # get and remove current stations
 | 
			
		||||
            if misc_json is not None:
 | 
			
		||||
                logger.info(misc_json)
 | 
			
		||||
                # logger.info(misc_json)
 | 
			
		||||
                logger.info("Removing misc station names phy, 1.1.eth (malformed station name) ")
 | 
			
		||||
                for name in list(misc_json):
 | 
			
		||||
                    for alias in list(name):
 | 
			
		||||
                        if 'phy' in alias and 'wiphy' not in alias:
 | 
			
		||||
                            logger.info(alias)
 | 
			
		||||
                            # logger.info(alias)
 | 
			
		||||
                            info = self.name_to_eid(alias)
 | 
			
		||||
                            req_url = "cli-json/rm_vlan"
 | 
			
		||||
                            data = {
 | 
			
		||||
@@ -322,17 +321,17 @@ class lf_clean(Realm):
 | 
			
		||||
                                "resource": info[1],
 | 
			
		||||
                                "port": info_2
 | 
			
		||||
                            }
 | 
			
		||||
                            logger.info(data)
 | 
			
		||||
                            # logger.info(data)
 | 
			
		||||
                            super().json_post(req_url, data)
 | 
			
		||||
                            time.sleep(.5)
 | 
			
		||||
                time.sleep(1)
 | 
			
		||||
            else:
 | 
			
		||||
                logger.info("No misc found to cleanup")
 | 
			
		||||
                still_looking_misc = False
 | 
			
		||||
        logger.info("clean_misc still_looking_misc {misc_looking}".format(misc_looking=still_looking_misc))
 | 
			
		||||
        if not still_looking_misc:
 | 
			
		||||
            self.misc_done = True
 | 
			
		||||
        return still_looking_misc
 | 
			
		||||
            logger.info("clean_misc still_looking_misc {misc_looking}".format(misc_looking=still_looking_misc))
 | 
			
		||||
            if not still_looking_misc:
 | 
			
		||||
                self.misc_done = True
 | 
			
		||||
            return still_looking_misc
 | 
			
		||||
 | 
			
		||||
    '''
 | 
			
		||||
        1: delete cx
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user