Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # lib/neutron |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 4 | # functions - functions specific to neutron |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 5 | |
| 6 | # Dependencies: |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 7 | # ``functions`` file |
| 8 | # ``DEST`` must be defined |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 9 | # ``STACK_USER`` must be defined |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 10 | |
| 11 | # ``stack.sh`` calls the entry points in this order: |
| 12 | # |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 13 | # - install_neutron_agent_packages |
| 14 | # - install_neutronclient |
| 15 | # - install_neutron |
| 16 | # - install_neutron_third_party |
| 17 | # - configure_neutron |
| 18 | # - init_neutron |
| 19 | # - configure_neutron_third_party |
| 20 | # - init_neutron_third_party |
| 21 | # - start_neutron_third_party |
| 22 | # - create_nova_conf_neutron |
| 23 | # - configure_neutron_after_post_config |
| 24 | # - start_neutron_service_and_check |
| 25 | # - check_neutron_third_party_integration |
| 26 | # - start_neutron_agents |
| 27 | # - create_neutron_initial_network |
| 28 | # |
| 29 | # ``unstack.sh`` calls the entry points in this order: |
| 30 | # |
| 31 | # - stop_neutron |
| 32 | # - stop_neutron_third_party |
| 33 | # - cleanup_neutron |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 34 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 35 | # Functions in lib/neutron are classified into the following categories: |
| 36 | # |
| 37 | # - entry points (called from stack.sh or unstack.sh) |
| 38 | # - internal functions |
| 39 | # - neutron exercises |
| 40 | # - 3rd party programs |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 41 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 42 | |
| 43 | # Neutron Networking |
| 44 | # ------------------ |
| 45 | |
| 46 | # Make sure that neutron is enabled in ``ENABLED_SERVICES``. If you want |
| 47 | # to run Neutron on this host, make sure that q-svc is also in |
| 48 | # ``ENABLED_SERVICES``. |
| 49 | # |
| 50 | # See "Neutron Network Configuration" below for additional variables |
| 51 | # that must be set in localrc for connectivity across hosts with |
| 52 | # Neutron. |
| 53 | |
| 54 | # Settings |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 55 | # -------- |
| 56 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 57 | |
| 58 | # Neutron Network Configuration |
| 59 | # ----------------------------- |
| 60 | |
| 61 | if is_service_enabled tls-proxy; then |
| 62 | Q_PROTOCOL="https" |
| 63 | fi |
| 64 | |
| 65 | |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 66 | # Set up default directories |
| 67 | GITDIR["python-neutronclient"]=$DEST/python-neutronclient |
| 68 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 69 | |
| 70 | NEUTRON_DIR=$DEST/neutron |
| 71 | NEUTRON_FWAAS_DIR=$DEST/neutron-fwaas |
| 72 | |
| 73 | # Support entry points installation of console scripts |
| 74 | if [[ -d $NEUTRON_DIR/bin/neutron-server ]]; then |
| 75 | NEUTRON_BIN_DIR=$NEUTRON_DIR/bin |
| 76 | else |
| 77 | NEUTRON_BIN_DIR=$(get_python_exec_prefix) |
| 78 | fi |
| 79 | |
| 80 | NEUTRON_CONF_DIR=/etc/neutron |
| 81 | NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf |
| 82 | export NEUTRON_TEST_CONFIG_FILE=${NEUTRON_TEST_CONFIG_FILE:-"$NEUTRON_CONF_DIR/debug.ini"} |
| 83 | |
Kevin Benton | 66b361b | 2017-06-13 00:31:01 -0700 | [diff] [blame] | 84 | # NEUTRON_DEPLOY_MOD_WSGI defines how neutron is deployed, allowed values: |
| 85 | # - False (default) : Run neutron under Eventlet |
| 86 | # - True : Run neutron under uwsgi |
| 87 | # TODO(annp): Switching to uwsgi in next cycle if things turn out to be stable |
| 88 | # enough |
Jens Harbott | 3492fee | 2018-11-30 13:57:17 +0000 | [diff] [blame] | 89 | NEUTRON_DEPLOY_MOD_WSGI=$(trueorfalse False NEUTRON_DEPLOY_MOD_WSGI) |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 90 | |
Stephen Finucane | 0cd8763 | 2024-04-19 12:12:16 +0100 | [diff] [blame] | 91 | NEUTRON_UWSGI=neutron.wsgi.api:application |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 92 | NEUTRON_UWSGI_CONF=$NEUTRON_CONF_DIR/neutron-api-uwsgi.ini |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 93 | |
Slawek Kaplonski | 24b65ad | 2021-06-22 15:31:46 +0200 | [diff] [blame] | 94 | # If NEUTRON_ENFORCE_SCOPE == True, it will set "enforce_scope" |
| 95 | # and "enforce_new_defaults" to True in the Neutron's config to enforce usage |
Ghanshyam Mann | bacb840 | 2023-10-25 12:52:28 -0700 | [diff] [blame] | 96 | # of the new RBAC policies and scopes. Set it to False if you do not |
| 97 | # want to run Neutron with new RBAC. |
| 98 | NEUTRON_ENFORCE_SCOPE=$(trueorfalse True NEUTRON_ENFORCE_SCOPE) |
Slawek Kaplonski | 24b65ad | 2021-06-22 15:31:46 +0200 | [diff] [blame] | 99 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 100 | # Agent binaries. Note, binary paths for other agents are set in per-service |
| 101 | # scripts in lib/neutron_plugins/services/ |
| 102 | AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent" |
| 103 | AGENT_L3_BINARY=${AGENT_L3_BINARY:-"$NEUTRON_BIN_DIR/neutron-l3-agent"} |
| 104 | AGENT_META_BINARY="$NEUTRON_BIN_DIR/neutron-metadata-agent" |
Brian Haley | 9aaa529 | 2017-09-20 14:23:05 -0400 | [diff] [blame] | 105 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 106 | # Agent config files. Note, plugin-specific Q_PLUGIN_CONF_FILE is set and |
| 107 | # loaded from per-plugin scripts in lib/neutron_plugins/ |
| 108 | Q_DHCP_CONF_FILE=$NEUTRON_CONF_DIR/dhcp_agent.ini |
| 109 | # NOTE(slaweq): NEUTRON_DHCP_CONF is used e.g. in neutron repository, |
| 110 | # it was previously defined in the lib/neutron module which is now deleted. |
| 111 | NEUTRON_DHCP_CONF=$Q_DHCP_CONF_FILE |
| 112 | Q_L3_CONF_FILE=$NEUTRON_CONF_DIR/l3_agent.ini |
| 113 | # NOTE(slaweq): NEUTRON_L3_CONF is used e.g. in neutron repository, |
| 114 | # it was previously defined in the lib/neutron module which is now deleted. |
| 115 | NEUTRON_L3_CONF=$Q_L3_CONF_FILE |
| 116 | Q_META_CONF_FILE=$NEUTRON_CONF_DIR/metadata_agent.ini |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 117 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 118 | # Default name for Neutron database |
| 119 | Q_DB_NAME=${Q_DB_NAME:-neutron} |
| 120 | # Default Neutron Plugin |
| 121 | Q_PLUGIN=${Q_PLUGIN:-ml2} |
| 122 | # Default Neutron Port |
| 123 | Q_PORT=${Q_PORT:-9696} |
| 124 | # Default Neutron Internal Port when using TLS proxy |
| 125 | Q_PORT_INT=${Q_PORT_INT:-19696} |
| 126 | # Default Neutron Host |
| 127 | Q_HOST=${Q_HOST:-$SERVICE_HOST} |
| 128 | # Default protocol |
| 129 | Q_PROTOCOL=${Q_PROTOCOL:-$SERVICE_PROTOCOL} |
| 130 | # Default listen address |
| 131 | Q_LISTEN_ADDRESS=${Q_LISTEN_ADDRESS:-$(ipv6_unquote $SERVICE_LISTEN_ADDRESS)} |
| 132 | # Default admin username |
| 133 | Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-neutron} |
| 134 | # Default auth strategy |
| 135 | Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone} |
| 136 | # RHEL's support for namespaces requires using veths with ovs |
| 137 | Q_OVS_USE_VETH=${Q_OVS_USE_VETH:-False} |
| 138 | Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True} |
| 139 | Q_USE_ROOTWRAP_DAEMON=$(trueorfalse True Q_USE_ROOTWRAP_DAEMON) |
| 140 | # Meta data IP |
| 141 | Q_META_DATA_IP=${Q_META_DATA_IP:-$(ipv6_unquote $SERVICE_HOST)} |
| 142 | # Allow Overlapping IP among subnets |
| 143 | Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-True} |
| 144 | Q_NOTIFY_NOVA_PORT_STATUS_CHANGES=${Q_NOTIFY_NOVA_PORT_STATUS_CHANGES:-True} |
| 145 | Q_NOTIFY_NOVA_PORT_DATA_CHANGES=${Q_NOTIFY_NOVA_PORT_DATA_CHANGES:-True} |
| 146 | VIF_PLUGGING_IS_FATAL=${VIF_PLUGGING_IS_FATAL:-True} |
| 147 | VIF_PLUGGING_TIMEOUT=${VIF_PLUGGING_TIMEOUT:-300} |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 148 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 149 | # Allow to skip stopping of OVN services |
| 150 | SKIP_STOP_OVN=${SKIP_STOP_OVN:-False} |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 151 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 152 | # The directory which contains files for Q_PLUGIN_EXTRA_CONF_FILES. |
| 153 | # /etc/neutron is assumed by many of devstack plugins. Do not change. |
| 154 | _Q_PLUGIN_EXTRA_CONF_PATH=/etc/neutron |
Julia Kreger | 6e5b138 | 2019-01-09 17:00:45 -0800 | [diff] [blame] | 155 | |
Slawek Kaplonski | 1a21ccb | 2022-07-08 21:57:45 +0200 | [diff] [blame] | 156 | # The name of the service in the endpoint URL |
| 157 | NEUTRON_ENDPOINT_SERVICE_NAME=${NEUTRON_ENDPOINT_SERVICE_NAME-"networking"} |
| 158 | if [[ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" && -z "$NEUTRON_ENDPOINT_SERVICE_NAME" ]]; then |
| 159 | NEUTRON_ENDPOINT_SERVICE_NAME="networking" |
| 160 | fi |
| 161 | |
elajkat | bb0c273 | 2023-11-16 11:30:04 +0100 | [diff] [blame] | 162 | # Source install libraries |
| 163 | ALEMBIC_REPO=${ALEMBIC_REPO:-https://github.com/sqlalchemy/alembic.git} |
| 164 | ALEMBIC_DIR=${ALEMBIC_DIR:-$DEST/alembic} |
| 165 | ALEMBIC_BRANCH=${ALEMBIC_BRANCH:-main} |
| 166 | SQLALCHEMY_REPO=${SQLALCHEMY_REPO:-https://github.com/sqlalchemy/sqlalchemy.git} |
| 167 | SQLALCHEMY_DIR=${SQLALCHEMY_DIR:-$DEST/sqlalchemy} |
| 168 | SQLALCHEMY_BRANCH=${SQLALCHEMY_BRANCH:-main} |
| 169 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 170 | # List of config file names in addition to the main plugin config file |
| 171 | # To add additional plugin config files, use ``neutron_server_config_add`` |
| 172 | # utility function. For example: |
| 173 | # |
| 174 | # ``neutron_server_config_add file1`` |
| 175 | # |
| 176 | # These config files are relative to ``/etc/neutron``. The above |
| 177 | # example would specify ``--config-file /etc/neutron/file1`` for |
| 178 | # neutron server. |
| 179 | declare -a -g Q_PLUGIN_EXTRA_CONF_FILES |
Julia Kreger | 6e5b138 | 2019-01-09 17:00:45 -0800 | [diff] [blame] | 180 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 181 | # same as Q_PLUGIN_EXTRA_CONF_FILES, but with absolute path. |
| 182 | declare -a -g _Q_PLUGIN_EXTRA_CONF_FILES_ABS |
| 183 | |
| 184 | |
| 185 | Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf |
| 186 | if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then |
| 187 | Q_RR_COMMAND="sudo" |
| 188 | else |
| 189 | NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron) |
| 190 | Q_RR_COMMAND="sudo $NEUTRON_ROOTWRAP $Q_RR_CONF_FILE" |
| 191 | if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then |
| 192 | Q_RR_DAEMON_COMMAND="sudo $NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE" |
| 193 | fi |
| 194 | fi |
| 195 | |
| 196 | |
| 197 | # Distributed Virtual Router (DVR) configuration |
| 198 | # Can be: |
| 199 | # - ``legacy`` - No DVR functionality |
| 200 | # - ``dvr_snat`` - Controller or single node DVR |
| 201 | # - ``dvr`` - Compute node in multi-node DVR |
| 202 | # - ``dvr_no_external`` - Compute node in multi-node DVR, no external network |
| 203 | # |
| 204 | Q_DVR_MODE=${Q_DVR_MODE:-legacy} |
| 205 | if [[ "$Q_DVR_MODE" != "legacy" ]]; then |
| 206 | Q_ML2_PLUGIN_MECHANISM_DRIVERS=openvswitch,l2population |
| 207 | fi |
| 208 | |
| 209 | # Provider Network Configurations |
| 210 | # -------------------------------- |
| 211 | |
| 212 | # The following variables control the Neutron ML2 plugins' allocation |
| 213 | # of tenant networks and availability of provider networks. If these |
| 214 | # are not configured in ``localrc``, tenant networks will be local to |
| 215 | # the host (with no remote connectivity), and no physical resources |
| 216 | # will be available for the allocation of provider networks. |
| 217 | |
| 218 | # To disable tunnels (GRE or VXLAN) for tenant networks, |
| 219 | # set to False in ``local.conf``. |
| 220 | # GRE tunnels are only supported by the openvswitch. |
| 221 | ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-True} |
| 222 | |
| 223 | # If using GRE, VXLAN or GENEVE tunnels for tenant networks, |
| 224 | # specify the range of IDs from which tenant networks are |
| 225 | # allocated. Can be overridden in ``localrc`` if necessary. |
| 226 | TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGES:-1:1000} |
| 227 | |
| 228 | # To use VLANs for tenant networks, set to True in localrc. VLANs |
| 229 | # are supported by the ML2 plugins, requiring additional configuration |
| 230 | # described below. |
| 231 | ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False} |
| 232 | |
| 233 | # If using VLANs for tenant networks, set in ``localrc`` to specify |
| 234 | # the range of VLAN VIDs from which tenant networks are |
| 235 | # allocated. An external network switch must be configured to |
| 236 | # trunk these VLANs between hosts for multi-host connectivity. |
| 237 | # |
| 238 | # Example: ``TENANT_VLAN_RANGE=1000:1999`` |
| 239 | TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-} |
| 240 | |
| 241 | # If using VLANs for tenant networks, or if using flat or VLAN |
| 242 | # provider networks, set in ``localrc`` to the name of the physical |
| 243 | # network, and also configure ``OVS_PHYSICAL_BRIDGE`` for the |
Brian Haley | 12abc72 | 2025-02-10 13:48:37 -0500 | [diff] [blame] | 244 | # openvswitch agent, as described below. |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 245 | # |
| 246 | # Example: ``PHYSICAL_NETWORK=default`` |
| 247 | PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-public} |
| 248 | |
| 249 | # With the openvswitch agent, if using VLANs for tenant networks, |
| 250 | # or if using flat or VLAN provider networks, set in ``localrc`` to |
| 251 | # the name of the OVS bridge to use for the physical network. The |
| 252 | # bridge will be created if it does not already exist, but a |
| 253 | # physical interface must be manually added to the bridge as a |
| 254 | # port for external connectivity. |
| 255 | # |
| 256 | # Example: ``OVS_PHYSICAL_BRIDGE=br-eth1`` |
| 257 | OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-br-ex} |
| 258 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 259 | # With the openvswitch plugin, set to True in ``localrc`` to enable |
| 260 | # provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False. |
| 261 | # |
| 262 | # Example: ``OVS_ENABLE_TUNNELING=True`` |
| 263 | OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS} |
| 264 | |
| 265 | # Use DHCP agent for providing metadata service in the case of |
| 266 | # without L3 agent (No Route Agent), set to True in localrc. |
| 267 | ENABLE_ISOLATED_METADATA=${ENABLE_ISOLATED_METADATA:-False} |
| 268 | |
| 269 | # Add a static route as dhcp option, so the request to 169.254.169.254 |
| 270 | # will be able to reach through a route(DHCP agent) |
| 271 | # This option require ENABLE_ISOLATED_METADATA = True |
| 272 | ENABLE_METADATA_NETWORK=${ENABLE_METADATA_NETWORK:-False} |
| 273 | # Neutron plugin specific functions |
| 274 | # --------------------------------- |
| 275 | |
| 276 | # Please refer to ``lib/neutron_plugins/README.md`` for details. |
| 277 | if [ -f $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN ]; then |
| 278 | source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN |
| 279 | fi |
| 280 | |
| 281 | # Agent metering service plugin functions |
| 282 | # ------------------------------------------- |
| 283 | |
| 284 | # Hardcoding for 1 service plugin for now |
| 285 | source $TOP_DIR/lib/neutron_plugins/services/metering |
| 286 | |
| 287 | # L3 Service functions |
| 288 | source $TOP_DIR/lib/neutron_plugins/services/l3 |
| 289 | |
| 290 | # Additional Neutron service plugins |
| 291 | source $TOP_DIR/lib/neutron_plugins/services/placement |
| 292 | source $TOP_DIR/lib/neutron_plugins/services/trunk |
| 293 | source $TOP_DIR/lib/neutron_plugins/services/qos |
elajkat | a84b209 | 2021-11-17 11:52:56 +0100 | [diff] [blame] | 294 | source $TOP_DIR/lib/neutron_plugins/services/segments |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 295 | |
| 296 | # Use security group or not |
| 297 | if has_neutron_plugin_security_group; then |
| 298 | Q_USE_SECGROUP=${Q_USE_SECGROUP:-True} |
| 299 | else |
| 300 | Q_USE_SECGROUP=False |
| 301 | fi |
| 302 | |
Harald Jensås | 16ac21f | 2023-08-31 15:06:52 +0200 | [diff] [blame] | 303 | # OVN_BRIDGE_MAPPINGS - ovn-bridge-mappings |
| 304 | # NOTE(hjensas): Initialize after sourcing neutron_plugins/services/l3 |
| 305 | # which initialize PUBLIC_BRIDGE. |
| 306 | OVN_BRIDGE_MAPPINGS=${OVN_BRIDGE_MAPPINGS:-$PHYSICAL_NETWORK:$PUBLIC_BRIDGE} |
| 307 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 308 | # Save trace setting |
| 309 | _XTRACE_NEUTRON=$(set +o | grep xtrace) |
| 310 | set +o xtrace |
| 311 | |
YAMAMOTO Takashi | eede9dd | 2016-07-15 10:27:53 +0900 | [diff] [blame] | 312 | |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 313 | # Functions |
| 314 | # --------- |
| 315 | |
| 316 | # Test if any Neutron services are enabled |
| 317 | # is_neutron_enabled |
| 318 | function is_neutron_enabled { |
Clark Boylan | 902158b | 2017-05-30 14:11:09 -0700 | [diff] [blame] | 319 | [[ ,${DISABLED_SERVICES} =~ ,"neutron" ]] && return 1 |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 320 | [[ ,${ENABLED_SERVICES} =~ ,"neutron-" || ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0 |
| 321 | return 1 |
| 322 | } |
| 323 | |
| 324 | # Test if any Neutron services are enabled |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 325 | # TODO(slaweq): this is not really needed now and we should remove it as soon |
| 326 | # as it will not be called from any other Devstack plugins, like e.g. Neutron |
| 327 | # plugin |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 328 | function is_neutron_legacy_enabled { |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 329 | return 0 |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 330 | } |
| 331 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 332 | function _determine_config_server { |
| 333 | if [[ "$Q_PLUGIN_EXTRA_CONF_PATH" != '' ]]; then |
| 334 | if [[ "$Q_PLUGIN_EXTRA_CONF_PATH" = "$_Q_PLUGIN_EXTRA_CONF_PATH" ]]; then |
| 335 | deprecated "Q_PLUGIN_EXTRA_CONF_PATH is deprecated" |
| 336 | else |
| 337 | die $LINENO "Q_PLUGIN_EXTRA_CONF_PATH is deprecated" |
| 338 | fi |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 339 | fi |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 340 | if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 ]]; then |
| 341 | deprecated "Q_PLUGIN_EXTRA_CONF_FILES is deprecated. Use neutron_server_config_add instead." |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 342 | fi |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 343 | for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do |
| 344 | _Q_PLUGIN_EXTRA_CONF_FILES_ABS+=($_Q_PLUGIN_EXTRA_CONF_PATH/$cfg_file) |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 345 | done |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 346 | |
| 347 | local cfg_file |
| 348 | local opts="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE" |
| 349 | for cfg_file in ${_Q_PLUGIN_EXTRA_CONF_FILES_ABS[@]}; do |
| 350 | opts+=" --config-file $cfg_file" |
| 351 | done |
| 352 | echo "$opts" |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 353 | } |
| 354 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 355 | function _determine_config_l3 { |
| 356 | local opts="--config-file $NEUTRON_CONF --config-file $Q_L3_CONF_FILE" |
| 357 | echo "$opts" |
Ihar Hrachyshka | e65ab4a | 2017-02-24 17:47:55 +0000 | [diff] [blame] | 358 | } |
| 359 | |
Rodolfo Alonso Hernandez | 3a0c0b9 | 2024-06-24 11:09:34 +0000 | [diff] [blame] | 360 | function _enable_ovn_maintenance { |
| 361 | if [[ $Q_AGENT == "ovn" ]]; then |
| 362 | enable_service neutron-ovn-maintenance-worker |
| 363 | fi |
| 364 | } |
| 365 | |
| 366 | function _run_ovn_maintenance { |
| 367 | if [[ $Q_AGENT == "ovn" ]]; then |
| 368 | run_process neutron-ovn-maintenance-worker "$NEUTRON_BIN_DIR/neutron-ovn-maintenance-worker $cfg_file_options" |
| 369 | fi |
| 370 | } |
| 371 | |
| 372 | function _stop_ovn_maintenance { |
| 373 | if [[ $Q_AGENT == "ovn" ]]; then |
| 374 | stop_process neutron-ovn-maintenance-worker |
| 375 | fi |
| 376 | } |
| 377 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 378 | # For services and agents that require it, dynamically construct a list of |
| 379 | # --config-file arguments that are passed to the binary. |
| 380 | function determine_config_files { |
| 381 | local opts="" |
| 382 | case "$1" in |
| 383 | "neutron-server") opts="$(_determine_config_server)" ;; |
| 384 | "neutron-l3-agent") opts="$(_determine_config_l3)" ;; |
| 385 | esac |
| 386 | if [ -z "$opts" ] ; then |
| 387 | die $LINENO "Could not determine config files for $1." |
YAMAMOTO Takashi | 1df17c9 | 2017-05-01 17:00:42 +0900 | [diff] [blame] | 388 | fi |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 389 | echo "$opts" |
| 390 | } |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 391 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 392 | # configure_neutron() |
| 393 | # Set common config for all neutron server and agents. |
| 394 | function configure_neutron { |
| 395 | _configure_neutron_common |
Sean M. Collins | 5394cc1 | 2016-05-11 15:03:38 -0400 | [diff] [blame] | 396 | iniset_rpc_backend neutron $NEUTRON_CONF |
| 397 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 398 | if is_service_enabled q-metering neutron-metering; then |
| 399 | _configure_neutron_metering |
| 400 | fi |
| 401 | if is_service_enabled q-agt neutron-agent; then |
| 402 | _configure_neutron_plugin_agent |
| 403 | fi |
| 404 | if is_service_enabled q-dhcp neutron-dhcp; then |
| 405 | _configure_neutron_dhcp_agent |
| 406 | fi |
| 407 | if is_service_enabled q-l3 neutron-l3; then |
| 408 | _configure_neutron_l3_agent |
| 409 | fi |
| 410 | if is_service_enabled q-meta neutron-metadata-agent; then |
| 411 | _configure_neutron_metadata_agent |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 412 | fi |
| 413 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 414 | if [[ "$Q_DVR_MODE" != "legacy" ]]; then |
| 415 | _configure_dvr |
| 416 | fi |
| 417 | if is_service_enabled ceilometer; then |
| 418 | _configure_neutron_ceilometer_notifications |
| 419 | fi |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 420 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 421 | if [[ $Q_AGENT == "ovn" ]]; then |
| 422 | configure_ovn |
| 423 | configure_ovn_plugin |
| 424 | fi |
Brian Haley | 9aaa529 | 2017-09-20 14:23:05 -0400 | [diff] [blame] | 425 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 426 | # Configure Neutron's advanced services |
| 427 | if is_service_enabled q-placement neutron-placement; then |
| 428 | configure_placement_extension |
| 429 | fi |
| 430 | if is_service_enabled q-trunk neutron-trunk; then |
| 431 | configure_trunk_extension |
| 432 | fi |
| 433 | if is_service_enabled q-qos neutron-qos; then |
| 434 | configure_qos |
| 435 | if is_service_enabled q-l3 neutron-l3; then |
| 436 | configure_l3_agent_extension_fip_qos |
| 437 | configure_l3_agent_extension_gateway_ip_qos |
Denis Buliga | 0bf75a4 | 2017-02-06 16:56:46 +0200 | [diff] [blame] | 438 | fi |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 439 | fi |
elajkat | a84b209 | 2021-11-17 11:52:56 +0100 | [diff] [blame] | 440 | if is_service_enabled neutron-segments; then |
| 441 | configure_placement_neutron |
| 442 | configure_segments_extension |
| 443 | fi |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 444 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 445 | # Finally configure Neutron server and core plugin |
| 446 | if is_service_enabled q-agt neutron-agent q-svc neutron-api; then |
| 447 | _configure_neutron_service |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 448 | fi |
| 449 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 450 | iniset $NEUTRON_CONF DEFAULT api_workers "$API_WORKERS" |
| 451 | # devstack is not a tool for running uber scale OpenStack |
| 452 | # clouds, therefore running without a dedicated RPC worker |
| 453 | # for state reports is more than adequate. |
| 454 | iniset $NEUTRON_CONF DEFAULT rpc_state_report_workers 0 |
Ihar Hrachyshka | e391593 | 2017-02-24 06:24:47 +0000 | [diff] [blame] | 455 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 456 | if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then |
Stephen Finucane | 0cd8763 | 2024-04-19 12:12:16 +0100 | [diff] [blame] | 457 | write_uwsgi_config "$NEUTRON_UWSGI_CONF" "$NEUTRON_UWSGI" "/networking" "" "neutron-api" |
Sean M. Collins | 8063fee | 2016-05-24 11:27:36 -0700 | [diff] [blame] | 458 | fi |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 459 | } |
| 460 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 461 | function configure_neutron_nova { |
| 462 | create_nova_conf_neutron $NOVA_CONF |
| 463 | if [[ "${CELLSV2_SETUP}" == "superconductor" ]]; then |
| 464 | for i in $(seq 1 $NOVA_NUM_CELLS); do |
| 465 | local conf |
| 466 | conf=$(conductor_conf $i) |
| 467 | create_nova_conf_neutron $conf |
| 468 | done |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 469 | fi |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 470 | } |
| 471 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 472 | function create_nova_conf_neutron { |
Lucas Alvares Gomes | e638593 | 2018-06-28 11:00:28 +0100 | [diff] [blame] | 473 | local conf=${1:-$NOVA_CONF} |
Matt Riedemann | e95f2a3 | 2018-06-18 16:17:29 -0400 | [diff] [blame] | 474 | iniset $conf neutron auth_type "password" |
| 475 | iniset $conf neutron auth_url "$KEYSTONE_SERVICE_URI" |
Dr. Jens Harbott | 696dbdf | 2024-07-09 16:36:37 +0200 | [diff] [blame] | 476 | iniset $conf neutron username nova |
Matt Riedemann | e95f2a3 | 2018-06-18 16:17:29 -0400 | [diff] [blame] | 477 | iniset $conf neutron password "$SERVICE_PASSWORD" |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 478 | iniset $conf neutron user_domain_name "$SERVICE_DOMAIN_NAME" |
| 479 | iniset $conf neutron project_name "$SERVICE_PROJECT_NAME" |
| 480 | iniset $conf neutron project_domain_name "$SERVICE_DOMAIN_NAME" |
| 481 | iniset $conf neutron auth_strategy "$Q_AUTH_STRATEGY" |
Matt Riedemann | e95f2a3 | 2018-06-18 16:17:29 -0400 | [diff] [blame] | 482 | iniset $conf neutron region_name "$REGION_NAME" |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 483 | |
Gary Kotton | 88f8558 | 2016-08-14 06:55:42 -0700 | [diff] [blame] | 484 | # optionally set options in nova_conf |
Matt Riedemann | e95f2a3 | 2018-06-18 16:17:29 -0400 | [diff] [blame] | 485 | neutron_plugin_create_nova_conf $conf |
Gary Kotton | 88f8558 | 2016-08-14 06:55:42 -0700 | [diff] [blame] | 486 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 487 | if is_service_enabled q-meta neutron-metadata-agent; then |
Matt Riedemann | e95f2a3 | 2018-06-18 16:17:29 -0400 | [diff] [blame] | 488 | iniset $conf neutron service_metadata_proxy "True" |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 489 | fi |
| 490 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 491 | iniset $conf DEFAULT vif_plugging_is_fatal "$VIF_PLUGGING_IS_FATAL" |
| 492 | iniset $conf DEFAULT vif_plugging_timeout "$VIF_PLUGGING_TIMEOUT" |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 493 | } |
| 494 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 495 | # create_neutron_accounts() - Set up common required neutron accounts |
| 496 | |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 497 | # Tenant User Roles |
| 498 | # ------------------------------------------------------------------ |
| 499 | # service neutron admin # if enabled |
| 500 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 501 | # Migrated from keystone_data.sh |
| 502 | function create_neutron_accounts { |
Kevin Benton | 66b361b | 2017-06-13 00:31:01 -0700 | [diff] [blame] | 503 | local neutron_url |
Kevin Benton | 66b361b | 2017-06-13 00:31:01 -0700 | [diff] [blame] | 504 | if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 505 | neutron_url=$Q_PROTOCOL://$SERVICE_HOST/ |
Kevin Benton | 66b361b | 2017-06-13 00:31:01 -0700 | [diff] [blame] | 506 | else |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 507 | neutron_url=$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/ |
Kevin Benton | 66b361b | 2017-06-13 00:31:01 -0700 | [diff] [blame] | 508 | fi |
Slawek Kaplonski | 1a21ccb | 2022-07-08 21:57:45 +0200 | [diff] [blame] | 509 | if [ ! -z "$NEUTRON_ENDPOINT_SERVICE_NAME" ]; then |
| 510 | neutron_url=$neutron_url$NEUTRON_ENDPOINT_SERVICE_NAME |
| 511 | fi |
Kevin Benton | 66b361b | 2017-06-13 00:31:01 -0700 | [diff] [blame] | 512 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 513 | if is_service_enabled q-svc neutron-api; then |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 514 | |
| 515 | create_service_user "neutron" |
| 516 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 517 | get_or_create_service "neutron" "network" "Neutron Service" |
| 518 | get_or_create_endpoint \ |
| 519 | "network" \ |
Kevin Benton | 66b361b | 2017-06-13 00:31:01 -0700 | [diff] [blame] | 520 | "$REGION_NAME" "$neutron_url" |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 521 | fi |
| 522 | } |
| 523 | |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 524 | # init_neutron() - Initialize databases, etc. |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 525 | function init_neutron { |
| 526 | recreate_database $Q_DB_NAME |
Clark Boylan | 633dbc3 | 2017-06-14 12:09:21 -0700 | [diff] [blame] | 527 | time_start "dbsync" |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 528 | # Run Neutron db migrations |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 529 | $NEUTRON_BIN_DIR/neutron-db-manage --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE upgrade head |
Clark Boylan | 633dbc3 | 2017-06-14 12:09:21 -0700 | [diff] [blame] | 530 | time_stop "dbsync" |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | # install_neutron() - Collect source and prepare |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 534 | function install_neutron { |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 535 | # Install neutron-lib from git so we make sure we're testing |
| 536 | # the latest code. |
| 537 | if use_library_from_git "neutron-lib"; then |
| 538 | git_clone_by_name "neutron-lib" |
| 539 | setup_dev_lib "neutron-lib" |
| 540 | fi |
| 541 | |
elajkat | bb0c273 | 2023-11-16 11:30:04 +0100 | [diff] [blame] | 542 | # Install SQLAlchemy and alembic from git when these are required |
| 543 | # see https://bugs.launchpad.net/neutron/+bug/2042941 |
| 544 | if use_library_from_git "sqlalchemy"; then |
| 545 | git_clone $SQLALCHEMY_REPO $SQLALCHEMY_DIR $SQLALCHEMY_BRANCH |
| 546 | setup_develop $SQLALCHEMY_DIR |
| 547 | fi |
| 548 | if use_library_from_git "alembic"; then |
| 549 | git_clone $ALEMBIC_REPO $ALEMBIC_DIR $ALEMBIC_BRANCH |
| 550 | setup_develop $ALEMBIC_DIR |
| 551 | fi |
| 552 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 553 | git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH |
| 554 | setup_develop $NEUTRON_DIR |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 555 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 556 | if [[ $Q_AGENT == "ovn" ]]; then |
| 557 | install_ovn |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 558 | fi |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | # install_neutronclient() - Collect source and prepare |
| 562 | function install_neutronclient { |
| 563 | if use_library_from_git "python-neutronclient"; then |
| 564 | git_clone_by_name "python-neutronclient" |
| 565 | setup_dev_lib "python-neutronclient" |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 566 | fi |
| 567 | } |
| 568 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 569 | # install_neutron_agent_packages() - Collect source and prepare |
| 570 | function install_neutron_agent_packages { |
| 571 | # radvd doesn't come with the OS. Install it if the l3 service is enabled. |
| 572 | if is_service_enabled q-l3 neutron-l3; then |
| 573 | install_package radvd |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 574 | fi |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 575 | # install packages that are specific to plugin agent(s) |
| 576 | if is_service_enabled q-agt neutron-agent q-dhcp neutron-dhcp q-l3 neutron-l3; then |
| 577 | neutron_plugin_install_agent_packages |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 578 | fi |
| 579 | } |
| 580 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 581 | # Finish neutron configuration |
| 582 | function configure_neutron_after_post_config { |
| 583 | if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then |
| 584 | iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 585 | fi |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 586 | configure_rbac_policies |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 587 | } |
| 588 | |
Slawek Kaplonski | 24b65ad | 2021-06-22 15:31:46 +0200 | [diff] [blame] | 589 | # configure_rbac_policies() - Configure Neutron to enforce new RBAC |
| 590 | # policies and scopes if NEUTRON_ENFORCE_SCOPE == True |
| 591 | function configure_rbac_policies { |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 592 | if [[ "$NEUTRON_ENFORCE_SCOPE" == "True" || "$ENFORCE_SCOPE" == True ]]; then |
Slawek Kaplonski | 24b65ad | 2021-06-22 15:31:46 +0200 | [diff] [blame] | 593 | iniset $NEUTRON_CONF oslo_policy enforce_new_defaults True |
| 594 | iniset $NEUTRON_CONF oslo_policy enforce_scope True |
| 595 | else |
| 596 | iniset $NEUTRON_CONF oslo_policy enforce_new_defaults False |
| 597 | iniset $NEUTRON_CONF oslo_policy enforce_scope False |
| 598 | fi |
| 599 | } |
| 600 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 601 | # Start running OVN processes |
| 602 | function start_ovn_services { |
| 603 | if [[ $Q_AGENT == "ovn" ]]; then |
Lucas Alvares Gomes | a389128 | 2023-07-18 16:31:28 +0100 | [diff] [blame] | 604 | if [ "$VIRT_DRIVER" != 'ironic' ]; then |
| 605 | # NOTE(TheJulia): Ironic's devstack plugin needs to perform |
| 606 | # additional networking configuration to setup a working test |
| 607 | # environment with test virtual machines to emulate baremetal, |
| 608 | # which requires OVN to be up and running earlier to complete |
| 609 | # that base configuration. |
| 610 | init_ovn |
| 611 | start_ovn |
| 612 | fi |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 613 | if [[ "$OVN_L3_CREATE_PUBLIC_NETWORK" == "True" ]]; then |
| 614 | if [[ "$NEUTRON_CREATE_INITIAL_NETWORKS" != "True" ]]; then |
| 615 | echo "OVN_L3_CREATE_PUBLIC_NETWORK=True is being ignored " |
| 616 | echo "because NEUTRON_CREATE_INITIAL_NETWORKS is set to False" |
| 617 | else |
| 618 | create_public_bridge |
| 619 | fi |
Matt Riedemann | e95f2a3 | 2018-06-18 16:17:29 -0400 | [diff] [blame] | 620 | fi |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 621 | fi |
| 622 | } |
| 623 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 624 | # Start running processes |
| 625 | function start_neutron_service_and_check { |
| 626 | local service_port=$Q_PORT |
| 627 | local service_protocol=$Q_PROTOCOL |
| 628 | local cfg_file_options |
| 629 | local neutron_url |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 630 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 631 | cfg_file_options="$(determine_config_files neutron-server)" |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 632 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 633 | if is_service_enabled tls-proxy; then |
| 634 | service_port=$Q_PORT_INT |
| 635 | service_protocol="http" |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 636 | fi |
Rodolfo Alonso Hernandez | 79a812a | 2024-07-31 14:41:33 +0000 | [diff] [blame] | 637 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 638 | # Start the Neutron service |
| 639 | if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then |
Rodolfo Alonso Hernandez | 79a812a | 2024-07-31 14:41:33 +0000 | [diff] [blame] | 640 | # The default value of "rpc_workers" is None (not defined). If |
| 641 | # "rpc_workers" is explicitly set to 0, the RPC workers process |
| 642 | # should not be executed. |
| 643 | local rpc_workers |
| 644 | rpc_workers=$(iniget_multiline $NEUTRON_CONF DEFAULT rpc_workers) |
| 645 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 646 | enable_service neutron-api |
| 647 | run_process neutron-api "$(which uwsgi) --procname-prefix neutron-api --ini $NEUTRON_UWSGI_CONF" |
| 648 | neutron_url=$Q_PROTOCOL://$Q_HOST/ |
Rodolfo Alonso Hernandez | 79a812a | 2024-07-31 14:41:33 +0000 | [diff] [blame] | 649 | if [ "$rpc_workers" != "0" ]; then |
Rodolfo Alonso Hernandez | aaaa037 | 2024-07-19 08:09:25 +0000 | [diff] [blame] | 650 | enable_service neutron-rpc-server |
| 651 | fi |
Rodolfo Alonso Hernandez | 56368c2 | 2024-06-17 15:10:40 +0000 | [diff] [blame] | 652 | enable_service neutron-periodic-workers |
Rodolfo Alonso Hernandez | 3a0c0b9 | 2024-06-24 11:09:34 +0000 | [diff] [blame] | 653 | _enable_ovn_maintenance |
Rodolfo Alonso Hernandez | 79a812a | 2024-07-31 14:41:33 +0000 | [diff] [blame] | 654 | if [ "$rpc_workers" != "0" ]; then |
Rodolfo Alonso Hernandez | aaaa037 | 2024-07-19 08:09:25 +0000 | [diff] [blame] | 655 | run_process neutron-rpc-server "$NEUTRON_BIN_DIR/neutron-rpc-server $cfg_file_options" |
| 656 | fi |
Rodolfo Alonso Hernandez | 56368c2 | 2024-06-17 15:10:40 +0000 | [diff] [blame] | 657 | run_process neutron-periodic-workers "$NEUTRON_BIN_DIR/neutron-periodic-workers $cfg_file_options" |
Rodolfo Alonso Hernandez | 3a0c0b9 | 2024-06-24 11:09:34 +0000 | [diff] [blame] | 658 | _run_ovn_maintenance |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 659 | else |
| 660 | run_process q-svc "$NEUTRON_BIN_DIR/neutron-server $cfg_file_options" |
| 661 | neutron_url=$service_protocol://$Q_HOST:$service_port/ |
| 662 | # Start proxy if enabled |
| 663 | if is_service_enabled tls-proxy; then |
| 664 | start_tls_proxy neutron '*' $Q_PORT $Q_HOST $Q_PORT_INT |
| 665 | fi |
| 666 | fi |
| 667 | if [ ! -z "$NEUTRON_ENDPOINT_SERVICE_NAME" ]; then |
| 668 | neutron_url=$neutron_url$NEUTRON_ENDPOINT_SERVICE_NAME |
| 669 | fi |
| 670 | echo "Waiting for Neutron to start..." |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 671 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 672 | local testcmd="wget ${ssl_ca} --no-proxy -q -O- $neutron_url" |
| 673 | test_with_retry "$testcmd" "Neutron did not start" $SERVICE_TIMEOUT |
YAMAMOTO Takashi | eede9dd | 2016-07-15 10:27:53 +0900 | [diff] [blame] | 674 | } |
| 675 | |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 676 | function start_neutron { |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 677 | start_l2_agent "$@" |
| 678 | start_other_agents "$@" |
| 679 | } |
| 680 | |
| 681 | # Control of the l2 agent is separated out to make it easier to test partial |
| 682 | # upgrades (everything upgraded except the L2 agent) |
| 683 | function start_l2_agent { |
| 684 | run_process q-agt "$AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE" |
| 685 | |
| 686 | if is_provider_network && [[ $Q_AGENT == "openvswitch" ]]; then |
| 687 | sudo ovs-vsctl --no-wait -- --may-exist add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE |
| 688 | sudo ip link set $OVS_PHYSICAL_BRIDGE up |
| 689 | sudo ip link set br-int up |
| 690 | sudo ip link set $PUBLIC_INTERFACE up |
| 691 | if is_ironic_hardware; then |
| 692 | for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do |
| 693 | sudo ip addr del $IP dev $PUBLIC_INTERFACE |
| 694 | sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE |
| 695 | done |
| 696 | sudo ip route replace $FIXED_RANGE via $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE |
| 697 | fi |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 698 | fi |
| 699 | } |
| 700 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 701 | function start_other_agents { |
| 702 | run_process q-dhcp "$AGENT_DHCP_BINARY --config-file $NEUTRON_CONF --config-file $Q_DHCP_CONF_FILE" |
| 703 | |
| 704 | run_process q-l3 "$AGENT_L3_BINARY $(determine_config_files neutron-l3-agent)" |
| 705 | |
| 706 | run_process q-meta "$AGENT_META_BINARY --config-file $NEUTRON_CONF --config-file $Q_META_CONF_FILE" |
| 707 | run_process q-metering "$AGENT_METERING_BINARY --config-file $NEUTRON_CONF --config-file $METERING_AGENT_CONF_FILENAME" |
| 708 | } |
| 709 | |
| 710 | # Start running processes, including screen |
| 711 | function start_neutron_agents { |
| 712 | # NOTE(slaweq): it's now just a wrapper for start_neutron function |
| 713 | start_neutron "$@" |
| 714 | } |
| 715 | |
| 716 | function stop_l2_agent { |
| 717 | stop_process q-agt |
| 718 | } |
| 719 | |
| 720 | # stop_other() - Stop running processes |
| 721 | function stop_other { |
| 722 | if is_service_enabled q-dhcp neutron-dhcp; then |
| 723 | stop_process q-dhcp |
| 724 | pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }') |
| 725 | [ ! -z "$pid" ] && sudo kill -9 $pid |
| 726 | fi |
| 727 | |
| 728 | if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then |
| 729 | stop_process neutron-rpc-server |
Rodolfo Alonso Hernandez | 56368c2 | 2024-06-17 15:10:40 +0000 | [diff] [blame] | 730 | stop_process neutron-periodic-workers |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 731 | stop_process neutron-api |
Rodolfo Alonso Hernandez | 3a0c0b9 | 2024-06-24 11:09:34 +0000 | [diff] [blame] | 732 | _stop_ovn_maintenance |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 733 | else |
| 734 | stop_process q-svc |
| 735 | fi |
| 736 | |
| 737 | if is_service_enabled q-l3 neutron-l3; then |
| 738 | sudo pkill -f "radvd -C $DATA_DIR/neutron/ra" |
| 739 | stop_process q-l3 |
| 740 | fi |
| 741 | |
| 742 | if is_service_enabled q-meta neutron-metadata-agent; then |
| 743 | stop_process q-meta |
| 744 | fi |
| 745 | |
| 746 | if is_service_enabled q-metering neutron-metering; then |
| 747 | neutron_metering_stop |
| 748 | fi |
| 749 | |
| 750 | if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then |
Bence Romsics | 71c3c40 | 2022-12-21 13:50:54 +0100 | [diff] [blame] | 751 | # pkill takes care not to kill itself, but it may kill its parent |
| 752 | # sudo unless we use the "ps | grep [f]oo" trick |
| 753 | sudo pkill -9 -f "$NEUTRON_ROOTWRAP-[d]aemon" || : |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 754 | fi |
| 755 | } |
| 756 | |
| 757 | # stop_neutron() - Stop running processes (non-screen) |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 758 | function stop_neutron { |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 759 | stop_other |
| 760 | stop_l2_agent |
| 761 | |
| 762 | if [[ $Q_AGENT == "ovn" && $SKIP_STOP_OVN != "True" ]]; then |
| 763 | stop_ovn |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 764 | fi |
| 765 | } |
| 766 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 767 | # _move_neutron_addresses_route() - Move the primary IP to the OVS bridge |
| 768 | # on startup, or back to the public interface on cleanup. If no IP is |
| 769 | # configured on the interface, just add it as a port to the OVS bridge. |
| 770 | function _move_neutron_addresses_route { |
| 771 | local from_intf=$1 |
| 772 | local to_intf=$2 |
| 773 | local add_ovs_port=$3 |
| 774 | local del_ovs_port=$4 |
| 775 | local af=$5 |
| 776 | |
| 777 | if [[ -n "$from_intf" && -n "$to_intf" ]]; then |
| 778 | # Remove the primary IP address from $from_intf and add it to $to_intf, |
| 779 | # along with the default route, if it exists. Also, when called |
| 780 | # on configure we will also add $from_intf as a port on $to_intf, |
| 781 | # assuming it is an OVS bridge. |
| 782 | |
| 783 | local IP_REPLACE="" |
| 784 | local IP_DEL="" |
| 785 | local IP_UP="" |
| 786 | local DEFAULT_ROUTE_GW |
| 787 | DEFAULT_ROUTE_GW=$(ip -f $af r | awk "/default.+$from_intf\s/ { print \$3; exit }") |
| 788 | local ADD_OVS_PORT="" |
| 789 | local DEL_OVS_PORT="" |
| 790 | local ARP_CMD="" |
| 791 | |
| 792 | IP_BRD=$(ip -f $af a s dev $from_intf scope global primary | grep inet | awk '{ print $2, $3, $4; exit }') |
| 793 | |
| 794 | if [ "$DEFAULT_ROUTE_GW" != "" ]; then |
| 795 | ADD_DEFAULT_ROUTE="sudo ip -f $af r replace default via $DEFAULT_ROUTE_GW dev $to_intf" |
| 796 | fi |
| 797 | |
| 798 | if [[ "$add_ovs_port" == "True" ]]; then |
| 799 | ADD_OVS_PORT="sudo ovs-vsctl --may-exist add-port $to_intf $from_intf" |
| 800 | fi |
| 801 | |
| 802 | if [[ "$del_ovs_port" == "True" ]]; then |
| 803 | DEL_OVS_PORT="sudo ovs-vsctl --if-exists del-port $from_intf $to_intf" |
| 804 | fi |
| 805 | |
| 806 | if [[ "$IP_BRD" != "" ]]; then |
| 807 | IP_DEL="sudo ip addr del $IP_BRD dev $from_intf" |
| 808 | IP_REPLACE="sudo ip addr replace $IP_BRD dev $to_intf" |
| 809 | IP_UP="sudo ip link set $to_intf up" |
| 810 | if [[ "$af" == "inet" ]]; then |
| 811 | IP=$(echo $IP_BRD | awk '{ print $1; exit }' | grep -o -E '(.*)/' | cut -d "/" -f1) |
| 812 | ARP_CMD="sudo arping -A -c 3 -w 5 -I $to_intf $IP " |
| 813 | fi |
| 814 | fi |
| 815 | |
| 816 | # The add/del OVS port calls have to happen either before or |
| 817 | # after the address is moved in order to not leave it orphaned. |
| 818 | $DEL_OVS_PORT; $IP_DEL; $IP_REPLACE; $IP_UP; $ADD_OVS_PORT; $ADD_DEFAULT_ROUTE; $ARP_CMD |
| 819 | fi |
| 820 | } |
| 821 | |
| 822 | # _configure_public_network_connectivity() - Configures connectivity to the |
| 823 | # external network using $PUBLIC_INTERFACE or NAT on the single interface |
| 824 | # machines |
| 825 | function _configure_public_network_connectivity { |
| 826 | # If we've given a PUBLIC_INTERFACE to take over, then we assume |
| 827 | # that we can own the whole thing, and privot it into the OVS |
| 828 | # bridge. If we are not, we're probably on a single interface |
| 829 | # machine, and we just setup NAT so that fixed guests can get out. |
| 830 | if [[ -n "$PUBLIC_INTERFACE" ]]; then |
| 831 | _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" True False "inet" |
| 832 | |
| 833 | if [[ $(ip -f inet6 a s dev "$PUBLIC_INTERFACE" | grep -c 'global') != 0 ]]; then |
| 834 | _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" False False "inet6" |
| 835 | fi |
YAMAMOTO Takashi | c043b6f | 2017-02-23 22:30:08 -0500 | [diff] [blame] | 836 | else |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 837 | for d in $default_v4_route_devs; do |
| 838 | sudo iptables -t nat -A POSTROUTING -o $d -s $FLOATING_RANGE -j MASQUERADE |
| 839 | done |
| 840 | fi |
| 841 | } |
| 842 | |
| 843 | # cleanup_neutron() - Remove residual data files, anything left over from previous |
| 844 | # runs that a clean run would need to clean up |
| 845 | function cleanup_neutron { |
| 846 | if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then |
| 847 | stop_process neutron-api |
| 848 | stop_process neutron-rpc-server |
Rodolfo Alonso Hernandez | 56368c2 | 2024-06-17 15:10:40 +0000 | [diff] [blame] | 849 | stop_process neutron-periodic-workers |
Rodolfo Alonso Hernandez | 3a0c0b9 | 2024-06-24 11:09:34 +0000 | [diff] [blame] | 850 | _stop_ovn_maintenance |
Stephen Finucane | d5182ce | 2024-04-19 12:27:14 +0100 | [diff] [blame] | 851 | remove_uwsgi_config "$NEUTRON_UWSGI_CONF" "neutron-api" |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 852 | sudo rm -f $(apache_site_config_for neutron-api) |
| 853 | fi |
| 854 | |
| 855 | if [[ -n "$OVS_PHYSICAL_BRIDGE" ]]; then |
| 856 | _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False True "inet" |
| 857 | |
| 858 | if [[ $(ip -f inet6 a s dev "$OVS_PHYSICAL_BRIDGE" | grep -c 'global') != 0 ]]; then |
| 859 | # ip(8) wants the prefix length when deleting |
| 860 | local v6_gateway |
| 861 | v6_gateway=$(ip -6 a s dev $OVS_PHYSICAL_BRIDGE | grep $IPV6_PUBLIC_NETWORK_GATEWAY | awk '{ print $2 }') |
| 862 | sudo ip -6 addr del $v6_gateway dev $OVS_PHYSICAL_BRIDGE |
| 863 | _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False False "inet6" |
| 864 | fi |
| 865 | |
| 866 | if is_provider_network && is_ironic_hardware; then |
| 867 | for IP in $(ip addr show dev $OVS_PHYSICAL_BRIDGE | grep ' inet ' | awk '{print $2}'); do |
| 868 | sudo ip addr del $IP dev $OVS_PHYSICAL_BRIDGE |
| 869 | sudo ip addr add $IP dev $PUBLIC_INTERFACE |
| 870 | done |
| 871 | sudo route del -net $FIXED_RANGE gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE |
| 872 | fi |
| 873 | fi |
| 874 | |
| 875 | if is_neutron_ovs_base_plugin; then |
| 876 | neutron_ovs_base_cleanup |
| 877 | fi |
| 878 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 879 | # delete all namespaces created by neutron |
| 880 | for ns in $(sudo ip netns list | grep -o -E '(qdhcp|qrouter|fip|snat)-[0-9a-f-]*'); do |
| 881 | sudo ip netns delete ${ns} |
| 882 | done |
| 883 | |
| 884 | if [[ $Q_AGENT == "ovn" ]]; then |
| 885 | cleanup_ovn |
| 886 | fi |
| 887 | } |
| 888 | |
| 889 | |
| 890 | function _create_neutron_conf_dir { |
| 891 | # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find |
| 892 | sudo install -d -o $STACK_USER $NEUTRON_CONF_DIR |
| 893 | } |
| 894 | |
| 895 | # _configure_neutron_common() |
| 896 | # Set common config for all neutron server and agents. |
| 897 | # This MUST be called before other ``_configure_neutron_*`` functions. |
| 898 | function _configure_neutron_common { |
| 899 | _create_neutron_conf_dir |
| 900 | |
| 901 | # Uses oslo config generator to generate core sample configuration files |
| 902 | (cd $NEUTRON_DIR && exec ./tools/generate_config_file_samples.sh) |
| 903 | |
| 904 | cp $NEUTRON_DIR/etc/neutron.conf.sample $NEUTRON_CONF |
| 905 | |
| 906 | Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json |
| 907 | |
| 908 | # allow neutron user to administer neutron to match neutron account |
| 909 | # NOTE(amotoki): This is required for nova works correctly with neutron. |
| 910 | if [ -f $NEUTRON_DIR/etc/policy.json ]; then |
| 911 | cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE |
| 912 | sed -i 's/"context_is_admin": "role:admin"/"context_is_admin": "role:admin or user_name:neutron"/g' $Q_POLICY_FILE |
| 913 | else |
| 914 | echo '{"context_is_admin": "role:admin or user_name:neutron"}' > $Q_POLICY_FILE |
| 915 | fi |
| 916 | |
| 917 | # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``. |
| 918 | # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``. |
| 919 | neutron_plugin_configure_common |
| 920 | |
| 921 | if [[ "$Q_PLUGIN_CONF_PATH" == '' || "$Q_PLUGIN_CONF_FILENAME" == '' || "$Q_PLUGIN_CLASS" == '' ]]; then |
| 922 | die $LINENO "Neutron plugin not set.. exiting" |
| 923 | fi |
| 924 | |
| 925 | # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR`` |
| 926 | mkdir -p /$Q_PLUGIN_CONF_PATH |
| 927 | Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME |
| 928 | # NOTE(slaweq): NEUTRON_CORE_PLUGIN_CONF is used e.g. in neutron repository, |
| 929 | # it was previously defined in the lib/neutron module which is now deleted. |
| 930 | NEUTRON_CORE_PLUGIN_CONF=$Q_PLUGIN_CONF_FILE |
| 931 | # NOTE(hichihara): Some neutron vendor plugins were already decomposed and |
| 932 | # there is no config file in Neutron tree. They should prepare the file in each plugin. |
| 933 | if [ -f "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" ]; then |
| 934 | cp "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" /$Q_PLUGIN_CONF_FILE |
| 935 | elif [ -f $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE ]; then |
| 936 | cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE |
| 937 | fi |
| 938 | |
| 939 | iniset $NEUTRON_CONF database connection `database_connection_url $Q_DB_NAME` |
| 940 | iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron |
| 941 | iniset $NEUTRON_CONF DEFAULT use_syslog $SYSLOG |
| 942 | iniset $NEUTRON_CONF DEFAULT bind_host $Q_LISTEN_ADDRESS |
| 943 | iniset $NEUTRON_CONF oslo_concurrency lock_path $DATA_DIR/neutron/lock |
| 944 | |
| 945 | # NOTE(freerunner): Need to adjust Region Name for nova in multiregion installation |
| 946 | iniset $NEUTRON_CONF nova region_name $REGION_NAME |
| 947 | |
| 948 | if [ "$VIRT_DRIVER" = 'fake' ]; then |
| 949 | # Disable arbitrary limits |
| 950 | iniset $NEUTRON_CONF quotas quota_network -1 |
| 951 | iniset $NEUTRON_CONF quotas quota_subnet -1 |
| 952 | iniset $NEUTRON_CONF quotas quota_port -1 |
| 953 | iniset $NEUTRON_CONF quotas quota_security_group -1 |
| 954 | iniset $NEUTRON_CONF quotas quota_security_group_rule -1 |
| 955 | fi |
| 956 | |
| 957 | # Format logging |
| 958 | setup_logging $NEUTRON_CONF |
| 959 | |
| 960 | if is_service_enabled tls-proxy && [ "$NEUTRON_DEPLOY_MOD_WSGI" == "False" ]; then |
| 961 | # Set the service port for a proxy to take the original |
| 962 | iniset $NEUTRON_CONF DEFAULT bind_port "$Q_PORT_INT" |
| 963 | iniset $NEUTRON_CONF oslo_middleware enable_proxy_headers_parsing True |
| 964 | fi |
| 965 | |
| 966 | _neutron_setup_rootwrap |
| 967 | } |
| 968 | |
| 969 | function _configure_neutron_dhcp_agent { |
| 970 | |
| 971 | cp $NEUTRON_DIR/etc/dhcp_agent.ini.sample $Q_DHCP_CONF_FILE |
| 972 | |
| 973 | iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL |
| 974 | # make it so we have working DNS from guests |
| 975 | iniset $Q_DHCP_CONF_FILE DEFAULT dnsmasq_local_resolv True |
| 976 | configure_root_helper_options $Q_DHCP_CONF_FILE |
| 977 | |
| 978 | if ! is_service_enabled q-l3 neutron-l3; then |
| 979 | if [[ "$ENABLE_ISOLATED_METADATA" = "True" ]]; then |
| 980 | iniset $Q_DHCP_CONF_FILE DEFAULT enable_isolated_metadata $ENABLE_ISOLATED_METADATA |
| 981 | iniset $Q_DHCP_CONF_FILE DEFAULT enable_metadata_network $ENABLE_METADATA_NETWORK |
| 982 | else |
| 983 | if [[ "$ENABLE_METADATA_NETWORK" = "True" ]]; then |
| 984 | die "$LINENO" "Enable isolated metadata is a must for metadata network" |
| 985 | fi |
| 986 | fi |
| 987 | fi |
| 988 | |
| 989 | _neutron_setup_interface_driver $Q_DHCP_CONF_FILE |
| 990 | |
| 991 | neutron_plugin_configure_dhcp_agent $Q_DHCP_CONF_FILE |
| 992 | } |
| 993 | |
| 994 | |
| 995 | function _configure_neutron_metadata_agent { |
| 996 | cp $NEUTRON_DIR/etc/metadata_agent.ini.sample $Q_META_CONF_FILE |
| 997 | |
| 998 | iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL |
| 999 | iniset $Q_META_CONF_FILE DEFAULT nova_metadata_host $Q_META_DATA_IP |
| 1000 | iniset $Q_META_CONF_FILE DEFAULT metadata_workers $API_WORKERS |
| 1001 | configure_root_helper_options $Q_META_CONF_FILE |
| 1002 | } |
| 1003 | |
| 1004 | function _configure_neutron_ceilometer_notifications { |
| 1005 | iniset $NEUTRON_CONF oslo_messaging_notifications driver messagingv2 |
| 1006 | } |
| 1007 | |
| 1008 | function _configure_neutron_metering { |
| 1009 | neutron_agent_metering_configure_common |
| 1010 | neutron_agent_metering_configure_agent |
| 1011 | } |
| 1012 | |
| 1013 | function _configure_dvr { |
| 1014 | iniset $NEUTRON_CONF DEFAULT router_distributed True |
| 1015 | iniset $Q_L3_CONF_FILE DEFAULT agent_mode $Q_DVR_MODE |
| 1016 | } |
| 1017 | |
| 1018 | |
| 1019 | # _configure_neutron_plugin_agent() - Set config files for neutron plugin agent |
| 1020 | # It is called when q-agt is enabled. |
| 1021 | function _configure_neutron_plugin_agent { |
| 1022 | # Specify the default root helper prior to agent configuration to |
| 1023 | # ensure that an agent's configuration can override the default |
| 1024 | configure_root_helper_options /$Q_PLUGIN_CONF_FILE |
| 1025 | iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL |
| 1026 | |
| 1027 | # Configure agent for plugin |
| 1028 | neutron_plugin_configure_plugin_agent |
| 1029 | } |
| 1030 | |
| 1031 | function _replace_api_paste_composite { |
| 1032 | local sep |
| 1033 | sep=$(echo -ne "\x01") |
| 1034 | # Replace it |
| 1035 | $sudo sed -i -e "s/\/\: neutronversions_composite/\/"${NEUTRON_ENDPOINT_SERVICE_NAME}"\/\: neutronversions_composite/" "$Q_API_PASTE_FILE" |
| 1036 | $sudo sed -i -e "s/\/healthcheck\: healthcheck/\/"${NEUTRON_ENDPOINT_SERVICE_NAME}"\/healthcheck\: healthcheck/" "$Q_API_PASTE_FILE" |
| 1037 | $sudo sed -i -e "s/\/v2.0\: neutronapi_v2_0/\/"${NEUTRON_ENDPOINT_SERVICE_NAME}"\/v2.0\: neutronapi_v2_0/" "$Q_API_PASTE_FILE" |
| 1038 | } |
| 1039 | |
| 1040 | # _configure_neutron_service() - Set config files for neutron service |
| 1041 | # It is called when q-svc is enabled. |
| 1042 | function _configure_neutron_service { |
| 1043 | Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini |
| 1044 | cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE |
| 1045 | |
Slawek Kaplonski | b500d80 | 2024-06-14 12:58:58 +0200 | [diff] [blame] | 1046 | if [[ "$NEUTRON_DEPLOY_MOD_WSGI" == "False" && -n "$NEUTRON_ENDPOINT_SERVICE_NAME" ]]; then |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 1047 | _replace_api_paste_composite |
| 1048 | fi |
| 1049 | |
| 1050 | # Update either configuration file with plugin |
| 1051 | iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS |
| 1052 | |
| 1053 | iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL |
| 1054 | iniset $NEUTRON_CONF oslo_policy policy_file $Q_POLICY_FILE |
| 1055 | |
| 1056 | iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY |
| 1057 | configure_keystone_authtoken_middleware $NEUTRON_CONF $Q_ADMIN_USERNAME |
| 1058 | |
| 1059 | # Configuration for neutron notifications to nova. |
| 1060 | iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_status_changes $Q_NOTIFY_NOVA_PORT_STATUS_CHANGES |
| 1061 | iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_PORT_DATA_CHANGES |
| 1062 | |
| 1063 | configure_keystone_authtoken_middleware $NEUTRON_CONF nova nova |
| 1064 | |
| 1065 | # Configuration for placement client |
| 1066 | configure_keystone_authtoken_middleware $NEUTRON_CONF placement placement |
| 1067 | |
| 1068 | # Configure plugin |
| 1069 | neutron_plugin_configure_service |
| 1070 | } |
| 1071 | |
| 1072 | # Utility Functions |
| 1073 | #------------------ |
| 1074 | |
| 1075 | # neutron_service_plugin_class_add() - add service plugin class |
| 1076 | function neutron_service_plugin_class_add { |
| 1077 | local service_plugin_class=$1 |
| 1078 | if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then |
| 1079 | Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class |
| 1080 | elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then |
| 1081 | Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class" |
| 1082 | fi |
| 1083 | } |
| 1084 | |
| 1085 | # neutron_ml2_extension_driver_add() - add ML2 extension driver |
| 1086 | function neutron_ml2_extension_driver_add { |
| 1087 | local extension=$1 |
| 1088 | if [[ $Q_ML2_PLUGIN_EXT_DRIVERS == '' ]]; then |
| 1089 | Q_ML2_PLUGIN_EXT_DRIVERS=$extension |
| 1090 | elif [[ ! ,${Q_ML2_PLUGIN_EXT_DRIVERS}, =~ ,${extension}, ]]; then |
| 1091 | Q_ML2_PLUGIN_EXT_DRIVERS="$Q_ML2_PLUGIN_EXT_DRIVERS,$extension" |
| 1092 | fi |
| 1093 | } |
| 1094 | |
| 1095 | # neutron_server_config_add() - add server config file |
| 1096 | function neutron_server_config_add { |
| 1097 | _Q_PLUGIN_EXTRA_CONF_FILES_ABS+=($1) |
| 1098 | } |
| 1099 | |
| 1100 | # neutron_deploy_rootwrap_filters() - deploy rootwrap filters to $Q_CONF_ROOTWRAP_D (owned by root). |
| 1101 | function neutron_deploy_rootwrap_filters { |
| 1102 | if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then |
| 1103 | return |
| 1104 | fi |
| 1105 | local srcdir=$1 |
| 1106 | sudo install -d -o root -m 755 $Q_CONF_ROOTWRAP_D |
| 1107 | sudo install -o root -m 644 $srcdir/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/ |
| 1108 | } |
| 1109 | |
| 1110 | # _neutron_setup_rootwrap() - configure Neutron's rootwrap |
| 1111 | function _neutron_setup_rootwrap { |
| 1112 | if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then |
| 1113 | return |
| 1114 | fi |
| 1115 | # Wipe any existing ``rootwrap.d`` files first |
| 1116 | Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d |
| 1117 | if [[ -d $Q_CONF_ROOTWRAP_D ]]; then |
| 1118 | sudo rm -rf $Q_CONF_ROOTWRAP_D |
| 1119 | fi |
| 1120 | |
| 1121 | neutron_deploy_rootwrap_filters $NEUTRON_DIR |
| 1122 | |
| 1123 | # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d`` |
| 1124 | # location moved in newer versions, prefer new location |
| 1125 | if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then |
| 1126 | sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/neutron/rootwrap.conf $Q_RR_CONF_FILE |
| 1127 | else |
| 1128 | sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE |
| 1129 | fi |
| 1130 | sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE |
yatinkarel | ffc1b76 | 2023-08-28 10:52:26 +0530 | [diff] [blame] | 1131 | # Rely on $PATH set by devstack to determine what is safe to execute |
| 1132 | # by rootwrap rather than use explicit whitelist of paths in |
| 1133 | # rootwrap.conf |
| 1134 | sudo sed -e 's/^exec_dirs=.*/#&/' -i $Q_RR_CONF_FILE |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 1135 | |
| 1136 | # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap |
| 1137 | ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *" |
| 1138 | ROOTWRAP_DAEMON_SUDOER_CMD="$NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE" |
| 1139 | |
| 1140 | # Set up the rootwrap sudoers for neutron |
| 1141 | TEMPFILE=`mktemp` |
| 1142 | echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE |
| 1143 | echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_DAEMON_SUDOER_CMD" >>$TEMPFILE |
| 1144 | chmod 0440 $TEMPFILE |
| 1145 | sudo chown root:root $TEMPFILE |
| 1146 | sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap |
| 1147 | |
| 1148 | # Update the root_helper |
| 1149 | configure_root_helper_options $NEUTRON_CONF |
| 1150 | } |
| 1151 | |
| 1152 | function configure_root_helper_options { |
| 1153 | local conffile=$1 |
| 1154 | iniset $conffile agent root_helper "$Q_RR_COMMAND" |
| 1155 | if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then |
| 1156 | iniset $conffile agent root_helper_daemon "$Q_RR_DAEMON_COMMAND" |
| 1157 | fi |
| 1158 | } |
| 1159 | |
| 1160 | function _neutron_setup_interface_driver { |
| 1161 | |
| 1162 | # ovs_use_veth needs to be set before the plugin configuration |
| 1163 | # occurs to allow plugins to override the setting. |
| 1164 | iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH |
| 1165 | |
| 1166 | neutron_plugin_setup_interface_driver $1 |
| 1167 | } |
| 1168 | # Functions for Neutron Exercises |
| 1169 | #-------------------------------- |
| 1170 | |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 1171 | # ssh check |
| 1172 | function _ssh_check_neutron { |
| 1173 | local from_net=$1 |
| 1174 | local key_file=$2 |
| 1175 | local ip=$3 |
| 1176 | local user=$4 |
| 1177 | local timeout_sec=$5 |
| 1178 | local probe_cmd = "" |
| 1179 | probe_cmd=`_get_probe_cmd_prefix $from_net` |
| 1180 | local testcmd="$probe_cmd ssh -o StrictHostKeyChecking=no -i $key_file ${user}@$ip echo success" |
| 1181 | test_with_retry "$testcmd" "server $ip didn't become ssh-able" $timeout_sec |
| 1182 | } |
| 1183 | |
| 1184 | function plugin_agent_add_l2_agent_extension { |
| 1185 | local l2_agent_extension=$1 |
| 1186 | if [[ -z "$L2_AGENT_EXTENSIONS" ]]; then |
| 1187 | L2_AGENT_EXTENSIONS=$l2_agent_extension |
| 1188 | elif [[ ! ,${L2_AGENT_EXTENSIONS}, =~ ,${l2_agent_extension}, ]]; then |
| 1189 | L2_AGENT_EXTENSIONS+=",$l2_agent_extension" |
YAMAMOTO Takashi | c043b6f | 2017-02-23 22:30:08 -0500 | [diff] [blame] | 1190 | fi |
| 1191 | } |
| 1192 | |
Sean M. Collins | 2a24251 | 2016-05-03 09:03:09 -0400 | [diff] [blame] | 1193 | # Restore xtrace |
Slawek Kaplonski | a52041c | 2022-11-18 11:39:56 +0100 | [diff] [blame] | 1194 | $_XTRACE_NEUTRON |
| 1195 | |
| 1196 | # Tell emacs to use shell-script-mode |
| 1197 | ## Local variables: |
| 1198 | ## mode: shell-script |
| 1199 | ## End: |