Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a2ff19d
Fixed update logic, all tests pass.
D1v38om83r Apr 2, 2026
7e419f4
saving work
D1v38om83r Apr 2, 2026
4865405
Final commit before PR
D1v38om83r Apr 3, 2026
bb67d35
Merge branch 'master' into dev/bhbrahma/fix-updates
D1v38om83r Apr 3, 2026
6bb8763
Merge branch 'master' into dev/bhbrahma/fix-updates
D1v38om83r Apr 3, 2026
f306f20
Addressed PR comments
D1v38om83r Apr 6, 2026
1f77896
Merge branch 'dev/bhbrahma/fix-updates' of https://github.com/Azure/V…
D1v38om83r Apr 6, 2026
e23b895
Updated makefiles so that extension version must be provided as param…
D1v38om83r Apr 6, 2026
ce58422
Updated makefiles to match extension version pattern
D1v38om83r Apr 6, 2026
119222f
Make makefile for linux not throw error on target collect-licenses
D1v38om83r Apr 6, 2026
96781b6
fixed typo
D1v38om83r Apr 6, 2026
e76208f
Added command to test compile time version
D1v38om83r Apr 6, 2026
944eb7e
Updated readme.md
D1v38om83r Apr 7, 2026
b541806
updated comment for findVersionDir and prettified it
D1v38om83r Apr 7, 2026
5ba58a6
Implement vmAppUpdateCallback on Linux to copy package registry file …
D1v38om83r Apr 7, 2026
df3c9f1
added code comments
D1v38om83r Apr 7, 2026
f92f71f
added logging for ExtensionVesion mismatch
D1v38om83r Apr 7, 2026
f1af9c1
Rename findVersionDir to splitPathAroundVersionedDir and updated code…
D1v38om83r Apr 7, 2026
ff2ded8
renamed variable
D1v38om83r Apr 7, 2026
ac03f69
fixed comment
D1v38om83r Apr 8, 2026
e7bebcf
Addressed PR comments
D1v38om83r Apr 8, 2026
bb37010
fixed error var name in Linux
D1v38om83r Apr 8, 2026
6df604c
updated comment
D1v38om83r Apr 9, 2026
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ bundle
extension-launcher*
internal/customactionplan/testdir/
licenses
main.exe
5 changes: 2 additions & 3 deletions internal/packageregistry/packageregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package packageregistry

import (
"encoding/json"
"io/ioutil"
"os"
"path"
"time"
Expand Down Expand Up @@ -168,7 +167,7 @@ func (self *PackageRegistry) GetExistingPackages() (CurrentPackageRegistry, erro
_, err := os.Stat(localApplicationRegistryFilePath)
if err == nil {
// The file exists
fileBytes, err := ioutil.ReadFile(localApplicationRegistryFilePath)
fileBytes, err := os.ReadFile(localApplicationRegistryFilePath)
if err != nil {
return currentPackageRegistry, err
}
Expand Down Expand Up @@ -210,7 +209,7 @@ func (self *PackageRegistry) WriteToDisk(packageRegistry CurrentPackageRegistry)
return err
}

err = ioutil.WriteFile(regFile, bytes, constants.FilePermissions_UserOnly_ReadWrite)
err = os.WriteFile(regFile, bytes, constants.FilePermissions_UserOnly_ReadWrite)
self.logger.Info("Wrote package registry to %v", regFile)

if doesBackupFileExist {
Expand Down
41 changes: 1 addition & 40 deletions main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func getVMExtension() (*vmextensionhelper.VMExtension, error) {
return nil, err
}

ii.UninstallCallback = vmAppUninstallCallback
ii.UninstallCallback = nil // no need to do any special handling on uninstall, so we can set the callback to nil
ii.UpdateCallback = vmAppUpdateCallback
ii.LogFileNamePattern = "VmAppExt_%v.log"

Expand Down Expand Up @@ -257,42 +257,3 @@ func customEnable(ext *vmextensionhelper.VMExtension, hostgaCommunicator hostgac

return nil
}

// Callback indicating the extension is being removed
func vmAppUninstallCallback(ext *vmextensionhelper.VMExtension) error {
ext.ExtensionEvents.LogInformationalEvent("Uninstalling", "VmApplications extension - removing all applications for uninstall")
hostGaCommunicator := hostgacommunicator.HostGaCommunicator{}
err := doVmAppUninstallCallback(ext, &hostGaCommunicator)
if err == nil {
ext.ExtensionEvents.LogInformationalEvent("Completed", "VmApplications extension uninstalled. Result=Success")
} else {
ext.ExtensionEvents.LogInformationalEvent(
"Completed",
fmt.Sprintf("VmApplications extension uninstall finished. Result=Failure;Reason=%v", err.Error()))
}
return err
}

func doVmAppUninstallCallback(ext *vmextensionhelper.VMExtension, hostGaCommunicator hostgacommunicator.IHostGaCommunicator) error {
packageRegistry, err := packageregistry.New(ext.ExtensionLogger, ext.HandlerEnv, filelockTimeoutDuration)
if err != nil {
return errors.Wrapf(err, "Could not create package registry")
}
defer packageRegistry.Close()

currentPackageRegistry, err := packageRegistry.GetExistingPackages()
if err != nil {
return errors.Wrapf(err, "Could not read current package registry")
}

// Create an empty incoming collection so we'll create an action plan to remove all applications
emptyIncomingCollection := make(packageregistry.VMAppPackageIncomingCollection, 0)

actionPlan := actionplan.New(currentPackageRegistry, emptyIncomingCollection, ext.HandlerEnv, hostGaCommunicator, ext.ExtensionLogger)
commandHandler := commandhandler.CommandHandler{}

// Removing applications is best effort, so even if there are errors here, we ignore them
_, _ = actionPlan.Execute(packageRegistry, ext.ExtensionEvents, &commandHandler)

return nil
}
79 changes: 0 additions & 79 deletions main/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
handlersettings "github.com/Azure/azure-extension-platform/pkg/settings"
"github.com/Azure/azure-extension-platform/pkg/status"
"github.com/Azure/azure-extension-platform/vmextension"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -466,84 +465,6 @@ func Test_main_nothingToProcess_withStatus(t *testing.T) {
require.Equal(t, requestedSequenceNumber, currentSequenceNumber)
}

func Test_uninstall_cannotCreatePackageRegistry(t *testing.T) {
vmApplications := []extdeserialization.VmAppSetting{}
ext := createTestVMExtension(t, vmApplications)
hostGaCommunicator := NoopHostGaCommunicator{}

// Set the config folder to an invalid path so we can't create a package registry
ext.HandlerEnv.ConfigFolder = "/yabaflarg/flarpaglarp"

err := doVmAppUninstallCallback(ext, &hostGaCommunicator)
require.Error(t, err)
require.EqualError(t, err, cannotCreatePackageRegistryError)
}

func Test_uninstall_cannotReadPackageRegistry(t *testing.T) {
vmApplications := []extdeserialization.VmAppSetting{}
ext := createTestVMExtension(t, vmApplications)
hostGaCommunicator := NoopHostGaCommunicator{}

// Write an invalid registry so we can't create a package registry
appRegistryFilePath := path.Join(ext.HandlerEnv.ConfigFolder, packageregistry.LocalApplicationRegistryFileName)
ioutil.WriteFile(appRegistryFilePath, []byte("}"), 0644)
defer os.Remove(appRegistryFilePath)

err := doVmAppUninstallCallback(ext, &hostGaCommunicator)
require.Error(t, err)
require.EqualError(t, err, "Could not read current package registry: invalid character '}' looking for beginning of value")
}

func Test_uninstall_noAppsToUninstall(t *testing.T) {
vmApplications := []extdeserialization.VmAppSetting{}
ext := createTestVMExtension(t, vmApplications)
hostGaCommunicator := NoopHostGaCommunicator{}

package1 := path.Join(ext.HandlerEnv.ConfigFolder, "package1")
package2 := path.Join(ext.HandlerEnv.ConfigFolder, "package2")
package1Quotes := fmt.Sprintf("\"%v\"", package1)
package2Quotes := fmt.Sprintf("\"%v\"", package2)

// Create a package registry where the remove commands will write their respective files
reg := packageregistry.CurrentPackageRegistry{"package1": &packageregistry.VMAppPackageCurrent{
ApplicationName: "package1",
DirectDownloadOnly: false,
InstallCommand: "dontcare",
RemoveCommand: "echo moein > " + package1Quotes,
UpdateCommand: "dontcare",
Version: "1.2.3.1",
}, "package2": &packageregistry.VMAppPackageCurrent{
ApplicationName: "package2",
DirectDownloadOnly: true,
InstallCommand: "dontcare",
RemoveCommand: "echo moein > " + package2Quotes,
UpdateCommand: "dontcare",
Version: "1.2.3.2",
}}

pkgHndlr, err := packageregistry.New(nopLog(), ext.HandlerEnv, time.Second)
assert.NoError(t, err, "operation should not throw error")
err = pkgHndlr.WriteToDisk(reg)
assert.NoError(t, err, "Should be able to write package registry to disk")
pkgHndlr.Close()

err = doVmAppUninstallCallback(ext, &hostGaCommunicator)
require.NoError(t, err)

// Verify we removed both apps, which deleted the files
require.True(t, fileExists(package1), "First application was not removed")
require.True(t, fileExists(package2), "Second application was not removed")
}

func Test_uninstall_uninstallApps(t *testing.T) {
vmApplications := []extdeserialization.VmAppSetting{}
ext := createTestVMExtension(t, vmApplications)
hostGaCommunicator := NoopHostGaCommunicator{}

err := doVmAppUninstallCallback(ext, &hostGaCommunicator)
require.NoError(t, err)
}

func fileExists(filePath string) bool {
if _, err := os.Stat(filePath); errors.Is(err, os.ErrNotExist) {
return false
Expand Down
Loading
Loading