From d67e483c1384c958352232e2e0c67b894e2296af Mon Sep 17 00:00:00 2001 From: Imre Farkas Date: Wed, 3 Jun 2015 06:25:58 -0400 Subject: [PATCH] Add overcloud validate command Change-Id: Idb42cbe4c90860b545f03e0a36de9e53d441c064 --- .../tests/v1/overcloud_validate/__init__.py | 0 .../tests/v1/overcloud_validate/fakes.py | 30 +++++++ .../test_overcloud_validate.py | 73 +++++++++++++++++ rdomanager_oscplugin/utils.py | 4 + rdomanager_oscplugin/v1/overcloud_validate.py | 80 +++++++++++++++++++ setup.cfg | 1 + 6 files changed, 188 insertions(+) create mode 100644 rdomanager_oscplugin/tests/v1/overcloud_validate/__init__.py create mode 100644 rdomanager_oscplugin/tests/v1/overcloud_validate/fakes.py create mode 100644 rdomanager_oscplugin/tests/v1/overcloud_validate/test_overcloud_validate.py create mode 100644 rdomanager_oscplugin/v1/overcloud_validate.py diff --git a/rdomanager_oscplugin/tests/v1/overcloud_validate/__init__.py b/rdomanager_oscplugin/tests/v1/overcloud_validate/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/rdomanager_oscplugin/tests/v1/overcloud_validate/fakes.py b/rdomanager_oscplugin/tests/v1/overcloud_validate/fakes.py new file mode 100644 index 000000000..f9879224e --- /dev/null +++ b/rdomanager_oscplugin/tests/v1/overcloud_validate/fakes.py @@ -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() diff --git a/rdomanager_oscplugin/tests/v1/overcloud_validate/test_overcloud_validate.py b/rdomanager_oscplugin/tests/v1/overcloud_validate/test_overcloud_validate.py new file mode 100644 index 000000000..d925d075c --- /dev/null +++ b/rdomanager_oscplugin/tests/v1/overcloud_validate/test_overcloud_validate.py @@ -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') + ]) diff --git a/rdomanager_oscplugin/utils.py b/rdomanager_oscplugin/utils.py index 90211b9ed..6f16a34af 100644 --- a/rdomanager_oscplugin/utils.py +++ b/rdomanager_oscplugin/utils.py @@ -599,3 +599,7 @@ def create_cephx_key(): key = os.urandom(16) header = struct.pack("&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) diff --git a/setup.cfg b/setup.cfg index 1e30ef258..d1591fcf6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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