Navigation Menu

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

SMF module for SmartOS can't determine if a service is available. #13983

Closed
johngrasty opened this issue Jul 5, 2014 · 5 comments
Closed

SMF module for SmartOS can't determine if a service is available. #13983

johngrasty opened this issue Jul 5, 2014 · 5 comments
Labels
Bug broken, incorrect, or confusing behavior severity-low 4th level, cosemtic problems, work around exists
Milestone

Comments

@johngrasty
Copy link
Contributor

Packages installed via pkgin in SmartOS have one name. When Salt checks svcs to see if it is available, svcs returns a portion of the FMRI name which is different.

For example, salt 'webserver.*' pkg.install nginx works as expected. Yet, salt '*' service.available nginx returns false. Any of the other service functions that begin by checking if the package is available will also fail.

So to install nginx, we use the name nginx. But when the smf module queries for the available services, it checks to see if nginx is in the results from get_all. get_all returns pkgsrc/nginx, not nginx.

Any help would be greatly appreciated!

[root@salt /opt/salt]# salt --versions-report
     Salt: 2014.1.5
     Python: 2.7.6 (default, Feb 19 2014, 13:37:36)
     Jinja2: 2.7.1
     M2Crypto: 0.21.1
     msgpack-python: 0.1.13
     msgpack-pure: Not Installed
     pycrypto: 2.6.1
     PyYAML: 3.10
     PyZMQ: 13.1.0
     ZMQ: 3.2.4
@johngrasty
Copy link
Contributor Author

Ok. So I am way out of my league finding the fix, but I think this will help.

/usr/bin/svcs -H -o SVC <pkgname>

This will take the package name and return the service name. I do not know if this is necessary or will work in other SMF distributions.

One thing that might be a deal breaker is that the above command does allow a search based on a pattern match and just not an abbreviated FMRI. I'm not sure if that could lead to false positives.

@johngrasty
Copy link
Contributor Author

Ok. Here is a fix (I think, but I really don't know what I'm doing) for the available and missing functions. It uses /usr/bin/svcs -H -o SVC <pkgname> to get the source name from the package name. As I worried in the comment above, it will match a pattern. For example, salt '*' service.available \*php\* will match and return true for php-fpm. I am a salt and python amateur though. I also don't know how this would affect other SMF based systems, so I used an if statement with a grain to specify this only for SmartOS.

Also here is a link to the current functions in smf.py.

def available(name):
    '''
    Returns ``True`` if the specified service is available, otherwise returns
    ``False``.

    CLI Example:


    CLI Example:

    .. code-block:: bash

        salt '*' service.available net-snmp
    '''
    if 'SmartOS' in __grains__['os']:
        cmd = '/usr/bin/svcs -H -o SVC {0}'.format(name)
        name = __salt__['cmd.run'](cmd)
        return name in get_all()
    else:
        return name in get_all()


def missing(name):
    '''
    The inverse of service.available.
    Returns ``True`` if the specified service is not available, otherwise returns
    ``False``.

    CLI Example:

    .. code-block:: bash

        salt '*' service.missing net-snmp
    '''
    if 'SmartOS' in __grains__['os']:
        cmd = '/usr/bin/svcs -H -o SVC {0}'.format(name)
        name = __salt__['cmd.run'](cmd)
        return name not in get_all()
    else:
        return name not in get_all()

@basepi
Copy link
Contributor

basepi commented Jul 7, 2014

With the careful partitioning based on the 'os' grain, I think this fix is the right way to go. Will you please submit a pull request?

@basepi basepi added Bug labels Jul 7, 2014
@basepi basepi added this to the Approved milestone Jul 7, 2014
@johngrasty
Copy link
Contributor Author

I've not checked the contributor's guidelines yet. Would a short explanation for the if statement be appropriate in the comments?

@basepi
Copy link
Contributor

basepi commented Jul 8, 2014

Looks like you threw it into the docstring, which is perfect. Thanks for getting that in, @johngrasty!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior severity-low 4th level, cosemtic problems, work around exists
Projects
None yet
Development

No branches or pull requests

2 participants