Skip to content

Commit e446c4f

Browse files
authored
Merge pull request #17 from cloudops/chef14
support Chef14
2 parents 43d1e14 + c6a691b commit e446c4f

15 files changed

+309
-304
lines changed

.circleci/config.yml

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
defaults: &defaults
2+
docker:
3+
- image: chef/chefdk
4+
working_directory: ~/cookbook/cookbook_cloudstack
5+
6+
version: 2
7+
jobs:
8+
checkout:
9+
<<: *defaults
10+
steps:
11+
- checkout
12+
- save_cache:
13+
key: repo-{{ .Environment.CIRCLE_SHA1 }}
14+
paths:
15+
- ~/cookbook/cookbook_cloudstack
16+
17+
cookstyle:
18+
<<: *defaults
19+
steps:
20+
- restore_cache:
21+
key: repo-{{ .Environment.CIRCLE_SHA1 }}
22+
- run: chef --version
23+
- run: chef exec cookstyle .
24+
25+
foodcritic:
26+
<<: *defaults
27+
steps:
28+
- restore_cache:
29+
key: repo-{{ .Environment.CIRCLE_SHA1 }}
30+
- run: chef --version
31+
- run: chef exec foodcritic .
32+
33+
chefspec:
34+
<<: *defaults
35+
steps:
36+
- restore_cache:
37+
key: repo-{{ .Environment.CIRCLE_SHA1 }}
38+
- run: chef --version
39+
- run: chef exec rspec spec
40+
41+
kitchen:
42+
machine:
43+
services:
44+
- docker
45+
working_directory: ~/cookbook/cookbook_cloudstack
46+
steps:
47+
- checkout
48+
- run: |
49+
if ! chef -v; then
50+
wget https://packages.chef.io/files/stable/chefdk/3.5.13/ubuntu/18.04/chefdk_3.5.13-1_amd64.deb
51+
sudo dpkg -i chefdk_3.5.13-1_amd64.deb
52+
fi
53+
- run: chef --version
54+
- run: bundle install
55+
- run: berks install
56+
- run: berks update
57+
- run: KITCHEN_LOCAL_YAML=.kitchen.docker.yml kitchen test --destroy always
58+
59+
workflows:
60+
version: 2
61+
build:
62+
jobs:
63+
- checkout:
64+
filters:
65+
tags:
66+
only: /v.*/
67+
68+
- cookstyle:
69+
requires:
70+
- checkout
71+
filters:
72+
tags:
73+
only: /v.*/
74+
75+
- foodcritic:
76+
requires:
77+
- checkout
78+
filters:
79+
tags:
80+
only: /v.*/
81+
82+
- chefspec:
83+
requires:
84+
- checkout
85+
filters:
86+
tags:
87+
only: /v.*/
88+
89+
- kitchen:
90+
requires:
91+
- checkout
92+
filters:
93+
tags:
94+
only: /v.*/

.kitchen.yml

+3-12
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,11 @@ provisioner:
66
name: chef_solo
77

88
platforms:
9-
- name: ubuntu-14.04
10-
- name: centos-6.6
11-
- name: centos-7.1
9+
# - name: ubuntu-16.04
10+
- name: centos-7
1211

1312
suites:
1413
- name: default
1514
run_list:
16-
- recipe[cloudstack::management_server]
17-
- recipe[cloudstack::usage]
15+
- recipe[cloudstack::circle-ci]
1816
attributes:
19-
- name: acs46
20-
run_list:
21-
- recipe[cloudstack::management_server]
22-
- recipe[cloudstack::usage]
23-
attributes:
24-
cloudstack:
25-
release_major: '4.6'

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ cloudstack CHANGELOG
33

44
This file is used to list changes made in each version of the co-cloudstack cookbook.
55

6+
6.0.0
7+
-----
8+
- pdion891 - Fix Chef14 issues on CentOS 7 for cloudstack_setup_database ressource.
9+
- Added circle-ci recipe for automated CI.
10+
- Remove management of sudoers file, pkgs are taking care of it.
11+
612
5.0.0
713
-----
814
- pdion891 - update default version to 4.11.

README.md

+24-22
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# CloudStack Cookbook
22

3-
Install and configure [Apache Cloudstack](http://cloudstack.apache.org) using [Chef](http://www.chef.io/). A wrapper cookbook is prefered in order to Install Apache CloudStack properly, refer to [cloudstack_wrapper cookbook](https://github.com/cloudops/cookbook_cloudstack_wrapper) for example.
3+
[![Build Status](https://circleci.com/gh/cloudops/cookbook_cloudstack.svg?style=svg)](https://circleci.com/gh/cloudops/cookbook_cloudstack)
4+
[![Cookbook Version](https://img.shields.io/cookbook/v/cloudstack.svg)](https://supermarket.chef.io/cookbooks/cloudstack)
45

5-
Work with Chef 12 only.
6+
Install and configure [Apache Cloudstack](http://cloudstack.apache.org) using [Chef](http://www.chef.io/). A wrapper cookbook is prefered in order to Install Apache CloudStack properly, refer to [cloudstack_wrapper cookbook](https://github.com/cloudops/cookbook_cloudstack_wrapper) for example.
67

7-
Tested on CentOS 7 and Ubuntu 16.04
8+
Tested on CentOS 7
9+
Some parts work with Ubuntu 16.04 but this cookbook does not perform all configuraiton required for CloudStack Management-server on Ubuntu.
810

911
## Table of Contents
1012

@@ -42,7 +44,7 @@ More info on: http://cloudstack.apache.org/
4244
- `yum` - packages management
4345
- `apt` - packages management
4446
- `mysql` - for MySQL database server and client
45-
- `sudo` - to configure sudoers for user "cloud"
47+
- `sudo` - to configure sudoers for user `cloud`
4648

4749
There is a dependency on Ruby gem [cloudstack_ruby_client](https://github.com/chipchilders/cloudstack_ruby_client) for chef which is handle in `recipe[cloudstack::default]`.
4850

@@ -54,18 +56,18 @@ Create MySQL database and connection configuration used by CloudStack management
5456

5557
```ruby
5658
# Using attributes
57-
cloudstack_setup_database node["cloudstack"]["db"]["host"] do
58-
root_user node["cloudstack"]["db"]["rootusername"]
59-
root_password node["cloudstack"]["db"]["rootpassword"]
60-
user node["cloudstack"]["db"]["username"]
61-
password node["cloudstack"]["db"]["password"]
59+
cloudstack_setup_database node['cloudstack']['db']['host'] do
60+
root_user node['cloudstack']['db']['rootusername']
61+
root_password node['cloudstack']['db']['rootpassword']
62+
user node['cloudstack']['db']['username']
63+
password node['cloudstack']['db']['password']
6264
action :create
6365
end
6466
```
6567

6668
```ruby
6769
# using mysql cookbook and CloudStack default passwords
68-
cloudstack_setup_database node["cloudstack"]["db"]["host"] do
70+
cloudstack_setup_database node['cloudstack']['db']['host'] do
6971
action :create
7072
end
7173
```
@@ -78,11 +80,11 @@ Download initial SystemVM template prior to initialize a CloudStack Region. clou
7880
# Using attributes
7981
cloudstack_system_template 'xenserver' do
8082
url node['cloudstack']['systemvm']['xenserver']
81-
nfs_path node["cloudstack"]["secondary"]["path"]
82-
nfs_server node["cloudstack"]["secondary"]["host"]
83-
db_user node["cloudstack"]["db"]["username"]
84-
db_password node["cloudstack"]["db"]["password"]
85-
db_host node["cloudstack"]["db"]["host"]
83+
nfs_path node['cloudstack']['secondary']['path']
84+
nfs_server node['cloudstack']['secondary']['host']
85+
db_user node['cloudstack']['db']['username']
86+
db_password node['cloudstack']['db']['password']
87+
db_host node['cloudstack']['db']['host']
8688
end
8789
```
8890

@@ -118,19 +120,19 @@ Generate api keys for account. Currently working only for admin account.
118120

119121
Will update attributes:
120122

121-
- `node["cloudstack"]["admin"]["api_key"]`
122-
- `node["cloudstack"]["admin"]["secret_key"]`
123+
- `node['cloudstack']['admin']['api_key']`
124+
- `node['cloudstack']['admin']['secret_key']`
123125

124126
``` ruby
125127
# Create API key if now exist in Cloudstack and update node attributes
126-
cloudstack_api_keys "admin" do
128+
cloudstack_api_keys 'admin' do
127129
action :create
128130
end
129131
```
130132

131133
``` ruby
132134
# Generate new API Keys
133-
cloudstack_api_keys "admin" do
135+
cloudstack_api_keys 'admin' do
134136
action :reset
135137
end
136138
```
@@ -140,9 +142,9 @@ end
140142
Update Global Settings values.
141143

142144
``` ruby
143-
cloudstack_global_setting "expunge.delay" do
144-
value "80"
145-
notifies :restart, "service[cloudstack-management]", :delayed
145+
cloudstack_global_setting 'expunge.delay' do
146+
value '80'
147+
notifies :restart, 'service[cloudstack-management]', :delayed
146148
end
147149
```
148150

Thorfile

-12
This file was deleted.

libraries/cloudstack_helper.rb

+24-7
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,32 @@ def port_open(ip, port, seconds = 1)
4141
false
4242
end
4343

44-
# Test if CloudStack Database already exist
44+
def verify_db_connection?(db_host = 'localhost', db_user = 'root', db_password = 'password')
45+
# Make sure we can connect to db server
46+
conn_db_test = "mysql -h #{db_host} -u #{db_user} -p#{db_password} -e 'show databases;'"
47+
begin
48+
if shell_out!(conn_db_test).error?
49+
false
50+
else
51+
true
52+
end
53+
rescue
54+
false
55+
end
56+
end
57+
4558
def db_exist?(db_host = 'localhost', db_user = 'cloud', db_password = 'password')
59+
# Test if CloudStack Database already exist
60+
# if fail to connect with db_user, return false;
4661
conn_db_test = "mysql -h #{db_host} -u #{db_user} -p#{db_password} -e 'show databases;'|grep cloud"
47-
conn_db_test_out = Mixlib::ShellOut.new(conn_db_test)
48-
conn_db_test_out.run_command
49-
if conn_db_test_out.exitstatus == 0
50-
return true
51-
else
52-
return false
62+
begin
63+
if shell_out!(conn_db_test).error?
64+
false
65+
else
66+
true
67+
end
68+
rescue
69+
false
5370
end
5471
end
5572

libraries/database.rb

-55
This file was deleted.

metadata.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
license 'Apache-2.0'
55
description 'Installs/Configures cloudstack'
66
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
7-
version '5.0.0'
7+
version '6.0.0'
88

9-
source_url 'https://github.com/cloudops/cookbook_cloudstack'
10-
issues_url 'https://github.com/cloudops/cookbook_cloudstack/issues'
9+
source_url 'https://github.com/cloudops/cookbook_cloudstack'
10+
issues_url 'https://github.com/cloudops/cookbook_cloudstack/issues'
1111

12-
depends 'yum', '> 3.0'
13-
depends 'apt', '> 2.0'
12+
depends 'yum' , '> 3.0'
13+
depends 'apt' , '> 2.0'
1414
depends 'mysql', '~> 8.0'
15-
depends 'sudo', '>= 2.6.0'
15+
depends 'sudo' , '>= 2.6.0'
1616

1717
supports 'centos'
1818
supports 'redhat'

0 commit comments

Comments
 (0)