Specify auth parameters in devstack tests
Single-node devstack does not have SSH key for stack user. In all tests we will use custom os-faults key and connect to localhost as `stack` user. Tests are also executed as `stack` user explicitly (by default they are run as zuul user, but we do not want to rely on this). Change-Id: Ibcc9a406dc850363e651d4023874147db45214f7
This commit is contained in:
parent
8f7e490c75
commit
fedc060158
@ -18,7 +18,9 @@
|
|||||||
description: |
|
description: |
|
||||||
Run os-faults integration tests on DevStack under Python 3
|
Run os-faults integration tests on DevStack under Python 3
|
||||||
timeout: 2400
|
timeout: 2400
|
||||||
|
pre-run: os_faults/tests/devstack/playbooks/pre.yml
|
||||||
run: os_faults/tests/devstack/playbooks/run_on_devstack.yml
|
run: os_faults/tests/devstack/playbooks/run_on_devstack.yml
|
||||||
|
post-run: os_faults/tests/devstack/playbooks/post.yml
|
||||||
required-projects:
|
required-projects:
|
||||||
- openstack/os-faults
|
- openstack/os-faults
|
||||||
vars:
|
vars:
|
||||||
|
@ -163,8 +163,9 @@ class AnsibleRunner(object):
|
|||||||
playbook_file_name = os.path.join(temp_dir, 'playbook')
|
playbook_file_name = os.path.join(temp_dir, 'playbook')
|
||||||
|
|
||||||
with open(inventory_file_name, 'w') as fd:
|
with open(inventory_file_name, 'w') as fd:
|
||||||
print(yaml.safe_dump(full_inventory, default_flow_style=False),
|
cnt = yaml.safe_dump(full_inventory, default_flow_style=False)
|
||||||
file=fd)
|
print(cnt, file=fd)
|
||||||
|
LOG.debug('Inventory:\n%s', cnt)
|
||||||
|
|
||||||
play = {
|
play = {
|
||||||
'hosts': 'all',
|
'hosts': 'all',
|
||||||
@ -173,7 +174,9 @@ class AnsibleRunner(object):
|
|||||||
}
|
}
|
||||||
|
|
||||||
with open(playbook_file_name, 'w') as fd:
|
with open(playbook_file_name, 'w') as fd:
|
||||||
print(yaml.safe_dump([play], default_flow_style=False), file=fd)
|
cnt = yaml.safe_dump([play], default_flow_style=False)
|
||||||
|
print(cnt, file=fd)
|
||||||
|
LOG.debug('Playbook:\n%s', cnt)
|
||||||
|
|
||||||
cmd = ('%(ansible)s --module-path %(module_path)s '
|
cmd = ('%(ansible)s --module-path %(module_path)s '
|
||||||
'-i %(inventory)s %(playbook)s' %
|
'-i %(inventory)s %(playbook)s' %
|
||||||
|
@ -4,6 +4,9 @@ node_discover:
|
|||||||
driver: node_list
|
driver: node_list
|
||||||
args:
|
args:
|
||||||
- ip: localhost
|
- ip: localhost
|
||||||
|
auth:
|
||||||
|
username: stack
|
||||||
|
private_key_file: os_faults_key
|
||||||
services:
|
services:
|
||||||
memcached:
|
memcached:
|
||||||
args:
|
args:
|
||||||
|
23
os_faults/tests/devstack/playbooks/post.yml
Normal file
23
os_faults/tests/devstack/playbooks/post.yml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- hosts: all
|
||||||
|
vars:
|
||||||
|
- test_results_path: "/opt/stack/os-faults/.tox/{{tox_envlist}}/log/pytest_results.html"
|
||||||
|
tasks:
|
||||||
|
- name: Check whether test results file exists
|
||||||
|
stat:
|
||||||
|
path: "{{ test_results_path }}"
|
||||||
|
register: test_results
|
||||||
|
|
||||||
|
- name: Copy job results
|
||||||
|
become: yes
|
||||||
|
synchronize:
|
||||||
|
src: "{{ test_results_path }}"
|
||||||
|
dest: "{{ zuul.executor.log_root }}"
|
||||||
|
mode: pull
|
||||||
|
copy_links: true
|
||||||
|
verify_host: true
|
||||||
|
rsync_opts:
|
||||||
|
- "--include=/**"
|
||||||
|
- "--include=*/"
|
||||||
|
when: test_results.stat.exists
|
5
os_faults/tests/devstack/playbooks/pre.yml
Normal file
5
os_faults/tests/devstack/playbooks/pre.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- hosts: all
|
||||||
|
roles:
|
||||||
|
- orchestrate-devstack
|
@ -1,30 +1,53 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
- hosts: all
|
- hosts: all
|
||||||
roles:
|
vars:
|
||||||
- orchestrate-devstack
|
- stack_home: "/opt/stack"
|
||||||
|
- os_faults_home: "/opt/stack/os-faults"
|
||||||
|
|
||||||
- hosts: all
|
|
||||||
tasks:
|
tasks:
|
||||||
- name: Run integration tests
|
|
||||||
|
- name: Create folder for SSH keys (as stack user)
|
||||||
|
file:
|
||||||
|
path: "{{ stack_home }}/.ssh"
|
||||||
|
state: directory
|
||||||
|
mode: 0755
|
||||||
|
become: yes
|
||||||
|
become_user: stack
|
||||||
|
|
||||||
|
- name: Generate SSH key pair
|
||||||
|
command: "ssh-keygen -t rsa -f {{ os_faults_home }}/os_faults_key -N ''"
|
||||||
|
become: yes
|
||||||
|
become_user: stack
|
||||||
|
|
||||||
|
- name: List os-faults folder
|
||||||
|
command: "ls -al {{ os_faults_home }}"
|
||||||
|
become: yes
|
||||||
|
become_user: stack
|
||||||
|
|
||||||
|
- name: Add os-faults key into authorized_keys for stack user
|
||||||
|
shell: |
|
||||||
|
cat {{ os_faults_home}}/os_faults_key.pub >> {{ stack_home }}/.ssh/authorized_keys
|
||||||
|
become: yes
|
||||||
|
become_user: stack
|
||||||
|
|
||||||
|
- name: Check SSH connection using os-faults key
|
||||||
|
command: "ssh -vvv -i os_faults_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ConnectTimeout=60 -o IdentitiesOnly=yes stack@localhost"
|
||||||
|
args:
|
||||||
|
chdir: "{{ os_faults_home }}"
|
||||||
|
become: yes
|
||||||
|
become_user: stack
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
command: "tox -e {{tox_envlist}}"
|
command: "tox -e {{tox_envlist}}"
|
||||||
args:
|
args:
|
||||||
chdir: "/opt/stack/os-faults"
|
chdir: "{{ os_faults_home }}"
|
||||||
|
|
||||||
|
|
||||||
- hosts: all
|
|
||||||
vars:
|
|
||||||
- test_results_path: "/opt/stack/os-faults/.tox/{{tox_envlist}}/log/pytest_results.html"
|
|
||||||
tasks:
|
|
||||||
- name: Copy job results
|
|
||||||
become: yes
|
become: yes
|
||||||
synchronize:
|
become_user: stack
|
||||||
src: "{{ test_results_path }}"
|
|
||||||
dest: "{{ zuul.executor.log_root }}"
|
- name: Check connectivity using command-line tool
|
||||||
mode: pull
|
shell: |
|
||||||
copy_links: true
|
cd /opt/stack/os-faults
|
||||||
verify_host: true
|
. .tox/devstack/bin/activate
|
||||||
rsync_opts:
|
os-inject-fault -c /opt/stack/os-faults/os_faults/tests/devstack/os-faults-universal.yaml -vd
|
||||||
- "--include=/**"
|
become: yes
|
||||||
- "--include=*/"
|
become_user: stack
|
||||||
|
48
os_faults/tests/devstack/test_lib.py
Normal file
48
os_faults/tests/devstack/test_lib.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
# 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.
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from oslotest import base
|
||||||
|
|
||||||
|
import os_faults
|
||||||
|
|
||||||
|
|
||||||
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class TestOSFaultsLibrary(base.BaseTestCase):
|
||||||
|
def test_connection_stack_user(self):
|
||||||
|
cloud_config = {
|
||||||
|
'cloud_management': {
|
||||||
|
'driver': 'universal'
|
||||||
|
},
|
||||||
|
'node_discover': {
|
||||||
|
'driver': 'node_list',
|
||||||
|
'args': [
|
||||||
|
{
|
||||||
|
'ip': 'localhost',
|
||||||
|
'auth': {
|
||||||
|
'username': 'stack',
|
||||||
|
'private_key_file': 'os_faults_key'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG.info('# Create connection to the cloud')
|
||||||
|
cloud_management = os_faults.connect(cloud_config)
|
||||||
|
self.assertIsNotNone(cloud_management)
|
||||||
|
|
||||||
|
LOG.info('# Verify connection to the cloud')
|
||||||
|
cloud_management.verify()
|
@ -28,7 +28,7 @@ class TestOSInjectFaultUniversalDriver(test.TestCase):
|
|||||||
'os-faults-universal.yaml')
|
'os-faults-universal.yaml')
|
||||||
|
|
||||||
def test_connect(self):
|
def test_connect(self):
|
||||||
cmd = 'os-inject-fault -c %s -v' % self.CONFIG_FILE
|
cmd = 'os-inject-fault -dc %s -v' % self.CONFIG_FILE
|
||||||
|
|
||||||
command_stdout, command_stderr = processutils.execute(
|
command_stdout, command_stderr = processutils.execute(
|
||||||
*shlex.split(cmd))
|
*shlex.split(cmd))
|
||||||
@ -37,7 +37,7 @@ class TestOSInjectFaultUniversalDriver(test.TestCase):
|
|||||||
self.assertTrue(success)
|
self.assertTrue(success)
|
||||||
|
|
||||||
def test_restart_etcd(self):
|
def test_restart_etcd(self):
|
||||||
cmd = 'os-inject-fault -c %s restart etcd service' % self.CONFIG_FILE
|
cmd = 'os-inject-fault -dc %s restart etcd service' % self.CONFIG_FILE
|
||||||
|
|
||||||
command_stdout, command_stderr = processutils.execute(
|
command_stdout, command_stderr = processutils.execute(
|
||||||
*shlex.split(cmd))
|
*shlex.split(cmd))
|
||||||
|
5
tox.ini
5
tox.ini
@ -58,9 +58,14 @@ install_command = {[testenv:common-constraints]install_command}
|
|||||||
commands = {[testenv:cover]commands}
|
commands = {[testenv:cover]commands}
|
||||||
|
|
||||||
[testenv:devstack]
|
[testenv:devstack]
|
||||||
|
# to execute the tests:
|
||||||
|
# 1) create SSH key in os-faults folder: ssh-keygen -t rsa -f os_faults_key -N ''
|
||||||
|
# 2) copy public key into authorized_keys of user stack: cat os_faults_key.pub >> ~/.ssh/authorized_keys
|
||||||
|
# 3) run tests normally: tox -e devstack
|
||||||
basepython = python3
|
basepython = python3
|
||||||
setenv = {[testenv]setenv}
|
setenv = {[testenv]setenv}
|
||||||
OS_TEST_PATH=./os_faults/tests/devstack
|
OS_TEST_PATH=./os_faults/tests/devstack
|
||||||
|
OS_DEBUG=True
|
||||||
deps = {[testenv]deps}
|
deps = {[testenv]deps}
|
||||||
extras =
|
extras =
|
||||||
commands =
|
commands =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user