diff --git a/fixtures.sh b/fixtures.sh index d84b73f..d3aa0cb 100755 --- a/fixtures.sh +++ b/fixtures.sh @@ -20,6 +20,8 @@ docker run -d --name runlike_fixture1 \ --device=/dev/null:/dev/null:r \ --label com.example.group="one" \ --label com.example.environment="test" \ + --add-host hostname2:127.0.0.2 \ + --add-host hostname3:127.0.0.3 \ --log-driver=fluentd \ --log-opt fluentd-async-connect=true \ --log-opt tag=docker.runlike \ diff --git a/runlike/__init__.py b/runlike/__init__.py index 3d18726..dd9b22c 100644 --- a/runlike/__init__.py +++ b/runlike/__init__.py @@ -1 +1 @@ -__version__ = "0.5.0" +__version__ = "0.5.1" diff --git a/runlike/inspector.py b/runlike/inspector.py index fad2abf..ffeb5d3 100644 --- a/runlike/inspector.py +++ b/runlike/inspector.py @@ -150,6 +150,10 @@ def parse_log(self): log_options.add('--log-opt %s=%s' % (key, value)) self.options += list(log_options) + def parse_extra_hosts(self): + hosts = self.get_fact("HostConfig.ExtraHosts") or [] + self.options += ['--add-host %s' % host for host in hosts] + def format_cli(self): self.output = "docker run " @@ -181,6 +185,7 @@ def format_cli(self): self.parse_devices() self.parse_labels() self.parse_log() + self.parse_extra_hosts() stdout_attached = self.get_fact("Config.AttachStdout") if not stdout_attached: diff --git a/test_runlike.py b/test_runlike.py index 677d7c3..4245ad1 100644 --- a/test_runlike.py +++ b/test_runlike.py @@ -95,6 +95,13 @@ def test_one_label(self): def test_labels_not_present(self): self.dont_expect_substr('--label', 3) + def test_extra_hosts(self): + self.expect_substr('--add-host hostname2:127.0.0.2 \\', 1) + self.expect_substr('--add-host hostname3:127.0.0.3 \\', 1) + + def test_extra_hosts_not_present(self): + self.dont_expect_substr('--add-host', 2) + def test_log_driver_default_no_opts(self): self.dont_expect_substr('--log-driver', 2) self.dont_expect_substr('--log-opt', 2)