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

Refactoring to support edge-tracking in graph #1078

Merged
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
20 changes: 9 additions & 11 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,8 @@ const (
// ModConnection defines details about connections between modules. Currently,
// only modules connected with "use" are tracked.
type ModConnection struct {
toID string
fromID string
// Currently only supports useConnection
kind ConnectionKind
// List of variables shared from module `fromID` to module `toID`
ref reference
kind ConnectionKind
sharedVariables []string
}

Expand Down Expand Up @@ -322,7 +319,8 @@ func (dc *DeploymentConfig) listUnusedModules() map[string][]string {
unusedModules := make(map[string][]string)
for _, conn := range dc.moduleConnections {
if conn.isEmpty() {
unusedModules[conn.fromID] = append(unusedModules[conn.fromID], conn.toID)
fromMod := conn.ref.FromModuleID()
unusedModules[fromMod] = append(unusedModules[fromMod], conn.ref.ToModuleID())
}
}
return unusedModules
Expand Down Expand Up @@ -508,21 +506,21 @@ func modToGrp(groups []DeploymentGroup, modID string) (int, error) {

// checkUsedModuleNames verifies that any used modules have valid names and
// are in the correct group
func checkUsedModuleNames(depGroups []DeploymentGroup) error {
for _, grp := range depGroups {
func checkUsedModuleNames(bp Blueprint) error {
for _, grp := range bp.DeploymentGroups {
for _, mod := range grp.Modules {
for _, usedMod := range mod.Use {
ref, err := identifyModuleByReference(usedMod, grp)
if err != nil {
return err
}

if err = ref.validate(depGroups); err != nil {
if err = ref.validate(bp); err != nil {
return err
}

// TODO: remove this when support is added!
if ref.FromGroupID != ref.ToGroupID {
if ref.fromGroupID != ref.toGroupID {
return fmt.Errorf("%s: %s is an intergroup reference",
errorMessages["varInAnotherGroup"], usedMod)
}
Expand Down Expand Up @@ -570,7 +568,7 @@ func (dc *DeploymentConfig) validateConfig() {
if err = checkModuleAndGroupNames(dc.Config.DeploymentGroups); err != nil {
log.Fatal(err)
}
if err = checkUsedModuleNames(dc.Config.DeploymentGroups); err != nil {
if err = checkUsedModuleNames(dc.Config); err != nil {
log.Fatal(err)
}
if err = checkBackends(dc.Config); err != nil {
Expand Down
34 changes: 24 additions & 10 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,39 +400,53 @@ func (s *MySuite) TestListUnusedModules(c *C) {
got := dc.listUnusedModules()
c.Assert(got, HasLen, 0)

// All "use" modules actually used
// test used module with shared variables
usedConn := ModConnection{
toID: "usedModule",
fromID: "usingModule",
ref: modReference{
toModuleID: "usedModule",
fromModuleID: "usingModule",
toGroupID: "group1",
fromGroupID: "group1",
explicit: true,
},
kind: useConnection,
sharedVariables: []string{"var1"},
}
dc.moduleConnections = []ModConnection{usedConn}
got = dc.listUnusedModules()
c.Assert(got["usingModule"], HasLen, 0)

// One fully unused module
// test used module with no shared variables (i.e. "unused")
unusedConn := ModConnection{
toID: "usedModule",
fromID: "usingModule",
ref: modReference{
toModuleID: "firstUnusedModule",
fromModuleID: "usingModule",
toGroupID: "group1",
fromGroupID: "group1",
explicit: true,
},
kind: useConnection,
sharedVariables: []string{},
}
dc.moduleConnections = append(dc.moduleConnections, unusedConn)
got = dc.listUnusedModules()
c.Assert(got["usingModule"], HasLen, 1)

// Two fully unused modules
// test second used module with no shared variables (i.e. "unused")
secondUnusedConn := ModConnection{
toID: "secondUnusedModule",
fromID: "usingModule",
ref: modReference{
toModuleID: "secondUnusedModule",
fromModuleID: "usingModule",
toGroupID: "group1",
fromGroupID: "group1",
explicit: true,
},
kind: useConnection,
sharedVariables: []string{},
}
dc.moduleConnections = append(dc.moduleConnections, secondUnusedConn)
got = dc.listUnusedModules()
c.Assert(got["usingModule"], HasLen, 2)

}

func (s *MySuite) TestAddKindToModules(c *C) {
Expand Down
Loading