[hostcfgd] hostcfgd will exit when set hostname in DEVICE_METADATA #3394
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Signed-off-by: ouxiaolong ouxiaolong@asterfusion.com
- What I did
1.when execute ‘redis-cli -n 4 HSET "DEVICE_METADATA|localhost" hostname 48S-wz.’ in SONiC bash ,hostcfgdwill exit,and there is a Traceback information in /var/log/syslog like this:
Aug 28 17:35:14.551892 48S-wz INFO hostcfgd[21512]: Traceback (most recent call last):
Aug 28 17:35:14.552642 48S-wz INFO hostcfgd[21512]: File "/usr/bin/hostcfgd", line 232, in
Aug 28 17:35:14.553171 48S-wz INFO hostcfgd[21512]: main()
Aug 28 17:35:14.553701 48S-wz INFO hostcfgd[21512]: File "/usr/bin/hostcfgd", line 228, in main
Aug 28 17:35:14.554190 48S-wz INFO hostcfgd[21512]: daemon.start()
Aug 28 17:35:14.554735 48S-wz INFO hostcfgd[21512]: File "/usr/bin/hostcfgd", line 223, in start
Aug 28 17:35:14.555217 48S-wz INFO hostcfgd[21512]: self.config_db.listen()
Aug 28 17:35:14.555704 48S-wz INFO hostcfgd[21512]: File "/usr/local/lib/python2.7/dist-packages/swsssdk/configdb.py", line 102, in listen
Aug 28 17:35:14.556188 48S-wz INFO hostcfgd[21512]: self.__fire(table, row, data)
Aug 28 17:35:14.556750 48S-wz INFO hostcfgd[21512]: File "/usr/local/lib/python2.7/dist-packages/swsssdk/configdb.py", line 87, in __fire
Aug 28 17:35:14.557263 48S-wz INFO hostcfgd[21512]: handler(table, key, data)
Aug 28 17:35:14.557764 48S-wz INFO hostcfgd[21512]: File "/usr/bin/hostcfgd", line 222, in
Aug 28 17:35:14.558266 48S-wz INFO hostcfgd[21512]: self.config_db.subscribe('DEVICE_METADATA', lambda table, key, data: self.hostname_handler(key, data))
Aug 28 17:35:14.558821 48S-wz INFO hostcfgd[21512]: File "/usr/bin/hostcfgd", line 189, in hostname_handler
Aug 28 17:35:14.559325 48S-wz INFO hostcfgd[21512]: if not is_valid_hostname(hostname):
Aug 28 17:35:14.559830 48S-wz INFO hostcfgd[21512]: File "/usr/bin/hostcfgd", line 27, in is_valid_hostname
Aug 28 17:35:14.560476 48S-wz INFO hostcfgd[21512]: if hostname[-1] == ".":
Aug 28 17:35:14.560993 48S-wz INFO hostcfgd[21512]: UnboundLocalError: local variable 'hostname' referenced before assignment
2.after I fixed it, there are some other err log in /var/log/syslog like this
Aug 29 10:13:33.583491 48S-wz INFO hostcfgd[27773]: Set hostname in bgp container
Aug 29 10:13:33.880805 48S-wz INFO hostcfgd[27773]: hostname: the specified hostname is invalid
Aug 29 10:13:36.008242 48S-wz INFO hostcfgd[27773]: Set hostname in swss container
Aug 29 10:13:36.276700 48S-wz INFO hostcfgd[27773]: hostname: the specified hostname is invalid
Aug 29 10:13:38.560297 48S-wz INFO hostcfgd[27773]: Set hostname in syncd container
Aug 29 10:13:38.853333 48S-wz INFO hostcfgd[27773]: hostname: the specified hostname is invalid
Aug 29 10:13:41.084499 48S-wz INFO hostcfgd[27773]: Set hostname in dhcp_relay container
Aug 29 10:13:41.357581 48S-wz INFO hostcfgd[27773]: hostname: the specified hostname is invalid
Aug 29 10:13:43.669783 48S-wz INFO hostcfgd[27773]: Set hostname in radv container
Aug 29 10:13:43.934936 48S-wz INFO hostcfgd[27773]: hostname: the specified hostname is invalid
Aug 29 10:13:46.110223 48S-wz INFO hostcfgd[27773]: Set hostname in snmp container
Aug 29 10:13:46.361012 48S-wz INFO hostcfgd[27773]: hostname: the specified hostname is invalid
Aug 29 10:13:48.693676 48S-wz INFO hostcfgd[27773]: Set hostname in teamd container
Aug 29 10:13:48.965765 48S-wz INFO hostcfgd[27773]: hostname: the specified hostname is invalid
Aug 29 10:13:51.149399 48S-wz INFO hostcfgd[27773]: Set hostname in lldp container
Aug 29 10:13:51.433085 48S-wz INFO hostcfgd[27773]: hostname: the specified hostname is invalid
Aug 29 10:13:53.758775 48S-wz INFO hostcfgd[27773]: Set hostname in pmon container
Aug 29 10:13:54.029597 48S-wz INFO hostcfgd[27773]: hostname: the specified hostname is invalid
Aug 29 10:13:56.273657 48S-wz INFO hostcfgd[27773]: Set hostname in database container
Aug 29 10:13:56.549141 48S-wz INFO hostcfgd[27773]: hostname: the specified hostname is invalid
- How I did it
1.fix is_valid_hostname in hostcfgd
2. log warning when hostname is invalid
- How to verify it
execute ‘redis-cli -n 4 HSET "DEVICE_METADATA|localhost" hostname 48S-wz.’ in SONiC bash, then check log in /var/log/syslog
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)