summaryrefslogtreecommitdiff
path: root/ironic/tests/unit
diff options
context:
space:
mode:
authorJulia Kreger <juliaashleykreger@gmail.com>2022-09-30 11:26:17 -0700
committerJulia Kreger <juliaashleykreger@gmail.com>2022-10-13 10:54:55 -0700
commit9344eb22d1462457fb5b521a19856f9a6cb1088e (patch)
tree9b4fee3e11708c7ef8c28c788b4740f96fd4f780 /ironic/tests/unit
parentcbaa871b255d81594fa35ac21c5ed391f0f47b74 (diff)
downloadironic-9344eb22d1462457fb5b521a19856f9a6cb1088e.tar.gz
Add upgrade check warning for allocations db
Adding an upgrade check to provide awareness to the state of the database in regards if an unexpected engine is in use or if the character set encoding is also not UTF8. These will raise non-fatal warnings on the upgrade status check. Change-Id: Ide0eb4690a056be557e5ea7d5ba5f6be37b50d0a Story: 2010384
Diffstat (limited to 'ironic/tests/unit')
-rw-r--r--ironic/tests/unit/cmd/test_status.py82
1 files changed, 82 insertions, 0 deletions
diff --git a/ironic/tests/unit/cmd/test_status.py b/ironic/tests/unit/cmd/test_status.py
index f776e2d51..2d044cc13 100644
--- a/ironic/tests/unit/cmd/test_status.py
+++ b/ironic/tests/unit/cmd/test_status.py
@@ -14,6 +14,7 @@
from unittest import mock
+from oslo_db import sqlalchemy
from oslo_upgradecheck.upgradecheck import Code
from ironic.cmd import dbsync
@@ -38,3 +39,84 @@ class TestUpgradeChecks(db_base.DbTestCase):
check_result = self.cmd._check_obj_versions()
self.assertEqual(Code.FAILURE, check_result.code)
self.assertEqual(msg, check_result.details)
+
+ def test__check_allocations_table_ok(self):
+ check_result = self.cmd._check_allocations_table()
+ self.assertEqual(Code.SUCCESS,
+ check_result.code)
+
+ @mock.patch.object(sqlalchemy.enginefacade.reader,
+ 'get_engine', autospec=True)
+ def test__check_allocations_table_latin1(self, mock_reader):
+ mock_engine = mock.Mock()
+ mock_res = mock.Mock()
+ mock_res.all.return_value = (
+ '... ENGINE=InnoDB DEFAULT CHARSET=latin1',
+ )
+ mock_engine.url = '..mysql..'
+ mock_engine.execute.return_value = mock_res
+ mock_reader.return_value = mock_engine
+ check_result = self.cmd._check_allocations_table()
+ self.assertEqual(Code.WARNING,
+ check_result.code)
+ expected_msg = ('The Allocations table is is not using UTF8 '
+ 'encoding. This is corrected in later versions '
+ 'of Ironic, where the table character set schema '
+ 'is automatically migrated. Continued use of a '
+ 'non-UTF8 character set may produce unexpected '
+ 'results.')
+ self.assertEqual(expected_msg, check_result.details)
+
+ @mock.patch.object(sqlalchemy.enginefacade.reader,
+ 'get_engine', autospec=True)
+ def test__check_allocations_table_myiasm(self, mock_reader):
+ mock_engine = mock.Mock()
+ mock_res = mock.Mock()
+ mock_engine.url = '..mysql..'
+ mock_res.all.return_value = (
+ '... ENGINE=MyIASM DEFAULT CHARSET=utf8',
+ )
+ mock_engine.execute.return_value = mock_res
+ mock_reader.return_value = mock_engine
+ check_result = self.cmd._check_allocations_table()
+ self.assertEqual(Code.WARNING,
+ check_result.code)
+ expected_msg = ('The engine used by MySQL for the allocations '
+ 'table is not the intended engine for the Ironic '
+ 'database tables to use. This may have been a '
+ 'result of an error with the table creation schema. '
+ 'This may require Database Administrator '
+ 'intervention and downtime to dump, modify the '
+ 'table engine to utilize InnoDB, and reload the '
+ 'allocations table to utilize the InnoDB engine.')
+ self.assertEqual(expected_msg, check_result.details)
+
+ @mock.patch.object(sqlalchemy.enginefacade.reader,
+ 'get_engine', autospec=True)
+ def test__check_allocations_table_myiasm_both(self, mock_reader):
+ mock_engine = mock.Mock()
+ mock_res = mock.Mock()
+ mock_engine.url = '..mysql..'
+ mock_res.all.return_value = (
+ '... ENGINE=MyIASM DEFAULT CHARSET=latin1',
+ )
+ mock_engine.execute.return_value = mock_res
+ mock_reader.return_value = mock_engine
+ check_result = self.cmd._check_allocations_table()
+ self.assertEqual(Code.WARNING,
+ check_result.code)
+ expected_msg = ('The Allocations table is is not using UTF8 '
+ 'encoding. This is corrected in later versions '
+ 'of Ironic, where the table character set schema '
+ 'is automatically migrated. Continued use of a '
+ 'non-UTF8 character set may produce unexpected '
+ 'results. Additionally: '
+ 'The engine used by MySQL for the allocations '
+ 'table is not the intended engine for the Ironic '
+ 'database tables to use. This may have been a '
+ 'result of an error with the table creation schema. '
+ 'This may require Database Administrator '
+ 'intervention and downtime to dump, modify the '
+ 'table engine to utilize InnoDB, and reload the '
+ 'allocations table to utilize the InnoDB engine.')
+ self.assertEqual(expected_msg, check_result.details)