Fix alarm-definition-list in Python 3
Python 3 uses unicode strings by default. This bug was caused by attempting to join a byte string to a unicode string when running with the Python 3 interpreter. A unit test was added to reproduce the problem. Whilst this fix allows alarm definitions to be listed, it doesn't fix the formatting problem in Python 3. A better fix may be to return unicode strings in Python 3 as part of a wider code audit. Story: 2004972 Task: 29427 Change-Id: Ib008ed2aacd93f499b15094cf5a7e1bb0bb50a1f
This commit is contained in:
parent
0b14b4d492
commit
59e2a9bd2f
@ -198,4 +198,4 @@ def format_list(in_list):
|
|||||||
else:
|
else:
|
||||||
key = k
|
key = k
|
||||||
string_list.append(key)
|
string_list.append(key)
|
||||||
return '\n'.join(string_list)
|
return b'\n'.join(string_list)
|
||||||
|
@ -71,6 +71,37 @@ class TestAlarmDefinitionShellV2(base.BaseTestCase):
|
|||||||
undetermined_actions=[ad_action_id]
|
undetermined_actions=[ad_action_id]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@mock.patch('monascaclient.osc.migration.make_client')
|
||||||
|
def test_alarm_definitions_list(self, mc):
|
||||||
|
mc.return_value = c = FakeV2Client()
|
||||||
|
|
||||||
|
c.alarm_definitions.list.return_value = [{
|
||||||
|
"name": "ntp_sync_check",
|
||||||
|
"id": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
|
||||||
|
"expression": "(max(ntp.offset{}, deterministic)>=1)",
|
||||||
|
"match_by": ['hostname'],
|
||||||
|
"description": "NTP time sync check",
|
||||||
|
"actions_enabled": True,
|
||||||
|
"deterministic": True,
|
||||||
|
"alarm_actions": ['aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'],
|
||||||
|
"ok_actions": [],
|
||||||
|
"undetermined_actions": [],
|
||||||
|
"severity": "HIGH",
|
||||||
|
}]
|
||||||
|
|
||||||
|
name, cmd_class = migr.create_command_class(
|
||||||
|
'do_alarm_definition_list',
|
||||||
|
shell
|
||||||
|
)
|
||||||
|
cmd = cmd_class(mock.Mock(), mock.Mock())
|
||||||
|
|
||||||
|
parser = cmd.get_parser(name)
|
||||||
|
raw_args = []
|
||||||
|
parsed_args = parser.parse_args(raw_args)
|
||||||
|
cmd.run(parsed_args)
|
||||||
|
|
||||||
|
c.alarm_definitions.list.assert_called_once()
|
||||||
|
|
||||||
@mock.patch('monascaclient.osc.migration.make_client')
|
@mock.patch('monascaclient.osc.migration.make_client')
|
||||||
def test_should_patch_name(self, mc):
|
def test_should_patch_name(self, mc):
|
||||||
ad_id = '0495340b-58fd-4e1c-932b-5e6f9cc96490'
|
ad_id = '0495340b-58fd-4e1c-932b-5e6f9cc96490'
|
||||||
|
Loading…
Reference in New Issue
Block a user