Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

655 lines
21 KiB

  1. Option Explicit
  2. '*****************************************************************************
  3. '*
  4. '* Define Constants
  5. '*
  6. '*****************************************************************************
  7. 'Debugging Constants
  8. CONST CONST_DEBUG = FALSE
  9. CONST CONST_CLEANUP = TRUE
  10. CONST USERNAME="administrator"
  11. CONST PASSWORD="xxxx"
  12. DIM objWMI
  13. DIM strTestHost
  14. DIM intTestRuns
  15. 'Parse Command Line
  16. If Wscript.Arguments.Count < 1 Then
  17. Wscript.Echo("Invalid Syntax:")
  18. Wscript.Echo("")
  19. Wscript.Echo("vssbvt.vbs <HostName> <#iterations>")
  20. Wscript.quit
  21. End If
  22. WScript.Echo "Starting tests...."
  23. strTestHost = Wscript.Arguments(0)
  24. intTestRuns = 1
  25. if Wscript.Arguments.Count > 1 then
  26. intTestRuns = Wscript.Arguments(1)
  27. end if
  28. WScript.Echo "Connecting to WMI CIMV2 namespace on " & strTestHost
  29. Call ConnectWMI(strTestHost, objWMI)
  30. WScript.Echo("")
  31. DIM iCount
  32. For iCount = 1 To intTestRuns
  33. WScript.Echo "Running Smoke Tests..." & iCount
  34. WScript.Echo "------------------------------------------------------------------------------"
  35. If blnSmoke(objWMI, intTestRuns) = FALSE Then
  36. 'Wscript.Quit
  37. End If
  38. WScript.Echo "------------------------------------------------------------------------------"
  39. WScript.Echo("")
  40. Next
  41. '*****************************************************************************
  42. '*
  43. '* Function ConnectWMI()
  44. '*
  45. '* Description: Connects to the target node WMI Namespace
  46. '*
  47. '* Parameters: IN ByRef strMachine The machine name
  48. '* OUT ByRef objController The wmi service object
  49. '*
  50. '* Output: TRUE if the operation was successful. FALSE if not.
  51. '*
  52. '******************************************************************************
  53. Function ConnectWMI(ByRef strMachine, ByRef objWMI)
  54. ConnectWMI = TRUE
  55. If CONST_DEBUG = FALSE Then
  56. On Error Resume Next
  57. End If
  58. ' Connect To WMI
  59. Set objWMI = new cWMI
  60. If objWMI.ConnectToNamespace("root\CIMV2", strMachine, "", "") = FALSE Then
  61. Wscript.echo("BVT FAIL: Error Connecting to WMI Namespace")
  62. ConnectWMI = FALSE
  63. Exit Function
  64. End If
  65. End Function
  66. '//***************************************************************************
  67. '//
  68. '// Function blnSelectVolumes
  69. '//
  70. '// Description: Select the first two volumes with >100MB freespace
  71. '//
  72. '// Parameters: [IN] ByRef objWMI The WMI Connection Object
  73. '// [OUT] ByRef objVolume A Volume to shadow
  74. '// [OUT] ByRef objDiffVolume A Volume to store the diff area
  75. '//
  76. '// Output: TRUE if the operation was successful. FALSE if not.
  77. '//
  78. '//*****************************************************************************
  79. Function blnSmoke(ByRef objWMI, ByVal intTestCases)
  80. blnSmoke = FALSE
  81. DIM objVolume, objDiffVolume, objShadow
  82. DIM objDiffVolumeToCheck
  83. If CONST_DEBUG = FALSE Then
  84. On Error Resume Next
  85. End If
  86. ' Delete all shadows to get to a known starting point
  87. If blnShadowDeleteAll(objWMI) = FALSE Then
  88. blnSmoke = FALSE
  89. Exit Function
  90. End If
  91. Wscript.Echo("All Shadow instances deleted")
  92. ' Delete all diff areas to get to a known starting point
  93. If blnStorageDeleteAll(objWMI) = FALSE Then
  94. blnSmoke = FALSE
  95. Exit Function
  96. End If
  97. Wscript.Echo("All ShadowStorage instances deleted")
  98. ' Select a volume to shadow and a volume for diff area storage
  99. If blnVolumeSelect2(objWMI, objVolume, objDiffVolume) = TRUE Then
  100. Wscript.Echo("Shadow volume: " & objVolume.DeviceID)
  101. Wscript.Echo("Diff area volume: " & objDiffVolume.DeviceID)
  102. ' Create a new diff are storage instance with the selected volumes
  103. if blnStorageCreate(objWMI, objVolume, objDiffVolume) = TRUE Then
  104. Wscript.Echo("ShadowStorage created")
  105. ' Create a new shadow instance for the selected volume
  106. if blnShadowCreate(objWMI, objVolume, objShadow) = TRUE Then
  107. Wscript.Echo("ShadowCopy created: ID=" & objShadow.ID)
  108. ' Traverse associations and check integrity of schema along the way
  109. if blnSmokeAssocTraverse(objWMI, objShadow, objVolume, objDiffVolume) = FALSE Then
  110. Wscript.Echo("BVT FAIL: Smoke: association check failed")
  111. Exit Function
  112. End If
  113. ' Change the size of the storage area
  114. if blnStorageChangeSize(objVolume, objDiffVolume) = FALSE Then
  115. Wscript.Echo("BVT FAIL: Smoke: diff area storage size change failed")
  116. Exit Function
  117. End If
  118. Wscript.Echo("ShadowStorage size modified")
  119. ' Clean up; delete the shadow and storage instances
  120. if blnShadowDeleteAll(objWMI) = FALSE Then
  121. Wscript.Echo("BVT FAIL: Smoke: cleanup deletion of shadows failed")
  122. Exit Function
  123. End If
  124. Wscript.Echo("All Shadow instances deleted")
  125. if blnStorageDeleteAll(objWMI) = FALSE Then
  126. Wscript.Echo("BVT FAIL: Smoke: cleanup deletion of diff area storage failed")
  127. Exit Function
  128. End If
  129. Wscript.Echo("All ShadowStorage instances deleted")
  130. blnSmoke = TRUE
  131. End If
  132. End If
  133. End If
  134. If Err.Number <> 0 Then
  135. DIM objLastError
  136. Wscript.Echo("BVT FAIL: Smoke: Unexpected Error " & err.number & " " & err.description)
  137. Set objLastError = CreateObject("wbemscripting.swbemlasterror")
  138. Wscript.Echo("Provider: " & objLastError.ProviderName)
  139. Wscript.Echo("Operation: " & objLastError.Operation)
  140. Wscript.Echo("Description: " & objLastError.Description)
  141. Wscript.Echo("StatusCode: 0x" & Hex(objLastError.StatusCode))
  142. blnSmoke = FALSE
  143. Err.Clear
  144. End If
  145. If blnSmoke = TRUE Then
  146. Wscript.Echo("BVT PASS: Smoke")
  147. End If
  148. If blnSmoke = FALSE Then
  149. Wscript.Echo("FAIL PASS: Smoke")
  150. End If
  151. End Function
  152. '//***************************************************************************
  153. '//
  154. '// Function blnSmokeTraverseAssoc
  155. '//
  156. '// Description: Traverse associations between ShadowCopy, Volume and Provider
  157. '//
  158. '// Parameters: [IN] ByRef objWMI WMI connection
  159. '// [IN] ByRef objShadow A ShadowCopy
  160. '// [IN] ByRef objVolume A Volume
  161. '// [IN] ByRef objDiffVolume A Volume storing the diff area
  162. '//
  163. '// Output: TRUE if the operation was successful. FALSE if not.
  164. '//
  165. '//*****************************************************************************
  166. Function blnSmokeAssocTraverse(ByRef objWMI, ByRef objShadow, ByRef objVolume, ByRef objDiffVolume)
  167. blnSmokeAssocTraverse = TRUE
  168. If CONST_DEBUG = FALSE Then
  169. On Error Resume Next
  170. End If
  171. DIM objSet, obj
  172. DIM intCount
  173. DIM blnFound
  174. DIM objProvider, objVol
  175. ' Check Win32_ShadowOn traversal
  176. intCount = 0
  177. blnFound = FALSE
  178. Set objSet = objShadow.Associators_("Win32_ShadowOn")
  179. For Each obj in objSet
  180. intCount = intCount + 1
  181. If intCount > 1 Then
  182. Wscript.Echo("BVT FAIL: shadowcopy associated with too many volume endpoints")
  183. blnSmokeAssocTraverse = FALSE
  184. End If
  185. If obj.DeviceID = objDiffVolume.DeviceID Then
  186. blnFound = TRUE
  187. End If
  188. Next
  189. if blnFound = FALSE Then
  190. Wscript.Echo("BVT FAIL: No volume endpoint found traversing Win32_ShadowOn")
  191. blnSmokeAssocTraverse = FALSE
  192. End If
  193. Wscript.Echo("ShadowOn association verified")
  194. ' Check Win32_ShadowBy traversal
  195. intCount = 0
  196. blnFound = FALSE
  197. Set objProvider = objWMI.objWMI.Get("Win32_ShadowProvider.ID='" & objShadow.ProviderID & "'")
  198. Set objSet = objProvider.Associators_("Win32_ShadowBy")
  199. For Each obj in objSet
  200. intCount = intCount + 1
  201. If intCount > 1 Then
  202. Wscript.Echo("BVT FAIL: Too many shadowcopies found")
  203. blnSmokeAssocTraverse = FALSE
  204. End If
  205. If obj.ID = objShadow.ID Then
  206. blnFound = TRUE
  207. End If
  208. Next
  209. if blnFound = FALSE Then
  210. Wscript.Echo("BVT FAIL: No shadowcopy endpoint found traversing Win32_ShadowBy")
  211. blnSmokeAssocTraverse = FALSE
  212. End If
  213. Wscript.Echo("ShadowBy association verified")
  214. ' Check Win32_ShadowFor traversal
  215. blnFound = FALSE
  216. intCount = 0
  217. Set objVol = objWMI.objWMI.Get("Win32_Volume.DeviceID='" & objShadow.VolumeName & "'")
  218. Set objSet = objVol.Associators_("Win32_ShadowFor")
  219. For Each obj in objSet
  220. intCount = intCount + 1
  221. If intCount > 1 Then
  222. Wscript.Echo("BVT FAIL: Too many shadowcopies found")
  223. blnSmokeAssocTraverse = FALSE
  224. End If
  225. If obj.ID = objShadow.ID Then
  226. blnFound = TRUE
  227. End If
  228. Next
  229. if blnFound = FALSE Then
  230. Wscript.Echo("BVT FAIL: No shadowcopy endpoint found traversing Win32_ShadowFor")
  231. blnSmokeAssocTraverse = FALSE
  232. End If
  233. Wscript.Echo("ShadowFor association verified")
  234. ' Check Win32_ShadowVolumeSupport traversal
  235. blnFound = FALSE
  236. intCount = 0
  237. Set objSet = objVolume.Associators_("Win32_ShadowVolumeSupport")
  238. For Each obj in objSet
  239. intCount = intCount + 1
  240. If intCount > 1 Then
  241. Wscript.Echo("BVT FAIL: Too many providers found")
  242. blnSmokeAssocTraverse = FALSE
  243. End If
  244. If obj.ID = objProvider.ID Then
  245. blnFound = TRUE
  246. End If
  247. Next
  248. if blnFound = FALSE Then
  249. Wscript.Echo("BVT FAIL: No provider endpoint found traversing Win32_ShadowVolumeSupport")
  250. blnSmokeAssocTraverse = FALSE
  251. End If
  252. Wscript.Echo("ShadowVolumeSupport association verified")
  253. ' Check Win32_ShadowDiffVolumeSupport traversal
  254. blnFound = FALSE
  255. intCount = 0
  256. Set objSet = objDiffVolume.Associators_("Win32_ShadowDiffVolumeSupport")
  257. For Each obj in objSet
  258. intCount = intCount + 1
  259. If intCount > 1 Then
  260. Wscript.Echo("BVT FAIL: Too many providers found")
  261. blnSmokeAssocTraverse = FALSE
  262. End If
  263. If obj.ID = objProvider.ID Then
  264. blnFound = TRUE
  265. End If
  266. Next
  267. if blnFound = FALSE Then
  268. Wscript.Echo("BVT FAIL: No provider endpoint found traversing Win32_ShadowDiffVolumeSupport")
  269. blnSmokeAssocTraverse = FALSE
  270. End If
  271. Wscript.Echo("ShadowDiffVolumeSupport association verified")
  272. ' Check Win32_ShadowStorage traversal
  273. blnFound = FALSE
  274. intCount = 0
  275. Set objSet = objVolume.Associators_("Win32_ShadowStorage",,"DiffVolume")
  276. For Each obj in objSet
  277. intCount = intCount + 1
  278. If intCount > 1 Then
  279. Wscript.Echo("BVT FAIL: Too many volumes found")
  280. blnSmokeAssocTraverse = FALSE
  281. End If
  282. If obj.DeviceID = objDiffVolume.DeviceID Then
  283. blnFound = TRUE
  284. End If
  285. Next
  286. if blnFound = FALSE Then
  287. Wscript.Echo("BVT FAIL: No volume endpoint found traversing Win32_ShadowStorage")
  288. blnSmokeAssocTraverse = FALSE
  289. End If
  290. Wscript.Echo("ShadowStorage association verified")
  291. If Err.Number <> 0 Then
  292. Wscript.Echo("BVT FAIL: blnSmokeTraverseAssoc: Unexpected Error 0x" & Hex(err.number) & " " & err.description)
  293. blnSmokeAssocTraverse = FALSE
  294. Err.Clear
  295. End If
  296. End Function
  297. '//***************************************************************************
  298. '//
  299. '// Function blnVolumeSelect2
  300. '//
  301. '// Description: Select the first two volumes with >100MB freespace
  302. '//
  303. '// Parameters: [IN] ByRef objWMI The WMI Connection Object
  304. '// [OUT] ByRef objVolume A Volume to shadow
  305. '// [OUT] ByRef objDiffVolume A Volume to store the diff area
  306. '//
  307. '// Output: TRUE if the operation was successful. FALSE if not.
  308. '//
  309. '//*****************************************************************************
  310. Function blnVolumeSelect2(ByRef objWMI, ByRef objVolume, ByRef objDiffVolume)
  311. blnVolumeSelect2 = TRUE
  312. If CONST_DEBUG = FALSE Then
  313. On Error Resume Next
  314. End If
  315. Dim intLoop, intFound
  316. Dim objVolumes, objVol
  317. Dim blnFound
  318. intFound = 0
  319. Set objVolumes = objWMI.objWMI.ExecQuery("select * from Win32_Volume where FreeSpace > 105000000 AND FileSystem='NTFS'")
  320. blnFound = FALSE
  321. For Each objVol in objVolumes
  322. intFound = intFound + 1
  323. if intFound = 1 Then
  324. Set objDiffVolume = objVol
  325. End If
  326. if intFound = 2 Then
  327. Set objVolume = objVol
  328. blnFound = TRUE
  329. Exit For
  330. End If
  331. Next
  332. If blnFound = FALSE Then
  333. Wscript.Echo("BVT FAIL: blnVolumeSelect2: Failed to find two volumes with >100MB free space")
  334. blnVolumeSelect2 = FALSE
  335. End If
  336. If Err.Number <> 0 Then
  337. Wscript.Echo("BVT FAIL: blnVolumeSelect2: Unexpected Error 0x" & Hex(err.number) & " " & err.description)
  338. blnVolumeSelect2 = FALSE
  339. Err.Clear
  340. End If
  341. End Function
  342. '//***************************************************************************
  343. '//
  344. '// Function blnShadowCreate
  345. '//
  346. '// Description: Create a Win32_Shadow instance with default context.
  347. '//
  348. '// Parameters: [IN] ByRef objWMI The WMI Connection Object
  349. '// [IN] ByRef objVolume A Volume to shadow
  350. '// [OUT] ByRef objShadow The created shadow object
  351. '//
  352. '// Output: TRUE if the operation was successful. FALSE if not.
  353. '//
  354. '//*****************************************************************************
  355. Function blnShadowCreate(ByRef objWMI, ByRef objVolume, ByRef objShadow)
  356. blnShadowCreate = TRUE
  357. If CONST_DEBUG = FALSE Then
  358. On Error Resume Next
  359. End If
  360. DIM classShadow
  361. DIM strShadowID
  362. DIM intResult
  363. DIM strMessage
  364. Set classShadow = objWMI.objWMI.Get("Win32_ShadowCopy")
  365. intResult = classShadow.Create(objVolume.DeviceID, , strShadowID)
  366. If intResult <> 0 Then
  367. strMessage = MapErrorCode("Win32_ShadowCopy", "Create", intResult)
  368. Wscript.Echo("BVT FAIL: blnShadowCreate: Create method failed 0x" & Hex(intResult) & " : " & strMessage)
  369. blnShadowCreate = FALSE
  370. End If
  371. Set objShadow = objWMI.objWMI.Get("Win32_ShadowCopy.ID='" & strShadowID & "'")
  372. If Err.Number <> 0 Then
  373. Wscript.Echo("BVT FAIL: blnShadowCreate: Unexpected Error 0x" & Hex(err.number) & " " & err.description)
  374. blnShadowCreate = FALSE
  375. Err.Clear
  376. End If
  377. End Function
  378. '//***************************************************************************
  379. '//
  380. '// Function blnStorageCreate
  381. '//
  382. '// Description: Create a Win32_ShadowStorage object with default MaxSize
  383. '//
  384. '// Parameters: [IN] ByRef objWMI The WMI Connection Object
  385. '// [IN] ByRef objVolume A Volume to shadow
  386. '// [IN] ByRef objDiffVolume A Volume to store the diff area
  387. '//
  388. '// Output: TRUE if the operation was successful. FALSE if not.
  389. '//
  390. '//*****************************************************************************
  391. Function blnStorageCreate(ByRef objWMI, ByRef objVolume, ByRef objDiffVolume)
  392. blnStorageCreate = TRUE
  393. If CONST_DEBUG = FALSE Then
  394. On Error Resume Next
  395. End If
  396. DIM classStorage
  397. DIM intResult
  398. DIM strMessage
  399. Set classStorage = objWMI.objWMI.Get("Win32_ShadowStorage")
  400. intResult = classStorage.Create(objVolume.DeviceID, objDiffVolume.DeviceID)
  401. If intResult <> 0 Then
  402. strMessage = MapErrorCode("Win32_ShadowStorage", "Create", intResult)
  403. Wscript.Echo("BVT FAIL: blnStorageCreate: Create method failed 0x" & Hex(intResult) & " : " & strMessage)
  404. blnStorageCreate = FALSE
  405. End If
  406. If Err.Number <> 0 Then
  407. Wscript.Echo("BVT FAIL: blnStorageCreate: Unexpected Error 0x" & Hex(err.number) & " " & err.description)
  408. blnStorageCreate = FALSE
  409. Err.Clear
  410. End If
  411. End Function
  412. '//***************************************************************************
  413. '//
  414. '// Function blnStorageChangeSize
  415. '//
  416. '// Description: Change the size of a Win32_ShadowStorage
  417. '//
  418. '// Parameters: [IN] ByRef objVolume a volume
  419. '// [IN] ByRef objDiffVolume a diff area volume
  420. '// [IN] ByVal intMaxSpace the new size
  421. '//
  422. '// Output: TRUE if the operation was successful. FALSE if not.
  423. '//
  424. '//*****************************************************************************
  425. Function blnStorageChangeSize(ByRef objVolume, ByRef objDiffVolume)
  426. blnStorageChangeSize = TRUE
  427. If CONST_DEBUG = FALSE Then
  428. On Error Resume Next
  429. End If
  430. DIM objStorageSet, objStorage
  431. DIM intResult
  432. Set objStorageSet = objVolume.References_("Win32_ShadowStorage", "Volume")
  433. For Each objStorage in objStorageSet
  434. objStorage.MaxSpace = Int(objDiffVolume.Capacity / 2)
  435. objStorage.Put_
  436. Exit For
  437. Next
  438. If Err.Number <> 0 Then
  439. Wscript.Echo("BVT FAIL: blnStorageChangeSize: Unexpected Error 0x" & Hex(err.number) & " " & err.description)
  440. blnStorageChangeSize = FALSE
  441. Err.Clear
  442. End If
  443. End Function
  444. '//***************************************************************************
  445. '//
  446. '// Function blnStorageDeleteAll
  447. '//
  448. '// Description: Deletes all Win32_ShadowStorage instances
  449. '//
  450. '// Parameters: [IN] ByRef objWMI The WMI Connection Object
  451. '//
  452. '// Output: TRUE if the operation was successful. FALSE if not.
  453. '//
  454. '//*****************************************************************************
  455. Function blnStorageDeleteAll(ByRef objWMI)
  456. blnStorageDeleteAll = TRUE
  457. If CONST_DEBUG = FALSE Then
  458. On Error Resume Next
  459. End If
  460. Dim objStorageSet, objStorage
  461. Set objStorageSet = objWMI.objWMI.InstancesOf("Win32_ShadowStorage")
  462. For Each objStorage in objStorageSet
  463. objStorage.Delete_
  464. Next
  465. If Err.Number <> 0 Then
  466. Wscript.Echo("BVT FAIL: blnStorageDeleteAll: Unexpected Error 0x" & Hex(err.number) & " " & err.description)
  467. blnStorageDeleteAll = FALSE
  468. Err.Clear
  469. End If
  470. End Function
  471. '//***************************************************************************
  472. '//
  473. '// Function blnShadowDeleteAll
  474. '//
  475. '// Description: Deletes all Win32_ShadowCopy instances
  476. '//
  477. '// Parameters: [IN] ByRef objWMI The WMI Connection Object
  478. '//
  479. '// Output: TRUE if the operation was successful. FALSE if not.
  480. '//
  481. '//*****************************************************************************
  482. Function blnShadowDeleteAll(ByRef objWMI)
  483. blnShadowDeleteAll = TRUE
  484. If CONST_DEBUG = FALSE Then
  485. On Error Resume Next
  486. End If
  487. Dim objShadows, objShadow
  488. Set objShadows = objWMI.objWMI.InstancesOf("Win32_ShadowCopy")
  489. For Each objShadow in objShadows
  490. objShadow.Delete_
  491. Next
  492. If Err.Number <> 0 Then
  493. Wscript.Echo("BVT FAIL: blnShadowDeleteAll: Unexpected Error 0x" & Hex(err.number) & " " & err.description)
  494. blnShadowDeleteAll = FALSE
  495. Err.Clear
  496. End If
  497. End Function
  498. Class cWMI 'A WMI Connection
  499. Public objWMI
  500. 'Add a controller to the list
  501. Public Function ConnectToNamespace(ByVal strNamespace, ByVal strMachine, ByVal strUsername, ByVal strPassword)
  502. ConnectToNamespace = TRUE
  503. If CONST_DEBUG = FALSE Then
  504. On Error Resume Next
  505. End If
  506. Dim objLocator
  507. Set objLocator = CreateObject("WbemScripting.SWbemLocator")
  508. Set objWMI = objLocator.ConnectServer(strMachine, strNamespace, strUserName, strPassword)
  509. objWMI.Security_.impersonationlevel = 3
  510. If Err.Number <> 0 then
  511. Wscript.echo(Err.number & " " & hex(Err.number))
  512. ConnectToNamespace = FALSE
  513. End If
  514. End Function
  515. End Class
  516. Function MapErrorCode(ByRef strClass, ByRef strMethod, ByRef intCode)
  517. set objClass = GetObject("winmgmts:").Get(strClass, &h20000)
  518. set objMethod = objClass.methods_(strMethod)
  519. values = objMethod.qualifiers_("values")
  520. if ubound(values) < intCode then
  521. wscript.echo " FAILURE - no error message found for " & intCode & " : " & strClass & "." & strMethod
  522. f.writeline ("FAILURE - no error message found for " & intCode & " : " & strClass & "." & strMethod)
  523. MapErrorCode = ""
  524. else
  525. MapErrorCode = values(intCode)
  526. end if
  527. End Function