Skip to content

Commit

Permalink
fix #47: allow host groups to have zero members
Browse files Browse the repository at this point in the history
Allow host groups to have zero members. Octopus will merely do nothing
for those groups and stll return successfully.

Signed-off-by: Blaine Gardner <[email protected]>
  • Loading branch information
BlaineEXE committed Oct 18, 2019
1 parent b550a9f commit 5b93a65
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
6 changes: 2 additions & 4 deletions internal/octopus/groupsfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ var getAddrsFromGroupsFile = func(hostGroups []string, groupsFile string) ([]str
cmd := exec.Command("bash", "-ec",
fmt.Sprintf("source %s ; echo %s", groupsFile, strings.Join(gVars, " ")))
o, err := cmd.CombinedOutput()
// convert to string which has exactly one newline
os := strings.TrimRight(string(o), "\n")
if err != nil {
return []string{}, fmt.Errorf("could not get groups %+v from %s: %+v\n%s", hostGroups, groupsFile, err, os)
return []string{}, fmt.Errorf("could not get groups %+v from %s: %+v\n%s", hostGroups, groupsFile, err, string(o))
}

addrs := strings.Split(os, " ")
addrs := strings.Fields(string(o))
return addrs, nil
}

Expand Down
1 change: 1 addition & 0 deletions test/setup-test-hosts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ cat << EOF > "$GROUPFILE"
export one='$one'
export rest='$rest'
export empty=''
EOF
echo 'export all="$one $rest"' >> "$GROUPFILE"
Expand Down
1 change: 1 addition & 0 deletions test/tests/01_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ echo "Running 'octopus host-groups' tests ..."
assert_success "with default groups" octopus host-groups
assert_output_count "one" 1
assert_output_count "rest" 1
assert_output_count "empty" 1

# create custom, more complex group file for this test
mkdir -p "$HOME/work"
Expand Down
4 changes: 4 additions & 0 deletions test/tests/02_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ for host in $HOSTNAMES; do # command failure should still report hostnames
assert_output_count "$host" 1
done
octopus -g one run "mv ${ls_location}.bkp ${ls_location}" 1> /dev/null


assert_success 'with group having no members' octopus -g empty run 'hostname'
assert_num_output_lines_with_text 0

0 comments on commit 5b93a65

Please sign in to comment.