File tree Expand file tree Collapse file tree 3 files changed +39
-2
lines changed
lib/octocatalog-diff/facts Expand file tree Collapse file tree 3 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -21,8 +21,18 @@ def self.fact_retriever(options = {}, node = '')
21
21
fact_file_data = fact_file_string . split ( /\n / )
22
22
fact_file_data [ 0 ] = '---' if fact_file_data [ 0 ] =~ /^---/
23
23
24
- # Load and return the parsed fact file.
25
- result = YAML . load ( fact_file_data . join ( "\n " ) )
24
+ # Load the parsed fact file.
25
+ parsed = YAML . load ( fact_file_data . join ( "\n " ) )
26
+
27
+ # This is a handler for a YAML file that has just the facts and none of the
28
+ # structure. For example if you saved the output of `facter -y` to a file and
29
+ # are passing that in, this will work.
30
+ result = if parsed . key? ( 'name' ) && parsed . key? ( 'values' )
31
+ parsed
32
+ else
33
+ { 'name' => node || parsed [ 'fqdn' ] || '' , 'values' => parsed }
34
+ end
35
+
26
36
result [ 'name' ] = node unless node == ''
27
37
result
28
38
end
Original file line number Diff line number Diff line change
1
+ ---
2
+ apt_update_last_success : 1458162123
3
+ architecture : amd64
4
+ datacenter : xyz
5
+ fqdn : rspec-node.xyz.github.net
6
+ " _timestamp " : 2014-12-02 12:56:20.865795 -08:00
7
+ ec2_metadata :
8
+ ami-id : ami-deadbeef
9
+ ami-launch-index : " 0"
10
+ ami-manifest-path : " (unknown)"
11
+ block-device-mapping :
12
+ ami : /dev/sda1
13
+ ephemeral0 : sdb
14
+ ephemeral1 : sdc
15
+ root : /dev/sda1
Original file line number Diff line number Diff line change 37
37
expect ( result [ 'name' ] ) . to eq ( 'override.node' )
38
38
expect ( result [ 'values' ] [ 'fqdn' ] ) . to eq ( 'rspec-node.xyz.github.net' )
39
39
end
40
+
41
+ it 'should convert unstructured facts into structured facts' do
42
+ fact_file = OctocatalogDiff ::Spec . fixture_path ( 'facts/unstructured.yaml' )
43
+ options = {
44
+ fact_file_string : File . read ( fact_file )
45
+ }
46
+ result = OctocatalogDiff ::Facts ::Yaml . fact_retriever ( options , 'override.node' )
47
+ expect ( result ) . to be_a_kind_of ( Hash )
48
+ expect ( result [ 'name' ] ) . to eq ( 'override.node' )
49
+ expect ( result [ 'values' ] [ 'fqdn' ] ) . to eq ( 'rspec-node.xyz.github.net' )
50
+ expect ( result [ 'values' ] [ 'ec2_metadata' ] [ 'block-device-mapping' ] [ 'ephemeral0' ] ) . to eq ( 'sdb' )
51
+ end
40
52
end
41
53
end
You can’t perform that action at this time.
0 commit comments