Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

Commit

Permalink
Getting the test consul server to work so that consul-template can pu…
Browse files Browse the repository at this point in the history
…ll data from the k-v

references #2 and #3
  • Loading branch information
pvandervelde committed Dec 25, 2017
1 parent 07c15e1 commit b877956
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 19 deletions.
22 changes: 7 additions & 15 deletions tests/integration/packer/packer.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,22 @@
"pause_before" : "30s",
"type": "shell"
},
{
"destination": "/tmp/pester",
"source": "{{ user `dir_temp` }}/tests/integration/pester",
"type": "file"
},
{
"expect_disconnect": false,
"inline": [
"ls /tmp/pester",
"ls /tmp/pester/consul"
"echo '{{user `admin_password`}}' | sudo -S -E mkdir -m 777 /test"
],
"type": "shell"
},
{
"expect_disconnect": false,
"inline": [
"nohub /opt/consul/1.0.1/consul agent -config-file /tmp/pester/consul/server.json &>/dev/null"
],
"type": "shell"
"destination": "/test/pester/",
"source": "{{ user `dir_temp` }}/tests/integration/pester",
"type": "file"
},
{
"expect_disconnect": false,
"inline": [
"(/usr/lib/update-notifier/apt-check --package-names 2>&1) &>> /tmp/updates.txt"
"(/usr/lib/update-notifier/apt-check --package-names 2>&1) &>> /test/updates.txt"
],
"type": "shell"
},
Expand All @@ -94,14 +86,14 @@
{
"expect_disconnect": false,
"inline": [
"echo '{{user `admin_password`}}' | sudo -S -E powershell -Command '. /tmp/pester/consul/Set-ConsulKV.ps1; Set-ConsulKV'"
"echo '{{user `admin_password`}}' | sudo -S -E powershell -Command '. /test/pester/consul/Set-ConsulKV.ps1; Set-ConsulKV'"
],
"type": "shell"
},
{
"expect_disconnect": false,
"inline": [
"echo '{{user `admin_password`}}' | sudo -S -E powershell -Command '$ErrorActionPreference = \"Stop\"; $result = Invoke-Pester -Script /tmp/pester/* -PassThru; exit $result.FailedCount '"
"echo '{{user `admin_password`}}' | sudo -S -E powershell -Command '$ErrorActionPreference = \"Stop\"; $result = Invoke-Pester -Script /test/pester/* -PassThru; exit $result.FailedCount '"
],
"type": "shell"
}
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/pester/System.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ Describe 'On the system' {
)

It 'should have a file with updates' {
'/tmp/updates.txt' | Should Exist
'/test/updates.txt' | Should Exist
}

$fileSize = (Get-Item '/tmp/updates.txt').Length
$fileSize = (Get-Item '/test/updates.txt').Length
if ($fileSize -gt 0)
{
$updates = Get-Content /tmp/updates.txt
Expand Down
35 changes: 34 additions & 1 deletion tests/integration/pester/consul/Set-ConsulKV.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
function Get-IpAddress
{
$output = & /sbin/ifconfig eth0
$line = $output |
Where-Object { $_.Contains('inet addr:') } |
Select-Object -First 1

$line = $line.Trim()
$line = $line.SubString('inet addr:'.Length)
return $line.SubString(0, $line.IndexOf(' '))
}

function Set-ConsulKV
{
Write-Output "Starting consul ..."
$process = Start-Process -FilePath '/opt/consul/1.0.1/consul' -ArgumentList "agent -config-file /test/pester/consul/server.json" -PassThru -RedirectStandardOutput /test/pester/consul/consuloutput.out -RedirectStandardError /test/pester/consul/consulerror.out

Write-Output "Going to sleep for 10 seconds ..."
Start-Sleep -Seconds 10

Write-Output "Setting consul key-values ..."

# Load config/services/consul
& /opt/consul/1.0.1/consul kv put -http-addr=http://127.0.0.1:8550 config/services/consul/datacenter 'test-integration'
& /opt/consul/1.0.1/consul kv put -http-addr=http://127.0.0.1:8550 config/services/consul/domain 'integrationtest'
Expand All @@ -15,7 +35,20 @@ function Set-ConsulKV
& /opt/consul/1.0.1/consul kv put -http-addr=http://127.0.0.1:8550 config/services/metrics/host 'write.metrics'
& /opt/consul/1.0.1/consul kv put -http-addr=http://127.0.0.1:8550 config/services/metrics/port '4242'

Write-Output "Joining the local consul ..."

# connect to the actual local consul instance
& /opt/consul/1.0.1/consul join -http-addr=http://127.0.0.1:8550 http://127.0.0.1:8500
$ipAddress = Get-IpAddress
Write-Output "Joining: $($ipAddress):8351"

Start-Process -FilePath '/opt/consul/1.0.1/consul' -ArgumentList "join $($ipAddress):8351"

Write-Output "Getting members for client"
& /opt/consul/1.0.1/consul members

Write-Output "Getting members for server"
& /opt/consul/1.0.1/consul members -http-addr=http://127.0.0.1:8550

Write-Output "Giving consul-template 30 seconds to process the data ..."
Start-Sleep -Seconds 30
}
6 changes: 5 additions & 1 deletion tests/integration/pester/consul/server.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
"datacenter": "test-integration",
"domain": "integrationtest",

"data_dir": "/tmp/pester/consul/data",
"data_dir": "/test/pester/consul/data",

"log_level": "INFO",

"node_id": "bfd590c8-82fd-4625-ac9a-077d34503ffc",

"node_name": "test-integration_server",

"ports" : {
"dns" : 8650,
"http" : 8550,
Expand Down

0 comments on commit b877956

Please sign in to comment.