From 3b0f8ad21f83f294b9fe7a04e20aadd487a441ec Mon Sep 17 00:00:00 2001 From: rabi Date: Tue, 24 May 2016 10:18:33 +0530 Subject: [PATCH] Add integration tests for admin actions Add integration tests for super admin actions. Change-Id: I277f23800274729cf7128fdcb4521e4b221233cf Partial-Bug: #1466694 --- heat_integrationtests/common/config.py | 3 + heat_integrationtests/common/test.py | 29 +++-- .../functional/functional_base.py | 1 - .../functional/test_admin_actions.py | 101 ++++++++++++++++++ .../functional/test_encryption_vol_type.py | 12 +-- .../heat_integrationtests.conf.sample | 3 + .../scenario/scenario_base.py | 2 - 7 files changed, 131 insertions(+), 20 deletions(-) create mode 100644 heat_integrationtests/functional/test_admin_actions.py diff --git a/heat_integrationtests/common/config.py b/heat_integrationtests/common/config.py index e99d0346b0..0397953391 100644 --- a/heat_integrationtests/common/config.py +++ b/heat_integrationtests/common/config.py @@ -35,6 +35,9 @@ IntegrationTestGroup = [ default=(os.environ.get('OS_PROJECT_NAME') or os.environ.get('OS_TENANT_NAME')), help="Tenant name to use for API requests."), + cfg.StrOpt('admin_tenant_name', + default='admin', + help="Admin tenant name to use for admin API requests."), cfg.StrOpt('auth_url', default=os.environ.get('OS_AUTH_URL'), help="Full URI of the OpenStack Identity API (Keystone)"), diff --git a/heat_integrationtests/common/test.py b/heat_integrationtests/common/test.py index 16d5920975..c864d3b7ad 100644 --- a/heat_integrationtests/common/test.py +++ b/heat_integrationtests/common/test.py @@ -81,8 +81,16 @@ class HeatIntegrationTest(testscenarios.WithScenarios, 'No username configured') self.assertIsNotNone(self.conf.password, 'No password configured') + self.setup_clients(self.conf) + self.useFixture(fixtures.FakeLogger(format=_LOG_FORMAT)) + self.updated_time = {} + if self.conf.disable_ssl_certificate_validation: + self.verify_cert = False + else: + self.verify_cert = self.conf.ca_file or True - self.manager = clients.ClientManager(self.conf) + def setup_clients(self, conf): + self.manager = clients.ClientManager(conf) self.identity_client = self.manager.identity_client self.orchestration_client = self.manager.orchestration_client self.compute_client = self.manager.compute_client @@ -90,12 +98,19 @@ class HeatIntegrationTest(testscenarios.WithScenarios, self.volume_client = self.manager.volume_client self.object_client = self.manager.object_client self.metering_client = self.manager.metering_client - self.useFixture(fixtures.FakeLogger(format=_LOG_FORMAT)) - self.updated_time = {} - if self.conf.disable_ssl_certificate_validation: - self.verify_cert = False - else: - self.verify_cert = self.conf.ca_file or True + + self.client = self.orchestration_client + + def setup_clients_for_admin(self): + self.assertIsNotNone(self.conf.admin_username, + 'No admin username configured') + self.assertIsNotNone(self.conf.admin_password, + 'No admin password configured') + conf = config.init_conf() + conf.username = self.conf.admin_username + conf.password = self.conf.admin_password + conf.tenant_name = self.conf.admin_tenant_name + self.setup_clients(conf) def get_remote_client(self, server_or_ip, username, private_key=None): if isinstance(server_or_ip, six.string_types): diff --git a/heat_integrationtests/functional/functional_base.py b/heat_integrationtests/functional/functional_base.py index 9f760110c4..73ccf1d4bc 100644 --- a/heat_integrationtests/functional/functional_base.py +++ b/heat_integrationtests/functional/functional_base.py @@ -20,7 +20,6 @@ class FunctionalTestsBase(test.HeatIntegrationTest): def setUp(self): super(FunctionalTestsBase, self).setUp() self.check_skip() - self.client = self.orchestration_client def check_skip(self): test_cls_name = reflection.get_class_name(self, fully_qualified=False) diff --git a/heat_integrationtests/functional/test_admin_actions.py b/heat_integrationtests/functional/test_admin_actions.py new file mode 100644 index 0000000000..2c9ff6e440 --- /dev/null +++ b/heat_integrationtests/functional/test_admin_actions.py @@ -0,0 +1,101 @@ +# 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 heat_integrationtests.functional import functional_base + +# Simple stack +test_template = { + 'heat_template_version': '2013-05-23', + 'resources': { + 'test1': { + 'type': 'OS::Heat::TestResource', + 'properties': { + 'value': 'Test1' + } + } + } +} + +# Nested stack +rsg_template = { + 'heat_template_version': '2013-05-23', + 'resources': { + 'random_group': { + 'type': 'OS::Heat::ResourceGroup', + 'properties': { + 'count': 2, + 'resource_def': { + 'type': 'OS::Heat::RandomString', + 'properties': { + 'length': 30, + 'salt': 'initial' + } + } + } + } + } +} + + +class AdminActionsTest(functional_base.FunctionalTestsBase): + + def setUp(self): + super(AdminActionsTest, self).setUp() + if not self.conf.admin_username or not self.conf.admin_password: + self.skipTest('No admin creds found, skipping') + + def create_stack_setup_admin_client(self, template=test_template): + # Create the stack with the default user + self.stack_identifier = self.stack_create(template=template) + + # Setup admin clients + self.setup_clients_for_admin() + + def test_admin_simple_stack_actions(self): + self.create_stack_setup_admin_client() + + updated_template = test_template.copy() + props = updated_template['resources']['test1']['properties'] + props['value'] = 'new_value' + + # Update, suspend and resume stack + self.update_stack(self.stack_identifier, + template=updated_template) + self.stack_suspend(self.stack_identifier) + self.stack_resume(self.stack_identifier) + + # List stack resources + initial_resources = {'test1': 'OS::Heat::TestResource'} + self.assertEqual(initial_resources, + self.list_resources(self.stack_identifier)) + # Delete stack + self._stack_delete(self.stack_identifier) + + def test_admin_complex_stack_actions(self): + self.create_stack_setup_admin_client(template=rsg_template) + + updated_template = rsg_template.copy() + props = updated_template['resources']['random_group']['properties'] + props['count'] = 3 + + # Update, suspend and resume stack + self.update_stack(self.stack_identifier, + template=updated_template) + self.stack_suspend(self.stack_identifier) + self.stack_resume(self.stack_identifier) + + # List stack resources + resources = {'random_group': 'OS::Heat::ResourceGroup'} + self.assertEqual(resources, + self.list_resources(self.stack_identifier)) + # Delete stack + self._stack_delete(self.stack_identifier) diff --git a/heat_integrationtests/functional/test_encryption_vol_type.py b/heat_integrationtests/functional/test_encryption_vol_type.py index ed4924988f..b34b094abf 100644 --- a/heat_integrationtests/functional/test_encryption_vol_type.py +++ b/heat_integrationtests/functional/test_encryption_vol_type.py @@ -11,8 +11,6 @@ # under the License. -from heat_integrationtests.common import clients -from heat_integrationtests.common import config from heat_integrationtests.functional import functional_base test_encryption_vol_type = { @@ -44,16 +42,10 @@ class EncryptionVolTypeTest(functional_base.FunctionalTestsBase): super(EncryptionVolTypeTest, self).setUp() if not self.conf.admin_username or not self.conf.admin_password: self.skipTest('No admin creds found, skipping') - self.conf = config.init_conf() # cinder security policy usage of volume type is limited # to being used by administrators only. - # Temporarily switch to admin - self.conf.username = self.conf.admin_username - self.conf.password = self.conf.admin_password - self.conf.tenant_name = 'admin' - self.manager = clients.ClientManager(self.conf) - self.client = self.manager.orchestration_client - self.volume_client = self.manager.volume_client + # Switch to admin + self.setup_clients_for_admin() def check_stack(self, sid): vt = 'my_volume_type' diff --git a/heat_integrationtests/heat_integrationtests.conf.sample b/heat_integrationtests/heat_integrationtests.conf.sample index b7a0f19d7b..59ff0db7df 100644 --- a/heat_integrationtests/heat_integrationtests.conf.sample +++ b/heat_integrationtests/heat_integrationtests.conf.sample @@ -19,6 +19,9 @@ # Tenant name to use for API requests. (string value) #tenant_name = +# Admin tenant name to use for admin API requests. (string value) +#admin_tenant_name = admin + # Full URI of the OpenStack Identity API (Keystone) (string value) #auth_url = diff --git a/heat_integrationtests/scenario/scenario_base.py b/heat_integrationtests/scenario/scenario_base.py index d41c9a1c95..df86e9eecd 100644 --- a/heat_integrationtests/scenario/scenario_base.py +++ b/heat_integrationtests/scenario/scenario_base.py @@ -21,8 +21,6 @@ class ScenarioTestsBase(test.HeatIntegrationTest): def setUp(self): super(ScenarioTestsBase, self).setUp() self.check_skip() - - self.client = self.orchestration_client self.sub_dir = 'templates' self.assign_keypair()