Add overcloud validate command

Change-Id: Idb42cbe4c90860b545f03e0a36de9e53d441c064
This commit is contained in:
Imre Farkas 2015-06-03 06:25:58 -04:00
parent abbaad4412
commit d67e483c13
6 changed files with 188 additions and 0 deletions

View File

@ -0,0 +1,30 @@
# Copyright 2015 Red Hat, Inc.
#
# 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 mock
from openstackclient.tests import utils
class FakeClientWrapper(object):
pass
class TestOvercloudValidate(utils.TestCommand):
def setUp(self):
super(TestOvercloudValidate, self).setUp()
self.app.client_manager.auth_ref = mock.Mock(auth_token="TOKEN")
self.app.client_manager.rdomanager_oscplugin = FakeClientWrapper()

View File

@ -0,0 +1,73 @@
# Copyright 2015 Red Hat, Inc.
#
# 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 mock
from rdomanager_oscplugin.tests.v1.overcloud_validate import fakes
from rdomanager_oscplugin.v1 import overcloud_validate
class TestOvercloudValidate(fakes.TestOvercloudValidate):
def setUp(self):
super(TestOvercloudValidate, self).setUp()
# Get the command object to test
self.cmd = overcloud_validate.ValidateOvercloud(self.app, None)
@mock.patch('os.chdir')
@mock.patch('os.mkdir')
@mock.patch('os.stat')
@mock.patch('os.path.expanduser')
@mock.patch('rdomanager_oscplugin.utils.run_shell')
def test_validate_ok(self, mock_run_shell, mock_os_path_expanduser,
mock_os_stat, mock_os_mkdir, mock_os_chdir):
mock_os_stat.return_value = True
mock_os_path_expanduser.return_value = '/home/user'
argslist = ['--overcloud-auth-url', 'http://foo',
'--overcloud-admin-password', 'password',
'--tempest-args', 'bar']
verifylist = [
('overcloud_auth_url', 'http://foo'),
('overcloud_admin_password', 'password'),
('tempest_args', 'bar')
]
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
self.cmd.take_action(parsed_args)
mock_os_stat.assert_called_with('/home/user/tempest')
self.assertEqual(0, mock_os_mkdir.call_count)
mock_os_chdir.assert_called_with('/home/user/tempest')
mock_run_shell.assert_has_calls([
mock.call('/usr/share/openstack-tempest-kilo/tools/'
'configure-tempest-directory'),
mock.call('./tools/config_tempest.py --out etc/tempest.conf '
'--debug --create '
'identity.uri http://foo '
'compute.allow_tenant_isolation true '
'object-storage.operator_role SwiftOperator '
'identity.admin_password password '
'compute.build_timeout 500 '
'compute.image_ssh_user cirros '
'compute.ssh_user cirros '
'network.build_timeout 500 '
'volume.build_timeout 500 '
'scenario.ssh_user cirros'),
mock.call('./run_tempest.sh --no-virtual-env -- bar 2>&1 | '
'tee /home/user/tempest/tempest-run.log')
])

View File

@ -599,3 +599,7 @@ def create_cephx_key():
key = os.urandom(16)
header = struct.pack("<hiih", 1, int(time.time()), 0, len(key))
return base64.b64encode(header + key)
def run_shell(cmd):
return subprocess.check_call([cmd], shell=True)

View File

@ -0,0 +1,80 @@
# Copyright 2015 Red Hat, Inc.
#
# 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
import os
from cliff import command
from rdomanager_oscplugin import utils
class ValidateOvercloud(command.Command):
"""Validates the functionality of an overcloud using Tempest"""
auth_required = False
log = logging.getLogger(__name__ + ".ValidateOvercloud")
def _run_tempest(self, overcloud_auth_url, overcloud_admin_password,
tempest_args):
tempest_run_dir = os.path.join(os.path.expanduser("~"), "tempest")
try:
os.stat(tempest_run_dir)
except OSError:
os.mkdir(tempest_run_dir)
os.chdir(tempest_run_dir)
utils.run_shell('/usr/share/openstack-tempest-kilo/tools/'
'configure-tempest-directory')
utils.run_shell('./tools/config_tempest.py --out etc/tempest.conf '
'--debug --create '
'identity.uri %(auth_url)s '
'compute.allow_tenant_isolation true '
'object-storage.operator_role SwiftOperator '
'identity.admin_password %(admin_password)s '
'compute.build_timeout 500 '
'compute.image_ssh_user cirros '
'compute.ssh_user cirros '
'network.build_timeout 500 '
'volume.build_timeout 500 '
'scenario.ssh_user cirros' %
{'auth_url': overcloud_auth_url,
'admin_password': overcloud_admin_password})
full_tempest_args = '--no-virtual-env'
if tempest_args:
full_tempest_args = '%s -- %s' % (full_tempest_args, tempest_args)
log_file = os.path.join(tempest_run_dir, "tempest-run.log")
utils.run_shell('./run_tempest.sh %(tempest_args)s 2>&1 '
'| tee %(log_file)s' %
{'tempest_args': full_tempest_args,
'log_file': log_file})
def get_parser(self, prog_name):
parser = super(ValidateOvercloud, self).get_parser(prog_name)
parser.add_argument('--overcloud-auth-url', required=True)
parser.add_argument('--overcloud-admin-password', required=True)
parser.add_argument('--tempest-args')
return parser
def take_action(self, parsed_args):
self.log.debug("take_action(%s)" % parsed_args)
self._run_tempest(parsed_args.overcloud_auth_url,
parsed_args.overcloud_admin_password,
parsed_args.tempest_args)

View File

@ -66,4 +66,5 @@ openstack.rdomanager_oscplugin.v1 =
overcloud_node_delete = rdomanager_oscplugin.v1.overcloud_node:DeleteNode
overcloud_scale_stack = rdomanager_oscplugin.v1.overcloud_scale:ScaleOvercloud
overcloud_update_stack = rdomanager_oscplugin.v1.overcloud_update:UpdateOvercloud
overcloud_validate = rdomanager_oscplugin.v1.overcloud_validate:ValidateOvercloud
undercloud_install = rdomanager_oscplugin.v1.undercloud:InstallPlugin