3 * ============LICENSE_START=======================================================
5 * ================================================================================
6 * Copyright (C) 2018 Samsung Electronics. All rights reserved.
7 * ================================================================================
9 * =============================================================================
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 USING VAGRANT for CREATING SALTSTACK SERVER
27 <CREATING saltstack environment is outside the scope of this adaptor, however the requirement is as follows>
28 a. The SaltStack server should have it’s SSH enabled.
29 b. Via ssh user account we should have the access to run saltstack command (here we will see how to enable root access via ssh and connect to server via root user).
31 INSTALLATION: Saltstack DEMO Environment creation:
34 1, Install VirtualBox.
36 3, Download https://github.com/UtahDave/salt-vagrant-demo. You can use git or download a zip of the project directly from GitHub (sample Vagrant attached).
37 4, Extract the zip file you downloaded, and then open a command prompt to the extracted directory.
38 5, Run vagrant up to start the demo environment: vagrant up
39 After Vagrant ups (~10 minutes) and you are back at the command prompt, you are ready to continue.
40 More info: https://docs.saltstack.com/en/getstarted/fundamentals/
43 Configuration: Sample Saltstack server execution configuration requirement.
45 1, login to Master Saltstack server node:
46 "sudo vi /etc/ssh/sshd_config" and SET the following
47 PermitEmptyPasswords yes
52 2, Run: "sudo passwd root"
53 and set the root password.
54 Then run: "sudo reboot"
56 3, On the host machine, open the virtual box set a port forwarding to the master server for 2222 -> 22
57 This will redirect messages to host machine to the Vagarant Master server.
60 TESTING: Sample Saltstack server command execution.
64 public void reqExecCommand_shouldSetSuccessReal() throws SvcLogicException,
65 IllegalStateException, IllegalArgumentException {
67 params.put("HostName", "127.0.0.1");
68 params.put("Port", "22");
69 params.put("User", "sdn");
70 params.put("Password", "foo");
71 params.put("Id", "test1");
72 params.put("Cmd", "ls -l");
73 params.put("SlsExec", "false");
74 params.put("Timeout", "12000");
75 adapter = new SaltstackAdapterImpl();
77 adapter.reqExecCommand(params, svcContext);
78 String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
79 TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
80 assertEquals("200", status);
81 assertEquals(TestId, "test1");
82 } catch (Exception e){
83 //if local ssh is not enabled
84 System.out.print(e.getMessage());
89 public void reqExecCommand_shouldSetSuccessRealSLSCommand() throws SvcLogicException,
90 IllegalStateException, IllegalArgumentException {
92 params.put("HostName", "<IP>");
93 params.put("Port", "2222");
94 params.put("User", "root");
95 params.put("Password", "vagrant");
96 params.put("Id", "test1");
97 params.put("Cmd", "salt '*' test.ping --out=json --static");
98 params.put("SlsExec", "false");
99 params.put("Timeout", "12000");
101 adapter = new SaltstackAdapterImpl();
103 adapter.reqExecCommand(params, svcContext);
104 String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
105 TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
106 assertEquals("200", status);
107 assertEquals(TestId, "test1");
108 TestId = svcContext.getAttribute("test1.minion1");
109 assertEquals(TestId, "true");
110 } catch (Exception e){
111 //if saltstack ssh IP is not enabled
112 System.out.print(e.getMessage());
117 public void reqExecCommand_shouldSetSuccessRealCommand() throws SvcLogicException,
118 IllegalStateException, IllegalArgumentException {
120 params.put("HostName", "<IP>");
121 params.put("Port", "2222");
122 params.put("User", "root");
123 params.put("Password", "vagrant");
124 params.put("Id", "test1");
125 params.put("Cmd", "cd /srv/salt/; salt '*' state.apply vim --out=json --static");
126 params.put("SlsExec", "true");
127 params.put("Timeout", "12000");
129 adapter = new SaltstackAdapterImpl();
131 adapter.reqExecCommand(params, svcContext);
132 String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
133 TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
134 assertEquals("200", status);
135 assertEquals(TestId, "test1");
136 } catch (Exception e){
137 //if saltstack ssh IP is not enabled
138 System.out.print(e.getMessage());
143 public void reqExecCommand_shouldSetSuccessRealSSL() throws SvcLogicException,
144 IllegalStateException, IllegalArgumentException {
146 params.put("HostName", "<IP>");
147 params.put("Port", "2222");
148 params.put("User", "root");
149 params.put("Password", "vagrant");
150 params.put("Id", "test1");
151 params.put("SlsName", "vim");
152 params.put("Timeout", "12000");
153 params.put("NodeList", "minion1");
155 adapter = new SaltstackAdapterImpl();
157 adapter.reqExecSLS(params, svcContext);
158 String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
159 TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
160 assertEquals("200", status);
161 assertEquals(TestId, "test1");
162 } catch (Exception e){
163 //if saltstack ssh IP is not enabled
164 System.out.print(e.getMessage());
169 public void reqExecCommand_shouldSetSuccessEnvParam() throws SvcLogicException,
170 IllegalStateException, IllegalArgumentException {
172 params.put("HostName", "<IP>");
173 params.put("Port", "2222");
174 params.put("User", "root");
175 params.put("Password", "vagrant");
176 params.put("Id", "test1");
177 params.put("SlsName", "vim");
178 params.put("Timeout", "12000");
179 params.put("NodeList", "minion1");
180 params.put("EnvParameters", "{\"exclude\": bar*}");
182 adapter = new SaltstackAdapterImpl();
184 adapter.reqExecSLS(params, svcContext);
185 String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
186 TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
187 assertEquals("200", status);
188 assertEquals(TestId, "test1");
189 } catch (Exception e){
190 //if saltstack ssh IP is not enabled
191 System.out.print(e.getMessage());
196 public void reqExecCommand_shouldSetSuccessFileParam() throws SvcLogicException,
197 IllegalStateException, IllegalArgumentException {
199 params.put("HostName", "<IP>");
200 params.put("Port", "2222");
201 params.put("User", "root");
202 params.put("Password", "vagrant");
203 params.put("Id", "test1");
204 params.put("SlsName", "vim");
205 params.put("Timeout", "12000");
206 params.put("NodeList", "minion1");
207 params.put("EnvParameters", "{\"exclude\": \"bar,baz\"}");
208 params.put("FileParameters", "{\"config.txt\":\"db_ip=10.1.1.1, sip_timer=10000\"}");
210 adapter = new SaltstackAdapterImpl();
212 adapter.reqExecSLS(params, svcContext);
213 String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
214 TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
215 assertEquals("200", status);
216 assertEquals(TestId, "test1");
217 } catch (Exception e){
218 //if saltstack ssh IP is not enabled
219 System.out.print(e.getMessage());
224 public void reqExecCommand_shouldSetSuccessPillarParam() throws SvcLogicException,
225 IllegalStateException, IllegalArgumentException {
227 params.put("HostName", "<IP>");
228 params.put("Port", "2222");
229 params.put("User", "root");
230 params.put("Password", "vagrant");
231 params.put("Id", "test1");
232 params.put("SlsName", "vim");
233 params.put("Timeout", "12000");
234 params.put("NodeList", "minion1");
235 params.put("EnvParameters", "{\"exclude\": \"bar,baz\", \"pillar\":\"'{\\\"foo\\\": \\\"bar\\\"}'\"}");
236 params.put("FileParameters", "{\"config.txt\":\"db_ip=10.1.1.1, sip_timer=10000\"}");
238 adapter = new SaltstackAdapterImpl();
240 adapter.reqExecSLS(params, svcContext);
241 String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
242 TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
243 assertEquals("200", status);
244 assertEquals(TestId, "test1");
245 } catch (Exception e){
246 //if saltstack ssh IP is not enabled
247 System.out.print(e.getMessage());
252 public void reqExecCommand_shouldSetSuccessMultiFileParam() throws SvcLogicException,
253 IllegalStateException, IllegalArgumentException {
255 params.put("HostName", "<IP>");
256 params.put("Port", "2222");
257 params.put("User", "root");
258 params.put("Password", "vagrant");
259 params.put("Id", "test1");
260 params.put("SlsName", "vim");
261 params.put("Timeout", "12000");
262 params.put("NodeList", "minion1");
263 params.put("EnvParameters", "{\"exclude\": bar*}");
264 params.put("FileParameters", "{\"config.txt\":\"db_ip=10.1.1.1, sip_timer=10000\" , \"config-tep.txt\":\"db_ip=10.1.1.1, sip_timer=10000\"}");
266 adapter = new SaltstackAdapterImpl();
268 adapter.reqExecSLS(params, svcContext);
269 String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
270 TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
271 assertEquals("200", status);
272 assertEquals(TestId, "test1");
273 } catch (Exception e){
274 //if saltstack ssh IP is not enabled
275 System.out.print(e.getMessage());
280 public void reqExecCommand_shouldSetSuccessSSLFile() throws SvcLogicException,
281 IllegalStateException, IllegalArgumentException {
283 params.put("HostName", "<IP>");
284 params.put("Port", "2222");
285 params.put("User", "root");
286 params.put("Password", "vagrant");
287 params.put("Id", "test1");
288 params.put("Timeout", "12000");
289 params.put("NodeList", "minion1");
290 params.put("SlsFile", "src/test/resources/config.sls");
292 adapter = new SaltstackAdapterImpl();
294 adapter.reqExecSLSFile(params, svcContext);
295 String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
296 TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
297 assertEquals("200", status);
298 assertEquals(TestId, "test1");
299 } catch (Exception e){
300 //if saltstack ssh IP is not enabled
301 System.out.print(e.getMessage());
306 public void reqExecCommand_shouldSetSuccessSSLFileMultiFileParam() throws SvcLogicException,
307 IllegalStateException, IllegalArgumentException {
309 params.put("HostName", "<IP>");
310 params.put("Port", "2222");
311 params.put("User", "root");
312 params.put("Password", "vagrant");
313 params.put("Id", "test1");
314 params.put("Timeout", "12000");
315 params.put("NodeList", "minion1");
316 params.put("SlsFile", "src/test/resources/config.sls");
317 params.put("EnvParameters", "{\"exclude\": bar, \"pillar\":\"'{\\\"foo\\\": \\\"bar\\\"}'\"}");
318 params.put("FileParameters", "{\"config.txt\":\"db_ip=10.1.1.1, sip_timer=10000\" , \"config-tep.txt\":\"db_ip=10.1.1.1, sip_timer=10000\"}");
320 adapter = new SaltstackAdapterImpl();
322 adapter.reqExecSLSFile(params, svcContext);
323 String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
324 TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
325 assertEquals("200", status);
326 assertEquals(TestId, "test1");
327 } catch (Exception e){
328 //if saltstack ssh IP is not enabled
329 System.out.print(e.getMessage());