Skip to content

[discussion] refactor inconsistent module naming #30533

Closed

Description

@sjorge

As mentioned by @damon-atkins in PR #30414

There are indeed lots of ways modules get named, below is a table of what we currently have and what there virtualname is.

filename virtualname loaded
bsd_shadow.py shadow os = %BSD%
darwin_pkgutil.py darwin_pkgutil os = MacOS
darwin_sysctl.py sysctl os = MacOS
deb_apache.py apache os_family = Debian
deb_postgres.py postgres which = pg_createcluster
debian_ip.py ip os_family = Debian
debian_service.py service os in ('Debian', 'Raspbian', 'Devuan')
freebsd_sysctl.py sysctl os = FreeBSD
freebsdjail.py jail os = FreeBSD
freebsdkmod.py kmod kernel = FreeBSD
freebsdpkg.py pkg os = FreeBSD and os_release > 10
freebsdports.py ports os = FreeBSD
freebsdservice.py service os = FreeBSD
gentoo_service.py service os = Gentoo
linux_acl.py acl which = getfacl
linux_ip.py ip which = ip and not os_family in ('Debian', 'RedHat')
linux_lvm.py lvm which = lvm
linux_sysctl.py sysctl kernel = Linux
mac_group.py group kernel = Darwin and os_releaseinfo > (10, 7)
mac_shadow.py shadow salt.utils.is_darwin
mac_softwareupdate.py softwareupdate salt.utils.is_darwin
mac_timezone.py timezone salt.utils.is_darwin
mac_user.py user kernel = Darwin and os_releaseinfo > (10, 7)
netbsd_sysctl.py sysctl os = NetBSD
netbsdservice.py service os = NetBSD and path /etc/rc.subr
openbsd_sysctl.py sysctl os = OpenBSD
openbsdpkg.py pkg os = OpenBSD
openbsdservice.py service os = OpenBSD and path /etc/rc.d/rc.subr and not path /usr/sbin/rcctl
openbsdrcctl.py service os = OpenBSD and path /usr/sbin/rcctl
osxdesktop.py desktop salt.utils.is_darwin
rh_ip.py ip os_family = RedHat
smartos_imgadm.py imgadm salt.utils.is_smartos_globalzone and which = imgadm
smartos_virt.py virst vmadm in modules
smartos_vmadm.py vmadm salt.utils.is_smartos_globalzone and which = vmadm
solaris_fmadm.py fmadm salt.utils.is_sunos() and which = fmdump and which = fmadm
solaris_group.py group kernel = SunOS
solaris_shadow.py shadow kernel = SunOS
solaris_system.py system salt.utils.is_sunos and which = shutdown
solaris_user.py user kernel = SunOS and HAS_PWD
solarisips.py pkg kernel = SunOS and kernelrelease > 5.10
solarispkg.py pkg kernel = SunOS and kernelrelease <= 5.10
win_autoruns.py autoruns salt.utils.is_windows
win_dacl.py win_dacl salt.utils.is_windows and HAS_WINDOWS_MODULES
win_disk.py disk salt.utils.is_windows
win_dns_client.py win_dns_client salt.utils.is_windows
win_dsc.py dsc salt.utils.is_windows
win_file.py file salt.utils.is_windows and HAS_WINDOWS_MODULES
win_firewall.py firewall salt.utils.is_windows
win_groupadd.py group salt.utils.is_windows and HAS_DEPENDENCIES
win_iis.py win_iis salt.utils.is_windows
win_ip.py ip salt.utils.is_windows
win_network.py network salt.utils.is_windows and HAS_DEPENDENCIES
win_ntp.py ntp salt.utils.is_windows
win_path.py win_path salt.utils.is_windows and HAS_WIN32
win_pkg.py pkg salt.utils.is_windows and HAS_DEPENDENCIES
win_powercfg.py powercfg os = Windows
win_repo.py winrepo salt.utils.is_windows
win_servermanager.py win_servermanager salt.utils.is_windows
win_service.py service salt.utils.is_windows
win_shadow.py shadow salt.utils.is_windows
win_status.py status salt.utils.is_windows and has_required_packages:
win_system.py system salt.utils.is_windows and HAS_WIN32NET_MODS
win_task.py task salt.utils.is_windows and HAS_DEPENDENCIES
win_timezone.py timezone salt.utils.is_windows and which = tzutil
win_update.py update salt.utils.is_windows and HAS_DEPENDENCIES
win_useradd.py user salt.utils.is_windows and HAS_WIN32NET_MODS
win_wua.py win_wua salt.utils.is_windows and HAS_DEPENDENCIES

^ the list probably not even complete, aptpkg, yumpkg,... come to mind

In have a proposal to clean this up, I will update this issues this weekend with a proposal to refactor this. Seeing this will be a massive change (not feature wise but layout wise) I think It's best there is a discussion up front so there is no wasted time doing stuff that won't get merged.

Activity

  1. sjorge commented on Jan 22, 2016

    @sjorge
    ContributorAuthor

    I propose the following naming convention:

    {virtualname}[_{variant}][_{os|os_family|kernel}].py

    I also realized there is no proper platform grains. e.g.

    bsd = os:openbsd, os:freebsd, ...
    linux = kernel:linux
    solaris = kernel:sunos(, kernel:illumos*)
    windows = kernel:windows

    examples:

    module format notes
    gem.py {virtualname}.py gem works the same on all platforms, nothing special
    user_linux.py {virtualname}_{os}.py linux systems have there own flavor
    user_solaris.py {virtualname}_{os}.py solaris-like systems have there own flavor
    user_bsd.py {virtualname}_{os_variant}.py bsd systems have there own flavor
    ip_debian.py {virtualname}_{os_family}.py debian family linux systems do it like X
    ip_redhat.py {virtualname}_{os_family}.py redhat family linux systems do it like Y
    ip_win.py {virtualname}_{os}.py windows systems do it like X
    vmadm_smartos.py {virtualname}_{os}.py vmadm is very specific to SmartOS
    pkg_apt.py {virtualname}_{variant}.py some systems use apt to manage packages
    pkg_yum.py {virtualname}_{variant}.py some systems use yum to manage packages
    pkg_pkg_solaris.py {virtualname}_{variant}_{os_family}.py solaris systems use pkg to manage packages, tool is not compatible with openbsd pkg
    pkg_pkg_openbsd.py {virtualname}_{variant}_{os}.py openbsd systems use pkg to manage packages, tool is not compatible with solaris pkg

    Making the uniform will require a lot of refactoring (on it self not a big problem). I'm not sure how to maintain backwards compatibility though 👎

    • if they ever get around to replacing the uname SunOS part with illumOS
  2. sjorge commented on Jan 22, 2016

    @sjorge
    ContributorAuthor

    concrete example for fixing the systems modules

    old filename new filename virtualname loaded
    system.py system_linux.py systems G@kernel:linux and which = shutdown
    win_system.py systems_windows.py systems G@os:windows and HAS_WIN32NET_MODS
    solaris_system.py system_solaris.py systems G@kernel:sunos and which = shutdown

    Of course the doc refs should also reflect the new filenames.

    The above refactor should be backwards compatible! However some others like for pkg would be nearly impossible to do without breaking backwards compat :(

  3. The-Loeki commented on Jan 22, 2016

    @The-Loeki
    Contributor

    There's been work on module 'dirs', would that not a much cleaner refactor if it can be done properly?

    system
      |- __init__.py
      |- linux.py
      |- windows.py
    pkg
      |- __init__.py
      |- yum.py
      |- apt.py
    etc.
    

    Although for this layout to work, further improvements would seem to have to be made to the module dir stuff on at least the 2015.8 branch

  4. damon-atkins commented on Jan 22, 2016

    @damon-atkins
    Contributor

    Yes "Dirs" like above would make it nicer, but comments in #30533 have indicated its not straight forward.

    If stuff might break, could a warning be printed and then continue by calling the new module code. Maybe a tool to search yaml and optionally replace it.

  5. sjorge commented on Jan 22, 2016

    @sjorge
    ContributorAuthor

    It's worse than that though, I little too to search files for X and print a warning line X has been replaced by Y should not be too hard.

    I also like the dirs approach, something did occur to me too... if we rename all that stuff it will make back porting/forward porting less easy. This is definitely something to consider too.

    I also suggest this does not happen withing the 2015.x release but if it should be in a release with the major (year) bumped.

  6. damon-atkins commented on Jan 22, 2016

    @damon-atkins
    Contributor

    I would suggest the warning starts in 2015.x to say it will be removed in 2016.x
    Or both work in 2015.x

  7. The-Loeki commented on Jan 22, 2016

    @The-Loeki
    Contributor

    Well the versioning scheme doesn't work that way, it'd be something like +X periodic table elements deprecation warning, so considering we're all waiting for Boron (5), the warning'd be like 'this module will dissapear in Salt Neon (10)' & just wait & see what version number Neon would actually get.

    Also I'm not so sure about the porting problems; by far most stuff should already be using the virtual names (e.g. pkg rather than package_freebsd) through the LazyLoader, which would leave manual provider config stanzas; it'd be easy to temporarily wrap those stanza's through a compat dict

    provider = {
    'freebsdpkg': 'pkg.fbsd',
    'yum_pkg': 'pkg.yum',
    }.get(provider, provider)
    

    or something like that :)

  8. added
    Feature
    pending-discussion
    Platform
    on Jan 22, 2016
  9. added this to the Approved milestone on Jan 22, 2016
  10. jfindlay commented on Jan 22, 2016

    @jfindlay
    Contributor

    Thanks for the great discussion on this. I think that if users are already using modules through their __virtualname__ refactoring their real names should not be too much of a problem. @whiteinge and @thatch45 may have some further comments.

  11. sjorge commented on Jan 22, 2016

    @sjorge
    ContributorAuthor

    @jfindlay: It will probably break the provides section of the minion config.

    But yes if they use purely __virtualnames__ they should be OK for most. The windows ones would still have odd virtual names, but so be it.

    e.g.

    old filename new filename virtualname
    win_servermanager.py servermanager_windows.py win_servermanager

    But for those a deprecated in warning could be added, and a temperarly mapping of win_servermanager to servermanager ?

  12. jfindlay commented on Jan 22, 2016

    @jfindlay
    Contributor

    @sjorge, I think you mean #30519.

  13. sjorge commented on Jan 22, 2016

    @sjorge
    ContributorAuthor

    Yeah you are right linked the wrong issue/pr.

  14. 51 remaining items

  15. thatch45 commented on May 1, 2017

    @thatch45
    Contributor

    Yes, we should be able to move forward on this using virtual aliases

  16. sjorge commented on May 1, 2017

    @sjorge
    ContributorAuthor

    @thatch45 could you point everywhere who missed it to the docs on why/when/how to use virtual_aliases?

  17. thatch45 commented on May 1, 2017

    @thatch45
    Contributor

    These are a very new addition, I think that @terminalmage put them in, he can likely point us in the right direction wrt docs on __virtual_aliases__.
    But it is rather straightforward, __virtual_aliases__ should be a tuple with a list of names you want the module to show up as along with the virtualname.

    When we set a new virtualname and then set the old name in aliases it should be well documented when the change was made and a proposal on how long to keep the old name working

  18. sjorge commented on May 1, 2017

    @sjorge
    ContributorAuthor

    That would indeed allow this suggestion to be implemented!
    Now we just all need to agree on a naming standard :) Scrolling back up think we got as far as:

    {virtualname}[_{variant}][_{os|os_family|kernel}].py
    
  19. terminalmage commented on May 2, 2017

    @terminalmage
    Contributor

    __virtual_aliases__ is new for Nitrogen. It is a feature in the loader where, when a module is being loaded, copies of the function are added to the loader instance for each of the module names in __virtual_aliases__. So, assuming a module foo.py with a function bar, if the module contained the following line:

    __virtual_aliases__ = ('bar', 'baz')

    Then each of the following function names would exist:

    foo.bar
    bar.bar
    baz.bar
    

    This works on any kind of module processed by the loader, by the way (execution modules, states, runners, etc.).

    The one problem that changing the naming may cause, which we need to properly address, is if we try to create namespaced function names (i.e. with dots, like pkg.freebsd.install). The reason for this is that the LazyLoader instance we return gets the function names setattr-ed into it, so you can do __salt__.pkg.install('foo'). Introducing function names which don't fit the module.func naming convention would break this functionality (and likely cause errors in the loader).

  20. sjorge commented on May 2, 2017

    @sjorge
    ContributorAuthor

    I don't think we want to go full namespace, just naming of the python files to make it easier to figure out what the file provides and for which platform.

  21. stale commented on Oct 14, 2018

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

    If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

  22. damon-atkins commented on Oct 15, 2018

    @damon-atkins
    Contributor

    .

  23. stale commented on Oct 15, 2018

    @stale

    Thank you for updating this issue. It is no longer marked as stale.

  24. stale commented on Jan 9, 2020

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

    If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

  25. damon-atkins commented on Jan 22, 2020

    @damon-atkins
    Contributor

    I think this will happen one day unless POP. Changes things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeaturePlatformpending-discussionstale

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions