Skip to content

Commit

Permalink
Merge remote-tracking branch 'uyuni/master' into master-fix/xml-rpc-c…
Browse files Browse the repository at this point in the history
…reateSystemRecord
  • Loading branch information
meaksh committed Nov 22, 2023
2 parents 00c76ed + a640d39 commit d32425a
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import static com.redhat.rhn.domain.contentmgmt.FilterCriteria.Matcher.MODULE_NONE;
import static com.redhat.rhn.domain.contentmgmt.FilterCriteria.Matcher.PROVIDES_NAME;
import static com.redhat.rhn.domain.contentmgmt.FilterCriteria.Matcher.PTF_ALL;
import static com.redhat.rhn.domain.contentmgmt.PackageFilter.BUILD_DATE;
import static com.redhat.rhn.domain.contentmgmt.PtfFilter.FIELD_PTF_ALL;
import static com.redhat.rhn.domain.contentmgmt.PtfFilter.FIELD_PTF_NUMBER;
import static com.redhat.rhn.domain.contentmgmt.PtfFilter.FIELD_PTF_PACKAGE;
Expand Down Expand Up @@ -86,6 +87,10 @@ public class FilterCriteria {
Triple.of(PACKAGE, GREATEREQ, "nevra"),
Triple.of(PACKAGE, GREATER, "nevra"),
Triple.of(PACKAGE, MATCHES, "name"),
Triple.of(PACKAGE, LOWER, BUILD_DATE),
Triple.of(PACKAGE, LOWEREQ, BUILD_DATE),
Triple.of(PACKAGE, GREATER, BUILD_DATE),
Triple.of(PACKAGE, GREATEREQ, BUILD_DATE),
Triple.of(ERRATUM, EQUALS, "advisory_name"),
Triple.of(ERRATUM, EQUALS, "advisory_type"),
Triple.of(ERRATUM, EQUALS, "synopsis"),
Expand Down
35 changes: 27 additions & 8 deletions java/code/src/com/redhat/rhn/domain/contentmgmt/PackageFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import com.redhat.rhn.domain.rhnpackage.Package;
import com.redhat.rhn.domain.rhnpackage.PackageEvr;

import java.time.Instant;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.regex.Pattern;

import javax.persistence.DiscriminatorValue;
Expand All @@ -31,6 +34,8 @@
@DiscriminatorValue("package")
public class PackageFilter extends ContentFilter<Package> {

public static final String BUILD_DATE = "build_date";

private Pattern pattern;

@Override
Expand All @@ -43,19 +48,15 @@ public boolean test(Package pack) {
case CONTAINS:
return getField(pack, field, String.class).contains(value);
case LOWER:
return checkNameAndArch(field, value, pack) && pack.getPackageEvr().compareTo(
PackageEvr.parsePackageEvr(pack.getPackageType(), getEvr(field, value))) < 0;
return preCondition(pack, field, value) && compareField(pack, field, value) < 0;
case LOWEREQ:
return checkNameAndArch(field, value, pack) && pack.getPackageEvr().compareTo(
PackageEvr.parsePackageEvr(pack.getPackageType(), getEvr(field, value))) <= 0;
return preCondition(pack, field, value) && compareField(pack, field, value) <= 0;
case EQUALS:
return getField(pack, field, String.class).equals(value);
case GREATEREQ:
return checkNameAndArch(field, value, pack) && pack.getPackageEvr().compareTo(
PackageEvr.parsePackageEvr(pack.getPackageType(), getEvr(field, value))) >= 0;
return preCondition(pack, field, value) && compareField(pack, field, value) >= 0;
case GREATER:
return checkNameAndArch(field, value, pack) && pack.getPackageEvr().compareTo(
PackageEvr.parsePackageEvr(pack.getPackageType(), getEvr(field, value))) > 0;
return preCondition(pack, field, value) && compareField(pack, field, value) > 0;
case MATCHES:
if (pattern == null) {
pattern = Pattern.compile(value);
Expand All @@ -70,6 +71,24 @@ public boolean test(Package pack) {
}
}

private int compareField(Package pack, String field, String value) {
return BUILD_DATE.equals(field) ? compareBuildDate(pack, value) : comparePackageEvr(pack, field, value);
}

private boolean preCondition(Package pack, String field, String value) {
return BUILD_DATE.equals(field) ? pack.getBuildTime() != null : checkNameAndArch(field, value, pack);
}

private int comparePackageEvr(Package pack, String field, String value) {
return pack.getPackageEvr().compareTo(PackageEvr.parsePackageEvr(pack.getPackageType(), getEvr(field, value)));
}

private int compareBuildDate(Package pack, String value) {
Instant valDate = ZonedDateTime.parse(value, DateTimeFormatter.ISO_OFFSET_DATE_TIME).toInstant();
Instant issueDate = pack.getBuildTime().toInstant();
return issueDate.compareTo(valDate);
}

private static <T> T getField(Package pack, String field, Class<T> type) {
switch (field) {
case "name":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.text.SimpleDateFormat;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Collections;
import java.util.Date;
import java.util.TimeZone;

/**
* Tests for {@link ContentFilter}
Expand Down Expand Up @@ -418,6 +420,37 @@ public void testErrataByDate2Filter() throws Exception {
" should be equal " + criteriaDate);
}

/**
* Test basic Package filtering based on build_date
*
* @throws Exception if anything goes wrong
*/
@Test
public void testPackageByBuildDate() throws Exception {
var df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
df.setTimeZone(TimeZone.getDefault());
FilterCriteria criteria = new FilterCriteria(FilterCriteria.Matcher.GREATEREQ, "build_date",
"2022-05-12T01:34:49+00:00");
ContentFilter filter = contentManager.createFilter("greatereq-filter", DENY, PACKAGE, criteria, user);

Package pack = PackageTest.createTestPackage(user.getOrg());

pack.setBuildTime(df.parse("2022-05-12T01:34:49+00:00"));
assertTrue(filter.test(pack));
pack.setBuildTime(df.parse("2022-05-07T21:49:36+00:00"));
assertFalse(filter.test(pack));

pack.setBuildTime(df.parse("2022-05-12T01:34:49+00:00"));
criteria.setMatcher(FilterCriteria.Matcher.GREATER);
assertFalse(filter.test(pack));

criteria.setMatcher(FilterCriteria.Matcher.LOWER);
assertFalse(filter.test(pack));

criteria.setMatcher(FilterCriteria.Matcher.LOWEREQ);
assertTrue(filter.test(pack));
}

/**
* Test basic Errata filtering based on equal match on synopsis
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add option to filter packages by build time in CLM (jsc#SUMA-282)
2 changes: 1 addition & 1 deletion susemanager/bin/server-migrator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ zypper ar -n "Main Update Repository" http://download.opensuse.org/update/leap/$
zypper ar -n "Non-OSS Repository" http://download.opensuse.org/distribution/leap/${NEW_VERSION_ID}/repo/non-oss repo-non-oss
zypper ar -n "Update Repository (Non-Oss)" http://download.opensuse.org/update/leap/${NEW_VERSION_ID}/non-oss/ repo-update-non-oss
zypper ar -n "Uyuni Server Stable" https://download.opensuse.org/repositories/systemsmanagement:/Uyuni:/Stable/images/repo/Uyuni-Server-POOL-x86_64-Media1/ uyuni-server-stable
zypper ar -n "Update repository wiht updates from SUSE Linux Enterprise" http://download.opensuse.org/update/leap/${NEW_VERSION_ID}/sle repo-sle-update
zypper ar -n "Update repository with updates from SUSE Linux Enterprise" http://download.opensuse.org/update/leap/${NEW_VERSION_ID}/sle repo-sle-update
zypper ar -n "Update repository of openSUSE Backports" http://download.opensuse.org/update/leap/${NEW_VERSION_ID}/backports/ repo-backports-update
zypper ref
zypper -n dup --allow-vendor-change
Expand Down
1 change: 1 addition & 0 deletions susemanager/susemanager.changes.simonflood.fix-wiht-typo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- fix typo in repo name within server-migrator.sh script
1 change: 1 addition & 0 deletions testsuite/dockerfiles/controller-dev/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ RUN zypper ref -f && \
zypper clean -a
COPY etc_pam.d_sshd /etc/pam.d/sshd
CMD ssh-keygen -A && /usr/sbin/sshd -De
RUN curl https://raw.githubusercontent.com/uyuni-project/uyuni/master/testsuite/Gemfile -o Gemfile && bundle.ruby2.5 install && rm Gemfile
2 changes: 1 addition & 1 deletion testsuite/podman_runner/07_start_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
set -xe
src_dir=$(cd $(dirname "$0")/../.. && pwd -P)

sudo -i podman run --rm --tmpfs /run -v ${src_dir}/schema/spacewalk/spacewalk-schema-upgrade:/usr/bin/spacewalk-schema-upgrade -v${src_dir}/testsuite:/testsuite -v ${src_dir}/schema/spacewalk/upgrade/:/etc/sysconfig/rhn/schema-upgrade/ -v ${src_dir}/schema/reportdb/upgrade/:/etc/sysconfig/rhn/reportdb-schema-upgrade/ -v ${src_dir}/web:/web -v ${src_dir}/branding:/branding -v ${src_dir}/java:/java -v ${src_dir}/client:/client -v /sys/fs/cgroup:/sys/fs/cgroup:rw -v /tmp/test-all-in-one:/tmp --cgroupns=host --add-host=download.opensuse.org:195.135.223.226 --add-host=registry.npmjs.org:104.16.31.34 --add-host=registry.yarnpkg.com:104.16.29.34 -h uyuni-server-all-in-one-test -p 8443:443 -p 8080:80 -p 4505:4505 -p 4506:4506 -d --name=uyuni-server-all-in-one-test --network uyuni-network-1 ghcr.io/$UYUNI_PROJECT/uyuni/ci-test-server-all-in-one-dev:$UYUNI_VERSION
sudo -i podman run --rm --tmpfs /run -v ${src_dir}/schema/spacewalk/spacewalk-schema-upgrade:/usr/bin/spacewalk-schema-upgrade -v${src_dir}/testsuite:/testsuite -v ${src_dir}/schema/spacewalk/upgrade/:/etc/sysconfig/rhn/schema-upgrade/ -v ${src_dir}/schema/reportdb/upgrade/:/etc/sysconfig/rhn/reportdb-schema-upgrade/ -v ${src_dir}/web:/web -v ${src_dir}/branding:/branding -v ${src_dir}/java:/java -v ${src_dir}/client:/client -v /sys/fs/cgroup:/sys/fs/cgroup:rw -v /tmp/test-all-in-one:/tmp --cgroupns=host -h uyuni-server-all-in-one-test -p 8443:443 -p 8080:80 -p 4505:4505 -p 4506:4506 -d --name=uyuni-server-all-in-one-test --network uyuni-network-1 ghcr.io/$UYUNI_PROJECT/uyuni/ci-test-server-all-in-one-dev:$UYUNI_VERSION

8 changes: 7 additions & 1 deletion testsuite/podman_runner/09_build_server_code.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
#!/bin/bash
set -xe
sudo -i podman exec uyuni-server-all-in-one-test bash -c "cp /testsuite/podman_runner/debug_logging.properties /etc/tomcat/logging.properties"

# Create missing directories that will be created by the new RPM https://github.com/uyuni-project/uyuni/pull/7651
sudo -i podman exec uyuni-server-all-in-one-test bash -c "[ -d /usr/share/susemanager/www ] || mkdir -p /usr/share/susemanager/www"
sudo -i podman exec uyuni-server-all-in-one-test bash -c "[ -d /usr/share/susemanager/www/htdocs ] || mkdir -p /usr/share/susemanager/www/htdocs"
sudo -i podman exec uyuni-server-all-in-one-test bash -c "[ -d /usr/share/susemanager/www/tomcat/webapps ] || mkdir -p /usr/share/susemanager/www/tomcat/webapps"

sudo -i podman exec uyuni-server-all-in-one-test bash -c "cd /java && ant -f manager-build.xml ivy refresh-branding-jar deploy-local"
sudo -i podman exec uyuni-server-all-in-one-test bash -c "set -xe;cd /web/html/src;[ -d dist ] || mkdir dist;yarn install --force --ignore-optional --production=true --frozen-lockfile;yarn autoclean --force;yarn build:novalidate; rsync -a dist/ /srv/www/htdocs/"
sudo -i podman exec uyuni-server-all-in-one-test bash -c "set -xe;cd /web/html/src;[ -d dist ] || mkdir dist;yarn install --force --ignore-optional --production=true --frozen-lockfile;yarn autoclean --force;yarn build:novalidate; rsync -a dist/ /usr/share/susemanager/www/htdocs/"
sudo -i podman exec uyuni-server-all-in-one-test bash -c "rctomcat restart"

# mgr-push
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ const FilterForm = (props: Props) => {
if (clmFilterOptions.ISSUE_DATE.key === filter.type) {
draft[clmFilterOptions.ISSUE_DATE.key] = localizedMoment();
}
if (clmFilterOptions.PACKAGE_BUILD_DATE.key === filter.type) {
draft[clmFilterOptions.PACKAGE_BUILD_DATE.key] = localizedMoment();
}
})
);
}
Expand Down Expand Up @@ -201,6 +204,16 @@ const FilterForm = (props: Props) => {
/>
)}

{clmFilterOptions.PACKAGE_BUILD_DATE.key === filterType && (
<DateTime
name={clmFilterOptions.PACKAGE_BUILD_DATE.key}
label={t("Build")}
labelClass="col-md-3"
divClass="col-md-8"
required
/>
)}

{clmFilterOptions.SYNOPSIS.key === filterType && (
<Text
name={clmFilterOptions.SYNOPSIS.key}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ export const clmFilterOptions: ClmFilterOptionsEnumType = {
entityType: filterEntity.PACKAGE,
matchers: [filterMatchers.PROVIDES_NAME],
},
PACKAGE_BUILD_DATE: {
key: "build_date",
text: t("Build date"),
entityType: filterEntity.PACKAGE,
matchers: [filterMatchers.LOWER, filterMatchers.LOWEREQ, filterMatchers.GREATER, filterMatchers.GREATEREQ],
},
ADVISORY_NAME: {
key: "advisory_name",
text: t("Advisory Name"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add option to filter packages by build time in CLM (jsc#SUMA-282)

0 comments on commit d32425a

Please sign in to comment.