This repository was archived by the owner on May 9, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -143,6 +143,9 @@ def _ruby_value(match):
143143 url = data .get ('chef_server_url' )
144144 client_name = data .get ('node_name' )
145145 key_path = data .get ('client_key' )
146+ if key_path and not os .path .isabs (key_path ):
147+ # Relative paths are relative to the config file
148+ key_path = os .path .abspath (os .path .join (os .path .dirname (path ), key_path ))
146149 else :
147150 log .debug ('Ruby parse failed with exit code %s: %s' , proc .returncode , out .strip ())
148151 if not url :
Original file line number Diff line number Diff line change 1+ key_name = 'client'
2+ chef_server_url "#{ url } "
3+ client_key "../#{ key_name } .pem"
4+ # Use both kind of quotes, also a comment for testing
5+ node_name "test_1"
6+ # test multiple line values
7+ client_name = {
8+ 'dev' => 'test_1'
9+ } [ 'dev' ]
Original file line number Diff line number Diff line change 11import os
22
3+ import mock
34import unittest2
45
56from chef .api import ChefAPI
67
8+
79class APITestCase (unittest2 .TestCase ):
810 def load (self , path ):
911 path = os .path .join (os .path .dirname (__file__ ), 'configs' , path )
1012 return ChefAPI .from_config_file (path )
1113
14+ @mock .patch ('chef.api.subprocess.Popen' )
15+ def test_config_with_interpolated_settings (self , mock_subproc_popen ):
16+ process_mock = mock .Mock ()
17+ output = b'{"chef_server_url": "http:///chef:4000", "client_key": "../client.pem",' \
18+ b'"node_name": "test_1"}'
19+ attrs = {
20+ 'communicate.return_value' : (output , 'error' ),
21+ 'returncode' : 0 }
22+ process_mock .configure_mock (** attrs )
23+ mock_subproc_popen .return_value = process_mock
24+
25+ api = self .load ('basic_with_interpolated_values.rb' )
26+ self .assertEqual (api .client , 'test_1' )
27+
1228 def test_basic (self ):
1329 api = self .load ('basic.rb' )
1430 self .assertEqual (api .url , 'http://chef:4000' )
You can’t perform that action at this time.
0 commit comments