Skip to content

Commit 4521928

Browse files
committed
Removed legacy files, update cloudstack_setup_database to work with Chef14, initial server specs tests
1 parent 43d1e14 commit 4521928

14 files changed

+190
-154
lines changed

.kitchen.yml

Lines changed: 3 additions & 12 deletions
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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
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.
44

5-
Work with Chef 12 only.
65

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

99
## Table of Contents
1010

Thorfile

Lines changed: 0 additions & 12 deletions
This file was deleted.

libraries/database.rb renamed to database.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module Cloudstack
2323
module Database
2424
def init_database
2525
# Create database in MySQL using cloudstack-setup-databases scripts
26-
setup_db_init_cmd = "#{@scriptname} #{@current_resource.user}:#{@current_resource.password}@#{@current_resource.ip} --deploy-as=#{@current_resource.root_user}:#{@current_resource.root_password} -m #{@current_resource.management_server_key} -k #{@current_resource.database_key}"
26+
setup_db_init_cmd = "#{@scriptname} #{new_resource.user}:#{new_resource.password}@#{new_resource.ip} --deploy-as=#{new_resource.root_user}:#{new_resource.root_password} -m #{new_resource.management_server_key} -k #{new_resource.database_key}"
2727
cloudstack_setup_database = Mixlib::ShellOut.new(setup_db_init_cmd)
2828
cloudstack_setup_database.run_command
2929
if cloudstack_setup_database.exitstatus == 0
@@ -32,7 +32,7 @@ def init_database
3232

3333
def init_config_database
3434
# Create database configuration for cloudstack management server that will use and existing database.
35-
setup_db_init_cmd = "#{@scriptname} #{@current_resource.user}:#{@current_resource.password}@#{@current_resource.ip} -m #{@current_resource.management_server_key} -k #{@current_resource.database_key}"
35+
setup_db_init_cmd = "#{@scriptname} #{new_resource.user}:#{new_resource.password}@#{new_resource.ip} -m #{new_resource.management_server_key} -k #{new_resource.database_key}"
3636
cloudstack_setup_database = Mixlib::ShellOut.new(setup_db_init_cmd)
3737
cloudstack_setup_database.run_command
3838
if cloudstack_setup_database.exitstatus == 0

libraries/cloudstack_helper.rb

Lines changed: 24 additions & 7 deletions
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

metadata.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
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

99
source_url 'https://github.com/cloudops/cookbook_cloudstack'
1010
issues_url 'https://github.com/cloudops/cookbook_cloudstack/issues'

providers/setup_management.rb

Lines changed: 0 additions & 57 deletions
This file was deleted.

recipes/circle-ci.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#
2+
# Cookbook Name:: cloudstack
3+
# Recipe:: default
4+
# Author:: Pierre-Luc Dion (<[email protected]>)
5+
# Copyright 2018, CloudOps, Inc.
6+
#
7+
# kitchen test file
8+
9+
include_recipe 'cloudstack::management_server'
10+
include_recipe 'cloudstack::usage'
11+
12+
# install mysql-server
13+
package 'mariadb-server'
14+
15+
execute 'set mysql root password' do
16+
command 'mysqladmin -h 127.0.0.1 -u root password password'
17+
action :nothing
18+
end
19+
20+
if platform?(%w(redhat centos fedora oracle))
21+
service 'mariadb' do
22+
action :start
23+
notifies :run, 'execute[set mysql root password]', :immediately
24+
end
25+
elsif platform?(%w(ubuntu debian))
26+
service 'mysql' do
27+
action :start
28+
notifies :run, 'execute[set mysql root password]', :immediately
29+
end
30+
end
31+
32+
# init database and connection configuration
33+
cloudstack_setup_database '127.0.0.1' do
34+
root_user 'root'
35+
root_password 'password'
36+
user 'cloud'
37+
password 'cloud'
38+
action :create
39+
end
40+
41+
cloudstack_setup_management node.name do
42+
tomcat7 true
43+
end
44+
45+
service 'cloudstack-management' do
46+
action [ :enable, :start ]
47+
end
48+
49+
service 'cloudstack-usage' do
50+
action [ :enable, :start ]
51+
end

recipes/management_server.rb

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -37,43 +37,3 @@
3737

3838
include_recipe 'cloudstack::vhd-util'
3939

40-
#
41-
# Set nproc limits for user cloud
42-
#
43-
template node['cloudstack']['nproc_limit_file'] do
44-
source 'nproc_limits.erb'
45-
owner 'root'
46-
group 'root'
47-
mode 0755
48-
variables user: node['cloudstack']['username'],
49-
hard: node['cloudstack']['nproc_limit_hard'],
50-
soft: node['cloudstack']['nproc_limit_soft'],
51-
recipe_file: __FILE__.to_s.split('cookbooks/').last,
52-
template_file: source.to_s
53-
end
54-
55-
#
56-
# Set nofile limits for user cloud
57-
#
58-
template node['cloudstack']['nofile_limit_file'] do
59-
source 'nofile_limits.erb'
60-
owner 'root'
61-
group 'root'
62-
mode 0755
63-
variables user: node['cloudstack']['username'],
64-
hard: node['cloudstack']['nofile_limit_hard'],
65-
soft: node['cloudstack']['nofile_limit_soft'],
66-
recipe_file: __FILE__.to_s.split('cookbooks/').last,
67-
template_file: source.to_s
68-
end
69-
70-
# Configure sudo for user cloud
71-
include_recipe 'sudo'
72-
sudo 'cloud' do
73-
template 'sudoers_cloudstack.erb'
74-
end
75-
76-
# service 'cloudstack-management' do
77-
# supports :restart => true, :status => true, :start => true, :stop => true
78-
# action :nothing
79-
# end

resources/setup_database.rb

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#
22
# Cookbook Name:: cloudstack
3-
# Resource:: init_db
3+
# Resource:: setup_database
44
# Author:: Pierre-Luc Dion (<[email protected]>)
5-
# Copyright 2015, CloudOps, Inc.
5+
# Copyright 2018, CloudOps, Inc.
66
#
77
# Licensed under the Apache License, Version 2.0 (the "License");
88
# you may not use this file except in compliance with the License.
@@ -16,16 +16,62 @@
1616
# See the License for the specific language governing permissions and
1717
# limitations under the License.
1818

19-
actions :create
19+
# include Chef::Mixin::ShellOut
2020

2121
default_action :create
2222

23-
attribute :ip, name_attribute: true, kind_of: String
24-
attribute :user, kind_of: String, default: 'cloud'
25-
attribute :password, kind_of: String, default: 'password'
26-
attribute :root_user, kind_of: String, default: 'root'
27-
attribute :root_password, kind_of: String, default: 'ilikerandompasswords'
28-
attribute :management_server_key, kind_of: String, default: 'password'
29-
attribute :database_key, kind_of: String, default: 'password'
23+
property :ip, String, name_property: true
24+
property :user, String, default: 'cloud'
25+
property :password, String, default: 'password'
26+
property :root_user, String, default: 'root'
27+
property :root_password, String, default: 'ilikerandompasswords'
28+
property :management_server_key, String, default: 'password'
29+
property :database_key, String, default: 'password'
3030

31-
attr_accessor :exists
31+
action :create do
32+
unless dbconf_exist?
33+
@scriptname = '/usr/bin/cloudstack-setup-databases'
34+
if ::File.exist?(@scriptname) && verify_db_connection?(new_resource.ip, new_resource.root_user, new_resource.root_password)
35+
if db_exist?(new_resource.ip, new_resource.user, new_resource.password)
36+
converge_by('Using existing CloudStack database') do
37+
init_config_database
38+
end
39+
else
40+
converge_by('Creating CloudStack database') do
41+
init_database
42+
end
43+
end
44+
else
45+
Chef::Log.error "#{@scriptname} not found or fail to connect to database."
46+
end
47+
end
48+
end
49+
50+
action_class do
51+
include Cloudstack::Helper
52+
53+
def init_database
54+
# Create database in MySQL using cloudstack-setup-databases scripts
55+
setup_db_init_cmd = "#{@scriptname} #{new_resource.user}:#{new_resource.password}@#{new_resource.ip} --deploy-as=#{new_resource.root_user}:#{new_resource.root_password} -m #{new_resource.management_server_key} -k #{new_resource.database_key}"
56+
shell_out!(setup_db_init_cmd)
57+
end
58+
59+
def init_config_database
60+
# Create database configuration for cloudstack management server that will use and existing database.
61+
setup_db_init_cmd = "#{@scriptname} #{new_resource.user}:#{new_resource.password}@#{new_resource.ip} -m #{new_resource.management_server_key} -k #{new_resource.database_key}"
62+
shell_out!(setup_db_init_cmd)
63+
end
64+
65+
def dbconf_exist?
66+
# test if db.properties as been modified from default installation file. if password encrypted, then we step there to not break anything.
67+
Chef::Log.debug 'Checking to see if database config db.properties as been configured'
68+
conf_exist = Mixlib::ShellOut.new('cat /etc/cloudstack/management/db.properties |grep "ENC("')
69+
conf_exist.run_command
70+
if conf_exist.exitstatus == 0
71+
true
72+
else
73+
Chef::Log.debug 'db.properties does not contain encrypted passwords.'
74+
false
75+
end
76+
end
77+
end

0 commit comments

Comments
 (0)