Repository: osbuild/osbuild-composer
Pull request #892 (2020-07-27 21:58:34)

Fix the return value for a blueprint depsolve error


Patch:
diff --git a/internal/weldr/api.go b/internal/weldr/api.go
index 2b68f9f1c..b15377d7c 100644
--- a/internal/weldr/api.go
+++ b/internal/weldr/api.go
@@ -1118,12 +1118,11 @@ func (api *API) blueprintsDepsolveHandler(writer http.ResponseWriter, request *h
 		dependencies, _, err := api.depsolveBlueprint(blueprint, nil)
 
 		if err != nil {
-			errors := responseError{
+			blueprintsErrors = append(blueprintsErrors, responseError{
 				ID:  "BlueprintsError",
 				Msg: fmt.Sprintf("%s: %s", name, err.Error()),
-			}
-			statusResponseError(writer, http.StatusBadRequest, errors)
-			return
+			})
+			dependencies = []rpmmd.PackageSpec{}
 		}
 
 		blueprints = append(blueprints, entry{*blueprint, dependencies})


Test patch:
diff --git a/internal/client/blueprints_test.go b/internal/client/blueprints_test.go
index 35ccc975b..67c635b0d 100644
--- a/internal/client/blueprints_test.go
+++ b/internal/client/blueprints_test.go
@@ -982,6 +982,31 @@ func TestDepsolveInvalidBlueprintV0(t *testing.T) {
 	require.Contains(t, api.Errors[0].Msg, "Invalid characters in API path")
 }
 
+// depsolve a blueprint with a depsolve that will fail
+func TestBadDepsolveBlueprintV0(t *testing.T) {
+	if testState.unitTest {
+		t.Skip()
+	}
+	bp := `{
+		"name": "test-baddep-blueprint-v0",
+		"description": "TestBadDepsolveBlueprintV0",
+		"version": "0.0.1",
+		"packages": [{"name": "bash", "version": "*"}, {"name": "bad-package", "version": "1.32.1"}]
+	}`
+
+	// Push a blueprint
+	resp, err := PostJSONBlueprintV0(testState.socket, bp)
+	require.NoError(t, err, "POST blueprint failed with a client error")
+	require.True(t, resp.Status, "POST blueprint failed: %#v", resp)
+
+	// Depsolve the blueprint
+	deps, api, err := DepsolveBlueprintV0(testState.socket, "test-baddep-blueprint-v0")
+	require.NoError(t, err, "Depsolve blueprint failed with a client error")
+	require.Nil(t, api, "DepsolveBlueprint failed: %#v", api)
+	require.Greater(t, len(deps.Blueprints), 0, "No blueprints returned")
+	require.Greater(t, len(deps.Errors), 0, "Not enough errors returned")
+}
+
 // freeze a blueprint
 func TestBlueprintFreezeV0(t *testing.T) {
 	if testState.unitTest {
diff --git a/internal/weldr/api_test.go b/internal/weldr/api_test.go
index 4afef1baf..86dcca5c6 100644
--- a/internal/weldr/api_test.go
+++ b/internal/weldr/api_test.go
@@ -441,8 +441,8 @@ func TestBlueprintsDepsolve(t *testing.T) {
 		ExpectedJSON   string
 	}{
 		{rpmmd_mock.BaseFixture, http.StatusOK, `{"blueprints":[{"blueprint":{"name":"test","description":"Test","version":"0.0.1","packages":[{"name":"dep-package1","version":"*"}],"groups":[],"modules":[{"name":"dep-package3","version":"*"}]},"dependencies":[{"name":"dep-package3","epoch":7,"version":"3.0.3","release":"1.fc30","arch":"x86_64"},{"name":"dep-package1","epoch":0,"version":"1.33","release":"2.fc30","arch":"x86_64"},{"name":"dep-package2","epoch":0,"version":"2.9","release":"1.fc30","arch":"x86_64"}]}],"errors":[]}`},
-		{rpmmd_mock.NonExistingPackage, http.StatusBadRequest, `{"status":false,"errors":[{"id":"BlueprintsError","msg":"test: DNF error occured: MarkingErrors: Error occurred when marking packages for installation: Problems in request:\nmissing packages: fash"}]}`},
-		{rpmmd_mock.BadDepsolve, http.StatusBadRequest, `{"status":false,"errors":[{"id":"BlueprintsError","msg":"test: DNF error occured: DepsolveError: There was a problem depsolving ['go2rpm']: \n Problem: conflicting requests\n  - nothing provides askalono-cli needed by go2rpm-1-4.fc31.noarch"}]}`},
+		{rpmmd_mock.NonExistingPackage, http.StatusOK, `{"blueprints":[{"blueprint":{"name":"test","description":"Test","version":"0.0.1","packages":[{"name":"dep-package1","version":"*"}],"groups":[],"modules":[{"name":"dep-package3","version":"*"}]},"dependencies":[]}],"errors":[{"id":"BlueprintsError","msg":"test: DNF error occured: MarkingErrors: Error occurred when marking packages for installation: Problems in request:\nmissing packages: fash"}]}`},
+		{rpmmd_mock.BadDepsolve, http.StatusOK, `{"blueprints":[{"blueprint":{"name":"test","description":"Test","version":"0.0.1","packages":[{"name":"dep-package1","version":"*"}],"groups":[],"modules":[{"name":"dep-package3","version":"*"}]},"dependencies":[]}],"errors":[{"id":"BlueprintsError","msg":"test: DNF error occured: DepsolveError: There was a problem depsolving ['go2rpm']: \n Problem: conflicting requests\n  - nothing provides askalono-cli needed by go2rpm-1-4.fc31.noarch"}]}`},
 	}
 
 	for _, c := range cases {