Cannot delete VM when VM CID contains semicolon
I used bbl, following these instructions to bootstrap an environment on Azure. The VM CIDs have semicolons in them, e.g.:
$ bosh is --details --json \
| jq '.Tables[0].Rows[] | {instance, state, process_state, az, ips, index, bootstrap, ignore, vm_cid, disk_cids}'
{
"instance": "etcd/25ffd08f-11cb-4af1-bd30-60935c471583",
"state": "started",
"process_state": "running",
"az": "z3",
"ips": "10.0.0.8",
"index": "2",
"bootstrap": "false",
"ignore": "false",
"vm_cid": "agent_id:b0002f87-edf1-47bd-b2cd-e5a09ccc07a1;resource_group_name:bbl-env-turkana-2018-06-15t05-27z-bosh;storage_account_name:bblenvturkana2018061pzn7",
"disk_cids": "caching:None;disk_name:bosh-data-9ebf042a-ac22-4241-8b2e-591b5d9880a6;storage_account_name:bblenvturkana2018061pzn7"
}
{
"instance": "etcd/ba41f52a-c309-43a5-8e7e-2d7043cf8bc3",
"state": "started",
"process_state": "running",
"az": "z1",
"ips": "10.0.0.11",
"index": "0",
"bootstrap": "false",
"ignore": "true",
"vm_cid": "agent_id:48ad686a-87ed-4b35-810a-088e6e635176;resource_group_name:bbl-env-turkana-2018-06-15t05-27z-bosh;storage_account_name:bblenvturkana2018061pzn7",
"disk_cids": "caching:None;disk_name:bosh-data-c4af143e-edef-48bd-928c-893b990c5f7a;storage_account_name:bblenvturkana2018061pzn7"
}
{
"instance": "etcd/e705a5a3-fdf0-44a8-8add-144ff5431ead",
"state": "started",
"process_state": "running",
"az": "z2",
"ips": "10.0.0.12",
"index": "1",
"bootstrap": "false",
"ignore": "false",
"vm_cid": "agent_id:2cc80a0a-0097-40e0-bfed-b21a15c97293;resource_group_name:bbl-env-turkana-2018-06-15t05-27z-bosh;storage_account_name:bblenvturkana2018061pzn7",
"disk_cids": "caching:None;disk_name:bosh-data-fba00181-3909-4aea-902b-13fda924a5db;storage_account_name:bblenvturkana2018061pzn7"
}
When I try to delete the VM via the BOSH CLI, BOSH appears to think the requested VM CID is everything before the first semicolon, so it's failing to find anything to delete:
$ BOSH_LOG_PATH=/tmp/bosh.log \
BOSH_LOG_LEVEL=debug \
bosh -d etcd delete-vm \
'agent_id:87abd836-8e23-4a9a-aca2-76f62f13d7df;resource_group_name:bbl-env-turkana-2018-06-15t05-27z-bosh;storage_account_name:bblenvturkana2018061pzn7'
Using environment 'https://10.0.0.6:25555' as client 'admin'
Task 53
Task 53 | 14:33:42 | Delete VM: agent_id:87abd836-8e23-4a9a-aca2-76f62f13d7df (00:01:46)
L Error: CPI error 'Bosh::Clouds::CloudError' with message 'Invalid instance id (version 1) `agent_id:87abd836-8e23-4a9a-aca2-76f62f13d7df'' in 'delete_vm' CPI method
Task 53 | 14:35:28 | Error: CPI error 'Bosh::Clouds::CloudError' with message 'Invalid instance id (version 1) `agent_id:87abd836-8e23-4a9a-aca2-76f62f13d7df'' in 'delete_vm' CPI method
Task 53 Started Sat Jun 16 14:33:42 UTC 2018
Task 53 Finished Sat Jun 16 14:35:28 UTC 2018
Task 53 Duration 00:01:46
Task 53 error
Capturing task '53' output:
Expected task '53' to succeed but state is 'error'
Exit code 1
I can provide CLI debug logs, task logs, config files, versions, etc. via DM.
Pivotal Tracker Story to Investigate
got same problem with "bosh delete-vm" as well. But the VM CID in my case looks like "agent_id:3dc13f1f-d695-41f4-bccc-e13399b54a7d;resource_group_name:tmca-cloudfoundry". If VM CID is not enclosed with quote, the command output is like
ubuntu@lab13:~$ bosh -e lab13 -d cf-b8a0cd3a767cd0eeca66 delete-vm agent_id:3dc13f1f-d695-41f4-bccc-e13399b54a7d;resource_group_name:tmca-cloudfoundry
Using environment '10.193.78.11' as user 'director' (bosh.*.read, openid, bosh.*.admin, bosh.read, bosh.admin)
Using deployment 'cf-b8a0cd3a767cd0eeca66'
Continue? [yN]: y
Task 1063
Task 1063 | 10:36:51 | Delete VM: agent_id:3dc13f1f-d695-41f4-bccc-e13399b54a7d
Task 1063 | 10:36:51 | Delete VM: VM agent_id:3dc13f1f-d695-41f4-bccc-e13399b54a7d is successfully deleted (00:00:00)
Task 1063 Started Fri Aug 3 10:36:51 UTC 2018
Task 1063 Finished Fri Aug 3 10:36:51 UTC 2018
Task 1063 Duration 00:00:00
Task 1063 done
Succeeded
-bash: resource_group_name:tmca-cloudfoundry: command not found
ubuntu@lab13:~$
If enclosed VM CID with quote or escape semicolon with backslash (agent_id:3dc13f1f-d695-41f4-bccc-e13399b54a7d\;resource_group_name:tmca-cloudfoundry):
ubuntu@lab13:~$ bosh -e lab13 -d cf-b8a0cd3a767cd0eeca66 delete-vm "agent_id:3dc13f1f-d695-41f4-bccc-e13399b54a7d;resource_group_name:tmca-cloudfoundry"
Using environment '10.193.78.11' as user 'director' (bosh.*.read, openid, bosh.*.admin, bosh.read, bosh.admin)
Using deployment 'cf-b8a0cd3a767cd0eeca66'
Continue? [yN]: y
Task 1064
Task 1064 | 10:37:20 | Delete VM: agent_id:3dc13f1f-d695-41f4-bccc-e13399b54a7d
Task 1064 | 10:37:20 | Delete VM: VM agent_id:3dc13f1f-d695-41f4-bccc-e13399b54a7d is successfully deleted (00:00:00)
Task 1064 Started Fri Aug 3 10:37:20 UTC 2018
Task 1064 Finished Fri Aug 3 10:37:20 UTC 2018
Task 1064 Duration 00:00:00
Task 1064 done
Succeeded
Though the response message is "Succeeded", actually the vm was not deleted at all in both cases. task debug logs show only the part of VM CID before semicolon was used to query "vms" table in bosh database.
ubuntu@lab13:~$ bosh task 1064 --debug |grep vms
D, [2018-08-03T10:39:51.719778 #31059] [task:1065] DEBUG -- DirectorJobRunner: (0.000472s) (conn: 47269830134640) SELECT * FROM "vms" WHERE (("cid" = 'agent_id:3dc13f1f-d695-41f4-bccc-e13399b54a7d') AND ("active" IS TRUE)) LIMIT 1
Except problem of recognizing semicolon in VM CID, should the task output also be enhanced to give some error (or warning) message instead of "Succeeded"?
@scottgai what version of director is this output from? I'm not seeing this behavior in 266.x or 265.x.
@dpb587-pivotal It's "BOSH Director for Azure" v2.2-build 296.
I don't have such env on Azure so checked on "BOSH Director for vSphere" v2.2-build 296 and got following info.
ubuntu@opsmgr-env8-v2-2:~$ bosh env
Using environment '172.18.0.11' as client 'ops_manager'
Name p-bosh
UUID aad3cf0c-3075-4adb-9526-024d93f302fe
Version 266.6.0 (00000000)
CPI vsphere_cpi
Features compiled_package_cache: disabled
config_server: enabled
dns: disabled
snapshots: disabled
User ops_manager
and CPI release is as following for this OpsMgr version according to release note.
Azure CPI | 35.2
vSphere CPI | 50
I mentioned in pivotal slack (2018-08-15) that I still hadn't been able to reproduce and would be interested in using one of your test environments to reproduce if you're still interested in this...
do you happen to have a test environment for the azure
delete-vmissue that I could get access to? or a few minutes to pair with you in the environment sometime to check a few things? might be easier than back and forth since i haven't been able to reproduce.
@dpb587-pivotal I don't have my environment anymore, but I just followed the instructions linked in my original post. Unfortunately I don't recall what version of bbl I used, and what Azure region I deployed to.
Issue could be reproduced on PCF 2.2 system not 2.1. Here is bosh env info from one 2.2 system.
$ bosh env
Using environment '10.0.8.10' as client 'ops_manager'
Name p-bosh
UUID 3155ac05-43a1-4027-a37b-658a96ebea98
Version 266.9.0 (00000000)
CPI azure_cpi
Features compiled_package_cache: disabled
config_server: enabled
dns: disabled
snapshots: disabled
User ops_manager
It looks like we do not encode CIDs when making the delete-vm request which can cause the web or app server to truncate the CID at the semicolon while decoding the URI. I think we'll want to change that behavior - we shouldn't be passing through arbitrary, unencoded data in the URLs.
We have created an issue in Pivotal Tracker to manage this:
https://www.pivotaltracker.com/story/show/160390130
The labels on this github issue will be updated when the story is started.
@dpb587-pivotal Just checking what the next step is? Will BOSH director pass an encoded data?
I hit a similar issue in attach_disk. After encoding ; to %3B, the command attach-disk works.
azureuser@binxi091701:~$ bosh -e azure -d cf attach-disk database/6672de96-12bf-4d84-af87-ebb88ddbe26c caching:None%3Bdisk_name:bosh-disk-data-8115562f-fc8f-4cb0-8578-c4e75cee7bba%3Bresource_group_name:binxi091701-vm-size
Using environment '10.0.0.4' as client 'admin'
Using deployment 'cf'
Task 353. Done
Succeeded
Looks like this got fixed a long time ago - https://github.com/cloudfoundry/bosh-cli/commit/505b0e2872d8aa071d7dd5c6b1ffea8cfd15afac#diff-0c7fa9080609bed09798334fcfacc36f so we're closing this issue as it stands.
But...we acknowledge there are probably other places in the CLI that are not properly encoding the URL, so we'll finish the tracker story attached to this issue [1] by scanning through other parts of the bosh-cli codebase.
Hopefully we'll find them all and fix them.
Best, - Aakash & @ssapra, BOSH TEAM
[1] https://www.pivotaltracker.com/story/show/160390130