#!/bin/bash
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

#
# This script is executed in the OpenStack CI job that runs DevStack + tempest.
# You can find the CI job configuration here:
#
# https://opendev.org/openstack/project-config/src/branch/master/grafana/networking-odl.yaml
#

# TODO(mkolesni): Remove in case we need more timeout.
# Currently timeout is too big causing the gate job to timeout entirely and
# not collect almost any logs, making it hard to debug.
export DEVSTACK_LOCAL_CONFIG+=$'\n'"BUILD_TIMEOUT=60"

CINDER_SERVICES=c-api,c-bak,c-sch,c-vol,cinder
COMMON_SERVICES=dstat,g-api,g-reg,key,mysql,n-api,n-cond,n-cpu,n-crt,n-obj,n-sch,rabbit,placement-api,n-api-meta
NEUTRON_NEW=neutron-dhcp,neutron-metadata-agent,neutron-api,neutron
# This variable is not being used, it will be removed once migration is complete
NEUTRON_LEGACY=q-dhcp,q-meta,q-svc,quantum

if [[ "$IS_GRENADE_JOB" == "True"  ]]; then
    # TODO(rajivk): workaround, Remove this once, grenade has moved to lib/neutron
    # from legacy. Currently, it checks service with q-*, so it does not detect new
    # neutron-*. Therefore neutron does not get registered for upgrade, if we
    # override and register neutron from networking-odl because it will look for
    # required files available with neutron only. For now, lib/neutron-legacy to
    # lib/neutron is not done for grenade jobs.
    ALL_ENABLED_SERVICES=${COMMON_SERVICES},${NEUTRON_LEGACY}
else
    ALL_ENABLED_SERVICES=${CINDER_SERVICES},${COMMON_SERVICES},${NEUTRON_NEW}
fi

export OVERRIDE_ENABLED_SERVICES=${ALL_ENABLED_SERVICES}
if [ -z "${RALLY_SCENARIO}" ] ; then
    # Only include tempest if this is not a rally job, As running tempest in Rally is likely to cause failure
    export OVERRIDE_ENABLED_SERVICES=${OVERRIDE_ENABLED_SERVICES},tempest
fi

# NOTE(manjeets) To prevent create of public network twice
if [[ "$DEVSTACK_GATE_TOPOLOGY" == "multinode" ]] ; then

    # NOTE(manjeets) Temporarily disabling LM test due to bug 1643678
    # https://bugs.launchpad.net/networking-odl/+bug/1643678
    export DEVSTACK_LOCAL_CONFIG+=$'\n'"LIVE_MIGRATION_AVAILABLE=False"
    export DEVSTACK_LOCAL_CONFIG+=$'\n'"USE_BLOCK_MIGRATION_FOR_LIVE_MIGRATION=False"
    # DEVSTACK_GATE_NEUTRON_DVR in devstack-gate set Q_DVR_MODE as dvr_snat
    export DEVSTACK_LOCAL_CONFIG+=$'\n'"Q_DVR_MODE=legacy"
    export DEVSTACK_SUBNODE_CONFIG+=$'\n'"Q_DVR_MODE=legacy"

    export DEVSTACK_SUBNODE_CONFIG+=$'\n'"disable_all_services"
    export DEVSTACK_SUBNODE_CONFIG+=$'\n'"ENABLED_SERVICES=n-cpu,dstat,c-vol,c-bak,mysql,placement-client"
    export DEVSTACK_SUBNODE_CONFIG+=$'\n'"RABBIT_HOST=\$SERVICE_HOST"
    export DEVSTACK_SUBNODE_CONFIG+=$'\n'"ODL_MODE=compute"
    export DEVSTACK_SUBNODE_CONFIG+=$'\n'"LIBVIRT_TYPE=qemu"
fi
