From f2328ffb02bfe78237a0e50616e8e7570a7ab027 Mon Sep 17 00:00:00 2001 From: NSSPKrishna Date: Thu, 9 May 2024 23:32:17 +0530 Subject: [PATCH] chore(super-agent): New uncaught error for no installations --- internal/install/recipe_installer.go | 15 ++++++++++++--- internal/install/recipe_installer_test.go | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/internal/install/recipe_installer.go b/internal/install/recipe_installer.go index 7516e297b..e21a94fa0 100644 --- a/internal/install/recipe_installer.go +++ b/internal/install/recipe_installer.go @@ -412,9 +412,13 @@ func (i *RecipeInstall) isTargetInstallRecipe(recipeName string) bool { // If the host has super agent installed infra agent and logs agent would be UNSUPPORTED // It then installs the additional bundle and reports any unsupported recipes. func (i *RecipeInstall) installAdditionalBundle(bundler RecipeBundler, bundleInstaller RecipeBundleInstaller, repo *recipes.RecipeRepository) error { - var additionalBundle *recipes.Bundle + var ( + additionalBundle *recipes.Bundle + bun *recipes.Bundler + ok bool + ) if i.hostHasSuperAgentProcess() { - if bun, ok := bundler.(*recipes.Bundler); ok { + if bun, ok = bundler.(*recipes.Bundler); ok { bun.HasSuperInstalled = true log.Debugf("Super agent process found. Proceeding with additional bundle.") } @@ -426,7 +430,7 @@ func (i *RecipeInstall) installAdditionalBundle(bundler RecipeBundler, bundleIns log.Debugf("bundling addtional bundle") log.Debugf("recipes in list %d", len(i.RecipeNames)) additionalBundle = bundler.CreateAdditionalTargetedBundle(i.RecipeNames) - if bundler.(*recipes.Bundler).HasSuperInstalled { + if bun.HasSuperInstalled { for _, coreRecipe := range bundler.(*recipes.Bundler).GetCoreRecipeNames() { if i, ok := additionalBundle.ContainsName(coreRecipe); ok { additionalBundle.BundleRecipes[i].AddDetectionStatus(execution.RecipeStatusTypes.UNSUPPORTED, 0) @@ -445,6 +449,11 @@ func (i *RecipeInstall) installAdditionalBundle(bundler RecipeBundler, bundleIns bundleInstaller.InstallContinueOnError(additionalBundle, i.AssumeYes) if bundleInstaller.InstalledRecipesCount() == 0 { + if bun.HasSuperInstalled { + return &types.UncaughtError{ + Err: fmt.Errorf("super Agent is installed, preventing the installation of this recipe"), + } + } return &types.UncaughtError{ Err: fmt.Errorf("no recipes were installed"), } diff --git a/internal/install/recipe_installer_test.go b/internal/install/recipe_installer_test.go index 5a4cdbc39..c8f981f25 100644 --- a/internal/install/recipe_installer_test.go +++ b/internal/install/recipe_installer_test.go @@ -348,7 +348,7 @@ func TestInstallTargetedInstallShouldInstallCoreIfCoreWasSkippedWhileSuperAgentI err := recipeInstall.Install() - assert.Equal(t, "no recipes were installed", err.Error()) + assert.Equal(t, "super Agent is installed, preventing the installation of this recipe", err.Error()) assert.Equal(t, 1, statusReporter.RecipeDetectedCallCount, "Detection Count") assert.Equal(t, 1, statusReporter.RecipeAvailableCallCount, "Available Count") assert.Equal(t, 0, statusReporter.RecipeInstallingCallCount, "Installing Count")