Using hiera_hash for augeas changes in hiera puppet - puppet

I've created yaml files for each environment type dev, qa, integration. However there are multiple dev environments and i want to override some changes via host specific yaml files.
Hiera
|--host
| |-dev1.internet.com
| |-dev2.intranet.com
|--servertype
| |-dev
| |-qa
dev.yaml
augeas_xml:
- 'set /root/node/servername/#text 'dev'
- 'set /root/node/serverlocation/#text 'London'
- 'set /root/node/ntp/#text '123.123.123.123'
dev1.internet.com.yaml
augeas_xml:
- 'set /root/node/serverlocation/#text 'New York'
- 'set /root/node/ntp/#text '123.123.123.125'
dev2.intranet.com.yaml
augeas_xml:
- 'set /root/node/serverlocation/#text 'Accrington'
I need a way to get the config of dev1.internet.com.yaml to have the following
augeas_xml:
- 'set /root/node/servername/#text 'dev'
- 'set /root/node/serverlocation/#text 'New York'
- 'set /root/node/ntp/#text '123.123.123.125'
hiera_array is not giving me the desired result and hiera_hash is giving me the following error:
Hiera type mismatch for key 'augeas_xml': expected Hash and got Array
The host specific settings are not taking priority over the environment specific settings. The example i gave is for a small set of servers. I'm using puppet to manage hundreds of servers. I could use hiera and create a yaml file for every single host. However, I want to have a default.yaml and be able to override the changes in the host.yaml
---
:hierarchy:
- "host/%{::fqdn}"
- "server_type/%{server_type}"
- default
:backends:
- yaml
:yaml:
:datadir: "/puppet/hieradata/%{::environment}"
:merge_behavior: deeper
The latter is producing
dev1.internet.com.yaml
augeas_xml:
- 'set /root/node/serverlocation/#text 'New York'
- 'set /root/node/ntp/#text '123.123.123.125'
- 'set /root/node/servername/#text 'dev'
- 'set /root/node/serverlocation/#text 'London'
- 'set /root/node/ntp/#text '123.123.123.123'
but I want it to do
dev1.internet.com.yaml
augeas_xml:
- 'set /root/node/servername/#text 'dev'
- 'set /root/node/serverlocation/#text 'London'
- 'set /root/node/ntp/#text '123.123.123.123'
- 'set /root/node/serverlocation/#text 'New York'
- 'set /root/node/ntp/#text '123.123.123.125'

It'd be much simpler to keep the Augeas commands and paths out of your data files and only put the important bits of data - the name, location, and server address - in the data files. The Augeas commands are most definitely implementation-specific, not data.
For example:
dev.yaml
servername: 'dev'
serverlocation: 'London'
ntp: '123.123.123.123'
dev1.internet.com.yaml
serverlocation: 'New York'
ntp: '123.123.123.125'
dev2.intranet.com.yaml
serverlocation: 'Accrington'
Then in your manifest, you have something like this:
$servername = hiera('servername')
$serverlocation = hiera('serverlocation')
$ntp = hiera('ntp')
augeas { 'node':
context => '/files/root/node',
changes => [
"set servername/#text '$servername'",
"set serverlocation/#text '$serverlocation'",
"set ntp/#text '$ntp'",
],
}
(note the other Augeas resource properties are missing and should be replaced by your own)

Related

Executing the test cases in alm from Excel by Test ID

I am trying to execute the test cases in QC ALM through an Excel macro. I am able to access the tests in testlist, but I am not able to find the particular test case I need to execute by its ID.
Below is the sample code I am using:
Set tsTreeMgr = tdConnection.testsettreemanager
Set tsFolder = tsTreeMgr.NodeByPath(nPath)
' --Search for the test set passed as an argument to the example code
Set tsList = tsFolder.FindTestSets("Test Set Name")
'------Accessing the Test Cases inside the Test SEt ----
Set theTestSet = tsList.Item(1)
For Each testsetfound In tsList
Set tsFolder = testsetfound.TestSetFolder
Set tsTestFactory = testsetfound.tsTestFactory
Set tsTestList = tsTestFactory.NewList("")
For Each tsTest In tsTestList
MsgBox (tsTest.Name+","+ tsTest.ID)
testrunname = "Test Case name from excel sheet"
'----Accesssing the Run Factory ---
Set RunFactory = tsTest.RunFactory
Set obj_theRun = RunFactory.AddItem(CStr(testrunname))
obj_theRun.Status = "Passed"
obj_theRun.Post
Next
Next
Any help to get TestCase in testset of testlab to execute would be great help.
I think you are looking for the TestId property of the TSTest object. So in your loop you could just test whether TestId matches the value from Excel:
If tsTest.TestId = testidfromexcel Then
' do something
End If
Or you can use a Filter to only get the TSTest instances from your Test Set that matches the respective test ID from Excel:
Set testSetFilter = tsTestFactory.Filter
testSetFilter.Filter("TC_TEST_ID") = testidfromexcel
Set tsTestList = testSetFilter.NewList()
Now your tsTestList should only contain test instances from the test with the ID from Excel.

HP ALM - download a resource under a specific folder in the Test Resource module

We are using ALM 12. We have multiple folders in our Test Resources module, and some of the resources stored in these folders have the same name as in other folders. I am able to download a resource using the name, but can't figure out how to get a resource under a specific folder. Anyone know how to download a resource specifying the folder to download it from?
e.g
Folder1
mysheet.xls
Folder2
mysheet.xls
I want to download Folder2\mysheet.xls and not Folder1\mysheet.xls
You could download the resource by resource id rather than resource name.
Below is VBS sample (with OTA API) for your reference:
Option Explicit
Dim tdc, cust, resource
set tdc = CreateObject("TDApiOle80.TDConnection")
tdc.InitConnectionEx "http://YourALMServer:Port/qcbin"
tdc.Login "username", "password"
tdc.Connect "domainName", "projectName"
# 1001 is the resource id which you want to download.
set resource = tdc.QCResourceFactory.Item("1001")
# "C:\\tmp\\" is the local path where you want to place the downloaded resource
resource.DownloadResource "C:\\tmp\\", TRUE
tdc.Disconnect
tdc.Logout
tdc.ReleaseConnection
Option Explicit
Dim objCon, cust, resource
set objCon= CreateObject("TDApiOle80.TDConnection")
objCon.InitConnectionEx "http://YourALMServer:Port/qcbin"
objCon.Login "username", "password"
objCon.Connect "domainName", "projectName"
Set oResourceFolder = objCon.QCResourceFolderFactory
Set oFilter = oResourceFolder.Filter
oFilter.Filter("RFO_NAME") ="abc" \\ abc is your folder name
Set oList = oFilter.NewList()
set oChild = oList.item(1).QCResourceFactory.NewList("")
''assuming that there is only 1 folder with name "abc" in Test Resources section
For i =1 to oChild.count Step 1
oChild.item(i).DownloadResource "c:\\a", TRUE
''c:\\a is the location where we need to safe the resource
next
set objCon = Nothing

registry key value read using VB SCRIPT

I store a website in the registry. For example:
SOFTWARE\Microsoft\Internet Explorer\Default Website
Key name: Website
Key value: www.google.com/
Then I try to create search plugin in IE.
Below is the code I use for that. It works for Google when I hard-code it,
but i want to use the registry value to set this variable.
<html>
<script language="VBSCRIPT">
set parentwin = external.menuArguments
str = trim(parentwin.document.selection.createRange().text)
bnewwindow = parentwin.event.shiftKey
defaultWebsite = ????????
url = defaultWebsite +"search?q=" + escape(str)
if(bnewwindow) then
window.open(url)
else
parentwin.window.navigate(url)
end if
</script>
</html>
You can use the Shell object to read and write registry values. You may get a warning in Internet Explorer when trying to instantiate an ActiveX control, since this requires access to the client PC.
' This uses HKCU. Change to HKLM, if you need.
Dim strKey = "HKCU\Software\Microsoft\Internet Explorer\Default Website\Website"
With CreateObject("WScript.Shell")
defaultWebsite = .RegRead(strKey)
End With

Typoscript output not utf8?

the config:
page.config {
additionalHeaders = Content-Type:text/html;charset=utf-8
metaCharset = utf-8
renderCharset = utf-8
}
and this here:
page.10.marks {
FOO = TEXT
FOO.value = ÜüÖöÄäß
}
the output is the "riddle" sign. also in the source code. There are more markers i need to fill with special characters for other languages later. whats the problem?
Set in the localconf.php:
$TYPO3_CONF_VARS['SYS']['setDBinit'] = 'SET NAMES utf8;'.chr(10).'SET SESSION character_set_server=utf8;';
$TYPO3_CONF_VARS['BE']['forceCharset'] = 'utf8';
However, this (probably) requires that collation of the database tables is set to UTF8, e.g. utf8_general_ci. If you are starting a project, set the collation. If it's a running website, convert the data before you do the settings in the localconf.php.
WARNING: If it's a running website, test it first on a copy.
In the Installtool you need to enable forceCharset=utf8 and in the localconf.php`$TYPO3_CONF_VARS['SYS'][' setDBinit'] = 'set names utf8' and ini_set('default_charset = utf-8'). Source: http://wiki.typo3.org/UTF-8_support.

save and close visio documents visual basic macro

I want to create a visio page, add some shapes, store it with a given filename and close it.
Currently, always the object/template toolbar is active and thus stored under the given filename.
What is the best way to store the current drawing?
thanks
Dim visioApp, visioPage as Object
Set visioApp = CreateObject("visio.application")
visioApp.Documents.AddEx ("")
Set visioPage = visioApp.ActiveWindow.Page
Set visioStencil = visioApp.Documents.Add("BASFLO_M.VSS")
' add shapes
visioApp.ActiveDocument.SaveAs ("c:\.......vsd")
visioApp.ActiveDocument.Close
As you point out, when you open the stencil the active document changes. You can change it back to the document you are editing like this:
Set visioApp = CreateObject("visio.application")
visioApp.Documents.AddEx ("")
Set visioPage = visioApp.ActiveWindow.Page
' Remember which window is active '
Set visioWindow = visioApp.ActiveWindow
Set visioStencil = visioApp.Documents.Add("BASFLO_M.VSS")
' Reactivate the drawing window '
visioWindow.Activate
visioPage.Drop visioStencil.Masters(1), 4, 4
visioApp.ActiveDocument.SaveAs "c:\temp\mydoc.vsd"
visioApp.ActiveDocument.Close
You could also use a reference to the document object you created and not rely on the active document:
Set visioApp = CreateObject("visio.application")
' Get a reference to the docment you are creating'
Set visioDoc = visioApp.Documents.AddEx("")
Set visioPage = visioApp.ActiveWindow.Page
Set visioStencil = visioApp.Documents.Add("BASFLO_M.VSS")
visioPage.Drop visioStencil.Masters(1), 4, 4
' Use the document object, not the active document '
visioDoc.SaveAs "c:\temp\mydoc1.vsd"
visioDoc.Close
I have one last suggestion. Instead of creating a new document and then a stencil I suggest you create a new document based on the Basic Flowchart template. By doing this you create a document with all the same default settings for grid, fonts, etc as the Basic Flowchart you would create if you selected that template in the user interface. Another benefit of using the template is that the flowchart stencils will be opened in the document's workspace every time the document you create is reopened. Try this:
Set visioApp = CreateObject("visio.application")
' BASFLO_M.VST is the filename of the Basic Flowchart Template (metric) '
Set visioDoc = visioApp.Documents.Add("BASFLO_M.VST")
Set visioPage = visioApp.ActiveWindow.Page
' The stencil will be already open as part of the BASFLO_M.VST workspace '
Set visioStencil = visioApp.Documents("BASFLO_M.VSS")
visioPage.Drop visioStencil.Masters(1), 4, 5
visioPage.Drop visioStencil.Masters(1), 5, 4
visioDoc.SaveAs "c:\temp\mydoc2.vsd"
visioDoc.Close

Resources