Migrate dvr multinode scenario to zuulv3 syntax

Job neutron-tempest-plugin-dvr-multinode-scenario was the
last job in neutron-tempest-plugin repo defined using
legacy zuulv2 templates.
This commit migrates it to zuulv3 syntax.

It also adds new ansible role "multi-node-setup" which
which creates patch ports between Neutron's external
bridge (br-ex) and infra bridge (br-infra). That is necessary
to provide connectivity to floating IPs, which may be
configured on subnode when dvr is used, from each node.

This patch introduces also new playbook
"dvr-multinode-scenario-pre-run" which is used to be run in
neutron-tempest-plugin-dvr-multinode-scenario job and which
uses "multi-node-setup" role to create those patch ports
on each host used in job.

Change-Id: Ic5bb7649ebb8bf229459f3d9911f64635cbf1e44
diff --git a/.zuul.yaml b/.zuul.yaml
index 9aa86b9..ff94a81 100644
--- a/.zuul.yaml
+++ b/.zuul.yaml
@@ -161,18 +161,126 @@
 
 - job:
     name: neutron-tempest-plugin-dvr-multinode-scenario
-    parent: legacy-dsvm-base-multinode
-    run: playbooks/neutron-tempest-plugin-dvr-multinode-scenario/run.yaml
-    post-run: playbooks/neutron-tempest-plugin-dvr-multinode-scenario/post.yaml
-    nodeset: legacy-ubuntu-xenial-2-node
-    timeout: 10800
+    parent: tempest-multinode-full
+    description: |
+        Perform setup for Neutron tempest tests in multinode with DVR scenario
+    roles:
+      - zuul: openstack-dev/devstack
     required-projects:
       - openstack-infra/devstack-gate
       - openstack/neutron
       - openstack/neutron-tempest-plugin
       - openstack/tempest
-    irrelevant-files: *tempest-irrelevant-files
+    pre-run: playbooks/dvr-multinode-scenario-pre-run.yaml
     voting: false
+    vars:
+      tempest_concurrency: 4
+      tox_envlist: all
+      tempest_test_regex: ^neutron_tempest_plugin\.scenario
+      devstack_localrc:
+        TEMPEST_PLUGINS: /opt/stack/neutron-tempest-plugin
+        NETWORK_API_EXTENSIONS: "address-scope,agent,allowed-address-pairs,auto-allocated-topology,availability_zone,binding,default-subnetpools,dhcp_agent_scheduler,dns-integration,dvr,empty-string-filtering,ext-gw-mode,external-net,extra_dhcp_opt,extraroute,fip-port-details,flavors,ip-substring-filtering,l3-flavors,l3-ha,l3_agent_scheduler,logging,metering,multi-provider,net-mtu,net-mtu-writable,network-ip-availability,network_availability_zone,pagination,port-security,project-id,provider,qos,qos-fip,quotas,quota_details,rbac-policies,router,router_availability_zone,security-group,port-security-groups-filtering,segment,service-type,sorting,standard-attr-description,standard-attr-revisions,standard-attr-segment,standard-attr-timestamp,standard-attr-tag,subnet_allocation,trunk,trunk-details"
+        PHYSICAL_NETWORK: default
+        DOWNLOAD_DEFAULT_IMAGES: false
+        IMAGE_URLS: http://cloud-images.ubuntu.com/releases/16.04/release-20180622/ubuntu-16.04-server-cloudimg-amd64-disk1.img,
+        DEFAULT_INSTANCE_TYPE: ds512M
+        DEFAULT_INSTANCE_USER: ubuntu
+        BUILD_TIMEOUT: 784
+      devstack_plugins:
+        neutron: git://git.openstack.org/openstack/neutron.git
+        neutron-tempest-plugin: git://git.openstack.org/openstack/neutron-tempest-plugin.git
+      devstack_services:
+        tls-proxy: false
+        tempest: true
+        neutron-dns: true
+        neutron-qos: true
+        neutron-segments: true
+        neutron-trunk: true
+        neutron-log: true
+        cinder: true
+      devstack_local_conf:
+        post-config:
+          $NEUTRON_CONF:
+            quotas:
+              quota_router: 100
+              quota_floatingip: 500
+              quota_security_group: 100
+              quota_security_group_rule: 1000
+            DEFAULT:
+              router_distributed: True
+          # NOTE(slaweq): We can get rid of this hardcoded absolute path when
+          # devstack-tempest job will be switched to use lib/neutron instead of
+          # lib/neutron-legacy
+          "/$NEUTRON_CORE_PLUGIN_CONF":
+            ml2:
+              type_drivers: flat,geneve,vlan,gre,local,vxlan
+              mechanism_drivers: openvswitch,l2population
+            ml2_type_vlan:
+              network_vlan_ranges: foo:1:10
+            ml2_type_vxlan:
+              vni_ranges: 1:2000
+            ml2_type_gre:
+              tunnel_id_ranges: 1:1000
+            agent:
+              enable_distributed_routing: True
+              l2_population: True
+              tunnel_types: vxlan,gre
+            ovs:
+              tunnel_bridge: br-tun
+              bridge_mappings: public:br-ex
+          $NEUTRON_L3_CONF:
+            DEFAULT:
+              agent_mode: dvr_snat
+            agent:
+              availability_zone: nova
+          $NEUTRON_DHCP_CONF:
+            agent:
+              availability_zone: nova
+          "/etc/neutron/api-paste.ini":
+            "composite:neutronapi_v2_0":
+              use: "call:neutron.auth:pipeline_factory"
+              noauth: "cors request_id catch_errors osprofiler extensions neutronapiapp_v2_0"
+              keystone: "cors request_id catch_errors osprofiler authtoken keystonecontext extensions neutronapiapp_v2_0"
+        test-config:
+          $TEMPEST_CONFIG:
+            neutron_plugin_options:
+              provider_vlans: foo,
+              agent_availability_zone: nova
+              image_is_advanced: true
+              available_type_drivers: flat,geneve,vlan,gre,local,vxlan
+              l3_agent_mode: dvr_snat
+    group-vars:
+      subnode:
+        devstack_services:
+          tls-proxy: false
+          q-agt: true
+          q-l3: true
+          q-meta: true
+          neutron-qos: true
+          neutron-trunk: true
+          neutron-log: true
+        devstack_local_conf:
+          post-config:
+            $NEUTRON_CONF:
+              DEFAULT:
+                router_distributed: True
+            # NOTE(slaweq): We can get rid of this hardcoded absolute path when
+            # devstack-tempest job will be switched to use lib/neutron instead of
+            # lib/neutron-legacy
+            "/$NEUTRON_CORE_PLUGIN_CONF":
+              agent:
+                enable_distributed_routing: True
+                l2_population: True
+                tunnel_types: vxlan,gre
+              ovs:
+                tunnel_bridge: br-tun
+                bridge_mappings: public:br-ex
+            $NEUTRON_L3_CONF:
+              DEFAULT:
+                agent_mode: dvr_snat
+              agent:
+                availability_zone: nova
+    irrelevant-files: *tempest-irrelevant-files
 
 - job:
     name: neutron-tempest-plugin-dvr-multinode-scenario-queens
diff --git a/playbooks/dvr-multinode-scenario-pre-run.yaml b/playbooks/dvr-multinode-scenario-pre-run.yaml
new file mode 100644
index 0000000..8afd8a5
--- /dev/null
+++ b/playbooks/dvr-multinode-scenario-pre-run.yaml
@@ -0,0 +1,3 @@
+- hosts: all
+  roles:
+    - multi-node-setup
diff --git a/playbooks/neutron-tempest-plugin-dvr-multinode-scenario/post.yaml b/playbooks/neutron-tempest-plugin-dvr-multinode-scenario/post.yaml
deleted file mode 100644
index e07f551..0000000
--- a/playbooks/neutron-tempest-plugin-dvr-multinode-scenario/post.yaml
+++ /dev/null
@@ -1,15 +0,0 @@
-- hosts: primary
-  tasks:
-
-    - name: Copy files from {{ ansible_user_dir }}/workspace/ on node
-      synchronize:
-        src: '{{ ansible_user_dir }}/workspace/'
-        dest: '{{ zuul.executor.log_root }}'
-        mode: pull
-        copy_links: true
-        verify_host: true
-        rsync_opts:
-          - --include=/logs/**
-          - --include=*/
-          - --exclude=*
-          - --prune-empty-dirs
diff --git a/playbooks/neutron-tempest-plugin-dvr-multinode-scenario/run.yaml b/playbooks/neutron-tempest-plugin-dvr-multinode-scenario/run.yaml
deleted file mode 100644
index a9ce3e0..0000000
--- a/playbooks/neutron-tempest-plugin-dvr-multinode-scenario/run.yaml
+++ /dev/null
@@ -1,60 +0,0 @@
-- hosts: primary
-  name: neutron-tempest-plugin-dvr-multinode-scenario
-  tasks:
-
-    - name: Ensure legacy workspace directory
-      file:
-        path: '{{ ansible_user_dir }}/workspace'
-        state: directory
-
-    - shell:
-        cmd: |
-          set -e
-          set -x
-          cat > clonemap.yaml << EOF
-          clonemap:
-            - name: openstack-infra/devstack-gate
-              dest: devstack-gate
-          EOF
-          /usr/zuul-env/bin/zuul-cloner -m clonemap.yaml --cache-dir /opt/git \
-              git://git.openstack.org \
-              openstack-infra/devstack-gate
-        executable: /bin/bash
-        chdir: '{{ ansible_user_dir }}/workspace'
-      environment: '{{ zuul | zuul_legacy_vars }}'
-
-    - shell:
-        cmd: |
-          set -e
-          set -x
-          export PYTHONUNBUFFERED=true
-          export DEVSTACK_GATE_TEMPEST=1
-          export DEVSTACK_GATE_TEMPEST_ALL_PLUGINS=1
-          export DEVSTACK_GATE_NEUTRON=1
-          export DEVSTACK_GATE_CONFIGDRIVE=0
-          export DEVSTACK_GATE_TEMPEST_REGEX="(neutron_tempest_plugin.scenario)"
-          export DEVSTACK_LOCAL_CONFIG="enable_plugin neutron-tempest-plugin git://git.openstack.org/openstack/neutron-tempest-plugin"
-          # Test DVR works multinode
-          export DEVSTACK_GATE_NEUTRON_DVR=1
-          export BRANCH_OVERRIDE=default
-          if [ "$BRANCH_OVERRIDE" != "default" ] ; then
-              export OVERRIDE_ZUUL_BRANCH=$BRANCH_OVERRIDE
-          fi
-          export DEVSTACK_GATE_TOPOLOGY="multinode"
-          export PROJECTS="openstack/neutron-tempest-plugin $PROJECTS"
-
-          function gate_hook {
-              bash -xe $BASE/new/neutron/neutron/tests/contrib/gate_hook.sh dsvm-scenario-ovs
-          }
-          export -f gate_hook
-
-          function post_test_hook {
-              bash -xe $BASE/new/neutron/neutron/tests/contrib/post_test_hook.sh dsvm-scenario-ovs
-          }
-          export -f post_test_hook
-
-          cp devstack-gate/devstack-vm-gate-wrap.sh ./safe-devstack-vm-gate-wrap.sh
-          ./safe-devstack-vm-gate-wrap.sh
-        executable: /bin/bash
-        chdir: '{{ ansible_user_dir }}/workspace'
-      environment: '{{ zuul | zuul_legacy_vars }}'
diff --git a/roles/multi-node-setup/README.rst b/roles/multi-node-setup/README.rst
new file mode 100644
index 0000000..b57a977
--- /dev/null
+++ b/roles/multi-node-setup/README.rst
@@ -0,0 +1,23 @@
+Set up connection between infra bridge and Neutron external bridge
+
+Network topology used in CI multinode jobs is described In `Devstack documention
+<https://git.openstack.org/cgit/openstack-infra/devstack-gate/tree/multinode_setup_info.txt#n81>`_
+
+In case when DVR is used, there is also additional bridge ``br-infra`` added
+on each node to provide connectivity to floating IPs from main node.
+
+This bridge needs to be connected with bridge used by Neutron as
+external bridge. Typically it is ``br-ex`` and this role adds patch ports
+between those bridges.
+
+**Role Variables**
+
+.. zuul:rolevar:: neutron_external_bridge_name
+   :default: br-ex
+
+   Name of the Neutron external bridge.
+
+.. zuul:rolevar:: infra_bridge_name
+   :default: br-infra
+
+   Name of the infra bridge.
diff --git a/roles/multi-node-setup/defaults/main.yaml b/roles/multi-node-setup/defaults/main.yaml
new file mode 100644
index 0000000..f166fe7
--- /dev/null
+++ b/roles/multi-node-setup/defaults/main.yaml
@@ -0,0 +1,2 @@
+infra_bridge_name: br-infra
+neutron_external_bridge_name: br-ex
diff --git a/roles/multi-node-setup/tasks/main.yaml b/roles/multi-node-setup/tasks/main.yaml
new file mode 100644
index 0000000..043e70f
--- /dev/null
+++ b/roles/multi-node-setup/tasks/main.yaml
@@ -0,0 +1,17 @@
+- name: Ensure the infra bridge exists
+  become: yes
+  openvswitch_bridge:
+    bridge: "{{ infra_bridge_name }}"
+
+- name: Ensure the Neutron external bridge exists
+  become: yes
+  openvswitch_bridge:
+    bridge: "{{ neutron_external_bridge_name }}"
+
+- name: Create patch port between bridges
+  become: yes
+  command: >-
+    ovs-vsctl --may-exist add-port {{ infra_bridge_name }} patch-{{ neutron_external_bridge_name }}
+    -- set interface patch-{{ neutron_external_bridge_name }} type=patch options:peer=patch-{{ infra_bridge_name }}
+    -- --may-exist add-port {{ neutron_external_bridge_name }} patch-{{ infra_bridge_name }}
+    -- set interface patch-{{ infra_bridge_name }} type=patch options:peer=patch-{{ neutron_external_bridge_name }}