Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4477 dpurdie 1
<%@LANGUAGE="VBSCRIPT"%>
2
<%
3
'=====================================================
4
'       Release Manager Admin Tests
5
'       Designed to be called via AJAX and to return
6
'       JSON formatted data to dynamic page
7
'=====================================================
8
%>
9
<%
10
Option explicit
11
' Good idea to set when using redirect
12
Response.Expires = 0   ' always load the page, dont store
13
%>
14
<!--#include file="common/conf.asp"-->
15
<!--#include file="common/globals.asp"-->
16
<!--#include file="common/qstr.asp"-->
17
<!--#include file="common/common_subs.asp"-->
18
<!--#include file="common/formating.asp"-->
5097 dpurdie 19
<!--#include file="common/release_changed.asp"-->
4477 dpurdie 20
<SCRIPT LANGUAGE="VBScript" RUNAT=SERVER SRC="common/base64encode.vbs"></SCRIPT> 
21
<SCRIPT LANGUAGE="VBScript" RUNAT=SERVER SRC="class/classaspJSON.vbs"></SCRIPT> 
22
<%
23
'------------ Variable Definition -------------
24
Dim parOpr, newitem
25
Dim result
26
 
27
' Basic Parameters
28
parOpr = QStrPar("Opr")
29
result = -1
30
 
31
' Init the output JSON class
32
'   Operations can add data
33
'   Default data will be added at the end
34
Dim oJSON
35
Set oJSON = New aspJSON
36
 
37
'
38
'   Determine the operation to be performed
4482 dpurdie 39
'   Invoke target routine
40
'   Expect:
41
'       result                    - test result
42
'       oJSON.data("emsgSummary") - Error detail
4477 dpurdie 43
'
4482 dpurdie 44
'
4477 dpurdie 45
If (parOpr = "zipTest") Then
4482 dpurdie 46
    Call zipFile
47
ElseIf (parOpr = "eventTest") Then
48
    Call sendEvent
49
ElseIf (parOpr = "emailTest") Then
50
    Call sendEmail
51
ElseIf (parOpr = "emailWshTest") Then
52
    Call sendWshEmail
53
ElseIf (parOpr = "remExecTest") Then
54
    Call remExec
55
ElseIf (parOpr = "pkgAccessTest") Then
56
    Call pkgAccess
5097 dpurdie 57
ElseIf (parOpr = "ddpTest") Then
58
    Call ddpTest
59
 
4482 dpurdie 60
Else
61
    oJSON.data("emsgSummary") = "Unknown operation requested:" & parOpr
62
End If
4477 dpurdie 63
 
4482 dpurdie 64
'
65
'   Create JSON data for the user
66
'   Important fields
67
'       result
68
'
69
'   Debug fields
70
'       Request (Array)
71
'
72
'Write single value
73
oJSON.data("result") = result
74
 
75
' DEBUG: An array of the user provided requests
76
Set oJSON.data("Request") = oJSON.Collection()
77
Set newitem = oJSON.AddToCollection(oJSON.data("Request"))
78
Dim variableName
79
for each variableName in Request.QueryString
80
    newitem.add variableName, Request.QueryString(variableName)
81
next
82
 
83
'Return the object
84
Response.Write oJSON.JSONoutput()
85
 
5097 dpurdie 86
Sub ddpTest
87
    Dim rv
88
        Dim objRC: Set objRC = New ReleaseChanged
89
        Call objRC.Run_ReleaseChanged(62884,1042919,enumRELEASE_CHANGE_MODE_PKG_ADDED, true)
90
        rv = objRC.last_resultCode
91
        Set objRC = Nothing
92
 
93
        If rv = 0 Then
94
            result = 0
95
        Else
96
            result = 1
97
            oJSON.data("emsgSummary") = "Error:("&rv&")"
98
        End If
99
 
100
End Sub
4482 dpurdie 101
'-------------------------------------------------
5097 dpurdie 102
' Function:    ddpTest
103
' Description:
104
' C:\WINDOWS\system32\cmd.exe" /c C:\clearcase\dpurdie_manager_suite\Release_Manager\scripts\bin\plink.exe -ssh -batch releasem@auperaarc01.vix.local -pw releasem "sudo ~/sbin/make_test_access;"
105
 
106
Sub ddpTest1
107
   Dim objWSH, rv, wCmdLine
108
   Dim plinkPath, plinkCmd, archiveServer, uname, upasswd, sudoCmd
109
 
110
      Dim sqry: sqry = "SELECT * FROM BUILD_SERVICE_CONFIG WHERE SERVICE='ARCHIVE SERVER'"
111
      Dim rsTemp
112
      Set rsTemp = OraDatabase.DbCreateDynaset( sqry , cint(0) )
113
      archiveServer = rsTemp("config")
114
      rsTemp.Close()
115
      Set rsTemp = Nothing
116
 
117
      Dim pArchive_Path : pArchive_Path = "dpkg_archive"
118
      Dim apkg_name     : apkg_name     = "pkg_name"
119
      Dim apkg_version  : apkg_version  = "pkg_version"
120
      Dim artag_id      : artag_id      = "rtag_id"
121
      Dim apkg_id       : apkg_id       = "pkg_id"
122
      Dim apv_id        : apv_id        = "pv_id"
123
      Dim aproj_id      : aproj_id      = "proj_id"
124
      Dim amode_id      : amode_id      = "mode_id"
125
 
126
      sudoCmd = "~/sbin/make_release_changed" &_
127
             " archive=" & pArchive_Path &_
128
             " pkg_name='\""" & apkg_name & "\""'" &_
129
             " pkg_version='\"""& apkg_version &"\""'" &_
130
             " rtag_id="& artag_id &_
131
             " pkg_id=" & apkg_id &_
132
             " pv_id="& apv_id &_
133
             " proj_id="& aproj_id &_
134
             " mode_id="& amode_id
135
 
136
       uname = "releasem"
137
       upasswd = "releasem"
138
       plinkPath = Request.ServerVariables("APPL_PHYSICAL_PATH") & "Release_Manager\scripts\bin\plink.exe"
139
       plinkCmd =  "-ssh -batch " & uname & "@" & archiveServer & " -pw " & upasswd & " ""sudo " & sudoCmd & ";"""
140
       wCmdLine =  plinkPath & " " & plinkCmd
141
 
142
        Set objWSH = Server.CreateObject("WScript.Shell")
143
        rv = objWSH.Run (wCmdLine, 0, TRUE)
144
        Set objWSH = Nothing
145
        If rv = 105 Then
146
            result = 0
147
        Else
148
            result = 1
149
            oJSON.data("emsgSummary") = "Error:("&rv&")" & wCmdLine
150
        End If
151
End Sub
152
 
153
'-------------------------------------------------
4482 dpurdie 154
' Function:    zipFile
155
' Description: Test the File Zipping process
156
Sub zipFile
4477 dpurdie 157
    '
158
    ' Create a test file in a known directory
159
    '
160
    Dim objZIPObject, ZipFile
161
    Dim outFile, objFSO, LocalDir, objFile
162
    Set objFSO=CreateObject("Scripting.FileSystemObject")
163
    LocalDir = Request.ServerVariables("APPL_PHYSICAL_PATH") & "release_manager\temp\"
164
 
165
    If NOT objFSO.FolderExists( LocalDir ) Then
166
        result = 1
167
        oJSON.data("emsgSummary") = "Folder not found:" & LocalDir
168
    Else
169
        ' Create a known file to zip up
170
        '
171
        outFile = LocalDir & "zipTestFile.txt"
172
        Set objFile = objFSO.CreateTextFile(outFile,True)
173
        objFile.Write "test string" & vbCrLf
174
        objFile.Close
175
 
176
        ' Zip up a test file
177
        '
178
        ZipFile = LocalDir & "zipTest.zip"
179
        If objFSO.FileExists(ZipFile) Then
180
       	    objFSO.DeleteFile ZipFile, TRUE
181
        End If
182
 
183
        On Error Resume Next
184
    	Set objZIPObject = Server.CreateObject("XStandard.Zip")
185
        If Err.Number <> 0 then
186
            result = 1
187
            oJSON.data("emsgSummary") = "Create XStandard.Zip:" & Err.Description
188
        Else
189
            objZIPObject.Pack outFile, ZipFile
190
 
191
            If objZIPObject.ErrorCode <> 0 then
192
                    result = 1
193
                    oJSON.data("emsgSummary") = "Zip Error XStandard:" & objZIPObject.ErrorCode & ":" & objZIPObject.ErrorDescription
194
            Else
195
                ' All done - must have passed
196
                result = 0
197
 
198
            End If
199
        End If
200
 
201
        '
202
        ' Clean up
203
        If objFSO.FileExists(outFile) Then
204
       	    objFSO.DeleteFile outFile, TRUE
205
        End If
206
 
207
        If objFSO.FileExists(ZipFile) Then
208
       	    objFSO.DeleteFile ZipFile, TRUE
209
        End If
210
 
211
        objZIPObject = Nothing
212
 
213
    End If
214
    set objFSO = Nothing
4482 dpurdie 215
End Sub
4477 dpurdie 216
 
4482 dpurdie 217
'-------------------------------------------------
218
' Function:    sendEvent
219
' Description: Send an Event to the Windows Log
220
Sub sendEvent
221
   Dim objWSH, rv
222
    Set objWSH = Server.CreateObject("WScript.Shell")
223
    rv = objWSH.Run ("cmd.exe /c cscript.exe //B //NoLogo " & rootPath & SCRIPTS_FOLDER & "\Admin_Test.wsf //job:onRaiseEvent", 0, TRUE)
224
    Set objWSH = Nothing
225
    If rv = 0 Then
226
        result = 0
227
    Else
228
        result = 1
229
        oJSON.data("emsgSummary") = "Error:("&rv&")"
230
    End If
231
End Sub
4477 dpurdie 232
 
4482 dpurdie 233
'-------------------------------------------------
234
' Function:     sendEmail
235
' Description:  Send an email
236
Sub sendEmail
237
   Dim Mode, Attachment, Message
238
 
239
   Attachment = Null
240
   Message = "This is a Test Email generated by the Release Manager Test."
241
   Mode = QStrPar("Mode")
242
 
243
   If Mode = "Attach" Then
244
        Attachment = Server.MapPath("images\img_reports_admin.jpg")
245
        Message = Message & " This message should have an attachment"
246
   End If
247
 
248
    Call Send_Email ( "Release Manager Notification", _
249
                       adminEmail, _
250
                       objAccessControl.UserEmail, _
251
                       "Test Email", _
252
                       Message, _
253
                       Attachment )
254
    result = Err.Number
255
    oJSON.data("emsgSummary") = Err.Description
256
    'oJSON.data("Info1") = Mode
257
    'oJSON.data("Info2") = Attachment
258
End Sub
259
 
260
'-------------------------------------------------
261
' Function:     sendWshEmail
262
' Description:  Send an email from a Wsh Script
263
Sub sendWshEmail
264
    Dim objWSH, rv
265
 
266
    Set objWSH = Server.CreateObject("WScript.Shell")
267
    rv = objWSH.Run ("cmd.exe /c cscript.exe //B //NoLogo " & rootPath & SCRIPTS_FOLDER & "\Admin_Test.wsf //job:onTestMail", 0, TRUE)
268
    Set objWSH = Nothing
269
    If rv = 0 Then
270
        result = 0
271
    Else
272
        result = 1
273
        oJSON.data("emsgSummary") = "Error:("&rv&")"
274
    End If
275
End Sub
276
 
277
'-------------------------------------------------
278
' Function:    remExec
279
' Description:  Test Release Manager Remote cmd Execution
280
Sub remExec
281
    Dim objWSH, rv
282
 
283
    Set objWSH = Server.CreateObject("WScript.Shell")
284
    rv = objWSH.Run ("cmd.exe /c cscript.exe //B //NoLogo " & rootPath & SCRIPTS_FOLDER & "\Admin_Test.wsf //job:onTestArchiveAccess", 0, TRUE)
285
    Set objWSH = Nothing
286
    If rv = 0 Then
287
        result = 0
288
    Else
289
        result = 1
290
        oJSON.data("emsgSummary") = "Error:("&rv&")"
291
    End If
292
End Sub
293
 
294
'-------------------------------------------------
295
' Function:    pkgAccess
296
' Description: Test dpkg_archive access - can we map it
4477 dpurdie 297
'
4482 dpurdie 298
Sub pkgAccess
299
    Dim objWSH, rv
4477 dpurdie 300
 
4482 dpurdie 301
    Set objWSH = Server.CreateObject("WScript.Shell")
302
    rv = objWSH.Run ("cmd.exe /c cscript.exe //B //NoLogo " & rootPath & SCRIPTS_FOLDER & "\Admin_Test.wsf //job:onTestMapArchive", 0, TRUE)
303
    Set objWSH = Nothing
304
    If rv = 0 Then
305
        result = 0
306
    Else
307
        result = 1
308
        oJSON.data("emsgSummary") = "Error:("&rv&")"
309
    End If
310
End Sub
4477 dpurdie 311
 
312
%>