From 4c71f8cac4337cadef5a4eabfe09a05bdf9366f1 Mon Sep 17 00:00:00 2001 From: Jim Idle Date: Wed, 24 Apr 2024 11:34:09 -0600 Subject: [PATCH] Ensure that python dependencies are installed during upgrade (#1390) ## Changes The installer.Upgrade() processing did not install Python dependencies. This resulted in errors such as: ``` ModuleNotFoundError: No module named 'databricks.labs.blueprint' ``` Any new dependencies are now installed during the upgrade process. Resolves: databrickslabs/ucx#1276 ## Tests The TestUpgraderWorksForReleases test now checks to see if the upgrade process resulted in the dependencies being installed. --------- Signed-off-by: Jim.Idle --- cmd/labs/project/installer.go | 4 ++++ cmd/labs/project/installer_test.go | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/cmd/labs/project/installer.go b/cmd/labs/project/installer.go index 235d29bc..42c4a849 100644 --- a/cmd/labs/project/installer.go +++ b/cmd/labs/project/installer.go @@ -136,6 +136,10 @@ func (i *installer) Upgrade(ctx context.Context) error { if err != nil { return fmt.Errorf("installer: %w", err) } + err = i.installPythonDependencies(ctx, ".") + if err != nil { + return fmt.Errorf("python dependencies: %w", err) + } return nil } diff --git a/cmd/labs/project/installer_test.go b/cmd/labs/project/installer_test.go index 709e14f2..0e049b4c 100644 --- a/cmd/labs/project/installer_test.go +++ b/cmd/labs/project/installer_test.go @@ -403,6 +403,12 @@ func TestUpgraderWorksForReleases(t *testing.T) { newHome := copyTestdata(t, "testdata/installed-in-home") ctx = env.WithUserHomeDir(ctx, newHome) + // Install stubs for the python calls we need to ensure were run in the + // upgrade process. + ctx, stub := process.WithStub(ctx) + stub.WithStderrFor(`python[\S]+ -m pip install .`, "[mock pip install]") + stub.WithStdoutFor(`python[\S]+ install.py`, "setting up important infrastructure") + py, _ := python.DetectExecutable(ctx) py, _ = filepath.Abs(py) ctx = env.Set(ctx, "PYTHON_BIN", py) @@ -420,4 +426,17 @@ func TestUpgraderWorksForReleases(t *testing.T) { r := internal.NewCobraTestRunnerWithContext(t, ctx, "labs", "upgrade", "blueprint") r.RunAndExpectOutput("setting up important infrastructure") + + // Check if the stub was called with the 'python -m pip install' command + pi := false + for _, call := range stub.Commands() { + if strings.HasSuffix(call, "-m pip install .") { + pi = true + break + } + } + if !pi { + t.Logf(`Expected stub command 'python[\S]+ -m pip install .' not found`) + t.FailNow() + } }