Move global glance opts into nova.image.glance
Move the glance_host, glance_port and glance_protocol options into the nova.image.glance module. Also move the generate_glance_url() and generate_image_url() utility methods there since they're the only uses of the options outside of the module. blueprint: scope-config-opts Change-Id: I3beca1a65cdd902a94ddc1c512d79a4de635ef38
This commit is contained in:
parent
942b3ed874
commit
2bcca39592
|
@ -18,7 +18,7 @@
|
|||
import os.path
|
||||
|
||||
from nova.api.openstack import common
|
||||
from nova import utils
|
||||
from nova.image import glance
|
||||
|
||||
|
||||
class ViewBuilder(common.ViewBuilder):
|
||||
|
@ -117,7 +117,7 @@ class ViewBuilder(common.ViewBuilder):
|
|||
|
||||
def _get_alternate_link(self, request, identifier):
|
||||
"""Create an alternate link for a specific image id."""
|
||||
glance_url = utils.generate_glance_url()
|
||||
glance_url = glance.generate_glance_url()
|
||||
glance_url = self._update_glance_link_prefix(glance_url)
|
||||
return os.path.join(glance_url,
|
||||
request.environ["nova.context"].project_id,
|
||||
|
|
|
@ -1259,7 +1259,7 @@ class ComputeManager(manager.SchedulerDependentManager):
|
|||
# This instance.exists message should contain the original
|
||||
# image_ref, not the new one. Since the DB has been updated
|
||||
# to point to the new one... we have to override it.
|
||||
orig_image_ref_url = utils.generate_image_url(orig_image_ref)
|
||||
orig_image_ref_url = glance.generate_image_url(orig_image_ref)
|
||||
extra_usage_info = {'image_ref_url': orig_image_ref_url}
|
||||
compute_utils.notify_usage_exists(context, instance,
|
||||
current_period=True, system_metadata=orig_sys_metadata,
|
||||
|
|
|
@ -47,16 +47,6 @@ global_opts = [
|
|||
cfg.StrOpt('my_ip',
|
||||
default=_get_my_ip(),
|
||||
help='ip address of this host'),
|
||||
cfg.StrOpt('glance_host',
|
||||
default='$my_ip',
|
||||
help='default glance hostname or ip'),
|
||||
cfg.IntOpt('glance_port',
|
||||
default=9292,
|
||||
help='default glance port'),
|
||||
cfg.StrOpt('glance_protocol',
|
||||
default='http',
|
||||
help='Default protocol to use when connecting to glance. '
|
||||
'Set to https for SSL.'),
|
||||
cfg.IntOpt('s3_port',
|
||||
default=3333,
|
||||
help='port used when accessing the s3 api'),
|
||||
|
|
|
@ -36,6 +36,16 @@ from nova.openstack.common import log as logging
|
|||
from nova.openstack.common import timeutils
|
||||
|
||||
glance_opts = [
|
||||
cfg.StrOpt('glance_host',
|
||||
default='$my_ip',
|
||||
help='default glance hostname or ip'),
|
||||
cfg.IntOpt('glance_port',
|
||||
default=9292,
|
||||
help='default glance port'),
|
||||
cfg.StrOpt('glance_protocol',
|
||||
default='http',
|
||||
help='Default protocol to use when connecting to glance. '
|
||||
'Set to https for SSL.'),
|
||||
cfg.ListOpt('glance_api_servers',
|
||||
default=['$glance_host:$glance_port'],
|
||||
help='A list of the glance api servers available to nova. '
|
||||
|
@ -54,6 +64,18 @@ LOG = logging.getLogger(__name__)
|
|||
CONF = cfg.CONF
|
||||
CONF.register_opts(glance_opts)
|
||||
CONF.import_opt('auth_strategy', 'nova.api.auth')
|
||||
CONF.import_opt('my_ip', 'nova.config')
|
||||
|
||||
|
||||
def generate_glance_url():
|
||||
"""Generate the URL to glance."""
|
||||
return "%s://%s:%d" % (CONF.glance_protocol, CONF.glance_host,
|
||||
CONF.glance_port)
|
||||
|
||||
|
||||
def generate_image_url(image_ref):
|
||||
"""Generate an image URL from an image_ref."""
|
||||
return "%s/images/%s" % (generate_glance_url(), image_ref)
|
||||
|
||||
|
||||
def _parse_image_ref(image_href):
|
||||
|
|
|
@ -22,6 +22,7 @@ the system.
|
|||
import nova.context
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova.image import glance
|
||||
from nova import network
|
||||
from nova.network import model as network_model
|
||||
from nova.openstack.common import cfg
|
||||
|
@ -277,7 +278,7 @@ def info_from_instance(context, instance_ref, network_info,
|
|||
def null_safe_str(s):
|
||||
return str(s) if s else ''
|
||||
|
||||
image_ref_url = utils.generate_image_url(instance_ref['image_ref'])
|
||||
image_ref_url = glance.generate_image_url(instance_ref['image_ref'])
|
||||
|
||||
instance_type_name = instance_ref.get('instance_type', {}).get('name', '')
|
||||
|
||||
|
|
|
@ -29,10 +29,10 @@ from nova.api.openstack.compute import images
|
|||
from nova.api.openstack.compute.views import images as images_view
|
||||
from nova.api.openstack import xmlutil
|
||||
from nova import exception
|
||||
from nova.image import glance
|
||||
from nova import test
|
||||
from nova.tests.api.openstack import fakes
|
||||
from nova.tests import matchers
|
||||
from nova import utils
|
||||
|
||||
NS = "{http://docs.openstack.org/compute/api/v1.1}"
|
||||
ATOMNS = "{http://www.w3.org/2005/Atom}"
|
||||
|
@ -62,7 +62,7 @@ class ImagesControllerTest(test.TestCase):
|
|||
|
||||
href = "http://localhost/v2/fake/images/124"
|
||||
bookmark = "http://localhost/fake/images/124"
|
||||
alternate = "%s/fake/images/124" % utils.generate_glance_url()
|
||||
alternate = "%s/fake/images/124" % glance.generate_glance_url()
|
||||
server_uuid = "aa640691-d1a7-4a67-9d3c-d35ee6b3cc74"
|
||||
server_href = "http://localhost/v2/fake/servers/" + server_uuid
|
||||
server_bookmark = "http://localhost/fake/servers/" + server_uuid
|
||||
|
@ -200,7 +200,7 @@ class ImagesControllerTest(test.TestCase):
|
|||
{
|
||||
"rel": "alternate",
|
||||
"type": "application/vnd.openstack.image",
|
||||
"href": alternate % (utils.generate_glance_url(), 123),
|
||||
"href": alternate % (glance.generate_glance_url(), 123),
|
||||
}],
|
||||
},
|
||||
{
|
||||
|
@ -238,7 +238,7 @@ class ImagesControllerTest(test.TestCase):
|
|||
{
|
||||
"rel": "alternate",
|
||||
"type": "application/vnd.openstack.image",
|
||||
"href": alternate % (utils.generate_glance_url(), 124),
|
||||
"href": alternate % (glance.generate_glance_url(), 124),
|
||||
}],
|
||||
},
|
||||
{
|
||||
|
@ -276,7 +276,7 @@ class ImagesControllerTest(test.TestCase):
|
|||
{
|
||||
"rel": "alternate",
|
||||
"type": "application/vnd.openstack.image",
|
||||
"href": "%s/fake/images/125" % utils.generate_glance_url()
|
||||
"href": "%s/fake/images/125" % glance.generate_glance_url()
|
||||
}],
|
||||
},
|
||||
{
|
||||
|
@ -314,7 +314,7 @@ class ImagesControllerTest(test.TestCase):
|
|||
{
|
||||
"rel": "alternate",
|
||||
"type": "application/vnd.openstack.image",
|
||||
"href": "%s/fake/images/126" % utils.generate_glance_url()
|
||||
"href": "%s/fake/images/126" % glance.generate_glance_url()
|
||||
}],
|
||||
},
|
||||
{
|
||||
|
@ -352,7 +352,7 @@ class ImagesControllerTest(test.TestCase):
|
|||
{
|
||||
"rel": "alternate",
|
||||
"type": "application/vnd.openstack.image",
|
||||
"href": "%s/fake/images/127" % utils.generate_glance_url()
|
||||
"href": "%s/fake/images/127" % glance.generate_glance_url()
|
||||
}],
|
||||
},
|
||||
{
|
||||
|
@ -390,7 +390,7 @@ class ImagesControllerTest(test.TestCase):
|
|||
{
|
||||
"rel": "alternate",
|
||||
"type": "application/vnd.openstack.image",
|
||||
"href": "%s/fake/images/128" % utils.generate_glance_url()
|
||||
"href": "%s/fake/images/128" % glance.generate_glance_url()
|
||||
}],
|
||||
},
|
||||
{
|
||||
|
@ -428,7 +428,7 @@ class ImagesControllerTest(test.TestCase):
|
|||
{
|
||||
"rel": "alternate",
|
||||
"type": "application/vnd.openstack.image",
|
||||
"href": "%s/fake/images/129" % utils.generate_glance_url()
|
||||
"href": "%s/fake/images/129" % glance.generate_glance_url()
|
||||
}],
|
||||
},
|
||||
{
|
||||
|
@ -452,7 +452,7 @@ class ImagesControllerTest(test.TestCase):
|
|||
{
|
||||
"rel": "alternate",
|
||||
"type": "application/vnd.openstack.image",
|
||||
"href": "%s/fake/images/130" % utils.generate_glance_url()
|
||||
"href": "%s/fake/images/130" % glance.generate_glance_url()
|
||||
}],
|
||||
},
|
||||
]
|
||||
|
@ -491,7 +491,7 @@ class ImagesControllerTest(test.TestCase):
|
|||
{
|
||||
"rel": "alternate",
|
||||
"type": "application/vnd.openstack.image",
|
||||
"href": alternate % (utils.generate_glance_url(), 123),
|
||||
"href": alternate % (glance.generate_glance_url(), 123),
|
||||
}],
|
||||
},
|
||||
{
|
||||
|
@ -529,7 +529,7 @@ class ImagesControllerTest(test.TestCase):
|
|||
{
|
||||
"rel": "alternate",
|
||||
"type": "application/vnd.openstack.image",
|
||||
"href": alternate % (utils.generate_glance_url(), 124),
|
||||
"href": alternate % (glance.generate_glance_url(), 124),
|
||||
}],
|
||||
}]
|
||||
|
||||
|
@ -656,7 +656,7 @@ class ImagesControllerTest(test.TestCase):
|
|||
view = images_view.ViewBuilder()
|
||||
request = fakes.HTTPRequest.blank('/v2/fake/images/1')
|
||||
generated_url = view._get_alternate_link(request, 1)
|
||||
actual_url = "%s/fake/images/1" % utils.generate_glance_url()
|
||||
actual_url = "%s/fake/images/1" % glance.generate_glance_url()
|
||||
self.assertEqual(generated_url, actual_url)
|
||||
|
||||
def test_delete_image(self):
|
||||
|
|
|
@ -41,6 +41,7 @@ from nova.compute import vm_states
|
|||
from nova import context
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova.image import glance
|
||||
from nova.network import api as network_api
|
||||
from nova.network import model as network_model
|
||||
from nova.openstack.common import cfg
|
||||
|
@ -1455,7 +1456,7 @@ class ComputeTestCase(BaseTestCase):
|
|||
self.assertTrue('created_at' in payload)
|
||||
self.assertTrue('launched_at' in payload)
|
||||
self.assertTrue(payload['launched_at'])
|
||||
image_ref_url = utils.generate_image_url(FAKE_IMAGE_REF)
|
||||
image_ref_url = glance.generate_image_url(FAKE_IMAGE_REF)
|
||||
self.assertEquals(payload['image_ref_url'], image_ref_url)
|
||||
self.compute.terminate_instance(self.context,
|
||||
instance=jsonutils.to_primitive(inst_ref))
|
||||
|
@ -1496,7 +1497,7 @@ class ComputeTestCase(BaseTestCase):
|
|||
self.assertTrue('launched_at' in payload)
|
||||
self.assertTrue('deleted_at' in payload)
|
||||
self.assertEqual(payload['deleted_at'], timeutils.strtime(cur_time))
|
||||
image_ref_url = utils.generate_image_url(FAKE_IMAGE_REF)
|
||||
image_ref_url = glance.generate_image_url(FAKE_IMAGE_REF)
|
||||
self.assertEquals(payload['image_ref_url'], image_ref_url)
|
||||
|
||||
def test_run_instance_existing(self):
|
||||
|
@ -1824,8 +1825,8 @@ class ComputeTestCase(BaseTestCase):
|
|||
|
||||
instance = db.instance_get_by_uuid(self.context, inst_ref['uuid'])
|
||||
|
||||
image_ref_url = utils.generate_image_url(image_ref)
|
||||
new_image_ref_url = utils.generate_image_url(new_image_ref)
|
||||
image_ref_url = glance.generate_image_url(image_ref)
|
||||
new_image_ref_url = glance.generate_image_url(new_image_ref)
|
||||
|
||||
self.assertEquals(len(test_notifier.NOTIFICATIONS), 3)
|
||||
msg = test_notifier.NOTIFICATIONS[0]
|
||||
|
@ -1904,7 +1905,7 @@ class ComputeTestCase(BaseTestCase):
|
|||
self.assertTrue('created_at' in payload)
|
||||
self.assertTrue('launched_at' in payload)
|
||||
self.assertEqual(payload['launched_at'], timeutils.strtime(cur_time))
|
||||
image_ref_url = utils.generate_image_url(FAKE_IMAGE_REF)
|
||||
image_ref_url = glance.generate_image_url(FAKE_IMAGE_REF)
|
||||
self.assertEquals(payload['image_ref_url'], image_ref_url)
|
||||
self.compute.terminate_instance(self.context,
|
||||
instance=jsonutils.to_primitive(new_instance))
|
||||
|
@ -1951,7 +1952,7 @@ class ComputeTestCase(BaseTestCase):
|
|||
self.assertTrue('display_name' in payload)
|
||||
self.assertTrue('created_at' in payload)
|
||||
self.assertTrue('launched_at' in payload)
|
||||
image_ref_url = utils.generate_image_url(FAKE_IMAGE_REF)
|
||||
image_ref_url = glance.generate_image_url(FAKE_IMAGE_REF)
|
||||
self.assertEquals(payload['image_ref_url'], image_ref_url)
|
||||
self.compute.terminate_instance(self.context, instance=new_instance)
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ from nova.compute import utils as compute_utils
|
|||
from nova import context
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova.image import glance
|
||||
from nova.network import api as network_api
|
||||
from nova.openstack.common import cfg
|
||||
from nova.openstack.common import importutils
|
||||
|
@ -33,7 +34,6 @@ from nova.openstack.common.notifier import test_notifier
|
|||
from nova import test
|
||||
from nova.tests import fake_network
|
||||
import nova.tests.image.fake
|
||||
from nova import utils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
CONF = cfg.CONF
|
||||
|
@ -281,7 +281,7 @@ class UsageInfoTestCase(test.TestCase):
|
|||
msg="Key %s not in payload" % attr)
|
||||
self.assertEquals(payload['image_meta'],
|
||||
{'md_key1': 'val1', 'md_key2': 'val2'})
|
||||
image_ref_url = "%s/images/1" % utils.generate_glance_url()
|
||||
image_ref_url = "%s/images/1" % glance.generate_glance_url()
|
||||
self.assertEquals(payload['image_ref_url'], image_ref_url)
|
||||
self.compute.terminate_instance(self.context, instance)
|
||||
|
||||
|
@ -317,7 +317,7 @@ class UsageInfoTestCase(test.TestCase):
|
|||
msg="Key %s not in payload" % attr)
|
||||
self.assertEquals(payload['image_meta'],
|
||||
{'md_key1': 'val1', 'md_key2': 'val2'})
|
||||
image_ref_url = "%s/images/1" % utils.generate_glance_url()
|
||||
image_ref_url = "%s/images/1" % glance.generate_glance_url()
|
||||
self.assertEquals(payload['image_ref_url'], image_ref_url)
|
||||
|
||||
def test_notify_usage_exists_instance_not_found(self):
|
||||
|
@ -343,7 +343,7 @@ class UsageInfoTestCase(test.TestCase):
|
|||
self.assertTrue(attr in payload,
|
||||
msg="Key %s not in payload" % attr)
|
||||
self.assertEquals(payload['image_meta'], {})
|
||||
image_ref_url = "%s/images/1" % utils.generate_glance_url()
|
||||
image_ref_url = "%s/images/1" % glance.generate_glance_url()
|
||||
self.assertEquals(payload['image_ref_url'], image_ref_url)
|
||||
|
||||
def test_notify_about_instance_usage(self):
|
||||
|
@ -376,7 +376,7 @@ class UsageInfoTestCase(test.TestCase):
|
|||
self.assertEquals(payload['image_meta'],
|
||||
{'md_key1': 'val1', 'md_key2': 'val2'})
|
||||
self.assertEquals(payload['image_name'], 'fake_name')
|
||||
image_ref_url = "%s/images/1" % utils.generate_glance_url()
|
||||
image_ref_url = "%s/images/1" % glance.generate_glance_url()
|
||||
self.assertEquals(payload['image_ref_url'], image_ref_url)
|
||||
self.compute.terminate_instance(self.context, instance)
|
||||
|
||||
|
|
|
@ -25,11 +25,14 @@ import glanceclient.exc
|
|||
from nova import context
|
||||
from nova import exception
|
||||
from nova.image import glance
|
||||
from nova.openstack.common import cfg
|
||||
from nova import test
|
||||
from nova.tests.api.openstack import fakes
|
||||
from nova.tests.glance import stubs as glance_stubs
|
||||
from nova.tests import matchers
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
class NullWriter(object):
|
||||
"""Used to test ImageService.get which takes a writer object"""
|
||||
|
@ -703,3 +706,17 @@ class TestGlanceClientWrapper(test.TestCase):
|
|||
|
||||
client2.call(ctxt, 1, 'get', 'meow')
|
||||
self.assertEqual(info['num_calls'], 2)
|
||||
|
||||
|
||||
class TestGlanceUrl(test.TestCase):
|
||||
|
||||
def test_generate_glance_http_url(self):
|
||||
generated_url = glance.generate_glance_url()
|
||||
http_url = "http://%s:%d" % (CONF.glance_host, CONF.glance_port)
|
||||
self.assertEqual(generated_url, http_url)
|
||||
|
||||
def test_generate_glance_https_url(self):
|
||||
self.flags(glance_protocol="https")
|
||||
generated_url = glance.generate_glance_url()
|
||||
https_url = "https://%s:%d" % (CONF.glance_host, CONF.glance_port)
|
||||
self.assertEqual(generated_url, https_url)
|
||||
|
|
|
@ -26,16 +26,10 @@ import mox
|
|||
|
||||
import nova
|
||||
from nova import exception
|
||||
from nova.openstack.common import cfg
|
||||
from nova.openstack.common import timeutils
|
||||
from nova import test
|
||||
from nova import utils
|
||||
|
||||
CONF = cfg.CONF
|
||||
CONF.import_opt('glance_host', 'nova.config')
|
||||
CONF.import_opt('glance_port', 'nova.config')
|
||||
CONF.import_opt('glance_protocol', 'nova.config')
|
||||
|
||||
|
||||
class ByteConversionTest(test.TestCase):
|
||||
def test_string_conversions(self):
|
||||
|
@ -380,17 +374,6 @@ class GenericUtilsTestCase(test.TestCase):
|
|||
self.assertFalse(utils.bool_from_str(None))
|
||||
self.assertFalse(utils.bool_from_str('junk'))
|
||||
|
||||
def test_generate_glance_http_url(self):
|
||||
generated_url = utils.generate_glance_url()
|
||||
http_url = "http://%s:%d" % (CONF.glance_host, CONF.glance_port)
|
||||
self.assertEqual(generated_url, http_url)
|
||||
|
||||
def test_generate_glance_https_url(self):
|
||||
self.flags(glance_protocol="https")
|
||||
generated_url = utils.generate_glance_url()
|
||||
https_url = "https://%s:%d" % (CONF.glance_host, CONF.glance_port)
|
||||
self.assertEqual(generated_url, https_url)
|
||||
|
||||
def test_read_cached_file(self):
|
||||
self.mox.StubOutWithMock(os.path, "getmtime")
|
||||
os.path.getmtime(mox.IgnoreArg()).AndReturn(1)
|
||||
|
|
|
@ -80,9 +80,6 @@ utils_opts = [
|
|||
CONF = cfg.CONF
|
||||
CONF.register_opts(monkey_patch_opts)
|
||||
CONF.register_opts(utils_opts)
|
||||
CONF.import_opt('glance_host', 'nova.config')
|
||||
CONF.import_opt('glance_port', 'nova.config')
|
||||
CONF.import_opt('glance_protocol', 'nova.config')
|
||||
CONF.import_opt('service_down_time', 'nova.config')
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
@ -975,17 +972,6 @@ def timefunc(func):
|
|||
return inner
|
||||
|
||||
|
||||
def generate_glance_url():
|
||||
"""Generate the URL to glance."""
|
||||
return "%s://%s:%d" % (CONF.glance_protocol, CONF.glance_host,
|
||||
CONF.glance_port)
|
||||
|
||||
|
||||
def generate_image_url(image_ref):
|
||||
"""Generate an image URL from an image_ref."""
|
||||
return "%s/images/%s" % (generate_glance_url(), image_ref)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def remove_path_on_error(path):
|
||||
"""Protect code that wants to operate on PATH atomically.
|
||||
|
|
Loading…
Reference in New Issue