Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
Strip newline from docker-machine ip output
Browse files Browse the repository at this point in the history
Docker-machine outputs a newline character at the end of command output.
In case of `ip` command this results in invalid address string if the
trailing newline is not stripped.
  • Loading branch information
Wiezzel committed Dec 6, 2019
1 parent 5478652 commit 58d7f37
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion golem/docker/hypervisor/docker_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def get_port_mapping(self, container_id: str, port: int) -> Tuple[str, int]:
c_config['NetworkSettings']['Ports'][f'{port}/tcp'][0]['HostPort'])
ip = self.command('ip', self._vm_name)
assert isinstance(ip, str)
return ip, port
return ip.strip(), port

@property
def config_dir(self):
Expand Down
2 changes: 1 addition & 1 deletion golem/docker/hypervisor/dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def get_port_mapping(self, container_id: str, port: int) -> Tuple[str, int]:
vm_ip = DockerMachineCommandHandler.run('ip', DOCKER_VM_NAME)
if vm_ip is None:
raise RuntimeError('Cannot retrieve Docker VM IP address')
ip_address = vm_ip
ip_address = vm_ip.strip()
else:
ip_address = net_config['Networks']['bridge']['IPAddress']

Expand Down
5 changes: 1 addition & 4 deletions golem/task/task_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ async def start(self, command: str, port: int) -> Tuple[str, int]:
)
self._runtime = self._env.runtime(runtime_payload)
loop = asyncio.get_event_loop()
d = self._runtime.prepare()
f = d.asFuture(loop)
await f
# await self._runtime.prepare().asFuture(loop)
await self._runtime.prepare().asFuture(loop)
await self._runtime.start().asFuture(loop)
return self._runtime.get_port_mapping(port)

Expand Down
5 changes: 3 additions & 2 deletions tests/golem/docker/test_hypervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ def test_get_port_mapping(self, local_client):
}
hypervisor = MockHypervisor()
vm_ip = '192.168.64.151'
with mock.patch.object(hypervisor, 'command', return_value=vm_ip):
cmd_out = vm_ip + '\n'
with mock.patch.object(hypervisor, 'command', return_value=cmd_out):
host, port = hypervisor.get_port_mapping('container_id', 12345)
self.assertEqual(host, vm_ip)
self.assertEqual(port, 54321)
Expand Down Expand Up @@ -502,7 +503,7 @@ def test_get_port_mapping(self, local_client, command_handler):
}
}
vm_ip = '10.0.0.3'
command_handler.run.return_value = vm_ip
command_handler.run.return_value = vm_ip + '\n'

hypervisor = DummyHypervisor(mock.Mock())
host, port = hypervisor.get_port_mapping('container_id', 12345)
Expand Down

0 comments on commit 58d7f37

Please # to comment.