Beispiel #1
0
    def test_parse_host_empty_value(self):
        unix_socket = 'http+unix://var/run/docker.sock'
        tcp_port = 'http://127.0.0.1:2375'

        for val in [None, '']:
            assert parse_host(val, is_win32=False) == unix_socket
            assert parse_host(val, is_win32=True) == tcp_port
    def test_parse_host(self):
        invalid_hosts = [
            '0.0.0.0',
            'tcp://',
            'udp://127.0.0.1',
            'udp://127.0.0.1:2375',
        ]

        valid_hosts = {
            '0.0.0.1:5555': 'http://0.0.0.1:5555',
            ':6666': 'http://127.0.0.1:6666',
            'tcp://:7777': 'http://127.0.0.1:7777',
            'http://:7777': 'http://127.0.0.1:7777',
            'https://kokia.jp:2375': 'https://kokia.jp:2375',
            '': 'http+unix://var/run/docker.sock',
            None: 'http+unix://var/run/docker.sock',
            'unix:///var/run/docker.sock': 'http+unix:///var/run/docker.sock',
            'unix://': 'http+unix://var/run/docker.sock'
        }

        for host in invalid_hosts:
            try:
                parsed = parse_host(host)
                self.fail('Expected to fail but success: %s -> %s' % (
                    host, parsed
                ))
            except DockerException:
                pass

        for host, expected in valid_hosts.items():
            self.assertEqual(parse_host(host), expected, msg=host)
    def test_parse_host(self):
        invalid_hosts = [
            '0.0.0.0',
            'tcp://',
            'udp://127.0.0.1',
            'udp://127.0.0.1:2375',
        ]

        valid_hosts = {
            '0.0.0.1:5555': 'http://0.0.0.1:5555',
            ':6666': 'http://127.0.0.1:6666',
            'tcp://:7777': 'http://127.0.0.1:7777',
            'http://:7777': 'http://127.0.0.1:7777',
            'https://kokia.jp:2375': 'https://kokia.jp:2375',
            '': 'http+unix://var/run/docker.sock',
            None: 'http+unix://var/run/docker.sock',
            'unix:///var/run/docker.sock': 'http+unix:///var/run/docker.sock',
            'unix://': 'http+unix://var/run/docker.sock'
        }

        for host in invalid_hosts:
            try:
                parsed = parse_host(host)
                self.fail('Expected to fail but success: %s -> %s' %
                          (host, parsed))
            except DockerException:
                pass

        for host, expected in valid_hosts.items():
            self.assertEqual(parse_host(host), expected, msg=host)
Beispiel #4
0
    def test_parse_host_empty_value(self):
        unix_socket = 'http+unix://var/run/docker.sock'
        npipe = 'npipe:////./pipe/docker_engine'

        for val in [None, '']:
            assert parse_host(val, is_win32=False) == unix_socket
            assert parse_host(val, is_win32=True) == npipe
Beispiel #5
0
    def test_parse_host(self):
        invalid_hosts = [
            '0.0.0.0',
            'tcp://',
            'udp://127.0.0.1',
            'udp://127.0.0.1:2375',
        ]

        valid_hosts = {
            '0.0.0.1:5555':
            'http://0.0.0.1:5555',
            ':6666':
            'http://127.0.0.1:6666',
            'tcp://:7777':
            'http://127.0.0.1:7777',
            'http://:7777':
            'http://127.0.0.1:7777',
            'https://kokia.jp:2375':
            'https://kokia.jp:2375',
            'unix:///var/run/docker.sock':
            'http+unix:///var/run/docker.sock',
            'unix://':
            'http+unix://var/run/docker.sock',
            'somehost.net:80/service/swarm':
            ('http://somehost.net:80/service/swarm'),
        }

        for host in invalid_hosts:
            with pytest.raises(DockerException):
                parse_host(host, None)

        for host, expected in valid_hosts.items():
            self.assertEqual(parse_host(host, None), expected, msg=host)
Beispiel #6
0
    def test_parse_host(self):
        invalid_hosts = ["0.0.0.0", "tcp://", "udp://127.0.0.1", "udp://127.0.0.1:2375"]

        valid_hosts = {
            "0.0.0.1:5555": "http://0.0.0.1:5555",
            ":6666": "http://127.0.0.1:6666",
            "tcp://:7777": "http://127.0.0.1:7777",
            "http://:7777": "http://127.0.0.1:7777",
            "https://kokia.jp:2375": "https://kokia.jp:2375",
            "": "http+unix://var/run/docker.sock",
            None: "http+unix://var/run/docker.sock",
            "unix:///var/run/docker.sock": "http+unix:///var/run/docker.sock",
            "unix://": "http+unix://var/run/docker.sock",
            "somehost.net:80/service/swarm": ("http://somehost.net:80/service/swarm"),
        }

        for host in invalid_hosts:
            try:
                parsed = parse_host(host)
                self.fail("Expected to fail but success: %s -> %s" % (host, parsed))
            except DockerException:
                pass

        for host, expected in valid_hosts.items():
            self.assertEqual(parse_host(host), expected, msg=host)
Beispiel #7
0
    def test_parse_host_empty_value(self):
        unix_socket = 'http+unix://var/run/docker.sock'
        npipe = 'npipe:////./pipe/docker_engine'

        for val in [None, '']:
            assert parse_host(val, is_win32=False) == unix_socket
            assert parse_host(val, is_win32=True) == npipe
Beispiel #8
0
    def test_parse_host(self):
        invalid_hosts = [
            '0.0.0.0',
            'tcp://',
            'udp://127.0.0.1',
            'udp://127.0.0.1:2375',
        ]

        valid_hosts = {
            '0.0.0.1:5555': 'http://0.0.0.1:5555',
            ':6666': 'http://127.0.0.1:6666',
            'tcp://:7777': 'http://127.0.0.1:7777',
            'http://:7777': 'http://127.0.0.1:7777',
            'https://kokia.jp:2375': 'https://kokia.jp:2375',
            'unix:///var/run/docker.sock': 'http+unix:///var/run/docker.sock',
            'unix://': 'http+unix://var/run/docker.sock',
            'somehost.net:80/service/swarm': (
                'http://somehost.net:80/service/swarm'
            ),
        }

        for host in invalid_hosts:
            with pytest.raises(DockerException):
                parse_host(host, None)

        for host, expected in valid_hosts.items():
            self.assertEqual(parse_host(host, None), expected, msg=host)
Beispiel #9
0
    def test_parse_host_empty_value(self):
        unix_socket = 'http+unix://var/run/docker.sock'
        tcp_port = 'http://127.0.0.1:2375'

        for val in [None, '']:
            assert parse_host(val, is_win32=False) == unix_socket
            assert parse_host(val, is_win32=True) == tcp_port
Beispiel #10
0
    def test_parse_host_empty_value(self):
        unix_socket = 'http+unix://var/run/docker.sock'
        tcp_port = 'http://127.0.0.1:2375'

        for val in [None, '']:
            for platform in ['darwin', 'linux2', None]:
                assert parse_host(val, platform) == unix_socket

            assert parse_host(val, 'win32') == tcp_port
Beispiel #11
0
    def test_parse_host_empty_value(self):
        unix_socket = 'http+unix://var/run/docker.sock'
        tcp_port = 'http://127.0.0.1:2375'

        for val in [None, '']:
            for platform in ['darwin', 'linux2', None]:
                assert parse_host(val, platform) == unix_socket

            assert parse_host(val, 'win32') == tcp_port
Beispiel #12
0
    def test_parse_host_empty_value(self):
        unix_socket = "http+unix://var/run/docker.sock"
        tcp_port = "http://127.0.0.1:2375"

        for val in [None, ""]:
            for platform in ["darwin", "linux2", None]:
                assert parse_host(val, platform) == unix_socket

            assert parse_host(val, "win32") == tcp_port
Beispiel #13
0
    def test_parse_host(self):
        invalid_hosts = [
            '0.0.0.0',
            'tcp://',
            'udp://127.0.0.1',
            'udp://127.0.0.1:2375',
            'ssh://:22/path',
            'tcp://*****:*****@host:22',
        ]

        valid_hosts = {
            '0.0.0.1:5555':
            'http://0.0.0.1:5555',
            ':6666':
            'http://127.0.0.1:6666',
            'tcp://:7777':
            'http://127.0.0.1:7777',
            'http://:7777':
            'http://127.0.0.1:7777',
            'https://kokia.jp:2375':
            'https://kokia.jp:2375',
            'unix:///var/run/docker.sock':
            'http+unix:///var/run/docker.sock',
            'unix://':
            'http+unix:///var/run/docker.sock',
            '12.234.45.127:2375/docker/engine':
            ('http://12.234.45.127:2375/docker/engine'),
            'somehost.net:80/service/swarm':
            ('http://somehost.net:80/service/swarm'),
            'npipe:////./pipe/docker_engine':
            'npipe:////./pipe/docker_engine',
            '[fd12::82d1]:2375':
            'http://[fd12::82d1]:2375',
            'https://[fd12:5672::12aa]:1090':
            'https://[fd12:5672::12aa]:1090',
            '[fd12::82d1]:2375/docker/engine':
            ('http://[fd12::82d1]:2375/docker/engine'),
            'ssh://':
            'ssh://127.0.0.1:22',
            'ssh://user@localhost:22':
            'ssh://user@localhost:22',
            'ssh://user@remote':
            'ssh://user@remote:22',
        }

        for host in invalid_hosts:
            with pytest.raises(DockerException):
                parse_host(host, None)

        for host, expected in valid_hosts.items():
            assert parse_host(host, None) == expected
Beispiel #14
0
    def test_parse_host(self):
        invalid_hosts = [
            '0.0.0.0',
            'tcp://',
            'udp://127.0.0.1',
            'udp://127.0.0.1:2375',
            'ssh://:22/path',
            'tcp://*****:*****@host:22',
        ]

        valid_hosts = {
            '0.0.0.1:5555': 'http://0.0.0.1:5555',
            ':6666': 'http://127.0.0.1:6666',
            'tcp://:7777': 'http://127.0.0.1:7777',
            'http://:7777': 'http://127.0.0.1:7777',
            'https://kokia.jp:2375': 'https://kokia.jp:2375',
            'unix:///var/run/docker.sock': 'http+unix:///var/run/docker.sock',
            'unix://': 'http+unix:///var/run/docker.sock',
            '12.234.45.127:2375/docker/engine': (
                'http://12.234.45.127:2375/docker/engine'
            ),
            'somehost.net:80/service/swarm': (
                'http://somehost.net:80/service/swarm'
            ),
            'npipe:////./pipe/docker_engine': 'npipe:////./pipe/docker_engine',
            '[fd12::82d1]:2375': 'http://[fd12::82d1]:2375',
            'https://[fd12:5672::12aa]:1090': 'https://[fd12:5672::12aa]:1090',
            '[fd12::82d1]:2375/docker/engine': (
                'http://[fd12::82d1]:2375/docker/engine'
            ),
            'ssh://': 'ssh://127.0.0.1:22',
            'ssh://user@localhost:22': 'ssh://user@localhost:22',
            'ssh://user@remote': 'ssh://user@remote:22',
        }

        for host in invalid_hosts:
            with pytest.raises(DockerException):
                parse_host(host, None)

        for host, expected in valid_hosts.items():
            assert parse_host(host, None) == expected
Beispiel #15
0
    def test_parse_host(self):
        invalid_hosts = [
            '0.0.0.0',
            'tcp://',
            'udp://127.0.0.1',
            'udp://127.0.0.1:2375',
        ]

        valid_hosts = {
            '0.0.0.1:5555':
            'http://0.0.0.1:5555',
            ':6666':
            'http://127.0.0.1:6666',
            'tcp://:7777':
            'http://127.0.0.1:7777',
            'http://:7777':
            'http://127.0.0.1:7777',
            'https://kokia.jp:2375':
            'https://kokia.jp:2375',
            'unix:///var/run/docker.sock':
            'http+unix:///var/run/docker.sock',
            'unix://':
            'http+unix://var/run/docker.sock',
            '12.234.45.127:2375/docker/engine':
            ('http://12.234.45.127:2375/docker/engine'),
            'somehost.net:80/service/swarm':
            ('http://somehost.net:80/service/swarm'),
            'npipe:////./pipe/docker_engine':
            'npipe:////./pipe/docker_engine',
            '[fd12::82d1]:2375':
            'http://[fd12::82d1]:2375',
            'https://[fd12:5672::12aa]:1090':
            'https://[fd12:5672::12aa]:1090',
            '[fd12::82d1]:2375/docker/engine':
            ('http://[fd12::82d1]:2375/docker/engine'),
        }

        for host in invalid_hosts:
            with pytest.raises(DockerException):
                parse_host(host, None)

        for host, expected in valid_hosts.items():
            assert parse_host(host, None) == expected
Beispiel #16
0
    def test_parse_host(self):
        invalid_hosts = ["0.0.0.0", "tcp://", "udp://127.0.0.1", "udp://127.0.0.1:2375"]

        valid_hosts = {
            "0.0.0.1:5555": "http://0.0.0.1:5555",
            ":6666": "http://127.0.0.1:6666",
            "tcp://:7777": "http://127.0.0.1:7777",
            "http://:7777": "http://127.0.0.1:7777",
            "https://kokia.jp:2375": "https://kokia.jp:2375",
            "unix:///var/run/docker.sock": "http+unix:///var/run/docker.sock",
            "unix://": "http+unix://var/run/docker.sock",
            "somehost.net:80/service/swarm": ("http://somehost.net:80/service/swarm"),
        }

        for host in invalid_hosts:
            with pytest.raises(DockerException):
                parse_host(host, None)

        for host, expected in valid_hosts.items():
            self.assertEqual(parse_host(host, None), expected, msg=host)
Beispiel #17
0
    def test_parse_host(self):
        invalid_hosts = [
            '0.0.0.0',
            'tcp://',
            'udp://127.0.0.1',
            'udp://127.0.0.1:2375',
        ]

        valid_hosts = {
            '0.0.0.1:5555': 'http://0.0.0.1:5555',
            ':6666': 'http://127.0.0.1:6666',
            'tcp://:7777': 'http://127.0.0.1:7777',
            'http://:7777': 'http://127.0.0.1:7777',
            'https://kokia.jp:2375': 'https://kokia.jp:2375',
            'unix:///var/run/docker.sock': 'http+unix:///var/run/docker.sock',
            'unix://': 'http+unix://var/run/docker.sock',
            '12.234.45.127:2375/docker/engine': (
                'http://12.234.45.127:2375/docker/engine'
            ),
            'somehost.net:80/service/swarm': (
                'http://somehost.net:80/service/swarm'
            ),
            'npipe:////./pipe/docker_engine': 'npipe:////./pipe/docker_engine',
            '[fd12::82d1]:2375': 'http://[fd12::82d1]:2375',
            'https://[fd12:5672::12aa]:1090': 'https://[fd12:5672::12aa]:1090',
            '[fd12::82d1]:2375/docker/engine': (
                'http://[fd12::82d1]:2375/docker/engine'
            ),
        }

        for host in invalid_hosts:
            with pytest.raises(DockerException):
                parse_host(host, None)

        for host, expected in valid_hosts.items():
            assert parse_host(host, None) == expected
Beispiel #18
0
 def test_kwargs_from_env_tls_verify_false(self):
     os.environ.update(DOCKER_HOST='tcp://192.168.59.103:2376',
                       DOCKER_CERT_PATH=TEST_CERT_DIR,
                       DOCKER_TLS_VERIFY='')
     kwargs = kwargs_from_env(assert_hostname=True)
     assert 'tcp://192.168.59.103:2376' == kwargs['base_url']
     assert 'ca.pem' in kwargs['tls'].ca_cert
     assert 'cert.pem' in kwargs['tls'].cert[0]
     assert 'key.pem' in kwargs['tls'].cert[1]
     assert kwargs['tls'].assert_hostname is True
     assert kwargs['tls'].verify is False
     parsed_host = parse_host(kwargs['base_url'], IS_WINDOWS_PLATFORM, True)
     try:
         client = APIClient(**kwargs)
         assert parsed_host == client.base_url
         assert kwargs['tls'].cert == client.cert
         assert not kwargs['tls'].verify
     except TypeError as e:
         self.fail(e)
Beispiel #19
0
 def test_kwargs_from_env_tls_verify_false(self):
     os.environ.update(DOCKER_HOST='tcp://192.168.59.103:2376',
                       DOCKER_CERT_PATH=TEST_CERT_DIR,
                       DOCKER_TLS_VERIFY='')
     kwargs = kwargs_from_env(assert_hostname=True)
     assert 'tcp://192.168.59.103:2376' == kwargs['base_url']
     assert 'ca.pem' in kwargs['tls'].ca_cert
     assert 'cert.pem' in kwargs['tls'].cert[0]
     assert 'key.pem' in kwargs['tls'].cert[1]
     assert kwargs['tls'].assert_hostname is True
     assert kwargs['tls'].verify is False
     parsed_host = parse_host(kwargs['base_url'], IS_WINDOWS_PLATFORM, True)
     try:
         client = APIClient(**kwargs)
         assert parsed_host == client.base_url
         assert kwargs['tls'].cert == client.cert
         assert not kwargs['tls'].verify
     except TypeError as e:
         self.fail(e)
Beispiel #20
0
 def test_parse_host_tls_tcp_proto(self):
     host_value = 'tcp://myhost.docker.net:3348'
     expected_result = 'https://myhost.docker.net:3348'
     assert parse_host(host_value, tls=True) == expected_result
Beispiel #21
0
 def test_parse_host_tls(self):
     host_value = 'myhost.docker.net:3348'
     expected_result = 'https://myhost.docker.net:3348'
     self.assertEqual(parse_host(host_value, None, True), expected_result)
def get_context_host(path=None):
    host = utils.parse_host(path, IS_WINDOWS_PLATFORM)
    if host == DEFAULT_UNIX_SOCKET:
        # remove http+ from default docker socket url
        return host.strip("http+")
    return host
Beispiel #23
0
 def test_parse_host_tls_tcp_proto(self):
     host_value = 'tcp://myhost.docker.net:3348'
     expected_result = 'https://myhost.docker.net:3348'
     assert parse_host(host_value, tls=True) == expected_result
Beispiel #24
0
 def test_parse_host_trailing_slash(self):
     host_value = 'tcp://myhost.docker.net:2376/'
     expected_result = 'http://myhost.docker.net:2376'
     assert parse_host(host_value) == expected_result
Beispiel #25
0
 def test_parse_host_trailing_slash(self):
     host_value = 'tcp://myhost.docker.net:2376/'
     expected_result = 'http://myhost.docker.net:2376'
     assert parse_host(host_value) == expected_result