Skip to content

Commit 46e9776

Browse files
Use configurable driver name in lookup URL
Allow configuration via command line arguments or kernel parameters. Default to agent_ipmitool, the reference driver. Depends on https://review.openstack.org/#/c/84795/12 Change-Id: I55c4a8713308d038002a6567471cd862bf89ec76
1 parent 952ade3 commit 46e9776

5 files changed

Lines changed: 27 additions & 12 deletions

File tree

ironic_python_agent/agent.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ def __init__(self, agent):
6666
super(IronicPythonAgentHeartbeater, self).__init__()
6767
self.agent = agent
6868
self.hardware = hardware.get_manager()
69-
self.api = ironic_api_client.APIClient(agent.api_url)
69+
self.api = ironic_api_client.APIClient(agent.api_url,
70+
agent.driver_name)
7071
self.log = log.getLogger(__name__)
7172
self.stop_event = threading.Event()
7273
self.error_delay = self.initial_delay
@@ -105,10 +106,12 @@ def stop(self):
105106

106107
class IronicPythonAgent(base.ExecuteCommandMixin):
107108
def __init__(self, api_url, advertise_address, listen_address,
108-
lookup_timeout, lookup_interval):
109+
lookup_timeout, lookup_interval, driver_name):
109110
super(IronicPythonAgent, self).__init__()
110111
self.api_url = api_url
111-
self.api_client = ironic_api_client.APIClient(self.api_url)
112+
self.driver_name = driver_name
113+
self.api_client = ironic_api_client.APIClient(self.api_url,
114+
self.driver_name)
112115
self.listen_address = listen_address
113116
self.advertise_address = advertise_address
114117
self.version = pkg_resources.get_distribution('ironic-python-agent')\

ironic_python_agent/cmd/agent.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,17 @@ def run():
9090
'doubled after each failure until timeout is '
9191
'exceeded.')
9292

93+
parser.add_argument('--driver-name',
94+
default=kparams.get('ipa-driver-name',
95+
'agent_ipmitool'),
96+
type=str,
97+
help='The Ironic driver in use for this node')
98+
9399
args = parser.parse_args()
94100

95101
agent.IronicPythonAgent(api_url or args.api_url,
96102
(args.advertise_host, args.advertise_port),
97103
(args.listen_host, args.listen_port),
98104
args.lookup_timeout,
99-
args.lookup_interval).run()
105+
args.lookup_interval,
106+
args.driver_name).run()

ironic_python_agent/ironic_api_client.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ class APIClient(object):
3030
api_version = 'v1'
3131
payload_version = '2'
3232

33-
def __init__(self, api_url):
33+
def __init__(self, api_url, driver_name):
3434
self.api_url = api_url.rstrip('/')
35+
self.driver_name = driver_name
3536
self.session = requests.Session()
3637
self.encoder = encoding.RESTJSONEncoder()
3738
self.log = log.getLogger(__name__)
@@ -92,8 +93,9 @@ def _do_lookup(self, hardware_info):
9293
"""The actual call to lookup a node. Should be called inside
9394
loopingcall.BackOffLoopingCall.
9495
"""
95-
path = '/{api_version}/drivers/teeth/vendor_passthru/lookup'.format(
96-
api_version=self.api_version
96+
path = '/{api_version}/drivers/{driver}/vendor_passthru/lookup'.format(
97+
api_version=self.api_version,
98+
driver=self.driver_name
9799
)
98100
# This hardware won't be saved on the node currently, because of
99101
# how driver_vendor_passthru is implemented (no node saving).

ironic_python_agent/tests/agent.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,9 @@ def setUp(self):
130130
'org:8081/',
131131
('203.0.113.1', 9990),
132132
('192.0.2.1', 9999),
133-
lookup_timeout=300,
134-
lookup_interval=1)
133+
300,
134+
1,
135+
'agent_ipmitool')
135136

136137
def assertEqualEncoded(self, a, b):
137138
# Evidently JSONEncoder.default() can't handle None (??) so we have to

ironic_python_agent/tests/ironic_api_client.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from ironic_python_agent.openstack.common import loopingcall
2626

2727
API_URL = 'http://agent-api.ironic.example.org/'
28+
DRIVER = 'agent_ipmitool'
2829

2930

3031
class FakeResponse(object):
@@ -38,7 +39,7 @@ def __init__(self, content=None, status_code=200, headers=None):
3839
class TestBaseIronicPythonAgent(test_base.BaseTestCase):
3940
def setUp(self):
4041
super(TestBaseIronicPythonAgent, self).setUp()
41-
self.api_client = ironic_api_client.APIClient(API_URL)
42+
self.api_client = ironic_api_client.APIClient(API_URL, DRIVER)
4243
self.hardware_info = {
4344
'interfaces': [
4445
hardware.NetworkInterface('eth0', '00:0c:29:8c:11:b1'),
@@ -158,10 +159,11 @@ def test_do_lookup(self):
158159
self.api_client._do_lookup,
159160
hardware_info=self.hardware_info)
160161

162+
url = '{api_url}v1/drivers/{driver}/vendor_passthru/lookup'.format(
163+
api_url=API_URL, driver=DRIVER)
161164
request_args = self.api_client.session.request.call_args[0]
162165
self.assertEqual(request_args[0], 'POST')
163-
self.assertEqual(request_args[1],
164-
API_URL + 'v1/drivers/teeth/vendor_passthru/lookup')
166+
self.assertEqual(request_args[1], url)
165167

166168
data = self.api_client.session.request.call_args[1]['data']
167169
content = json.loads(data)

0 commit comments

Comments
 (0)