Failover logic doesn't handle anti-affinity

During anti affinity failover the server-group wasn't stored
in the flow. This will rectify that.

To test: Load this patch on top of new soft-anti-affinity patch,
set to ACTIVE-PASSIVE, perform failover, see newly created server
belongs to same server-group.

Change-Id: I620c42101fd2362156b15f7f2390c2a72a04c566
Closes-Bug: 1677379
This commit is contained in:
German Eichberger 2017-03-31 10:04:17 -04:00
parent afd6c2b874
commit 1069b1732f
2 changed files with 58 additions and 7 deletions

View File

@ -622,15 +622,25 @@ class ControllerWorker(base_taskflow.BaseTaskFlowEngine):
try:
amp = self._amphora_repo.get(db_apis.get_session(),
id=amphora_id)
stored_params = {constants.FAILED_AMPHORA: amp,
constants.LOADBALANCER_ID: amp.load_balancer_id,
constants.BUILD_TYPE_PRIORITY:
constants.LB_CREATE_FAILOVER_PRIORITY}
# if we run with anti-affinity we need to set the server group
# as well
if CONF.nova.enable_anti_affinity:
lb = self._amphora_repo.get_all_lbs_on_amphora(
db_apis.get_session(), amp.id)
if lb:
stored_params[constants.SERVER_GROUP_ID] = (
lb[0].server_group_id)
failover_amphora_tf = self._taskflow_load(
self._amphora_flows.get_failover_flow(role=amp.role,
status=amp.status),
store={constants.FAILED_AMPHORA: amp,
constants.LOADBALANCER_ID: amp.load_balancer_id,
constants.BUILD_TYPE_PRIORITY:
constants.LB_CREATE_FAILOVER_PRIORITY
})
self._amphora_flows.get_failover_flow(
role=amp.role,
status=amp.status),
store=stored_params)
with tf_logging.DynamicLoggingListener(
failover_amphora_tf, log=LOG,
hide_inputs_outputs_of=self._exclude_result_logging_tasks):

View File

@ -1095,6 +1095,47 @@ class TestControllerWorker(base.TestCase):
_flow_mock.run.assert_called_once_with()
@mock.patch('octavia.controller.worker.flows.'
'amphora_flows.AmphoraFlows.get_failover_flow',
return_value=_flow_mock)
@mock.patch(
'octavia.db.repositories.AmphoraRepository.get_all_lbs_on_amphora',
return_value=[_load_balancer_mock])
def test_failover_amphora_anti_affinity(self,
mock_get_update_listener_flow,
mock_get_all_lbs_for_amp_mock,
mock_api_get_session,
mock_dyn_log_listener,
mock_taskflow_load,
mock_pool_repo_get,
mock_member_repo_get,
mock_l7rule_repo_get,
mock_l7policy_repo_get,
mock_listener_repo_get,
mock_lb_repo_get,
mock_health_mon_repo_get,
mock_amp_repo_get):
self.conf.config(group="nova", enable_anti_affinity=True)
_flow_mock.reset_mock()
_load_balancer_mock.server_group_id = "123"
cw = controller_worker.ControllerWorker()
cw.failover_amphora(AMP_ID)
(base_taskflow.BaseTaskFlowEngine._taskflow_load.
assert_called_once_with(
_flow_mock,
store={constants.FAILED_AMPHORA: _amphora_mock,
constants.LOADBALANCER_ID:
_amphora_mock.load_balancer_id,
constants.BUILD_TYPE_PRIORITY:
constants.LB_CREATE_FAILOVER_PRIORITY,
constants.SERVER_GROUP_ID: "123",
}))
_flow_mock.run.assert_called_once_with()
@mock.patch('octavia.controller.worker.flows.'
'amphora_flows.AmphoraFlows.cert_rotate_amphora_flow',
return_value=_flow_mock)