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

Use external JSON configuration files for PAYG #8688

Merged
merged 7 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
import com.redhat.rhn.taskomatic.TaskomaticApi;
import com.redhat.rhn.testing.TestUtils;


import com.suse.cloud.CloudPaygManager;
import com.suse.cloud.test.TestCloudPaygManagerBuilder;
import com.suse.manager.attestation.AttestationManager;
import com.suse.manager.virtualization.VirtManagerSalt;
import com.suse.manager.webui.controllers.bootstrap.RegularMinionBootstrapper;
Expand Down Expand Up @@ -97,7 +97,7 @@ public class AdminConfigurationHandlerTest extends BaseHandlerTestCase {
private TaskomaticApi taskomaticApi = new TaskomaticApi();
private final SystemQuery systemQuery = new TestSystemQuery();
private final SaltApi saltApi = new TestSaltApi();
private final CloudPaygManager paygManager = new CloudPaygManager();
private final CloudPaygManager paygManager = new TestCloudPaygManagerBuilder().build();
private final AttestationManager attestationManager = new AttestationManager();
private final ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi);
private RegularMinionBootstrapper regularMinionBootstrapper =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import com.redhat.rhn.testing.UserTestUtils;

import com.suse.cloud.CloudPaygManager;
import com.suse.cloud.test.TestCloudPaygManagerBuilder;
import com.suse.manager.attestation.AttestationManager;
import com.suse.manager.virtualization.VirtManagerSalt;
import com.suse.manager.webui.controllers.bootstrap.RegularMinionBootstrapper;
Expand Down Expand Up @@ -115,7 +116,7 @@ public class ChannelSoftwareHandlerTest extends BaseHandlerTestCase {
private TaskomaticApi taskomaticApi = new TaskomaticApi();
private final SystemQuery systemQuery = new TestSystemQuery();
private final SaltApi saltApi = new TestSaltApi();
private final CloudPaygManager paygManager = new CloudPaygManager();
private final CloudPaygManager paygManager = new TestCloudPaygManagerBuilder().build();
private final AttestationManager attestationManager = new AttestationManager();
private final ServerGroupManager serverGroupManager = new ServerGroupManager(saltApi);
private RegularMinionBootstrapper regularMinionBootstrapper =
Expand All @@ -135,7 +136,7 @@ public class ChannelSoftwareHandlerTest extends BaseHandlerTestCase {
private SystemManager systemManager =
new SystemManager(ServerFactory.SINGLETON, ServerGroupFactory.SINGLETON, saltApi);
private SystemHandler systemHandler = new SystemHandler(taskomaticApi, xmlRpcSystemHelper, systemEntitlementManager,
systemManager, serverGroupManager, new CloudPaygManager(), new AttestationManager());
systemManager, serverGroupManager, new TestCloudPaygManagerBuilder().build(), new AttestationManager());
private ChannelSoftwareHandler handler = new ChannelSoftwareHandler(taskomaticApi, xmlRpcSystemHelper);
private ErrataHandler errataHandler = new ErrataHandler();

Expand Down Expand Up @@ -328,7 +329,7 @@ public void testSetSystemChannelsBaseChannel() throws Exception {
assertFalse(child2.isBaseChannel());

SystemHandler sh = new SystemHandler(taskomaticApi, xmlRpcSystemHelper, systemEntitlementManager, systemManager,
serverGroupManager, new CloudPaygManager(), new AttestationManager());
serverGroupManager, new TestCloudPaygManagerBuilder().build(), new AttestationManager());

int sid = server.getId().intValue();
int rc1 = sh.setBaseChannel(admin, sid, base.getLabel());
Expand Down Expand Up @@ -357,7 +358,7 @@ public void testSetSystemChannelsBaseChannel() throws Exception {
@Test
public void testSetBaseChannel() throws Exception {
SystemHandler sh = new SystemHandler(taskomaticApi, xmlRpcSystemHelper, systemEntitlementManager, systemManager,
serverGroupManager, new CloudPaygManager(), new AttestationManager());
serverGroupManager, new TestCloudPaygManagerBuilder().build(), new AttestationManager());

Channel c1 = ChannelFactoryTest.createTestChannel(admin);
Server server = ServerFactoryTest.createTestServer(admin, true);
Expand Down Expand Up @@ -878,7 +879,7 @@ public void testChannelSubscription() throws Exception {
childChan.setParentChannel(baseChan);

SystemHandler sh = new SystemHandler(taskomaticApi, xmlRpcSystemHelper, systemEntitlementManager, systemManager,
serverGroupManager, new CloudPaygManager(), new AttestationManager());
serverGroupManager, new TestCloudPaygManagerBuilder().build(), new AttestationManager());

int return1 = sh.setBaseChannel(admin, server.getId().intValue(), baseChan.getLabel());
int return2 = sh.setChildChannels(admin, server.getId().intValue(), List.of(childChan.getLabel()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.redhat.rhn.testing.UserTestUtils;

import com.suse.cloud.CloudPaygManager;
import com.suse.cloud.test.TestCloudPaygManagerBuilder;
import com.suse.manager.attestation.AttestationManager;
import com.suse.manager.ssl.SSLCertData;
import com.suse.manager.ssl.SSLCertManager;
Expand Down Expand Up @@ -65,7 +66,7 @@ public class ProxyHandlerTest extends RhnJmockBaseTestCase {

private final SaltApi saltApi = new TestSaltApi();
private final SystemQuery systemQuery = new TestSystemQuery();
private final CloudPaygManager paygManager = new CloudPaygManager();
private final CloudPaygManager paygManager = new TestCloudPaygManagerBuilder().build();
private final AttestationManager attestationManager = new AttestationManager();
private final RegularMinionBootstrapper regularMinionBootstrapper =
new RegularMinionBootstrapper(systemQuery, saltApi, paygManager, attestationManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import com.redhat.rhn.testing.TestUtils;

import com.suse.cloud.CloudPaygManager;
import com.suse.cloud.test.TestCloudPaygManagerBuilder;
import com.suse.manager.attestation.AttestationManager;
import com.suse.manager.webui.controllers.bootstrap.RegularMinionBootstrapper;
import com.suse.manager.webui.controllers.bootstrap.SSHMinionBootstrapper;
Expand Down Expand Up @@ -90,7 +91,7 @@ public class ServerConfigHandlerTest extends BaseHandlerTestCase {
private final TaskomaticApi taskomaticApi = new TaskomaticApi();
private final SaltApi saltApi = new TestSaltApi();
private final SystemQuery systemQuery = new TestSystemQuery();
private final CloudPaygManager paygManager = new CloudPaygManager();
private final CloudPaygManager paygManager = new TestCloudPaygManagerBuilder().build();
private final AttestationManager attestationManager = new AttestationManager();
private final RegularMinionBootstrapper regularMinionBootstrapper =
new RegularMinionBootstrapper(systemQuery, saltApi, paygManager, attestationManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.redhat.rhn.testing.TestUtils;

import com.suse.cloud.CloudPaygManager;
import com.suse.cloud.test.TestCloudPaygManagerBuilder;
import com.suse.manager.attestation.AttestationManager;
import com.suse.manager.webui.controllers.bootstrap.RegularMinionBootstrapper;
import com.suse.manager.webui.controllers.bootstrap.SSHMinionBootstrapper;
Expand All @@ -52,7 +53,7 @@ public class SnapshotHandlerTest extends BaseHandlerTestCase {

private final SaltApi saltApi = new TestSaltApi();
private final SystemQuery systemQuery = new TestSystemQuery();
private final CloudPaygManager paygManager = new CloudPaygManager();
private final CloudPaygManager paygManager = new TestCloudPaygManagerBuilder().build();
private final AttestationManager attestationManager = new AttestationManager();
private final RegularMinionBootstrapper regularMinionBootstrapper =
new RegularMinionBootstrapper(systemQuery, saltApi, paygManager, attestationManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.redhat.rhn.testing.UserTestUtils;

import com.suse.cloud.CloudPaygManager;
import com.suse.cloud.test.TestCloudPaygManagerBuilder;
import com.suse.manager.attestation.AttestationManager;
import com.suse.manager.webui.controllers.bootstrap.RegularMinionBootstrapper;
import com.suse.manager.webui.controllers.bootstrap.SSHMinionBootstrapper;
Expand All @@ -66,7 +67,7 @@
public class ServerGroupHandlerTest extends BaseHandlerTestCase {
private final SaltApi saltApi = new TestSaltApi();
private final SystemQuery systemQuery = new TestSystemQuery();
private final CloudPaygManager paygManager = new CloudPaygManager();
private final CloudPaygManager paygManager = new TestCloudPaygManagerBuilder().build();
private final AttestationManager attestationManager = new AttestationManager();
private final RegularMinionBootstrapper regularMinionBootstrapper =
new RegularMinionBootstrapper(systemQuery, saltApi, paygManager, attestationManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import com.redhat.rhn.testing.PackageTestUtils;

import com.suse.cloud.CloudPaygManager;
import com.suse.cloud.test.TestCloudPaygManagerBuilder;
import com.suse.manager.attestation.AttestationManager;
import com.suse.manager.virtualization.VirtManagerSalt;
import com.suse.manager.webui.controllers.bootstrap.RegularMinionBootstrapper;
Expand Down Expand Up @@ -106,7 +107,7 @@ public void setUp() throws Exception {
TaskomaticApi taskomaticApi = new TaskomaticApi();
SystemQuery systemQuery = new TestSystemQuery();
SaltApi saltApi = new TestSaltApi();
CloudPaygManager paygMgr = new CloudPaygManager();
CloudPaygManager paygMgr = new TestCloudPaygManagerBuilder().build();
AttestationManager attMgr = new AttestationManager();

RegularMinionBootstrapper regularBootstrapper =
Expand All @@ -125,7 +126,7 @@ public void setUp() throws Exception {
SystemManager systemManager = new SystemManager(ServerFactory.SINGLETON, ServerGroupFactory.SINGLETON, saltApi);

handler = new SystemHandler(taskomaticApi, xmlRpcHelper, entitlementManager, systemManager, groupManager,
new CloudPaygManager(), new AttestationManager());
new TestCloudPaygManagerBuilder().build(), new AttestationManager());

standard = PackageTest.createTestPackage(admin.getOrg());
standardUpdated = PackageTestUtils.newVersionOfPackage(standard, null, "2.0.0", null, admin.getOrg());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
import com.redhat.rhn.testing.UserTestUtils;

import com.suse.cloud.CloudPaygManager;
import com.suse.cloud.test.TestCloudPaygManagerBuilder;
import com.suse.manager.attestation.AttestationManager;
import com.suse.manager.virtualization.VirtManagerSalt;
import com.suse.manager.webui.controllers.bootstrap.RegularMinionBootstrapper;
Expand Down Expand Up @@ -213,7 +214,7 @@ public class SystemHandlerTest extends BaseHandlerTestCase {
private TaskomaticApi taskomaticApi = new TaskomaticApi();
private final SystemQuery systemQuery = new TestSystemQuery();
private final SaltApi saltApi = new TestSaltApi();
private final CloudPaygManager paygManager = new CloudPaygManager();
private final CloudPaygManager paygManager = new TestCloudPaygManagerBuilder().build();
private final AttestationManager attestationManager = new AttestationManager();
private RegularMinionBootstrapper regularMinionBootstrapper =
new RegularMinionBootstrapper(systemQuery, saltApi, paygManager, attestationManager);
Expand All @@ -234,7 +235,7 @@ public class SystemHandlerTest extends BaseHandlerTestCase {
new SystemManager(ServerFactory.SINGLETON, ServerGroupFactory.SINGLETON, saltApi);
private SystemHandler handler =
new SystemHandler(taskomaticApi, xmlRpcSystemHelper, systemEntitlementManager, systemManager,
serverGroupManager, new CloudPaygManager(), new AttestationManager());
serverGroupManager, new TestCloudPaygManagerBuilder().build(), new AttestationManager());

@RegisterExtension
protected final Mockery mockContext = new JUnit5Mockery() {{
Expand Down Expand Up @@ -3733,7 +3734,7 @@ public void testChangeProxy() throws Exception {
private SystemHandler getMockedHandler() throws Exception {
TaskomaticApi taskomaticMock = mockContext.mock(TaskomaticApi.class);
SystemHandler systemHandler = new SystemHandler(taskomaticMock, xmlRpcSystemHelper, systemEntitlementManager,
systemManager, serverGroupManager, new CloudPaygManager(), new AttestationManager());
systemManager, serverGroupManager, new TestCloudPaygManagerBuilder().build(), new AttestationManager());

mockContext.checking(new Expectations() {{
allowing(taskomaticMock).scheduleActionExecution(with(any(Action.class)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.redhat.rhn.testing.TestUtils;

import com.suse.cloud.CloudPaygManager;
import com.suse.cloud.test.TestCloudPaygManagerBuilder;
import com.suse.manager.attestation.AttestationManager;
import com.suse.manager.webui.controllers.bootstrap.RegularMinionBootstrapper;
import com.suse.manager.webui.controllers.bootstrap.SSHMinionBootstrapper;
Expand Down Expand Up @@ -132,7 +133,7 @@ public void testExternalGroupToServerGroupMap() {
String desc = TestUtils.randomString();
SaltApi saltApi = new TestSaltApi();
SystemQuery systemQuery = new TestSystemQuery();
CloudPaygManager paygManager = new CloudPaygManager();
CloudPaygManager paygManager = new TestCloudPaygManagerBuilder().build();
AttestationManager attMgr = new AttestationManager();
RegularMinionBootstrapper regularMinionBootstrapper =
new RegularMinionBootstrapper(systemQuery, saltApi, paygManager, attMgr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import com.redhat.rhn.testing.ServerTestUtils;

import com.suse.cloud.CloudPaygManager;
import com.suse.cloud.test.TestCloudPaygManagerBuilder;
import com.suse.manager.attestation.AttestationManager;
import com.suse.manager.virtualization.VirtManagerSalt;
import com.suse.manager.webui.controllers.bootstrap.RegularMinionBootstrapper;
Expand Down Expand Up @@ -106,7 +107,7 @@ public class MinionActionManagerTest extends JMockBaseTestCaseWithUser {
new SystemUnentitler(virtManager, monitoringManager, serverGroupManager),
new SystemEntitler(saltApi, virtManager, monitoringManager, serverGroupManager)
);
private final CloudPaygManager paygManager = new CloudPaygManager();
private final CloudPaygManager paygManager = new TestCloudPaygManagerBuilder().build();
private final AttestationManager attestationManager = new AttestationManager();
private RegularMinionBootstrapper regularMinionBootstrapper =
new RegularMinionBootstrapper(systemQuery, saltApi, paygManager, attestationManager);
Expand Down Expand Up @@ -154,7 +155,7 @@ public void testPackageInstallWithStagingInsideWindow() throws Exception {
MinionActionManager.setTaskomaticApi(taskomaticMock);

SystemHandler handler = new SystemHandler(taskomaticMock, xmlRpcSystemHelper, systemEntitlementManager,
systemManager, serverGroupManager, new CloudPaygManager(), new AttestationManager());
systemManager, serverGroupManager, new TestCloudPaygManagerBuilder().build(), new AttestationManager());
context().checking(new Expectations() { {
Matcher<Map<Long, ZonedDateTime>> minionMatcher =
AllOf.allOf(IsMapContaining.hasKey(minion1.getId()));
Expand Down Expand Up @@ -205,7 +206,7 @@ public void testPackageInstallWithStagingBeforeWindow() throws Exception {


SystemHandler handler = new SystemHandler(taskomaticMock, xmlRpcSystemHelper, systemEntitlementManager,
systemManager, serverGroupManager, new CloudPaygManager(), new AttestationManager());
systemManager, serverGroupManager, new TestCloudPaygManagerBuilder().build(), new AttestationManager());

context().checking(new Expectations() { {
Matcher<Map<Long, ZonedDateTime>> minionMatcher =
Expand Down Expand Up @@ -257,7 +258,7 @@ public void testPackageInstallWithStagingAfterWindow() throws Exception {
MinionActionManager.setTaskomaticApi(taskomaticMock);

SystemHandler handler = new SystemHandler(taskomaticMock, xmlRpcSystemHelper, systemEntitlementManager,
systemManager, serverGroupManager, new CloudPaygManager(), new AttestationManager());
systemManager, serverGroupManager, new TestCloudPaygManagerBuilder().build(), new AttestationManager());

context().checking(new Expectations() { {
exactly(1).of(taskomaticMock)
Expand Down Expand Up @@ -308,7 +309,7 @@ public void testPackageInstallWithStagingBeforeWindowExceedingDuration()
MinionActionManager.setTaskomaticApi(taskomaticMock);

SystemHandler handler = new SystemHandler(taskomaticMock, xmlRpcSystemHelper, systemEntitlementManager,
systemManager, serverGroupManager, new CloudPaygManager(), new AttestationManager());
systemManager, serverGroupManager, new TestCloudPaygManagerBuilder().build(), new AttestationManager());
context().checking(new Expectations() {{
Matcher<Map<Long, ZonedDateTime>> minionMatcher =
AllOf.allOf(IsMapContaining.hasKey(minion1.getId()));
Expand Down Expand Up @@ -359,7 +360,7 @@ public void testPackageInstallWithoutStaging() throws Exception {
MinionActionManager.setTaskomaticApi(taskomaticMock);

SystemHandler handler = new SystemHandler(taskomaticMock, xmlRpcSystemHelper, systemEntitlementManager,
systemManager, serverGroupManager, new CloudPaygManager(), new AttestationManager());
systemManager, serverGroupManager, new TestCloudPaygManagerBuilder().build(), new AttestationManager());

context().checking(new Expectations() { {
exactly(1).of(taskomaticMock)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.redhat.rhn.testing.TestUtils;

import com.suse.cloud.CloudPaygManager;
import com.suse.cloud.test.TestCloudPaygManagerBuilder;

import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -224,10 +225,9 @@ private Channel createBaseChannel() throws Exception {
}

private CloudPaygManager getFakeCloudPaygManager() {
CloudPaygManager cloudPaygManager = new CloudPaygManager();
cloudPaygManager.setPaygInstance(true);
cloudPaygManager.setCompliant(true);
return cloudPaygManager;
return new TestCloudPaygManagerBuilder()
.withPaygInstance()
.build();
}

private Channel createChildrenWIthProductChannel(Channel parentChannel) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import com.redhat.rhn.testing.TestUtils;

import com.suse.cloud.CloudPaygManager;
import com.suse.cloud.test.TestCloudPaygManagerBuilder;

import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.client.WireMock;
Expand Down Expand Up @@ -150,12 +151,9 @@ private void clearDb() {
@Test
public void testRefreshPayg() throws Exception {
Config.get().setString(ConfigDefaults.PRODUCT_TREE_TAG, "SUMA4.3");
CloudPaygManager mgr = new CloudPaygManager() {
@Override
public boolean isPaygInstance() {
return true;
}
};
CloudPaygManager mgr = new TestCloudPaygManagerBuilder()
.withPaygInstance()
.build();
PAYG_DATA_TASK.setCloudPaygManager(mgr);

WireMockServer wireMockServer = setupWireMockServer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import com.redhat.rhn.testing.TestUtils;

import com.suse.cloud.CloudPaygManager;
import com.suse.cloud.test.TestCloudPaygManagerBuilder;
import com.suse.manager.webui.services.pillar.MinionGeneralPillarGenerator;
import com.suse.manager.webui.services.pillar.MinionPillarManager;
import com.suse.mgrsync.MgrSyncStatus;
Expand Down Expand Up @@ -1932,9 +1933,9 @@ public void testIsRefreshNeededPAYG() {
CredentialsFactory.removeCredentials(c);
}
ManagerInfoFactory.setLastMgrSyncRefresh(0);
CloudPaygManager mgr = new CloudPaygManager();
mgr.setPaygInstance(true);
mgr.setCompliant(true);
CloudPaygManager mgr = new TestCloudPaygManagerBuilder()
.withPaygInstance()
.build();
ContentSyncManager csm = new ContentSyncManager(null, mgr);
CloudRMTCredentials rmtCreds = CredentialsFactory.createCloudRmtCredentials("RMTUSER", "secret",
"http://example.com");
Expand Down
Loading
Loading