Issue with Chef not finding contents within a file

Hello Chefs!

I am working on an audit mode cookbook that verifies an application was deployed to IIS with the expected configuration and token values in the Web.config. The issue I am experiencing is that Chef tells me that the values I am expecting to exist in the Web.config file are not there, but manually reviewing the file shows them to be there. I thought perhaps IIS was locking the file, so I copied it out to a temporary location but I am still seeing it fail.

Exception

  1. Verify deployment tokens should exist
    Failure/Error: expect(file(web_config_file)).to contain token
    expected File “Web.config” to contain “<add key=“GFSIntranetDBType” value=“false”/>”

    c:/chef/cache/cookbooks/nsm_deploy_audit/recipes/audit.rb:93:in `block (5 levels) in from_file’

Snippet of Web.config



Relevant code in cookbook

web_config_file = “Web.config”

control “tokens” do
# tokens_to_check is an array of strings each containing XML text that is expected in the web.config
tokens_to_check.each do |token|
it ‘should exist’ do
expect(file(web_config_file)).to contain token
end
end
end

Any guidance you all could provide in identifying the cause of the failures is appreciated!

Thanks,
Matt

Could it be down to a simple spacing issue? Your web.config looks like it has a space before the slash that self-closes the element, but your example in the failure message doesn’t appear to have this space?

Stuart

From: Matt Clark [mailto:mattc0802@gmail.com]
Sent: 08 September 2015 17:57
To: Chef Mailing List chef@lists.opscode.com
Subject: [chef] Issue with Chef not finding contents within a file

Hello Chefs!

I am working on an audit mode cookbook that verifies an application was deployed to IIS with the expected configuration and token values in the Web.config. The issue I am experiencing is that Chef tells me that the values I am expecting to exist in the Web.config file are not there, but manually reviewing the file shows them to be there. I thought perhaps IIS was locking the file, so I copied it out to a temporary location but I am still seeing it fail.

Exception

  1. Verify deployment tokens should exist
    Failure/Error: expect(file(web_config_file)).to contain token
    expected File “Web.config” to contain “<add key=“GFSIntranetDBType” value=“false”/>”

    c:/chef/cache/cookbooks/nsm_deploy_audit/recipes/audit.rb:93:in `block (5 levels) in from_file’

Snippet of Web.config



Relevant code in cookbook

web_config_file = “Web.config”

control “tokens” do
# tokens_to_check is an array of strings each containing XML text that is expected in the web.config
tokens_to_check.each do |token|
it ‘should exist’ do
expect(file(web_config_file)).to contain token
end
end
end

Any guidance you all could provide in identifying the cause of the failures is appreciated!

Thanks,
Matt

Nice catch! I am using Nokogiri to parse the XML and select the elements to match with search statements. It looks like Nokogiri is stripping out the space between the ending tag. I'll look into that.

Thanks!

Matt

On Sep 8, 2015, at 12:59 PM, Stuart Preston stuart@pendrica.com wrote:

Could it be down to a simple spacing issue? Your web.config looks like it has a space before the slash that self-closes the element, but your example in the failure message doesn’t appear to have this space?

Stuart

From: Matt Clark [mailto:mattc0802@gmail.com]
Sent: 08 September 2015 17:57
To: Chef Mailing List chef@lists.opscode.com
Subject: [chef] Issue with Chef not finding contents within a file

Hello Chefs!

I am working on an audit mode cookbook that verifies an application was deployed to IIS with the expected configuration and token values in the Web.config. The issue I am experiencing is that Chef tells me that the values I am expecting to exist in the Web.config file are not there, but manually reviewing the file shows them to be there. I thought perhaps IIS was locking the file, so I copied it out to a temporary location but I am still seeing it fail.

Exception

  1. Verify deployment tokens should exist
    Failure/Error: expect(file(web_config_file)).to contain token
    expected File "Web.config" to contain "<add key="GFSIntranetDBType" value="false"/>"

    c:/chef/cache/cookbooks/nsm_deploy_audit/recipes/audit.rb:93:in `block (5 levels) in from_file'

Snippet of Web.config

...

...

Relevant code in cookbook

web_config_file = "Web.config"

control "tokens" do
# tokens_to_check is an array of strings each containing XML text that is expected in the web.config
tokens_to_check.each do |token|
it 'should exist' do
expect(file(web_config_file)).to contain token
end
end
end

Any guidance you all could provide in identifying the cause of the failures is appreciated!

Thanks,
Matt