summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZane Bitter <zbitter@redhat.com>2020-10-27 10:05:16 -0400
committerIury Gregory Melo Ferreira <iurygregory@gmail.com>2020-11-10 10:16:43 +0000
commite2b55a8cb835e0b63830de34a002b7652753cb3d (patch)
tree8ee6f409d14644eeccfdffa02aa538fa667138d6
parent193b93c585acf2a84ddf1150cb98b2447ed53d2e (diff)
downloadironic-e2b55a8cb835e0b63830de34a002b7652753cb3d.tar.gz
json-rpc: surround IPv6 address with [] in conductor URL
If the conductor's host option is configured to be an IPv6 address, we need to surround it with [] when incorporating it in a URL to contact the conductor over json-rpc. Change-Id: Ib3bc4c570ec0f2e5c73e3ce15b05684b8e4c1ff9 Story: 2008288 Task: 41166 (cherry picked from commit 85b489288669af342bbbd4b0a875580a346c2441)
-rw-r--r--ironic/common/json_rpc/client.py5
-rw-r--r--ironic/tests/unit/common/test_json_rpc.py34
-rw-r--r--releasenotes/notes/json-rpc-ipv6-host-30eca350f34bc091.yaml6
3 files changed, 44 insertions, 1 deletions
diff --git a/ironic/common/json_rpc/client.py b/ironic/common/json_rpc/client.py
index 8979d6f02..3fcc06d99 100644
--- a/ironic/common/json_rpc/client.py
+++ b/ironic/common/json_rpc/client.py
@@ -18,6 +18,7 @@ This client is compatible with any JSON RPC 2.0 implementation, including ours.
from oslo_config import cfg
from oslo_log import log
from oslo_utils import importutils
+from oslo_utils import netutils
from oslo_utils import strutils
from oslo_utils import uuidutils
@@ -170,7 +171,9 @@ class _CallContext(object):
scheme = 'http'
if CONF.json_rpc.use_ssl:
scheme = 'https'
- url = '%s://%s:%d' % (scheme, self.host, CONF.json_rpc.port)
+ url = '%s://%s:%d' % (scheme,
+ netutils.escape_ipv6(self.host),
+ CONF.json_rpc.port)
result = _get_session().post(url, json=body)
LOG.debug('RPC %s returned %s', method,
strutils.mask_password(result.text or '<None>'))
diff --git a/ironic/tests/unit/common/test_json_rpc.py b/ironic/tests/unit/common/test_json_rpc.py
index bc0ccc5d6..fb7e7eca0 100644
--- a/ironic/tests/unit/common/test_json_rpc.py
+++ b/ironic/tests/unit/common/test_json_rpc.py
@@ -348,6 +348,40 @@ class TestClient(test_base.TestCase):
'params': {'answer': 42, 'context': self.ctx_json},
'id': self.context.request_id})
+ def test_call_ipv4_success(self, mock_session):
+ response = mock_session.return_value.post.return_value
+ response.json.return_value = {
+ 'jsonrpc': '2.0',
+ 'result': 42
+ }
+ cctx = self.client.prepare('foo.192.0.2.1')
+ self.assertEqual('192.0.2.1', cctx.host)
+ result = cctx.call(self.context, 'do_something', answer=42)
+ self.assertEqual(42, result)
+ mock_session.return_value.post.assert_called_once_with(
+ 'http://192.0.2.1:8089',
+ json={'jsonrpc': '2.0',
+ 'method': 'do_something',
+ 'params': {'answer': 42, 'context': self.ctx_json},
+ 'id': self.context.request_id})
+
+ def test_call_ipv6_success(self, mock_session):
+ response = mock_session.return_value.post.return_value
+ response.json.return_value = {
+ 'jsonrpc': '2.0',
+ 'result': 42
+ }
+ cctx = self.client.prepare('foo.2001:db8::1')
+ self.assertEqual('2001:db8::1', cctx.host)
+ result = cctx.call(self.context, 'do_something', answer=42)
+ self.assertEqual(42, result)
+ mock_session.return_value.post.assert_called_once_with(
+ 'http://[2001:db8::1]:8089',
+ json={'jsonrpc': '2.0',
+ 'method': 'do_something',
+ 'params': {'answer': 42, 'context': self.ctx_json},
+ 'id': self.context.request_id})
+
def test_call_success_with_version(self, mock_session):
response = mock_session.return_value.post.return_value
response.json.return_value = {
diff --git a/releasenotes/notes/json-rpc-ipv6-host-30eca350f34bc091.yaml b/releasenotes/notes/json-rpc-ipv6-host-30eca350f34bc091.yaml
new file mode 100644
index 000000000..96944012c
--- /dev/null
+++ b/releasenotes/notes/json-rpc-ipv6-host-30eca350f34bc091.yaml
@@ -0,0 +1,6 @@
+---
+fixes:
+ - |
+ When configured to use json-rpc, the ``[DEFAULT].host`` configuration
+ option to ironic-conductor can now be set to an IPv6 address. Previously
+ it could only be an IPv4 address or a DNS name.