Skip to content

Commit

Permalink
More test results more consistent by sorting lists.
Browse files Browse the repository at this point in the history
  • Loading branch information
nbering committed May 25, 2019
1 parent 34a8592 commit 7a44486
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 25 deletions.
12 changes: 6 additions & 6 deletions sample_data/0.11.x/basic/expect.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"all": {
"children": [],
"hosts": [
"www.example.com",
"base.example.com",
"db.example.com"
"db.example.com",
"www.example.com"
],
"vars": {}
},
Expand All @@ -36,16 +36,16 @@
"example": {
"children": [],
"hosts": [
"www.example.com",
"db.example.com"
"db.example.com",
"www.example.com"
],
"vars": {}
},
"web": {
"children": [
"foo",
"bar",
"baz"
"baz",
"foo"
],
"hosts": [
"www.example.com"
Expand Down
6 changes: 3 additions & 3 deletions sample_data/0.11.x/count-advanced/expect.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
"all": {
"children": [],
"hosts": [
"rough-bread.example.com",
"broad-union.example.com",
"young-violet.example.com",
"lively-tree.example.com",
"mute-fog.example.com"
"mute-fog.example.com",
"rough-bread.example.com",
"young-violet.example.com"
],
"vars": {}
}
Expand Down
6 changes: 3 additions & 3 deletions sample_data/0.11.x/count-basic/expect.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
"all": {
"children": [],
"hosts": [
"count-sample-4.example.com",
"count-sample-0.example.com",
"count-sample-1.example.com",
"count-sample-2.example.com",
"count-sample-3.example.com",
"count-sample-0.example.com",
"count-sample-1.example.com"
"count-sample-4.example.com"
],
"vars": {}
}
Expand Down
8 changes: 4 additions & 4 deletions sample_data/0.11.x/individual-vars/expect.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"all": {
"children": [],
"hosts": [
"www.example.com",
"db.example.com"
"db.example.com",
"www.example.com"
],
"vars": {}
},
Expand All @@ -32,8 +32,8 @@
"example": {
"children": [],
"hosts": [
"www.example.com",
"db.example.com"
"db.example.com",
"www.example.com"
],
"vars": {}
},
Expand Down
4 changes: 2 additions & 2 deletions sample_data/0.12.x/basic/expect.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
},
"web": {
"children": [
"foo",
"bar",
"baz"
"baz",
"foo"
],
"hosts": [
"www.example.com"
Expand Down
4 changes: 2 additions & 2 deletions sample_data/0.12.x/count-advanced/expect.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
"children": [],
"hosts": [
"broad-union.example.com",
"young-violet.example.com",
"lively-tree.example.com",
"mute-fog.example.com",
"rough-bread.example.com"
"rough-bread.example.com",
"young-violet.example.com"
],
"vars": {}
}
Expand Down
18 changes: 13 additions & 5 deletions terraform.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python

import bisect
import sys
import json
import os
Expand Down Expand Up @@ -40,10 +41,17 @@ def _extract_list(attrs, key):


def _init_group(children=None, hosts=None, vars=None):
if children is None:
children = []
if hosts is None:
hosts = []
if vars is None:
vars = {}

return {
"hosts": [] if hosts is None else hosts,
"vars": {} if vars is None else vars,
"children": [] if children is None else children
"hosts": sorted(hosts),
"vars": vars,
"children": sorted(children)
}


Expand All @@ -67,7 +75,7 @@ def _add_host(inventory, hostname, groups, host_vars):
if group not in inventory.keys():
inventory[group] = _init_group(hosts=[hostname])
elif hostname not in inventory[group]["hosts"]:
inventory[group]["hosts"].append(hostname)
bisect.insort(inventory[group]["hosts"], hostname)


def _add_group(inventory, group_name, children, group_vars):
Expand All @@ -78,7 +86,7 @@ def _add_group(inventory, group_name, children, group_vars):
else:
# Start out with support for only one "group" with a given name
# If there's a second group by the name, last in wins
inventory[group_name]["children"] = children
inventory[group_name]["children"] = sorted(children)
inventory[group_name]["vars"] = group_vars


Expand Down

0 comments on commit 7a44486

Please sign in to comment.