Skip to content

Commit

Permalink
config: do not shutdown conn if not yet connected
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Outhenin-Chalandre <arthur.outhenin-chalandre@cern.ch>
  • Loading branch information
MrFreezeex committed Jun 24, 2022
1 parent 8a7df0b commit 2e46f30
Showing 1 changed file with 0 additions and 8 deletions.
8 changes: 0 additions & 8 deletions ceph/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ func (config *Config) GetCephConnection() (*rados.Conn, error) {
conn, err = rados.NewConn()
}
if err != nil {
conn.Shutdown()
return nil, err
}

if config.ConfigPath != "" {
if err = conn.ReadConfigFile(config.ConfigPath); err != nil {
conn.Shutdown()
return nil, err
}
} else {
Expand All @@ -47,22 +45,19 @@ func (config *Config) GetCephConnection() (*rados.Conn, error) {

if config.MonHost != "" {
if err = conn.SetConfigOption("mon_host", config.MonHost); err != nil {
conn.Shutdown()
return nil, err
}
}

if config.Key != "" {
if err = conn.SetConfigOption("key", config.Key); err != nil {
conn.Shutdown()
return nil, err
}
}

if config.Keyring != "" {
keyringFile, err := ioutil.TempFile("", "terraform-provider-ceph")
if err != nil {
conn.Shutdown()
return nil, err
}
defer os.Remove(keyringFile.Name())
Expand All @@ -71,15 +66,12 @@ func (config *Config) GetCephConnection() (*rados.Conn, error) {
return nil, err
}
if _, err = keyringFile.WriteString(config.Keyring); err != nil {
conn.Shutdown()
return nil, err
}
}

if err = conn.Connect(); err == nil {
config.RadosConn = conn
} else {
conn.Shutdown()
}
return conn, err
}

0 comments on commit 2e46f30

Please sign in to comment.