forked from canonical/microceph
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Peter Sabaini <[email protected]>
- Loading branch information
Showing
4 changed files
with
283 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/canonical/microceph/microceph/api/types" | ||
"github.com/canonical/microceph/microceph/client" | ||
"github.com/canonical/microceph/microceph/mocks" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type clusterRemoveSuite struct { | ||
suite.Suite | ||
} | ||
|
||
func TestClusterRemove(t *testing.T) { | ||
suite.Run(t, new(clusterRemoveSuite)) | ||
} | ||
|
||
func (s *clusterRemoveSuite) SetupTest() { | ||
|
||
} | ||
|
||
// TestRemoveNode tests the happy path of node removal | ||
func (s *clusterRemoveSuite) TestRemoveNode() { | ||
m := mocks.NewClientInterface(s.T()) | ||
|
||
client.MClient = m | ||
m.On("GetClusterMembers", mock.Anything).Return([]string{"foonode", "barnode", "quuxnode"}, nil).Once() | ||
m.On("GetDisks", mock.Anything).Return(types.Disks{}, nil).Once() | ||
m.On("GetServices", mock.Anything).Return( | ||
types.Services{ | ||
{ | ||
Service: "mon", | ||
Location: "foonode", | ||
}, | ||
{ | ||
Service: "mon", | ||
Location: "barnode", | ||
}, | ||
{ | ||
Service: "mgr", | ||
Location: "barnode", | ||
}, | ||
{ | ||
Service: "mds", | ||
Location: "barnode", | ||
}, | ||
}, | ||
nil, | ||
) | ||
m.On("DeleteService", mock.Anything, "foonode", "mon").Return(nil).Once() | ||
m.On("DeleteClusterMember", mock.Anything, "foonode", false).Return(nil).Once() | ||
|
||
err := removeNode(nil, "foonode", false) | ||
|
||
assert.NoError(s.T(), err) | ||
} | ||
|
||
// TestRemoveNodeWithDisks tests that we don't try to delete a node that has OSDs | ||
func (s *clusterRemoveSuite) TestRemoveNodeWithDisks() { | ||
m := mocks.NewClientInterface(s.T()) | ||
|
||
client.MClient = m | ||
m.On("GetClusterMembers", mock.Anything).Return([]string{"foonode", "barnode", "quuxnode"}, nil).Once() | ||
m.On("GetDisks", mock.Anything).Return(types.Disks{ | ||
{ | ||
Location: "foonode", | ||
}, | ||
}, nil).Once() | ||
|
||
err := removeNode(nil, "foonode", false) | ||
|
||
assert.Error(s.T(), err) | ||
|
||
// assert that we didn't try to delete the node | ||
m.AssertNotCalled(s.T(), "DeleteClusterMember", mock.Anything, "foonode", false) | ||
} | ||
|
||
// TestRemoveNodeLastMon tests that we don't try to delete a node that has the last mon | ||
func (s *clusterRemoveSuite) TestRemoveNodeLastMon() { | ||
m := mocks.NewClientInterface(s.T()) | ||
|
||
client.MClient = m | ||
m.On("GetClusterMembers", mock.Anything).Return([]string{"foonode", "barnode", "quuxnode"}, nil).Once() | ||
m.On("GetDisks", mock.Anything).Return(types.Disks{}, nil).Once() | ||
m.On("GetServices", mock.Anything).Return( | ||
types.Services{ | ||
{ | ||
Service: "mon", | ||
Location: "foonode", | ||
}, | ||
}, | ||
nil, | ||
) | ||
|
||
err := removeNode(nil, "foonode", false) | ||
|
||
assert.Error(s.T(), err) | ||
|
||
// assert that we didn't try to delete the node | ||
m.AssertNotCalled(s.T(), "DeleteClusterMember", mock.Anything, "foonode", false) | ||
} | ||
|
||
// TestRemoveNodeForce tests that we don't check prerequisites and delete a node if forced | ||
func (s *clusterRemoveSuite) TestRemoveNodeForce() { | ||
m := mocks.NewClientInterface(s.T()) | ||
|
||
client.MClient = m | ||
|
||
m.On("GetServices", mock.Anything).Return( | ||
types.Services{ | ||
{ | ||
Service: "mon", | ||
Location: "foonode", | ||
}, | ||
}, | ||
nil, | ||
) | ||
m.On("DeleteService", mock.Anything, "foonode", "mon").Return(nil).Once() | ||
m.On("DeleteClusterMember", mock.Anything, "foonode", true).Return(nil).Once() | ||
|
||
err := removeNode(nil, "foonode", true) | ||
|
||
assert.NoError(s.T(), err) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.