Skip to content

Commit 2d189ec

Browse files
authored
Add --clobber command to windows script (#211)
* SUMO-272481 add clobber flag to script * SUMO-272481 use correct flag * SUMO-272481 remove unused variable * SUMO-272481 change clobber to boolean * SUMO-272481 add tests for unix script * SUMO-272481 add windows install script * SUMO-272481 fix bug during build * SUMO-272481 add windows test for clobber * SUMO-272481 fix bugs * SUMO-272481 trigger new workflow * SUMO-272481 change to bool * SUMO-272481 fix test * SUMO-272481 change assertion to string * SUMO-272481 update installOptions of windows * SUMO-272481 add new tests * SUMO-272481 fix lowercase typo * SUMO-272481 pass flag to powershell script in test * SUMO-272481 make common function windows specific * SUMO-272481 change function name
1 parent 5a4586b commit 2d189ec

File tree

9 files changed

+134
-2
lines changed

9 files changed

+134
-2
lines changed

install-script/install.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ param (
3030
# The Timezone option is used to specify the timezone of the collector.
3131
[string] $Timezone,
3232

33+
[bool] $Clobber,
34+
3335
# The API URL used to communicate with the SumoLogic backend
3436
[string] $Api,
3537

@@ -461,6 +463,9 @@ try {
461463
if ($Timezone.Length -gt 0) {
462464
$msiProperties += "TIMEZONE=`"${Timezone}`""
463465
}
466+
if ($Clobber -eq $true) {
467+
$msiAddLocal += "CLOBBER"
468+
}
464469
if ($msiAddLocal.Count -gt 0) {
465470
$addLocalStr = $msiAddLocal -Join ","
466471
$msiProperties += "ADDLOCAL=${addLocalStr}"

install-script/test/check_windows.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@ func checkEphemeralInConfig(p string) func(c check) bool {
8989
}
9090
}
9191

92+
func checkClobberInSumoConfig(p string) func(c check) bool {
93+
return func(c check) bool {
94+
assert.True(c.test, c.installOptions.clobber, "clobber was not specified")
95+
96+
conf, err := getConfig(p)
97+
if !assert.NoError(c.test, err, "error while reading configuration") {
98+
return false
99+
}
100+
101+
assert.True(c.test, conf.Extensions.Sumologic.Clobber, "clobber is not true")
102+
return true
103+
}
104+
}
105+
92106
func checkTokenInConfig(c check) bool {
93107
if !assert.NotEmpty(c.test, c.installOptions.installToken, "installation token has not been provided") {
94108
return false

install-script/test/command_windows.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ func (io *installOptions) string() []string {
4545
opts = append(opts, "-Ephemeral", "1")
4646
}
4747

48+
if io.clobber {
49+
opts = append(opts, "-Clobber", "1")
50+
}
51+
4852
if len(io.tags) > 0 {
4953
opts = append(opts, "-Tags", getTagOptValue(io.tags))
5054
}

install-script/test/install_windows_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,44 @@ func TestInstallScript(t *testing.T) {
145145
checkTags,
146146
},
147147
},
148+
{
149+
name: "installation token and clobber",
150+
options: installOptions{
151+
installToken: installToken,
152+
clobber: true,
153+
},
154+
preChecks: []checkFunc{checkBinaryNotCreated, checkConfigNotCreated, checkUserConfigNotCreated},
155+
postChecks: []checkFunc{
156+
checkBinaryCreated,
157+
checkBinaryIsRunning,
158+
checkConfigCreated,
159+
checkConfigFilesOwnershipAndPermissions(localSystemSID),
160+
checkUserConfigCreated,
161+
checkTokenInConfig,
162+
checkEphemeralNotInConfig(userConfigPath),
163+
checkHostmetricsConfigNotCreated,
164+
checkClobberInSumoConfig(userConfigPath),
165+
},
166+
},
167+
{
168+
name: "installation token, remotely-managed, and clobber",
169+
options: installOptions{
170+
installToken: installToken,
171+
remotelyManaged: true,
172+
clobber: true,
173+
},
174+
preChecks: []checkFunc{checkBinaryNotCreated, checkConfigNotCreated, checkUserConfigNotCreated},
175+
postChecks: []checkFunc{
176+
checkBinaryCreated,
177+
checkBinaryIsRunning,
178+
checkConfigCreated,
179+
checkConfigFilesOwnershipAndPermissions(localSystemSID),
180+
checkRemoteConfigDirectoryCreated,
181+
checkTokenInSumoConfig,
182+
checkEphemeralNotInConfig(configPath),
183+
checkClobberInSumoConfig(configPath),
184+
},
185+
},
148186
} {
149187
t.Run(spec.name, func(t *testing.T) {
150188
if err := runTest(t, &spec); err != nil {

msi/SumoLogic.wixext/SumoLogic.wixext/Config.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class Config
1414
public string Api { get; set; }
1515
public string OpAmpApi { get; set; }
1616
public string Timezone { get; set; }
17+
public bool Clobber { get; set; }
1718

1819
public Config() {
1920
this.CollectorFields = new Dictionary<string, string>();

msi/SumoLogic.wixext/SumoLogic.wixext/ConfigUpdater.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ public void Update(Config config)
101101
sumologic.Children["time_zone"] = config.Timezone;
102102
}
103103

104+
if (config.Clobber)
105+
{
106+
EnsureScalarKey(sumologic, "clobber");
107+
sumologic.Children["clobber"] = "true";
108+
}
109+
104110

105111
// Make sure the sumologic processor node is a map node, otherwise an empty string
106112
// is generated as the value instead of an empty node.

msi/SumoLogic.wixext/SumoLogic.wixext/CustomAction.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class CustomActions
2525
private const string pOpAmpFolder = "OpAmpFolder";
2626
private const string pOpAmpApi = "OpAmpApi";
2727
private const string pTimezone = "Timezone";
28+
private const string pClobber = "Clobber";
2829
private const string pConfigFragmentsFolder = "ConfigFragmentsFolder";
2930

3031
// WiX features
@@ -72,6 +73,7 @@ public static ActionResult UpdateConfig(Session session)
7273
var opAmpFolder = session.CustomActionData[pOpAmpFolder];
7374
var opAmpApi = session.CustomActionData[pOpAmpApi];
7475
var timezone = session.CustomActionData[pTimezone];
76+
var clobber = (session.CustomActionData.ContainsKey(pClobber) && session.CustomActionData[pClobber] == "true");
7577
var api = session.CustomActionData[pApi];
7678

7779
if (remotelyManaged && string.IsNullOrEmpty(opAmpFolder))
@@ -82,7 +84,7 @@ public static ActionResult UpdateConfig(Session session)
8284

8385
// Load config from disk and replace values
8486
Config config = new Config { InstallationToken = installationToken, RemotelyManaged = remotelyManaged, Ephemeral = ephemeral,
85-
OpAmpFolder = opAmpFolder, OpAmpApi = opAmpApi, Api = api, Timezone = timezone };
87+
OpAmpFolder = opAmpFolder, OpAmpApi = opAmpApi, Api = api, Timezone = timezone, Clobber = clobber };
8688
config.SetCollectorFieldsFromTags(tags);
8789

8890
var configFile = remotelyManaged ? sumoLogicConfigPath : commonConfigPath;

msi/SumoLogic.wixext/SumoLogicTests/ConfigUpdaterTests.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,34 @@ public void TimezoneAssertions(Config config, StreamReader sr)
187187
Assert.AreEqual(config.Timezone, endpoint.ToString());
188188
}
189189

190+
public void ClobberAssertions(Config config, StreamReader sr)
191+
{
192+
YamlStream ys = new YamlStream();
193+
ys.Load(sr);
194+
YamlMappingNode root = (YamlMappingNode)ys.Documents[0].RootNode;
195+
196+
Assert.IsTrue(root.Children.ContainsKey("extensions"));
197+
Assert.AreEqual(YamlNodeType.Mapping, root.Children["extensions"].NodeType);
198+
var extensions = (YamlMappingNode)root.Children["extensions"];
199+
200+
Assert.IsTrue(extensions.Children.ContainsKey("sumologic"));
201+
Assert.AreEqual(YamlNodeType.Mapping, extensions.Children["sumologic"].NodeType);
202+
var sumologic = (YamlMappingNode)extensions.Children["sumologic"];
203+
var endpoint = (YamlScalarNode)sumologic.Children["clobber"];
204+
if(config.Clobber){
205+
Assert.IsTrue(sumologic.Children.ContainsKey("clobber"));
206+
Assert.AreEqual(YamlNodeType.Scalar, sumologic.Children["clobber"].NodeType);
207+
Assert.AreEqual("true", endpoint.ToString());
208+
}
209+
else{
210+
if(sumologic.Children.ContainsKey("clobber")){
211+
Assert.AreEqual(YamlNodeType.Scalar, sumologic.Children["clobber"].NodeType);
212+
Assert.AreEqual("false", endpoint.ToString());
213+
}
214+
}
215+
}
216+
217+
190218

191219
[TestMethod]
192220
public void TestUpdate_WithExtensionsBlock()
@@ -476,6 +504,7 @@ public void TestUpdate_OpAmpApi()
476504
}
477505

478506

507+
479508
[TestMethod]
480509
public void TestUpdate_Timezone()
481510
{
@@ -503,5 +532,32 @@ public void TestUpdate_Timezone()
503532
}
504533
}
505534

535+
[TestMethod]
536+
public void TestUpdate_Clobber()
537+
{
538+
var filePath = Path.Combine(testDataPath, "with-extensions-block.yaml");
539+
var config = new Config { InstallationToken = "foobar", Clobber = true };
540+
config.SetCollectorFieldsFromTags(@"foo=bar,baz=kaz,xaz=yaz");
541+
542+
using (MemoryStream ms = new MemoryStream())
543+
{
544+
var configUpdater = new ConfigUpdater(new StreamReader(filePath));
545+
configUpdater.Update(config);
546+
configUpdater.Save(new StreamWriter(ms));
547+
548+
ms.Seek(0, SeekOrigin.Begin);
549+
550+
StreamReader sr = new StreamReader(ms);
551+
while (!sr.EndOfStream)
552+
{
553+
Console.WriteLine(sr.ReadLine());
554+
}
555+
556+
ms.Seek(0, SeekOrigin.Begin);
557+
558+
ClobberAssertions(config, sr);
559+
}
560+
}
561+
506562
}
507563
}

msi/wix/package.wxs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
<!-- Whether or not the remotely managed and ephemeral features are selected -->
7878
<Property Id="REMOTELYMANAGEDSELECTED" Value="false" Hidden="yes" />
7979
<Property Id="EPHEMERALSELECTED" Value="false" Hidden="yes" />
80+
<Property Id="CLOBBERSELECTED" Value="false" Hidden="yes" />
8081

8182
<!-- The API base URL if overriden -->
8283
<Property Id="API" Hidden="yes" />
@@ -105,12 +106,13 @@
105106
<CustomAction Id="UpdateConfigActionData1" Property="UpdateConfigAction1"
106107
Value="CommonConfigPath=[ConfigFragmentsFolder]common.yaml;SumoLogicConfigPath=[ConfigFolder]sumologic.yaml;InstallToken=[INSTALLTOKEN];InstallationToken=[INSTALLATIONTOKEN]" />
107108
<CustomAction Id="UpdateConfigActionData2" Property="UpdateConfigAction2"
108-
Value="Tags=[TAGS];OpAmpFolder=[OpAmpFolder];OpAmpApi=[OPAMPAPI];Timezone=[TIMEZONE];Ephemeral=[EPHEMERALSELECTED];RemotelyManaged=[REMOTELYMANAGEDSELECTED];Api=[API]" />
109+
Value="Tags=[TAGS];OpAmpFolder=[OpAmpFolder];OpAmpApi=[OPAMPAPI];Timezone=[TIMEZONE];Ephemeral=[EPHEMERALSELECTED];Clobber=[CLOBBERSELECTED];RemotelyManaged=[REMOTELYMANAGEDSELECTED];Api=[API]" />
109110
<CustomAction Id="UpdateConfigActionData" Property="UpdateConfigAction" Value="[UpdateConfigAction1];[UpdateConfigAction2]" />
110111

111112
<!-- Before updating the config files set the properties indicating whether or not the remotely managed and ephemeral features are selected -->
112113
<SetProperty Id="REMOTELYMANAGEDSELECTED" Value="true" Sequence="execute" Before="UpdateConfigActionData" Condition="&amp;REMOTELYMANAGED=3" />
113114
<SetProperty Id="EPHEMERALSELECTED" Value="true" Sequence="execute" Before="UpdateConfigActionData" Condition="&amp;EPHEMERAL=3" />
115+
<SetProperty Id="CLOBBERSELECTED" Value="true" Sequence="execute" Before="UpdateConfigActionData" Condition="&amp;CLOBBER=3" />
114116

115117
<!-- Execute Sequence -->
116118
<InstallExecuteSequence>
@@ -143,6 +145,10 @@
143145
<Feature Id="EPHEMERAL" Title="Ephemeral" Level="2" AllowAbsent="yes" AllowAdvertise="no" TypicalDefault="install" >
144146
<Component Id="EphemeralComponent" Location="local" Directory="INSTALLFOLDER" Guid="4095b4ee-d011-49c3-b7a7-755aa36fcc5e" />
145147
</Feature>
148+
149+
<Feature Id="CLOBBER" Title="Clobber" Level="2" AllowAbsent="yes" AllowAdvertise="no" TypicalDefault="install" >
150+
<Component Id="ClobberComponent" Location="local" Directory="INSTALLFOLDER" Guid="6448c76f-83a7-4534-bcc9-e008da4c2bb7" />
151+
</Feature>
146152
</Feature>
147153

148154
<!-- UI -->

0 commit comments

Comments
 (0)