Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Centralize all RBD related shell cmds and logging #529

Merged
merged 1 commit into from
May 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 26 additions & 17 deletions drivers/storage/rbd/executor/rbd_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/akutz/goof"
"github.com/akutz/gotil"

"github.com/codedellemc/libstorage/api/context"
"github.com/codedellemc/libstorage/api/registry"
"github.com/codedellemc/libstorage/api/types"
"github.com/codedellemc/libstorage/drivers/storage/rbd"
Expand Down Expand Up @@ -56,7 +57,8 @@ func (d *driver) Supported(
return false, nil
}

if err := exec.Command("modprobe", "rbd").Run(); err != nil {
cmd := exec.Command("modprobe", "rbd")
if _, _, err := utils.RunCommand(ctx, cmd); err != nil {
return false, nil
}

Expand Down Expand Up @@ -94,13 +96,15 @@ func (d *driver) InstanceID(
ctx types.Context,
opts types.Store) (*types.InstanceID, error) {

return GetInstanceID(nil, nil)
return GetInstanceID(ctx, nil, nil)
}

// GetInstanceID returns the instance ID object
func GetInstanceID(
ctx types.Context,
monIPs []net.IP,
localIntfs []net.Addr) (*types.InstanceID, error) {

/* Ceph doesn't have only one unique identifier per client, it can have
several. With the way the RBD driver is used, we will see multiple
identifiers used, and therefore returning any of those identifiers
Expand All @@ -112,15 +116,19 @@ func GetInstanceID(
segment so we grab the IP from the default route.
*/

if ctx == nil {
ctx = context.Background()
}

var err error
if nil == monIPs {
monIPs, err = getCephMonIPs()
monIPs, err = getCephMonIPs(ctx)
if err != nil {
return nil, err
}
}
if len(monIPs) == 0 {
return nil, goof.New("No Ceph Monitors found")
return nil, goof.New("no ceph monitors found")
}

if nil == localIntfs {
Expand All @@ -143,7 +151,7 @@ func GetInstanceID(
}

// No luck finding L2 match, check for default/static route to monitor
localIP, err := getSrcIP(monIPs[0].String())
localIP, err := getSrcIP(ctx, monIPs[0].String())
if err != nil {
return nil, err
}
Expand All @@ -152,14 +160,12 @@ func GetInstanceID(
return iid, nil
}

func getCephMonIPs() ([]net.IP, error) {
out, err := exec.Command("ceph-conf", "--lookup", "mon_host").Output()
func getCephMonIPs(ctx types.Context) ([]net.IP, error) {

cmd := exec.Command("ceph-conf", "--lookup", "mon_host")
out, _, err := utils.RunCommand(ctx, cmd)
if err != nil {
if exiterr, ok := err.(*exec.ExitError); ok {
return nil, goof.WithField("stderr", string(exiterr.Stderr),
"unable to get Ceph monitors")
}
return nil, goof.WithError("unable to get Ceph monitors", err)
return nil, goof.WithError("unable to get ceph monitors", err)
}

monStrings := strings.Split(strings.TrimSpace(string(out)), ",")
Expand All @@ -172,11 +178,14 @@ func getCephMonIPs() ([]net.IP, error) {
return monIps, nil
}

func getSrcIP(destIP string) (string, error) {
out, err := exec.Command(
"ip", "-oneline", "route", "get", destIP).Output()
func getSrcIP(
ctx types.Context,
destIP string) (string, error) {

cmd := exec.Command("ip", "-oneline", "route", "get", destIP)
out, _, err := utils.RunCommand(ctx, cmd)
if err != nil {
return "", goof.WithError("Unable get IP routes", err)
return "", goof.WithError("unable get ip routes", err)
}

byteReader := bytes.NewReader(out)
Expand All @@ -192,5 +201,5 @@ func getSrcIP(destIP string) (string, error) {
}
return scanner.Text(), nil
}
return "", goof.New("Unable to parse ip output")
return "", goof.New("unable to parse ip output")
}
5 changes: 3 additions & 2 deletions drivers/storage/rbd/tests/rbd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestInstanceID(t *testing.T) {
t.SkipNow()
}

iid, err := rbdx.GetInstanceID(nil, nil)
iid, err := rbdx.GetInstanceID(nil, nil, nil)
assert.NoError(t, err)
if err != nil {
t.Error("failed TestInstanceID")
Expand Down Expand Up @@ -143,7 +143,8 @@ func TestInstanceIDSimulatedIPs(t *testing.T) {
}

for _, test := range testIPs {
iid, err := rbdx.GetInstanceID(test.monIPs, test.interfaces)
iid, err := rbdx.GetInstanceID(
nil, test.monIPs, test.interfaces)

assert.NoError(t, err)
if err != nil {
Expand Down
Loading