{"action":"created","issue":{"url":"https://api.github.com/repos/ManageIQ/manageiq/issues/12222","repository_url":"https://api.github.com/repos/ManageIQ/manageiq","labels_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/12222/labels{/name}","comments_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/12222/comments","events_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/12222/events","html_url":"https://github.com/ManageIQ/manageiq/pull/12222","id":185495939,"number":12222,"title":"Fix targeted refresh of a VM without its host clearing all folder relationships","user":{"login":"agrare","id":12851112,"avatar_url":"https://avatars.githubusercontent.com/u/12851112?v=3","gravatar_id":"","url":"https://api.github.com/users/agrare","html_url":"https://github.com/agrare","followers_url":"https://api.github.com/users/agrare/followers","following_url":"https://api.github.com/users/agrare/following{/other_user}","gists_url":"https://api.github.com/users/agrare/gists{/gist_id}","starred_url":"https://api.github.com/users/agrare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/agrare/subscriptions","organizations_url":"https://api.github.com/users/agrare/orgs","repos_url":"https://api.github.com/users/agrare/repos","events_url":"https://api.github.com/users/agrare/events{/privacy}","received_events_url":"https://api.github.com/users/agrare/received_events","type":"User","site_admin":false},"labels":[{"id":106615676,"url":"https://api.github.com/repos/ManageIQ/manageiq/labels/bug","name":"bug","color":"fc2929","default":true},{"id":447068054,"url":"https://api.github.com/repos/ManageIQ/manageiq/labels/euwe/yes","name":"euwe/yes","color":"000000","default":false},{"id":211525939,"url":"https://api.github.com/repos/ManageIQ/manageiq/labels/providers/vmware/infra","name":"providers/vmware/infra","color":"5319e7","default":false}],"state":"closed","locked":false,"assignee":{"login":"Fryguy","id":52120,"avatar_url":"https://avatars.githubusercontent.com/u/52120?v=3","gravatar_id":"","url":"https://api.github.com/users/Fryguy","html_url":"https://github.com/Fryguy","followers_url":"https://api.github.com/users/Fryguy/followers","following_url":"https://api.github.com/users/Fryguy/following{/other_user}","gists_url":"https://api.github.com/users/Fryguy/gists{/gist_id}","starred_url":"https://api.github.com/users/Fryguy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fryguy/subscriptions","organizations_url":"https://api.github.com/users/Fryguy/orgs","repos_url":"https://api.github.com/users/Fryguy/repos","events_url":"https://api.github.com/users/Fryguy/events{/privacy}","received_events_url":"https://api.github.com/users/Fryguy/received_events","type":"User","site_admin":false},"assignees":[{"login":"Fryguy","id":52120,"avatar_url":"https://avatars.githubusercontent.com/u/52120?v=3","gravatar_id":"","url":"https://api.github.com/users/Fryguy","html_url":"https://github.com/Fryguy","followers_url":"https://api.github.com/users/Fryguy/followers","following_url":"https://api.github.com/users/Fryguy/following{/other_user}","gists_url":"https://api.github.com/users/Fryguy/gists{/gist_id}","starred_url":"https://api.github.com/users/Fryguy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fryguy/subscriptions","organizations_url":"https://api.github.com/users/Fryguy/orgs","repos_url":"https://api.github.com/users/Fryguy/repos","events_url":"https://api.github.com/users/Fryguy/events{/privacy}","received_events_url":"https://api.github.com/users/Fryguy/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/ManageIQ/manageiq/milestones/43","html_url":"https://github.com/ManageIQ/manageiq/milestones/Sprint%2049%20Ending%20Nov%2014,%202016","labels_url":"https://api.github.com/repos/ManageIQ/manageiq/milestones/43/labels","id":2091083,"number":43,"title":"Sprint 49 Ending Nov 14, 2016","description":"","creator":{"login":"chessbyte","id":82161,"avatar_url":"https://avatars.githubusercontent.com/u/82161?v=3","gravatar_id":"","url":"https://api.github.com/users/chessbyte","html_url":"https://github.com/chessbyte","followers_url":"https://api.github.com/users/chessbyte/followers","following_url":"https://api.github.com/users/chessbyte/following{/other_user}","gists_url":"https://api.github.com/users/chessbyte/gists{/gist_id}","starred_url":"https://api.github.com/users/chessbyte/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chessbyte/subscriptions","organizations_url":"https://api.github.com/users/chessbyte/orgs","repos_url":"https://api.github.com/users/chessbyte/repos","events_url":"https://api.github.com/users/chessbyte/events{/privacy}","received_events_url":"https://api.github.com/users/chessbyte/received_events","type":"User","site_admin":false},"open_issues":0,"closed_issues":151,"state":"open","created_at":"2016-10-25T02:44:35Z","updated_at":"2016-11-02T17:30:23Z","due_on":"2016-11-14T00:00:00Z","closed_at":null},"comments":7,"created_at":"2016-10-26T20:05:13Z","updated_at":"2016-11-02T18:09:29Z","closed_at":"2016-11-02T17:09:22Z","pull_request":{"url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/12222","html_url":"https://github.com/ManageIQ/manageiq/pull/12222","diff_url":"https://github.com/ManageIQ/manageiq/pull/12222.diff","patch_url":"https://github.com/ManageIQ/manageiq/pull/12222.patch"},"body":"When filtering folder inventory during a targeted refresh, `ems_metadata_inv_by_vm_inv` walks up the hosts & clusters path and the vms & templates path.  These two paths share common ancestors, the datacenter and root folder.\n\nA simple folder structure looks something like this:\n\n```\n     rootFolder\n      /      \\\n     DC1     DC2\n     / \\\n    vm host\n    /    \\\n folder1 cluster1\n    \\       \\\n     \\     host1\n      \\    /\n        vm1\n```\n\nIt is possible to configure permissions such that the user has administrator access to everything under the vm folder, but no access to anything on the clusters/hosts side.  This leads to VMs in inventory that have we do not have hosts for.\n\nWhen we do a targeted refresh of one of these VMs the walk up the hosts & clusters view fails because there is no host, the walk up the vms & templates view breaks out at the datacenter, meaning there is no root folder (the datacenter's parent) return in inventory.\n\nThis causes `link_ems_inventory` to change the root folder which deletes the rest of the relationships.\n\nBefore the patch:\n\n```\nMIQ(EmsRefresh.link_ems_inventory) EMS: [vc], id: [1] Linking EMS Inventory...\nMIQ(EmsRefresh.link_ems_inventory) EMS: [vc], id: [1] prev_relats: {:folders_to_vms=>{13=>[108]}, :folders_to_folders=>{8=>[13], 15=>[8], 1=>[15]}, :ext_management_systems_to_folders=>{1=>[1]}}\nMIQ(EmsRefresh.link_ems_inventory) EMS: [vc], id: [1] new_relats:  {:folders_to_vms=>{13=>[108]}, :folders_to_folders=>{8=>[13]}, :ext_management_systems_to_folders=>{1=>[8]}\n```\n\n```\n  Relationship Load (1.9ms)  SELECT \"relationships\".* FROM \"relationships\" WHERE (\"relationships\".\"ancestry\" ILIKE '197/5740/%' OR \"relationships\".\"ancestry\" = '197/5740')\n  Relationship Inst Including Associations (3.9ms - 550rows)\n  SQL (0.3ms)  DELETE FROM \"relationships\" WHERE \"relationships\".\"id\" = $1  [[\"id\", 5741]]\n  SQL (0.2ms)  DELETE FROM \"relationships\" WHERE \"relationships\".\"id\" = $1  [[\"id\", 5742]]\n  SQL (0.2ms)  DELETE FROM \"relationships\" WHERE \"relationships\".\"id\" = $1  [[\"id\", 5749]]\n  SQL (0.2ms)  DELETE FROM \"relationships\" WHERE \"relationships\".\"id\" = $1  [[\"id\", 5747]]\n  SQL (0.2ms)  DELETE FROM \"relationships\" WHERE \"relationships\".\"id\" = $1  [[\"id\", 5748]]\n  SQL (0.2ms)  DELETE FROM \"relationships\" WHERE \"relationships\".\"id\" = $1  [[\"id\", 5746]]\n  SQL (0.1ms)  DELETE FROM \"relationships\" WHERE \"relationships\".\"id\" = $1  [[\"id\", 5750]]\n  SQL (0.2ms)  DELETE FROM \"relationships\" WHERE \"relationships\".\"id\" = $1  [[\"id\", 5751]]\n  SQL (0.1ms)  DELETE FROM \"relationships\" WHERE \"relationships\".\"id\" = $1  [[\"id\", 5744]]\n  SQL (0.1ms)  DELETE FROM \"relationships\" WHERE \"relationships\".\"id\" = $1  [[\"id\", 5745]]\n  SQL (0.1ms)  DELETE FROM \"relationships\" WHERE \"relationships\".\"id\" = $1  [[\"id\", 5743]]\n  SQL (0.1ms)  DELETE FROM \"relationships\" WHERE \"relationships\".\"id\" = $1  [[\"id\", 5752]]\n```\n\n![screenshot from 2016-10-26 16-19-34](https://cloud.githubusercontent.com/assets/12851112/19743686/3f854480-9b98-11e6-902c-7e224312a654.png)\n\nAfter the patch:\n\n```\nMIQ(EmsRefresh.link_ems_inventory) EMS: [vc], id: [1] Linking EMS Inventory...\nMIQ(EmsRefresh.link_ems_inventory) EMS: [vc], id: [1] prev_relats: {:folders_to_vms=>{13=>[108]}, :folders_to_folders=>{8=>[13], 15=>[8], 1=>[15]}, :ext_management_systems_to_folders=>{1=>[1]}}\nMIQ(EmsRefresh.link_ems_inventory) EMS: [vc], id: [1] new_relats:  {:folders_to_folders=>{1=>[15], 8=>[13], 15=>[8]}, :folders_to_vms=>{13=>[108]}, :ext_management_systems_to_folders=>{1=>[1]}}\n```\n\n```\n  Relationship Load (0.4ms)  SELECT \"relationships\".* FROM \"relationships\" WHERE \"relationships\".\"resource_type\" = $1 AND \"relationships\".\"resource_id\" IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)  [[\"resource_type\", \"EmsFolder\"]]\n  Relationship Inst Including Associations (0.2ms - 13rows)\n  Relationship Load (0.2ms)  SELECT \"relationships\".* FROM \"relationships\" WHERE \"relationships\".\"ancestry\" = '197/6844'\n  Relationship Inst Including Associations (0.0ms - 2rows)\n  Relationship Load (0.5ms)  SELECT \"relationships\".* FROM \"relationships\" WHERE \"relationships\".\"ancestry\" = '197/6844/6849/6856'\n```\n\n![screenshot from 2016-10-26 16-34-12](https://cloud.githubusercontent.com/assets/12851112/19744121/12e0c2ea-9b9a-11e6-933c-e7d1275bec9b.png)\n\nhttps://bugzilla.redhat.com/show_bug.cgi?id=1387336\n"},"comment":{"url":"https://api.github.com/repos/ManageIQ/manageiq/issues/comments/257950923","html_url":"https://github.com/ManageIQ/manageiq/pull/12222#issuecomment-257950923","issue_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/12222","id":257950923,"user":{"login":"chrispy1","id":4118847,"avatar_url":"https://avatars.githubusercontent.com/u/4118847?v=3","gravatar_id":"","url":"https://api.github.com/users/chrispy1","html_url":"https://github.com/chrispy1","followers_url":"https://api.github.com/users/chrispy1/followers","following_url":"https://api.github.com/users/chrispy1/following{/other_user}","gists_url":"https://api.github.com/users/chrispy1/gists{/gist_id}","starred_url":"https://api.github.com/users/chrispy1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrispy1/subscriptions","organizations_url":"https://api.github.com/users/chrispy1/orgs","repos_url":"https://api.github.com/users/chrispy1/repos","events_url":"https://api.github.com/users/chrispy1/events{/privacy}","received_events_url":"https://api.github.com/users/chrispy1/received_events","type":"User","site_admin":false},"created_at":"2016-11-02T18:09:29Z","updated_at":"2016-11-02T18:09:29Z","body":"@miq-bot add_label blocker"}}
{"actor":{"display_login":"chrispy1"}}