summaryrefslogtreecommitdiffstats
path: root/saltstack-server/README.md
blob: 69e47ec44b1fdb3ddaf1b4484b04d89512593b07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
'''
/*-
* ============LICENSE_START=======================================================
* ONAP : CCSDK
* ================================================================================
* Copyright (C) 2018 Samsung Electronics.  All rights reserved.
* ================================================================================
* 
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* 
* 
* ============LICENSE_END=========================================================
*/
'''
USING VAGRANT for CREATING SALTSTACK SERVER
<CREATING saltstack environment is outside the scope of this adaptor, however the requirement is as follows>
a. The SaltStack server should have it’s SSH enabled.
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).
============
INSTALLATION: Saltstack DEMO Environment creation:
============

1, Install VirtualBox.
2, Install Vagrant.
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).
4, Extract the zip file you downloaded, and then open a command prompt to the extracted directory.
5, Run vagrant up to start the demo environment: vagrant up
   After Vagrant ups (~10 minutes) and you are back at the command prompt, you are ready to continue.
   More info: https://docs.saltstack.com/en/getstarted/fundamentals/

============
Configuration: Sample Saltstack server execution configuration requirement.
============
1, login to Master Saltstack server node:
"sudo vi /etc/ssh/sshd_config" and SET the following
PermitEmptyPasswords yes
PermitRootLogin yes

SAVE and close.

2, Run: "sudo passwd root"
and set the root password.
Then run: "sudo reboot"

3, On the host machine, open the virtual box set a port forwarding to the master server for 2222 -> 22 
This will redirect messages to host machine to the Vagarant Master server.  

============
TESTING: Sample Saltstack server command execution.
============
    
    @Test
    public void reqExecCommand_shouldSetSuccessReal() throws SvcLogicException,
            IllegalStateException, IllegalArgumentException {

        params.put("HostName", "127.0.0.1");
        params.put("Port", "22");
        params.put("User", "sdn");
        params.put("Password", "foo");
        params.put("Id", "test1");
        params.put("Cmd", "ls -l");
        params.put("SlsExec", "false");
        params.put("Timeout", "12000");
        adapter = new SaltstackAdapterImpl();
        try {
            adapter.reqExecCommand(params, svcContext);
            String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
            TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
            assertEquals("200", status);
            assertEquals(TestId, "test1");
        } catch (Exception e){
            //if local ssh is not enabled
            System.out.print(e.getMessage());
        }
    }

    @Test
    public void reqExecCommand_shouldSetSuccessRealSLSCommand() throws SvcLogicException,
            IllegalStateException, IllegalArgumentException {

        params.put("HostName", "<IP>");
        params.put("Port", "2222");
        params.put("User", "root");
        params.put("Password", "vagrant");
        params.put("Id", "test1");
        params.put("Cmd", "salt '*' test.ping --out=json --static");
        params.put("SlsExec", "false");
        params.put("Timeout", "12000");

        adapter = new SaltstackAdapterImpl();
        try {
            adapter.reqExecCommand(params, svcContext);
            String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
            TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
            assertEquals("200", status);
            assertEquals(TestId, "test1");
            TestId = svcContext.getAttribute("test1.minion1");
            assertEquals(TestId, "true");
        } catch (Exception e){
            //if saltstack ssh IP is not enabled
            System.out.print(e.getMessage());
        }
    }

    @Test
    public void reqExecCommand_shouldSetSuccessRealCommand() throws SvcLogicException,
            IllegalStateException, IllegalArgumentException {

        params.put("HostName", "<IP>");
        params.put("Port", "2222");
        params.put("User", "root");
        params.put("Password", "vagrant");
        params.put("Id", "test1");
        params.put("Cmd", "cd /srv/salt/; salt '*' state.apply vim --out=json --static");
        params.put("SlsExec", "true");
        params.put("Timeout", "12000");

        adapter = new SaltstackAdapterImpl();
        try {
            adapter.reqExecCommand(params, svcContext);
            String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
            TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
            assertEquals("200", status);
            assertEquals(TestId, "test1");
        } catch (Exception e){
            //if saltstack ssh IP is not enabled
            System.out.print(e.getMessage());
        }
    }

    @Test
    public void reqExecCommand_shouldSetSuccessRealSSL() throws SvcLogicException,
            IllegalStateException, IllegalArgumentException {

        params.put("HostName", "<IP>");
        params.put("Port", "2222");
        params.put("User", "root");
        params.put("Password", "vagrant");
        params.put("Id", "test1");
        params.put("SlsName", "vim");
        params.put("Timeout", "12000");
        params.put("NodeList", "minion1");

        adapter = new SaltstackAdapterImpl();
        try {
            adapter.reqExecSLS(params, svcContext);
            String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
            TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
            assertEquals("200", status);
            assertEquals(TestId, "test1");
        } catch (Exception e){
            //if saltstack ssh IP is not enabled
            System.out.print(e.getMessage());
        }
    }

    @Test
    public void reqExecCommand_shouldSetSuccessEnvParam() throws SvcLogicException,
            IllegalStateException, IllegalArgumentException {

        params.put("HostName", "<IP>");
        params.put("Port", "2222");
        params.put("User", "root");
        params.put("Password", "vagrant");
        params.put("Id", "test1");
        params.put("SlsName", "vim");
        params.put("Timeout", "12000");
        params.put("NodeList", "minion1");
        params.put("EnvParameters", "{\"exclude\": bar*}");

        adapter = new SaltstackAdapterImpl();
        try {
            adapter.reqExecSLS(params, svcContext);
            String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
            TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
            assertEquals("200", status);
            assertEquals(TestId, "test1");
        } catch (Exception e){
            //if saltstack ssh IP is not enabled
            System.out.print(e.getMessage());
        }
    }

    @Test
    public void reqExecCommand_shouldSetSuccessFileParam() throws SvcLogicException,
            IllegalStateException, IllegalArgumentException {

        params.put("HostName", "<IP>");
        params.put("Port", "2222");
        params.put("User", "root");
        params.put("Password", "vagrant");
        params.put("Id", "test1");
        params.put("SlsName", "vim");
        params.put("Timeout", "12000");
        params.put("NodeList", "minion1");
        params.put("EnvParameters", "{\"exclude\": \"bar,baz\"}");
        params.put("FileParameters", "{\"config.txt\":\"db_ip=10.1.1.1, sip_timer=10000\"}");

        adapter = new SaltstackAdapterImpl();
        try {
            adapter.reqExecSLS(params, svcContext);
            String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
            TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
            assertEquals("200", status);
            assertEquals(TestId, "test1");
        } catch (Exception e){
            //if saltstack ssh IP is not enabled
            System.out.print(e.getMessage());
        }
    }

    @Test
    public void reqExecCommand_shouldSetSuccessPillarParam() throws SvcLogicException,
            IllegalStateException, IllegalArgumentException {

        params.put("HostName", "<IP>");
        params.put("Port", "2222");
        params.put("User", "root");
        params.put("Password", "vagrant");
        params.put("Id", "test1");
        params.put("SlsName", "vim");
        params.put("Timeout", "12000");
        params.put("NodeList", "minion1");
        params.put("EnvParameters", "{\"exclude\": \"bar,baz\", \"pillar\":\"'{\\\"foo\\\": \\\"bar\\\"}'\"}");
        params.put("FileParameters", "{\"config.txt\":\"db_ip=10.1.1.1, sip_timer=10000\"}");

        adapter = new SaltstackAdapterImpl();
        try {
            adapter.reqExecSLS(params, svcContext);
            String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
            TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
            assertEquals("200", status);
            assertEquals(TestId, "test1");
        } catch (Exception e){
            //if saltstack ssh IP is not enabled
            System.out.print(e.getMessage());
        }
    }

    @Test
    public void reqExecCommand_shouldSetSuccessMultiFileParam() throws SvcLogicException,
            IllegalStateException, IllegalArgumentException {

        params.put("HostName", "<IP>");
        params.put("Port", "2222");
        params.put("User", "root");
        params.put("Password", "vagrant");
        params.put("Id", "test1");
        params.put("SlsName", "vim");
        params.put("Timeout", "12000");
        params.put("NodeList", "minion1");
        params.put("EnvParameters", "{\"exclude\": bar*}");
        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\"}");

        adapter = new SaltstackAdapterImpl();
        try {
            adapter.reqExecSLS(params, svcContext);
            String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
            TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
            assertEquals("200", status);
            assertEquals(TestId, "test1");
        } catch (Exception e){
            //if saltstack ssh IP is not enabled
            System.out.print(e.getMessage());
        }
    }

    @Test
    public void reqExecCommand_shouldSetSuccessSSLFile() throws SvcLogicException,
            IllegalStateException, IllegalArgumentException {

        params.put("HostName", "<IP>");
        params.put("Port", "2222");
        params.put("User", "root");
        params.put("Password", "vagrant");
        params.put("Id", "test1");
        params.put("Timeout", "12000");
        params.put("NodeList", "minion1");
        params.put("SlsFile", "src/test/resources/config.sls");

        adapter = new SaltstackAdapterImpl();
        try {
            adapter.reqExecSLSFile(params, svcContext);
            String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
            TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
            assertEquals("200", status);
            assertEquals(TestId, "test1");
        } catch (Exception e){
            //if saltstack ssh IP is not enabled
            System.out.print(e.getMessage());
        }
    }
    
        @Test
        public void reqExecCommand_shouldSetSuccessSSLFileMultiFileParam() throws SvcLogicException,
                IllegalStateException, IllegalArgumentException {
    
            params.put("HostName", "<IP>");
            params.put("Port", "2222");
            params.put("User", "root");
            params.put("Password", "vagrant");
            params.put("Id", "test1");
            params.put("Timeout", "12000");
            params.put("NodeList", "minion1");
            params.put("SlsFile", "src/test/resources/config.sls");
            params.put("EnvParameters", "{\"exclude\": bar, \"pillar\":\"'{\\\"foo\\\": \\\"bar\\\"}'\"}");
            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\"}");
    
            adapter = new SaltstackAdapterImpl();
            try {
                adapter.reqExecSLSFile(params, svcContext);
                String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
                TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
                assertEquals("200", status);
                assertEquals(TestId, "test1");
            } catch (Exception e){
                //if saltstack ssh IP is not enabled
                System.out.print(e.getMessage());
            }
        }