From 6fa0b7985ad74b2e20d1c8e869f9146254b7cb44 Mon Sep 17 00:00:00 2001 From: Jose Perez Carranza Date: Sun, 29 Sep 2019 09:57:35 -0500 Subject: [PATCH] Enable python3 fort the test suite Enable the suite to be used with python3 and added enough documentation to README that are required for this support. Note: only version 3.5.2 tested Change-Id: I07490dad2d4c49658c269b2732fefffd8e412654 Signed-off-by: Jose Perez Carranza --- automated-robot-suite/Libraries/common.py | 4 ++-- automated-robot-suite/Libraries/iso_setup.py | 2 +- automated-robot-suite/Libraries/pxe_server.py | 11 +++++++---- automated-robot-suite/README.rst | 6 +++--- automated-robot-suite/Utils/network.py | 6 +++--- automated-robot-suite/Utils/utils.py | 12 ++++++------ automated-robot-suite/requirements.txt | 3 +-- automated-robot-suite/test-requirements.txt | 3 ++- 8 files changed, 25 insertions(+), 22 deletions(-) diff --git a/automated-robot-suite/Libraries/common.py b/automated-robot-suite/Libraries/common.py index 96eadc5..0d7ed50 100644 --- a/automated-robot-suite/Libraries/common.py +++ b/automated-robot-suite/Libraries/common.py @@ -157,7 +157,7 @@ def string_to_dict(string_table): # in unicode format, so we need the following # 1. converting string_table variable from unicode to ascii code # 2. split in a list with line breaks - line_breaks_list = string_table['stdout'].encode('utf-8').split('\n') + line_breaks_list = string_table['stdout'].split('\n') robot_dictionary = {} @@ -339,7 +339,7 @@ def grub_checker(iso, mode, grub_option, grub_cmd): regex = '-e "label [0-9]" -e "label [A-Z][0-9]" -e append' grub_extracted_lines = bash.run_command('grep {} {}'.format( regex, grub)) - grub_option_list = grub_extracted_lines[1].split('\n') + grub_option_list = grub_extracted_lines[1].decode('utf-8').split('\n') key_dict = [] values_dict = [] diff --git a/automated-robot-suite/Libraries/iso_setup.py b/automated-robot-suite/Libraries/iso_setup.py index 997f607..91f4d1f 100644 --- a/automated-robot-suite/Libraries/iso_setup.py +++ b/automated-robot-suite/Libraries/iso_setup.py @@ -138,7 +138,7 @@ class Installer(object): try: for stdout in self.child: - cmd_stdout.append(stdout.strip()) + cmd_stdout.append(stdout.strip().decode('utf-8')) except pexpect.exceptions.TIMEOUT: LOG.info('custom timeout reached') diff --git a/automated-robot-suite/Libraries/pxe_server.py b/automated-robot-suite/Libraries/pxe_server.py index 4226108..3506be6 100644 --- a/automated-robot-suite/Libraries/pxe_server.py +++ b/automated-robot-suite/Libraries/pxe_server.py @@ -142,7 +142,7 @@ class PxeServer(object): for service in services: active_service = bash('sudo systemctl is-active {}' .format(service)) - if 'active' in active_service.stdout: + if 'active'.encode('utf-8') in active_service.stdout: LOG.info('%s service is active', service) continue else: @@ -246,9 +246,12 @@ class Node(object): LOG.info('Booting %s To PXE', self.name) LOG.info('Node %s : Setting PXE as first boot option', self.name) - set_pxe = bash('ipmitool -I lanplus -H %s -U %s -P %s ' - 'chassis bootdev pxe', self.bmc_ip, self.bmc_user, - self.bmc_pswd) + set_pxe = bash('ipmitool -I lanplus -H {node_bmc_ip} ' + '-U {node_bmc_user} -P {node_bmc_pswd} ' + 'chassis bootdev pxe'.format( + node_bmc_ip=self.bmc_ip, + node_bmc_user=self.bmc_user, + node_bmc_pswd=self.bmc_pswd)) if set_pxe.stderr: LOG.info(set_pxe.stderr) diff --git a/automated-robot-suite/README.rst b/automated-robot-suite/README.rst index 9438f5c..7e0efb5 100644 --- a/automated-robot-suite/README.rst +++ b/automated-robot-suite/README.rst @@ -25,8 +25,7 @@ be ready soon. Suite is based on Robot Framework and Python, please follow below instructions to properly use the suite. -***NOTE***: Currently the suite is designed to run on Pyhton 2.7 environment, -migration to Python 3.5 is undergoing and will be ready soon. +Suite should be executed with Python3 (tested with 3.5.2) __ https://docs.starlingx.io/deploy_install_guides/index.html @@ -168,6 +167,7 @@ Make sure you have python **virtualenv** package installed in your host machine. .. code:: bash $ sudo apt install python-pip + $ sudo apt-get install python3-dev $ sudo pip install virtualenv You can manage your virtual environments for the two options explained below: @@ -227,7 +227,7 @@ you can follow below steps: .. code:: bash - $ virtualenv my-venv + $ virtualenv -p python3 my-venv $ source my-venv/bin/activate Install the project requirements on virtual environment. diff --git a/automated-robot-suite/Utils/network.py b/automated-robot-suite/Utils/network.py index 4263354..777ef8e 100644 --- a/automated-robot-suite/Utils/network.py +++ b/automated-robot-suite/Utils/network.py @@ -27,7 +27,7 @@ def delete_network_interfaces(): # becoming in root elevate(graphical=False) - ifdata = Ifcfg(subprocess.check_output(['ifconfig', '-a'])) + ifdata = Ifcfg(subprocess.check_output(['ifconfig', '-a']).decode('utf-8')) # Destroy NAT network if exist try: @@ -75,7 +75,7 @@ def configure_network_interfaces(): for net in networks: eval_cmd = bash('sudo ifconfig {} up'.format(net)) - if 'ERROR' in eval_cmd.stderr: + if 'ERROR'.encode('utf-8') in eval_cmd.stderr: LOG.error(eval_cmd.stderr) raise EnvironmentError(eval_cmd.stderr) @@ -84,7 +84,7 @@ def configure_network_interfaces(): 'MASQUERADE') eval_cmd = bash(iptables) - if 'ERROR' in eval_cmd.stderr: + if 'ERROR'.encode('utf-8') in eval_cmd.stderr: LOG.error(eval_cmd.stderr) raise EnvironmentError(eval_cmd.stderr) diff --git a/automated-robot-suite/Utils/utils.py b/automated-robot-suite/Utils/utils.py index 960f506..38eed74 100644 --- a/automated-robot-suite/Utils/utils.py +++ b/automated-robot-suite/Utils/utils.py @@ -117,21 +117,21 @@ def clean_qemu_environment(): for vm in vms: # check if the current image is running to shutting down - cmd = ebash('sudo virsh domstate {}'.format(vm)) - stdout = cmd.stdout.strip() - stderr = cmd.stderr.strip() + cmd = ebash('sudo virsh domstate {}'.format(vm.decode('utf-8'))) + stdout = cmd.stdout.strip().decode('utf-8') + stderr = cmd.stderr.strip().decode('utf-8') if stdout == 'running' and 'failed to get domain' not in stderr: # the vm is running - ebash('sudo virsh destroy {}'.format(vm)) + ebash('sudo virsh destroy {}'.format(vm.decode('utf-8'))) # removing controller/compute from Virtual Machine Manager ebash( 'sudo virsh undefine {} --remove-all-storage --snapshots-metadata' - .format(vm)) + .format(vm.decode('utf-8'))) for partition in partitions: - ebash('sudo rm {}/{}'.format(images_path, partition)) + ebash('sudo rm {}/{}'.format(images_path, partition.decode('utf-8'))) def qemu_configuration_files(): diff --git a/automated-robot-suite/requirements.txt b/automated-robot-suite/requirements.txt index 4d31ac5..d9adef6 100644 --- a/automated-robot-suite/requirements.txt +++ b/automated-robot-suite/requirements.txt @@ -1,6 +1,5 @@ watchdog robotframework==3.1.1 -robotframework-debuglibrary robotframework-seleniumlibrary robotframework-sshlibrary pexpect @@ -9,6 +8,6 @@ netifaces bash elevate ifparser -pynetlinux +git+https://github.com/rlisagor/pynetlinux.git@master#egg=pynetlinux kmodpy psutil diff --git a/automated-robot-suite/test-requirements.txt b/automated-robot-suite/test-requirements.txt index 5a3ddd6..1a12875 100644 --- a/automated-robot-suite/test-requirements.txt +++ b/automated-robot-suite/test-requirements.txt @@ -3,7 +3,8 @@ hacking flake8-import-order mock coverage -pylint +pylint==2.3.0 pep8-naming ipdb ipython +mccabe==0.5.3