Skip to content
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

Need an assist on serverspec #31

Open
jaypipes opened this issue Jul 15, 2013 · 4 comments
Open

Need an assist on serverspec #31

jaypipes opened this issue Jul 15, 2013 · 4 comments

Comments

@jaypipes
Copy link
Contributor

Hi Chris,

OK, so I'm very happy with Vagabond so far. It's been immensely useful for me to test a fix for CHEF 2100 (http://tickets.opscode.com/browse/COOK-2100). I have a master and slave recipe in my local cookbook and two nodes in a cluster assigned respectively. Here's my Vagabondfile:

{
    :nodes => {
        :metering_master => {
            :template => "ubuntu_1204",
            :ipaddress => "10.0.3.30",
            :environment => "testing",
            :run_list => [
                "recipe[infra-db::metering-master-db]"
            ]
        },
        :metering_slave => {
            :template => "ubuntu_1204",
            :ipaddress => "10.0.3.31",
            :environment => "testing",
            :run_list => [
                "recipe[infra-db::metering-slave-db]"
            ]
        }
    },
    :clusters => {
        "metering-db" => [ "metering_master", "metering_slave" ]
    },
    :local_chef_server => {
        :zero => false,
        :berkshelf => true,
        :librarian => false,
        :enabled => true,
        :auto_upload => true
    },
    :sudo => true
}

I run bundle exec vagabond cluster metering_db and the cluster nodes come up just fine. All good in the hood.

So, I decided to move on to writing some serverspec tests. I did a bundle exec vagabond spec init, edited the Layout file to look like this:

{
  :defaults => {
    :platform => 'ubuntu_1204',
    :environment => 'testing'
  },
  :definitions => {
    :metering_master => {
        :template => "ubuntu_1204",
        :ipaddress => "10.0.3.30",
        :environment => "testing",
        :run_list => [
            "recipe[infra-db::metering-master-db]"
        ]
    },
    :metering_slave => {
        :template => "ubuntu_1204",
        :ipaddress => "10.0.3.31",
        :environment => "testing",
        :run_list => [
            "recipe[infra-db::metering-slave-db]"
        ]
    }
  },
  :clusters => {
    :metering_db => {
      :nodes => [
        'metering_master',
        'metering_slave'
      ]
    }
  }
}

I then created two identical serverspec tests:

require 'serverspec_helper'

describe 'mysqld' do
  it { should be_enabled }
  it { should be_running }
end

and placed the above into files called spec/metering_master.rb and spec/metering_slave.rb.

After that, I fired off the spec, using:

bundle exec vagabond spec start metering_db

Both the master and slave nodes came up, and at the end of the run, I got:

  -> PROVISIONED
Destroying cluster: metering_db
Vagabond: Destroying node: s-metering_master-0-PDPVBPZvMD
Waiting for graceful shutdown and cleanup...
  -> DESTROYED
Vagabond: Destroying node: s-metering_slave-1-PDPVBPZvMD
Waiting for graceful shutdown and cleanup...
  -> DESTROYED
 --> Cluster metering_db DESTROYED
--> Specs for cluster metering_db: PASSED

Now, my question is... did the tests actually get run? I don't think they actually did :)

Best,
-jay

@chrisroberts
Copy link
Owner

spec/recipes/infra-db/metering-slave/mysqld.rb and spec/recipes/infra-db/metering-master/mysqld.rb

The spec stuff is based off the run list of the node, not the name. This allows for a flow of a "node that has a runlist of x should behave like y". It will map to a directory, and use all files within it, so you can have one, or a bunch to help organize them. There is some support for a custom_specs key within the configurations, but it's not fully fleshed out yet. Feel free to have a look in spec.rb and give it a try if they work :)

@jaypipes
Copy link
Contributor Author

Chris,

I did what you suggested but didn't have much luck... I destroyed the Chef server and all nodes and then ran vagabond spec start metering-db but this time, it didn't really do anything. The Chef server got deployed and then the cluster gets immediately destroyed and the tests fail:

jpipes@uberbox:~/repos/att-cloud/cookbook-infra-db$ bundle exec vagabond spec start metering-db
Vagabond: Creating server
  -> Chef Server container created!
  -> Chef Server CREATED!
  -> Bootstrapping erchef...
Auto uploading all assets to local Chef server...
Local chef server: Uploading roles
  -> UPLOADED ROLES
Local chef server: Uploading data bags
  -> UPLOADED DATA BAGS
Local chef server: Uploading environments
  -> UPLOADED ENVIRONMENTS
Local chef server: Uploading cookbooks
Cookbooks being uploaded via berks
  -> UPLOADED COOKBOOKS
  -> All assets uploaded!
  -> CREATED!
Destroying cluster: metering-db
 --> Cluster metering-db DESTROYED
--> Specs for cluster metering-db: FAILED

Not sure what happened, but all I did was mv the two files as you suggested and re-start the cluster. Passing --debug to the command did not produce any more output:

jpipes@uberbox:~/repos/att-cloud/cookbook-infra-db$ bundle exec vagabond spec start metering-db --debug
[sudo] password for jpipes: 
ERROR: Node already exists and is running: server
Vagabond: Starting node: server
  -> STARTED
Destroying cluster: metering-db
 --> Cluster metering-db DESTROYED
--> Specs for cluster metering-db: FAILED

Any ideas?

Best,
-jay

@jaypipes
Copy link
Contributor Author

Doh, ignore the above :( I was using metering-db and not metering_db. Probably would be good to have a better error message in case of mistyped cluster names! :) I'll work on that and push a patch.

@jaypipes
Copy link
Contributor Author

OK, well the cluster completed again, and I got all tests passed:

10.0.3.31 [2013-07-16T12:30:56+00:00] WARN: Changing master to 10.0.3.30 at log position 190 in log file mysql-bin.000002
10.0.3.31 [2013-07-16T12:30:56+00:00] WARN: Starting slave ubuntu1204-ynDjVVlnvaYn
10.0.3.31 
10.0.3.31     - execute the ruby block start-slave
10.0.3.31 
10.0.3.31 
10.0.3.31 Chef Client finished, 19 resources updated
  -> PROVISIONED
Destroying cluster: metering_db
Vagabond: Destroying node: s-metering_master-0-PDPVBPZvMD
Waiting for graceful shutdown and cleanup...
  -> DESTROYED
Vagabond: Destroying node: s-metering_slave-1-PDPVBPZvMD
Waiting for graceful shutdown and cleanup...
  -> DESTROYED
 --> Cluster metering_db DESTROYED
--> Specs for cluster metering_db: PASSED

It's still not clear however that the tests ran.. any way I can tell ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants