sous-chefs/iis

iis_site action :config not functioning as expected

aperture74 opened this issue · 16 comments

Cookbook version

6.8.0

Chef-client version

13.5.3

Platform Details

Windows Server 2012 R2 - Vagrant

Scenario:

I am creating a test site with a port, say 8080. Then i am applying action :config and changing the port to 8090. The recipe runs, the result is "everything is up to date" and the port never changes.

Steps to Reproduce:

I am using the folowing

directory "#{node['iis']['docroot']}\\mytest" do
  action :create
end

iis_site 'MyTest' do
  protocol :http
  port 8080
  path "#{node['iis']['docroot']}\\mytest"
  action [:add,:start]
end

When the IIS cookbook version is set to 6.5.3 i can change the above to

iis_site 'MyTest' do
  protocol :http
  port 8090
  path "#{node['iis']['docroot']}\\mytest"
  action :config
end

and the port will indeed change to 8090.

When the IIS version is changed to 6.8.0 then the port never changes.

Expected Result:

The expected result is the following

10.10.27.40     - update MyTest
10.10.27.40     -   set port to 8090 (was 8080)

Actual Result:

The actual output when the IIS is set to 6.8.0 is

10.10.27.40   * iis_site[MyTest] action config[2017-11-07T02:31:49-08:00] INFO: Processing iis_site[MyTest] action config (test_iis::iis line 11)
10.10.27.40  (up to date)

if i were just guessing in the dark:
https://github.com/chef-cookbooks/iis/blob/master/resources/site.rb#L88

is the reason why this isn't working since it is checking values but it hasn't been set if site id was nil, however this likely should only impact create.

A test should be made that simply sets the port of a site then changes it later in the same test.

Thanks a lot for the reply @EasyAsABC123
I have created the following test with IIS version 6.8.0 in the same recipe as you suggested. Also i totally wiped any previous instances of the mytest site

directory "#{node['iis']['docroot']}\\mytest" do
  action :create
end

iis_site 'MyTest' do
  protocol :http
  port 8080
  path "#{node['iis']['docroot']}\\mytest"
  action [:add,:start]
end

iis_site 'MyTest' do
  protocol :http
  port 8090
  path "#{node['iis']['docroot']}\\mytest"
  action :config
end

The output is the following

10.10.27.40 Converging 3 resources
10.10.27.40
10.10.27.40 Recipe: iis_test::iis
10.10.27.40   * directory[C:\inetpub\wwwroot\mytest] action create[2017-11-07T05:48:41-08:00] INFO: Processing directory[C:\inetpub\wwwroot\mytest] action create (iis_test::iis line 7)
10.10.27.40  (up to date)
10.10.27.40   * iis_site[MyTest] action add[2017-11-07T05:48:41-08:00] INFO: Processing iis_site[MyTest] action add (iis_test::iis line 11)
10.10.27.40
10.10.27.40     - update MyTest
10.10.27.40     -   set path to "C:\\inetpub\\wwwroot\\mytest" (was nil)[2017-11-07T05:48:41-08:00] INFO: iis_site[MyTest] added new site 'MyTest'
10.10.27.40
10.10.27.40     - Created the Site - "iis_site[MyTest]"
10.10.27.40   * iis_site[MyTest] action start[2017-11-07T05:48:41-08:00] INFO: Processing iis_site[MyTest] action start (iis_test::iis line 11)
10.10.27.40  (up to date)
10.10.27.40
10.10.27.40   * iis_site[MyTest] action config[2017-11-07T05:48:41-08:00] INFO: Processing iis_site[MyTest] action config (iis_test::iis line 18)
10.10.27.40  (up to date)
10.10.27.40
DEBUG: [WinRM] Waiting for output...
DEBUG: [WinRM] Processing output
10.10.27.40 [2017-11-07T05:48:42-08:00] INFO: Chef Run complete in 5.641719 seconds
10.10.27.40
10.10.27.40
10.10.27.40 Running handlers:
10.10.27.40 [2017-11-07T05:48:42-08:00] INFO: Running report handlers
10.10.27.40 Running handlers complete
10.10.27.40 [2017-11-07T05:48:42-08:00] INFO: Report handlers complete
10.10.27.40 Chef Client finished, 1/4 resources updated in 09 seconds

@aperture74 you have to do something between the two items you are testng

directory "#{node['iis']['docroot']}\\mytest" do
  action :create
end

iis_site 'MyTest' do
  protocol :http
  port 8080
  path "#{node['iis']['docroot']}\\mytest"
  action [:add,:start]
end

directory "#{node['iis']['docroot']}\\mytest" do
  action :create
end

iis_site 'MyTest' do
  protocol :http
  port 8090
  path "#{node['iis']['docroot']}\\mytest"
  action :config
end

or something else but if you don't chef will concat them into one block of code

@aperture74 we also would want that test added here:

https://github.com/chef-cookbooks/iis/blob/master/test/cookbooks/test/recipes/site.rb
and then add the checks here
https://github.com/chef-cookbooks/iis/blob/master/test/integration/site/site_spec.rb

Then you can run kitchen test site and it will run your test against windows2012 and windows 2008

Thanks again @EasyAsABC123
I will add the test as you suggest. Nevertheless i also performed the test by doing something in the middle and it "failed" again as you can see below

directory "#{node['iis']['docroot']}\\mytest" do
  action :create
end

iis_site 'MyTest' do
  protocol :http
  port 8080
  path "#{node['iis']['docroot']}\\mytest"
  action [:add,:start]
end

iis_app 'MyTest' do
  path '/testpool'
  application_pool 'Test AppPool'
  physical_path "#{node['iis']['docroot']}\\mytest"
  enabled_protocols 'http'
  action :add
end


iis_site 'MyTest' do
  protocol :http
  port 8090
  path "#{node['iis']['docroot']}\\mytest"
  action :config
end

Output

10.10.27.40 Recipe: iis_test::iis
10.10.27.40   * directory[C:\inetpub\wwwroot\mytest] action create[2017-11-07T06:13:05-08:00] INFO: Processing directory[C:\inetpub\wwwroot\mytest] action create (iis_test::iis line 7)
10.10.27.40  (up to date)
10.10.27.40   * iis_site[MyTest] action add[2017-11-07T06:13:05-08:00] INFO: Processing iis_site[MyTest] action add (iis_test::iis line 11)
10.10.27.40
10.10.27.40     - update MyTest
10.10.27.40     -   set path to "C:\\inetpub\\wwwroot\\mytest" (was nil)[2017-11-07T06:13:05-08:00] INFO: iis_site[MyTest] added new site 'MyTest'
10.10.27.40
10.10.27.40     - Created the Site - "iis_site[MyTest]"
10.10.27.40   * iis_site[MyTest] action start[2017-11-07T06:13:05-08:00] INFO: Processing iis_site[MyTest] action start (iis_test::iis line 11)
10.10.27.40  (up to date)
10.10.27.40
10.10.27.40   * iis_app[MyTest] action add[2017-11-07T06:13:05-08:00] INFO: Processing iis_app[MyTest] action add (iis_test::iis line 18)
10.10.27.40
10.10.27.40     - Creating the Application - "iis_app[MyTest]"
10.10.27.40   * iis_site[MyTest] action config[2017-11-07T06:13:05-08:00] INFO: Processing iis_site[MyTest] action config (iis_test::iis line 27)
10.10.27.40  (up to date)
10.10.27.40
DEBUG: [WinRM] Waiting for output...
DEBUG: [WinRM] Processing output
10.10.27.40 [2017-11-07T06:13:06-08:00] INFO: Chef Run complete in 4.452341 seconds
10.10.27.40
10.10.27.40
10.10.27.40 Running handlers:
10.10.27.40 [2017-11-07T06:13:06-08:00] INFO: Running report handlers
10.10.27.40 Running handlers complete
10.10.27.40 [2017-11-07T06:13:06-08:00] INFO: Report handlers complete
10.10.27.40 Chef Client finished, 2/5 resources updated in 08 seconds

It succeeded when i changed to version 6.5.3 not matter whether i was performing an action in between or not.

@aperture74 interesting in all my tests i had to add actions between for them to work. i wonder if that was changed in chef 13 and if it was i can't imagine it was intentional

@iennae was the recipe behavior changes in chef 13 to stop concat of blocks?

@EasyAsABC123 I have added the recipes / tests where you suggested and i will create a pull request as well. I have also tried to run kitchen but i dont have Vagrant login so cannot access the boxes specified

    default: Box Version: >= 0
 The box 'chef/windows-server-2008r2-standard' could not be found or
 could not be accessed in the remote catalog. If this is a private
 box on HashiCorp's Vagrant Cloud, please verify you're logged in via
 `vagrant login`. Also, please double-check the name. The expanded
 URL and error message are shown below:

@aperture74 yeah chef doesn't share their images..
you have to go into .kitchen.yml and change
line 17 to opentable/win-2008r2-standard-amd64-nocm
line 20 to opentable/win-2012r2-standard-amd64-nocm

@EasyAsABC123 For some reason i am getting denied when trying to push a new branch i created but nevertheless i have run kitchen on Windows 2012R2 using the tests below (I have not run it against Windows 2008 since i am on a slow download link and it is still downloading !)

The tests i used

describe iis_site('mytest') do
  it { should exist }
  it { should be_running }
  its('bindings') { should eq ['http *:8090:localhost'] }
end

describe port(8090) do
  it { should be_listening }
end

The output from kitchen test

  iis_site 'mytest'
     [PASS]  should exist
     [PASS]  should be running
     [MAJR]  bindings should eq ["http *:8090:localhost"]

     expected: ["http *:8090:localhost"]
          got: ["http *:8080:"]

     (compared using ==)

  Port 8090
     [MAJR]  should be listening
     expected `Port 8090.listening?` to return true, got false

Test Summary: 17 successful, 2 failures, 0 skipped

Cool so the tests need to be tweaked a little, to push you need to make a fork (top right corner) then you can add it as a remote, push to it.

git remote add myiis your_url
git push myiis branch_name

then head to the github page and do a pull request

Thanks @EasyAsABC123 . Pushed and created the pull request.

@aperture74 thanks! much appreciated.

I'll like need to pull your changes to my local machine and fix the bug then add a new pull request (this way you still get commit credit but the build passes)

@aperture74 thanks for this, the changes have been made and can be seen in #402

Thanks a lot @EasyAsABC123 !

@aperture74 thank you for actually writing the tests and providing valuable feedback the bug is https://github.com/chef-cookbooks/iis/blob/master/resources/site.rb#L185 this line isn't checking the port property...meaning it is ignored. Good catch and thanks for making our unit tests all the better!

If you ever want to learn more or contribute more tests, feel free, as these our the backwards compatibility tests for this whole cookbook.

Also if you have an issue in the future make sure to run your chef-client run with -l debug so we get a lot of data, the use github gist to link to the file.

Note: @iennae is traveling abroad and might take a while to code review.

Thanks for the response,help and tips @EasyAsABC123 !