mirror of https://github.com/docker/docs.git
Merge pull request #2607 from askb/2595-dm-force-fails
Fixes #2595 remove fails when config.json is not found
This commit is contained in:
commit
906ac38d5a
|
|
@ -17,9 +17,13 @@ func cmdRm(c CommandLine, api libmachine.API) error {
|
|||
confirm := c.Bool("y")
|
||||
|
||||
for _, hostName := range c.Args() {
|
||||
h, err := api.Load(hostName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error removing host %q: %s", hostName, err)
|
||||
h, loaderr := api.Load(hostName)
|
||||
if loaderr != nil {
|
||||
// On --force, continue to remove on-disk files/dir
|
||||
if !force {
|
||||
return fmt.Errorf("Error removing host %q: %s", hostName, loaderr)
|
||||
}
|
||||
log.Errorf("Error removing host %q: %s. Continuing on `-f`, host instance may by running", hostName, loaderr)
|
||||
}
|
||||
|
||||
if !confirm && !force {
|
||||
|
|
@ -29,10 +33,12 @@ func cmdRm(c CommandLine, api libmachine.API) error {
|
|||
}
|
||||
}
|
||||
|
||||
if err := h.Driver.Remove(); err != nil {
|
||||
if !force {
|
||||
log.Errorf("Provider error removing machine %q: %s", hostName, err)
|
||||
continue
|
||||
if loaderr == nil {
|
||||
if err := h.Driver.Remove(); err != nil {
|
||||
if !force {
|
||||
log.Errorf("Provider error removing machine %q: %s", hostName, err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,3 +53,87 @@ func TestCmdRm(t *testing.T) {
|
|||
assert.False(t, libmachinetest.Exists(api, "machineToRemove2"))
|
||||
assert.True(t, libmachinetest.Exists(api, "machine"))
|
||||
}
|
||||
|
||||
func TestCmdRmforcefully(t *testing.T) {
|
||||
commandLine := &commandstest.FakeCommandLine{
|
||||
CliArgs: []string{"machineToRemove1", "machineToRemove2"},
|
||||
LocalFlags: &commandstest.FakeFlagger{
|
||||
Data: map[string]interface{}{
|
||||
"force": true,
|
||||
},
|
||||
},
|
||||
}
|
||||
api := &libmachinetest.FakeAPI{
|
||||
Hosts: []*host.Host{
|
||||
{
|
||||
Name: "machineToRemove1",
|
||||
Driver: &fakedriver.Driver{},
|
||||
},
|
||||
{
|
||||
Name: "machineToRemove2",
|
||||
Driver: &fakedriver.Driver{},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
err := cmdRm(commandLine, api)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.False(t, libmachinetest.Exists(api, "machineToRemove1"))
|
||||
assert.False(t, libmachinetest.Exists(api, "machineToRemove2"))
|
||||
}
|
||||
|
||||
func TestCmdRmforceDoesAutoConfirm(t *testing.T) {
|
||||
commandLine := &commandstest.FakeCommandLine{
|
||||
CliArgs: []string{"machineToRemove1", "machineToRemove2"},
|
||||
LocalFlags: &commandstest.FakeFlagger{
|
||||
Data: map[string]interface{}{
|
||||
"y": false,
|
||||
"force": true,
|
||||
},
|
||||
},
|
||||
}
|
||||
api := &libmachinetest.FakeAPI{
|
||||
Hosts: []*host.Host{
|
||||
{
|
||||
Name: "machineToRemove1",
|
||||
Driver: &fakedriver.Driver{},
|
||||
},
|
||||
{
|
||||
Name: "machineToRemove2",
|
||||
Driver: &fakedriver.Driver{},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
err := cmdRm(commandLine, api)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.False(t, libmachinetest.Exists(api, "machineToRemove1"))
|
||||
assert.False(t, libmachinetest.Exists(api, "machineToRemove2"))
|
||||
}
|
||||
|
||||
func TestCmdRmforceConfirmUnset(t *testing.T) {
|
||||
commandLine := &commandstest.FakeCommandLine{
|
||||
CliArgs: []string{"machineToRemove1"},
|
||||
LocalFlags: &commandstest.FakeFlagger{
|
||||
Data: map[string]interface{}{
|
||||
"y": false,
|
||||
"force": false,
|
||||
},
|
||||
},
|
||||
}
|
||||
api := &libmachinetest.FakeAPI{
|
||||
Hosts: []*host.Host{
|
||||
{
|
||||
Name: "machineToRemove1",
|
||||
Driver: &fakedriver.Driver{},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
err := cmdRm(commandLine, api)
|
||||
assert.EqualError(t, err, "EOF")
|
||||
|
||||
assert.True(t, libmachinetest.Exists(api, "machineToRemove1"))
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue