ipmitool drivers fail with integer passwords

ironic.drivers.modules.ipmitool gives "Failed to create the password file.
expected a character buffer object" WARNING message and it causes "Error:
IPMI call failed: power status..". "expected a character buffer object" is
a python error message and raised when write() function expected string as
input type  but gets something else (i.e. int / numeric) if ipmi password
is set just using numbers(i.e 12345678)

This simple bug fix solves the issue by casting "password" to string.

Change-Id: Id9645e06eb707ef21a7cb99c420309f54a95aa9b
Closes-Bug: 1416298
This commit is contained in:
Erhan Ekici 2015-02-04 00:32:10 +02:00 committed by Ramakrishnan G
parent c14e3dc46e
commit 32437956cc
2 changed files with 11 additions and 4 deletions

View File

@ -187,7 +187,7 @@ def _make_password_file(password):
fd, path = tempfile.mkstemp()
os.fchmod(fd, stat.S_IRUSR | stat.S_IWUSR)
with os.fdopen(fd, "w") as f:
f.write(password)
f.write(str(password))
yield path
utils.delete_if_exists(path)

View File

@ -16,6 +16,7 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
"""Test class for IPMITool driver module."""
@ -221,16 +222,22 @@ class IPMIToolPrivateMethodTestCase(db_base.DbTestCase):
driver_info=INFO_DICT)
self.info = ipmi._parse_driver_info(self.node)
def test__make_password_file(self, mock_sleep):
with ipmi._make_password_file(self.info.get('password')) as pw_file:
def _test__make_password_file(self, mock_sleep, input_password):
with ipmi._make_password_file(input_password) as pw_file:
del_chk_pw_file = pw_file
self.assertTrue(os.path.isfile(pw_file))
self.assertEqual(0o600, os.stat(pw_file)[stat.ST_MODE] & 0o777)
with open(pw_file, "r") as f:
password = f.read()
self.assertEqual(self.info.get('password'), password)
self.assertEqual(str(input_password), password)
self.assertFalse(os.path.isfile(del_chk_pw_file))
def test__make_password_file_str_password(self, mock_sleep):
self._test__make_password_file(mock_sleep, self.info.get('password'))
def test__make_password_file_with_numeric_password(self, mock_sleep):
self._test__make_password_file(mock_sleep, 12345)
def test__parse_driver_info(self, mock_sleep):
# make sure we get back the expected things
_OPTIONS = ['address', 'username', 'password', 'uuid']