diff --git a/src/VirtualClient/VirtualClient.Actions.FunctionalTests/Redis/RedisServerProfileTests.cs b/src/VirtualClient/VirtualClient.Actions.FunctionalTests/Redis/RedisServerProfileTests.cs index 37ade6ffce..7548183ed7 100644 --- a/src/VirtualClient/VirtualClient.Actions.FunctionalTests/Redis/RedisServerProfileTests.cs +++ b/src/VirtualClient/VirtualClient.Actions.FunctionalTests/Redis/RedisServerProfileTests.cs @@ -35,7 +35,7 @@ public void SetupFixture() ComponentTypeCache.Instance.LoadComponentTypes(TestDependencies.TestDirectory); this.mockFixture.SetupWorkloadPackage("wget", expectedFiles: "linux-x64/wget2"); - this.mockFixture.SetupFile("redis", "redis-6.2.1/src/redis-server", new byte[0]); + this.mockFixture.SetupFile("redis", "src/redis-server", new byte[0]); this.mockFixture.SystemManagement.Setup(mgr => mgr.GetCpuInfoAsync(It.IsAny())) .ReturnsAsync(new CpuInfo("AnyName", "AnyDescription", 1, 4, 1, 0, true)); } diff --git a/src/VirtualClient/VirtualClient.Dependencies.UnitTests/RedisPackageInstallationTests.cs b/src/VirtualClient/VirtualClient.Dependencies.UnitTests/RedisPackageInstallationTests.cs index 61be90443d..cd95b26c6b 100644 --- a/src/VirtualClient/VirtualClient.Dependencies.UnitTests/RedisPackageInstallationTests.cs +++ b/src/VirtualClient/VirtualClient.Dependencies.UnitTests/RedisPackageInstallationTests.cs @@ -73,6 +73,31 @@ public async Task RedisPackageInstallationExecutesExpectedInstallationCommandsOn } } + [Test] + [TestCase(Architecture.X64, "linux-x64")] + [TestCase(Architecture.Arm64, "linux-arm64")] + public async Task RedisPackageInstallationExecutesExpectedInstallationCommandsOnAzLinux(Architecture architecture, string platformArchitecture) + { + this.SetupDefaultMockBehavior(PlatformID.Unix, architecture); + + LinuxDistributionInfo mockInfo = new LinuxDistributionInfo() + { + OperationSystemFullName = "TestAzLinux", + LinuxDistribution = LinuxDistribution.AzLinux + }; + + this.mockFixture.SystemManagement.Setup(sm => sm.GetLinuxDistributionAsync(It.IsAny())) + .ReturnsAsync(mockInfo); + + using (TestRedisPackageInstallation installation = new TestRedisPackageInstallation(this.mockFixture.Dependencies, this.mockFixture.Parameters)) + { + await installation.ExecuteAsync(CancellationToken.None); + + Assert.IsTrue(this.mockFixture.ProcessManager.CommandsExecuted($"dnf update")); + Assert.IsTrue(this.mockFixture.ProcessManager.CommandsExecuted($"dnf install redis -y")); + } + } + private void SetupDefaultMockBehavior(PlatformID platform = PlatformID.Unix, Architecture architecture = Architecture.X64) { this.mockFixture.Setup(platform, architecture); diff --git a/src/VirtualClient/VirtualClient.Dependencies/RedisPackageInstallation.cs b/src/VirtualClient/VirtualClient.Dependencies/RedisPackageInstallation.cs index a2a35ce6c4..92bc80aaab 100644 --- a/src/VirtualClient/VirtualClient.Dependencies/RedisPackageInstallation.cs +++ b/src/VirtualClient/VirtualClient.Dependencies/RedisPackageInstallation.cs @@ -22,7 +22,7 @@ namespace VirtualClient.Dependencies /// /// Provides functionality for installing latest version of Redis from Apt package manager on specific OS distribution version. /// - [SupportedPlatforms("linux-arm64,linux-x64")] + [SupportedPlatforms("linux-arm64,linux-x64", throwError: true)] public class RedisPackageInstallation : VirtualClientComponent { private IFileSystem fileSystem; @@ -81,25 +81,20 @@ public string Version /// protected override async Task InitializeAsync(EventContext telemetryContext, CancellationToken cancellationToken) { - if (this.Platform != PlatformID.Unix) - { - throw new WorkloadException($"Unsupported platform. The platform '{this.Platform}' is not supported.", ErrorReason.NotSupported); - } + LinuxDistributionInfo distroInfo = await this.systemManager.GetLinuxDistributionAsync(cancellationToken); + this.Logger.LogMessage($"Print Distro Info:{distroInfo}", telemetryContext); + this.Logger.LogMessage($"Print LinuxDistribution:{distroInfo.LinuxDistribution}", telemetryContext); - if (this.Platform == PlatformID.Unix) + switch (distroInfo.LinuxDistribution) { - LinuxDistributionInfo distroInfo = await this.systemManager.GetLinuxDistributionAsync(cancellationToken); - - switch (distroInfo.LinuxDistribution) - { - case LinuxDistribution.Ubuntu: - break; - - default: - throw new WorkloadException( - $"Redis installation is not supported by Virtual Client on the current Unix/Linux distro '{distroInfo.LinuxDistribution}'.", - ErrorReason.LinuxDistributionNotSupported); - } + case LinuxDistribution.Ubuntu: + break; + case LinuxDistribution.AzLinux: + break; + default: + throw new WorkloadException( + $"Redis installation is not supported by Virtual Client on the current Unix/Linux distro '{distroInfo.LinuxDistribution}'.", + ErrorReason.LinuxDistributionNotSupported); } this.PackagePath = this.PlatformSpecifics.GetPackagePath(this.PackageName); @@ -122,20 +117,22 @@ protected override async Task ExecuteAsync(EventContext telemetryContext, Cancel case LinuxDistribution.Debian: await this.InstallOnUbuntuAsync(telemetryContext, cancellationToken); break; + case LinuxDistribution.AzLinux: + await this.InstallOnAzLinuxAsync(telemetryContext, cancellationToken); + break; } } } private async Task InstallOnUbuntuAsync(EventContext telemetryContext, CancellationToken cancellationToken) { - if (this.Version != string.Empty) + if (!string.IsNullOrEmpty(this.Version)) { this.installRedisCommand = $"install redis={this.Version} -y"; } else { this.installRedisCommand = $"install redis -y"; - } await this.ExecuteCommandAsync("apt", "update", Environment.CurrentDirectory, telemetryContext, cancellationToken) @@ -154,5 +151,35 @@ await this.systemManager.PackageManager.RegisterPackageAsync(redisPackage, cance .ConfigureAwait(false); } + + private async Task InstallOnAzLinuxAsync(EventContext telemetryContext, CancellationToken cancellationToken) + { + if (!string.IsNullOrEmpty(this.Version)) + { + this.installRedisCommand = $"install redis-{this.Version} -y"; + } + else + { + this.installRedisCommand = $"install redis -y"; + + } + + await this.ExecuteCommandAsync("dnf", "update -y", Environment.CurrentDirectory, telemetryContext, cancellationToken) + .ConfigureAwait(false); + await this.ExecuteCommandAsync("dnf", this.installRedisCommand, Environment.CurrentDirectory, telemetryContext, cancellationToken) + .ConfigureAwait(false); + + this.fileSystem.Directory.CreateDirectory(this.PackagePath); + this.fileSystem.Directory.CreateDirectory(this.PlatformSpecifics.Combine(this.PackagePath, "src")); + + await this.ExecuteCommandAsync("cp", $"/usr/bin/redis-server {this.PlatformSpecifics.Combine(this.PackagePath, "src")}", Environment.CurrentDirectory, telemetryContext, cancellationToken) + .ConfigureAwait(false); + + DependencyPath redisPackage = new DependencyPath(this.PackageName, this.PackagePath); + await this.systemManager.PackageManager.RegisterPackageAsync(redisPackage, cancellationToken) + .ConfigureAwait(false); + + } + } } diff --git a/src/VirtualClient/VirtualClient.Main/profiles/GET-STARTED-REDIS.json b/src/VirtualClient/VirtualClient.Main/profiles/GET-STARTED-REDIS.json index 14099b5485..5e9bd3ce38 100644 --- a/src/VirtualClient/VirtualClient.Main/profiles/GET-STARTED-REDIS.json +++ b/src/VirtualClient/VirtualClient.Main/profiles/GET-STARTED-REDIS.json @@ -55,22 +55,10 @@ } }, { - "Type": "WgetPackageInstallation", + "Type": "RedisPackageInstallation", "Parameters": { - "Scenario": "InstallRedisPackage", - "PackageName": "redis", - "PackageUri": "https://github.com/redis/redis/archive/refs/tags/6.2.1.tar.gz", - "SubPath": "redis-6.2.1", - "Notes": "Example path to package -> /packages/redis/redis-6.2.1" - } - }, - { - "Type": "ExecuteCommand", - "Parameters": { - "Scenario": "CompileRedis", - "SupportedPlatforms": "linux-x64,linux-arm64", - "Command": "make", - "WorkingDirectory": "{PackagePath:redis}" + "Scenario": "InstallRedisPackageFromAptRepository", + "PackageName": "redis" } }, { @@ -78,6 +66,7 @@ "Parameters": { "Scenario": "CloneMemtierRepo", "RepoUri": "https://github.com/RedisLabs/memtier_benchmark", + "Commit": "1.4.0", "PackageName": "memtier" } }, @@ -86,7 +75,7 @@ "Parameters": { "Scenario": "CompileMemtier", "SupportedPlatforms": "linux-x64,linux-arm64", - "Command": "git checkout 1.4.0&&autoreconf -ivf&&bash -c './configure'&&make", + "Command": "autoreconf -ivf&&bash -c './configure'&&make", "WorkingDirectory": "{PackagePath:memtier}" } }, diff --git a/src/VirtualClient/VirtualClient.Main/profiles/PERF-REDIS.json b/src/VirtualClient/VirtualClient.Main/profiles/PERF-REDIS.json index 9c46e54911..6a00fe9caa 100644 --- a/src/VirtualClient/VirtualClient.Main/profiles/PERF-REDIS.json +++ b/src/VirtualClient/VirtualClient.Main/profiles/PERF-REDIS.json @@ -234,41 +234,18 @@ } }, { - "Type": "DependencyPackageInstallation", + "Type": "RedisPackageInstallation", "Parameters": { - "Scenario": "InstallKeysForRedisTLS", - "BlobContainer": "packages", - "BlobName": "redisresources.zip", - "PackageName": "redisresources", - "Extract": true + "Scenario": "InstallRedisPackageFromAptRepository", + "PackageName": "redis" } }, - { - "Type": "WgetPackageInstallation", - "Parameters": { - "Scenario": "InstallRedisPackage", - "PackageName": "redis", - "PackageUri": "https://github.com/redis/redis/archive/refs/tags/6.2.1.tar.gz", - "SubPath": "redis-6.2.1", - "Notes": "Example path to package -> /packages/redis/redis-6.2.1" - } - }, - { - "Type": "ExecuteCommand", - "Parameters": { - "Scenario": "CompileRedis", - "SupportedPlatforms": "linux-x64,linux-arm64", - "IsTLSEnabled": "$.Parameters.IsTLSEnabled", - "BUILD_TLS": "{calculate({IsTLSEnabled} ? \"yes\" : \"no\" )}", - "Command": "make BUILD_TLS={BUILD_TLS}", - "WorkingDirectory": "{PackagePath:redis}" - } - }, { "Type": "GitRepoClone", "Parameters": { "Scenario": "CloneMemtierRepo", "RepoUri": "https://github.com/RedisLabs/memtier_benchmark", + "Commit": "1.4.0", "PackageName": "memtier" } }, @@ -277,7 +254,7 @@ "Parameters": { "Scenario": "CompileMemtier", "SupportedPlatforms": "linux-x64,linux-arm64", - "Command": "git checkout 1.4.0&&autoreconf -ivf&&bash -c './configure'&&make", + "Command": "autoreconf -ivf&&bash -c './configure'&&make", "WorkingDirectory": "{PackagePath:memtier}" } },