From a5f9c33e110a60358d660f6cc9f4e7ea31a7e4cd Mon Sep 17 00:00:00 2001 From: Volodymyr Rozhanskyy Date: Mon, 17 Oct 2016 10:38:32 +0300 Subject: [PATCH] added cleanup actions after for manila verify Change-Id: I06c770d2e5ae3cbccd0d6f2099a5e0a439a5037c --- plugin_test/helpers/manila_service_verify.py | 63 ++++++++++++++------ plugin_test/helpers/openstack.py | 28 ++++++++- plugin_test/helpers/os_manila_actions.py | 59 ++++++++++++++++-- 3 files changed, 127 insertions(+), 23 deletions(-) diff --git a/plugin_test/helpers/manila_service_verify.py b/plugin_test/helpers/manila_service_verify.py index 8cd946a..5b90ede 100644 --- a/plugin_test/helpers/manila_service_verify.py +++ b/plugin_test/helpers/manila_service_verify.py @@ -14,7 +14,6 @@ from fuelweb_test.helpers import os_actions from fuelweb_test import logger -from fuelweb_test import logwrap from fuelweb_test.settings import SERVTEST_PASSWORD from fuelweb_test.settings import SERVTEST_TENANT from fuelweb_test.settings import SERVTEST_USERNAME @@ -24,11 +23,11 @@ from helpers import os_manila_actions from proboscis import asserts - class TestPluginCheck(object): """Test suite for GCS plugin check.""" def __init__(self, obj): + # type: (object) -> object """Create Test client for run tests. :param obj: Test case object @@ -36,39 +35,48 @@ class TestPluginCheck(object): self.obj = obj cluster_id = self.obj.fuel_web.get_last_created_cluster() + logger.info('#' * 10 + "Cluster ID: " + str(cluster_id)) ip = self.obj.fuel_web.get_public_vip(cluster_id) + logger.info('#' * 10 + "IP : " + str(ip)) + self.os_conn = os_actions.OpenStackActions( ip, SERVTEST_USERNAME, SERVTEST_PASSWORD, SERVTEST_TENANT) self.manila_conn = os_manila_actions.ManilaActions( ip, SERVTEST_USERNAME, SERVTEST_PASSWORD, SERVTEST_TENANT) - @logwrap - def verify_share_mount(self, ssh_client, test_share): + def verify_share_mount(self, ssh_client, test_share, share_prot): # create mounting point + logger.info('#' * 10 + "Testing share protocol is : " + share_prot) mounting_point = '/mnt/share1' cmd = "sudo mkdir {0}".format(mounting_point) + logger.info('#' * 10 + "Executing :" + cmd) openstack.execute(ssh_client, cmd) - - # mounting point - cmd2 = "sudo mount -t nfs {1} {0}".format(mounting_point, - test_share.export_location) - + # mounting share + cmd2 = "sudo mount -t " + share_prot + ' {1} {0}'.format(mounting_point, + test_share.export_location) + logger.info('#' * 10 + "Executing :" + cmd2) output_1 = openstack.execute(ssh_client, cmd2) - cmd3 = "echo Share is created > {0}/file.txt ".format(mounting_point) - openstack.execute(ssh_client, cmd3) asserts.assert_true(output_1['exit_code'] == 0, message="Failed to mount network share") - + # create file on share + cmd3 = "echo Share is created|sudo tee --append {0}/file.txt".\ + format(mounting_point) + logger.info('#' * 10 + "Executing :" + cmd3) + output_1 = openstack.execute(ssh_client, cmd3) + asserts.assert_true(output_1['exit_code'] == 0, + message="Failed to create file on network share") + # read created file cmd4 = "cat /mnt/share1/file.txt ".format(mounting_point) + logger.info('#' * 10 + "Executing :" + cmd4) output_2 = openstack.execute(ssh_client, cmd4) asserts.assert_true( 'Share is created' in output_2['stdout'], "R/W access for {0} verified".format(test_share.export_location)) logger.info('#' * 10 + "Network share mounted and work as expected") - @logwrap - def verify_manila_functionality(self): + def verify_manila_functionality(self, share_prot='nfs', clean_up=True, + backend='generic'): """This method do basic functionality check : * creates share-type, share network, share, access_rule ; @@ -83,7 +91,12 @@ class TestPluginCheck(object): type_name='default_share_type') asserts.assert_equal(share_type.name, 'default_share_type', message="Failed to create default share type") + self.manila_conn.set_share_type_extrascpecs( + share_type.name, + {'share_backend_name': backend} + ) + logger.info('#'*10 + "share type id : " + str(share_type.id)) # get internal id of admin_internal_net network and subnet id # neutron net-list | grep 'admin_internal_net' network = self.os_conn.get_network('admin_internal_net') @@ -93,7 +106,8 @@ class TestPluginCheck(object): logger.info('#'*10 + "Create manila share network" + '#' * 10) s_net = self.manila_conn.create_share_network( net_id=network.get('id'), subnet_id=network.get('subnets')) - asserts.assert_equal(s_net.name, 'Test Share network', + logger.info('#' * 10 + "share type id : " + str(s_net.name)) + asserts.assert_equal(s_net.name, 'test_share_network', message="Failed to create manila share network") share_network_id = s_net.id @@ -102,6 +116,7 @@ class TestPluginCheck(object): # create share and wait until it will becomes available logger.info('#'*10 + "Create manila share" + '#' * 10) test_share = self.manila_conn.create_basic_share( + protocol=share_prot, share_name='test_share', network=share_network_id) asserts.assert_equal(test_share.name, 'test_share', message="Failed to create manila share") @@ -113,7 +128,7 @@ class TestPluginCheck(object): self.manila_conn.add_acc_rule(share_id=test_share, rule='0.0.0.0/0') logger.info('#'*10 + "Create and configure instance to verify share") - test_instance = openstack.create_instance(self.os_conn) + test_instance, sec_group = openstack.create_instance(self.os_conn) openstack.verify_instance_state(self.os_conn, 'test_share_server') logger.info('#'*10 + "Assign floating ip for server") @@ -127,4 +142,18 @@ class TestPluginCheck(object): msg = 'New instance started floating ip is: {0}'.format(fl_ip) logger.info(msg) - self.verify_share_mount(ssh_client, test_share) + self.verify_share_mount(ssh_client, test_share, share_prot) + + if clean_up: + logger.info('#'*10 + "Cleanup test objects" + '#'*10) + logger.info('#' * 10 + "Delete test instance") + openstack.delete_instance(self.os_conn, test_instance) + logger.info('#' * 10 + "Delete test security group") + openstack.delete_sec_group(self.os_conn, sec_group.id) + + logger.info('#' * 10 + "Delete test share") + self.manila_conn.delete_all_shares() + logger.info('#' * 10 + "Delete test share network") + self.manila_conn.delete_all_share_networks() + logger.info('#' * 10 + "Delete test share type ") + self.manila_conn.delete_all_share_types() diff --git a/plugin_test/helpers/openstack.py b/plugin_test/helpers/openstack.py index 0782d01..b8b8afa 100644 --- a/plugin_test/helpers/openstack.py +++ b/plugin_test/helpers/openstack.py @@ -55,7 +55,7 @@ def create_instance(os_conn, timeout=200, image=image_id ) - return server + return server, sec_group def verify_instance_state(os_conn, inst_name, expected_state='ACTIVE'): @@ -135,3 +135,29 @@ def execute(ssh_client, command): result['stdout'] = channel.recv(1024) result['stderr'] = channel.recv_stderr(1024) return result + + +def delete_instance(os_conn, test_instance): + """Delete Instance""" + + os_conn.delete_instance(test_instance) + wait(lambda: os_conn.is_srv_deleted(test_instance), timeout=200, + timeout_msg='Instance was not deleted.') + + +def delete_sec_group(os_conn, sec_group): + """Delete security group""" + try: + os_conn.nova.security_groups.delete(sec_group) + except Exception as exc: + logger.info( + 'Security group {0} was not deleted. {1}'.format( + sec_group, exc)) + + +def delete_float_ip(os_conn, ip): + """Delete Floating IP""" + + os_conn.delete_instance(ip) + wait(lambda: os_conn.is_srv_deleted(ip), timeout=200, + timeout_msg='Floating IP was not deleted.') diff --git a/plugin_test/helpers/os_manila_actions.py b/plugin_test/helpers/os_manila_actions.py index bc74f5d..f382203 100644 --- a/plugin_test/helpers/os_manila_actions.py +++ b/plugin_test/helpers/os_manila_actions.py @@ -22,6 +22,7 @@ from keystoneclient.auth.identity import v2 from manilaclient.v2 import client from time import sleep + class ManilaActions(common.Common): """Manila client class to operate with Manila API""" @@ -60,11 +61,11 @@ class ManilaActions(common.Common): def create_share_network(self, net_id=None, subnet_id=None, - name='Test Share network', + name='test_share_network', description='For testing purpose' ): """Create share network""" - + sleep(10) if self.get_share_network(name) is None: manila_client = client.Client('2', session=self.__keystone_ses) share_network = manila_client.share_networks.create( @@ -100,9 +101,11 @@ class ManilaActions(common.Common): def create_share_type(self, type_name='Test_share_type', handle_serv=True, snap_sup=True, - public_share=True): + public_share=True + ): """Create share type""" + sleep(10) if self.get_share_type(type_name) is None: manila_client = client.Client('2', session=self.__keystone_ses) manila_client.share_types.create( @@ -121,7 +124,12 @@ class ManilaActions(common.Common): return share return None - def create_basic_share(self, protocol='NFS', + def set_share_type_extrascpecs(self, share_type, extra_specs): + """set extra specs for share type""" + share_type = self.get_share_type(share_type) + share_type.set_keys(extra_specs) + + def create_basic_share(self, protocol='nfs', size=1, share_name='Default_test_share', share_type='default_share_type', @@ -129,7 +137,7 @@ class ManilaActions(common.Common): public_share=True): """Create share""" - sleep(20) + sleep(10) manila_client = client.Client('2', session=self.__keystone_ses) share = manila_client.shares.create( share_proto=protocol, @@ -163,3 +171,44 @@ class ManilaActions(common.Common): access=rule, access_level=acc_level) return manila_client.shares.access_list(share_id) + def delete_share(self, share): + manila_client = client.Client('2', session=self.__keystone_ses) + s = self.get_share(share) + print(s) + manila_client.shares.delete(share) + wait(lambda: self.get_shares_list() is None, + timeout=60, interval=5, + timeout_msg="Shares didn't deleted") + + def delete_share_network(self, net_id): + manila_client = client.Client('2', session=self.__keystone_ses) + manila_client.share_networks.delete(net_id) + + def delete_share_type(self, type_id): + manila_client = client.Client('2', session=self.__keystone_ses) + manila_client.share_types.delete(type_id) + + def delete_all_shares(self): + manila_client = client.Client('2', session=self.__keystone_ses) + for shares in manila_client.shares.list(): + manila_client.shares.delete(shares.id) + wait(lambda: manila_client.shares.list() == [], + timeout=120, interval=5, + timeout_msg="all shares didn't deleted {0}".format( + manila_client.share_networks.list())) + + def delete_all_share_networks(self): + manila_client = client.Client('2', session=self.__keystone_ses) + for network in manila_client.share_networks.list(): + manila_client.share_networks.delete(network.id) + wait(lambda: manila_client.share_networks.list() == [], + timeout=120, interval=5, + timeout_msg="all networks didn't deleted") + + def delete_all_share_types(self): + manila_client = client.Client('2', session=self.__keystone_ses) + for type in manila_client.share_types.list(): + manila_client.share_types.delete(type.id) + wait(lambda: manila_client.share_types.list() == [], + timeout=120, interval=5, + timeout_msg="All share types didn't deleted")