Fix CellStateManagerFile init to failure
Currently, specifying a cells_config file in nova.conf causes CellStateManager to fail and in turn stops the nova-cells service from starting. The reason is that CellsManager creates an instance of CellStateManager with no arguments. CellStateManager __new__ runs and creates an instance of CellStateManagerFile which runs __new__ and __init__ with cell_state_cls and cells_config_path set. At this point __new__ returns CellStateManagerFile and the new instance's __init__ method is invoked (CellStateManagerFile.__init__) with the original arguments (there weren't any) which then results in: 2014-04-29 11:52:05.240 16759 TRACE nova self.state_manager = cell_state_manager() 2014-04-29 11:52:05.240 16759 TRACE nova TypeError: __init__() takes exactly 3 arguments (1 given) It seems reasonable for CellStateManagerFile to derive the cells_config_path info for itself so I have updated the code with that change and added unit tests to catch this bug and to check that the correct managers are still returned Change-Id: I9021640515142a3ca95c2d9e7b03e19b529bc175 Closes-Bug: #1314677
This commit is contained in:
parent
ce15077ccb
commit
695191fa89
|
@ -153,10 +153,7 @@ class CellStateManager(base.Base):
|
|||
cells_config = CONF.cells.cells_config
|
||||
|
||||
if cells_config:
|
||||
config_path = CONF.find_file(cells_config)
|
||||
if not config_path:
|
||||
raise cfg.ConfigFilesNotFoundError(config_files=[cells_config])
|
||||
return CellStateManagerFile(cell_state_cls, config_path)
|
||||
return CellStateManagerFile(cell_state_cls)
|
||||
|
||||
return CellStateManagerDB(cell_state_cls)
|
||||
|
||||
|
@ -461,8 +458,11 @@ class CellStateManagerDB(CellStateManager):
|
|||
|
||||
|
||||
class CellStateManagerFile(CellStateManager):
|
||||
def __init__(self, cell_state_cls, cells_config_path):
|
||||
self.cells_config_path = cells_config_path
|
||||
def __init__(self, cell_state_cls=None):
|
||||
cells_config = CONF.cells.cells_config
|
||||
self.cells_config_path = CONF.find_file(cells_config)
|
||||
if not self.cells_config_path:
|
||||
raise cfg.ConfigFilesNotFoundError(config_files=[cells_config])
|
||||
super(CellStateManagerFile, self).__init__(cell_state_cls)
|
||||
|
||||
def _cell_data_sync(self, force=False):
|
||||
|
|
|
@ -20,15 +20,16 @@ import time
|
|||
|
||||
import mock
|
||||
from oslo.config import cfg
|
||||
import six
|
||||
|
||||
from nova.cells import state
|
||||
from nova import db
|
||||
from nova.db.sqlalchemy import models
|
||||
from nova import exception
|
||||
from nova.openstack.common.db import exception as db_exc
|
||||
from nova.openstack.common import fileutils
|
||||
from nova import test
|
||||
|
||||
|
||||
FAKE_COMPUTES = [
|
||||
('host1', 1024, 100, 0, 0),
|
||||
('host2', 1024, 100, -1, -1),
|
||||
|
@ -82,6 +83,19 @@ class TestCellsStateManager(test.TestCase):
|
|||
state.CellStateManager)
|
||||
self.assertEqual(['no_such_file_exists.conf'], e.config_files)
|
||||
|
||||
@mock.patch.object(cfg.ConfigOpts, 'find_file')
|
||||
@mock.patch.object(fileutils, 'read_cached_file')
|
||||
def test_filemanager_returned(self, mock_read_cached_file, mock_find_file):
|
||||
mock_find_file.return_value = "/etc/nova/cells.json"
|
||||
mock_read_cached_file.return_value = (False, six.StringIO({}))
|
||||
self.flags(cells_config='cells.json', group='cells')
|
||||
self.assertIsInstance(state.CellStateManager(),
|
||||
state.CellStateManagerFile)
|
||||
|
||||
def test_dbmanager_returned(self):
|
||||
self.assertIsInstance(state.CellStateManager(),
|
||||
state.CellStateManagerDB)
|
||||
|
||||
def test_capacity_no_reserve(self):
|
||||
# utilize entire cell
|
||||
cap = self._capacity(0.0)
|
||||
|
|
Loading…
Reference in New Issue