Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCS CLI tools crash on empty hosts config #351

Closed
cnweaver opened this issue Sep 6, 2023 · 0 comments · Fixed by #353
Closed

OCS CLI tools crash on empty hosts config #351

cnweaver opened this issue Sep 6, 2023 · 0 comments · Fixed by #353
Assignees
Labels
bug Something isn't working

Comments

@cnweaver
Copy link
Contributor

cnweaver commented Sep 6, 2023

If the site YAML contains the hosts key but its value is empty (implicitly null), ocsbow, ocs-local-support, etc. crash:

$ cat ${OCS_CONFIG_DIR}/default.yaml
# Site configuration for a fake observatory.
hub:

  wamp_server: ws://localhost:8001/ws
  wamp_http: http://localhost:8001/call
  wamp_realm: test_realm
  address_root: observatory

hosts:

$ ocsbow status                                                          
Traceback (most recent call last):
  File "$VIRTUAL_ENV/bin/ocsbow", line 8, in <module>
    sys.exit(main())
  File "$VIRTUAL_ENV/lib/python3.7/site-packages/ocs/ocsbow.py", line 821, in main
    args, site_config = get_args_and_site_config(args)
  File "$VIRTUAL_ENV/lib/python3.7/site-packages/ocs/ocsbow.py", line 100, in get_args_and_site_config
    args_ = ocs.site_config.parse_args(agent_class=agent_class, parser=parser, args=args)
  File "$VIRTUAL_ENV/lib/python3.7/site-packages/ocs/site_config.py", line 699, in parse_args
    site, host, instance = get_config(pre_args, agent_class=agent_class)
  File "$VIRTUAL_ENV/lib/python3.7/site-packages/ocs/site_config.py", line 422, in get_config
    site_config = SiteConfig.from_yaml(site_file)
  File "$VIRTUAL_ENV/lib/python3.7/site-packages/ocs/site_config.py", line 61, in from_yaml
    self = cls.from_dict(data)
  File "$VIRTUAL_ENV/lib/python3.7/site-packages/ocs/site_config.py", line 50, in from_dict
    for k, v in data.get('hosts', {}).items():
AttributeError: 'NoneType' object has no attribute 'items'

Such a config file could be viewed as ill-formed and rejected, but it would be nice if this were diagnosed with a clear message to the user instead of crashing with an internal error, as using YAML makes this mistake very easy to make.

@mhasself mhasself self-assigned this Sep 6, 2023
@mhasself mhasself mentioned this issue Sep 13, 2023
6 tasks
@BrianJKoopman BrianJKoopman added the bug Something isn't working label Sep 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants