Remove glance related utility methods
We don't have glance in the undercloud since victoria. Change-Id: I4ccf6beb687a90498787849edb030f59177ee8da
This commit is contained in:
parent
5a442aa0c4
commit
bcc74f59fc
|
@ -1,78 +0,0 @@
|
|||
# Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# 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.
|
||||
|
||||
import collections
|
||||
from unittest import mock
|
||||
|
||||
from glanceclient import exc as exceptions
|
||||
import testtools
|
||||
|
||||
from tripleo_common.tests import base
|
||||
from tripleo_common.utils import glance
|
||||
|
||||
|
||||
class GlanceTest(base.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(GlanceTest, self).setUp()
|
||||
self.image = collections.namedtuple('image', ['id'])
|
||||
|
||||
def test_return_existing_kernel_and_ramdisk(self):
|
||||
client = mock.MagicMock()
|
||||
expected = {'kernel': 'aaa', 'ramdisk': 'zzz'}
|
||||
client.images.find.side_effect = (self.image('aaa'), self.image('zzz'))
|
||||
ids = glance.create_or_find_kernel_and_ramdisk(client, 'bm-kernel',
|
||||
'bm-ramdisk')
|
||||
client.images.create.assert_not_called()
|
||||
self.assertEqual(expected, ids)
|
||||
|
||||
def test_raise_exception_kernel(self):
|
||||
client = mock.MagicMock()
|
||||
client.images.find.side_effect = exceptions.NotFound
|
||||
message = "Kernel image bm-kernel not found in Glance"
|
||||
with testtools.ExpectedException(ValueError, message):
|
||||
glance.create_or_find_kernel_and_ramdisk(client, 'bm-kernel',
|
||||
None)
|
||||
|
||||
def test_raise_exception_ramdisk(self):
|
||||
client = mock.MagicMock()
|
||||
client.images.find.side_effect = (self.image('aaa'),
|
||||
exceptions.NotFound)
|
||||
message = "Ramdisk image bm-ramdisk not found in Glance"
|
||||
with testtools.ExpectedException(ValueError, message):
|
||||
glance.create_or_find_kernel_and_ramdisk(client, 'bm-kernel',
|
||||
'bm-ramdisk')
|
||||
|
||||
def test_return_files(self):
|
||||
client = mock.MagicMock()
|
||||
expected = {'kernel': 'file:///kernel', 'ramdisk': 'file:///ramdisk'}
|
||||
ids = glance.create_or_find_kernel_and_ramdisk(
|
||||
None, 'file:///kernel', 'file:///ramdisk')
|
||||
client.images.assert_not_called()
|
||||
self.assertEqual(expected, ids)
|
||||
|
||||
def test_return_urls(self):
|
||||
client = mock.MagicMock()
|
||||
expected = {'kernel': 'http://kernel', 'ramdisk': 'http://ramdisk'}
|
||||
ids = glance.create_or_find_kernel_and_ramdisk(
|
||||
client, 'http://kernel', 'http://ramdisk')
|
||||
client.images.assert_not_called()
|
||||
self.assertEqual(expected, ids)
|
||||
|
||||
def test_return_https_urls_no_client(self):
|
||||
expected = {'kernel': 'https://kernel', 'ramdisk': 'https://ramdisk'}
|
||||
ids = glance.create_or_find_kernel_and_ramdisk(
|
||||
None, 'https://kernel', 'https://ramdisk')
|
||||
self.assertEqual(expected, ids)
|
|
@ -353,20 +353,12 @@ class NodesTest(base.TestCase):
|
|||
"cpu_arch": "amd64",
|
||||
"capabilities": "num_nics:6"}
|
||||
ironic = mock.MagicMock()
|
||||
glance = mock.MagicMock()
|
||||
image = collections.namedtuple('image', ['id'])
|
||||
glance.images.find.side_effect = (image('kernel-123'),
|
||||
image('ramdisk-999'))
|
||||
nodes.register_all_nodes(node_list, client=ironic,
|
||||
glance_client=glance, kernel_name='bm-kernel',
|
||||
kernel_name='bm-kernel',
|
||||
ramdisk_name='bm-ramdisk')
|
||||
pxe_node_driver_info = {"ipmi_address": "foo.bar",
|
||||
"ipmi_username": "test",
|
||||
"ipmi_password": "random",
|
||||
"deploy_kernel": "kernel-123",
|
||||
"deploy_ramdisk": "ramdisk-999",
|
||||
"rescue_kernel": "kernel-123",
|
||||
"rescue_ramdisk": "ramdisk-999"}
|
||||
"ipmi_password": "random"}
|
||||
pxe_node = mock.call(driver="ipmi",
|
||||
name='node1',
|
||||
driver_info=pxe_node_driver_info,
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
# Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# 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.
|
||||
|
||||
import re
|
||||
|
||||
from glanceclient import exc as exceptions
|
||||
from glanceclient.v2.client import Client as real_glance_client
|
||||
|
||||
|
||||
def create_or_find_kernel_and_ramdisk(glanceclient, kernel_name, ramdisk_name):
|
||||
"""Map kernel and ramdisk to file/HTTP path or Glance ID.
|
||||
|
||||
An exception will be raised if kernel_name or ramdisk_name is not a path
|
||||
and instead refers to a non-existent Glance image.
|
||||
|
||||
:param glanceclient: A client for Glance.
|
||||
:param kernel_name: Name to search for the kernel or path to kernel.
|
||||
:param ramdisk_name: Name to search for the ramdisk or path to ramdisk.
|
||||
|
||||
:returns: A dictionary mapping kernel or ramdisk to path or Glance ID.
|
||||
"""
|
||||
kernel_image = _check_image(glanceclient, kernel_name, disk_format='aki',
|
||||
image_type='Kernel')
|
||||
ramdisk_image = _check_image(glanceclient, ramdisk_name, disk_format='ari',
|
||||
image_type='Ramdisk')
|
||||
return {'kernel': kernel_image, 'ramdisk': ramdisk_image}
|
||||
|
||||
|
||||
def _check_image(glanceclient, name, disk_format, image_type):
|
||||
if re.match(r'^(file|https?)://', name):
|
||||
return name
|
||||
|
||||
try:
|
||||
if isinstance(glanceclient, real_glance_client):
|
||||
images = glanceclient.images.list(name=name,
|
||||
disk_format=disk_format)
|
||||
image = None
|
||||
for img in images:
|
||||
if ((img['name'] == name or img['id'] == name) and
|
||||
img['disk_format'] == disk_format):
|
||||
image = img
|
||||
break
|
||||
else:
|
||||
# TODO(dprince) remove this
|
||||
# This code expects the python-openstackclient version of
|
||||
# "glanceclient" (which isn't pure python-glanceclient) and is
|
||||
# here for backwards compat until python-tripleoclient starts
|
||||
# using the Mistral API for this functionality.
|
||||
image = glanceclient.images.find(name=name,
|
||||
disk_format=disk_format)
|
||||
except exceptions.NotFound:
|
||||
image = None
|
||||
|
||||
if image:
|
||||
return image.id
|
||||
raise ValueError("%s image %s not found in Glance" % (image_type,
|
||||
name))
|
|
@ -22,7 +22,6 @@ import six
|
|||
from ironicclient import exceptions as ironicexceptions
|
||||
from oslo_concurrency import processutils
|
||||
from tripleo_common import exception
|
||||
from tripleo_common.utils import glance
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
@ -550,18 +549,8 @@ def register_all_nodes(nodes_list, client, remove=False, glance_client=None,
|
|||
LOG.debug('Registering all nodes.')
|
||||
node_map = _populate_node_mapping(client)
|
||||
|
||||
glance_ids = {'kernel': None, 'ramdisk': None}
|
||||
if kernel_name and ramdisk_name:
|
||||
glance_ids = glance.create_or_find_kernel_and_ramdisk(
|
||||
glance_client, kernel_name, ramdisk_name)
|
||||
|
||||
seen = []
|
||||
for node in nodes_list:
|
||||
if glance_ids['kernel'] and 'kernel_id' not in node:
|
||||
node['kernel_id'] = glance_ids['kernel']
|
||||
if glance_ids['ramdisk'] and 'ramdisk_id' not in node:
|
||||
node['ramdisk_id'] = glance_ids['ramdisk']
|
||||
|
||||
node = _update_or_register_ironic_node(node, node_map, client=client)
|
||||
seen.append(node)
|
||||
|
||||
|
|
Loading…
Reference in New Issue