Merge pull request #16942 from swagiaal/distinguish-format-and-mount

Auto commit by PR queue bot
This commit is contained in:
k8s-merge-robot
2015-12-03 10:51:26 -08:00
12 changed files with 42 additions and 32 deletions

View File

@@ -49,16 +49,20 @@ type MountPoint struct {
Pass int
}
// SafeFormatAndMount probes a device to see if it is formatted. If
// so it mounts it otherwise it formats it and mounts it
// SafeFormatAndMount probes a device to see if it is formatted.
// Namely it checks to see if a file system is present. If so it
// mounts it otherwise the device is formatted first then mounted.
type SafeFormatAndMount struct {
Interface
Runner exec.Interface
}
// Mount mounts the given disk. If the disk is not formatted and the disk is not being mounted as read only
// it will format the disk first then mount it.
func (mounter *SafeFormatAndMount) Mount(source string, target string, fstype string, options []string) error {
// FormatAndMount formats the given disk, if needed, and mounts it.
// That is if the disk is not formatted and it is not being mounted as
// read-only it will format it first then mount it. Otherwise, if the
// disk is already formatted or it is being mounted as read-only, it
// will be mounted without formatting.
func (mounter *SafeFormatAndMount) FormatAndMount(source string, target string, fstype string, options []string) error {
// Don't attempt to format if mounting as readonly. Go straight to mounting.
for _, option := range options {
if option == "ro" {

View File

@@ -156,7 +156,7 @@ func TestSafeFormatAndMount(t *testing.T) {
device := "/dev/foo"
dest := "/mnt/bar"
err := mounter.Mount(device, dest, test.fstype, test.mountOptions)
err := mounter.FormatAndMount(device, dest, test.fstype, test.mountOptions)
if test.expectedError == nil {
if err != nil {
t.Errorf("unexpected non-error: %v", err)