Skip to content
This repository has been archived by the owner on Mar 24, 2022. It is now read-only.

iis.py in _modules #134

Open
alexzheng0000 opened this issue Aug 4, 2015 · 2 comments
Open

iis.py in _modules #134

alexzheng0000 opened this issue Aug 4, 2015 · 2 comments

Comments

@alexzheng0000
Copy link
Contributor

with the original iis.py module, I could get a error comment while trying to get "physicalPath" of iis site.

errors showing below:

image

I changed few codes in "_resource_get_config" function, and works well for me.

previous code:

def _resource_get_config(resource, name, settings):
    '''
    Returns the configuration of the Resource
    '''

    ret = {}
    for i in settings:
            cmd_ret = __salt__['cmd.run_all']([appcmd, 'list', R.upper(), '/{0}.name:{1}'.format(R.lower(), name), '/text:{0}'.format(i)])
        if cmd_ret['retcode'] != 0:
            log.error('can\'t get "{0}" from {1} "{2}"'.format(i, resource, name))
            return False
        ret[i] = cmd_ret['stdout'].strip()
    return ret

new code:

def _resource_get_config(resource, name, settings):
    '''
    Returns the configuration of the Resource
    '''

    ret = {}
    for i in settings:
        if i == 'physicalPath':
            R  = 'vdir'
            cmd_ret = __salt__['cmd.run_all']([appcmd, 'list', R.upper(), '/vdir.name:{0}/'.format(name), '/text:{0}'.format(i)])
        else:
            R = resource
            cmd_ret = __salt__['cmd.run_all']([appcmd, 'list', R.upper(), '/{0}.name:{1}'.format(R.lower(), name), '/text:{0}'.format(i)])
        if cmd_ret['retcode'] != 0:
            log.error('can\'t get "{0}" from {1} "{2}"'.format(i, resource, name))
            return False
        ret[i] = cmd_ret['stdout'].strip()
    return ret

please kindly consider to modify the iis.py code in module function if this do work well, thanks

@jfindlay
Copy link
Contributor

jfindlay commented Aug 4, 2015

@Cheng0919, thanks for reporting this issue. Ping @evgenysub.

@sbreidba
Copy link

sbreidba commented Oct 5, 2015

I case anyone else gets tripped up on this and lands here, I thought I'd add my findings. One is a small code issue, the other is a documentation issue.

  • Code: the return from _resource_get_config is a boolean on failure, and the caller does not check that condition. Could be fixed to be friendlier, but not a big deal.
  • Documentation: the notes in states/iis.py call this out by saying "for example in order to config a vdir property of a vdir of a certain app use the vdir_present and not the app_present. this sounds a bit obvious but it is a common pitfall =)".

The underlying issue is that appcmd will implicitly create a vdir & app when asked to create a site, but properties such as physicalPath are not site properties. So the site_present example, MySite, will work fine the first time highstate is run but not afterwards, as the code will fail when it attempts to fetch the physicalPath property to see if it needs to be modified. (This code path obviously does not occur when the site is intially created.)

Conversely, the changes that @Cheng0919 proposes would allow the site to be modified, but would fail if the site did not exist already.

I recommend removing the physicalPath setting in the site_present example as it does not fully work, and potentially providing a more complete example instead. The test code that was successful for me, both initially and in subsequent highstate runs, was as follows:

ensure_test_vdir_exists:
  iis.vdir_present:
    - name: /
    - app: Test-Site/
    - settings:
        physicalPath: 'C:\test_app_path'
    - require: 
        - iis: ensure_test_app_exists

ensure_test_app_exists:
  iis.app_present:
    - name: /
    - site: Test-Site
    - settings:
        applicationPool: Test-Pool
        path: /
    - require: 
        - iis: ensure_test_site_exists
        - iis: ensure_test_pool_exists

ensure_test_pool_exists:
  iis.apppool_present:
    - name: Test-Pool
    - settings:
        managedRuntimeVersion: v4.0

ensure_test_site_exists:
  iis.site_present:
    - name: Test-Site
    - settings:
        bindings: "http/*:80:test.com"

I know that this is more of a "how to use appcmd" issue, but it might also be worth noting that you can get a list of properties for a given resource by running appcmd set <resource> <resource_identifier> /? (or maybe add something to the module that would do this).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants