Skip to content

Commit

Permalink
Merge pull request #6 from dongyuzheng/master
Browse files Browse the repository at this point in the history
Version 0.4.4 - 2/29/2016
  • Loading branch information
poliva83 committed Feb 29, 2016
2 parents 359a157 + a419a48 commit c6e7a7e
Show file tree
Hide file tree
Showing 52 changed files with 1,015 additions and 630 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/.buildpath
/.project
/pkg/*
/test-results
/nodes
spec/config.rb
Gemfile.lock
*~
8 changes: 4 additions & 4 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ inherit_from: .rubocop_todo.yml

AllCops:
Exclude:
- 'vendor/**/*'
- 'spec/*'
- 'files/default/ha.rb'
- 'chef-provisioning-opennebula.gemspec'

AlignParameters:
Expand All @@ -20,7 +17,7 @@ MethodLength:
Max: 50

CyclomaticComplexity:
Max: 20
Max: 24

PerceivedComplexity:
Max: 20
Expand All @@ -45,6 +42,9 @@ Style/SpecialGlobalVars:
Style/SignalException:
Enabled: false

Style/FileName:
Enabled: false

Style/RescueModifier:
Description: 'Avoid using rescue in its modifier form.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-rescue-modifiers'
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## 0.4.4 (2/29/2016)
- Rewrote RSpec test suite
- Improved chef-run error detection algorithm
- RSpec test results are now organized by datetime and the path of the test recipe
- RSpec now uses `spec/config.rb` rather than environment variables
- Test values, such as disk images, are no longer hardcoded, but are in `config.rb`
- Tests for idempotency are now taken into account
- Expected output for `converge_test_recipe` can now be specified in regex
- Cleanup recipe has been split into multiple deletion tests
- Cleanup is now run before and after the test suite runs
- Fixed a bug introduced in 0.4.3 which failed to create proper VM template if the primitive values were non-string

## 0.4.3 (2/12/2016)
- Fixed get_pool method to process symbols correctly
- Update driver and resources to use new get_pool method
Expand Down
26 changes: 8 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ chef-provisioning-opennebula

This is the implementation of the OpenNebula driver for chef-provisioning. It also comes with additional chef resources to manage OpenNebula:

* Template (one_template)
* Template (one_template)
* Image (one_image)
* VNET (one_vnet)
* Lease (one_vnet_lease)
Expand Down Expand Up @@ -480,17 +480,8 @@ end

## Rspec Integration tests

Run 'bundle exec rspec ./spec/integration/test_all_integration_spec.rb' in your chef-provisioning-opennebula folder

Set the following environment variables according to your needs:

```ruby
ENV['HOME'] - your home directory
ENV['ONE_XMLRPC'] - this is the OpenNebula endpoint url
ENV['ONE_AUTH'] - the path to your one_auth file
ENV['ONE_HTTPBASE'] - the base URL from which files are downloaded eg. chef-client.deb, init.sh, service.gz etc.
ENV['CHEF_REPO_PATH'] - the path to your local chef repo
```
- Create and configure `spec/config.rb` from `spec/config_sample.rb`, be sure to **read the comments**
- Run `bundle exec rspec ./spec/integration/test_all_integration_spec.rb` from your chef-provisioning-opennebula folder

## <a name="development"></a> Development

Expand All @@ -513,12 +504,11 @@ Created by [Bogdan Buczynski](https://github.com/bbuczynski) (<[email protected]>

## <a name="maintainers"></a> Maintainers

Maintained by
* [Andrew J. Brown](https://github.com/andrewjamesbrown) (<[email protected]>)
* [Bogdan Buczynski](https://github.com/bbuczynski) (<[email protected]>)
* [Dongyu 'Gary' Zheng](https://github.com/dongyuzheng) (<[email protected]>)
* [Evgeny Yurchenko](https://github.com/EYurchenko) (<[email protected]>)
* [Phil Oliva](https://github.com/poliva83) (<[email protected]>)
* [Andrew J. Brown](https://github.com/andrewjamesbrown) (<[email protected]>)
* [Bogdan Buczynski](https://github.com/bbuczynski) (<[email protected]>)
* [Dongyu 'Gary' Zheng](https://github.com/dongyuzheng) (<[email protected]>)
* [Evgeny Yurchenko](https://github.com/EYurchenko) (<[email protected]>)
* [Phil Oliva](https://github.com/poliva83) (<[email protected]>)

## <a name="license"></a> License

Expand Down
16 changes: 8 additions & 8 deletions chef-provisioning-opennebula.gemspec
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Copyright 2015, BlackBerry, Inc.
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

$:.unshift(File.dirname(__FILE__) + '/lib')
require 'chef/provisioning/opennebula_driver/version'
Expand Down
22 changes: 19 additions & 3 deletions lib/chef/provider/one_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ def load_current_resource

return unless @current_resource.exists

new_resource_template = @new_resource.template_file.nil? ?
@new_resource.template :
driver.one.template_from_file(@new_resource.template_file)
new_resource_template = if @new_resource.template_file.nil?
convert_types(@new_resource.template)
else
driver.one.template_from_file(@new_resource.template_file)
end

@current_id = template.to_hash['VMTEMPLATE']['ID'].to_i
@current_resource.template(template.to_hash['VMTEMPLATE']['TEMPLATE'])
Expand Down Expand Up @@ -150,6 +152,20 @@ def create_template
end
end

def convert_types(hash)
tpl_str = driver.one.create_template(hash)
t_hash = nil
doc = OpenNebula::CustomObject.new(OpenNebula::CustomObject.build_xml, driver.one.client)
unless OpenNebula.is_error?(doc)
rc = doc.allocate(tpl_str)
fail "Failed to allocate OpenNebula document: #{rc.message}" if OpenNebula.is_error?(rc)
doc.info!
t_hash = doc.to_hash['DOCUMENT']['TEMPLATE']
doc.delete
end
t_hash
end

def get_mode(template)
perms = template.to_hash['VMTEMPLATE']['PERMISSIONS']
mode = 0
Expand Down
15 changes: 11 additions & 4 deletions lib/chef/provisioning/opennebula_driver/one_lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,17 @@ def create_template(t, level = 0)
else
comma = (index < count) && level > 0
level.times { tpl << " " }
# Escape quotation marks to fix MAND-1394:
# template does not support embedded quotation marks
# Escaping of " only happens if " is not already escaped, preceded by \\
tpl << "#{k} = \"#{v.gsub(/(?<!\\)\"/, '\"')}\"" << (comma ? ",\n" : "\n")
if v.is_a?(Integer)
tpl << "#{k} = \"#{v}\""
elsif v.is_a?(String)
# Fix for: template does not support embedded quotation marks
# Escaping of " only happens if " is not already escaped, preceded by \\
tpl << "#{k} = \"#{v.gsub(/(?<!\\)\"/, '\"')}\""
else # any other type
# convert to string and print it
tpl << "#{k} = \"#{v}\""
end
tpl << (comma ? ",\n" : "\n")
index += 1
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/chef/provisioning/opennebula_driver/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module Provisioning
# Extending module.
#
module OpenNebulaDriver
VERSION = '0.4.3'
VERSION = '0.4.4'
end
end
end
60 changes: 60 additions & 0 deletions spec/config_sample.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#######################################################
## This is the config file used for the RSpec tests. ##
## Feel free to modify any variables to your needs. ##
#######################################################

# this is the OpenNebula endpoint url
ONE_XMLRPC = 'http://1.2.3.4:443/api:boggi'

# the path to your local chef repo, an empty folder would work, if the folder does not exist, one will be automatically created
CHEF_REPO_PATH = '/home/gary/test-repo'

# required for recipes/OneDriver/create_one_image_spec.rb
DATASTORE_ID = 103

VM_TEMPLATE = {
# the base URL from which files are downloaded eg. chef-client.deb, init.sh, service.gz etc.
'HTTPBASE' => 'http://my.server.com',
# it is highly recommended to keep resources low for these tests
'MEMORY' => '256',
'CPU' => '1',
'VCPU' => '1',
'OS' => {
'ARCH' => 'x86_64'
},
'DISK' => {
'IMAGE' => 'Ubuntu-14.04.1-pre-prod-201411201',
'IMAGE_UNAME' => 'my_user',
'DRIVER' => 'qcow2'
},
'NIC' => {
'NETWORK' => 'my_network',
'NETWORK_UNAME' => 'my_network_user'
},
'GRAPHICS' => {
'LISTEN' => '0.0.0.0',
'TYPE' => 'vnc'
},
'CONTEXT' => {
'NETWORK' => 'YES',
'HOSTNAME' => '$NAME',
'INSTALL_CHEF_CLIENT_COMMAND' => 'dpkg -E -i /mnt/chef-client.deb',
'SSH_USERNAME' => 'local',
'SSH_PUBLIC_KEY' => File.read("#{ENV['HOME']}/.ssh/id_rsa.pub").strip,
'FILES' => '$HTTPBASE/01_chef $HTTPBASE/../chef-client.deb'
}
}

MACHINE_OPTIONS = {
:ssh_username => 'local',
:ssh_options => {
:keys_only => false,
:forward_agent => true,
:use_agent => true,
:user_known_hosts_file => '/dev/null'
},
:ssh_execute_options => {
:prefix => 'sudo '
},
:cached_installer => true
}
Loading

0 comments on commit c6e7a7e

Please sign in to comment.