Skip to content

Commit

Permalink
return an error when the server list does not contain the address
Browse files Browse the repository at this point in the history
This is to avoid the error:

2023-09-25 14:43:23 Allocating openstack:cirros-64...
panic: runtime error: index out of range [0] with length 0

goroutine 30 [running]:
github.com/snapcore/spread/spread.(*openstackProvider).waitServerCompleteSetup(0xc0000ae240,
0xc000100e60, 0xf0, 0x0, 0x0)

/home/test/src/github.com/snapcore/spread/spread/openstack.go:379 +0x5bc
github.com/snapcore/spread/spread.(*openstackProvider).createMachine(0xc0000ae240,
0x9183c0, 0xc000069240, 0xc0000a8b40, 0x0, 0xc0000e39d8, 0xc0000a90e0)

/home/test/src/github.com/snapcore/spread/spread/openstack.go:511 +0xbbb
github.com/snapcore/spread/spread.(*openstackProvider).Allocate(0xc0000ae240,
0x9183c0, 0xc000069240, 0xc0000a8b40, 0xc0000a9168, 0xc0000489c8,
0x41a4e3, 0x8)

/home/test/src/github.com/snapcore/spread/spread/openstack.go:143 +0x6e
github.com/snapcore/spread/spread.(*Runner).allocateServer(0xc0000ac900,
0xc00006f080, 0xc0000a8b40, 0x0)
	/home/test/src/github.com/snapcore/spread/spread/runner.go:887
+0x25a
github.com/snapcore/spread/spread.(*Runner).client(0xc0000ac900,
0xc00006f080, 0xc0000a8b40, 0x0)
	/home/test/src/github.com/snapcore/spread/spread/runner.go:769
+0x767
github.com/snapcore/spread/spread.(*Runner).worker(0xc0000ac900,
0xc00006f080, 0xc0000a8b40, 0xc00014c248, 0x1, 0x1)
	/home/test/src/github.com/snapcore/spread/spread/runner.go:536
+0xa0
created by github.com/snapcore/spread/spread.(*Runner).loop
	/home/test/src/github.com/snapcore/spread/spread/runner.go:234
+0x702
  • Loading branch information
sergiocazzolato committed Sep 25, 2023
1 parent 463c503 commit d82abf5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion spread/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,11 @@ func (p *openstackProvider) waitServerCompleteSetup(s *openstackServer, timeoutS
// The adreesses for a network is map of networks and list of ip adresses
// We are configuring just 1 network address for the network
// To get the address is used the first network
s.address = server.Addresses[s.d.Networks[0]][0].Address
if len(server.Addresses) > 0 && len(s.d.Networks) > 0 {
s.address = server.Addresses[s.d.Networks[0]][0].Address
} else {
return fmt.Errorf("cannot retrieve server address")
}

config := &ssh.ClientConfig{
User: "root",
Expand Down

0 comments on commit d82abf5

Please sign in to comment.