equinixmetal-archive/packngo

Potential bug in volume attachment code

jprukner opened this issue · 5 comments

Hi!
I got problem with volume attachment using this library. When I use script available at https://github.com/packethost/csi-packet/blob/master/packet-scripts/create_and_attach.sh, I can get targets using iscsiadm just fine:

root@master:~# export PACKET_TOKEN=...
root@master:~# create_and_attach.sh master
...
root@master:~# iscsiadm --mode discovery --portal 10.144.35.235 --type sendtargets --discover
10.144.51.100:3260,1 iqn.2013-05.com.daterainc:tc:01:sn:ecbfd08c1c3c38aa
10.144.35.235:3260,1 iqn.2013-05.com.daterainc:tc:01:sn:ecbfd08c1c3c38aa

When I try this same thing using packngo, please see https://gist.github.com/jprukner/55b1c9321c50fb2e7eb042875ececa03, volume is created and attached but I'm not able to get targets, iscsiadm fails with error No portals found:

root@master:~/go/src/packetvolume# go run main.go
2019/05/14 12:58:10 Created packngo.Volume{Attachments:[], BillingCycle:"hourly", Created:"2019-05-14T12:58:09Z", Description:"testingvolume", Facility:packngo.Facility{ID:"", Name:"", Code:"", URL:"/facilities/e1e9c52e-a0bc-4117-b996-0fc94843ea09"}, Href:"/storage/907f0794-8dff-4511-8430-e1d3cf39b4da", ID:"907f0794-8dff-4511-8430-e1d3cf39b4da", Locked:false, Name:"volume-907f0794", Plan:packngo.Plan{ID:"87728148-3155-4992-a730-8d1e6aca8a32", Slug:"storage_1", Name:"Standard", Description:"TBD", Line:"storage", Specs:packngo.Specs{}, Pricing:packngo.Pricing{Hourly:0, Monthly:0}}, Project:packngo.Project{ID:"", Name:"", Organization:packngo.Organization{ID:"", Name:"", Description:"", Website:"", Twitter:"", Created:"", Updated:"", Address:packngo.Address{ID:""}, TaxID:"", MainPhone:"", BillingPhone:"", CreditAmount:0, Logo:"", LogoThumb:"", URL:""}, Created:"", Updated:"", URL:"/projects/2fd10789-77c0-4138-9d6c-d7e8c7a81ed2", PaymentMethod:packngo.PaymentMethod{ID:"", Name:"", Created:"", Updated:"", Nonce:"", Default:false, Organization:packngo.Organization{ID:"", Name:"", Description:"", Website:"", Twitter:"", Created:"", Updated:"", Address:packngo.Address{ID:""}, TaxID:"", MainPhone:"", BillingPhone:"", CreditAmount:0, Logo:"", LogoThumb:"", URL:""}, Type:"", CardholderName:"", ExpMonth:"", ExpYear:"", Last4:"", BillingAddress:packngo.BillingAddress{StreetAddress:"", PostalCode:"", CountryCode:""}, URL:""}}, Size:10, SnapshotPolicies:[], State:"queued", Updated:"2019-05-14T12:58:09Z"}
2019/05/14 12:58:11 201
2019/05/14 12:58:11 &{/storage/attachments/fdb5cf44-7122-405b-9ce7-93579f22c00f fdb5cf44-7122-405b-9ce7-93579f22c00f packngo.Volume{BillingCycle:"", Created:"", Description:"", Href:"/storage/907f0794-8dff-4511-8430-e1d3cf39b4da", ID:"", Locked:false, Name:"", Size:0, State:"", Updated:""} packngo.Device{ID:"", Href:"/devices/7670d17c-79e5-4be2-921a-0cf8902da000", Hostname:"", State:"", Created:"", Updated:"", Locked:false, BillingCycle:"", Storage:map[], ProvisionPer:0, UserData:"", RootPassword:"", IPXEScriptURL:"", AlwaysPXE:false, HardwareReservation:packngo.Href{Href:""}, SpotInstance:false, SpotPriceMax:0}}
root@master:~/go/src/packetvolume# iscsiadm --mode discovery --portal 10.144.35.235 --type sendtargets --discover
iscsiadm: No portals found

When I dettach the volume created by packngo by hand in portal and attach it back again, everything works fine. When I create new volume and attach it using create_and_attach.sh mentioned above, everything works also fine. So I suspect there is something wrong with volume attachment code in packngo library. Any ideas @t0mk?

Packngo version used:

[[constraint]]
  name = "github.com/packethost/packngo"
  revision = "269c1b559fe7609a20f26ca76584669a6db1a409"

Ok, so that is wierd. I reran the go program, got new IPs for a volume, everything works now. So it might be related to provisioning through api but only for some cases. Closing for now, until I get what is going on.

I was trying to figure this out why running https://gist.github.com/jprukner/55b1c9321c50fb2e7eb042875ececa03 sometimes works and I can get targets and sometimes I can't get them. It might have something to do with the way requests are sent to the Packet API and the way the API interprets them. Using curl works everytime in create_and_attach.sh script. What do you think? @t0mk

Thanks @jprukner will get some eyes on this to see if we have an API caching issue or related going on.

t0mk commented

hey @jprukner, greetings to my hometown :)

The volume API resource has state, and in your comment, the state is queued. Maybe you can wait for the volume to be active? Like here:
https://github.com/packethost/packngo/blob/master/volumes_test.go#L9

If the problem persists for active volumes, I will take a deeper look.

BTW, you can set PACKNGO_DEBUG=1 and compiled binary should print HTTP requests and reposes, might be useful for debugging.

@t0mk you come from Brno? What a coincidence! :D
Thank you for suggestions. If there hasn't been any issue with Packet API fixed @jacobsmith928 , waiting for the volume to be active before attaching it solves this issue. Closing.