Skip to content

Commit

Permalink
Merge pull request #41 from raviprasadsn/rpcluster
Browse files Browse the repository at this point in the history
cmd/status.go:31 (TODO): Added px describe cluster command
  • Loading branch information
lpabon authored Aug 9, 2019
2 parents 99ae5b0 + efc2512 commit 82eee11
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 94 deletions.
53 changes: 26 additions & 27 deletions cmd/status.go → cmd/describeCluster.go
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
/*
Copyright © 2019 Portworx
// Copyright © 2019 Portworx
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
"fmt"

api "github.com/libopenstorage/openstorage-sdk-clients/sdk/golang"
"github.com/portworx/px/pkg/util"

"github.com/spf13/cobra"
)

var statusCmd *cobra.Command
var describeClusterCmd *cobra.Command

var _ = RegisterCommandVar(func() {
statusCmd = &cobra.Command{
Use: "status",
// TODO
Short: "TODO: this will move to px describe cluster",
RunE: statusExec,
// describeClusterCmd represents the describeCluster command
describeClusterCmd = &cobra.Command{
Use: "cluster",
Short: "Describe a Portworx cluster",
Long: "Show detailed information of Portworx cluster",
Example: `$ px describe cluster`,

RunE: describeClusterExec,
}
})

var _ = RegisterCommandInit(func() {
rootCmd.AddCommand(statusCmd)
describeCmd.AddCommand(describeClusterCmd)
})

func statusExec(cmd *cobra.Command, args []string) error {
func describeClusterExec(cmd *cobra.Command, args []string) error {
ctx, conn, err := PxConnectDefault()
if err != nil {
return err
Expand All @@ -54,10 +54,10 @@ func statusExec(cmd *cobra.Command, args []string) error {
}
var versionDetails string
for k, v := range version.GetVersion().GetDetails() {
versionDetails += fmt.Sprintf(" %s: %s\n", k, v)
versionDetails += fmt.Sprintf(" %s: %s\n", k, v)
}

// Print the cluster information
// Print cluster information
cluster := api.NewOpenStorageClusterClient(conn)
clusterInfo, err := cluster.InspectCurrent(ctx, &api.SdkClusterInspectCurrentRequest{})
if err != nil {
Expand Down Expand Up @@ -104,7 +104,6 @@ func statusExec(cmd *cobra.Command, args []string) error {
}
usedStr := fmt.Sprintf("%d Gi", used/Gi)
capacityStr := fmt.Sprintf("%d Gi", capacity/Gi)

t.AddLine(n.GetHostname(), n.GetMgmtIp(), n.GetSchedulerNodeName(), usedStr, capacityStr, n.GetStatus())
}
t.Print()
Expand Down
75 changes: 75 additions & 0 deletions cmd/describeCluster_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
Copyright © 2019 Portworx
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
"strings"
"testing"

"github.com/stretchr/testify/assert"
)

func getKey(s string, delim string) []string {
x := strings.Split(s, delim)
return x
}

func TestDescribeCluster(t *testing.T) {

// Setup to run: px describe cluster and return the Stdout, Stderr,
// and a function to restore state
so, _, r := pxTestSetupCli("px describe cluster")

// Defer to cleanup state
defer r()

// Start the CLI
err := runPx()
assert.NoError(t, err)

lines := strings.Split(so.String(), "\n")
index := 0
k := getKey(lines[index], ":")
assert.Contains(t, k[0], "Cluster ID")
index++
k = getKey(lines[index], ":")
assert.Contains(t, k, "Cluster UUID")
index++
k = getKey(lines[index], ":")
assert.Contains(t, k, "Cluster Status")
index++
k = getKey(lines[index], ":")
assert.Contains(t, k, "Version")
index++
k = getKey(lines[index], ":")
/* need to fix mock server
mock server returns example: data instead of build
*/
//assert.Contains(t, k, "build")
index++
k = getKey(lines[index], " ")
assert.Contains(t, k, "SDK")
assert.Contains(t, k[1], "Version")
index++
index++
k = getKey(lines[index], " ")
assert.Contains(t, k[0], "Hostname")
assert.Contains(t, k[6], "IP")
assert.Contains(t, k[16], "SchedulerNodeName")
assert.Contains(t, k[18], "Used")
assert.Contains(t, k[20], "Capacity")
assert.Contains(t, k[22], "Status")
}
67 changes: 0 additions & 67 deletions cmd/status_test.go

This file was deleted.

0 comments on commit 82eee11

Please sign in to comment.