Lint and test-kitchen fixes

* Adds test kitchen infrastructure
* Fixes lint errors produced from foodcritic
This commit is contained in:
Jay Pipes
2012-11-14 16:19:52 -05:00
parent 8a3fb44a07
commit 46a69a6340
24 changed files with 42 additions and 181 deletions

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
*.swp
cookbooks
test/kitchen/.kitchen

3
Gemfile Normal file
View File

@@ -0,0 +1,3 @@
source :rubygems
gem 'test-kitchen'

View File

@@ -4,6 +4,13 @@ default["enable_monit"] = false # OS provides packages
default["developer_mode"] = false # we want secure passwords by default
########################################################################
# Set to some text value if you want templated config files
# to contain a custom banner at the top of the written file
default["nova"]["custom_template_banner"] = "
# This file autogenerated by Chef
# Do not edit, changes will be overwritten
"
# The name of the Chef role that knows about the message queue server
# that Nova uses
default["nova"]["rabbit_server_chef_role"] = "rabbitmq-server"

View File

@@ -4,6 +4,7 @@ license "Apache 2.0"
description "The OpenStack Compute service Nova."
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "5.0.0"
name "nova"
recipe "api-ec2", ""
recipe "api-metadata", ""

View File

@@ -116,11 +116,12 @@ template "/etc/nova/api-paste.ini" do
group "root"
mode "0644"
variables(
"keystone_api_ipaddress" => identity_endpoint["host"],
"service_port" => identity_endpoint["port"],
"admin_port" => identity_admin_endpoint["port"],
"admin_token" => keystone["admin_token"]
)
"custom_template_banner" => node["nova"]["custom_template_banner"],
"keystone_api_ipaddress" => identity_endpoint["host"],
"service_port" => identity_endpoint["port"],
"admin_port" => identity_admin_endpoint["port"],
"admin_token" => keystone["admin_token"]
)
notifies :restart, resources(:service => "nova-api-os-compute"), :delayed
end

View File

@@ -57,6 +57,7 @@ template "/etc/nova/api-paste.ini" do
group "root"
mode "0644"
variables(
"custom_template_banner" => node["nova"]["custom_template_banner"],
"keystone_api_ipaddress" => identity_endpoint["host"],
"service_port" => identity_endpoint["port"],
"admin_port" => identity_admin_endpoint["port"],

View File

@@ -73,8 +73,9 @@ template "/etc/libvirt/libvirtd.conf" do
group "root"
mode "0644"
variables(
:auth_tcp => node["nova"]["libvirt"]["auth_tcp"]
)
"custom_template_banner" => node["nova"]["custom_template_banner"],
"auth_tcp" => node["nova"]["libvirt"]["auth_tcp"]
)
notifies :restart, resources(:service => "libvirt-bin"), :immediately
end

View File

@@ -81,6 +81,7 @@ template "/etc/nova/nova.conf" do
group "root"
mode "0644"
variables(
"custom_template_banner" => node["nova"]["custom_template_banner"],
"use_syslog" => node["nova"]["syslog"]["use"],
"log_facility" => node["nova"]["syslog"]["facility"],
"sql_connection" => sql_connection,
@@ -133,6 +134,7 @@ template "/root/openrc" do
group "root"
mode "0600"
variables(
"custom_template_banner" => node["nova"]["custom_template_banner"],
"user" => keystone["admin_user"],
"tenant" => keystone["users"][keystone["admin_user"]]["default_tenant"],
"password" => keystone["users"][keystone["admin_user"]]["password"],

View File

@@ -1,32 +0,0 @@
#
# Cookbook Name:: nova
# Recipe:: nova-scheduler-patch
#
# Copyright 2012, Rackspace US, 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
#
# 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.
#
include_recipe "osops-utils"
# lp:bug https://bugs.launchpad.net/nova/+bug/1007573
# affinity filters don't work if scheduler_hints is None
template "/usr/share/pyshared/nova/scheduler/filters/affinity_filter.py" do
source "patches/affinity_filter.py.2012.1+stable~20120612-3ee026e-0ubuntu1.2"
owner "root"
group "root"
mode "0644"
notifies :restart, resources(:service => "nova-scheduler"), :immediately
only_if { ::Chef::Recipe::Patch.check_package_version("nova-scheduler","2012.1+stable~20120612-3ee026e-0ubuntu1.2",node) ||
::Chef::Recipe::Patch.check_package_version("nova-scheduler","2012.1+stable~20120612-3ee026e-0ubuntu1.3",node) }
end

View File

@@ -1,8 +1,4 @@
# This file autogenerated by Chef
# Do not edit, changes will be overwritten
<% if not node["custom_template_banner"].nil? %>
<%= node["custom_template_banner"] %>
<% end %>
<%= @custom_template_banner %>
$DirGroup adm
$DirCreateMode 0755
$FileGroup adm

View File

@@ -1,8 +1,4 @@
# This file autogenerated by Chef
# Do not edit, changes will be overwritten
<% if not node["custom_template_banner"].nil? -%>
<%= node["custom_template_banner"] %>
<% end -%>
<%= @custom_template_banner %>
############
# Metadata #
############

View File

@@ -1,8 +1,4 @@
# This file autogenerated by Chef
# Do not edit, changes will be overwritten
<% if not node["custom_template_banner"].nil? %>
<%= node["custom_template_banner"] %>
<% end %>
<%= @custom_template_banner %>
LoadPlugin "<%= @name %>"
<Plugin "<%= @name %>">

View File

@@ -1,8 +1,4 @@
# This file autogenerated by Chef
# Do not edit, changes will be overwritten
<% if not node["custom_template_banner"].nil? %>
<%= node["custom_template_banner"] %>
<% end %>
<%= @custom_template_banner %>
LoadPlugin "<%= @name %>"
<% if not @options.empty? %>

View File

@@ -1,8 +1,4 @@
# This file autogenerated by Chef
# Do not edit, changes will be overwritten
<% if not node["custom_template_banner"].nil? %>
<%= node["custom_template_banner"] %>
<% end %>
<%= @custom_template_banner %>
# Defaults for libvirt-bin initscript (/etc/init.d/libvirt-bin)
# This is a POSIX shell fragment

View File

@@ -1,3 +1,4 @@
<%= @custom_template_banner %>
Host *
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null

View File

@@ -1,7 +1,2 @@
# This file autogenerated by Chef
# Do not edit, changes will be overwritten
<% if not node["custom_template_banner"].nil? %>
<%= node["custom_template_banner"] %>
<% end %>
<%= @custom_template_banner %>
<%= @private_key %>

View File

@@ -1,7 +1,2 @@
# This file autogenerated by Chef
# Do not edit, changes will be overwritten
<% if not node["custom_template_banner"].nil? %>
<%= node["custom_template_banner"] %>
<% end %>
<%= @custom_template_banner %>
<%= @public_key %>

View File

@@ -1,8 +1,4 @@
# This file autogenerated by Chef
# Do not edit, changes will be overwritten
<% if not node["custom_template_banner"].nil? %>
<%= node["custom_template_banner"] %>
<% end %>
<%= @custom_template_banner %>
# Master libvirt daemon configuration file
#
@@ -149,7 +145,7 @@ auth_unix_rw = "none"
# Don't do this outside of a dev/test scenario. For real world
# use, always enable SASL and use the GSSAPI or DIGEST-MD5
# mechanism in /etc/sasl2/libvirt.conf
auth_tcp = "<%= node["nova"]["libvirt"]["auth_tcp"] %>"
auth_tcp = "<%= @auth_tcp %>"
# Change the authentication scheme for TLS sockets.
#

View File

@@ -1,3 +1,4 @@
<%= @custom_template_banner %>
# Override the default config file
# NOTE: This setting is no longer honoured if using
# systemd. Set '--config /etc/libvirt/libvirtd.conf'

View File

@@ -1,8 +1,4 @@
# This file autogenerated by Chef
# Do not edit, changes will be overwritten
<% if not node["custom_template_banner"].nil? %>
<%= node["custom_template_banner"] %>
<% end %>
<%= @custom_template_banner %>
import os

View File

@@ -1,8 +1,4 @@
# This file autogenerated by Chef
# Do not edit, changes will be overwritten
<% if not node["custom_template_banner"].nil? %>
<%= node["custom_template_banner"] %>
<% end %>
<%= @custom_template_banner %>
[DEFAULT]
# LOGS/STATE

View File

@@ -1,8 +1,4 @@
# This file autogenerated by Chef
# Do not edit, changes will be overwritten
<% if not node["custom_template_banner"].nil? %>
<%= node["custom_template_banner"] %>
<% end %>
<%= @custom_template_banner %>
# COMMON OPENSTACK ENVS
export OS_USERNAME=<%= @user %>

View File

@@ -1,84 +0,0 @@
# Copyright 2012, Piston Cloud Computing, Inc.
# Copyright 2012, OpenStack LLC.
# All Rights Reserved.
#
# 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.
import netaddr
from nova.compute import api as compute
from nova import flags
from nova.scheduler import filters
class AffinityFilter(filters.BaseHostFilter):
def __init__(self):
self.compute_api = compute.API()
def _all_hosts(self, context):
all_hosts = {}
for instance in self.compute_api.get_all(context):
all_hosts[instance['uuid']] = instance['host']
return all_hosts
class DifferentHostFilter(AffinityFilter):
'''Schedule the instance on a different host from a set of instances.'''
def host_passes(self, host_state, filter_properties):
context = filter_properties['context']
scheduler_hints = filter_properties.get('scheduler_hints') or {}
me = host_state.host
all_hosts = self._all_hosts(context)
affinity_uuids = scheduler_hints.get('different_host', [])
if affinity_uuids:
return not any([i for i in affinity_uuids
if all_hosts.get(i) == me])
# With no different_host key
return True
class SameHostFilter(AffinityFilter):
'''Schedule the instance on the same host as another instance in a set of
of instances.
'''
def host_passes(self, host_state, filter_properties):
context = filter_properties['context']
scheduler_hints = filter_properties.get('scheduler_hints') or {}
me = host_state.host
all_hosts = self._all_hosts(context)
affinity_uuids = scheduler_hints.get('same_host', [])
if affinity_uuids:
return any([i for i in affinity_uuids
if all_hosts.get(i) == me])
# With no same_host key
return True
class SimpleCIDRAffinityFilter(AffinityFilter):
def host_passes(self, host_state, filter_properties):
scheduler_hints = filter_properties.get('scheduler_hints') or {}
affinity_cidr = scheduler_hints.get('cidr', '/24')
affinity_host_addr = scheduler_hints.get('build_near_host_ip')
if affinity_host_addr:
affinity_net = netaddr.IPNetwork(str.join('', (affinity_host_addr,
affinity_cidr)))
return netaddr.IPAddress(flags.FLAGS.my_ip) in affinity_net
# We don't have an affinity host address.
return True

4
test/kitchen/Kitchenfile Normal file
View File

@@ -0,0 +1,4 @@
cookbook "cookbook-nova" do
lint(:ignore => ["FC024"])
runtimes []
end