Browse Source

Merge "json-rpc: surround IPv6 address with [] in conductor URL" into stable/ussuri

changes/06/782006/1
Zuul 4 weeks ago
committed by Gerrit Code Review
parent
commit
6332840b67
3 changed files with 44 additions and 1 deletions
  1. +4
    -1
      ironic/common/json_rpc/client.py
  2. +34
    -0
      ironic/tests/unit/common/test_json_rpc.py
  3. +6
    -0
      releasenotes/notes/json-rpc-ipv6-host-30eca350f34bc091.yaml

+ 4
- 1
ironic/common/json_rpc/client.py View File

@ -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
@ -156,7 +157,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>'))


+ 34
- 0
ironic/tests/unit/common/test_json_rpc.py View File

@ -318,6 +318,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 = {


+ 6
- 0
releasenotes/notes/json-rpc-ipv6-host-30eca350f34bc091.yaml View File

@ -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.

Loading…
Cancel
Save