Fix for neutron-netns-cleanup-cron.py script.

Change-Id: I40a9b42204db4455f656e2711dda8ca136b201cb
This commit is contained in:
Alexey Terekhin 2022-06-28 10:31:05 -07:00 committed by Alexey
parent 820788a501
commit 7b05f28e82
3 changed files with 31 additions and 17 deletions

View File

@ -14,7 +14,7 @@ apiVersion: v1
appVersion: v1.0.0
description: OpenStack-Helm Neutron
name: neutron
version: 0.2.20
version: 0.2.21
home: https://docs.openstack.org/neutron/latest/
icon: https://www.openstack.org/themes/openstack/images/project-mascots/Neutron/OpenStack_Project_Neutron_vertical.png
sources:

View File

@ -6,12 +6,13 @@ import time
import socket
from neutron.common import config
from oslo_config import cfg
from oslo_concurrency import processutils
from neutron.agent.linux import dhcp
from neutron.agent.l3 import namespaces
from neutron.agent.l3 import dvr_snat_ns
from neutron.agent.l3 import dvr_fip_ns
from neutron.cmd.netns_cleanup import setup_conf
from neutron.cmd.netns_cleanup import destroy_namespace
from neutron.cmd.netns_cleanup import unplug_device
from neutron.cmd.netns_cleanup import eligible_for_deletion
from neutron.conf.agent import common as agent_config
from neutron.agent.linux import ip_lib
@ -31,10 +32,24 @@ def get_neutron_creds():
'username': os.getenv('OS_USERNAME', 'admin'),
'cafile' : os.getenv('OS_CACERT','/var/lib/neutron/openstack-helm/openstack-helm.crt'),
'insecure' : os.getenv('NEUTRON_CLEANUP_INSECURE', 'true'),
'debug': os.getenv('NEUTRON_CLEANUP_DEBUG', 'false'),
'wait': os.getenv('NEUTRON_CLEANUP_TIMEOUT', '1800')}
'debug': os.getenv('NEUTRON_CLEANUP_DEBUG', 'true'),
'wait': os.getenv('NEUTRON_CLEANUP_TIMEOUT', '600')}
return opts
def ldestroy_namespace(conf, namespace):
try:
ip = ip_lib.IPWrapper(namespace=namespace)
if ip.netns.exists(namespace):
cmd = ['ip', 'netns', 'pids', namespace]
output = processutils.execute(*cmd, run_as_root=True, root_helper=conf.AGENT.root_helper)
for pid in output[0].splitlines():
utils.kill_process(pid, signal.SIGTERM, run_as_root=True, root_helper=conf.AGENT.root_helper)
for device in ip.get_devices():
unplug_device(device)
ip.garbage_collect_namespace()
except Exception as e:
sys.stderr.write("Error - unable to destroy namespace: {} : {}\n".format(namespace, e))
def net_list(neutron_get):
hosts = dict()
net_list = neutron_get.list_networks()
@ -64,26 +79,26 @@ def del_bad_dhcp(dhcp_ns, dhcp_hosts, conf, dhcp_prefix, debug):
cut_ns_name = ns[len(dhcp_prefix):]
if cut_ns_name in dhcp_hosts:
if hostname not in dhcp_hosts[cut_ns_name]:
destroy_namespace(conf, ns, conf.force)
ldestroy_namespace(conf, ns)
if debug:
sys.stdout.write("DEBUG: {} host {} deleted {} because host wrong\n"
sys.stderr.write("DEBUG: {} host {} deleted {} because host wrong\n"
.format(sys.argv[0], hostname, ns))
else:
if debug:
sys.stdout.write("DEBUG: {} host {} {} looks ok\n"
sys.stderr.write("DEBUG: {} host {} {} looks ok\n"
.format(sys.argv[0], hostname, ns))
else:
destroy_namespace(conf, ns, conf.force)
ldestroy_namespace(conf, ns)
if debug:
sys.stdout.write("DEBUG: {} host {} deleted {} because no related network found\n"
sys.stderr.write("DEBUG: {} host {} deleted {} because no related network found\n"
.format(sys.argv[0], hostname, ns))
def del_bad_not_dhcp(not_dhcp_ns, conf, debug):
for ns in not_dhcp_ns:
if eligible_for_deletion(conf, ns, conf.force):
destroy_namespace(conf, ns, conf.force)
ldestroy_namespace(conf, ns)
if debug:
sys.stdout.write("DEBUG: {} host {} deleted {} because no IP addr\n"
sys.stderr.write("DEBUG: {} host {} deleted {} because no IP addr\n"
.format(sys.argv[0], hostname, ns))
if __name__ == "__main__":
@ -118,17 +133,17 @@ if __name__ == "__main__":
del_bad_dhcp(dhcp_ns, dhcp_hosts, conf, DHCP_NS_PREFIX, debug)
else:
if debug:
sys.stdout.write("DEBUG: {} host {} no dhcp ns found\n"
sys.stderr.write("DEBUG: {} host {} no dhcp ns found\n"
.format(sys.argv[0], hostname))
if not_dhcp_ns:
del_bad_not_dhcp(not_dhcp_ns, conf, debug)
else:
if debug:
sys.stdout.write("DEBUG: {} host {} no not_dhcp ns found\n"
sys.stderr.write("DEBUG: {} host {} no not_dhcp ns found\n"
.format(sys.argv[0], hostname))
else:
if debug:
sys.stdout.write("DEBUG: {} host {} no ns found at all\n"
sys.stderr.write("DEBUG: {} host {} no ns found at all\n"
.format(sys.argv[0], hostname))
except Exception as ex:
sys.stderr.write(
@ -139,6 +154,4 @@ if __name__ == "__main__":
sys.stderr.write(
"Cleaning network namespaces caught an exception")
time.sleep(30)
finally:
cfg.CONF.clear()
time.sleep(timeout)
time.sleep(timeout)

View File

@ -34,4 +34,5 @@ neutron:
- 0.2.18 Updated naming for subchart compatibility
- 0.2.19 Added qdhcp NS host validation for deleting wrong namespaces.
- 0.2.20 Add Xena and Yoga values overrides
- 0.2.21 Fix for qdhcp NS host validation for deleting wrong namespaces.
...