mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Plugins: Skip install errors if dependency plugin already exists (#94710)
* skip install errors if dependency plugin already exists * add test
This commit is contained in:
parent
284c2d6f71
commit
f97f489c2c
@ -75,6 +75,11 @@ func (m *PluginInstaller) Add(ctx context.Context, pluginID, version string, opt
|
||||
|
||||
err = m.Add(ctx, dep.ID, dep.Version, opts)
|
||||
if err != nil {
|
||||
var dupeErr plugins.DuplicateError
|
||||
if errors.As(err, &dupeErr) {
|
||||
m.log.Info("Dependency already installed", "pluginId", dep.ID)
|
||||
continue
|
||||
}
|
||||
return fmt.Errorf("%v: %w", fmt.Sprintf("failed to download plugin %s from repository", dep.ID), err)
|
||||
}
|
||||
}
|
||||
|
@ -279,6 +279,50 @@ func TestPluginManager_Add_Remove(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []string{p2Zip, p1Zip}, loadedPaths)
|
||||
})
|
||||
|
||||
t.Run("Plugin can successfully install even if dependency plugin is already installed", func(t *testing.T) {
|
||||
const pluginDependencyID = "test-plugin-dependency"
|
||||
reg := &fakes.FakePluginRegistry{
|
||||
Store: map[string]*plugins.Plugin{
|
||||
pluginDependencyID: createPlugin(t, pluginDependencyID, plugins.ClassExternal, false, false),
|
||||
},
|
||||
}
|
||||
|
||||
var loadedPaths []string
|
||||
loader := &fakes.FakeLoader{
|
||||
LoadFunc: func(ctx context.Context, src plugins.PluginSource) ([]*plugins.Plugin, error) {
|
||||
loadedPaths = append(loadedPaths, src.PluginURIs(ctx)...)
|
||||
return []*plugins.Plugin{}, nil
|
||||
},
|
||||
}
|
||||
|
||||
pluginRepo := &fakes.FakePluginRepo{
|
||||
GetPluginArchiveFunc: func(_ context.Context, id, version string, _ repo.CompatOpts) (*repo.PluginArchive, error) {
|
||||
return &repo.PluginArchive{File: &zip.ReadCloser{Reader: zip.Reader{File: []*zip.File{{
|
||||
FileHeader: zip.FileHeader{Name: fmt.Sprintf("%s.zip", id)},
|
||||
}}}}}, nil
|
||||
},
|
||||
}
|
||||
|
||||
fs := &fakes.FakePluginStorage{
|
||||
ExtractFunc: func(_ context.Context, id string, _ storage.DirNameGeneratorFunc, z *zip.ReadCloser) (*storage.ExtractedPluginArchive, error) {
|
||||
switch id {
|
||||
case testPluginID:
|
||||
return &storage.ExtractedPluginArchive{
|
||||
Dependencies: []*storage.Dependency{{ID: pluginDependencyID}},
|
||||
Path: "test-plugin.zip",
|
||||
}, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown plugin %s", id)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
inst := New(reg, loader, pluginRepo, fs, storage.SimpleDirNameGeneratorFunc, &fakes.FakeAuthService{})
|
||||
err := inst.Add(context.Background(), testPluginID, "", testCompatOpts())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []string{"test-plugin.zip"}, loadedPaths)
|
||||
})
|
||||
}
|
||||
|
||||
func createPlugin(t *testing.T, pluginID string, class plugins.Class, managed, backend bool, cbs ...func(*plugins.Plugin)) *plugins.Plugin {
|
||||
|
Loading…
Reference in New Issue
Block a user