-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor and add tests #6
Refactor and add tests #6
Conversation
|
||
class rancher::management { | ||
require ::docker |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure what the thinking is here? Can't we just include?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using require explictly makes sure that the docker class has been applied before all the resources in the class are. Using include does not, details here: https://docs.puppetlabs.com/puppet/latest/reference/lang_classes.html#using-require
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thats super cool, did not know about that, thanks @petems !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant to ask about the explicit top scope i.e. why require ::docker
and not require docker
? I see people doing this and I haven't been able to find out why. I'll go through and do it consistently if we agree this is preferred.
Thanks, @alexharv074 That's a real big improvement. |
matrix: | ||
include: | ||
- rvm: 1.9.3 | ||
env: PUPPET_GEM_VERSION="~> 3.2.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason you're testing 3.2? It's a pretty old, there's not much benefit testing it because it's missing out a lot of essentials such as contain
Generally we test 3.8, 3.8 Future parser, latest 4.0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should speed up the builds as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing, I'll remove that.
@alexharv074 Looks good! Got some questions about some of your changes, but I agree with most of it! 😄 |
Ok, I just had a look into the puppet install helper gem. It's controlled by environment variables by the looks of it. I'll refactor to use the puppet install helper. Glad someone's finally cleared this up for me. :) |
86105d2
to
c3a632f
Compare
@petems I have rebased including most of your suggestions.
describe docker_container('rancher/server') do
it { is_expected.to be_running }
end I believe there's a bug in serverspec and I'm still investigating.
{
"type": "collection",
"resourceType": "apiVersion",
"links": {
"self": "http://0.0.0.0:8080/",
"latest": "http://0.0.0.0:8080/v1"
},
"createTypes": {},
"actions": {},
"data": [
{
"id": "v1",
"type": "apiVersion",
"links": {
"self": "http://0.0.0.0:8080/v1"
},
"actions": {}
}
],
"sortLinks": {},
"pagination": null,
"sort": null,
"filters": {},
"createDefaults": {}
}
|
Ok, to the Serverspec bug. I have confirmed that a new feature is to be released in Docker 1.11 release notes:
The version of Docker that has installed is 1.10.3 and it doesn't have this feature. Meanwhile Serverspec has a method The really weird part is that this was added in Serverspec on Oct 12, 2014. I am tempted to simply not do this test, or use a command instead. Any feedback on this would be welcome, as this doesn't make any sense to me. I feel I must have misread or misunderstood something but can't see where. |
Ok, I have removed the troublesome test, which is really redundant anyway considering the test that follows it. |
@petems @nickschuch AFAICT, the only outstanding issue is Pete's expectation that |
|
||
context 'is expected to be running on the default port' do | ||
before :each do | ||
sleep 5 # Give it time to start. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, due to the nature of how beaker-rspec runs, this won't delay the check. This sleep will just happen when the Ruby spec runs:
centos-72-x64 10:38:25$ /bin/sh -c curl\ 0.0.0.0:8080
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
curl: (56) Recv failure: Connection reset by peer
You have to put a sleep exec into the host itself to work:
describe command('sleep 5 && echo "Give Rancher time to start"') do
its(:exit_status) { should eq 0 }
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about something along these lines:
describe Windows_scheduled_task('puppet upgrade task') do
it { should exist }
end
#This will fail if your laptop (and therefor the Vagrant vm) is not running on AC power
describe package('puppet') do
it {
sleep(240) #Wait for the task to execute
should be_installed.with_version('3.5.1')
}
end
From Liam Bennett's blog here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this still won't work. From my test just now, even with a super long wait, it doesn't work 😢
Oh, I should add that Rancher seems to be working fine when I point a browser at port 8080. |
Yeah it is working, when I test it, it's running. But depending on the speed of your VM it might not be ready at the time of the spec running. For example, see my history of it not running during the test, but OK a few seconds after the acceptance test:
|
I set up the following test to determine whether Liam's code works: describe command('date') do
it {
t = Time.now; puts "Sleeping at #{t}"; sleep 10
o = subject.stdout; puts "subject.stdout is #{o}"
}
end The output:
Accordingly I believe I can write our test as: context 'is expected to be running on the default port' do
describe command('curl 0.0.0.0:8080') do
it {
sleep 5 # Give Rancher time to start.
expect(subject.stdout).to match /self.*0.0.0.0:8080/
}
end
end Is that OK with you? |
Hmm ok. Are you running the acceptance tests locally? It doesn't seem to work when I try. |
I'm running the tests on my laptop. Do you mean you tried that exact same code and got a different result? |
Ah, sorry about that, I misread, I just tried pulling from this PR and re-running it and still got the error. Didnt realise you'd not added in the updated code above yet! 😄 I'm just running it now with the updated code, it looks like it does work from your test, I must've written it wrong in my test or there's something different about my setup that causes the sleep not to work. |
Ok, just ran with Vagrant and still got the failure using the code from above:
|
Perhaps you could add in the time-related puts statements to establish if it's failing because of timing or something else? |
I changed it to the following code: describe command('date') do
it {
t = Time.now; puts "Sleeping at #{t}"; sleep 10
o = subject.stdout; puts "Before subject.stdout is #{o}"
}
end
context 'is expected to be running on the default port' do
describe command('curl 0.0.0.0:8080') do
it {
sleep 30 # Give Rancher time to start.
expect(subject.stdout).to match /self.*0.0.0.0:8080/
}
end
end
describe command('date') do
it {
t = Time.now; puts "Sleeping at #{t}"; sleep 10
o = subject.stdout; puts "After subject.stdout is #{o}"
}
end
context 'is expected to be running on the default port (after the previous sleep)' do
describe command('curl 0.0.0.0:8080') do
it {
sleep 30 # Give Rancher time to start.
expect(subject.stdout).to match /self.*0.0.0.0:8080/
}
end
end And it passed successfully, but I think that's because the sleep happens in a separate rspec subject, and I'm not sure the benefit between doing the sleep within the machine or doing it as a sleep outside in a seperate block. It's your call, I'm cool with either as long as the test passes! 😄 |
@alexharv074 To make things easier, I PR'd to add the ability to run the acceptance tests in Travis automatically (docker in docker in docker... inception) alex-harvey-z3q#1 When that's merged it should make proving the acceptance tests work easier 👍 |
To be honest I'm having trouble getting it to work too but seems like it's another issue. I'm going to play around a bit more tomorrow (2.10am here in Sydney!). It's bugging me because I feel it's ugly to have a dummy test that just adds a sleep. I like rspec, and that kind of issue will cause me to dislike it! :) |
No worries! I don't think it's an issue with rspec tbh, probably with the way beaker-rspec handles the examples. I also forgot to add in the new acceptance spec rake task, so just PR'd a new one: alex-harvey-z3q#2 |
- more recent version of boilerplate. - fixes to get tests to pass.
ef58162
to
08ef1d0
Compare
Ok, I timed it. It took 42 seconds for Rancher to start up. Now that I've set the wait time to 1 minute it seems fine. |
Ok, looks like the outstanding issue is the build's red because our new docker in docker in docker in Travis isn't working. |
it 'is expected to apply with no errors' do | ||
pp = <<-EOS | ||
class { 'rancher::node': | ||
'management' => '10.0.1.1', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These don't need single quotes, that's what's causing the syntax error should be:
class { '::rancher::node':
management => '10.0.1.1',
registration_token => 'DB121CFBA836F9493653:1434085200000:2ZOwUMd6fIzz44efikGhBP1veo',
}
d4afb8e
to
4edef77
Compare
env: PUPPET_GEM_VERSION='~> 4.3.0' STRICT_VARIABLES=yes | ||
- rvm: 2.1.6 | ||
env: PUPPET_GEM_VERSION='~> 4.0' STRICT_VARIABLES=yes | ||
- rvm: 2.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2.1 or 2.1.6?
Now the build is failing with:
Investigating ways to raise the time out. |
tbh, it's possible that you can't run docker in docker in docker inside travis instances... I say, leave the acceptance tests in for people to run manually to confirm things are working, remove them from the travis.yml and get this merged in. We can investigate the feasibility of doing the acceptance tests as part of Travis afterwards 👍 |
I agree. This is WAY more than what we had before, happy to see the acceptance tests get debugged in a seperate PR. |
43ae91d
to
ea1d061
Compare
I also agree, and feel free to merge. |
PR uses #5 by @petems as a starting point.
Fixes tests.
Newer boilerplate.
rancher::node fails compilation if empty input provided.
Updated nodeset for latest PL CentOS 7 box (CentOS 7.2).
Removes Gemfile.lock from git.
Modified .travis.yml.