chef / chef-zero

Simple, easy-run, fast-start in-memory Chef server for testing and solo purposes
Apache License 2.0
532 stars 98 forks source link

Chef Client local mode (chef zero) search inconsistencies (NOT / AND NOT) #150

Open petecheslock opened 9 years ago

petecheslock commented 9 years ago

This is with both Chef 12.0.0 and 12.1.1

When talking to a real chef server (in that case hosted chef) - and running the following queries. I get the following results (there are about 60 other nodes in this hosted chef account).

chef > search(:node, "role:api_server AND chef_environment:#{node.chef_environment} NOT tags:hidden", :filter_result => { 'ip' => ['ipaddress'] })
 => [{"ip"=>"1.1.1.1"}]
chef > search(:node, "role:api_server AND chef_environment:#{node.chef_environment} AND NOT tags:hidden", :filter_result => { 'ip' => ['ipaddress'] })
 => [{"ip"=>"1.1.1.1"}]

Works as I would expect

Also here i'm using filter results - but have confirmed the issue with both normal search and "partial" search.

On a test server - (using test-kichen with chef zero provisioner), and pre-populating node data, I see the following:

Node Data

cat /tmp/kitchen/nodes/api_server.json
{
  "id": "api_server",
  "chef_environment": "test",
  "run_list": [
    "role[api_server]"
  ],
  "automatic": {
    "ipaddress": "172.33.33.34",
    "hostname": "api-server",
    "roles": [
      "api_server"
    ]
  }
}
{
  "id": "sensu_master",
  "chef_environment": "test",
  "run_list": [
    "role[sensu_master]"
  ],
  "automatic": {
    "ipaddress": "172.33.33.50",
    "hostname": "sensu-master",
    "roles": [
      "sensu_master"
    ]
  }
}

Then running queries against:

pry(#<Chef::Recipe>)> search(:node, "role:api_server AND chef_environment:#{node.chef_environment} NOT tags:hidden", :filter_result => { 'ip' => ['ipaddress'] })
=> [{"ip"=>"172.33.33.34"},{"ip"=>"172.33.33.50"}]
pry(#<Chef::Recipe>)> search(:node, "role:api_server AND chef_environment:#{node.chef_environment} AND NOT tags:hidden", :filter_result => { 'ip' => ['ipaddress'] })
=> [{"ip"=>"172.33.33.34"}]
pry(#<Chef::Recipe>)> search(:node, "role:api_server AND chef_environment:#{node.chef_environment}", :filter_result => { 'ip' => ['ipaddress'] })
=> [{"ip"=>"172.33.33.34"}]

So in this case it seems to be the AND or AND NOT at the end. This is easy for us to work around by using AND NOT in our cookbooks since that seems to work for both, but there might be a chef-zero or localmode bug.

thommay commented 8 years ago

I suspect this is another instance of #92 - @petecheslock if you do "role:api_server AND chef_environment:#{node.chef_environment} OR NOT tags:hidden" do you still get both nodes returned?

petecheslock commented 8 years ago

@thommay yea - same thing (using latest 12.12.15 version of chef), if I do the query: role:api_server AND chef_environment:#{node.chef_environment} OR NOT tags:hidden then both nodes are still returned.

chilicheech commented 6 years ago

I just hit this bug too. In solr as far as I can tell the proper search query is: role:A AND chef_environment:B NOT tags:C. That NOT behaves as an AND NOT. However, that NOT seems to behave as an OR NOT in chef-zero instead. I'm able to workaround the issue by replacing the NOT with AND NOT.