diff --git a/devstack/plugin.sh b/devstack/plugin.sh index 4432a07aa..ff245214a 100644 --- a/devstack/plugin.sh +++ b/devstack/plugin.sh @@ -120,9 +120,6 @@ function configure_tobiko_nova { # Write key_file local key_file=${TOBIKO_NOVA_KEY_FILE:-} - if ! [ -r "${key_file}" ]; then - ssh-keygen -t rsa -q -P "" -f "${key_file}" - fi iniset "${tobiko_config}" nova key_file "${key_file}" } diff --git a/tobiko/openstack/stacks/_nova.py b/tobiko/openstack/stacks/_nova.py index 5786e3ce5..c1d3fdb80 100644 --- a/tobiko/openstack/stacks/_nova.py +++ b/tobiko/openstack/stacks/_nova.py @@ -26,6 +26,7 @@ from tobiko.openstack import neutron from tobiko.openstack.stacks import _hot from tobiko.openstack.stacks import _neutron from tobiko.shell import ssh +from tobiko.shell import sh CONF = config.CONF @@ -38,6 +39,7 @@ class KeyPairStackFixture(heat.HeatStackFixture): private_key = None def setup_fixture(self): + self.create_key_file() self.read_keys() super(KeyPairStackFixture, self).setup_fixture() @@ -47,6 +49,19 @@ class KeyPairStackFixture(heat.HeatStackFixture): with open(self.key_file + '.pub', 'r') as fd: self.public_key = as_str(fd.read()) + def create_key_file(self): + key_file = os.path.realpath(self.key_file) + if not os.path.isfile(key_file): + key_dir = os.path.dirname(key_file) + if not os.path.isdir(key_dir): + os.makedirs(key_dir) + assert os.path.isdir(key_dir) + command = sh.shell_command(['ssh-keygen', + '-f', key_file, + '-P', '']) + sh.local_execute(command) + assert os.path.isfile(key_file) + class FlavorStackFixture(heat.HeatStackFixture): template = _hot.heat_template_file('nova/flavor.yaml') diff --git a/tobiko/tests/functional/openstack/test_nova.py b/tobiko/tests/functional/openstack/test_nova.py new file mode 100644 index 000000000..ec6b3050f --- /dev/null +++ b/tobiko/tests/functional/openstack/test_nova.py @@ -0,0 +1,32 @@ +# Copyright (c) 2019 Red Hat, Inc. +# +# All Rights Reserved. +# +# 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. +from __future__ import absolute_import + +import os + +import testtools + +import tobiko +from tobiko.openstack import stacks + + +class KeyPairTest(testtools.TestCase): + + stack = tobiko.required_setup_fixture(stacks.KeyPairStackFixture) + + def test_key_files(self): + self.assertTrue(os.path.isfile(self.stack.key_file)) + self.assertTrue(os.path.isfile(self.stack.key_file + '.pub'))