Variable 'domain_ref' referenced before assignment

Variable not declared before try...catch sentences trigger a
"Local variable 'domain_ref' referenced before assignment" error when
an exception is raised.

Co-Authored-By: David Stanek <dstanek@dstanek.com>
Change-Id: I0a63347cb316e3a5923243dd934a7fc51dbf1e13
Closes-Bug: #1274402
This commit is contained in:
Marcos Lobo 2014-01-30 08:53:58 +01:00 committed by David Stanek
parent e8f8c17749
commit 15b5209540
4 changed files with 74 additions and 13 deletions

View File

@ -103,20 +103,20 @@ class DomainConfigs(dict):
LOG.warning(
_('Invalid domain name (%s) found in config file name'),
domain_name)
return
if domain_ref:
# Create a new entry in the domain config dict, which contains
# a new instance of both the conf environment and driver using
# options defined in this set of config files. Later, when we
# service calls via this Manager, we'll index via this domain
# config dict to make sure we call the right driver
domain = domain_ref['id']
self[domain] = {}
self[domain]['cfg'] = cfg.ConfigOpts()
config.configure(conf=self[domain]['cfg'])
self[domain]['cfg'](args=[], project='keystone',
default_config_files=file_list)
self._load_driver(assignment_api, domain)
# Create a new entry in the domain config dict, which contains
# a new instance of both the conf environment and driver using
# options defined in this set of config files. Later, when we
# service calls via this Manager, we'll index via this domain
# config dict to make sure we call the right driver
domain = domain_ref['id']
self[domain] = {}
self[domain]['cfg'] = cfg.ConfigOpts()
config.configure(conf=self[domain]['cfg'])
self[domain]['cfg'](args=[], project='keystone',
default_config_files=file_list)
self._load_driver(assignment_api, domain)
def setup_domain_drivers(self, standard_driver, assignment_api):
# This is called by the api call wrapper

View File

View File

View File

@ -0,0 +1,61 @@
# 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.
"""Unit tests for core identity behavior."""
import os
import uuid
import mock
import testtools
from keystone import config
from keystone import exception
from keystone import identity
from keystone import tests
CONF = config.CONF
class TestDomainConfigs(testtools.TestCase):
def setUp(self):
super(TestDomainConfigs, self).setUp()
self.addCleanup(CONF.reset)
self.tmp_dir = tests.dirs.tmp()
CONF.set_override('domain_config_dir', self.tmp_dir, 'identity')
def test_config_for_nonexistent_domain(self):
"""Having a config for a non-existent domain will be ignored.
There are no assertions in this test because there are no side
effects. If there is a config file for a domain that does not
exist it should be ignored.
"""
domain_id = uuid.uuid4().hex
domain_config_filename = os.path.join(self.tmp_dir,
'keystone.%s.conf' % domain_id)
self.addCleanup(lambda: os.remove(domain_config_filename))
with open(domain_config_filename, 'w'):
"""Write an empty config file."""
e = exception.DomainNotFound(domain_id=domain_id)
mock_assignment_api = mock.Mock()
mock_assignment_api.get_domain_by_name.side_effect = e
domain_config = identity.DomainConfigs()
fake_standard_driver = None
domain_config.setup_domain_drivers(fake_standard_driver,
mock_assignment_api)