Merge "Remove auth token saving from iLO driver"
This commit is contained in:
commit
27897005dc
@ -30,7 +30,6 @@ from ironic.common.i18n import _LE
|
||||
from ironic.common.i18n import _LI
|
||||
from ironic.common import images
|
||||
from ironic.common import swift
|
||||
from ironic.common import utils
|
||||
from ironic.drivers.modules import deploy_utils
|
||||
|
||||
ilo_client = importutils.try_import('proliantutils.ilo.client')
|
||||
@ -227,11 +226,11 @@ def _prepare_floppy_image(task, params):
|
||||
"""Prepares the floppy image for passing the parameters.
|
||||
|
||||
This method prepares a temporary vfat filesystem image. Then it adds
|
||||
two files into the image - one containing the authentication token and
|
||||
the other containing the parameters to be passed to the ramdisk. Then it
|
||||
uploads the file to Swift in 'swift_ilo_container', setting it to
|
||||
auto-expire after 'swift_object_expiry_timeout' seconds. Then it returns
|
||||
the temp url for the Swift object.
|
||||
a file into the image which contains the parameters to be passed to
|
||||
the ramdisk. After adding the parameters, it then uploads the file to Swift
|
||||
in 'swift_ilo_container', setting it to auto-expire after
|
||||
'swift_object_expiry_timeout' seconds. Then it returns the temp url for the
|
||||
Swift object.
|
||||
|
||||
:param task: a TaskManager instance containing the node to act on.
|
||||
:param params: a dictionary containing 'parameter name'->'value' mapping
|
||||
@ -243,20 +242,7 @@ def _prepare_floppy_image(task, params):
|
||||
with tempfile.NamedTemporaryFile() as vfat_image_tmpfile_obj:
|
||||
|
||||
vfat_image_tmpfile = vfat_image_tmpfile_obj.name
|
||||
|
||||
# If auth_strategy is noauth, then no need to write token into
|
||||
# the image file.
|
||||
if task.context.auth_token:
|
||||
with tempfile.NamedTemporaryFile() as token_tmpfile_obj:
|
||||
files_info = {}
|
||||
token_tmpfile = token_tmpfile_obj.name
|
||||
utils.write_to_file(token_tmpfile, task.context.auth_token)
|
||||
files_info[token_tmpfile] = 'token'
|
||||
images.create_vfat_image(vfat_image_tmpfile,
|
||||
files_info=files_info,
|
||||
parameters=params)
|
||||
else:
|
||||
images.create_vfat_image(vfat_image_tmpfile, parameters=params)
|
||||
images.create_vfat_image(vfat_image_tmpfile, parameters=params)
|
||||
|
||||
container = CONF.ilo.swift_ilo_container
|
||||
object_name = _get_floppy_image_name(task.node)
|
||||
|
@ -25,7 +25,6 @@ import six
|
||||
from ironic.common import exception
|
||||
from ironic.common import images
|
||||
from ironic.common import swift
|
||||
from ironic.common import utils
|
||||
from ironic.conductor import task_manager
|
||||
from ironic.drivers.modules.ilo import common as ilo_common
|
||||
from ironic.tests.conductor import utils as mgr_utils
|
||||
@ -181,24 +180,16 @@ class IloCommonMethodsTestCase(db_base.DbTestCase):
|
||||
@mock.patch.object(swift, 'SwiftAPI', spec_set=True, autospec=True)
|
||||
@mock.patch.object(images, 'create_vfat_image', spec_set=True,
|
||||
autospec=True)
|
||||
@mock.patch.object(utils, 'write_to_file', spec_set=True,
|
||||
autospec=True)
|
||||
@mock.patch.object(tempfile, 'NamedTemporaryFile', spec_set=True,
|
||||
autospec=True)
|
||||
def test__prepare_floppy_image(self, tempfile_mock, write_mock,
|
||||
fatimage_mock, swift_api_mock):
|
||||
mock_token_file_handle = mock.MagicMock(spec=file)
|
||||
mock_token_file_obj = mock.MagicMock(spec=file)
|
||||
mock_token_file_obj.name = 'token-tmp-file'
|
||||
mock_token_file_handle.__enter__.return_value = mock_token_file_obj
|
||||
|
||||
def test__prepare_floppy_image(self, tempfile_mock, fatimage_mock,
|
||||
swift_api_mock):
|
||||
mock_image_file_handle = mock.MagicMock(spec=file)
|
||||
mock_image_file_obj = mock.MagicMock(spec=file)
|
||||
mock_image_file_obj.name = 'image-tmp-file'
|
||||
mock_image_file_handle.__enter__.return_value = mock_image_file_obj
|
||||
|
||||
tempfile_mock.side_effect = iter([mock_image_file_handle,
|
||||
mock_token_file_handle])
|
||||
tempfile_mock.return_value = mock_image_file_handle
|
||||
|
||||
swift_obj_mock = swift_api_mock.return_value
|
||||
self.config(swift_ilo_container='ilo_cont', group='ilo')
|
||||
@ -210,16 +201,11 @@ class IloCommonMethodsTestCase(db_base.DbTestCase):
|
||||
|
||||
with task_manager.acquire(self.context, self.node.uuid,
|
||||
shared=False) as task:
|
||||
|
||||
task.context.auth_token = 'token'
|
||||
temp_url = ilo_common._prepare_floppy_image(task, deploy_args)
|
||||
node_uuid = task.node.uuid
|
||||
|
||||
object_name = 'image-' + node_uuid
|
||||
files_info = {'token-tmp-file': 'token'}
|
||||
write_mock.assert_called_once_with('token-tmp-file', 'token')
|
||||
fatimage_mock.assert_called_once_with('image-tmp-file',
|
||||
files_info=files_info,
|
||||
parameters=deploy_args)
|
||||
|
||||
swift_obj_mock.create_object.assert_called_once_with(
|
||||
@ -229,34 +215,6 @@ class IloCommonMethodsTestCase(db_base.DbTestCase):
|
||||
'ilo_cont', object_name, timeout)
|
||||
self.assertEqual('temp-url', temp_url)
|
||||
|
||||
@mock.patch.object(swift, 'SwiftAPI', spec_set=True, autospec=True)
|
||||
@mock.patch.object(images, 'create_vfat_image', spec_set=True,
|
||||
autospec=True)
|
||||
@mock.patch.object(tempfile, 'NamedTemporaryFile', spec_set=True,
|
||||
autospec=True)
|
||||
def test__prepare_floppy_image_noauth(self, tempfile_mock, fatimage_mock,
|
||||
swift_api_mock):
|
||||
mock_token_file_obj = mock.MagicMock(spec=file)
|
||||
mock_token_file_obj.name = 'token-tmp-file'
|
||||
mock_image_file_handle = mock.MagicMock(spec=file)
|
||||
mock_image_file_obj = mock.MagicMock(spec=file)
|
||||
mock_image_file_obj.name = 'image-tmp-file'
|
||||
mock_image_file_handle.__enter__.return_value = mock_image_file_obj
|
||||
tempfile_mock.side_effect = iter([mock_image_file_handle])
|
||||
|
||||
self.config(swift_ilo_container='ilo_cont', group='ilo')
|
||||
self.config(swift_object_expiry_timeout=1, group='ilo')
|
||||
deploy_args = {'arg1': 'val1', 'arg2': 'val2'}
|
||||
|
||||
with task_manager.acquire(self.context, self.node.uuid,
|
||||
shared=False) as task:
|
||||
|
||||
task.context.auth_token = None
|
||||
ilo_common._prepare_floppy_image(task, deploy_args)
|
||||
|
||||
fatimage_mock.assert_called_once_with('image-tmp-file',
|
||||
parameters=deploy_args)
|
||||
|
||||
@mock.patch.object(ilo_common, 'get_ilo_object', spec_set=True,
|
||||
autospec=True)
|
||||
def test_attach_vmedia(self, get_ilo_object_mock):
|
||||
|
Loading…
Reference in New Issue
Block a user