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 +30
-2
lines changed Expand file tree Collapse file tree 3 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -136,13 +136,16 @@ def _ruby_value(match):
136
136
url = key_path = client_name = None
137
137
proc = subprocess .Popen ('ruby' , stdin = subprocess .PIPE , stdout = subprocess .PIPE )
138
138
script = config_ruby_script % path .replace ('\\ ' , '\\ \\ ' ).replace ("'" , "\\ '" )
139
- out , err = proc .communicate (script )
139
+ out , err = proc .communicate (script . encode () )
140
140
if proc .returncode == 0 and out .strip ():
141
- data = json .loads (out )
141
+ data = json .loads (out . decode () )
142
142
log .debug ('Ruby parse succeeded with %r' , data )
143
143
url = data .get ('chef_server_url' )
144
144
client_name = data .get ('node_name' )
145
145
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 ))
146
149
else :
147
150
log .debug ('Ruby parse failed with exit code %s: %s' , proc .returncode , out .strip ())
148
151
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 1
1
import os
2
2
3
+ import mock
3
4
import unittest2
4
5
5
6
from chef .api import ChefAPI
6
7
8
+
7
9
class APITestCase (unittest2 .TestCase ):
8
10
def load (self , path ):
9
11
path = os .path .join (os .path .dirname (__file__ ), 'configs' , path )
10
12
return ChefAPI .from_config_file (path )
11
13
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
+
12
28
def test_basic (self ):
13
29
api = self .load ('basic.rb' )
14
30
self .assertEqual (api .url , 'http://chef:4000' )
You can’t perform that action at this time.
0 commit comments