def _get_post_map_lb_subflow(self, prefix, role): """Set amphora type after mapped to lb.""" sf_name = prefix + '-' + constants.POST_MAP_AMP_TO_LB_SUBFLOW post_map_amp_to_lb = linear_flow.Flow(sf_name) post_map_amp_to_lb.add( database_tasks.ReloadAmphora(name=sf_name + '-' + constants.RELOAD_AMPHORA, requires=constants.AMPHORA_ID, provides=constants.AMPHORA)) post_map_amp_to_lb.add( amphora_driver_tasks.AmphoraConfigUpdate( name=sf_name + '-' + constants.AMPHORA_CONFIG_UPDATE_TASK, requires=(constants.AMPHORA, constants.FLAVOR))) if role == constants.ROLE_MASTER: post_map_amp_to_lb.add( database_tasks.MarkAmphoraMasterInDB( name=sf_name + '-' + constants.MARK_AMP_MASTER_INDB, requires=constants.AMPHORA)) elif role == constants.ROLE_BACKUP: post_map_amp_to_lb.add( database_tasks.MarkAmphoraBackupInDB( name=sf_name + '-' + constants.MARK_AMP_BACKUP_INDB, requires=constants.AMPHORA)) elif role == constants.ROLE_STANDALONE: post_map_amp_to_lb.add( database_tasks.MarkAmphoraStandAloneInDB( name=sf_name + '-' + constants.MARK_AMP_STANDALONE_INDB, requires=constants.AMPHORA)) return post_map_amp_to_lb
def update_amphora_config_flow(self): """Creates a flow to update the amphora agent configuration. :returns: The flow for updating an amphora """ update_amphora_flow = linear_flow.Flow( constants.UPDATE_AMPHORA_CONFIG_FLOW) update_amphora_flow.add(lifecycle_tasks.AmphoraToErrorOnRevertTask( requires=constants.AMPHORA)) update_amphora_flow.add(amphora_driver_tasks.AmphoraConfigUpdate( requires=(constants.AMPHORA, constants.FLAVOR))) return update_amphora_flow
def test_amphora_config_update(self, mock_build_config, mock_driver, mock_generate_uuid, mock_log, mock_get_session, mock_listener_repo_get, mock_listener_repo_update, mock_amphora_repo_update): mock_build_config.return_value = FAKE_CONFIG_FILE amp_config_update_obj = amphora_driver_tasks.AmphoraConfigUpdate() mock_driver.update_amphora_agent_config.side_effect = [ None, None, driver_except.AmpDriverNotImplementedError, driver_except.TimeOutException] # With Flavor flavor = {constants.LOADBALANCER_TOPOLOGY: constants.TOPOLOGY_ACTIVE_STANDBY} amp_config_update_obj.execute(_amphora_mock, flavor) mock_build_config.assert_called_once_with( _amphora_mock.id, constants.TOPOLOGY_ACTIVE_STANDBY) mock_driver.update_amphora_agent_config.assert_called_once_with( _amphora_mock, FAKE_CONFIG_FILE) # With no Flavor mock_driver.reset_mock() mock_build_config.reset_mock() amp_config_update_obj.execute(_amphora_mock, None) mock_build_config.assert_called_once_with( _amphora_mock.id, constants.TOPOLOGY_SINGLE) mock_driver.update_amphora_agent_config.assert_called_once_with( _amphora_mock, FAKE_CONFIG_FILE) # With amphora that does not support config update mock_driver.reset_mock() mock_build_config.reset_mock() amp_config_update_obj.execute(_amphora_mock, flavor) mock_build_config.assert_called_once_with( _amphora_mock.id, constants.TOPOLOGY_ACTIVE_STANDBY) mock_driver.update_amphora_agent_config.assert_called_once_with( _amphora_mock, FAKE_CONFIG_FILE) # With an unknown exception mock_driver.reset_mock() mock_build_config.reset_mock() self.assertRaises(driver_except.TimeOutException, amp_config_update_obj.execute, _amphora_mock, flavor)