Skip to content

Commit

Permalink
config options: move image_file_url download options
Browse files Browse the repository at this point in the history
In August 2013 the blueprint "image-multiple-location" got merged
with commit 6f9ed56. This commit introduced another way of
downloading images from glance, despite the normal way via HTTP.
This feature introduced new config options which dynamically generate
new "nova.conf" groups and therefore got never listed in the sample
"nova.conf" file nor in the configuration reference manual.

This change moves these options to "nova/conf/". A follow up change
will deprecate those options as we believe that this feature is never
used in any production environment.

bp centralize-config-options-newton

Change-Id: I140ce486d70e59eaca127d4bc8274c205a2355ee
  • Loading branch information
markuszoeller committed May 10, 2016
1 parent afce1f2 commit 9f6bb41
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
23 changes: 23 additions & 0 deletions nova/conf/image_file_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,36 @@
'image_file_url:<list entry name> '
'sections'))

# NOTE(jbresnah) because the group under which these options are added is
# dyncamically determined these options need to stay out of global space
# or they will confuse generate_sample.sh
filesystem_opts = [
cfg.StrOpt('id',
help=_('A unique ID given to each file system. This is '
'value is set in Glance and agreed upon here so '
'that the operator knowns they are dealing with '
'the same file system.')),
cfg.StrOpt('mountpoint',
help=_('The path at which the file system is mounted.')),
]

ALL_OPTS = [filesystems]


def register_opts(conf):
conf.register_group(image_file_url_group)
conf.register_opts(ALL_OPTS, group=image_file_url_group)
for fs in conf.image_file_url.filesystems:
group_name = 'image_file_url:' + fs
conf.register_opts(filesystem_opts, group=group_name)


def list_opts():
# NOTE(markus_z): As the "filesystem" opt has an empty list as a default
# value and this value is necessary for a correct group name, we cannot
# list the "filesystem_opts" for the "nova.conf.sample" file here. A
# follow up patch will deprecate those. Due to their dynamic creation
# they never got shown in "nova.conf.sample" nor the config reference
# manual. I see no need to change this here with a dummy group or somehing
# like that.
return {image_file_url_group: ALL_OPTS}
20 changes: 0 additions & 20 deletions nova/image/download/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.

from oslo_config import cfg
from oslo_log import log as logging

import nova.conf
Expand Down Expand Up @@ -63,19 +62,6 @@ class FileTransfer(xfer_base.TransferBase):

desc_required_keys = ['id', 'mountpoint']

# NOTE(jbresnah) because the group under which these options are added is
# dyncamically determined these options need to stay out of global space
# or they will confuse generate_sample.sh
filesystem_opts = [
cfg.StrOpt('id',
help=_('A unique ID given to each file system. This is '
'value is set in Glance and agreed upon here so '
'that the operator knowns they are dealing with '
'the same file system.')),
cfg.StrOpt('mountpoint',
help=_('The path at which the file system is mounted.')),
]

def _get_options(self):
fs_dict = {}
for fs in CONF.image_file_url.filesystems:
Expand All @@ -89,12 +75,6 @@ def _get_options(self):
fs_dict[CONF[group_name].id] = CONF[group_name]
return fs_dict

def __init__(self):
# create the needed options
for fs in CONF.image_file_url.filesystems:
group_name = 'image_file_url:' + fs
CONF.register_opts(self.filesystem_opts, group=group_name)

def _verify_config(self):
for fs_key in self.filesystems:
for r in self.desc_required_keys:
Expand Down
9 changes: 9 additions & 0 deletions nova/tests/unit/image/test_transfer_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,22 @@
import mock
import six.moves.urllib.parse as urlparse

import nova.conf
from nova import exception
from nova.image.download import file as tm_file
from nova import test

CONF = nova.conf.CONF


class TestFileTransferModule(test.NoDBTestCase):

@mock.patch('nova.virt.libvirt.utils.copy_image')
def test_filesystem_success(self, copy_mock):
self.flags(allowed_direct_url_schemes=['file'], group='glance')
self.flags(group='image_file_url', filesystems=['gluster'])
# register opts for dynamically created group 'image_file_url:gluster'
nova.conf.image_file_url.register_opts(CONF)

mountpoint = '/gluster'
url = 'file:///gluster/my/image/path'
Expand All @@ -52,6 +57,8 @@ def test_filesystem_success(self, copy_mock):
def test_filesystem_mismatched_mountpoint(self, copy_mock):
self.flags(allowed_direct_url_schemes=['file'], group='glance')
self.flags(group='image_file_url', filesystems=['gluster'])
# register opts for dynamically created group 'image_file_url:gluster'
nova.conf.image_file_url.register_opts(CONF)

mountpoint = '/gluster'
# Should include the mountpoint before my/image/path
Expand All @@ -78,6 +85,8 @@ def test_filesystem_mismatched_mountpoint(self, copy_mock):
def test_filesystem_mismatched_filesystem(self, copy_mock):
self.flags(allowed_direct_url_schemes=['file'], group='glance')
self.flags(group='image_file_url', filesystems=['gluster'])
# register opts for dynamically created group 'image_file_url:gluster'
nova.conf.image_file_url.register_opts(CONF)

mountpoint = '/gluster'
# Should include the mountpoint before my/image/path
Expand Down

0 comments on commit 9f6bb41

Please sign in to comment.