salt-ext-modules-vmware icon indicating copy to clipboard operation
salt-ext-modules-vmware copied to clipboard

Profile behavior behaves badly when unsuccessful

Open waynew opened this issue 3 years ago • 1 comments

See #351 for more info, but generally speaking there are two behaviors when using profiles that are just terrible.

<snip>
  File "/home/wayne/mine/review-saltext/src/saltext/vmware/utils/connect.py", line 45, in get_config
    credentials = conf[profile]
KeyError: 'fnord'

A huge stack trace appears when doing something like salt-call vmware_vm.list profile=fnord and the profile doesn't exist.

We could pretty easily catch a KeyError here and then look for profiles that might match, and provide a useful error/exit like "Profile 'fnord' does not exist. Perhaps you meant X?"

Alternatively, if you don't have any config data in the base and only have profiles, and do not provide a profile, you get this:

<snip>
  File "/home/wayne/mine/review-saltext/src/saltext/vmware/utils/connect.py", line 134, in get_service_instance
    config = get_config(config=config, profile=profile, esxi_host=esxi_host)
  File "/home/wayne/mine/review-saltext/src/saltext/vmware/utils/connect.py", line 60, in get_config
    raise ValueError("Cannot create service instance, VMware credentials incomplete.")
ValueError: Cannot create service instance, VMware credentials incomplete.

Also super useless.

Basically what we should do in this case is check if there's a host/user/pass, and if any of those things are missing then we should provide a useful message such as:

No credentials found in the base profile, and no profiles found.

Or

No credentials found in the base profile, but profiles <a, b, c> exist. Are you missing profile=a?

Something to that effect.

waynew avatar Jan 20 '23 18:01 waynew

This is the behavior when using connect.get_service_instance but a different handling/error is done when using connect.request which is used by other modules. Not sure how profiles are supposed to work, is there any guide for using them?

jgangel avatar Jan 23 '23 14:01 jgangel