From 31dead5e7632619d49925fc17308eb96db0da305 Mon Sep 17 00:00:00 2001 From: Alina Nesterova Date: Wed, 14 Dec 2016 14:16:30 +0400 Subject: [PATCH] Add new negative cli tests for node group templates Also include few minors in node group template update test Change-Id: I55fcb6b5942ca78b2dd1513949451fdd4cf1c40c --- sahara_tempest_plugin/tests/cli/base.py | 5 +- .../tests/cli/node_group_templates.py | 72 ++++++++++++++----- .../tests/cli/test_scenario.py | 5 +- 3 files changed, 60 insertions(+), 22 deletions(-) diff --git a/sahara_tempest_plugin/tests/cli/base.py b/sahara_tempest_plugin/tests/cli/base.py index e9648958..2b84662b 100644 --- a/sahara_tempest_plugin/tests/cli/base.py +++ b/sahara_tempest_plugin/tests/cli/base.py @@ -108,8 +108,7 @@ class ClientTestBase(base.ClientTestBase): def _get_cluster_status(self, cluster_name): status = None - show_cluster = self.listing_result(''.join(['cluster show ', - cluster_name])) + show_cluster = self.listing_result('cluster show %s' % cluster_name) for line in show_cluster: if line['Field'] == 'Status': status = line['Value'] @@ -146,7 +145,7 @@ class ClientTestBase(base.ClientTestBase): # if name exists in the command "type list" than tests should fail with fixtures.Timeout(300, gentle=True): while True: - list_of_types = self.listing_result(''.join([type, ' list'])) + list_of_types = self.listing_result('%s list' % type) list_names = [p['Name'] for p in list_of_types] if name in list_names: name_exist = True diff --git a/sahara_tempest_plugin/tests/cli/node_group_templates.py b/sahara_tempest_plugin/tests/cli/node_group_templates.py index c58b01a9..925213a2 100644 --- a/sahara_tempest_plugin/tests/cli/node_group_templates.py +++ b/sahara_tempest_plugin/tests/cli/node_group_templates.py @@ -10,9 +10,10 @@ # License for the specific language governing permissions and limitations # under the License. -from sahara_tempest_plugin.tests.cli import base from tempest.lib.common.utils import data_utils +from sahara_tempest_plugin.tests.cli import base + class SaharaNodeGroupCLITest(base.ClientTestBase): @@ -31,17 +32,15 @@ class SaharaNodeGroupCLITest(base.ClientTestBase): node_group_name = data_utils.rand_name(ng_type) flags = ("%(ngt_name)s %(plugin)s %(plugin-version)s " "%(processes)s %(flavor)s %(floating-pool)s" - % {'floating-pool': ''.join([' --floating-ip-pool ', - id_net_pool]), - 'flavor': ''.join([' --flavor ', flavor_id]), + % {'floating-pool': ' --floating-ip-pool %s' % id_net_pool, + 'flavor': ' --flavor %s' % flavor_id, 'processes': ' --processes datanode', - 'plugin-version': - ''.join([' --plugin-version ', plugin['Versions']]), - 'plugin': ''.join([' --plugin ', plugin['Name']]), - 'ngt_name': ''.join(['--name ', node_group_name])}) + 'plugin-version': ' --plugin-version %s' + % plugin['Versions'], + 'plugin': ' --plugin %s' % plugin['Name'], + 'ngt_name': '--name %s' % node_group_name}) self.assertTableStruct( - self.listing_result(''.join(['node group template create ', - flags])), [ + self.listing_result('node group template create %s' % flags), [ 'Field', 'Value' ]) @@ -49,17 +48,32 @@ class SaharaNodeGroupCLITest(base.ClientTestBase): def openstack_node_group_template_show(self, node_group_name): self.find_in_listing( - self.listing_result( - ''.join(['node group template show ', node_group_name])), + self.listing_result('node group template show %s' + % node_group_name), node_group_name) - def openstack_node_group_template_update(self, node_group_name): - new_node_group_name = ''.join([node_group_name, '1']) + def openstack_node_group_template_update(self, node_group_name, + update_field=None): + """Update node group template with necessary parameters + Args: + node_group_name (str): name of node group to update + update_field (str): param how to update the node group. Using + this arg, there are several available updates of node group: + name, public/private, protected/unprotected + """ + new_node_group_name = None + cmd = 'node group template update %s' % node_group_name + if update_field == 'name': + new_node_group_name = data_utils.rand_name(node_group_name) + update_cmd = '--%s %s' % (update_field, new_node_group_name) + elif update_field: + # here we check only updating with public/protected flags for now + update_cmd = '--%s' % update_field + else: + # if update_field is None, update_command should be empty + update_cmd = '' self.assertTableStruct( - self.listing_result( - ''.join(['node group template update --name ', - new_node_group_name, ' ', - node_group_name])), [ + self.listing_result('%s %s' % (cmd, update_cmd)), [ 'Field', 'Value' ]) @@ -67,3 +81,25 @@ class SaharaNodeGroupCLITest(base.ClientTestBase): def openstack_node_group_template_delete(self, node_group_name): self.check_if_delete('node group template', node_group_name) + + def negative_delete_removed_node_group(self, node_group_name): + """Test to remove already deleted node group template""" + command_to_execute = 'node group template delete' + self.check_negative_scenarios(base.TEMPEST_ERROR_MESSAGE, + command_to_execute, + node_group_name) + + def negative_try_to_delete_protected_node_group(self, node_group_name): + """Test to delete protected node group template""" + self.openstack_node_group_template_update(node_group_name, + update_field='protected') + error_message = ("NodeGroupTemplate with id '%s' could not be deleted " + "because it's marked as protected" + % self._get_resource_id('node group template', + node_group_name)) + command_to_execute = 'node group template delete' + self.check_negative_scenarios(error_message, + command_to_execute, + node_group_name) + self.openstack_node_group_template_update(node_group_name, + update_field='unprotected') diff --git a/sahara_tempest_plugin/tests/cli/test_scenario.py b/sahara_tempest_plugin/tests/cli/test_scenario.py index 41ae425a..858601b8 100644 --- a/sahara_tempest_plugin/tests/cli/test_scenario.py +++ b/sahara_tempest_plugin/tests/cli/test_scenario.py @@ -54,15 +54,18 @@ class Scenario(images.SaharaImageCLITest, worker_ngt) self.openstack_node_group_template_list() - new_master_ngt = self.openstack_node_group_template_update(master_ngt) + new_master_ngt = self.openstack_node_group_template_update( + master_ngt, update_field='name') self.addCleanup(self.delete_resource, 'node group template', new_master_ngt) self.openstack_node_group_template_show(new_master_ngt) self.openstack_node_group_template_delete(new_master_ngt) + self.negative_try_to_delete_protected_node_group(worker_ngt) self.openstack_node_group_template_delete(worker_ngt) self.wait_for_resource_deletion(new_master_ngt, 'node group template') self.wait_for_resource_deletion(worker_ngt, 'node group template') + self.negative_delete_removed_node_group(worker_ngt) def test_cluster_template_cli(self): ng_master = (