Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new test for python pip version check and functionality #17681

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file added data/console/pysample_package-1.0.tar.gz
Binary file not shown.
8 changes: 8 additions & 0 deletions data/console/test_pysample_package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import pysample_package

print(pysample_package.__version__)
#print(pysample_package.__author__)

from pysample_package import mymodule
mymodule.greet("Ram")
mymodule.print_hello()
Comment on lines +1 to +8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use the package from: #17675 if you rebase on top of her changes, so you can leverage on @DeepthiYV's module

2 changes: 2 additions & 0 deletions schedule/functional/extra_tests_textmode.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ conditional_schedule:
- console/zziplib
- console/vsftpd
- console/python3_new_version_check
- console/python3_pip_version_check
- console/year_2038_detection
tumbleweed_tests:
VERSION:
Expand All @@ -95,6 +96,7 @@ conditional_schedule:
- console/vsftpd
- console/python_flake8
- console/python3_new_version_check
- console/python3_pip_version_check
- console/year_2038_detection
schedule:
- installation/bootloader_start
Expand Down
2 changes: 2 additions & 0 deletions schedule/qam/common/mau-extratests1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ conditional_schedule:
- console/golang
- console/redis
- console/python3_new_version_check
- console/python3_pip_version_check
- '{{arch_specific}}'
15-SP4:
- console/golang
- console/redis
- console/python3_new_version_check
- console/python3_pip_version_check
- '{{arch_specific}}'
15-SP3:
- console/openssl_nodejs
Expand Down
103 changes: 103 additions & 0 deletions tests/console/python3_pip_version_check.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# SUSE's openQA tests

Check failure on line 1 in tests/console/python3_pip_version_check.pm

View workflow job for this annotation

GitHub Actions / CI: Running static tests with perl v5.32

File tests/console/python3_pip_version_check.pm needs tidying
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to run make tidy-full to have this document also tidied

#
# Copyright 2022 SUSE LLC
# SPDX-License-Identifier: FSFAP
#
# Package: python3?
# Summary: Run python3 testsuite
# - Test suitable only for SLE15SPs+
# - Check that Python 3.x is the main version installed based on SPs
# - Check that Python 3.1? is available to install
# - Install some python package using pip (e.g. pysample_package)
# - Test installed package by importing it in python script
# - Uninstall previously installed python package using pip
# Maintainer: QE Core <qe-core@suse.com>

use base "consoletest";
use strict;
use warnings;
use testapi;
use serial_terminal 'select_serial_terminal';
use version_utils;
use utils "zypper_call";
use registration "add_suseconnect_product";

sub run{
select_serial_terminal;
# Test system python3 version
my @system_python3_version = script_output(qq[zypper se --installed-only --provides '/usr/bin/python3' | awk -F '|' '/python3[0-9]*/ {gsub(" ", ""); print \$2}' | awk -F '-' '{print \$1}' | uniq | head -1]);
die "There are many python3 versions installed " if (scalar(@system_python3_version) > 1);
my $sys_python3_version = get_python3_version($system_python3_version[0]);
record_info("System python version", "$sys_python3_version");
my ($python_version, $pip_version) = get_pip_version($sys_python3_version);
#Test system python3 pip
test_python_pip($python_version, $pip_version);
#Test other available python versions
test_available_python_versions();
}

sub test_available_python_versions {
# Test all avaiable new python3 versions if any
my $ret = zypper_call('se "python3[0-9]*"', exitcode => [0, 104]);
die('No new python3 packages available') if ($ret == 104);
my @python3_versions = split(/\n/, script_output(qq[zypper se 'python3[0-9]*' | awk -F '|' '/python3[0-9]/ {gsub(" ", ""); print \$2}' | awk -F '-' '{print \$1}' | uniq]));
record_info("Available versions", "All available new python3 versions are: @python3_versions");
foreach my $python3_spec_release (@python3_versions) {
record_info("Installing $python3_spec_release", "$python3_spec_release is tested now");
zypper_call("install $python3_spec_release");
my $python3_version = get_python3_version($python3_spec_release);
my ($python_version, $pip_version) = get_pip_version($python3_version);
#Test system python3 pip
test_python_pip($python_version, $pip_version);
}
}

sub test_python_pip {
#Test pip package installation and uninstallation
my ($python_version, $pip_version) = @_;
my $package = "pysample_package-1.0.tar.gz";
my $script = "test_pysample_package.py";
assert_script_run("[ -f $package ] || curl -O " . data_url("console/$package") . " || true");
record_info("Testing pip version $pip_version", "$pip_version is tested now");
my $pip_install_cmd = "$pip_version install ".((split(/-/, $package))[0])." --no-index --find-links .";
my $pip_install_output = script_output("$pip_install_cmd");
record_info("Pip installed package:","$pip_install_output");
my $pip_show_cmd = "$pip_version show ".((split(/-/, $package))[0]);
my $pip_show_output = script_output("$pip_show_cmd");
record_info("Verify package installation", "$pip_show_output");
assert_script_run("[ -f $script ] || curl -O " . data_url("console/$script") . " || true");
my $output = script_output("$python_version $script");
record_info("Script output", "$output");
my $pip_uninstall_cmd = "$pip_version uninstall -y ".((split(/-/, $package))[0]);
$output = script_output("$pip_uninstall_cmd");
record_info("Uninstall package: ", "$output");
}

sub get_python3_version {
#Get specific version of python e.g."Python 3.6.15"
my ($python3_version) = @_;
if ($python3_version eq "python3") {
return script_output("$python3_version --version");
}
my $sub_version = substr($python3_version, 7);
return script_output("python3.$sub_version --version");
}

sub get_pip_version {
#Get python and associated pip version e.g. "python3.6" and "pip3.6"
my ($python_version) = @_;
my ($major, $minor) = split(/\./, substr($python_version, 7),3);
my ($pip_version) = script_output("pip$major.$minor --version");
die "No associated pip installed for $python_version" if ($pip_version eq "");
record_info("Pip version associated to $python_version is", "$pip_version");
return ("python$major.$minor", "pip$major.$minor")
}


sub post_fail_hook {
select_console 'log-console';
assert_script_run 'save_y2logs /tmp/python3_pip_version_check_y2logs.tar.bz2';
upload_logs '/tmp/python3_pip_version_check_y2logs.tar.bz2';
}

1;