Skip to content

Commit 840d9a5

Browse files
f5-rahmcaphrim007
authored andcommitted
Issue #1487 - Fix issue with Node FQDN required parameters (#1492)
* Issue #1487 - Fix issue with Node FQDN required parameters Problem: SDK requires address parameter with Node, but the REST API does not require it for fqdn type nodes Solution: This PR looks for a set of required parameters that exclusively permits the fqdn or the address for the create method. Files Changed: - f5/bigip/tm/ltm/node.py (changed) - f5/bigip/tm/ltm/test/functional/test_node.py (changed) * Issue #1487 - removed pytest-xdist as test requirement
1 parent 15bf328 commit 840d9a5

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

f5/bigip/tm/ltm/node.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
from f5.bigip.resource import Resource
3232
from f5.bigip.resource import Stats
3333
from f5.sdk_exception import NodeStateModifyUnsupported
34+
from f5.sdk_exception import RequiredOneOf
35+
from six import iterkeys
3436

3537

3638
class Nodes(Collection):
@@ -47,12 +49,22 @@ class Node(Resource):
4749
def __init__(self, nodes):
4850
super(Node, self).__init__(nodes)
4951
self._meta_data['required_json_kind'] = 'tm:ltm:node:nodestate'
50-
self._meta_data['required_creation_parameters'].update(
51-
('partition', 'address',)
52-
)
52+
self._meta_data['required_creation_parameters'] = set()
5353
self._meta_data['read_only_attributes'].append('ephemeral')
5454
self._meta_data['read_only_attributes'].append('address')
5555

56+
def create(self, **kwargs):
57+
required_one_of = [
58+
['name', 'address'],
59+
['name', 'fqdn']
60+
]
61+
args = set(iterkeys(kwargs))
62+
has_any = [set(x).issubset(args) for x in required_one_of]
63+
if len([x for x in has_any if x is True]) == 1:
64+
return self._create(**kwargs)
65+
66+
raise RequiredOneOf(required_one_of)
67+
5668
def update(self, **kwargs):
5769
"""Call this to change the configuration of the service on the device.
5870

f5/bigip/tm/ltm/test/functional/test_node.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
import pytest
1717

18-
from f5.sdk_exception import MissingRequiredCreationParameter
1918
from f5.sdk_exception import NodeStateModifyUnsupported
19+
from f5.sdk_exception import RequiredOneOf
2020

2121

2222
TESTDESCRIPTION = "TESTDESCRIPTION"
@@ -40,7 +40,7 @@ def teardown():
4040
class TestNode(object):
4141
def test_create_missing_args(self, mgmt_root):
4242
n1 = mgmt_root.tm.ltm.nodes.node
43-
with pytest.raises(MissingRequiredCreationParameter):
43+
with pytest.raises(RequiredOneOf):
4444
n1.create(name="n1", partition='Common')
4545

4646
def test_CURDLE(self, request, mgmt_root):

requirements.test.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ pyOpenSSL==16.2.0
1111
requests-mock==1.2.0
1212
netaddr
1313
q
14-
pytest-xdist
1514
pycodestyle
1615
jinja2
1716
tox

0 commit comments

Comments
 (0)