Adds fix for heat directory bug
This commit is contained in:
parent
0bfea3ce71
commit
530ae4d533
@ -38,14 +38,15 @@ class HeatPlugin(base.BaseUserDataPlugin):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(HeatPlugin, self).__init__("text/x-cfninitdata")
|
super(HeatPlugin, self).__init__("text/x-cfninitdata")
|
||||||
|
|
||||||
def _check_heat_config_dir(self):
|
def _check_dir(self, file_name):
|
||||||
if not os.path.exists(CONF.heat_config_dir):
|
dir_name = os.path.dirname(file_name)
|
||||||
os.makedirs(CONF.heat_config_dir)
|
if not os.path.exists(dir_name):
|
||||||
|
os.makedirs(dir_name)
|
||||||
|
|
||||||
def process(self, part):
|
def process(self, part):
|
||||||
self._check_heat_config_dir()
|
|
||||||
|
|
||||||
file_name = os.path.join(CONF.heat_config_dir, part.get_filename())
|
file_name = os.path.join(CONF.heat_config_dir, part.get_filename())
|
||||||
|
self._check_dir(file_name)
|
||||||
|
|
||||||
with open(file_name, 'wb') as f:
|
with open(file_name, 'wb') as f:
|
||||||
f.write(part.get_payload())
|
f.write(part.get_payload())
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
@ -31,25 +32,36 @@ class HeatUserDataHandlerTests(unittest.TestCase):
|
|||||||
|
|
||||||
@mock.patch('os.path.exists')
|
@mock.patch('os.path.exists')
|
||||||
@mock.patch('os.makedirs')
|
@mock.patch('os.makedirs')
|
||||||
def test_check_heat_config_dir(self, mock_makedirs, mock_exists):
|
@mock.patch('os.path.dirname')
|
||||||
|
def test_check_heat_config_dir(self, mock_dirname, mock_makedirs,
|
||||||
|
mock_exists):
|
||||||
mock_exists.return_value = False
|
mock_exists.return_value = False
|
||||||
self._heat._check_heat_config_dir()
|
fake_path = mock.sentinel.fake_path
|
||||||
mock_exists.assert_called_once_with(CONF.heat_config_dir)
|
fake_dir = mock.sentinel.fake_dir
|
||||||
mock_makedirs.assert_called_once_with(CONF.heat_config_dir)
|
mock_dirname.return_value = fake_dir
|
||||||
|
|
||||||
|
self._heat._check_dir(file_name=fake_path)
|
||||||
|
|
||||||
|
mock_dirname.assert_called_once_with(fake_path)
|
||||||
|
mock_exists.assert_called_once_with(fake_dir)
|
||||||
|
mock_makedirs.assert_called_once_with(fake_dir)
|
||||||
|
|
||||||
@mock.patch('cloudbaseinit.plugins.windows.userdatautils'
|
@mock.patch('cloudbaseinit.plugins.windows.userdatautils'
|
||||||
'.execute_user_data_script')
|
'.execute_user_data_script')
|
||||||
@mock.patch('cloudbaseinit.plugins.windows.userdataplugins.heat'
|
@mock.patch('cloudbaseinit.plugins.windows.userdataplugins.heat'
|
||||||
'.HeatPlugin._check_heat_config_dir')
|
'.HeatPlugin._check_dir')
|
||||||
def _test_process(self, mock_check_heat_config_dir,
|
def _test_process(self, mock_check_dir, mock_execute_user_data_script,
|
||||||
mock_execute_user_data_script, filename):
|
filename):
|
||||||
mock_part = mock.MagicMock()
|
mock_part = mock.MagicMock()
|
||||||
mock_part.get_filename.return_value = filename
|
mock_part.get_filename.return_value = filename
|
||||||
with mock.patch('six.moves.builtins.open', mock.mock_open(),
|
with mock.patch('six.moves.builtins.open', mock.mock_open(),
|
||||||
create=True) as handle:
|
create=True) as handle:
|
||||||
response = self._heat.process(mock_part)
|
response = self._heat.process(mock_part)
|
||||||
|
|
||||||
handle().write.assert_called_once_with(mock_part.get_payload())
|
handle().write.assert_called_once_with(mock_part.get_payload())
|
||||||
mock_check_heat_config_dir.assert_called_once_with()
|
|
||||||
|
path = os.path.join(CONF.heat_config_dir, filename)
|
||||||
|
mock_check_dir.assert_called_once_with(path)
|
||||||
mock_part.get_filename.assert_called_with()
|
mock_part.get_filename.assert_called_with()
|
||||||
if filename == self._heat._heat_user_data_filename:
|
if filename == self._heat._heat_user_data_filename:
|
||||||
mock_execute_user_data_script.assert_called_with(
|
mock_execute_user_data_script.assert_called_with(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user