Keep cache of nodes under discovery in the local database
Introduces SQLite database to keep a cache of nodes for discovery. Move node lookup code into a new module `node_cache`. This will greatly improve performance by doing less network requests and will allow both implementing timeouts and getting rid of using maintenance mode. Change-Id: I543cb32d9d04f55bcf4573e9e0d341317cae4df6 Partial-Bug: #1391868 Partial-Bug: #1391871
This commit is contained in:
parent
baef340b28
commit
cb32def5c5
|
@ -192,6 +192,9 @@ Change Log
|
||||||
v1.0.0
|
v1.0.0
|
||||||
~~~~~~
|
~~~~~~
|
||||||
|
|
||||||
|
* Cache nodes under discovery in a local SQLite database. Set ``database``
|
||||||
|
configuration option to persist this database. Improves performance by
|
||||||
|
making less calls to Ironic API.
|
||||||
* Create ``CONTRIBUTING.rst``.
|
* Create ``CONTRIBUTING.rst``.
|
||||||
|
|
||||||
v0.2.4
|
v0.2.4
|
||||||
|
|
|
@ -32,6 +32,8 @@
|
||||||
; Whether to authenticate with Keystone on discovery initialization endpoint.
|
; Whether to authenticate with Keystone on discovery initialization endpoint.
|
||||||
; Note that discovery postback endpoint is never authenticated.
|
; Note that discovery postback endpoint is never authenticated.
|
||||||
;authenticate = true
|
;authenticate = true
|
||||||
|
; SQLite3 database to store nodes under discovery, defaults to in-memory.
|
||||||
|
;database =
|
||||||
|
|
||||||
; Debug mode enabled/disabled.
|
; Debug mode enabled/disabled.
|
||||||
;debug = false
|
;debug = false
|
||||||
|
|
|
@ -23,7 +23,8 @@ DEFAULTS = {
|
||||||
'firewall_update_period': '15',
|
'firewall_update_period': '15',
|
||||||
'ports_for_inactive_interfaces': 'false',
|
'ports_for_inactive_interfaces': 'false',
|
||||||
'ironic_retry_attempts': '5',
|
'ironic_retry_attempts': '5',
|
||||||
'ironic_retry_period': '5'
|
'ironic_retry_period': '5',
|
||||||
|
'database': '',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -19,11 +19,11 @@ from ironicclient import exceptions
|
||||||
|
|
||||||
from ironic_discoverd import conf
|
from ironic_discoverd import conf
|
||||||
from ironic_discoverd import firewall
|
from ironic_discoverd import firewall
|
||||||
|
from ironic_discoverd import node_cache
|
||||||
from ironic_discoverd import utils
|
from ironic_discoverd import utils
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger("discoverd")
|
LOG = logging.getLogger("discoverd")
|
||||||
ALLOW_SEARCH_BY_MAC = True
|
|
||||||
|
|
||||||
|
|
||||||
def process(node_info):
|
def process(node_info):
|
||||||
|
@ -71,47 +71,20 @@ def process(node_info):
|
||||||
'ipmi_address': node_info.get('ipmi_address')})
|
'ipmi_address': node_info.get('ipmi_address')})
|
||||||
LOG.info('Eligible interfaces are %s', valid_interfaces)
|
LOG.info('Eligible interfaces are %s', valid_interfaces)
|
||||||
|
|
||||||
|
uuid = node_cache.pop_node(bmc_address=node_info['ipmi_address'],
|
||||||
|
mac=valid_macs)
|
||||||
|
if uuid is None:
|
||||||
|
LOG.debug('Unable to find a node, cannot proceed')
|
||||||
|
return
|
||||||
|
|
||||||
ironic = utils.get_client()
|
ironic = utils.get_client()
|
||||||
bmc_known = bool(node_info.get('ipmi_address'))
|
try:
|
||||||
if bmc_known:
|
node = ironic.node.get(uuid)
|
||||||
# TODO(dtantsur): bulk loading
|
except exceptions.NotFound as exc:
|
||||||
nodes = ironic.node.list(maintenance=True, limit=0,
|
LOG.error('Node UUID %(uuid)s is in the cache, but not found '
|
||||||
sort_key='created_at',
|
'by Ironic: %(exc)s',
|
||||||
sort_dir='desc', detail=True)
|
{'uuid': uuid,
|
||||||
address = node_info['ipmi_address']
|
'exc': exc})
|
||||||
for node in nodes:
|
|
||||||
if node.driver_info.get('ipmi_address') == address:
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
LOG.error('Unable to find node with ipmi_address %s',
|
|
||||||
node_info['ipmi_address'])
|
|
||||||
return
|
|
||||||
elif ALLOW_SEARCH_BY_MAC:
|
|
||||||
# In case of testing with vms and pxe_ssh driver
|
|
||||||
LOG.warning('No BMC address provided, trying to use MAC '
|
|
||||||
'addresses for finding node')
|
|
||||||
port = None
|
|
||||||
for mac in valid_macs:
|
|
||||||
try:
|
|
||||||
port = ironic.port.get_by_address(mac)
|
|
||||||
except exceptions.NotFound:
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
break
|
|
||||||
|
|
||||||
if port is not None:
|
|
||||||
try:
|
|
||||||
node = ironic.node.get(port.node_uuid)
|
|
||||||
except exceptions.NotFound:
|
|
||||||
node = None
|
|
||||||
|
|
||||||
if port is None or node is None:
|
|
||||||
LOG.error('Unable to find node with macs %s',
|
|
||||||
valid_macs)
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
LOG.error('No ipmi_address provided and searching by MAC is not '
|
|
||||||
'allowed')
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if not node.extra.get('on_discovery'):
|
if not node.extra.get('on_discovery'):
|
||||||
|
@ -153,16 +126,10 @@ def _process_node(ironic, node, node_info, valid_macs):
|
||||||
'management configuration:\n%s', node.uuid, exc)
|
'management configuration:\n%s', node.uuid, exc)
|
||||||
|
|
||||||
|
|
||||||
class DiscoveryFailed(Exception):
|
|
||||||
def __init__(self, msg, code=400):
|
|
||||||
super(DiscoveryFailed, self).__init__(msg)
|
|
||||||
self.http_code = code
|
|
||||||
|
|
||||||
|
|
||||||
def discover(uuids):
|
def discover(uuids):
|
||||||
"""Initiate discovery for given node uuids."""
|
"""Initiate discovery for given node uuids."""
|
||||||
if not uuids:
|
if not uuids:
|
||||||
raise DiscoveryFailed("No nodes to discover")
|
raise utils.DiscoveryFailed("No nodes to discover")
|
||||||
|
|
||||||
ironic = utils.get_client()
|
ironic = utils.get_client()
|
||||||
LOG.debug('Validating nodes %s', uuids)
|
LOG.debug('Validating nodes %s', uuids)
|
||||||
|
@ -172,10 +139,10 @@ def discover(uuids):
|
||||||
node = ironic.node.get(uuid)
|
node = ironic.node.get(uuid)
|
||||||
except exceptions.NotFound:
|
except exceptions.NotFound:
|
||||||
LOG.error('Node %s cannot be found', uuid)
|
LOG.error('Node %s cannot be found', uuid)
|
||||||
raise DiscoveryFailed("Cannot find node %s" % uuid, code=404)
|
raise utils.DiscoveryFailed("Cannot find node %s" % uuid, code=404)
|
||||||
except exceptions.HttpError as exc:
|
except exceptions.HttpError as exc:
|
||||||
LOG.exception('Cannot get node %s', uuid)
|
LOG.exception('Cannot get node %s', uuid)
|
||||||
raise DiscoveryFailed("Cannot get node %s: %s" % (uuid, exc))
|
raise utils.DiscoveryFailed("Cannot get node %s: %s" % (uuid, exc))
|
||||||
|
|
||||||
_validate(ironic, node)
|
_validate(ironic, node)
|
||||||
|
|
||||||
|
@ -192,7 +159,7 @@ def _validate(ironic, node):
|
||||||
if node.instance_uuid:
|
if node.instance_uuid:
|
||||||
LOG.error('Refusing to discover node %s with assigned instance_uuid',
|
LOG.error('Refusing to discover node %s with assigned instance_uuid',
|
||||||
node.uuid)
|
node.uuid)
|
||||||
raise DiscoveryFailed(
|
raise utils.DiscoveryFailed(
|
||||||
'Refusing to discover node %s with assigned instance uuid' %
|
'Refusing to discover node %s with assigned instance uuid' %
|
||||||
node.uuid)
|
node.uuid)
|
||||||
|
|
||||||
|
@ -202,7 +169,7 @@ def _validate(ironic, node):
|
||||||
LOG.error('Refusing to discover node %s with power_state "%s" '
|
LOG.error('Refusing to discover node %s with power_state "%s" '
|
||||||
'and maintenance mode off',
|
'and maintenance mode off',
|
||||||
node.uuid, power_state)
|
node.uuid, power_state)
|
||||||
raise DiscoveryFailed(
|
raise utils.DiscoveryFailed(
|
||||||
'Refusing to discover node %s with power state "%s" and '
|
'Refusing to discover node %s with power state "%s" and '
|
||||||
'maintenance mode off' %
|
'maintenance mode off' %
|
||||||
(node.uuid, power_state))
|
(node.uuid, power_state))
|
||||||
|
@ -211,8 +178,8 @@ def _validate(ironic, node):
|
||||||
if not validation.power['result']:
|
if not validation.power['result']:
|
||||||
LOG.error('Failed validation of power interface for node %s, '
|
LOG.error('Failed validation of power interface for node %s, '
|
||||||
'reason: %s', node.uuid, validation.power['reason'])
|
'reason: %s', node.uuid, validation.power['reason'])
|
||||||
raise DiscoveryFailed('Failed validation of power interface for '
|
raise utils.DiscoveryFailed('Failed validation of power interface for '
|
||||||
'node %s' % node.uuid)
|
'node %s' % node.uuid)
|
||||||
|
|
||||||
|
|
||||||
def _background_discover(ironic, nodes):
|
def _background_discover(ironic, nodes):
|
||||||
|
@ -228,15 +195,18 @@ def _background_discover(ironic, nodes):
|
||||||
|
|
||||||
ironic.node.update(node.uuid, patch + node_patch)
|
ironic.node.update(node.uuid, patch + node_patch)
|
||||||
|
|
||||||
to_exclude = set()
|
all_macs = set()
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
# TODO(dtantsur): pagination
|
# TODO(dtantsur): pagination
|
||||||
ports = ironic.node.list_ports(node.uuid, limit=0)
|
macs = [p.address for p in ironic.node.list_ports(node.uuid, limit=0)]
|
||||||
to_exclude.update(p.address for p in ports)
|
all_macs.update(macs)
|
||||||
|
node_cache.add_node(node.uuid,
|
||||||
|
bmc_address=node.driver_info.get('ipmi_address'),
|
||||||
|
mac=macs)
|
||||||
|
|
||||||
if to_exclude:
|
if all_macs:
|
||||||
LOG.info('Whitelisting MAC\'s %s in the firewall', to_exclude)
|
LOG.info('Whitelisting MAC\'s %s in the firewall', all_macs)
|
||||||
firewall.whitelist_macs(to_exclude)
|
firewall.whitelist_macs(all_macs)
|
||||||
firewall.update_filters(ironic)
|
firewall.update_filters(ironic)
|
||||||
|
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
|
|
|
@ -24,6 +24,7 @@ from keystoneclient import exceptions
|
||||||
from ironic_discoverd import conf
|
from ironic_discoverd import conf
|
||||||
from ironic_discoverd import discoverd
|
from ironic_discoverd import discoverd
|
||||||
from ironic_discoverd import firewall
|
from ironic_discoverd import firewall
|
||||||
|
from ironic_discoverd import node_cache
|
||||||
from ironic_discoverd import utils
|
from ironic_discoverd import utils
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,7 +57,7 @@ def post_discover():
|
||||||
LOG.debug("Got JSON %s", data)
|
LOG.debug("Got JSON %s", data)
|
||||||
try:
|
try:
|
||||||
discoverd.discover(data)
|
discoverd.discover(data)
|
||||||
except discoverd.DiscoveryFailed as exc:
|
except utils.DiscoveryFailed as exc:
|
||||||
return str(exc), exc.http_code
|
return str(exc), exc.http_code
|
||||||
else:
|
else:
|
||||||
return "", 202
|
return "", 202
|
||||||
|
@ -87,6 +88,7 @@ def main():
|
||||||
if not conf.getboolean('discoverd', 'authenticate'):
|
if not conf.getboolean('discoverd', 'authenticate'):
|
||||||
LOG.warning('Starting unauthenticated, please check configuration')
|
LOG.warning('Starting unauthenticated, please check configuration')
|
||||||
|
|
||||||
|
node_cache.init()
|
||||||
firewall.init()
|
firewall.init()
|
||||||
utils.check_ironic_available()
|
utils.check_ironic_available()
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,125 @@
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
"""Cache for nodes currently under discovery."""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import sqlite3
|
||||||
|
import time
|
||||||
|
|
||||||
|
from ironic_discoverd import conf
|
||||||
|
from ironic_discoverd import utils
|
||||||
|
|
||||||
|
|
||||||
|
LOG = logging.getLogger("discoverd")
|
||||||
|
_DB = None
|
||||||
|
_SCHEMA = """
|
||||||
|
create table if not exists nodes
|
||||||
|
(uuid text primary key, started_at real);
|
||||||
|
|
||||||
|
create table if not exists attributes
|
||||||
|
(name text, value text, uuid text,
|
||||||
|
primary key (name, value),
|
||||||
|
foreign key (uuid) references nodes);
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def init():
|
||||||
|
"""Initialize the database."""
|
||||||
|
global _DB
|
||||||
|
conn = conf.get('discoverd', 'database') or ':memory:'
|
||||||
|
_DB = sqlite3.connect(conn)
|
||||||
|
_DB.executescript(_SCHEMA)
|
||||||
|
|
||||||
|
|
||||||
|
def _db():
|
||||||
|
if _DB is None:
|
||||||
|
init()
|
||||||
|
return _DB
|
||||||
|
|
||||||
|
|
||||||
|
def add_node(uuid, **attributes):
|
||||||
|
"""Store information about a node under discovery.
|
||||||
|
|
||||||
|
All existing information about this node is dropped.
|
||||||
|
Empty values are skipped.
|
||||||
|
|
||||||
|
:param uuid: Ironic node UUID
|
||||||
|
:param attributes: attributes known about this node (like macs, BMC etc)
|
||||||
|
"""
|
||||||
|
drop_node(uuid)
|
||||||
|
with _db():
|
||||||
|
_db().execute("insert into nodes(uuid, started_at) "
|
||||||
|
"values(?, ?)", (uuid, time.time()))
|
||||||
|
for (name, value) in attributes.items():
|
||||||
|
if not value:
|
||||||
|
continue
|
||||||
|
if not isinstance(value, list):
|
||||||
|
value = [value]
|
||||||
|
|
||||||
|
try:
|
||||||
|
_db().executemany("insert into attributes(name, value, uuid) "
|
||||||
|
"values(?, ?, ?)",
|
||||||
|
[(name, v, uuid) for v in value])
|
||||||
|
except sqlite3.IntegrityError:
|
||||||
|
raise utils.DiscoveryFailed(
|
||||||
|
'Some or all of %(name)s\'s %(value)s are already '
|
||||||
|
'on discovery' %
|
||||||
|
{'name': name, 'value': value})
|
||||||
|
|
||||||
|
|
||||||
|
def drop_node(uuid):
|
||||||
|
"""Forget information about node with given uuid."""
|
||||||
|
with _db():
|
||||||
|
_db().execute("delete from nodes where uuid=?", (uuid,))
|
||||||
|
_db().execute("delete from attributes where uuid=?", (uuid,))
|
||||||
|
|
||||||
|
|
||||||
|
def pop_node(**attributes):
|
||||||
|
"""Find node in cache.
|
||||||
|
|
||||||
|
This function also deletes a node from the cache, thus it's name.
|
||||||
|
|
||||||
|
:param attributes: attributes known about this node (like macs, BMC etc)
|
||||||
|
:returns: UUID or None
|
||||||
|
"""
|
||||||
|
# NOTE(dtantsur): sorting is not required, but gives us predictability
|
||||||
|
found = set()
|
||||||
|
for (name, value) in sorted(attributes.items()):
|
||||||
|
if not value:
|
||||||
|
LOG.warning('Empty value for attribute %s', name)
|
||||||
|
continue
|
||||||
|
if not isinstance(value, list):
|
||||||
|
value = [value]
|
||||||
|
|
||||||
|
LOG.debug('Trying to use %s %s for discovery' % (name, value))
|
||||||
|
rows = _db().execute('select distinct uuid from attributes where ' +
|
||||||
|
' OR '.join('name=? AND value=?' for _ in value),
|
||||||
|
sum(([name, v] for v in value), [])).fetchall()
|
||||||
|
if rows:
|
||||||
|
found.update(item[0] for item in rows)
|
||||||
|
|
||||||
|
if not found:
|
||||||
|
LOG.error('Could not find a node based on attributes %s',
|
||||||
|
list(attributes))
|
||||||
|
return
|
||||||
|
elif len(found) > 1:
|
||||||
|
LOG.error('Multiple nodes were matched based on attributes %(keys)s: '
|
||||||
|
'%(uuids)s',
|
||||||
|
{'keys': list(attributes),
|
||||||
|
'uuids': list(found)})
|
||||||
|
return
|
||||||
|
|
||||||
|
uuid = found.pop()
|
||||||
|
drop_node(uuid)
|
||||||
|
return uuid
|
|
@ -26,20 +26,24 @@ from ironic_discoverd import conf
|
||||||
from ironic_discoverd import discoverd
|
from ironic_discoverd import discoverd
|
||||||
from ironic_discoverd import firewall
|
from ironic_discoverd import firewall
|
||||||
from ironic_discoverd import main
|
from ironic_discoverd import main
|
||||||
|
from ironic_discoverd import node_cache
|
||||||
from ironic_discoverd import utils
|
from ironic_discoverd import utils
|
||||||
|
|
||||||
|
|
||||||
def init_conf():
|
def init_conf():
|
||||||
conf.init_conf()
|
conf.init_conf()
|
||||||
conf.CONF.add_section('discoverd')
|
conf.CONF.add_section('discoverd')
|
||||||
|
conf.CONF.set('discoverd', 'database', '')
|
||||||
|
node_cache._DB = None
|
||||||
|
|
||||||
|
|
||||||
# FIXME(dtantsur): this test suite is far from being complete
|
# FIXME(dtantsur): this test suite is far from being complete
|
||||||
@patch.object(firewall, 'update_filters', autospec=True)
|
@patch.object(firewall, 'update_filters', autospec=True)
|
||||||
|
@patch.object(node_cache, 'pop_node', autospec=True)
|
||||||
@patch.object(utils, 'get_client', autospec=True)
|
@patch.object(utils, 'get_client', autospec=True)
|
||||||
class TestProcess(unittest.TestCase):
|
class TestProcess(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.node = Mock(driver_info={},
|
self.node = Mock(driver_info={'ipmi_address': '1.2.3.4'},
|
||||||
properties={'cpu_arch': 'i386', 'local_gb': 40},
|
properties={'cpu_arch': 'i386', 'local_gb': 40},
|
||||||
uuid='uuid',
|
uuid='uuid',
|
||||||
extra={'on_discovery': 'true'})
|
extra={'on_discovery': 'true'})
|
||||||
|
@ -50,6 +54,7 @@ class TestProcess(unittest.TestCase):
|
||||||
{'op': 'add', 'path': '/properties/memory_mb', 'value': '1024'},
|
{'op': 'add', 'path': '/properties/memory_mb', 'value': '1024'},
|
||||||
]
|
]
|
||||||
self.data = {
|
self.data = {
|
||||||
|
'ipmi_address': '1.2.3.4',
|
||||||
'cpus': 2,
|
'cpus': 2,
|
||||||
'cpu_arch': 'x86_64',
|
'cpu_arch': 'x86_64',
|
||||||
'memory_mb': 1024,
|
'memory_mb': 1024,
|
||||||
|
@ -67,60 +72,20 @@ class TestProcess(unittest.TestCase):
|
||||||
'66:55:44:33:22:11'])
|
'66:55:44:33:22:11'])
|
||||||
init_conf()
|
init_conf()
|
||||||
|
|
||||||
def _do_test_bmc(self, client_mock, filters_mock):
|
def _do_test(self, client_mock, pop_mock, filters_mock):
|
||||||
self.node.driver_info['ipmi_address'] = '1.2.3.4'
|
|
||||||
cli = client_mock.return_value
|
cli = client_mock.return_value
|
||||||
cli.node.list.return_value = [
|
|
||||||
Mock(driver_info={}),
|
|
||||||
Mock(driver_info={'ipmi_address': '4.3.2.1'}),
|
|
||||||
self.node,
|
|
||||||
Mock(driver_info={'ipmi_address': '1.2.1.2'}),
|
|
||||||
]
|
|
||||||
cli.port.create.side_effect = [None, exceptions.Conflict()]
|
|
||||||
|
|
||||||
self.data['ipmi_address'] = '1.2.3.4'
|
|
||||||
discoverd.process(self.data)
|
|
||||||
|
|
||||||
self.assertTrue(cli.node.list.called)
|
|
||||||
self.assertFalse(cli.port.get_by_address.called)
|
|
||||||
cli.node.update.assert_called_once_with(self.node.uuid, self.patch)
|
|
||||||
cli.port.create.assert_any_call(node_uuid=self.node.uuid,
|
|
||||||
address='11:22:33:44:55:66')
|
|
||||||
cli.port.create.assert_any_call(node_uuid=self.node.uuid,
|
|
||||||
address='66:55:44:33:22:11')
|
|
||||||
self.assertEqual(2, cli.port.create.call_count)
|
|
||||||
filters_mock.assert_called_once_with(cli)
|
|
||||||
self.assertEqual(set(), firewall.MACS_DISCOVERY)
|
|
||||||
cli.node.set_power_state.assert_called_once_with(self.node.uuid, 'off')
|
|
||||||
|
|
||||||
def test_bmc(self, client_mock, filters_mock):
|
|
||||||
self._do_test_bmc(client_mock, filters_mock)
|
|
||||||
|
|
||||||
def test_bmc_deprecated_macs(self, client_mock, filters_mock):
|
|
||||||
del self.data['interfaces']
|
|
||||||
self.data['macs'] = self.macs
|
|
||||||
self._do_test_bmc(client_mock, filters_mock)
|
|
||||||
|
|
||||||
def test_bmc_ports_for_inactive(self, client_mock, filters_mock):
|
|
||||||
del self.data['interfaces']['em4']
|
|
||||||
conf.CONF.set('discoverd', 'ports_for_inactive_interfaces',
|
|
||||||
'true')
|
|
||||||
self._do_test_bmc(client_mock, filters_mock)
|
|
||||||
|
|
||||||
def test_macs(self, client_mock, filters_mock):
|
|
||||||
discoverd.ALLOW_SEARCH_BY_MAC = True
|
|
||||||
cli = client_mock.return_value
|
|
||||||
cli.port.get_by_address.side_effect = [
|
|
||||||
exceptions.NotFound(), Mock(node_uuid=self.node.uuid)]
|
|
||||||
cli.port.create.side_effect = [None, exceptions.Conflict()]
|
cli.port.create.side_effect = [None, exceptions.Conflict()]
|
||||||
|
pop_mock.return_value = self.node.uuid
|
||||||
cli.node.get.return_value = self.node
|
cli.node.get.return_value = self.node
|
||||||
|
|
||||||
discoverd.process(self.data)
|
discoverd.process(self.data)
|
||||||
|
|
||||||
self.assertFalse(cli.node.list.called)
|
pop_mock.assert_called_once_with(bmc_address='1.2.3.4',
|
||||||
cli.port.get_by_address.assert_any_call('11:22:33:44:55:66')
|
mac=ANY)
|
||||||
cli.port.get_by_address.assert_any_call('66:55:44:33:22:11')
|
|
||||||
cli.node.get.assert_called_once_with(self.node.uuid)
|
cli.node.get.assert_called_once_with(self.node.uuid)
|
||||||
|
self.assertEqual(['11:22:33:44:55:66', '66:55:44:33:22:11'],
|
||||||
|
sorted(pop_mock.call_args[1]['mac']))
|
||||||
|
|
||||||
cli.node.update.assert_called_once_with(self.node.uuid, self.patch)
|
cli.node.update.assert_called_once_with(self.node.uuid, self.patch)
|
||||||
cli.port.create.assert_any_call(node_uuid=self.node.uuid,
|
cli.port.create.assert_any_call(node_uuid=self.node.uuid,
|
||||||
address='11:22:33:44:55:66')
|
address='11:22:33:44:55:66')
|
||||||
|
@ -131,28 +96,68 @@ class TestProcess(unittest.TestCase):
|
||||||
self.assertEqual(set(), firewall.MACS_DISCOVERY)
|
self.assertEqual(set(), firewall.MACS_DISCOVERY)
|
||||||
cli.node.set_power_state.assert_called_once_with(self.node.uuid, 'off')
|
cli.node.set_power_state.assert_called_once_with(self.node.uuid, 'off')
|
||||||
|
|
||||||
|
def test_ok(self, client_mock, pop_mock, filters_mock):
|
||||||
|
self._do_test(client_mock, pop_mock, filters_mock)
|
||||||
|
|
||||||
|
def test_deprecated_macs(self, client_mock, pop_mock, filters_mock):
|
||||||
|
del self.data['interfaces']
|
||||||
|
self.data['macs'] = self.macs
|
||||||
|
self._do_test(client_mock, pop_mock, filters_mock)
|
||||||
|
|
||||||
|
def test_ports_for_inactive(self, client_mock, pop_mock, filters_mock):
|
||||||
|
del self.data['interfaces']['em4']
|
||||||
|
conf.CONF.set('discoverd', 'ports_for_inactive_interfaces',
|
||||||
|
'true')
|
||||||
|
self._do_test(client_mock, pop_mock, filters_mock)
|
||||||
|
|
||||||
|
def test_not_found(self, client_mock, pop_mock, filters_mock):
|
||||||
|
cli = client_mock.return_value
|
||||||
|
pop_mock.return_value = None
|
||||||
|
|
||||||
|
discoverd.process(self.data)
|
||||||
|
|
||||||
|
self.assertFalse(cli.node.update.called)
|
||||||
|
self.assertFalse(cli.port.create.called)
|
||||||
|
self.assertFalse(cli.node.set_power_state.called)
|
||||||
|
|
||||||
|
def test_not_found_in_ironic(self, client_mock, pop_mock, filters_mock):
|
||||||
|
cli = client_mock.return_value
|
||||||
|
pop_mock.return_value = self.node.uuid
|
||||||
|
cli.node.get.side_effect = exceptions.NotFound()
|
||||||
|
|
||||||
|
discoverd.process(self.data)
|
||||||
|
|
||||||
|
cli.node.get.assert_called_once_with(self.node.uuid)
|
||||||
|
self.assertFalse(cli.node.update.called)
|
||||||
|
self.assertFalse(cli.port.create.called)
|
||||||
|
self.assertFalse(cli.node.set_power_state.called)
|
||||||
|
|
||||||
|
|
||||||
@patch.object(eventlet.greenthread, 'spawn_n',
|
@patch.object(eventlet.greenthread, 'spawn_n',
|
||||||
side_effect=lambda f, *a: f(*a) and None)
|
side_effect=lambda f, *a: f(*a) and None)
|
||||||
@patch.object(firewall, 'update_filters', autospec=True)
|
@patch.object(firewall, 'update_filters', autospec=True)
|
||||||
|
@patch.object(node_cache, 'add_node', autospec=True)
|
||||||
@patch.object(utils, 'get_client', autospec=True)
|
@patch.object(utils, 'get_client', autospec=True)
|
||||||
class TestDiscover(unittest.TestCase):
|
class TestDiscover(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestDiscover, self).setUp()
|
super(TestDiscover, self).setUp()
|
||||||
self.node1 = Mock(driver='pxe_ssh',
|
self.node1 = Mock(driver='pxe_ssh',
|
||||||
uuid='uuid1',
|
uuid='uuid1',
|
||||||
|
driver_info={},
|
||||||
maintenance=True,
|
maintenance=True,
|
||||||
instance_uuid=None,
|
instance_uuid=None,
|
||||||
# allowed with maintenance=True
|
# allowed with maintenance=True
|
||||||
power_state='power on')
|
power_state='power on')
|
||||||
self.node2 = Mock(driver='pxe_ipmitool',
|
self.node2 = Mock(driver='pxe_ipmitool',
|
||||||
uuid='uuid2',
|
uuid='uuid2',
|
||||||
|
driver_info={'ipmi_address': '1.2.3.4'},
|
||||||
maintenance=False,
|
maintenance=False,
|
||||||
instance_uuid=None,
|
instance_uuid=None,
|
||||||
power_state=None,
|
power_state=None,
|
||||||
extra={'on_discovery': True})
|
extra={'on_discovery': True})
|
||||||
self.node3 = Mock(driver='pxe_ipmitool',
|
self.node3 = Mock(driver='pxe_ipmitool',
|
||||||
uuid='uuid3',
|
uuid='uuid3',
|
||||||
|
driver_info={'ipmi_address': '1.2.3.5'},
|
||||||
maintenance=False,
|
maintenance=False,
|
||||||
instance_uuid=None,
|
instance_uuid=None,
|
||||||
power_state='power off',
|
power_state='power off',
|
||||||
|
@ -161,25 +166,40 @@ class TestDiscover(unittest.TestCase):
|
||||||
init_conf()
|
init_conf()
|
||||||
|
|
||||||
@patch.object(time, 'time', lambda: 42.0)
|
@patch.object(time, 'time', lambda: 42.0)
|
||||||
def test_ok(self, client_mock, filters_mock, spawn_mock):
|
def test_ok(self, client_mock, add_mock, filters_mock, spawn_mock):
|
||||||
cli = client_mock.return_value
|
cli = client_mock.return_value
|
||||||
cli.node.get.side_effect = [
|
cli.node.get.side_effect = [
|
||||||
self.node1,
|
self.node1,
|
||||||
self.node2,
|
self.node2,
|
||||||
self.node3,
|
self.node3,
|
||||||
]
|
]
|
||||||
cli.node.list_ports.return_value = [Mock(address='1'),
|
ports = [
|
||||||
Mock(address='2')]
|
[Mock(address='1-1'), Mock(address='1-2')],
|
||||||
|
[Mock(address='2-1'), Mock(address='2-2')],
|
||||||
|
[Mock(address='3-1'), Mock(address='3-2')],
|
||||||
|
]
|
||||||
|
cli.node.list_ports.side_effect = ports
|
||||||
|
|
||||||
discoverd.discover(['uuid1', 'uuid2', 'uuid3'])
|
discoverd.discover(['uuid1', 'uuid2', 'uuid3'])
|
||||||
|
|
||||||
self.assertEqual(3, cli.node.get.call_count)
|
self.assertEqual(3, cli.node.get.call_count)
|
||||||
self.assertEqual(3, cli.node.list_ports.call_count)
|
self.assertEqual(3, cli.node.list_ports.call_count)
|
||||||
|
self.assertEqual(3, add_mock.call_count)
|
||||||
cli.node.list_ports.assert_any_call('uuid1', limit=0)
|
cli.node.list_ports.assert_any_call('uuid1', limit=0)
|
||||||
cli.node.list_ports.assert_any_call('uuid2', limit=0)
|
cli.node.list_ports.assert_any_call('uuid2', limit=0)
|
||||||
cli.node.list_ports.assert_any_call('uuid3', limit=0)
|
cli.node.list_ports.assert_any_call('uuid3', limit=0)
|
||||||
|
add_mock.assert_any_call(self.node1.uuid,
|
||||||
|
bmc_address=None,
|
||||||
|
mac=['1-1', '1-2'])
|
||||||
|
add_mock.assert_any_call(self.node2.uuid,
|
||||||
|
bmc_address='1.2.3.4',
|
||||||
|
mac=['2-1', '2-2'])
|
||||||
|
add_mock.assert_any_call(self.node3.uuid,
|
||||||
|
bmc_address='1.2.3.5',
|
||||||
|
mac=['3-1', '3-2'])
|
||||||
filters_mock.assert_called_once_with(cli)
|
filters_mock.assert_called_once_with(cli)
|
||||||
self.assertEqual(set(['1', '2']), firewall.MACS_DISCOVERY)
|
self.assertEqual(set(port.address for l in ports for port in l),
|
||||||
|
firewall.MACS_DISCOVERY)
|
||||||
self.assertEqual(3, cli.node.set_power_state.call_count)
|
self.assertEqual(3, cli.node.set_power_state.call_count)
|
||||||
cli.node.set_power_state.assert_called_with(ANY, 'reboot')
|
cli.node.set_power_state.assert_called_with(ANY, 'reboot')
|
||||||
patch = [{'op': 'add', 'path': '/extra/on_discovery', 'value': 'true'},
|
patch = [{'op': 'add', 'path': '/extra/on_discovery', 'value': 'true'},
|
||||||
|
@ -198,13 +218,14 @@ class TestDiscover(unittest.TestCase):
|
||||||
spawn_mock.assert_called_once_with(discoverd._background_discover,
|
spawn_mock.assert_called_once_with(discoverd._background_discover,
|
||||||
cli, ANY)
|
cli, ANY)
|
||||||
|
|
||||||
def test_failed_to_get_node(self, client_mock, filters_mock, spawn_mock):
|
def test_failed_to_get_node(self, client_mock, add_mock, filters_mock,
|
||||||
|
spawn_mock):
|
||||||
cli = client_mock.return_value
|
cli = client_mock.return_value
|
||||||
cli.node.get.side_effect = [
|
cli.node.get.side_effect = [
|
||||||
self.node1,
|
self.node1,
|
||||||
exceptions.NotFound(),
|
exceptions.NotFound(),
|
||||||
]
|
]
|
||||||
self.assertRaisesRegexp(discoverd.DiscoveryFailed,
|
self.assertRaisesRegexp(utils.DiscoveryFailed,
|
||||||
'Cannot find node uuid2',
|
'Cannot find node uuid2',
|
||||||
discoverd.discover, ['uuid1', 'uuid2'])
|
discoverd.discover, ['uuid1', 'uuid2'])
|
||||||
|
|
||||||
|
@ -212,7 +233,7 @@ class TestDiscover(unittest.TestCase):
|
||||||
exceptions.Conflict(),
|
exceptions.Conflict(),
|
||||||
self.node1,
|
self.node1,
|
||||||
]
|
]
|
||||||
self.assertRaisesRegexp(discoverd.DiscoveryFailed,
|
self.assertRaisesRegexp(utils.DiscoveryFailed,
|
||||||
'Cannot get node uuid1',
|
'Cannot get node uuid1',
|
||||||
discoverd.discover, ['uuid1', 'uuid2'])
|
discoverd.discover, ['uuid1', 'uuid2'])
|
||||||
|
|
||||||
|
@ -221,8 +242,9 @@ class TestDiscover(unittest.TestCase):
|
||||||
self.assertEqual(0, filters_mock.call_count)
|
self.assertEqual(0, filters_mock.call_count)
|
||||||
self.assertEqual(0, cli.node.set_power_state.call_count)
|
self.assertEqual(0, cli.node.set_power_state.call_count)
|
||||||
self.assertEqual(0, cli.node.update.call_count)
|
self.assertEqual(0, cli.node.update.call_count)
|
||||||
|
self.assertFalse(add_mock.called)
|
||||||
|
|
||||||
def test_failed_to_validate_node(self, client_mock, filters_mock,
|
def test_failed_to_validate_node(self, client_mock, add_mock, filters_mock,
|
||||||
spawn_mock):
|
spawn_mock):
|
||||||
cli = client_mock.return_value
|
cli = client_mock.return_value
|
||||||
cli.node.get.side_effect = [
|
cli.node.get.side_effect = [
|
||||||
|
@ -234,7 +256,7 @@ class TestDiscover(unittest.TestCase):
|
||||||
Mock(power={'result': False, 'reason': 'oops'}),
|
Mock(power={'result': False, 'reason': 'oops'}),
|
||||||
]
|
]
|
||||||
self.assertRaisesRegexp(
|
self.assertRaisesRegexp(
|
||||||
discoverd.DiscoveryFailed,
|
utils.DiscoveryFailed,
|
||||||
'Failed validation of power interface for node uuid2',
|
'Failed validation of power interface for node uuid2',
|
||||||
discoverd.discover, ['uuid1', 'uuid2'])
|
discoverd.discover, ['uuid1', 'uuid2'])
|
||||||
|
|
||||||
|
@ -244,14 +266,17 @@ class TestDiscover(unittest.TestCase):
|
||||||
self.assertEqual(0, filters_mock.call_count)
|
self.assertEqual(0, filters_mock.call_count)
|
||||||
self.assertEqual(0, cli.node.set_power_state.call_count)
|
self.assertEqual(0, cli.node.set_power_state.call_count)
|
||||||
self.assertEqual(0, cli.node.update.call_count)
|
self.assertEqual(0, cli.node.update.call_count)
|
||||||
|
self.assertFalse(add_mock.called)
|
||||||
|
|
||||||
def test_no_uuids(self, client_mock, filters_mock, spawn_mock):
|
def test_no_uuids(self, client_mock, add_mock, filters_mock, spawn_mock):
|
||||||
self.assertRaisesRegexp(discoverd.DiscoveryFailed,
|
self.assertRaisesRegexp(utils.DiscoveryFailed,
|
||||||
'No nodes to discover',
|
'No nodes to discover',
|
||||||
discoverd.discover, [])
|
discoverd.discover, [])
|
||||||
self.assertFalse(client_mock.called)
|
self.assertFalse(client_mock.called)
|
||||||
|
self.assertFalse(add_mock.called)
|
||||||
|
|
||||||
def test_with_instance_uuid(self, client_mock, filters_mock, spawn_mock):
|
def test_with_instance_uuid(self, client_mock, add_mock, filters_mock,
|
||||||
|
spawn_mock):
|
||||||
self.node2.instance_uuid = 'uuid'
|
self.node2.instance_uuid = 'uuid'
|
||||||
cli = client_mock.return_value
|
cli = client_mock.return_value
|
||||||
cli.node.get.side_effect = [
|
cli.node.get.side_effect = [
|
||||||
|
@ -259,7 +284,7 @@ class TestDiscover(unittest.TestCase):
|
||||||
self.node2,
|
self.node2,
|
||||||
]
|
]
|
||||||
self.assertRaisesRegexp(
|
self.assertRaisesRegexp(
|
||||||
discoverd.DiscoveryFailed,
|
utils.DiscoveryFailed,
|
||||||
'node uuid2 with assigned instance uuid',
|
'node uuid2 with assigned instance uuid',
|
||||||
discoverd.discover, ['uuid1', 'uuid2'])
|
discoverd.discover, ['uuid1', 'uuid2'])
|
||||||
|
|
||||||
|
@ -268,8 +293,10 @@ class TestDiscover(unittest.TestCase):
|
||||||
self.assertEqual(0, filters_mock.call_count)
|
self.assertEqual(0, filters_mock.call_count)
|
||||||
self.assertEqual(0, cli.node.set_power_state.call_count)
|
self.assertEqual(0, cli.node.set_power_state.call_count)
|
||||||
self.assertEqual(0, cli.node.update.call_count)
|
self.assertEqual(0, cli.node.update.call_count)
|
||||||
|
self.assertFalse(add_mock.called)
|
||||||
|
|
||||||
def test_wrong_power_state(self, client_mock, filters_mock, spawn_mock):
|
def test_wrong_power_state(self, client_mock, add_mock, filters_mock,
|
||||||
|
spawn_mock):
|
||||||
self.node2.power_state = 'power on'
|
self.node2.power_state = 'power on'
|
||||||
self.node2.maintenance = False
|
self.node2.maintenance = False
|
||||||
cli = client_mock.return_value
|
cli = client_mock.return_value
|
||||||
|
@ -278,7 +305,7 @@ class TestDiscover(unittest.TestCase):
|
||||||
self.node2,
|
self.node2,
|
||||||
]
|
]
|
||||||
self.assertRaisesRegexp(
|
self.assertRaisesRegexp(
|
||||||
discoverd.DiscoveryFailed,
|
utils.DiscoveryFailed,
|
||||||
'node uuid2 with power state "power on"',
|
'node uuid2 with power state "power on"',
|
||||||
discoverd.discover, ['uuid1', 'uuid2'])
|
discoverd.discover, ['uuid1', 'uuid2'])
|
||||||
|
|
||||||
|
@ -287,6 +314,7 @@ class TestDiscover(unittest.TestCase):
|
||||||
self.assertEqual(0, filters_mock.call_count)
|
self.assertEqual(0, filters_mock.call_count)
|
||||||
self.assertEqual(0, cli.node.set_power_state.call_count)
|
self.assertEqual(0, cli.node.set_power_state.call_count)
|
||||||
self.assertEqual(0, cli.node.update.call_count)
|
self.assertEqual(0, cli.node.update.call_count)
|
||||||
|
self.assertFalse(add_mock.called)
|
||||||
|
|
||||||
|
|
||||||
class TestApi(unittest.TestCase):
|
class TestApi(unittest.TestCase):
|
||||||
|
@ -305,7 +333,7 @@ class TestApi(unittest.TestCase):
|
||||||
@patch.object(discoverd, 'discover', autospec=True)
|
@patch.object(discoverd, 'discover', autospec=True)
|
||||||
def test_discover_failed(self, discover_mock):
|
def test_discover_failed(self, discover_mock):
|
||||||
conf.CONF.set('discoverd', 'authenticate', 'false')
|
conf.CONF.set('discoverd', 'authenticate', 'false')
|
||||||
discover_mock.side_effect = discoverd.DiscoveryFailed("boom")
|
discover_mock.side_effect = utils.DiscoveryFailed("boom")
|
||||||
res = self.app.post('/v1/discover', data='["uuid1"]')
|
res = self.app.post('/v1/discover', data='["uuid1"]')
|
||||||
self.assertEqual(400, res.status_code)
|
self.assertEqual(400, res.status_code)
|
||||||
self.assertEqual(b"boom", res.data)
|
self.assertEqual(b"boom", res.data)
|
||||||
|
@ -399,5 +427,108 @@ class TestCheckIronicAvailable(unittest.TestCase):
|
||||||
self.assertEqual(attempts, sleep_mock.call_count)
|
self.assertEqual(attempts, sleep_mock.call_count)
|
||||||
|
|
||||||
|
|
||||||
|
class TestNodeCache(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
super(TestNodeCache, self).setUp()
|
||||||
|
init_conf()
|
||||||
|
self.db = node_cache._db()
|
||||||
|
self.node = Mock(driver_info={'ipmi_address': '1.2.3.4'},
|
||||||
|
uuid='uuid')
|
||||||
|
self.macs = ['11:22:33:44:55:66', '66:55:44:33:22:11']
|
||||||
|
|
||||||
|
def test_add_node(self):
|
||||||
|
# Ensure previous node information is cleared
|
||||||
|
self.db.execute("insert into nodes(uuid) values(?)", (self.node.uuid,))
|
||||||
|
self.db.execute("insert into nodes(uuid) values('uuid2')")
|
||||||
|
self.db.execute("insert into attributes(name, value, uuid) "
|
||||||
|
"values(?, ?, ?)",
|
||||||
|
('mac', '11:22:11:22:11:22', self.node.uuid))
|
||||||
|
|
||||||
|
node_cache.add_node(self.node.uuid, mac=self.macs,
|
||||||
|
bmc_address='1.2.3.4', foo=None)
|
||||||
|
|
||||||
|
res = self.db.execute("select uuid, started_at "
|
||||||
|
"from nodes order by uuid").fetchall()
|
||||||
|
self.assertEqual(['uuid', 'uuid2'], [t[0] for t in res])
|
||||||
|
self.assertTrue(time.time() - 60 < res[0][1] < time.time() + 60)
|
||||||
|
|
||||||
|
res = self.db.execute("select name, value, uuid from attributes "
|
||||||
|
"order by name, value").fetchall()
|
||||||
|
self.assertEqual([('bmc_address', '1.2.3.4', 'uuid'),
|
||||||
|
('mac', '11:22:33:44:55:66', 'uuid'),
|
||||||
|
('mac', '66:55:44:33:22:11', 'uuid')],
|
||||||
|
res)
|
||||||
|
|
||||||
|
def test_add_node_duplicate_mac(self):
|
||||||
|
self.db.execute("insert into nodes(uuid) values(?)", ('another-uuid',))
|
||||||
|
self.db.execute("insert into attributes(name, value, uuid) "
|
||||||
|
"values(?, ?, ?)",
|
||||||
|
('mac', '11:22:11:22:11:22', 'another-uuid'))
|
||||||
|
|
||||||
|
self.assertRaises(utils.DiscoveryFailed,
|
||||||
|
node_cache.add_node,
|
||||||
|
self.node.uuid, mac=['11:22:11:22:11:22'])
|
||||||
|
|
||||||
|
def test_drop_node(self):
|
||||||
|
self.db.execute("insert into nodes(uuid) values(?)", (self.node.uuid,))
|
||||||
|
self.db.execute("insert into nodes(uuid) values('uuid2')")
|
||||||
|
self.db.execute("insert into attributes(name, value, uuid) "
|
||||||
|
"values(?, ?, ?)",
|
||||||
|
('mac', '11:22:11:22:11:22', self.node.uuid))
|
||||||
|
|
||||||
|
node_cache.drop_node(self.node.uuid)
|
||||||
|
|
||||||
|
self.assertEqual([('uuid2',)], self.db.execute(
|
||||||
|
"select uuid from nodes").fetchall())
|
||||||
|
self.assertEqual([], self.db.execute(
|
||||||
|
"select * from attributes").fetchall())
|
||||||
|
|
||||||
|
|
||||||
|
class TestNodeCachePop(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
super(TestNodeCachePop, self).setUp()
|
||||||
|
init_conf()
|
||||||
|
self.db = node_cache._db()
|
||||||
|
self.uuid = 'uuid'
|
||||||
|
self.macs = ['11:22:33:44:55:66', '66:55:44:33:22:11']
|
||||||
|
self.macs2 = ['00:00:00:00:00:00']
|
||||||
|
node_cache.add_node(self.uuid,
|
||||||
|
bmc_address='1.2.3.4',
|
||||||
|
mac=self.macs)
|
||||||
|
|
||||||
|
def test_no_data(self):
|
||||||
|
self.assertIsNone(node_cache.pop_node())
|
||||||
|
self.assertIsNone(node_cache.pop_node(mac=[]))
|
||||||
|
|
||||||
|
def test_bmc(self):
|
||||||
|
res = node_cache.pop_node(bmc_address='1.2.3.4')
|
||||||
|
self.assertEqual(self.uuid, res)
|
||||||
|
self.assertEqual([], self.db.execute(
|
||||||
|
"select * from attributes").fetchall())
|
||||||
|
|
||||||
|
def test_macs(self):
|
||||||
|
res = node_cache.pop_node(mac=['11:22:33:33:33:33', self.macs[1]])
|
||||||
|
self.assertEqual(self.uuid, res)
|
||||||
|
self.assertEqual([], self.db.execute(
|
||||||
|
"select * from attributes").fetchall())
|
||||||
|
|
||||||
|
def test_macs_not_found(self):
|
||||||
|
res = node_cache.pop_node(mac=['11:22:33:33:33:33',
|
||||||
|
'66:66:44:33:22:11'])
|
||||||
|
self.assertIsNone(res)
|
||||||
|
|
||||||
|
def test_macs_multiple_found(self):
|
||||||
|
node_cache.add_node('uuid2', mac=self.macs2)
|
||||||
|
res = node_cache.pop_node(mac=[self.macs[0], self.macs2[0]])
|
||||||
|
self.assertIsNone(res)
|
||||||
|
|
||||||
|
def test_both(self):
|
||||||
|
res = node_cache.pop_node(bmc_address='1.2.3.4',
|
||||||
|
mac=self.macs)
|
||||||
|
self.assertEqual(self.uuid, res)
|
||||||
|
self.assertEqual([], self.db.execute(
|
||||||
|
"select * from attributes").fetchall())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -26,6 +26,12 @@ LOG = logging.getLogger('discoverd')
|
||||||
OS_ARGS = ('os_password', 'os_username', 'os_auth_url', 'os_tenant_name')
|
OS_ARGS = ('os_password', 'os_username', 'os_auth_url', 'os_tenant_name')
|
||||||
|
|
||||||
|
|
||||||
|
class DiscoveryFailed(Exception):
|
||||||
|
def __init__(self, msg, code=400):
|
||||||
|
super(DiscoveryFailed, self).__init__(msg)
|
||||||
|
self.http_code = code
|
||||||
|
|
||||||
|
|
||||||
def get_client(): # pragma: no cover
|
def get_client(): # pragma: no cover
|
||||||
args = dict((k, conf.get('discoverd', k)) for k in OS_ARGS)
|
args = dict((k, conf.get('discoverd', k)) for k in OS_ARGS)
|
||||||
return client.get_client(1, **args)
|
return client.get_client(1, **args)
|
||||||
|
|
Loading…
Reference in New Issue