Use my_ip as default URL instead of localhost
python-openstackclient for ironic-discoverd fails like: $ openstack baremetal introspection status <uuid> ERROR: openstack 'utf8' codec can't decode byte 0xa5 in position 89: invalid start byte When set "DISCOVERD_URL" environment value as http://<my_ip>:5050, this error doesn't occur. So that, the reason of this error is using localhost as default url. This patch set fix the default url to host's URL. Change-Id: I59e6bf30c19eee65b52e8d2bd56c148cd3b29efa Closes-Bug: #1439468
This commit is contained in:
parent
8a1466cec3
commit
fa6f3513fa
|
@ -16,13 +16,14 @@ from __future__ import print_function
|
||||||
import argparse
|
import argparse
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
from oslo_utils import netutils
|
||||||
import requests
|
import requests
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from ironic_discoverd.common.i18n import _
|
from ironic_discoverd.common.i18n import _
|
||||||
|
|
||||||
|
|
||||||
_DEFAULT_URL = 'http://127.0.0.1:5050/v1'
|
_DEFAULT_URL = 'http://' + netutils.get_my_ipv4() + ':5050/v1'
|
||||||
_ERROR_ENCODING = 'utf-8'
|
_ERROR_ENCODING = 'utf-8'
|
||||||
|
|
||||||
|
|
||||||
|
@ -54,7 +55,7 @@ def introspect(uuid, base_url=None, auth_token=None,
|
||||||
|
|
||||||
:param uuid: node uuid
|
:param uuid: node uuid
|
||||||
:param base_url: *ironic-discoverd* URL in form: http://host:port[/ver],
|
:param base_url: *ironic-discoverd* URL in form: http://host:port[/ver],
|
||||||
defaults to ``http://127.0.0.1:5050/v1``.
|
defaults to ``http://<current host>:5050/v1``.
|
||||||
:param auth_token: Keystone authentication token.
|
:param auth_token: Keystone authentication token.
|
||||||
:param new_ipmi_password: if set, *ironic-discoverd* will update IPMI
|
:param new_ipmi_password: if set, *ironic-discoverd* will update IPMI
|
||||||
password to this value.
|
password to this value.
|
||||||
|
@ -81,7 +82,7 @@ def get_status(uuid, base_url=None, auth_token=None):
|
||||||
New in ironic-discoverd version 1.0.0.
|
New in ironic-discoverd version 1.0.0.
|
||||||
:param uuid: node uuid.
|
:param uuid: node uuid.
|
||||||
:param base_url: *ironic-discoverd* URL in form: http://host:port[/ver],
|
:param base_url: *ironic-discoverd* URL in form: http://host:port[/ver],
|
||||||
defaults to ``http://127.0.0.1:5050/v1``.
|
defaults to ``http://<current host>:5050/v1``.
|
||||||
:param auth_token: Keystone authentication token.
|
:param auth_token: Keystone authentication token.
|
||||||
:raises: *requests* library HTTP errors.
|
:raises: *requests* library HTTP errors.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
from oslo_utils import netutils
|
||||||
from oslo_utils import uuidutils
|
from oslo_utils import uuidutils
|
||||||
|
|
||||||
from ironic_discoverd import client
|
from ironic_discoverd import client
|
||||||
|
@ -25,6 +26,7 @@ class TestIntrospect(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestIntrospect, self).setUp()
|
super(TestIntrospect, self).setUp()
|
||||||
self.uuid = uuidutils.generate_uuid()
|
self.uuid = uuidutils.generate_uuid()
|
||||||
|
self.my_ip = 'http://' + netutils.get_my_ipv4() + ':5050/v1'
|
||||||
|
|
||||||
def test(self, mock_post):
|
def test(self, mock_post):
|
||||||
client.introspect(self.uuid, base_url="http://host:port",
|
client.introspect(self.uuid, base_url="http://host:port",
|
||||||
|
@ -52,7 +54,8 @@ class TestIntrospect(unittest.TestCase):
|
||||||
def test_default_url(self, mock_post):
|
def test_default_url(self, mock_post):
|
||||||
client.introspect(self.uuid, auth_token="token")
|
client.introspect(self.uuid, auth_token="token")
|
||||||
mock_post.assert_called_once_with(
|
mock_post.assert_called_once_with(
|
||||||
"http://127.0.0.1:5050/v1/introspection/%s" % self.uuid,
|
"%(my_ip)s/introspection/%(uuid)s" %
|
||||||
|
{'my_ip': self.my_ip, 'uuid': self.uuid},
|
||||||
headers={'X-Auth-Token': 'token'},
|
headers={'X-Auth-Token': 'token'},
|
||||||
params={'new_ipmi_username': None, 'new_ipmi_password': None}
|
params={'new_ipmi_username': None, 'new_ipmi_password': None}
|
||||||
)
|
)
|
||||||
|
@ -70,7 +73,8 @@ class TestIntrospect(unittest.TestCase):
|
||||||
def test_none_ok(self, mock_post):
|
def test_none_ok(self, mock_post):
|
||||||
client.introspect(self.uuid)
|
client.introspect(self.uuid)
|
||||||
mock_post.assert_called_once_with(
|
mock_post.assert_called_once_with(
|
||||||
"http://127.0.0.1:5050/v1/introspection/%s" % self.uuid,
|
"%(my_ip)s/introspection/%(uuid)s" %
|
||||||
|
{'my_ip': self.my_ip, 'uuid': self.uuid},
|
||||||
headers={},
|
headers={},
|
||||||
params={'new_ipmi_username': None, 'new_ipmi_password': None}
|
params={'new_ipmi_username': None, 'new_ipmi_password': None}
|
||||||
)
|
)
|
||||||
|
@ -118,6 +122,7 @@ class TestGetStatus(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestGetStatus, self).setUp()
|
super(TestGetStatus, self).setUp()
|
||||||
self.uuid = uuidutils.generate_uuid()
|
self.uuid = uuidutils.generate_uuid()
|
||||||
|
self.my_ip = 'http://' + netutils.get_my_ipv4() + ':5050/v1'
|
||||||
|
|
||||||
def test(self, mock_get):
|
def test(self, mock_get):
|
||||||
mock_get.return_value.json.return_value = 'json'
|
mock_get.return_value.json.return_value = 'json'
|
||||||
|
@ -125,7 +130,8 @@ class TestGetStatus(unittest.TestCase):
|
||||||
client.get_status(self.uuid, auth_token='token')
|
client.get_status(self.uuid, auth_token='token')
|
||||||
|
|
||||||
mock_get.assert_called_once_with(
|
mock_get.assert_called_once_with(
|
||||||
"http://127.0.0.1:5050/v1/introspection/%s" % self.uuid,
|
"%(my_ip)s/introspection/%(uuid)s" %
|
||||||
|
{'my_ip': self.my_ip, 'uuid': self.uuid},
|
||||||
headers={'X-Auth-Token': 'token'}
|
headers={'X-Auth-Token': 'token'}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue