From f411f8bfc5d04aed6499dfc90e357c58713bc84d Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Wed, 11 Jun 2014 20:54:40 +0000 Subject: [PATCH 1/2] Allow --net=none & -h Docker-DCO-1.1-Signed-off-by: Victor Vieux (github: vieux) --- runconfig/parse.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runconfig/parse.go b/runconfig/parse.go index 0fa287adb1..acb0b41c87 100644 --- a/runconfig/parse.go +++ b/runconfig/parse.go @@ -18,7 +18,7 @@ var ( ErrInvalidWorkingDirectory = fmt.Errorf("The working directory is invalid. It needs to be an absolute path.") ErrConflictAttachDetach = fmt.Errorf("Conflicting options: -a and -d") ErrConflictDetachAutoRemove = fmt.Errorf("Conflicting options: --rm and -d") - ErrConflictNetworkHostname = fmt.Errorf("Conflicting options: -h and --net") + ErrConflictNetworkHostname = fmt.Errorf("Conflicting options: -h and the network mode (--net)") ) //FIXME Only used in tests @@ -104,7 +104,7 @@ func parseRun(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Conf return nil, nil, cmd, ErrConflictDetachAutoRemove } - if *flNetMode != "bridge" && *flHostname != "" { + if *flNetMode != "bridge" && *flNetMode != "none" && *flHostname != "" { return nil, nil, cmd, ErrConflictNetworkHostname } From 6cb16f1c316c55e3b6108d178ffcde2e705cbe47 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Wed, 11 Jun 2014 21:15:48 +0000 Subject: [PATCH 2/2] add tests Docker-DCO-1.1-Signed-off-by: Victor Vieux (github: vieux) --- runconfig/parse_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/runconfig/parse_test.go b/runconfig/parse_test.go index 8ad40b9d2d..88fa0dd542 100644 --- a/runconfig/parse_test.go +++ b/runconfig/parse_test.go @@ -22,3 +22,29 @@ func TestParseLxcConfOpt(t *testing.T) { } } } + +func TestNetHostname(t *testing.T) { + if _, _, _, err := Parse([]string{"-h=name", "img", "cmd"}, nil); err != nil { + t.Fatal("Unexpected error: %s", err) + } + + if _, _, _, err := Parse([]string{"--net=host", "img", "cmd"}, nil); err != nil { + t.Fatal("Unexpected error: %s", err) + } + + if _, _, _, err := Parse([]string{"-h=name", "--net=bridge", "img", "cmd"}, nil); err != nil { + t.Fatal("Unexpected error: %s", err) + } + + if _, _, _, err := Parse([]string{"-h=name", "--net=none", "img", "cmd"}, nil); err != nil { + t.Fatal("Unexpected error: %s", err) + } + + if _, _, _, err := Parse([]string{"-h=name", "--net=host", "img", "cmd"}, nil); err != ErrConflictNetworkHostname { + t.Fatal("Expected error ErrConflictNetworkHostname, got: %s", err) + } + + if _, _, _, err := Parse([]string{"-h=name", "--net=container:other", "img", "cmd"}, nil); err != ErrConflictNetworkHostname { + t.Fatal("Expected error ErrConflictNetworkHostname, got: %s", err) + } +}