Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

worker: fixed duplicated ns and ns not inherited bug #403

Merged
merged 1 commit into from
Jun 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 11 additions & 8 deletions worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,26 +145,29 @@ func detectContent(imageFormat, name, path string, headers map[string]string, pa
return
}

// detectNamespaces returns a list of unique namespaces detected in a layer and its ancestry.
func detectNamespaces(name string, files tarutil.FilesMap, parent *database.Layer) (namespaces []database.Namespace, err error) {
namespaces, err = featurens.Detect(files)
nsSet := map[string]*database.Namespace{}
nsCurrent, err := featurens.Detect(files)
if err != nil {
return
}
if len(namespaces) > 0 {
for _, ns := range namespaces {
log.WithFields(log.Fields{logLayerName: name, "detected namespace": ns.Name}).Debug("detected namespace")
}
return

for _, ns := range nsCurrent {
nsSet[ns.Name] = &ns
log.WithFields(log.Fields{logLayerName: name, "detected namespace": ns.Name}).Debug("detected namespace")
}

// Fallback to the parent's namespace.
if parent != nil {
for _, ns := range parent.Namespaces {
nsSet[ns.Name] = &ns
log.WithFields(log.Fields{logLayerName: name, "detected namespace": ns.Name}).Debug("detected namespace (from parent)")
}
return
}

for _, ns := range nsSet {
namespaces = append(namespaces, *ns)
}
return
}

Expand Down
11 changes: 8 additions & 3 deletions worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,16 @@ func TestProcessWithDistUpgrade(t *testing.T) {
// Ensure that the 'wheezy' layer has the expected namespace and non-upgraded features.
jessie, ok := datastore.layers["jessie"]
if assert.True(t, ok, "layer 'jessie' not processed") {
if !assert.Len(t, jessie.Namespaces, 1) {
if !assert.Len(t, jessie.Namespaces, 2) {
return
}
assert.Equal(t, "debian:8", jessie.Namespaces[0].Name)
assert.Len(t, jessie.Features, 74)
nsNames := []string{jessie.Namespaces[0].Name, jessie.Namespaces[1].Name}
// the old features and namespace should remain here with only the features in new namespaces detected
assert.Contains(t, nsNames, "debian:8")
assert.Contains(t, nsNames, "debian:7")

// because the featurefmt detects the features under "debian:8" and "debian:7", therefore the number of features is duplicated
assert.Len(t, jessie.Features, 148)

for _, nufv := range nonUpgradedFeatureVersions {
nufv.Feature.Namespace.Name = "debian:7"
Expand Down