Skip to content

Commit a8e38ee

Browse files
caladdmasonkatz
authored andcommitted
BUGFIX: Do interface validation of set interface commands in a case-insensitive manor, to match the DB.
1 parent be77681 commit a8e38ee

3 files changed

Lines changed: 77 additions & 11 deletions

File tree

common/src/stack/command/stack/commands/set/host/interface/__init__.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,48 @@ class command(stack.commands.set.host.command):
1414
def validate(self, hosts, interface=None, mac=None, network=None):
1515
"""
1616
Validated that the provided interface, mac, and/or network
17-
exist for the hosts, or raise an error.
17+
exist for the hosts, or raise an error. The validation needs to
18+
be done in a case-insensitive manor, to match the DB behavior.
1819
"""
1920

2021
# Construct our host data to check against
2122
host_data = defaultdict(lambda: defaultdict(set))
2223
for row in self.call('list.host.interface', hosts):
2324
combo = []
2425
if row['interface']:
25-
host_data[row['host']]['interfaces'].add(row['interface'])
26-
combo.append(row['interface'])
26+
host_data[row['host']]['interfaces'].add(row['interface'].lower())
27+
combo.append(row['interface'].lower())
2728

2829
if row['mac']:
29-
host_data[row['host']]['macs'].add(row['mac'])
30-
combo.append(row['mac'])
30+
host_data[row['host']]['macs'].add(row['mac'].lower())
31+
combo.append(row['mac'].lower())
3132

3233
if row['network']:
33-
host_data[row['host']]['networks'].add(row['network'])
34-
combo.append(row['network'])
34+
host_data[row['host']]['networks'].add(row['network'].lower())
35+
combo.append(row['network'].lower())
3536

3637
if len(combo) > 1:
3738
host_data[row['host']]['combos'].add(tuple(combo))
3839

3940
# Our combination the user asked for
40-
combo = tuple(filter(None, (interface, mac, network)))
41+
combo = []
42+
if interface:
43+
combo.append(interface.lower())
44+
if mac:
45+
combo.append(mac.lower())
46+
if network:
47+
combo.append(network.lower())
48+
combo = tuple(combo)
4149

4250
# Check the provided arguements against the host data
4351
for host in hosts:
44-
if interface and interface not in host_data[host]['interfaces']:
52+
if interface and interface.lower() not in host_data[host]['interfaces']:
4553
raise CommandError(self, f'interface "{interface}" does not exist for host "{host}"')
4654

47-
if mac and mac not in host_data[host]['macs']:
55+
if mac and mac.lower() not in host_data[host]['macs']:
4856
raise CommandError(self, f'mac "{mac}" does not exist for host "{host}"')
4957

50-
if network and network not in host_data[host]['networks']:
58+
if network and network.lower() not in host_data[host]['networks']:
5159
raise CommandError(self, f'network "{network}" does not exist for host "{host}"')
5260

5361
if len(combo) > 1 and combo not in host_data[host]['combos']:

test-framework/test-suites/integration/tests/set/test_set_host_interface_interface.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,35 @@ def test_all_parameters(self, host, add_host, add_network):
142142
'vlan': None
143143
}]
144144

145+
def test_all_parameters_insensitive(self, host, add_host, add_network):
146+
# Add an interface with a mac and network to our test host
147+
result = host.run('stack add host interface backend-0-0 mac=aa:bb:cc:dd:ee:ff network=test')
148+
assert result.rc == 0
149+
150+
# Set the default host interface
151+
result = host.run(
152+
'stack set host interface interface backend-0-0 interface=eth0 '
153+
'mac=AA:BB:CC:DD:EE:FF network=TEST'
154+
)
155+
assert result.rc == 0
156+
157+
# Check that it made it into the database
158+
result = host.run('stack list host interface backend-0-0 output-format=json')
159+
assert result.rc == 0
160+
assert json.loads(result.stdout) == [{
161+
'channel': None,
162+
'default': None,
163+
'host': 'backend-0-0',
164+
'interface': 'eth0',
165+
'ip': None,
166+
'mac': 'aa:bb:cc:dd:ee:ff',
167+
'module': None,
168+
'name': None,
169+
'network': 'test',
170+
'options': None,
171+
'vlan': None
172+
}]
173+
145174
def test_multiple_hosts(self, host, add_host, add_network):
146175
# Add an interface with a MAC and network
147176
result = host.run('stack add host interface backend-0-0 mac=00:11:22:33:44:55 network=test')

test-framework/test-suites/integration/tests/set/test_set_host_interface_mac.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,35 @@ def test_all_parameters(self, host, add_host, add_network):
159159
'vlan': None
160160
}]
161161

162+
def test_all_parameters_insensitive(self, host, add_host, add_network):
163+
# Add an interface with a interface device and network to our test host
164+
result = host.run('stack add host interface backend-0-0 interface=eth0 network=test')
165+
assert result.rc == 0
166+
167+
# Set the host interface mac
168+
result = host.run(
169+
'stack set host interface mac backend-0-0 interface=ETH0 '
170+
'mac=aa:bb:cc:dd:ee:ff network=TEST'
171+
)
172+
assert result.rc == 0
173+
174+
# Check that it made it into the database
175+
result = host.run('stack list host interface backend-0-0 output-format=json')
176+
assert result.rc == 0
177+
assert json.loads(result.stdout) == [{
178+
'channel': None,
179+
'default': None,
180+
'host': 'backend-0-0',
181+
'interface': 'eth0',
182+
'ip': None,
183+
'mac': 'aa:bb:cc:dd:ee:ff',
184+
'module': None,
185+
'name': None,
186+
'network': 'test',
187+
'options': None,
188+
'vlan': None
189+
}]
190+
162191
def test_multiple_hosts(self, host, add_host):
163192
# Add a second test backend
164193
add_host('backend-0-1', '0', '1', 'backend')

0 commit comments

Comments
 (0)