3 * ============LICENSE_START=======================================================
5 * ================================================================================
6 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
7 * ================================================================================
8 * Copyright (C) 2017 Amdocs
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.
22 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 * ============LICENSE_END=========================================================
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("execTimeout", "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("250", status);
81 assertEquals(TestId, "test1");
82 } catch (Exception e){
83 //if local ssh is not enabled
89 public void reqExecCommand_shouldSetSuccessRealCommand() throws SvcLogicException,
90 IllegalStateException, IllegalArgumentException {
92 params.put("HostName", "<IP address of SS server>");
93 params.put("Port", "2222");
94 params.put("User", "root");
95 params.put("Password", "vagrant");
96 params.put("Id", "test1");
97 params.put("cmd", "cd /srv/salt/; salt '*' state.apply vim --out=json --static");
98 params.put("slsExec", "true");
99 params.put("execTimeout", "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 } catch (Exception e){
109 //if saltstack ssh IP is not enabled
115 public void reqExecCommand_shouldSetSuccessRealSSL() throws SvcLogicException,
116 IllegalStateException, IllegalArgumentException {
118 params.put("HostName", "10.251.92.17");
119 params.put("Port", "2222");
120 params.put("User", "root");
121 params.put("Password", "vagrant");
122 params.put("Id", "test1");
123 params.put("slsName", "vim");
124 params.put("execTimeout", "12000");
125 params.put("applyTo", "minion1");
127 adapter = new SaltstackAdapterImpl();
129 adapter.reqExecSLS(params, svcContext);
130 String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
131 TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
132 assertEquals("200", status);
133 assertEquals(TestId, "test1");
134 } catch (Exception e){
135 //if saltstack ssh IP is not enabled
141 public void reqExecCommand_shouldSetSuccessRealSSLNoApplyTo() throws SvcLogicException,
142 IllegalStateException, IllegalArgumentException {
144 params.put("HostName", "10.251.92.17");
145 params.put("Port", "2222");
146 params.put("User", "root");
147 params.put("Password", "vagrant");
148 params.put("Id", "test1");
149 params.put("slsName", "vim");
150 params.put("execTimeout", "12000");
152 adapter = new SaltstackAdapterImpl();
154 adapter.reqExecSLS(params, svcContext);
155 String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
156 TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
157 assertEquals("200", status);
158 assertEquals(TestId, "test1");
159 } catch (Exception e){
160 //if saltstack ssh IP is not enabled
166 public void reqExecCommand_shouldSetSuccessSSLFile() throws SvcLogicException,
167 IllegalStateException, IllegalArgumentException {
169 params.put("HostName", "10.251.92.17");
170 params.put("Port", "2222");
171 params.put("User", "root");
172 params.put("Password", "vagrant");
173 params.put("Id", "test1");
174 params.put("execTimeout", "12000");
175 params.put("applyTo", "minion1");
176 params.put("slsFile", "src/test/resources/config.sls");
178 adapter = new SaltstackAdapterImpl();
180 adapter.reqExecSLSFile(params, svcContext);
181 String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
182 TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
183 assertEquals("200", status);
184 assertEquals(TestId, "test1");
185 } catch (Exception e){
186 //if saltstack ssh IP is not enabled