From 5769763094a312b64826a5cf8fc8317a729e21cb Mon Sep 17 00:00:00 2001 From: Simon Van den Bossche Date: Mon, 9 Apr 2018 11:12:39 +0200 Subject: [PATCH 1/2] Introduction of nbd-integration test excluded, as for now no automation lib calls have been implemented --- .../iscsi/nbd_fio-exclude/__init__.py | 0 ci/scenarios/iscsi/nbd_fio-exclude/main.py | 162 ++++++++++++++++++ 2 files changed, 162 insertions(+) create mode 100644 ci/scenarios/iscsi/nbd_fio-exclude/__init__.py create mode 100644 ci/scenarios/iscsi/nbd_fio-exclude/main.py diff --git a/ci/scenarios/iscsi/nbd_fio-exclude/__init__.py b/ci/scenarios/iscsi/nbd_fio-exclude/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ci/scenarios/iscsi/nbd_fio-exclude/main.py b/ci/scenarios/iscsi/nbd_fio-exclude/main.py new file mode 100644 index 0000000..65ae528 --- /dev/null +++ b/ci/scenarios/iscsi/nbd_fio-exclude/main.py @@ -0,0 +1,162 @@ +# Copyright (C) 2018 iNuron NV +# +# This file is part of Open vStorage Open Source Edition (OSE), +# as available from +# +# http://www.openvstorage.org and +# http://www.openvstorage.com. +# +# This file is free software; you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License v3 (GNU AGPLv3) +# as published by the Free Software Foundation, in version 3 as it comes +# in the LICENSE.txt file of the Open vStorage OSE distribution. +# +# Open vStorage is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY of any kind. +""" +NBD integtration test +""" + +import os +import random +from ci.api_lib.helpers.vdisk import VDiskHelper +from ci.api_lib.helpers.vpool import VPoolHelper +from ci.api_lib.setup.vdisk import VDiskSetup +from ci.api_lib.remove.vdisk import VDiskRemover +from ci.scenario_helpers.ci_constants import CIConstants +from ci.scenario_helpers.data_writing import DataWriter +from ovs.extensions.generic.logger import Logger +from ovs_extensions.generic.sshclient import SSHClient + +# todo if this test is to be used, change paths by api_lib calls +from source.tools.nbd import NBDManager +from source.tools.servicefactory import ServiceFactory + + +class NBDIntegration(CIConstants): + """ + Integration tests for NBD io + """ + + CASE_TYPE = 'AT_QUICK' + TEST_NAME = "nbd_integration_test" + LOGGER = Logger('scenario-{0}'.format(TEST_NAME)) + VDISK_NAME = 'vdisk_nbd_integration_test' + + AMOUNT_TO_WRITE = 5 * 1024 + VDISK_SIZE = 100 * 1024 + DEFAULT_PORT = 26203 + + ip = '10.100.196.1' + + def __init__(self): + cluster_info = self.setup() + + self.vd = VDiskHelper.get_vdisk_by_guid(cluster_info.get('target_vdisk')) + credentials = 'tcp://root:rooter@{0}:{1}/{2}'.format(self.ip, self.DEFAULT_PORT, self.VDISK_NAME) + + # Initialize NBD devices + self.mgr = NBDManager() + self.nbd_path = self.mgr.create_service(credentials) # Create the service + self.nbd = self.nbd_path.lstrip('/dev/') # NBD number + self.mgr.start_device(nbd_path=self.nbd_path) # Start the service + # Parameters for testing + self.client = SSHClient('127.0.0.1', username='root') + + # For testing fio, a job file is req. This file is stored temp. on this location + self.fio_target_file_path = '/tmp/ovs_integration_test_{0}_output'.format(self.nbd) + + def main(self, blocked): + """ + Run all required methods for the test. + :param blocked: was the test blocked by other test? + :type blocked: bool + :return: results of test + :rtype: dict + """ + + self.LOGGER.info('Starting') + _ = blocked + return self.start_test() + + def start_test(self): + # type: () -> None + """ + Start test and clean up file and config mgmt afterwards + :return: + """ + try: + self.run_test() + except Exception as ex: + self.LOGGER.exception(ex) + finally: # Whatever happens, clean up + self.cleanup() + + @classmethod + def setup(cls): + # type: () -> Dict[str, VDisk] + """ + Setup environment for testing + :return: Dict + """ + + # target selection: storagerouter ip + vpool, vdisk creation + vpool = None + for vp in VPoolHelper.get_vpools(): + if len(vp.storagedrivers) >= 1: + vpool = vp + break + assert vpool is not None, 'Found no vpool' + + vd = VDiskSetup.create_vdisk(size=cls.VDISK_SIZE, + storagerouter_ip=cls.ip, + vdisk_name=cls.VDISK_NAME, + vpool_name=vpool.name) + assert vd is not None, 'Found no vdisk' + + cluster_info = {'target_vdisk': vd} # Store in dict for consistency accros tests + return cluster_info + + def run_test(self): + # type: (None) -> None + """ + Start the test + :return: None + """ + if not ServiceFactory.get_manager().get_service_status('ovs-{0}-{1}'.format(self.nbd, self.VDISK_NAME), client=self.client) == 'active': + raise RuntimeError('Service state is not marked as "active"') + + screen_names = [] + fio_config = {'io_size': self.AMOUNT_TO_WRITE, 'configuration': random.choice(self.DATA_TEST_CASES), 'bs': '4k'} + + try: + screen_names, output_files = DataWriter.write_data_fio(client=self.client, + fio_configuration=fio_config, + file_locations=[self.fio_target_file_path]) + finally: + for screen_name in screen_names: + self.client.run(['screen', '-S', screen_name, '-X', 'quit']) + + def cleanup(self): + # type: () -> None + """ + Clean up created service in configmanagement and file system + :return: None + """ + self.mgr.destroy_device(nbd_path=self.nbd_path) + VDiskRemover.remove_vdisk(self.vd.guid) + + +def run(blocked=False): + """ + Run a test + + :param blocked: was the test blocked by other test? + :return: results of test + :rtype: dict + """ + return NBDIntegration().main(blocked) + + +if __name__ == "__main__": + run() From f028571a3b7e13fe3d79baa000c839b9e184b240 Mon Sep 17 00:00:00 2001 From: Simon Van den Bossche Date: Mon, 9 Apr 2018 11:19:33 +0200 Subject: [PATCH 2/2] more comments and cleanup --- ci/scenarios/iscsi/nbd_fio-exclude/main.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/ci/scenarios/iscsi/nbd_fio-exclude/main.py b/ci/scenarios/iscsi/nbd_fio-exclude/main.py index 65ae528..099208a 100644 --- a/ci/scenarios/iscsi/nbd_fio-exclude/main.py +++ b/ci/scenarios/iscsi/nbd_fio-exclude/main.py @@ -17,7 +17,6 @@ NBD integtration test """ -import os import random from ci.api_lib.helpers.vdisk import VDiskHelper from ci.api_lib.helpers.vpool import VPoolHelper @@ -47,7 +46,7 @@ class NBDIntegration(CIConstants): VDISK_SIZE = 100 * 1024 DEFAULT_PORT = 26203 - ip = '10.100.196.1' + ip = '10.100.196.1' # todo change ip to node with nbd installed on local env def __init__(self): cluster_info = self.setup() @@ -55,15 +54,15 @@ def __init__(self): self.vd = VDiskHelper.get_vdisk_by_guid(cluster_info.get('target_vdisk')) credentials = 'tcp://root:rooter@{0}:{1}/{2}'.format(self.ip, self.DEFAULT_PORT, self.VDISK_NAME) - # Initialize NBD devices + # Initialize NBD device self.mgr = NBDManager() self.nbd_path = self.mgr.create_service(credentials) # Create the service self.nbd = self.nbd_path.lstrip('/dev/') # NBD number self.mgr.start_device(nbd_path=self.nbd_path) # Start the service - # Parameters for testing - self.client = SSHClient('127.0.0.1', username='root') - # For testing fio, a job file is req. This file is stored temp. on this location + self.local_client = SSHClient('127.0.0.1', username='root') + + # Fio output file path self.fio_target_file_path = '/tmp/ovs_integration_test_{0}_output'.format(self.nbd) def main(self, blocked): @@ -94,7 +93,7 @@ def start_test(self): @classmethod def setup(cls): - # type: () -> Dict[str, VDisk] + # type: () -> Dict[str, str] """ Setup environment for testing :return: Dict @@ -123,19 +122,19 @@ def run_test(self): Start the test :return: None """ - if not ServiceFactory.get_manager().get_service_status('ovs-{0}-{1}'.format(self.nbd, self.VDISK_NAME), client=self.client) == 'active': + if not ServiceFactory.get_manager().get_service_status('ovs-{0}-{1}'.format(self.nbd, self.VDISK_NAME), client=self.local_client) == 'active': raise RuntimeError('Service state is not marked as "active"') screen_names = [] fio_config = {'io_size': self.AMOUNT_TO_WRITE, 'configuration': random.choice(self.DATA_TEST_CASES), 'bs': '4k'} try: - screen_names, output_files = DataWriter.write_data_fio(client=self.client, + screen_names, output_files = DataWriter.write_data_fio(client=self.local_client, fio_configuration=fio_config, file_locations=[self.fio_target_file_path]) finally: for screen_name in screen_names: - self.client.run(['screen', '-S', screen_name, '-X', 'quit']) + self.local_client.run(['screen', '-S', screen_name, '-X', 'quit']) def cleanup(self): # type: () -> None