Skip to content

Commit

Permalink
Adds decision logic for action result code.
Browse files Browse the repository at this point in the history
Signed-off-by: Utkarsh Bhatt <[email protected]>
  • Loading branch information
UtkarshBhatthere committed Apr 15, 2024
1 parent b0d0012 commit 471811a
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions zaza/openstack/charm_tests/ceph/rbd_mirror/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,18 @@ def setup_rbd_mirror():
)


def get_action_result(result: dict) -> str:
"""Get action result code."""
if result.get('Code', None):
return result['Code']
elif result.get('return-code', None):
return result['return-code']
else:
# default for non-zero return code.
logging.error("No suitable return code found in action result.")
return "-1"


class CephRBDMirrorBase(test_utils.BaseCharmTest):
"""Base class for ``ceph-rbd-mirror`` tests."""

Expand Down Expand Up @@ -503,7 +515,7 @@ def execute_failover_juju_actions(self,
'pools': ','.join(primary_site_pools)
})
logging.info(result.results)
self.assertEqual(int(result.results['Code']), 0)
self.assertEqual(int(get_action_result(result.results)), 0)

# Validate that the demoted pools count matches the total primary site
# pools count.
Expand Down Expand Up @@ -537,7 +549,7 @@ def execute_failover_juju_actions(self,
'pools': ','.join(secondary_site_pools)
})
logging.info(result.results)
self.assertEqual(int(result.results['Code']), 0)
self.assertEqual(int(get_action_result(result.results)), 0)

# Validate that the promoted pools count matches the total secondary
# site pools count.
Expand Down Expand Up @@ -711,7 +723,7 @@ def test_203_juju_resync(self):
'i-really-mean-it': True,
})
logging.info(result.results)
self.assertEqual(int(result.results['Code']), 0)
self.assertEqual(int(get_action_result(result.results)), 0)

# Validate that the Ceph images from site-b report 'up+replaying'
# (which is reported by secondary Ceph images). And check that images
Expand Down Expand Up @@ -801,7 +813,7 @@ def test_100_forced_juju_failover(self):
action_params={
'pools': ','.join(site_b_pools),
})
self.assertEqual(int(result.results['Code']), 0)
self.assertEqual(int(get_action_result(result.results)), 0)

# The action may not show up as 'failed' if there are no pools that
# needed to be promoted.
Expand All @@ -816,7 +828,7 @@ def test_100_forced_juju_failover(self):
'force': True,
'pools': ','.join(site_b_pools),
})
self.assertEqual(int(result.results['Code']), 0)
self.assertEqual(int(get_action_result(result.results)), 0)

# Validate successful Juju action execution
self.assertEqual(result.status, 'completed')
Expand Down

0 comments on commit 471811a

Please sign in to comment.