
This improves the nodescan testing by: * Removing the fake handling from the production code * Adds explicit host-key-checking: false settings to most nodepool test fixtures. * Adding explicit success/failure tests for nodescan with the full node request lifecycle. * Moves the test-only fakes into their own file so they can be shared with the new launcher nodescan tests as well as the dedicated nodescan unit tests. * Allows for customizable timeouts in the requestNodes helper method since the failing test takes a while. It also allows the boot-timeout to be correctly set in the section or provider object in addition to the label, for convenience. Change-Id: If6361cb437ad28472f154f3af9dde190d43c0d1e
88 lines
2.1 KiB
Python
88 lines
2.1 KiB
Python
# Copyright (C) 2023 Acme Gating, LLC
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
# implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
class FakeSocket:
|
|
def __init__(self):
|
|
self.blocking = True
|
|
self.fd = 1
|
|
|
|
def setblocking(self, b):
|
|
self.blocking = b
|
|
|
|
def getsockopt(self, level, optname):
|
|
return None
|
|
|
|
def connect(self, addr):
|
|
if not self.blocking:
|
|
raise BlockingIOError()
|
|
raise Exception("blocking connect attempted")
|
|
|
|
def fileno(self):
|
|
return self.fd
|
|
|
|
|
|
class FakePoll:
|
|
def __init__(self, _fail=False):
|
|
self.fds = []
|
|
self._fail = _fail
|
|
|
|
def register(self, fd, bitmap):
|
|
self.fds.append(fd)
|
|
|
|
def unregister(self, fd):
|
|
if fd in self.fds:
|
|
self.fds.remove(fd)
|
|
|
|
def poll(self, timeout=None):
|
|
if self._fail:
|
|
return []
|
|
fds = self.fds[:]
|
|
self.fds = [f for f in fds if not isinstance(f, FakeSocket)]
|
|
fds = [f.fileno() if hasattr(f, 'fileno') else f for f in fds]
|
|
return [(f, 0) for f in fds]
|
|
|
|
|
|
class Dummy:
|
|
pass
|
|
|
|
|
|
class FakeKey:
|
|
def get_name(self):
|
|
return 'fake key'
|
|
|
|
def get_base64(self):
|
|
return 'fake base64'
|
|
|
|
|
|
class FakeTransport:
|
|
def __init__(self, _fail=False, active=True):
|
|
self.active = active
|
|
self._fail = _fail
|
|
|
|
def start_client(self, event=None, timeout=None):
|
|
if not self._fail:
|
|
event.set()
|
|
|
|
def get_security_options(self):
|
|
ret = Dummy()
|
|
ret.key_types = ['rsa']
|
|
return ret
|
|
|
|
def get_remote_server_key(self):
|
|
return FakeKey()
|
|
|
|
def get_exception(self):
|
|
return Exception("Fake ssh error")
|