Skip to content

Commit

Permalink
Merge pull request #18928 from rfan1/python_libgit2
Browse files Browse the repository at this point in the history
Create test module libgit2
  • Loading branch information
rfan1 committed Mar 25, 2024
2 parents fd33171 + d486430 commit cd5e1fe
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 2 deletions.
10 changes: 10 additions & 0 deletions data/libgit2/pygit2_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pygit2

url = "https://github.com/libgit2/libgit2"
path = "./libgit2_clone"

try:
pygit2.clone_repository(url, path)
print("Repository cloned successfully to {}".format(path))
except Exception as e:
print("Error: {}".format(e))
9 changes: 7 additions & 2 deletions lib/python_version_utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,17 @@ sub get_system_python_version() {

=head2 get_available_python_versions
returns an array of strings with all the available python versions in the repository
returns an array of strings with all the available python versions in the repository,
we can get the latest version with parameter defined
=cut

sub get_available_python_versions() {
sub get_available_python_versions ($get_latest_version = undef) {
my @python3_versions = split(/\n/, script_output(qq[zypper se '/^python3[0-9]{1,2}\$/' | 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");
if ($get_latest_version) {
record_info("The latest version is:", "$python3_versions[$#python3_versions]");
return $python3_versions[$#python3_versions];
}
return @python3_versions;
}

Expand Down
1 change: 1 addition & 0 deletions schedule/functional/extra_tests_textmode.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,5 @@ schedule:
- console/coredump_collect
- console/valgrind
- console/sssd_389ds_functional
- console/libgit2
- console/zypper_log_packages
68 changes: 68 additions & 0 deletions tests/console/libgit2.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# SUSE's openQA tests
#
# Copyright 2024 SUSE LLC
# SPDX-License-Identifier: FSFAP
#
# Summary: Basic libgit2 test via python pygit2
# - Test should test on sle15sp6+ and tw, see https://jira.suse.com/browse/PED-7228
# - Package 'pygit2' requires Python '>=3.7'
# - Run some basic test (pygit2_test.py)
#
# 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 qw(is_sle is_leap);
use utils 'zypper_call';
use python_version_utils;
use registration 'add_suseconnect_product';

my $python3_version;
my $python_sub_version;

sub run {
return if (is_sle('<15-sp6') || is_leap('<15.6'));

select_serial_terminal;

# Install libgit2
if (is_sle) {
add_suseconnect_product('sle-module-desktop-applications');
add_suseconnect_product('sle-module-development-tools');
add_suseconnect_product('sle-module-python3');
}
my $pkg_ver = script_output("zypper se '/^libgit2-[0-9].*[0-9]\$/' | awk -F '|' '/libgit2-[0-9]/ {gsub(\" \", \"\"); print \$2}' | uniq");
zypper_call "in $pkg_ver libgit2-tools";
record_info("Installed libgit2 version", script_output("rpm -q --qf '%{VERSION}\n' $pkg_ver"));

# Install the latest python3 package
$python3_version = get_available_python_versions('1');
zypper_call "in $python3_version";
$python_sub_version = substr($python3_version, 7);

# Install pygit2
assert_script_run "pip3.$python_sub_version install pygit2 --break-system-packages";

# Run test script
assert_script_run "wget --quiet " . data_url('libgit2/pygit2_test.py') . " -O pygit2_test.py";
assert_script_run "python3.$python_sub_version pygit2_test.py";

# Cleanup
clean_up();
}

sub clean_up {
assert_script_run "pip3.$python_sub_version uninstall pygit2 -y --break-system-packages";
zypper_call "rm $python3_version";
assert_script_run "rm -rf libgit2";
}

sub post_fail_hook {
select_console 'log-console';
clean_up();
}

1;

0 comments on commit cd5e1fe

Please sign in to comment.