Skip to content
This repository has been archived by the owner on Nov 11, 2024. It is now read-only.

Commit

Permalink
Set overrides in DSS as a single property, refactor code for submitti…
Browse files Browse the repository at this point in the history
…ng runs (#654)

* Change DSS overrides into single property, refactor submitRuns

Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com>

* Update overrides comment

Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com>

* Split overrides on newlines

Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com>

* Load overrides from DSS in separate method

Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com>

* Minor refactor to reduce duplicate prefix concatenation

Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com>

* Change DSS overrides into a JSON array instead of a string separated by newlines

Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com>

---------

Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com>
  • Loading branch information
eamansour authored Oct 7, 2024
1 parent 5999762 commit 70da23d
Show file tree
Hide file tree
Showing 9 changed files with 1,349 additions and 248 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
import java.time.temporal.ChronoUnit;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.Map.Entry;

import javax.validation.constraints.NotNull;

import dev.galasa.ResultArchiveStoreContentType;
import dev.galasa.framework.beans.Property;
import dev.galasa.framework.internal.runner.ITestRunnerEventsProducer;
import dev.galasa.framework.spi.AbstractManager;
import dev.galasa.framework.spi.ConfigurationPropertyStoreException;
import dev.galasa.framework.spi.DynamicStatusStoreException;
import dev.galasa.framework.spi.FrameworkException;
import dev.galasa.framework.spi.IConfigurationPropertyStoreService;
Expand All @@ -33,6 +32,7 @@
import dev.galasa.framework.spi.ResultArchiveStoreException;
import dev.galasa.framework.spi.teststructure.TestStructure;
import dev.galasa.framework.spi.utils.DssUtils;
import dev.galasa.framework.spi.utils.GalasaGson;

public class BaseTestRunner {

Expand Down Expand Up @@ -61,6 +61,8 @@ public class BaseTestRunner {

protected Properties overrideProperties;

private static final GalasaGson gson = new GalasaGson();

protected void init(ITestRunnerDataProvider dataProvider) throws TestRunException {
this.run = dataProvider.getRun() ;
this.framework = dataProvider.getFramework();
Expand Down Expand Up @@ -166,12 +168,15 @@ private void loadOverrideProperties(Properties overrideProperties,
IDynamicStatusStoreService dss) throws TestRunException {
//*** Load the overrides if present
try {
String prefix = "run." + run.getName() + ".override.";
Map<String, String> runOverrides = dss.getPrefix(prefix);
for(Entry<String, String> entry : runOverrides.entrySet()) {
String key = entry.getKey().substring(prefix.length());
String value = entry.getValue();
overrideProperties.put(key, value);
// The overrides DSS property contains a JSON array of overrides in the form:
// dss.framework.run.X.overrides=[{ "key1": "value1" }, { "key2", "value2" }]
String runOverridesProp = "run." + run.getName() + ".overrides";
String runOverrides = dss.get(runOverridesProp);
if (runOverrides != null && !runOverrides.isBlank()) {
Property[] properties = gson.fromJson(runOverrides, Property[].class);
for (Property override : properties) {
overrideProperties.put(override.getKey(), override.getValue());
}
}
} catch(Exception e) {
throw new TestRunException("Problem loading overrides from the run properties", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
import java.io.IOException;
import java.net.*;
import java.util.*;
import java.util.Map.Entry;
import java.nio.file.*;
import javax.validation.constraints.NotNull;
import org.apache.commons.logging.*;
import org.osgi.framework.*;

import dev.galasa.framework.beans.Property;
import dev.galasa.framework.spi.*;
import dev.galasa.framework.spi.creds.*;
import dev.galasa.framework.spi.utils.GalasaGson;

public class FrameworkInitialisation implements IFrameworkInitialisation {

Expand All @@ -35,6 +37,7 @@ public class FrameworkInitialisation implements IFrameworkInitialisation {

private String galasaHome;

private static final GalasaGson gson = new GalasaGson();

public FrameworkInitialisation(
Properties bootstrapProperties,
Expand Down Expand Up @@ -144,18 +147,24 @@ public FrameworkInitialisation(
// *** If this is a test run, add the overrides from the run dss properties to
// these overrides
if (testrun) {
String prefix = "run." + framework.getTestRunName() + ".override.";
int len = prefix.length();
loadOverridePropertiesFromDss(overrideProperties);
}
}

Map<String, String> runOverrides = this.dssFramework.getPrefix(prefix);
for (Entry<String, String> override : runOverrides.entrySet()) {
String key = override.getKey().substring(len);
private void loadOverridePropertiesFromDss(Properties overrideProperties) throws DynamicStatusStoreException {
// The overrides DSS property contains a JSON array of overrides in the form:
// dss.framework.run.X.overrides=[{ "key1": "value1" }, { "key2", "value2" }]
String runOverridesProp = "run." + framework.getTestRunName() + ".overrides";
String runOverrides = this.dssFramework.get(runOverridesProp);
if (runOverrides != null && !runOverrides.isBlank()) {
Property[] properties = gson.fromJson(runOverrides, Property[].class);
for (Property override : properties) {
String key = override.getKey();
String value = override.getValue();

if (logger.isTraceEnabled()) {
logger.trace("Setting run override " + key + "=" + value);
}
overrideProperties.put(override.getKey(), override.getValue());
overrideProperties.put(key, value);
}
}
}
Expand Down
Loading

0 comments on commit 70da23d

Please sign in to comment.