Merge "force_config_drive: StrOpt -> BoolOpt"

This commit is contained in:
Jenkins 2015-11-11 22:42:58 +00:00 committed by Gerrit Code Review
commit f0882bf2ec
2 changed files with 20 additions and 40 deletions

View File

@ -12,36 +12,14 @@
# License for the specific language governing permissions and limitations
# under the License.
from oslo_utils import strutils
from nova import objects
from nova import test
from nova.virt import configdrive
class ConfigDriveTestCase(test.NoDBTestCase):
def test_valid_string_values(self):
instance = objects.Instance(
config_drive=None,
system_metadata={}
)
for value in (strutils.TRUE_STRINGS + ('always',)):
self.flags(force_config_drive=value)
self.assertTrue(configdrive.required_by(instance))
def test_invalid_string_values(self):
instance = objects.Instance(
config_drive=None,
system_metadata={}
)
for value in (strutils.FALSE_STRINGS + ('foo',)):
self.flags(force_config_drive=value)
self.assertFalse(configdrive.required_by(instance))
def test_instance_force(self):
self.flags(force_config_drive="no")
self.flags(force_config_drive=False)
instance = objects.Instance(
config_drive="yes",
@ -53,7 +31,7 @@ class ConfigDriveTestCase(test.NoDBTestCase):
self.assertTrue(configdrive.required_by(instance))
def test_image_meta_force(self):
self.flags(force_config_drive="no")
self.flags(force_config_drive=False)
instance = objects.Instance(
config_drive=None,
@ -64,8 +42,20 @@ class ConfigDriveTestCase(test.NoDBTestCase):
self.assertTrue(configdrive.required_by(instance))
def test_image_meta_opt(self):
self.flags(force_config_drive="no")
def test_config_flag_force(self):
self.flags(force_config_drive=True)
instance = objects.Instance(
config_drive=None,
system_metadata={
"image_img_config_drive": "optional",
}
)
self.assertTrue(configdrive.required_by(instance))
def test_no_config_drive(self):
self.flags(force_config_drive=False)
instance = objects.Instance(
config_drive=None,

View File

@ -21,11 +21,9 @@ import shutil
from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import fileutils
from oslo_utils import strutils
from oslo_utils import units
from nova import exception
from nova.i18n import _LW
from nova import objects
from nova.objects import fields
from nova import utils
@ -38,13 +36,9 @@ configdrive_opts = [
default='iso9660',
choices=('iso9660', 'vfat'),
help='Config drive format.'),
# force_config_drive is a string option, to allow for future behaviors
# (e.g. use config_drive based on image properties)
cfg.StrOpt('force_config_drive',
choices=('always', 'True', 'False'),
help='Set to "always" to force injection to take place on a '
'config drive. NOTE: The "always" will be deprecated in '
'the Liberty release cycle.'),
cfg.BoolOpt('force_config_drive',
help='Force injection to take place on a config drive',
default=False),
cfg.StrOpt('mkisofs_cmd',
default='genisoimage',
help='Name and optionally path of the tool used for '
@ -62,9 +56,6 @@ class ConfigDriveBuilder(object):
"""Build config drives, optionally as a context manager."""
def __init__(self, instance_md=None):
if CONF.force_config_drive == 'always':
LOG.warning(_LW('The setting "always" will be deprecated in the '
'Liberty version. Please use "True" instead'))
self.imagefile = None
self.mdfiles = []
@ -186,8 +177,7 @@ def required_by(instance):
fields.ConfigDrivePolicy.OPTIONAL)
return (instance.config_drive or
'always' == CONF.force_config_drive or
strutils.bool_from_string(CONF.force_config_drive) or
CONF.force_config_drive or
image_prop == fields.ConfigDrivePolicy.MANDATORY
)