From 341a3db1610e01b49a20cddbb4359b9d859752ae Mon Sep 17 00:00:00 2001
From: Federico Ressi <fressi@redhat.com>
Date: Fri, 23 Oct 2020 12:51:13 +0200
Subject: [PATCH] Generate SSH key pair when it is missing

Depends-On: https://review.opendev.org/760088/
Change-Id: Ie17cd336d9273912192e9f3477e1775b4569ad7a
---
 Vagrantfile                      |  8 +++++++-
 devstack/plugin.sh               | 19 ++++++++++++++-----
 playbooks/vagrant/ovs/local.conf |  2 ++
 3 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/Vagrantfile b/Vagrantfile
index 06141fe..a402637 100644
--- a/Vagrantfile
+++ b/Vagrantfile
@@ -39,7 +39,7 @@ TOX_ENVLIST = ENV.fetch('TOX_ENVLIST', '')
 TOX_EXTRA_ARGS = ENV.fetch('TOX_EXTRA_ARGS', '--notest')
 
 # Allow to switch configuration
-DEVSTACK_CONF_NAME = ENV.fetch('DEVSTACK_CONF_NAME', 'ovs')
+DEVSTACK_CONF_NAME = ENV.fetch('DEVSTACK_CONF_NAME', 'ovn')
 
 DEVSTACK_LOCAL_CONF_FILE = ENV.fetch(
   'DEVSTACK_LOCAL_CONF_FILE',
@@ -57,10 +57,16 @@ DEVSTACK_PROJECTS = {
     'src_dir' => ENV.fetch("DEVSTACK_PLUGIN_TOBIKO_SRC_DIR", VAGRANTFILE_DIR),
   },
 
+  # Local directory from where look for OpenStack requirements project files
+  'requirements' => {
+    'src_dir' => ENV.fetch("REQUIREMENTS_DIR", "#{PROJECTS_DIR}/requirements"),
+  },
+
   # Local directory from where looking for Tobiko project files
   'tobiko' => {
     'src_dir' => ENV.fetch("TOBIKO_SRC_DIR", "#{PROJECTS_DIR}/tobiko"),
   },
+
 }
 
 
diff --git a/devstack/plugin.sh b/devstack/plugin.sh
index dbea0f4..c7a353c 100644
--- a/devstack/plugin.sh
+++ b/devstack/plugin.sh
@@ -149,11 +149,20 @@ function configure_tobiko_nova {
     echo_summary "Write [nova] section to ${TOBIKO_CONF_FILE}"
     local tobiko_conf_file=$1
 
-    # Write key_file
-    local key_file=${TOBIKO_NOVA_KEY_FILE:-}
-    if [ "${key_file}" != "" ]; then
-        iniset "${tobiko_conf_file}" nova key_file "${key_file}"
-    fi
+    (
+        cd $(dirname "${tobiko_conf_file}")
+        local key_file=${TOBIKO_NOVA_KEY_FILE}
+        if [ "${key_file}" != "" ]; then
+            iniset "${tobiko_conf_file}" nova key_file "${key_file}"
+        else
+            # Use the default keyfile name
+            key_file=~/.ssh/id_rsa
+        fi
+        if ! [ -r "${key_file}" ]; then
+            mkdir -p $(dirname "${key_file}")
+            ssh-keygen -f "${key_file}" -N ""
+        fi
+    )
 }
 
 
diff --git a/playbooks/vagrant/ovs/local.conf b/playbooks/vagrant/ovs/local.conf
index f7d5ce3..0fe87cc 100644
--- a/playbooks/vagrant/ovs/local.conf
+++ b/playbooks/vagrant/ovs/local.conf
@@ -16,6 +16,8 @@ disable_service tempest
 
 # Configure Neutron -----------------------------------------------------------
 
+enable_plugin neutron https://opendev.org/openstack/neutron.git
+
 HOST_IP=192.168.33.10
 IP_VERSION=4