Skip to content

Commit ce67ddb

Browse files
committed
CI: Fix Multinode ssh key/hostname for unit tests
In multinode, the devstack plugin for networking-generic-switch can't really work as intended. But, the authorized keys is copied on all nodes, and zuul puts a consistent key in place, so it doesn't really need to do what it is doing, but we need to use the stack user's pre-existing keys to access the remote host. This will allow Ironic's multinode grenade job to work without errors about accessing the key file, which is a red herring for when the connection fails. Additionally, the underlying ngs code is suseptible to a race on configuration loading as configuration is loaded separately. We can't really force it to load the option. We also can't explicitly add it, so the best thing to do is to wrap it and rely upon a mock to facilitate the unit test. Change-Id: Ia8550c124f2ef1cce620a4fb28c35700d34aa027 (cherry picked from commit c6c10a1)
1 parent b177c49 commit ce67ddb

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

devstack/plugin.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ function configure_generic_switch {
145145
if [ -n "$HOST_TOPOLOGY_SUBNODES" ]; then
146146
# NOTE(vsaienko) with multinode topology we need to add switches from all
147147
# the subnodes to the config on primary node
148+
# NOTE(TheJulia) We *also* need to use the local key which will have
149+
# access to the subnode instead of attemping to configure our own,
150+
# as the plugins execute separately.
151+
if [ -f /opt/stack/.ssh/id_rsa ]; then
152+
GENERIC_SWITCH_KEY_FILE="/opt/stack/.ssh/id_rsa"
153+
fi
148154
local cnt=0
149155
local section
150156
for node in $HOST_TOPOLOGY_SUBNODES; do

networking_generic_switch/devices/netmiko_devices/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def __init__(self, device_cfg):
109109
if CONF.ngs_coordination.backend_url:
110110
self.locker = coordination.get_coordinator(
111111
CONF.ngs_coordination.backend_url,
112-
('ngs-' + CONF.host).encode('ascii'))
112+
('ngs-' + device_utils.get_hostname()).encode('ascii'))
113113
self.locker.start()
114114
atexit.register(self.locker.stop)
115115

networking_generic_switch/devices/utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
1414

15+
from oslo_config import cfg
16+
17+
18+
CONF = cfg.CONF
19+
1520

1621
def get_switch_device(switches, switch_info=None,
1722
ngs_mac_address=None):
@@ -46,3 +51,8 @@ def sanitise_config(config):
4651
key: "******" if key in sanitised_fields else value
4752
for key, value in config.items()
4853
}
54+
55+
56+
def get_hostname():
57+
"""Helper to allow isolation of CONF.host and plugin loading."""
58+
return CONF.host

networking_generic_switch/tests/unit/netmiko/test_netmiko_base.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from tooz import coordination
2525

2626
from networking_generic_switch.devices import netmiko_devices
27+
from networking_generic_switch.devices import utils
2728
from networking_generic_switch import exceptions as exc
2829

2930

@@ -320,17 +321,18 @@ def fake_save_config():
320321
connect_mock.send_command.assert_has_calls([mock.call('save'),
321322
mock.call('y')])
322323

324+
@mock.patch.object(utils, 'get_hostname', autospec=True)
323325
@mock.patch.object(netmiko_devices.ngs_lock, 'PoolLock', autospec=True)
324326
@mock.patch.object(netmiko_devices.netmiko, 'ConnectHandler')
325327
@mock.patch.object(coordination, 'get_coordinator', autospec=True)
326328
def test_switch_send_commands_with_coordinator(self, get_coord_mock,
327-
nm_mock, lock_mock):
329+
nm_mock, lock_mock,
330+
mock_hostname):
328331
self.cfg.config(acquire_timeout=120, backend_url='mysql://localhost',
329332
group='ngs_coordination')
330-
self.cfg.config(host='viking')
331333
coord = mock.Mock()
332334
get_coord_mock.return_value = coord
333-
335+
mock_hostname.return_value = 'viking'
334336
switch = self._make_switch_device(
335337
extra_cfg={'ngs_max_connections': 2})
336338
self.assertEqual(coord, switch.locker)
@@ -348,6 +350,7 @@ def test_switch_send_commands_with_coordinator(self, get_coord_mock,
348350
timeout=120)
349351
lock_mock.return_value.__exit__.assert_called_once()
350352
lock_mock.return_value.__enter__.assert_called_once()
353+
mock_hostname.assert_called_once()
351354

352355
def test_check_output(self):
353356
self.switch.check_output('fake output', 'fake op')

0 commit comments

Comments
 (0)