Subversion Repositories DevTools

Rev

Rev 6645 | Details | Compare with Previous | 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
5168 dpurdie 13
Response.ContentType="application/json"
4477 dpurdie 14
%>
15
<!--#include file="common/conf.asp"-->
16
<!--#include file="common/globals.asp"-->
17
<!--#include file="common/qstr.asp"-->
18
<!--#include file="common/common_subs.asp"-->
19
<!--#include file="common/formating.asp"-->
5097 dpurdie 20
<!--#include file="common/release_changed.asp"-->
4477 dpurdie 21
<SCRIPT LANGUAGE="VBScript" RUNAT=SERVER SRC="common/base64encode.vbs"></SCRIPT> 
22
<SCRIPT LANGUAGE="VBScript" RUNAT=SERVER SRC="class/classaspJSON.vbs"></SCRIPT> 
23
<%
24
'------------ Variable Definition -------------
25
Dim parOpr, newitem
26
Dim result
27
 
28
' Basic Parameters
29
parOpr = QStrPar("Opr")
30
result = -1
31
 
32
' Init the output JSON class
33
'   Operations can add data
34
'   Default data will be added at the end
35
Dim oJSON
36
Set oJSON = New aspJSON
37
 
38
'
39
'   Determine the operation to be performed
4482 dpurdie 40
'   Invoke target routine
41
'   Expect:
42
'       result                    - test result
43
'       oJSON.data("emsgSummary") - Error detail
4477 dpurdie 44
'
4482 dpurdie 45
'
4477 dpurdie 46
If (parOpr = "zipTest") Then
4482 dpurdie 47
    Call zipFile
48
ElseIf (parOpr = "eventTest") Then
49
    Call sendEvent
50
ElseIf (parOpr = "emailTest") Then
51
    Call sendEmail
5172 dpurdie 52
ElseIf (parOpr = "reportEvent") Then
53
    Call reportEvent
4482 dpurdie 54
ElseIf (parOpr = "remExecTest") Then
5172 dpurdie 55
    Call remExecTest
4482 dpurdie 56
ElseIf (parOpr = "pkgAccessTest") Then
5172 dpurdie 57
    Call pkgAccessTest
5245 dpurdie 58
ElseIf (parOpr = "lxrAccessTest") Then
59
    Call lxrAccessTest
7260 dpurdie 60
ElseIf (parOpr = "abtLogAccess") Then
61
    Call abtLogAccess
5097 dpurdie 62
 
4482 dpurdie 63
Else
64
    oJSON.data("emsgSummary") = "Unknown operation requested:" & parOpr
65
End If
4477 dpurdie 66
 
4482 dpurdie 67
'
68
'   Create JSON data for the user
69
'   Important fields
70
'       result
71
'
72
'   Debug fields
73
'       Request (Array)
74
'
75
'Write single value
76
oJSON.data("result") = result
77
 
78
' DEBUG: An array of the user provided requests
79
Set oJSON.data("Request") = oJSON.Collection()
80
Set newitem = oJSON.AddToCollection(oJSON.data("Request"))
81
Dim variableName
82
for each variableName in Request.QueryString
83
    newitem.add variableName, Request.QueryString(variableName)
84
next
85
 
86
'Return the object
87
Response.Write oJSON.JSONoutput()
5957 dpurdie 88
Set oJSON = Nothing
89
Call Destroy_All_Objects
4482 dpurdie 90
 
91
'-------------------------------------------------
92
' Function:    zipFile
93
' Description: Test the File Zipping process
94
Sub zipFile
4477 dpurdie 95
    '
96
    ' Create a test file in a known directory
97
    '
98
    Dim objZIPObject, ZipFile
99
    Dim outFile, objFSO, LocalDir, objFile
100
    Set objFSO=CreateObject("Scripting.FileSystemObject")
6645 dpurdie 101
    LocalDir = Server.MapPath("temp")
4477 dpurdie 102
 
103
    If NOT objFSO.FolderExists( LocalDir ) Then
104
        result = 1
105
        oJSON.data("emsgSummary") = "Folder not found:" & LocalDir
106
    Else
107
        ' Create a known file to zip up
108
        '
109
        outFile = LocalDir & "zipTestFile.txt"
110
        Set objFile = objFSO.CreateTextFile(outFile,True)
111
        objFile.Write "test string" & vbCrLf
112
        objFile.Close
113
 
114
        ' Zip up a test file
115
        '
116
        ZipFile = LocalDir & "zipTest.zip"
117
        If objFSO.FileExists(ZipFile) Then
118
       	    objFSO.DeleteFile ZipFile, TRUE
119
        End If
120
 
121
        On Error Resume Next
122
    	Set objZIPObject = Server.CreateObject("XStandard.Zip")
123
        If Err.Number <> 0 then
124
            result = 1
125
            oJSON.data("emsgSummary") = "Create XStandard.Zip:" & Err.Description
126
        Else
127
            objZIPObject.Pack outFile, ZipFile
128
 
129
            If objZIPObject.ErrorCode <> 0 then
130
                    result = 1
131
                    oJSON.data("emsgSummary") = "Zip Error XStandard:" & objZIPObject.ErrorCode & ":" & objZIPObject.ErrorDescription
132
            Else
133
                ' All done - must have passed
134
                result = 0
135
 
136
            End If
137
        End If
138
 
139
        '
140
        ' Clean up
141
        If objFSO.FileExists(outFile) Then
142
       	    objFSO.DeleteFile outFile, TRUE
143
        End If
144
 
145
        If objFSO.FileExists(ZipFile) Then
146
       	    objFSO.DeleteFile ZipFile, TRUE
147
        End If
148
 
149
        objZIPObject = Nothing
150
 
151
    End If
152
    set objFSO = Nothing
4482 dpurdie 153
End Sub
4477 dpurdie 154
 
4482 dpurdie 155
'-------------------------------------------------
5168 dpurdie 156
' Function:    reportEvent
157
' Description:  Create an event in the machines event log
158
 
159
Sub reportEvent
160
    Report_Event enumEVENT_ERROR, "Admin Test", "", "Release Manager test: reportEvent" 
161
    If Err.number = 0 Then
162
        result = 0
163
    Else
164
        result = 1
165
        oJSON.data("emsgSummary") = "Error:("&Err.number&"):" & Err.description
166
    End If
167
End Sub
168
 
169
'-------------------------------------------------
4482 dpurdie 170
' Function:    sendEvent
171
' Description: Send an Event to the Windows Log
172
Sub sendEvent
5168 dpurdie 173
    Send_Event enumEVENT_ERROR, "Release Manager Test Log" 
174
    If Err.number = 0 Then
175
        result = 0
176
    Else
177
        result = 1
178
        oJSON.data("emsgSummary") = "Error:("&Err.number&"):" & err.description
179
    End If
180
End Sub
181
 
182
'-------------------------------------------------
4482 dpurdie 183
' Function:     sendEmail
184
' Description:  Send an email
185
Sub sendEmail
186
   Dim Mode, Attachment, Message
187
 
188
   Attachment = Null
189
   Message = "This is a Test Email generated by the Release Manager Test."
190
   Mode = QStrPar("Mode")
191
 
192
   If Mode = "Attach" Then
193
        Attachment = Server.MapPath("images\img_reports_admin.jpg")
194
        Message = Message & " This message should have an attachment"
195
   End If
196
 
197
    Call Send_Email ( "Release Manager Notification", _
5357 dpurdie 198
                       ADMIN_EMAIL, _
4482 dpurdie 199
                       objAccessControl.UserEmail, _
200
                       "Test Email", _
201
                       Message, _
202
                       Attachment )
203
    result = Err.Number
204
    oJSON.data("emsgSummary") = Err.Description
205
    'oJSON.data("Info1") = Mode
206
    'oJSON.data("Info2") = Attachment
207
End Sub
208
 
209
'-------------------------------------------------
5172 dpurdie 210
' Function:    remExecTest
211
' Description: Ensure that we can communicate with the package server
212
 
213
Sub remExecTest
4482 dpurdie 214
 
5172 dpurdie 215
    Dim objRC: Set objRC = New ReleaseChanged
216
    Dim rv
4482 dpurdie 217
 
5172 dpurdie 218
    Call objRC.TestAccess(request.servervariables("server_name"))
219
    rv = objRc.last_resultCode
4482 dpurdie 220
    If rv = 0 Then
221
        result = 0
222
    Else
223
        result = 1
5172 dpurdie 224
        oJSON.data("emsgSummary") = "Error:("&rv&"), " & objRc.last_errorMsg
4482 dpurdie 225
    End If
5172 dpurdie 226
    Set objRC = Nothing
4482 dpurdie 227
End Sub
228
 
229
'-------------------------------------------------
5172 dpurdie 230
' Function:    pkgAccessTest
4482 dpurdie 231
' Description: Test dpkg_archive access - can we map it
4477 dpurdie 232
'
5172 dpurdie 233
Sub pkgAccessTest
4477 dpurdie 234
 
5172 dpurdie 235
    If testArchiveAccessPkg("","") Then
4482 dpurdie 236
        result = 0
237
    Else
238
        result = 1
5172 dpurdie 239
        oJSON.data("emsgSummary") = "Archive not responding"
4482 dpurdie 240
    End If
241
End Sub
4477 dpurdie 242
 
5245 dpurdie 243
'-------------------------------------------------
244
' Function:    lxrAccessTest
245
' Description: Test dpkg_archive access - can we map it
246
'
247
Sub lxrAccessTest
248
 
249
    Dim oXMLHTTP
250
    Dim testUrl
251
    Dim testAccess
252
    testAccess = False
6070 dpurdie 253
    testUrl = LXR_URL & ".test"
5245 dpurdie 254
    Set oXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.3.0")
255
 
256
    ' Use error handling in case dpkg_archive is not available
257
    ' Use HEAD to test existence
258
    Err.Clear
259
    On Error Resume Next
260
    oXMLHTTP.Open "HEAD", testUrl, False
261
    oXMLHTTP.Send
262
 
263
    ' Do not combine the next two If statments - it will not work
264
    If Err.Number = 0  Then
6070 dpurdie 265
        If oXMLHTTP.Status = 200 Then 
266
            testAccess = True
267
        End If
5245 dpurdie 268
    End If
269
    On Error Goto 0
270
 
271
    If testAccess Then
272
        result = 0
273
    Else
274
        result = 1
275
        oJSON.data("emsgSummary") = "LXR Server not responding"
276
    End If
277
End Sub
278
 
7260 dpurdie 279
'-------------------------------------------------
280
' Function:    abtLogAccess
281
' Description: Test dpkg_archive access - can we map it
282
'
283
Sub abtLogAccess
284
 
285
    Dim oXMLHTTP
286
    Dim testUrl
287
    Dim testAccess
288
    testAccess = False
289
 
290
    testUrl = HTTP_PKG_ARCHIVE & "/cgi-bin/getBuildLogs.pl"
291
    Set oXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.3.0")
292
 
293
    ' Use error handling in case dpkg_archive is not available
294
    ' Use HEAD to test existence
295
    Err.Clear
296
    On Error Resume Next
297
    oXMLHTTP.Open "HEAD", testUrl, False
298
    oXMLHTTP.Send
299
 
300
    ' Do not combine the next two If statments - it will not work
301
    If Err.Number = 0  Then
302
        If oXMLHTTP.Status = 200 Then 
303
            testAccess = True
304
        End If
305
    End If
306
    On Error Goto 0
307
 
308
    If testAccess Then
309
        result = 0
310
    Else
311
        result = 1
312
        oJSON.data("emsgSummary") = "ABTLOG Server not responding"
313
    End If
314
End Sub
315
 
4477 dpurdie 316
%>