Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
fleetctl: add debug messages arround getUnit*()
Browse files Browse the repository at this point in the history
* Cover code path of getUnit*() functions with debug messages
* Improve code comments
  • Loading branch information
Djalal Harouni committed Feb 16, 2016
1 parent b2d34cd commit 44e9b2c
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions fleetctl/fleetctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,17 +484,21 @@ func getChecker() *ssh.HostKeyChecker {

func getUnit(file string) (*unit.UnitFile, error) {
var uf *unit.UnitFile
name := unitNameMangle(file)

// Failing that, assume the name references a local unit file on disk,
// and attempt to load that, if it exists
log.Debugf("Looking up for Unit(%s) or its corresponding template", name)

// Assume that the file references a local unit file on disk and
// attempt to load it, if it exists
if _, err := os.Stat(file); !os.IsNotExist(err) {
uf, err = getUnitFromFile(file)
if err != nil {
return nil, fmt.Errorf("failed getting Unit(%s) from file: %v", file, err)
}
} else {
// Otherwise (if the unit file does not exist), check if the name appears to be an instance unit,
// and if so, check for a corresponding template unit in the Registry
// Otherwise (if the unit file does not exist), check if the
// name appears to be an instance unit, and if so, check for
// a corresponding template unit in the Registry or disk
uf, err = getUnitFromTemplate(file)
if err != nil {
return nil, err
Expand All @@ -504,6 +508,7 @@ func getUnit(file string) (*unit.UnitFile, error) {
// the Registry - same unit file as the template, but different name
}

log.Debugf("Found Unit(%s)", name)
return uf, nil
}

Expand Down Expand Up @@ -542,9 +547,13 @@ func getUnitFromTemplate(arg string) (*unit.UnitFile, error) {
return nil, fmt.Errorf("error retrieving template Unit(%s) from Registry: %v", uni.Template, err)
}

// Finally, if we could not find a template unit in the Registry,
// check the local disk for one instead
if tmpl == nil {
if tmpl != nil {
warnOnDifferentLocalUnit(arg, tmpl)
uf = schema.MapSchemaUnitOptionsToUnitFile(tmpl.Options)
log.Debugf("Template Unit(%s) found in registry", uni.Template)
} else {
// Finally, if we could not find a template unit in the Registry,
// check the local disk for one instead
file := path.Join(path.Dir(arg), uni.Template)
if _, err := os.Stat(file); os.IsNotExist(err) {
return nil, fmt.Errorf("unable to find Unit(%s) or template Unit(%s) in Registry or on filesystem", name, uni.Template)
Expand All @@ -554,9 +563,6 @@ func getUnitFromTemplate(arg string) (*unit.UnitFile, error) {
if err != nil {
return nil, fmt.Errorf("failed getting template Unit(%s) from file: %v", uni.Template, err)
}
} else {
warnOnDifferentLocalUnit(arg, tmpl)
uf = schema.MapSchemaUnitOptionsToUnitFile(tmpl.Options)
}

return uf, nil
Expand Down Expand Up @@ -680,6 +686,9 @@ func lazyCreateUnits(args []string) error {
continue
}

// Assume that the name references a local unit file on
// disk or if it is an instance unit and if so get its
// corresponding unit
uf, err := getUnit(arg)
if err != nil {
return err
Expand Down

0 comments on commit 44e9b2c

Please sign in to comment.