repo_name
stringlengths
6
97
path
stringlengths
3
341
text
stringlengths
8
1.02M
javier-delgado/URF-picker
app/models/search_option.rb
# == Schema Information # # Table name: search_options # # id :integer not null, primary key # name :string # associated_stat :string # created_at :datetime not null # updated_at :datetime not null # ordering :string # explanation :text # class SearchOption < ActiveRecord::Base validates_uniqueness_of :name def order_query associated_stat + " " + ordering end def explanation_for(champ_name) explanation.sub("{champ_name}", champ_name) end def self.for_select all.shuffle.map { |x| x.name } end end
javier-delgado/URF-picker
lib/tasks/collect_data.rake
namespace :api do task :collect_urf_data => :environment do Collector.new.collect! end end
javier-delgado/URF-picker
db/migrate/20150405223419_add_ordering_to_search_option.rb
class AddOrderingToSearchOption < ActiveRecord::Migration def change add_column :search_options, :ordering, :string end end
javier-delgado/URF-picker
app/controllers/search_controller.rb
<gh_stars>0 class SearchController < ApplicationController def search_champion @option = SearchOption.find_by(name: params[:search_option]) redirect_to root_path if @option.nil? @region = Region.find_by(key: params[:region]) if @option.ordering == 'champion' @result = HighestStat.by_region(@region) .by_champ_name(@option.associated_stat).first else @result = HighestStat.by_region(@region) .order(@option.order_query).first end render :results end end
javier-delgado/URF-picker
db/migrate/20150331182958_create_highest_stats.rb
<filename>db/migrate/20150331182958_create_highest_stats.rb class CreateHighestStats < ActiveRecord::Migration def change create_table :highest_stats do |t| t.references :champion, index: true t.integer :assists, limit: 8 t.integer :champ_level, limit: 8 t.integer :deaths, limit: 8 t.integer :double_kills, limit: 8 t.integer :gold_earned, limit: 8 t.integer :item0, limit: 8 t.integer :item1, limit: 8 t.integer :item2, limit: 8 t.integer :item3, limit: 8 t.integer :item4, limit: 8 t.integer :item5, limit: 8 t.integer :item6, limit: 8 t.integer :item7, limit: 8 t.integer :kills, limit: 8 t.integer :magic_damage_dealt_to_champions, limit: 8 t.integer :magic_damage_taken, limit: 8 t.integer :minions_killed, limit: 8 t.integer :neutral_minions_killed, limit: 8 t.integer :penta_kills, limit: 8 t.integer :physical_damage_dealt_to_champions, limit: 8 t.integer :physical_damage_taken, limit: 8 t.integer :quadra_kills, limit: 8 t.integer :total_damage_dealt_to_champions, limit: 8 t.integer :total_damage_taken, limit: 8 t.integer :total_heal, limit: 8 t.integer :total_time_crowd_control_dealt, limit: 8 t.integer :tower_kills, limit: 8 t.integer :triple_kills, limit: 8 t.integer :true_damage_dealt_to_champions, limit: 8 t.integer :unreal_kills, limit: 8 t.integer :wards_placed, limit: 8 t.integer :wins t.integer :loses end add_foreign_key :highest_stats, :champions end end
javier-delgado/URF-picker
db/schema.rb
<filename>db/schema.rb<gh_stars>0 # encoding: UTF-8 # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # # Note that this schema.rb definition is the authoritative source for your # database schema. If you need to create the application database on another # system, you should be using db:schema:load, not running all the migrations # from scratch. The latter is a flawed and unsustainable approach (the more migrations # you'll amass, the slower it'll run and the greater likelihood for issues). # # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema.define(version: 20150405231715) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" create_table "banned_champions", force: :cascade do |t| t.integer "team_id" t.integer "champion_id" t.integer "champion_key" t.datetime "created_at", null: false t.datetime "updated_at", null: false end add_index "banned_champions", ["champion_id"], name: "index_banned_champions_on_champion_id", using: :btree add_index "banned_champions", ["team_id"], name: "index_banned_champions_on_team_id", using: :btree create_table "champions", force: :cascade do |t| t.integer "champion_key" t.string "name" t.string "title" t.string "image" t.string "sprite" t.datetime "created_at", null: false t.datetime "updated_at", null: false end create_table "champions_participants", id: false, force: :cascade do |t| t.integer "champion_id" t.integer "participant_id" end add_index "champions_participants", ["champion_id", "participant_id"], name: "index_champions_participants_on_champion_id_and_participant_id", using: :btree add_index "champions_participants", ["participant_id"], name: "index_champions_participants_on_participant_id", using: :btree create_table "highest_stats", force: :cascade do |t| t.integer "champion_id" t.float "assists" t.float "champ_level" t.float "deaths" t.float "double_kills" t.integer "gold_earned", limit: 8 t.float "kills" t.integer "magic_damage_dealt_to_champions", limit: 8 t.integer "magic_damage_taken", limit: 8 t.float "minions_killed" t.float "neutral_minions_killed" t.float "penta_kills" t.integer "physical_damage_dealt_to_champions", limit: 8 t.integer "physical_damage_taken", limit: 8 t.float "quadra_kills" t.integer "total_damage_dealt_to_champions", limit: 8 t.integer "total_damage_taken", limit: 8 t.integer "total_heal", limit: 8 t.integer "total_time_crowd_control_dealt", limit: 8 t.float "tower_kills" t.float "triple_kills" t.integer "true_damage_dealt_to_champions", limit: 8 t.float "unreal_kills" t.float "wards_placed" t.float "wins" t.float "loses" t.integer "region_id" t.integer "count" end add_index "highest_stats", ["champion_id"], name: "index_highest_stats_on_champion_id", using: :btree create_table "match_details", force: :cascade do |t| t.datetime "match_creation" t.integer "match_duration", limit: 8 t.string "region_key" t.datetime "created_at", null: false t.datetime "updated_at", null: false end create_table "participant_stats", force: :cascade do |t| t.integer "participant_id" t.integer "assists", limit: 8 t.integer "champ_level", limit: 8 t.integer "deaths", limit: 8 t.integer "double_kills", limit: 8 t.integer "gold_earned", limit: 8 t.integer "item0", limit: 8 t.integer "item1", limit: 8 t.integer "item2", limit: 8 t.integer "item3", limit: 8 t.integer "item4", limit: 8 t.integer "item5", limit: 8 t.integer "item6", limit: 8 t.integer "item7", limit: 8 t.integer "kills", limit: 8 t.integer "magic_damage_dealt_to_champions", limit: 8 t.integer "magic_damage_taken", limit: 8 t.integer "minions_killed", limit: 8 t.integer "neutral_minions_killed", limit: 8 t.integer "penta_kills", limit: 8 t.integer "physical_damage_dealt_to_champions", limit: 8 t.integer "physical_damage_taken", limit: 8 t.integer "quadra_kills", limit: 8 t.integer "total_damage_dealt_to_champions", limit: 8 t.integer "total_damage_taken", limit: 8 t.integer "total_heal", limit: 8 t.integer "total_time_crowd_control_dealt", limit: 8 t.integer "tower_kills", limit: 8 t.integer "triple_kills", limit: 8 t.integer "true_damage_dealt_to_champions", limit: 8 t.integer "unreal_kills", limit: 8 t.integer "wards_placed", limit: 8 t.boolean "winner" t.datetime "created_at", null: false t.datetime "updated_at", null: false end add_index "participant_stats", ["participant_id"], name: "index_participant_stats_on_participant_id", using: :btree create_table "participants", force: :cascade do |t| t.integer "match_detail_id" t.integer "team_id" t.integer "champion_key" t.integer "team_key" t.string "highest_achieved_season_tier" t.integer "participant_key" t.integer "spell1Id" t.integer "spell2Id" t.datetime "created_at", null: false t.datetime "updated_at", null: false end add_index "participants", ["match_detail_id"], name: "index_participants_on_match_detail_id", using: :btree add_index "participants", ["team_id"], name: "index_participants_on_team_id", using: :btree create_table "regions", force: :cascade do |t| t.string "key" t.string "name" t.datetime "created_at", null: false t.datetime "updated_at", null: false end create_table "search_options", force: :cascade do |t| t.string "name" t.string "associated_stat" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "ordering" t.text "explanation" end create_table "teams", force: :cascade do |t| t.integer "team_key" t.integer "baron_kills" t.integer "dragon_kills" t.boolean "firs_baron" t.boolean "first_dragon" t.boolean "first_blood" t.boolean "first_inhibitor" t.boolean "first_tower" t.integer "tower_kills" t.boolean "winner" t.integer "match_detail_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false end add_index "teams", ["match_detail_id"], name: "index_teams_on_match_detail_id", using: :btree add_foreign_key "banned_champions", "champions" add_foreign_key "banned_champions", "teams" add_foreign_key "highest_stats", "champions" add_foreign_key "participant_stats", "participants" add_foreign_key "participants", "match_details" add_foreign_key "participants", "teams" add_foreign_key "teams", "match_details" end
javier-delgado/URF-picker
db/migrate/20150331011821_create_match_details.rb
<reponame>javier-delgado/URF-picker class CreateMatchDetails < ActiveRecord::Migration def change create_table :match_details do |t| t.datetime :match_creation t.integer :match_duration, limit: 8 t.string :region t.timestamps null: false end end end
javier-delgado/URF-picker
db/migrate/20150402211744_add_region_to_highest_stat.rb
class AddRegionToHighestStat < ActiveRecord::Migration def change add_column :highest_stats, :region_id, :integer end end
javier-delgado/URF-picker
app/models/champion.rb
# == Schema Information # # Table name: champions # # id :integer not null, primary key # champion_key :integer # name :string # title :string # image :string # sprite :string # created_at :datetime not null # updated_at :datetime not null # class Champion < ActiveRecord::Base validates_uniqueness_of :champion_key has_many :highest_stats has_many :participants, foreign_key: :champion_key, primary_key: :champion_key def highest_stat_by_region(region) highest_stats.where(region: region) end end
javier-delgado/URF-picker
app/models/match_detail.rb
<reponame>javier-delgado/URF-picker # == Schema Information # # Table name: match_details # # id :integer not null, primary key # match_creation :datetime # match_duration :integer # region_key :string # created_at :datetime not null # updated_at :datetime not null # class MatchDetail < ActiveRecord::Base has_many :participants has_many :teams belongs_to :region, foreign_key: :region_key, primary_key: :key end
javier-delgado/URF-picker
app/models/highest_stat_summatory.rb
class HighestStatSummatory attr_accessor :champion, :region, :assists, :champ_level, :deaths, :kills, :double_kills, :gold_earned, :kills, :magic_damage_dealt_to_champions, :magic_damage_taken, :minions_killed, :neutral_minions_killed, :penta_kills, :physical_damage_dealt_to_champions, :physical_damage_taken, :quadra_kills, :total_damage_dealt_to_champions, :total_damage_taken, :total_heal, :total_time_crowd_control_dealt, :tower_kills, :triple_kills, :true_damage_dealt_to_champions, :unreal_kills, :wards_placed, :wins, :loses def initialize(champion, region = "global") @champion = champion @region = region @count = 0 @assists = 0 @champ_level = 0 @deaths = 0 @kills = 0 @double_kills = 0 @gold_earned = 0 @magic_damage_dealt_to_champions = 0 @magic_damage_taken = 0 @minions_killed = 0 @neutral_minions_killed = 0 @penta_kills = 0 @physical_damage_dealt_to_champions = 0 @physical_damage_taken = 0 @quadra_kills = 0 @total_damage_dealt_to_champions = 0 @total_damage_taken = 0 @total_heal = 0 @total_time_crowd_control_dealt = 0 @tower_kills = 0 @triple_kills = 0 @true_damage_dealt_to_champions = 0 @unreal_kills = 0 @wards_placed = 0 @wins = 0 @loses = 0 end def add_values(stats) @count += 1 @assists += stats.assists @champ_level += stats.champ_level @deaths += stats.deaths @kills += stats.kills @double_kills += stats.double_kills @gold_earned += stats.gold_earned @magic_damage_dealt_to_champions += stats.magic_damage_dealt_to_champions @magic_damage_taken += stats.magic_damage_taken @minions_killed += stats.minions_killed @neutral_minions_killed += stats.neutral_minions_killed @penta_kills += stats.penta_kills @physical_damage_dealt_to_champions += stats.physical_damage_dealt_to_champions @physical_damage_taken += stats.physical_damage_taken @quadra_kills += stats.quadra_kills @total_damage_dealt_to_champions += stats.total_damage_dealt_to_champions @total_damage_taken += stats.total_damage_taken @total_heal += stats.total_heal @total_time_crowd_control_dealt += stats.total_time_crowd_control_dealt @tower_kills += stats.tower_kills @triple_kills += stats.triple_kills @true_damage_dealt_to_champions += stats.true_damage_dealt_to_champions @unreal_kills += stats.unreal_kills @wards_placed += stats.wards_placed if stats.winner @wins += 1 else @loses += 1 end end def calculate_and_save! @count = 1 if @count == 0 #To avoid division by zero HighestStat.create( champion: @champion, region: @region == "global" ? nil : @region, count: @count, assists: (@assists.to_f / @count), champ_level: (@champ_level.to_f / @count), deaths: (@deaths.to_f / @count), kills: (@kills.to_f / @count), double_kills: (@double_kills.to_f / @count), gold_earned: (@gold_earned / @count), kills: (@kills / @count), magic_damage_dealt_to_champions: (@magic_damage_dealt_to_champions / @count), magic_damage_taken: (@magic_damage_taken / @count), minions_killed: (@minions_killed.to_f / @count), neutral_minions_killed: (@neutral_minions_killed.to_f / @count), penta_kills: (@penta_kills.to_f / @count), physical_damage_dealt_to_champions: (@physical_damage_dealt_to_champions / @count), physical_damage_taken: (@physical_damage_taken / @count), quadra_kills: (@quadra_kills.to_f / @count), total_damage_dealt_to_champions: (@total_damage_dealt_to_champions / @count), total_damage_taken: (@total_damage_taken / @count), total_heal: (@total_heal / @count), total_time_crowd_control_dealt: (@total_time_crowd_control_dealt / @count), tower_kills: (@tower_kills.to_f / @count), triple_kills: (@triple_kills.to_f / @count), true_damage_dealt_to_champions: (@true_damage_dealt_to_champions / @count), unreal_kills: (@unreal_kills.to_f / @count), wards_placed: (@wards_placed.to_f / @count), wins: (@wins.to_f / @count), loses: (@loses.to_f / @count) ) end end
javier-delgado/URF-picker
lib/tasks/make_splash_urls.rake
namespace :champion do task :set_image_urls => :environment do Champion.all.each do |champ| champ.image = "http://ddragon.leagueoflegends.com/cdn/img/champion/splash/" + champ.name.gsub(" ", "").gsub("'", "").gsub(".", "") + "_0.jpg" champ.save end #Fix special cases champ = Champion.find_by(name: "Cho'Gath") champ.image = "http://ddragon.leagueoflegends.com/cdn/img/champion/splash/Chogath_0.jpg" champ.save champ = Champion.find_by(name: "Kha'Zix") champ.image = "http://ddragon.leagueoflegends.com/cdn/img/champion/splash/Khazix_0.jpg" champ.save champ = Champion.find_by(name: "Vel'Koz") champ.image = "http://ddragon.leagueoflegends.com/cdn/img/champion/splash/Velkoz_0.jpg" champ.save end end
javier-delgado/URF-picker
app/services/data_fetcher.rb
<filename>app/services/data_fetcher.rb<gh_stars>0 class DataFetcher attr_writer :region def initialize(region) @region = region end def fetch_match_data(match_id) full_url = build_full_url("/api/lol/#{@region.url_key}/v2.2/match/#{match_id}") response = HTTParty.get(full_url) return response end def fetch_urf_matches(begin_date) full_url = build_full_url("/api/lol/#{@region.url_key}/v4.1/game/ids") + "&beginDate=#{begin_date}" response = HTTParty.get(full_url) return response end private def build_full_url(request_url) return get_regional_api + request_url + "?api_key=" + Rails.application.secrets.riot_games_api_key end def get_regional_api return "https://#{@region.url_key}.api.pvp.net" end end
javier-delgado/URF-picker
db/seeds.rb
Region.create(name: "North America", key: "NA") Region.create(name: "Latin America South", key: "LAS") Region.create(name: "Latin America North", key: "LAN") Region.create(name: "Brazil", key: "BR") Region.create(name: "Europe Nordic & East", key: "EUNE") Region.create(name: "Europe West", key: "EUW") Region.create(name: "Oceania", key: "OCE") Region.create(name: "Republic of Korea", key: "KR") Region.create(name: "Russia", key: "RU") Region.create(name: "Turkey", key: "TR") response = HTTParty.get("http://ddragon.leagueoflegends.com/cdn/5.6.1/data/en_US/champion.json") champions = JSON.parse response.body champions['data'].each do |champ| champion = champ[1] Champion.create( champion_key: champion['key'].to_i, name: champion['name'], title: champion['title'], image: "http://ddragon.leagueoflegends.com/cdn/img/champion/splash/#{champion['name']}_0.jpg", sprite: "http://ddragon.leagueoflegends.com/cdn/5.6.1/img/champion/#{champion['image']['full']}" ) end SearchOption.create(name: 'Win every game!', associated_stat: 'wins', ordering: 'DESC', explanation: "{champ_name} has the highest winrate of all the champions. Pick this champion in yout next game to increase your chances of winning!") SearchOption.create(name: 'Make tons of damage!', associated_stat: 'total_damage_dealt_to_champions', ordering: 'DESC', explanation: "{champ_name} has the highest damage rate in the entire URF kingdom. Choose this champion to make your enemies cry for mercy!") SearchOption.create(name: 'Kill all the enemies!', associated_stat: 'kills', ordering: 'DESC', explanation: "So you want to get very VERY fed? {champ_name} has the highest kill rate; pick this champion and kill 'em all!") SearchOption.create(name: 'Be very useful for my teammates!', associated_stat: 'assists', ordering: 'DESC', explanation: "So you want to help your teammates no matter what? Choose {champ_name} in order to get as many assists as is possible in a match!") SearchOption.create(name: 'Get my level through the sky!', associated_stat: 'champ_level', ordering: 'DESC', explanation: "If you want to get your champion level to the roof, pick {champ_name} and get the highest posible level! (Note: in URF there is no level cap at 18)") SearchOption.create(name: 'Be unkillable!', associated_stat: 'deaths', ordering: 'ASC', explanation: "So you want to survive every single teamfight and give your opponents a headache trying to kill you? {champ_name} is your best choice to remain unbeaten for the entire game!") SearchOption.create(name: 'Be a double kill monster!', associated_stat: 'double_kills', ordering: 'DESC', explanation: "you want to get many double kills? That's not very ambitious... Anyway, pick {champ_name} and get tons of double kills! (just don't kill more than two champions in a row)") SearchOption.create(name: 'Be rich!', associated_stat: 'gold_earned', ordering: 'DESC', explanation: "Pick {champ_name} and let the gold fall from the sky (not literally) and become the richest champion!") SearchOption.create(name: 'Deal tons of magic damage!', associated_stat: 'magic_damage_dealt_to_champions', ordering: 'DESC', explanation: "In order to become the best wizzard of all times, you should pick {champ_name}. Get your enemies vaporized with your high magic damage spells!") SearchOption.create(name: 'Tank lots of magic damage!', associated_stat: 'magic_damage_taken', ordering: 'DESC', explanation: "If you want to absorb all of the magic damage from the enemy team you should definitely pick {champ_name}") SearchOption.create(name: 'Farm, farm and keep farming!', associated_stat: 'minions_killed', ordering: 'DESC', explanation: "Can you hear it? It's the scream of the minions running. If you want to get your creep score through the roof, pick {champ_name}") SearchOption.create(name: 'The monster of the jungle!', associated_stat: 'neutral_minions_killed', ordering: 'DESC', explanation: "Pick {champ_name} and you'll kill more jungle creeps than any other jungler before!") SearchOption.create(name: 'Be a Penta-Player!', associated_stat: 'penta_kills', ordering: 'DESC', explanation: "Is 5 the perfect number for you? Then pick {champ_name} and get one PentaKill after another!") SearchOption.create(name: 'AD monster!', associated_stat: 'physical_damage_dealt_to_champions', ordering: 'DESC', explanation: 'Make your enemies cry for mercy, because {champ_name} will deal tons of Physical damage to them') SearchOption.create(name: 'Tank lots of physical damage!', associated_stat: 'physical_damage_taken', ordering: 'DESC', explanation: '{champ_name} has the perfect armor, so pick him and no one will ever get your HP low again!') SearchOption.create(name: 'Be a quadra kill player!', associated_stat: 'quadra_kills', ordering: 'DESC', explanation: 'You want to get as many quadra kills as possible? Pick {champ_name} and make your dream become true! (Just remember to leave the fifth player alive)') SearchOption.create(name: 'Be a damage monster!', associated_stat: 'total_damage_dealt_to_champions', ordering: 'DESC', explanation: '{champ_name}, the perfect attack champion. Pick him and cause tons of physical and magical damage to your enemies!') SearchOption.create(name: 'Be the perfect tank!', associated_stat: 'total_damage_taken', ordering: 'DESC', explanation: "Use {champ_name} and you'll absorb plenty of damage from all the sources!") SearchOption.create(name: 'Get as little damage as possible!', associated_stat: 'total_damage_taken', ordering: 'ASC', explanation: "So you want to play your game without receiving any damage? Pick {champ_name} and let the Tanks do their job!") SearchOption.create(name: 'Be a healing machine!', associated_stat: 'total_heal', ordering: 'DESC', explanation: "Pick {champ_name} and give tons of HP to your teammates! (Don't use it on yourself, don't be egoist)") SearchOption.create(name: 'Be a crowd control beast!', associated_stat: 'total_time_crowd_control_dealt', ordering: 'DESC', explanation: "So you love when your enemies are stunned, rooted, snared, feared, slowed, airborned, ... (and every single form of crowd control)? Pick {champ_name} and your opponents will remain still the entire game!") SearchOption.create(name: 'Destroy every single tower!', associated_stat: 'tower_kills', ordering: 'DESC', explanation: "If you want to destroy one tower after another, pick {champ_name} and make the towers wish they could run away!") SearchOption.create(name: 'Get many triple kills!', associated_stat: 'triple_kills', ordering: 'DESC', explanation: "If you want to get lots of triple kills (not quadras or pentas), pick {champ_name}! (You should consider playing in twisted treeline though)") SearchOption.create(name: 'Be the true danage king!', associated_stat: 'true_damage_dealt_to_champions', ordering: 'DESC', explanation: "Can your fell it? That's the fear of your enemies, because they now there is no defense to prevent you from destroying them. Pick {champ_name} and devour your opponents! (nom nom nom)") SearchOption.create(name: 'Be an unreal player!', associated_stat: 'unreal_kills', ordering: 'DESC', explanation: "So penta kills are not enough for you? You like to kill all your opponents and kill them again as soon as they revive? Pick {champ_name} and keep the hexakill spirit alive!") SearchOption.create(name: 'Have sight of the entire map!', associated_stat: 'wards_placed', ordering: 'DESC', explanation: "Pick {champ_name} name and start placing wards all over the place! (Even though you could the the same with any champion in the game)") SearchOption.create(name: 'Be popular!', associated_stat: 'count', ordering: 'DESC', explanation: "{champ_name} is the most played champion, pick him and follow the trend!") #Special cases SearchOption.create(name: 'Draaaaven!', associated_stat: 'Draven', ordering: 'champion', explanation: "If you want to draven more you should pick Draven and show your enemies what League of Draven is about") SearchOption.create(name: 'Nom nom nom!', associated_stat: "Cho'Gath", ordering: 'champion', explanation: "Eat your enemies -> Become bigger -> Win the game. With Cho'Gath is as simple as that") SearchOption.create(name: 'Go where I please!', associated_stat: 'Dr. Mundo', ordering: 'champion', explanation: "Pick Dr. Mundo and he'll take you wherever he pleases!") SearchOption.create(name: 'Be a captain on duty!', associated_stat: 'Teemo', ordering: 'champion', explanation: 'Pick Teemo and your enemies and teammates will recognize you as the most annoyin... I mean best player of all times!') SearchOption.create(name: 'Ok', associated_stat: 'Rammus', ordering: 'champion', explanation: "If you want to be Ok pick Rammus and you'll be Ok") SearchOption.create(name: 'Be a DunkMaster!', associated_stat: 'Darius', ordering: 'champion', explanation: "Pick Darius and dunk everyone, everywhere, everytime! Unless ultimate is on cooldown... If that's the case just walk away.")
javier-delgado/URF-picker
app/services/collector.rb
class Collector def collect! @start_time = Time.now @errors = 0 p "Collector invoked" Region.all.each do |region| fetcher = DataFetcher.new(region) match_ids = [] response = fetcher.fetch_urf_matches(round_time(2.hours.ago, 5).to_i) if response.code == 200 match_ids = JSON.parse(response.body) else @errors += 1 end match_ids.each do |match_id| response = fetcher.fetch_match_data(match_id) if response.code == 200 json_string = response.body parser = DataParser.new(json_string) parser.parse! else @errors += 1 end end end p "Collector finished: " + (Time.now - @start_time).to_s + " seconds" p "Errors: " + @errors.to_s end def round_time(time, minutes) time-time.sec-time.min%minutes*60 end end
javier-delgado/URF-picker
app/helpers/search_helper.rb
module SearchHelper #def search_options #options = SearchOption.all.shuffle #end def to_decimal_non_zero_value(number, decimals = 1) result = "%.10g" % ("%.#{decimals}f" % number) if result.to_f == 0 && decimals < 8 return to_decimal_non_zero_value(number, decimals + 1) else return result end end end
javier-delgado/URF-picker
app/services/champ_averages.rb
<filename>app/services/champ_averages.rb class ChampAverages def calculate! create_stats_per_champion_per_region perform_summatory HighestStat.destroy_all #Erase previous data p "saving..." @stats_array.map {|hss| hss.calculate_and_save! } end private def create_stats_per_champion_per_region @stats_array = [] Champion.all.each do |champ| @stats_array << HighestStatSummatory.new(champ) Region.all.each do |region| @stats_array << HighestStatSummatory.new(champ, region) end end end def perform_summatory total = MatchDetail.count idx = 1 MatchDetail.includes(:participants => :champion).joins(:participants => :champion) .includes(:participants => :stats).joins(:participants => :stats) .includes(:region).joins(:region).find_each(batch_size: 1000) do |match| print "\r#{idx}/#{total} complete" idx += 1 match.participants.each do |participant| #regional hss = find_highest_stat_summatory(participant.champion, match.region) hss.add_values(participant.stats) #global hss = find_highest_stat_summatory(participant.champion, "global") hss.add_values(participant.stats) end end end def find_highest_stat_summatory(champion, region) i = @stats_array.find_index {|hs| hs.champion == champion && hs.region == region} @stats_array[i] end end
javier-delgado/URF-picker
config/routes.rb
Rails.application.routes.draw do root 'home#search' post :search_champion, to: 'search#search_champion' end
javier-delgado/URF-picker
app/models/participant.rb
# == Schema Information # # Table name: participants # # id :integer not null, primary key # match_detail_id :integer # team_id :integer # champion_key :integer # team_key :integer # highest_achieved_season_tier :string # participant_key :integer # spell1Id :integer # spell2Id :integer # created_at :datetime not null # updated_at :datetime not null # class Participant < ActiveRecord::Base belongs_to :match_detail belongs_to :team has_one :stats, class_name: "ParticipantStat" belongs_to :champion, foreign_key: :champion_key, primary_key: :champion_key end
javier-delgado/URF-picker
db/migrate/20150405225106_remove_objects.rb
class RemoveObjects < ActiveRecord::Migration def change remove_column :highest_stats, :item0 remove_column :highest_stats, :item1 remove_column :highest_stats, :item2 remove_column :highest_stats, :item3 remove_column :highest_stats, :item4 remove_column :highest_stats, :item5 remove_column :highest_stats, :item6 remove_column :highest_stats, :item7 end end
javier-delgado/URF-picker
db/migrate/20150405225800_add_explanation_to_search_option.rb
class AddExplanationToSearchOption < ActiveRecord::Migration def change add_column :search_options, :explanation, :text end end
javier-delgado/URF-picker
config/schedule.rb
set :environment, "production" set :output, {:error => "log/cron_error_log.log", :standard => "log/cron_log.log"} #Disabled beacuse of end of event #every 10.minutes do #rake "api:collect_urf_data" #end
javier-delgado/URF-picker
db/migrate/20150402214123_fis_column_name_match_details.rb
<reponame>javier-delgado/URF-picker class FisColumnNameMatchDetails < ActiveRecord::Migration def change rename_column :match_details, :region, :region_key end end
javier-delgado/URF-picker
app/models/banned_champion.rb
<reponame>javier-delgado/URF-picker # == Schema Information # # Table name: banned_champions # # id :integer not null, primary key # team_id :integer # champion_id :integer # champion_key :integer # created_at :datetime not null # updated_at :datetime not null # class BannedChampion < ActiveRecord::Base belongs_to :team end
linyize/SlateActivityIndicatorView
SlateActivityIndicatorView.podspec
<reponame>linyize/SlateActivityIndicatorView Pod::Spec.new do |s| s.name = "SlateActivityIndicatorView" s.version = "0.1.0" s.summary = "A custom activity indicator view." s.description = <<-DESC A custom activity indicator view. Support white, gray, white large, gray large styles. DESC s.homepage = "https://github.com/islate/SlateActivityIndicatorView" s.license = 'Apache 2.0' s.author = { "wangliqun" => "<EMAIL>", "linyize" => "<EMAIL>" } s.source = { :git => "https://github.com/islate/SlateActivityIndicatorView.git", :tag => s.version.to_s } s.platform = :ios, '7.0' s.requires_arc = true s.source_files = '*.{h,m}' s.resource_bundles = { 'ActivityIndicator' => ['resources/*.png'] } end
Abduliokhanio/pirate_project02
db/migrate/02_create_tickets_table.rb
class CreateTicketsTable < ActiveRecord::Migration[5.2] def change create_table :tickets do |t| t.string :title t.integer :owner_id end end end
Abduliokhanio/pirate_project02
app/controllers/tickets_controller.rb
class TicketsController < ApplicationController get '/tickets' do erb :'/tickets/index' end end
Abduliokhanio/pirate_project02
app/models/employee.rb
<gh_stars>0 class Employee < ActiveRecord::Base has_many :tickets end
Abduliokhanio/pirate_project02
app/controllers/application_controller.rb
class ApplicationController < Sinatra::Base register Sinatra::ActiveRecordExtension set :session_secret, "my_application_secret" set :views, Proc.new { File.join(root, "../views/") } get '/' do erb :'index' end get '/register' do erb :'/registrations/signup' end post '/registrations' do @user = Employee.new(name: params["name"], Username: params["Username"], password: params["password"]) @user.save session[:user_id] = @user.id redirect '/employees/welcome' end get '/sessions/login' do erb :'sessions/login' end post '/sessions' do @user = Employee.find_by(Username: params[:Username], password: params[:password]) if @user session[:user_id] = @user.id redirect '/employees/welcome' end redirect '/sessions/login' end get '/sessions/logout' do session.clear redirect '/' end end
Abduliokhanio/pirate_project02
app/controllers/employees_controller.rb
class EmployeesController < ApplicationController get '/employees' do erb :'/employees/index' end get '/employees/welcome' do erb :'/employees/welcome' end end
Abduliokhanio/pirate_project02
app/models/ticket.rb
<reponame>Abduliokhanio/pirate_project02 class Ticket < ActiveRecord::Base belongs_to :employee end
matthewtidd/site_logger
app/controllers/dmt/site_logger/logs_controller.rb
class Dmt::SiteLogger::LogsController < ApplicationController # GET /dmt/site_logger/logs # GET /dmt/site_logger/logs.xml def index @logs = Dmt::SiteLogger::Log.find(:all) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @logs } end end # GET /dmt/site_logger/logs/1 # GET /dmt/site_logger/logs/1.xml def show @log = Dmt::SiteLogger::Log.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @log } end end end
matthewtidd/site_logger
app/models/dmt/site_logger/log.rb
<gh_stars>1-10 class Dmt::SiteLogger::Log < ActiveRecord::Base set_table_name 'dmt_site_logger_logs' validates_presence_of :controller validates_presence_of :action validates_presence_of :params validates_presence_of :ipaddr end
matthewtidd/site_logger
routes.rb
<gh_stars>1-10 resources :logs, :path_prefix => '/dmt/site_logger', :name_prefix => 'dmt_site_logger_', :controller => 'dmt/site_logger/logs'
matthewtidd/site_logger
lib/site_logger.rb
# SiteLogger module DMT module SiteLogger def self.included(mod) mod.extend(ClassMethods) end module ClassMethods def dmt_site_logger(args=Hash.new()) self.send(:after_filter, :dmt_site_logger, args) extend DMT::SiteLogger::SingletonMethods include DMT::SiteLogger::InstanceMethods end end module SingletonMethods end module InstanceMethods attr_accessor :dmt_site_logger_flag def dmt_site_logger_disable self.dmt_site_logger_flag = true end def dmt_site_logger if !self.dmt_site_logger_flag data = Hash.new data = { 'controller' => params[:controller], 'action' => params[:action], 'user' => params[:user], 'path_uri' => request.env['REQUEST_URI'], 'params' => params.to_yaml + "\n" + response.headers["Status"], 'ipaddr' => request.remote_addr, 'referer' => request.env['HTTP_REFERER'], 'browser' => request.user_agent } log = Dmt::SiteLogger::Log.new(data) log.save end end end module ViewHelpers def dmt_site_logger_count Dmt::SiteLogger::Log.count end end end end
matthewtidd/site_logger
lib/tasks/site_logger.rake
<filename>lib/tasks/site_logger.rake<gh_stars>1-10 namespace :dmt do namespace :site_logger do desc "Migrate the database for the site_logger plugin." task :migrate => :environment do ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true ActiveRecord::Migrator.migrate("vendor/plugins/site_logger/db/migrate", ENV["VERSION"] ? ENV["VERSION"].to_i : nil) Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby end end end
matthewtidd/site_logger
app/helpers/dmt/site_logger/logs_helper.rb
<filename>app/helpers/dmt/site_logger/logs_helper.rb module Dmt::SiteLogger::LogsHelper end
matthewtidd/site_logger
init.rb
# Include hook code here require "site_logger" ActionController::Base.class_eval do include DMT::SiteLogger end ActionView::Base.send :include, DMT::SiteLogger::ViewHelpers
shaicoleman/paseto.rb
spec/paseto/v2/public_spec.rb
<gh_stars>1-10 # frozen_string_literal: true require 'securerandom' RSpec.describe Paseto::V2::Public do let(:public) { described_class } # Generated using https://github.com/paragonie/paseto: # # use ParagonIE\Paseto\Protocol\Version2; # use ParagonIE\Paseto\Keys\AsymmetricSecretKey; # use ParagonIE\ConstantTime\Base64UrlSafe; # # $secretKey = new AsymmetricSecretKey( # Base64UrlSafe::decode('<KEY>') # ); # $token = Version2::sign('test', $secretKey); # $tokenWithFooter = Version2::sign('test', $secretKey, 'plain text footer') # # echo $token; # echo $tokenWithFooter; let(:encoded_secret_key) { '<KEY>' } let(:secret_key) { Paseto::V2::Public::SecretKey.decode64(encoded_secret_key) } let(:encoded_public_key) { '<KEY>' } let(:public_key) { Paseto::V2::Public::PublicKey.decode64(encoded_public_key) } let(:footer) { nil } let(:message) { 'test' } let(:signed_message) do 'v2.public.dGVzdC7gAlr_TQTcxOKxEN5uRM9k18CbQPG8MChyiqJJx17AM7hBByXV2U0e4aQCQuTPL<KEY>GB9CAA' end let(:bad_message) do 'v2.public.1GVzdD-ZV9h7UClSTPyEwdDMJ7u82FBGCuLMETNCQ9l27dwuWiTz28cJa3sKwXAalpmmWIHVR6nCSK6uBfGlkDDcNAk' end let(:signed_message_with_footer) do 'v2.public.<KEY>' end describe 'common use cases' do it 'can be used to sign public cleartext' do key = public::SecretKey.generate token = key.sign('clear as day') # in the most common case, the public key will be serialized and stored / # sent somewhere, and the counterparty will decode it and verify the token sent_key = key.public_key.encode64 decoded_key = public::PublicKey.decode64(sent_key) expect(decoded_key.verify(token)).to eq('clear as day') end it 'can verify a value signed by pypaseto' do # Generated using python 3.6.2 / libsodium: 1.0.16: # from paseto import PasetoV2 # import pysodium # import base64 # import secrets # public, secret = pysodium.crypto_sign_keypair() # print('public', base64.b64encode(public).replace(b'=', b'')) # print('token', PasetoV2.sign(b'clear as day', secret, b'yet another footer')) python_key = '<KEY>' python_token = '<KEY>' key = public::PublicKey.decode64(python_key) expect(key.verify(python_token, 'yet another footer')).to eq('clear as day') end end describe Paseto::V2::Public::SecretKey do it 'can encode key material' do expect(secret_key.encode64).to eq(encoded_secret_key) end it 'can export public key' do expect(secret_key.public_key.encode64).to eq(encoded_public_key) end end describe Paseto::V2::Public::SecretKey do it 'can encode key material' do expect(public_key.encode64).to eq(encoded_public_key) end end describe '#sign' do it 'signs a message' do expect(public.sign(message, secret_key)).to eq signed_message end context 'with a footer' do let(:footer) { 'plain text footer' } it 'signs a message' do expect(public.sign(message, secret_key, footer)).to eq signed_message_with_footer end end end describe '#verify' do it 'verifies a message' do expect(public.verify(signed_message, public_key)).to be_truthy end it 'can verify a message with the secret key' do expect(public.verify(signed_message, secret_key)).to be_truthy end it 'rejects a bad signature' do expect { public.verify(bad_message, public_key) }.to( raise_error Paseto::AuthenticationError ) end it 'raises an error for a bad header' do expect { public.verify('incorrect.header', public_key) }.to( raise_error Paseto::HeaderError ) end it 'raises error trying to decrypt junk' do expect { public.verify('v2.public.' + SecureRandom.hex, public_key) }.to( raise_error Paseto::Error ) end it 'allows access to the signed payload' do expect(public.verify(signed_message, public_key)).to eq(message) end context 'with a footer' do let(:footer) { 'plain text footer' } let(:bad_footer) { 'other foot' } it "verifies when the footer matches what's expected" do message = public.verify(signed_message_with_footer, public_key, footer) expect(message).to eq(message) end it 'does not require a footer from a parsed message' do message = public_key.verify(Paseto.parse(signed_message_with_footer)) expect(message).to eq(message) end it "raises when the footer doesn't match what's expected" do expect do public.verify(signed_message_with_footer, public_key, bad_footer) end.to raise_error Paseto::TokenError end end end end
shaicoleman/paseto.rb
spec/paseto_spec.rb
<filename>spec/paseto_spec.rb # frozen_string_literal: true RSpec.describe Paseto do it 'has a version number' do expect(Paseto::VERSION).not_to be nil end describe '#encode_length' do it 'encodes empty' do expect(described_class.encode_length(0)).to eq("\x00\x00\x00\x00\x00\x00\x00\x00") end it 'encodes a length' do expect(described_class.encode_length(4)).to eq("\x04\x00\x00\x00\x00\x00\x00\x00") end it 'encodes numbers greater than 255' do expect(described_class.encode_length(256)).to eq("\x00\x01\x00\x00\x00\x00\x00\x00") end end describe '#pre_auth_encode' do it 'encodes an empty array' do expect(described_class.pre_auth_encode).to eq("\x00\x00\x00\x00\x00\x00\x00\x00") end it 'encodes an empty string' do expect(described_class.pre_auth_encode('')).to( eq("\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00") ) end it 'encodes a string' do expect(described_class.pre_auth_encode('test')).to( eq("\x01\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00test") ) end end describe '#parse' do it 'can be used to read the message footer' do Token = Paseto::V2::Local token = Token.encrypt('message', Token::Key.generate, 'hello there') expect(described_class.parse(token).footer).to eq('hello there') end end end
shaicoleman/paseto.rb
lib/paseto/public.rb
<reponame>shaicoleman/paseto.rb # frozen_string_literal: true module Paseto module V2 # Asymmetric Authentication (Public-Key Signatures) module Public HEADER = 'v2.public' SIGNATURE_BYTES = RbNaCl::SigningKey.signature_bytes BadMessageError = Class.new(Paseto::Error) # Encode a message + footer in a Paseto payload module Encoder private def encode_message(message, footer) Paseto.pre_auth_encode(HEADER + '.', message, footer) end end # secret-key used for signing and verifing class SecretKey include Encoder def self.generate new(RbNaCl::SigningKey.generate) end def self.decode64(encoded_key) new(Paseto.decode64(encoded_key)) end def initialize(key) @key = key @nacl = RbNaCl::SigningKey.new(key) end def sign(message, footer = EMPTY_FOOTER) data = encode_message(message, footer) # Sign a message with the signing key signature = @nacl.sign(data) Paseto::Token.new(HEADER, message + signature, footer).to_message end def verify(message, footer = nil) public_key.verify(message, footer) end def public_key PublicKey.new(@nacl.verify_key.to_bytes) end def encode64 Paseto.encode64(@key) end end # public-key used for signing and verifing class PublicKey include Encoder def self.decode64(encoded_key) new(Paseto.decode64(encoded_key)) end def initialize(key) @key = key @nacl = RbNaCl::VerifyKey.new(key) end def encode64 Paseto.encode64(@key) end def verify(token, footer = nil) footer ||= token.footer if token.is_a? Paseto::Token footer ||= EMPTY_FOOTER parsed = Paseto.verify_token(token, HEADER, footer) decoded_message = parsed.payload[0..-(SIGNATURE_BYTES + 1)] signature = parsed.payload[-SIGNATURE_BYTES..-1] if decoded_message.nil? || signature.nil? raise BadMessageError, 'Unable to process message' end begin data = encode_message(decoded_message, footer) @nacl.verify(signature, data) decoded_message rescue RbNaCl::BadSignatureError raise AuthenticationError, 'Token signature invalid' end end end def self.sign(message, key, footer = EMPTY_FOOTER) key.sign(message, footer) end def self.verify(token, key, footer = nil) key.verify(token, footer) end end end end
hoperays/openstack-ha-puppet-module
vswitch/lib/puppet/type/vs_config.rb
require 'puppet' Puppet::Type.newtype(:vs_config) do desc 'Switch configurations' ensurable newparam(:name, :namevar => true) do desc 'Configuration parameter whose value need to be set' validate do |value| if !value.is_a?(String) raise ArgumentError, "Invalid name #{value}. Requires a String, not a #{value.class}" end end end newproperty(:value) do desc 'Configuration value for the paramter' validate do |value| if !value.is_a?(String) raise ArgumentError, "Invalid external_ids #{value}. Requires a String, not a #{value.class}" end end munge do |value| if value[0] == '[' && value[-1] == ']' "[#{value[1..-2].split(',').map(&:strip).sort.join(",")}]" else super(value) end end end end
hoperays/openstack-ha-puppet-module
nova/spec/classes/nova_migration_libvirt_spec.rb
<filename>nova/spec/classes/nova_migration_libvirt_spec.rb<gh_stars>0 # # Copyright (C) 2013 eNovance SAS <<EMAIL>> # # Author: <NAME> <<EMAIL>> # # 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. # # Unit tests for nova::migration::libvirt class # require 'spec_helper' describe 'nova::migration::libvirt' do generate = {} before(:each) { Puppet::Parser::Functions.newfunction(:generate, :type => :rvalue) { |args| generate.call() } generate.stubs(:call).returns('0000-111-111') } let :pre_condition do 'include nova include nova::compute include nova::compute::libvirt' end shared_examples_for 'nova migration with libvirt' do context 'with default params' do it { is_expected.to contain_file_line('/etc/libvirt/libvirtd.conf listen_tls').with(:line => "listen_tls = 0") } it { is_expected.to contain_file_line('/etc/libvirt/libvirtd.conf listen_tcp').with(:line => "listen_tcp = 1") } it { is_expected.not_to contain_file_line('/etc/libvirt/libvirtd.conf auth_tls')} it { is_expected.to contain_file_line('/etc/libvirt/libvirtd.conf auth_tcp').with(:line => "auth_tcp = \"none\"") } it { is_expected.to contain_nova_config('libvirt/live_migration_tunnelled').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_nova_config('libvirt/live_migration_completion_timeout').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_nova_config('libvirt/live_migration_progress_timeout').with_value('<SERVICE DEFAULT>') } end context 'with override_uuid enabled' do let :params do { :override_uuid => true, } end it { is_expected.to contain_file('/etc/libvirt/libvirt_uuid').with({ :content => '0000-111-111', }).that_requires('Package[libvirt]') } it { is_expected.to contain_augeas('libvirt-conf-uuid').with({ :context => '/files/etc/libvirt/libvirtd.conf', :changes => [ "set host_uuid 0000-111-111" ], }).that_requires('Package[libvirt]').that_notifies('Service[libvirt]') } end context 'with tls enabled' do let :params do { :use_tls => true, } end it { is_expected.to contain_file_line('/etc/libvirt/libvirtd.conf listen_tls').with(:line => "listen_tls = 1") } it { is_expected.to contain_file_line('/etc/libvirt/libvirtd.conf listen_tcp').with(:line => "listen_tcp = 0") } it { is_expected.to contain_file_line('/etc/libvirt/libvirtd.conf auth_tls').with(:line => "auth_tls = \"none\"") } it { is_expected.not_to contain_file_line('/etc/libvirt/libvirtd.conf auth_tcp')} it { is_expected.to contain_nova_config('libvirt/live_migration_uri').with_value('qemu+tls://%s/system')} end context 'with migration flags set' do let :params do { :live_migration_tunnelled => true, :live_migration_completion_timeout => '1500', :live_migration_progress_timeout => '1500', } end it { is_expected.to contain_nova_config('libvirt/live_migration_tunnelled').with(:value => true) } it { is_expected.to contain_nova_config('libvirt/live_migration_completion_timeout').with_value('1500') } it { is_expected.to contain_nova_config('libvirt/live_migration_progress_timeout').with_value('1500') } end context 'with auth set to sasl' do let :params do { :auth => '<PASSWORD>', } end it { is_expected.not_to contain_file_line('/etc/libvirt/libvirtd.conf auth_tls')} it { is_expected.to contain_file_line('/etc/libvirt/libvirtd.conf auth_tcp').with(:line => "auth_tcp = \"sasl\"") } end context 'with auth set to sasl and tls enabled' do let :params do { :auth => '<PASSWORD>', :use_tls => true } end it { is_expected.to contain_file_line('/etc/libvirt/libvirtd.conf auth_tls').with(:line => "auth_tls = \"sasl\"") } it { is_expected.not_to contain_file_line('/etc/libvirt/libvirtd.conf auth_tcp')} end context 'with auth set to an invalid setting' do let :params do { :auth => 'inexistent_auth', } end it { expect { is_expected.to contain_class('nova::compute::libvirt') }.to \ raise_error(Puppet::Error, /Valid options for auth are none and sasl./) } end context 'when not configuring libvirt' do let :params do { :configure_libvirt => false } end it { is_expected.not_to contain_file_line('/etc/libvirt/libvirtd.conf listen_tls') } end context 'when not configuring nova and tls enabled' do let :params do { :configure_nova => false, :use_tls => true, } end it { is_expected.not_to contain_nova_config('libvirt/live_migration_uri').with_value('qemu+tls://%s/system') } end end # TODO (degorenko): switch to on_supported_os function when we got Xenial context 'on Debian platforms with Ubuntu release 16' do let :facts do @default_facts.merge({ :osfamily => 'Debian', :operatingsystem => 'Ubuntu', :operatingsystemmajrelease => '16' }) end it_configures 'nova migration with libvirt' it { is_expected.to contain_file_line('/etc/default/libvirt-bin libvirtd opts').with(:line => 'libvirtd_opts="-l"') } end context 'on Debian platforms release' do let :facts do @default_facts.merge({ :osfamily => 'Debian', :operatingsystem => 'Debian', :operatingsystemmajrelease => '8' }) end it_configures 'nova migration with libvirt' it { is_expected.to contain_file_line('/etc/default/libvirt-bin libvirtd opts').with(:line => 'libvirtd_opts="-d -l"') } end context 'on RedHat platforms' do let :facts do @default_facts.merge({ :osfamily => 'RedHat', :operatingsystem => 'CentOS', :operatingsystemmajrelease => '7.0' }) end it_configures 'nova migration with libvirt' it { is_expected.to contain_file_line('/etc/sysconfig/libvirtd libvirtd args').with(:line => 'LIBVIRTD_ARGS="--listen"') } end end
hoperays/openstack-ha-puppet-module
trove/spec/classes/trove_deps_spec.rb
require 'spec_helper' describe 'trove::deps' do it 'set up the anchors' do is_expected.to contain_anchor('trove::install::begin') is_expected.to contain_anchor('trove::install::end') is_expected.to contain_anchor('trove::config::begin') is_expected.to contain_anchor('trove::config::end') is_expected.to contain_anchor('trove::db::begin') is_expected.to contain_anchor('trove::db::end') is_expected.to contain_anchor('trove::dbsync::begin') is_expected.to contain_anchor('trove::dbsync::end') is_expected.to contain_anchor('trove::service::begin') is_expected.to contain_anchor('trove::service::end') end end
hoperays/openstack-ha-puppet-module
trove/spec/classes/trove_guestagent_spec.rb
<reponame>hoperays/openstack-ha-puppet-module require 'spec_helper' describe 'trove::guestagent' do shared_examples 'trove-guestagent' do context 'with default parameters' do let :pre_condition do "class { 'trove': os_region_name => 'RegionOne', nova_proxy_admin_pass => '<PASSWORD>'}" end it 'installs trove-guestagent package and service' do is_expected.to contain_service('trove-guestagent').with( :name => platform_params[:guestagent_service_name], :ensure => 'running', :hasstatus => true, :enable => true ) is_expected.to contain_package('trove-guestagent').with( :name => platform_params[:guestagent_package_name], :ensure => 'present', :tag => ['openstack', 'trove-package'] ) end it 'configures trove-guestagent with default parameters' do is_expected.to contain_trove_guestagent_config('DEFAULT/debug').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('DEFAULT/use_syslog').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('DEFAULT/syslog_log_facility').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('DEFAULT/log_file').with_value('/var/log/trove/trove-guestagent.log') is_expected.to contain_trove_guestagent_config('DEFAULT/log_dir').with_value('/var/log/trove') is_expected.to contain_trove_guestagent_config('DEFAULT/os_region_name').with_value('RegionOne') is_expected.to contain_trove_guestagent_config('DEFAULT/control_exchange').with_value('trove') is_expected.to contain_trove_guestagent_config('DEFAULT/transport_url').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_notifications/transport_url').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_notifications/driver').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_notifications/topics').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/rabbit_host').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/rabbit_hosts').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/rabbit_port').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/rabbit_userid').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/rabbit_password').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/kombu_reconnect_delay').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/amqp_durable_queues').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('DEFAULT/swift_url').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('DEFAULT/root_grant').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('DEFAULT/root_grant_option').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('DEFAULT/default_password_length').with_value('<SERVICE DEFAULT>') end context 'when using a single RabbitMQ server' do let :pre_condition do "class { 'trove': nova_proxy_admin_pass => '<PASSWORD>', rabbit_host => '10.0.0.1'}" end it 'configures trove-guestagent with RabbitMQ' do is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/rabbit_host').with_value('10.0.0.1') is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/amqp_durable_queues').with_value('<SERVICE DEFAULT>') end end context 'when using a single RabbitMQ server with enable ha options' do let :pre_condition do "class { 'trove': nova_proxy_admin_pass => '<PASSWORD>', rabbit_ha_queues => 'true', amqp_durable_queues => 'true', rabbit_host => '10.0.0.1'}" end it 'configures trove-api with RabbitMQ' do is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/rabbit_host').with_value('10.0.0.1') is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('true') is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/amqp_durable_queues').with_value('true') end end context 'when using multiple RabbitMQ servers' do let :pre_condition do "class { 'trove': nova_proxy_admin_pass => '<PASSWORD>', rabbit_hosts => ['10.0.0.1','10.0.0.2']}" end it 'configures trove-guestagent with RabbitMQ' do is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/rabbit_hosts').with_value(['10.0.0.1,10.0.0.2']) is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('true') end end end context 'with custom parameters' do let :pre_condition do "class { 'trove': nova_proxy_admin_pass => '<PASSWORD>'}" end let :params do { :auth_url => "http://10.0.0.1:5000/v2.0", :swift_url => "http://10.0.0.1:8080/v1/AUTH_", :rabbit_host => '10.1.0.1', :rabbit_port => '5673', :rabbit_use_ssl => 'true' } end it 'configures trove-guestagent with custom parameters' do is_expected.to contain_trove_guestagent_config('DEFAULT/trove_auth_url').with_value('http://10.0.0.1:5000/v2.0') is_expected.to contain_trove_guestagent_config('DEFAULT/swift_url').with_value('http://10.0.0.1:8080/v1/AUTH_') is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/rabbit_host').with_value('10.1.0.1') is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/rabbit_port').with_value('5673') is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('true') end end context 'with SSL enabled with kombu' do let :pre_condition do "class { 'trove': nova_proxy_admin_pass => '<PASSWORD>', rabbit_use_ssl => true, kombu_ssl_ca_certs => '/path/to/ssl/ca/certs', kombu_ssl_certfile => '/path/to/ssl/cert/file', kombu_ssl_keyfile => '/path/to/ssl/keyfile', kombu_ssl_version => 'TLSv1'}" end it do is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('true') is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('/path/to/ssl/ca/certs') is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('/path/to/ssl/cert/file') is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('/path/to/ssl/keyfile') is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('TLSv1') end end context 'with SSL enabled without kombu' do let :pre_condition do "class { 'trove': nova_proxy_admin_pass => '<PASSWORD>', rabbit_use_ssl => true}" end it do is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('true') is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('<SERVICE DEFAULT>') end end context 'with SSL disabled' do let :pre_condition do "class { 'trove': nova_proxy_admin_pass => '<PASSWORD>', rabbit_use_ssl => false}" end it do is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('false') is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('<SERVICE DEFAULT>') end end context 'with transport_url entries' do let :pre_condition do "class { 'trove': nova_proxy_admin_pass => '<PASSWORD>', default_transport_url => 'rabbit://rabbit_user:password@localhost:5673', notification_transport_url => 'rabbit://rabbit_user:password@localhost:5673' }" end it do is_expected.to contain_trove_guestagent_config('DEFAULT/transport_url').with_value('rabbit://rabbit_user:password@localhost:5673') is_expected.to contain_trove_guestagent_config('oslo_messaging_notifications/transport_url').with_value('rabbit://rabbit_user:password@localhost:5673') end end context 'with amqp rpc' do let :pre_condition do "class { 'trove' : nova_proxy_admin_pass => '<PASSWORD>', rpc_backend => 'amqp' }" end it do is_expected.to contain_trove_guestagent_config('DEFAULT/rpc_backend').with_value('amqp') is_expected.to contain_trove_guestagent_config('oslo_messaging_amqp/server_request_prefix').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_amqp/broadcast_prefix').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_amqp/group_request_prefix').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_amqp/container_name').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_amqp/idle_timeout').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_amqp/trace').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_amqp/ssl_ca_file').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_amqp/ssl_cert_file').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_amqp/ssl_key_file').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_amqp/ssl_key_password').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_amqp/allow_insecure_clients').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_amqp/sasl_mechanisms').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_amqp/sasl_config_dir').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_amqp/sasl_config_name').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_amqp/username').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_guestagent_config('oslo_messaging_amqp/password').with_value('<SERVICE DEFAULT>') end end end context 'on Debian platforms' do let :facts do @default_facts.merge({ :osfamily => 'Debian', :processorcount => 8 }) end let :platform_params do { :guestagent_package_name => 'trove-guestagent', :guestagent_service_name => 'trove-guestagent' } end it_configures 'trove-guestagent' end context 'on RedHat platforms' do let :facts do @default_facts.merge({ :osfamily => 'RedHat', :processorcount => 8 }) end let :platform_params do { :guestagent_package_name => 'openstack-trove-guestagent', :guestagent_service_name => 'openstack-trove-guestagent' } end it_configures 'trove-guestagent' end end
hoperays/openstack-ha-puppet-module
openstacklib/lib/puppet/provider/openstack/credentials.rb
<reponame>hoperays/openstack-ha-puppet-module<gh_stars>10-100 require 'puppet' require 'puppet/provider/openstack' class Puppet::Provider::Openstack::Credentials KEYS = [ :auth_url, :password, :project_name, :username, :token, :url, :identity_api_version, :region_name ] KEYS.each { |var| attr_accessor var } def self.defined?(name) KEYS.include?(name.to_sym) end def set(key, val) if self.class.defined?(key.to_sym) self.instance_variable_set("@#{key}".to_sym, val) end end def set? return true if user_password_set? || service_token_set? end def service_token_set? return true if @token && @url end def to_env env = {} self.instance_variables.each do |var| name = var.to_s.sub(/^@/,'OS_').upcase env.merge!(name => self.instance_variable_get(var)) end env end def user_password_set? return true if @username && @password && @project_name && @auth_url end def unset KEYS.each do |key| if key != :identity_api_version && self.instance_variable_defined?("@#{key}") set(key, '') end end end def version self.class.to_s.sub(/.*V/,'').sub('_','.') end end class Puppet::Provider::Openstack::CredentialsV2_0 < Puppet::Provider::Openstack::Credentials end class Puppet::Provider::Openstack::CredentialsV3 < Puppet::Provider::Openstack::Credentials KEYS = [ :cacert, :cert, :default_domain, :domain_id, :domain_name, :key, :project_domain_id, :project_domain_name, :project_id, :trust_id, :user_domain_id, :user_domain_name, :user_id ] KEYS.each { |var| attr_accessor var } def self.defined?(name) KEYS.include?(name.to_sym) || super end def user_password_set? return true if (@username || @user_id) && @password && (@project_name || @project_id) && @auth_url end def initialize set(:identity_api_version, version) end end
hoperays/openstack-ha-puppet-module
swift/spec/classes/swift_proxy_staticweb_spec.rb
<gh_stars>0 require 'spec_helper' describe 'swift::proxy::staticweb' do let :facts do {} end it { is_expected.to contain_concat_fragment('swift-proxy-staticweb').with_content(/[filter:staticweb]/) } it { is_expected.to contain_concat_fragment('swift-proxy-staticweb').with_content(/use = egg:swift#staticweb/) } describe "when overriding default parameters" do let :params do { :url_base => 'https://www.example.com', } end it { is_expected.to contain_concat_fragment('swift-proxy-staticweb').with_content(/url_base = https:\/\/www.example.com/) } end end
hoperays/openstack-ha-puppet-module
trove/spec/classes/trove_api_spec.rb
# # Copyright (C) 2014 eNovance SAS <<EMAIL>> # # Author: <NAME> <<EMAIL>> # # 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. # # Unit tests for trove::api # require 'spec_helper' describe 'trove::api' do let :params do { :keystone_password => '<PASSWORD>', :identity_uri => 'http://10.0.0.10:35357/', :auth_uri => 'http://10.0.0.10:5000/v2.0/', :keystone_tenant => '_services_', :keystone_user => 'trove', } end shared_examples 'trove-api' do context 'with default parameters' do let :pre_condition do "class { 'trove': nova_proxy_admin_pass => '<PASSWORD>', os_region_name => 'RegionOne', nova_compute_service_type => 'compute', cinder_service_type => 'volume', swift_service_type => 'object-store', heat_service_type => 'orchestration', neutron_service_type => 'network'}" end it 'installs trove-api package and service' do is_expected.to contain_service('trove-api').with( :name => platform_params[:api_service_name], :ensure => 'running', :hasstatus => true, :enable => true ) is_expected.to contain_package('trove-api').with( :name => platform_params[:api_package_name], :ensure => 'present', :tag => ['openstack', 'trove-package'], ) end it 'configures trove-api with default parameters' do is_expected.to contain_trove_config('DEFAULT/bind_host').with_value('0.0.0.0') is_expected.to contain_trove_config('DEFAULT/bind_port').with_value('8779') is_expected.to contain_trove_config('DEFAULT/backlog').with_value('4096') is_expected.to contain_trove_config('DEFAULT/trove_api_workers').with_value('8') is_expected.to contain_trove_config('DEFAULT/trove_auth_url').with_value('http://10.0.0.10:5000/v2.0/') is_expected.to contain_trove_config('DEFAULT/nova_proxy_admin_user').with_value('admin') is_expected.to contain_trove_config('DEFAULT/nova_proxy_admin_pass').with_value('verysecrete') is_expected.to contain_trove_config('DEFAULT/nova_proxy_admin_tenant_name').with_value('admin') is_expected.to contain_trove_config('keystone_authtoken/auth_uri').with_value('http://10.0.0.10:5000/v2.0/') is_expected.to contain_trove_config('keystone_authtoken/auth_url').with_value('http://10.0.0.10:35357/') is_expected.to contain_trove_config('keystone_authtoken/project_name').with_value('_services_') is_expected.to contain_trove_config('keystone_authtoken/username').with_value('trove') is_expected.to contain_trove_config('keystone_authtoken/password').with_value('<PASSWORD>') is_expected.to contain_trove_config('DEFAULT/control_exchange').with_value('trove') is_expected.to contain_trove_config('DEFAULT/os_region_name').with_value('RegionOne') is_expected.to contain_trove_config('DEFAULT/nova_compute_service_type').with_value('compute') is_expected.to contain_trove_config('DEFAULT/cinder_service_type').with_value('volume') is_expected.to contain_trove_config('DEFAULT/swift_service_type').with_value('object-store') is_expected.to contain_trove_config('DEFAULT/heat_service_type').with_value('orchestration') is_expected.to contain_trove_config('DEFAULT/neutron_service_type').with_value('network') is_expected.to contain_trove_config('DEFAULT/http_get_rate').with_value('200') is_expected.to contain_trove_config('DEFAULT/http_post_rate').with_value('200') is_expected.to contain_trove_config('DEFAULT/http_put_rate').with_value('200') is_expected.to contain_trove_config('DEFAULT/http_delete_rate').with_value('200') is_expected.to contain_trove_config('DEFAULT/http_mgmt_post_rate').with_value('200') is_expected.to contain_trove_config('DEFAULT/transport_url').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_config('oslo_messaging_notifications/transport_url').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_config('oslo_messaging_notifications/driver').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_config('oslo_messaging_notifications/topics').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_config('oslo_messaging_rabbit/rabbit_userid').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_config('oslo_messaging_rabbit/rabbit_password').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_config('oslo_messaging_rabbit/kombu_reconnect_delay').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_config('oslo_messaging_rabbit/amqp_durable_queues').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_config('ssl/cert_file').with_ensure('absent') is_expected.to contain_trove_config('ssl/key_file').with_ensure('absent') is_expected.to contain_trove_config('ssl/ca_file').with_ensure('absent') end context 'with SSL enabled on API' do before :each do params.merge!( :cert_file => 'cert', :key_file => 'key', :ca_file => 'ca', ) end it 'contains ssl parameters' do is_expected.to contain_trove_config('ssl/cert_file').with_value('cert') is_expected.to contain_trove_config('ssl/key_file').with_value('key') is_expected.to contain_trove_config('ssl/ca_file').with_value('ca') end end context 'with overridden rate limit parameters' do before :each do params.merge!( :http_get_rate => '1000', :http_post_rate => '1000', :http_put_rate => '1000', :http_delete_rate => '1000', :http_mgmt_post_rate => '2000', ) end it 'contains overrided rate limit values' do is_expected.to contain_trove_config('DEFAULT/http_get_rate').with_value('1000') is_expected.to contain_trove_config('DEFAULT/http_post_rate').with_value('1000') is_expected.to contain_trove_config('DEFAULT/http_put_rate').with_value('1000') is_expected.to contain_trove_config('DEFAULT/http_delete_rate').with_value('1000') is_expected.to contain_trove_config('DEFAULT/http_mgmt_post_rate').with_value('2000') end end context 'when using a single RabbitMQ server' do let :pre_condition do "class { 'trove': nova_proxy_admin_pass => '<PASSWORD>', rabbit_host => '10.0.0.1'}" end it 'configures trove-api with RabbitMQ' do is_expected.to contain_trove_config('oslo_messaging_rabbit/rabbit_host').with_value('10.0.0.1') is_expected.to contain_trove_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_config('oslo_messaging_rabbit/amqp_durable_queues').with_value('<SERVICE DEFAULT>') end end context 'when using a single RabbitMQ server with enable ha options' do let :pre_condition do "class { 'trove': nova_proxy_admin_pass => '<PASSWORD>', rabbit_ha_queues => 'true', amqp_durable_queues => 'true', rabbit_host => '10.0.0.1'}" end it 'configures trove-api with RabbitMQ' do is_expected.to contain_trove_config('oslo_messaging_rabbit/rabbit_host').with_value('10.0.0.1') is_expected.to contain_trove_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('true') is_expected.to contain_trove_config('oslo_messaging_rabbit/amqp_durable_queues').with_value('true') end end context 'when using multiple RabbitMQ servers' do let :pre_condition do "class { 'trove': nova_proxy_admin_pass => '<PASSWORD>', rabbit_ha_queues => 'true', rabbit_hosts => ['10.0.0.1','10.0.0.2']}" end it 'configures trove-api with RabbitMQ' do is_expected.to contain_trove_config('oslo_messaging_rabbit/rabbit_hosts').with_value(['10.0.0.1,10.0.0.2']) is_expected.to contain_trove_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('true') end end end context 'with SSL enabled with kombu' do let :pre_condition do "class { 'trove': nova_proxy_admin_pass => '<PASSWORD>', rabbit_use_ssl => true, kombu_ssl_ca_certs => '/path/to/ssl/ca/certs', kombu_ssl_certfile => '/path/to/ssl/cert/file', kombu_ssl_keyfile => '/path/to/ssl/keyfile', kombu_ssl_version => 'TLSv1'}" end it do is_expected.to contain_trove_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('true') is_expected.to contain_trove_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('/path/to/ssl/ca/certs') is_expected.to contain_trove_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('/path/to/ssl/cert/file') is_expected.to contain_trove_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('/path/to/ssl/keyfile') is_expected.to contain_trove_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('TLSv1') end end context 'with SSL enabled without kombu' do let :pre_condition do "class { 'trove': nova_proxy_admin_pass => '<PASSWORD>', rabbit_use_ssl => true}" end it do is_expected.to contain_trove_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('true') is_expected.to contain_trove_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('<SERVICE DEFAULT>') end end context 'with SSL disabled' do let :pre_condition do "class { 'trove': nova_proxy_admin_pass => '<PASSWORD>', rabbit_use_ssl => false}" end it do is_expected.to contain_trove_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('false') is_expected.to contain_trove_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('<SERVICE DEFAULT>') end end context 'with transport_url entries' do let :pre_condition do "class { 'trove': nova_proxy_admin_pass => '<PASSWORD>', default_transport_url => 'rabbit://rabbit_user:password@localhost:5673', notification_transport_url => 'rabbit://rabbit_user:password@localhost:5673' }" end it do is_expected.to contain_trove_config('DEFAULT/transport_url').with_value('rabbit://rabbit_user:password@localhost:5673') is_expected.to contain_trove_config('oslo_messaging_notifications/transport_url').with_value('rabbit://rabbit_user:password@localhost:5673') end end context 'with amqp rpc' do let :pre_condition do "class { 'trove' : nova_proxy_admin_pass => '<PASSWORD>', rpc_backend => 'amqp' }" end it do is_expected.to contain_trove_config('DEFAULT/rpc_backend').with_value('amqp') is_expected.to contain_trove_config('oslo_messaging_amqp/server_request_prefix').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_config('oslo_messaging_amqp/broadcast_prefix').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_config('oslo_messaging_amqp/group_request_prefix').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_config('oslo_messaging_amqp/container_name').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_config('oslo_messaging_amqp/idle_timeout').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_config('oslo_messaging_amqp/trace').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_config('oslo_messaging_amqp/ssl_ca_file').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_config('oslo_messaging_amqp/ssl_cert_file').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_config('oslo_messaging_amqp/ssl_key_file').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_config('oslo_messaging_amqp/ssl_key_password').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_config('oslo_messaging_amqp/allow_insecure_clients').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_config('oslo_messaging_amqp/sasl_mechanisms').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_config('oslo_messaging_amqp/sasl_config_dir').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_config('oslo_messaging_amqp/sasl_config_name').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_config('oslo_messaging_amqp/username').with_value('<SERVICE DEFAULT>') is_expected.to contain_trove_config('oslo_messaging_amqp/password').with_value('<SERVICE DEFAULT>') end end end context 'on Debian platforms' do let :facts do @default_facts.merge({ :osfamily => 'Debian', :processorcount => 8, }) end let :platform_params do { :api_package_name => 'trove-api', :api_service_name => 'trove-api' } end it_configures 'trove-api' end context 'on RedHat platforms' do let :facts do @default_facts.merge({ :osfamily => 'RedHat', :processorcount => 8, }) end let :platform_params do { :api_package_name => 'openstack-trove-api', :api_service_name => 'openstack-trove-api' } end it_configures 'trove-api' end end
hoperays/openstack-ha-puppet-module
cinder/spec/defines/cinder_backend_nfs_spec.rb
<filename>cinder/spec/defines/cinder_backend_nfs_spec.rb require 'spec_helper' describe 'cinder::backend::nfs' do let(:title) {'hippo'} let :params do { :nfs_servers => ['10.10.10.10:/shares', '10.10.10.10:/shares2'], :nfs_mount_attempts => '4', :nfs_mount_options => 'vers=3', :nfs_shares_config => '/etc/cinder/other_shares.conf', :nfs_disk_util => 'du', :nfs_sparsed_volumes => true, :nfs_mount_point_base => '/cinder_mount_point', :nfs_used_ratio => '0.7', :nfs_oversub_ratio => '0.9' } end describe 'nfs volume driver' do it 'configures nfs volume driver' do is_expected.to contain_cinder_config('hippo/volume_backend_name').with( :value => 'hippo') is_expected.to contain_cinder_config('hippo/volume_driver').with_value( 'cinder.volume.drivers.nfs.NfsDriver') is_expected.to contain_cinder_config('hippo/nfs_shares_config').with_value( '/etc/cinder/other_shares.conf') is_expected.to contain_cinder_config('hippo/nfs_mount_attempts').with_value( '4') is_expected.to contain_cinder_config('hippo/nfs_mount_options').with_value( 'vers=3') is_expected.to contain_cinder_config('hippo/nfs_sparsed_volumes').with_value( true) is_expected.to contain_cinder_config('hippo/nfs_mount_point_base').with_value( '/cinder_mount_point') is_expected.to contain_cinder_config('hippo/nfs_disk_util').with_value( 'du') is_expected.to contain_cinder_config('hippo/nfs_used_ratio').with_value( '0.7') is_expected.to contain_cinder_config('hippo/nfs_oversub_ratio').with_value( '0.9') is_expected.to contain_file('/etc/cinder/other_shares.conf').with( :content => "10.10.10.10:/shares\n10.10.10.10:/shares2", :require => 'Anchor[cinder::install::end]', :notify => 'Anchor[cinder::service::begin]' ) end end describe 'nfs backend with additional configuration' do before :each do params.merge!({:extra_options => {'hippo/param1' => {'value' => 'value1'}}}) end it 'configure nfs backend with additional configuration' do is_expected.to contain_cinder_config('hippo/param1').with({ :value => 'value1', }) end end describe 'nfs backend with cinder type' do before :each do params.merge!({:manage_volume_type => true}) end it 'should create type with properties' do should contain_cinder_type('hippo').with(:ensure => :present, :properties => ['volume_backend_name=hippo']) end end end
hoperays/openstack-ha-puppet-module
glance/spec/classes/glance_registry_spec.rb
<reponame>hoperays/openstack-ha-puppet-module require 'spec_helper' describe 'glance::registry' do let :default_params do { :debug => false, :use_stderr => '<SERVICE DEFAULT>', :bind_host => '<SERVICE DEFAULT>', :bind_port => '9191', :workers => facts[:processorcount], :log_file => '/var/log/glance/registry.log', :log_dir => '/var/log/glance', :enabled => true, :manage_service => true, :auth_type => 'keystone', :keystone_password => '<PASSWORD>', :purge_config => false, :sync_db => true, :os_region_name => '<SERVICE DEFAULT>', :ca_file => '<SERVICE DEFAULT>', :cert_file => '<SERVICE DEFAULT>', :key_file => '<SERVICE DEFAULT>', } end shared_examples_for 'glance::registry' do [ {:keystone_password => '<PASSWORD>'}, { :bind_host => '127.0.0.1', :bind_port => '9111', :workers => '5', :enabled => false, :auth_type => 'keystone', :keystone_password => '<PASSWORD>', :sync_db => false, :os_region_name => 'RegionOne2', } ].each do |param_set| describe "when #{param_set == {:keystone_password => '<PASSWORD>'} ? "using default" : "specifying"} class parameters" do let :param_hash do default_params.merge(param_set) end let :params do param_set end it { is_expected.to contain_class 'glance::registry' } it { is_expected.to contain_class 'glance::registry::db' } it { is_expected.to contain_class 'glance::registry::logging' } it { is_expected.to contain_service('glance-registry').with( 'ensure' => (param_hash[:manage_service] && param_hash[:enabled]) ? 'running' : 'stopped', 'enable' => param_hash[:enabled], 'hasstatus' => true, 'hasrestart' => true, 'tag' => 'glance-service', )} it { is_expected.to contain_service('glance-registry').that_subscribes_to('Anchor[glance::service::begin]')} it { is_expected.to contain_service('glance-registry').that_notifies('Anchor[glance::service::end]')} it 'is_expected.to not sync the db if sync_db is set to false' do if !param_hash[:sync_db] is_expected.not_to contain_exec('glance-manage db_sync') end end it 'passes purge to resource' do is_expected.to contain_resources('glance_registry_config').with({ :purge => false }) end it 'is_expected.to configure itself' do [ 'workers', 'bind_port', 'bind_host', ].each do |config| is_expected.to contain_glance_registry_config("DEFAULT/#{config}").with_value(param_hash[config.intern]) end if param_hash[:auth_type] == 'keystone' is_expected.to contain_glance_registry_config("paste_deploy/flavor").with_value('keystone') end end it 'is_expected.to lay down default glance_store registry config' do [ 'os_region_name', ].each do |config| is_expected.to contain_glance_registry_config("glance_store/#{config}").with_value(param_hash[config.intern]) end end it 'is_expected.to lay down default ssl config' do [ 'ca_file', 'cert_file', 'key_file', ].each do |config| is_expected.to contain_glance_registry_config("DEFAULT/#{config}").with_value(param_hash[config.intern]) end end end end describe 'with disabled service managing' do let :params do { :keystone_password => '<PASSWORD>', :manage_service => false, :enabled => false, } end it { is_expected.to contain_service('glance-registry').with( 'ensure' => nil, 'enable' => false, 'hasstatus' => true, 'hasrestart' => true, 'tag' => 'glance-service', )} it { is_expected.to contain_service('glance-registry').that_subscribes_to('Anchor[glance::service::begin]')} it { is_expected.to contain_service('glance-registry').that_notifies('Anchor[glance::service::end]')} end describe 'with overridden pipeline' do # At the time of writing there was only blank and keystone as options # but there is no reason that there can't be more options in the future. let :params do { :keystone_password => '<PASSWORD>', :pipeline => 'validoptionstring', } end it { is_expected.to contain_glance_registry_config('paste_deploy/flavor').with_value('validoptionstring') } end describe 'with blank pipeline' do let :params do { :keystone_password => '<PASSWORD>', :pipeline => '', } end it { is_expected.to contain_glance_registry_config('paste_deploy/flavor').with_ensure('absent') } end [ 'keystone/', 'keystone+', '+keystone', 'keystone+cachemanagement+', '+' ].each do |pipeline| describe "with pipeline incorrect value #{pipeline}" do let :params do { :keystone_password => '<PASSWORD>', :auth_type => 'keystone', :pipeline => pipeline } end it { expect { is_expected.to contain_glance_registry_config('filter:paste_deploy/flavor') }.to\ raise_error(Puppet::Error, /validate_re\(\): .* does not match/) } end end describe 'with ssl options' do let :params do default_params.merge({ :ca_file => '/tmp/ca_file', :cert_file => '/tmp/cert_file', :key_file => '/tmp/key_file' }) end context 'with ssl options' do it { is_expected.to contain_glance_registry_config('DEFAULT/ca_file').with_value('/tmp/ca_file') } it { is_expected.to contain_glance_registry_config('DEFAULT/cert_file').with_value('/tmp/cert_file') } it { is_expected.to contain_glance_registry_config('DEFAULT/key_file').with_value('/tmp/key_file') } end end describe 'with deprecated auth parameters' do let :params do default_params.merge({ :auth_type => 'keystone', :keystone_tenant => 'services', :keystone_user => 'glance', :keystone_password => 'password', :token_cache_time => '1000', :memcached_servers => 'localhost:11211', :signing_dir => '/tmp/keystone', :auth_uri => 'http://127.0.0.1:5000', :identity_uri => 'http://127.0.0.1:35357', }) end it 'deprecated auth parameters' do is_expected.to contain_glance_registry_config('keystone_authtoken/memcached_servers').with_value(params[:memcached_servers]) is_expected.to contain_glance_registry_config('keystone_authtoken/username').with_value(params[:keystone_user]) is_expected.to contain_glance_registry_config('keystone_authtoken/project_name').with_value(params[:keystone_tenant]) is_expected.to contain_glance_registry_config('keystone_authtoken/password').with_value(params[:keystone_password]) is_expected.to contain_glance_registry_config('keystone_authtoken/token_cache_time').with_value(params[:token_cache_time]) is_expected.to contain_glance_registry_config('keystone_authtoken/signing_dir').with_value(params[:signing_dir]) is_expected.to contain_glance_registry_config('keystone_authtoken/auth_uri').with_value(params[:auth_uri]) is_expected.to contain_glance_registry_config('keystone_authtoken/auth_url').with_value(params[:identity_uri]) end end end shared_examples_for 'glance::registry Debian' do # We only test this on Debian platforms, since on RedHat there isn't a # separate package for glance registry. ['present', 'latest'].each do |package_ensure| context "with package_ensure '#{package_ensure}'" do let(:params) { default_params.merge({ :package_ensure => package_ensure }) } it { is_expected.to contain_package('glance-registry').with( :ensure => package_ensure, :tag => ['openstack', 'glance-package'] )} end end end shared_examples_for 'glance::registry RedHat' do let(:params) { default_params } it { is_expected.to contain_package('openstack-glance') } end on_supported_os({ :supported_os => OSDefaults.get_supported_os }).each do |os,facts| context "on #{os}" do let (:facts) do facts.merge!(OSDefaults.get_facts()) end it_configures 'glance::registry' it_configures "glance::registry #{facts[:osfamily]}" end end describe 'on unknown platforms' do let :facts do OSDefaults.get_facts({ :osfamily => 'unknown' }) end let(:params) { default_params } it_raises 'a Puppet::Error', /module glance only support osfamily RedHat and Debian/ end end
hoperays/openstack-ha-puppet-module
heat/spec/classes/heat_init_spec.rb
<reponame>hoperays/openstack-ha-puppet-module require 'spec_helper' describe 'heat' do let :params do { :package_ensure => 'present', :debug => 'False', :use_stderr => 'True', :log_dir => '/var/log/heat', :rabbit_host => '<SERVICE DEFAULT>', :rabbit_port => 5672, :rabbit_userid => '<SERVICE DEFAULT>', :rabbit_password => '<SERVICE DEFAULT>', :rabbit_virtual_host => '<SERVICE DEFAULT>', :database_connection => 'mysql+pymysql://user@host/database', :database_idle_timeout => 3600, :keystone_ec2_uri => 'http://127.0.0.1:5000/v2.0/ec2tokens', :flavor => 'keystone', :keystone_password => '<PASSWORD>', :heat_clients_url => '<SERVICE DEFAULT>', :purge_config => false, :yaql_limit_iterators => 400, :yaql_memory_quota => 20000, } end shared_examples_for 'heat' do context 'with rabbit_host parameter' do it_configures 'a heat base installation' it_configures 'rabbit without HA support (with backward compatibility)' end context 'with rabbit_hosts parameter' do context 'with one server' do before { params.merge!( :rabbit_hosts => ['127.0.0.1:5672'] ) } it_configures 'a heat base installation' it_configures 'rabbit without HA support (without backward compatibility)' end context 'with multiple servers' do before { params.merge!( :rabbit_hosts => ['rabbit1:5672', 'rabbit2:5672'], :amqp_durable_queues => true) } it_configures 'a heat base installation' it_configures 'rabbit with HA support' end end context 'with rabbit heartbeat configured' do before { params.merge!( :rabbit_heartbeat_timeout_threshold => '60', :rabbit_heartbeat_rate => '10' ) } it_configures 'a heat base installation' it_configures 'rabbit with heartbeat configured' end it_configures 'with SSL enabled with kombu' it_configures 'with SSL enabled without kombu' it_configures 'with SSL disabled' it_configures 'with SSL wrongly configured' it_configures 'with enable_stack_adopt and enable_stack_abandon set' it_configures 'with notification_driver set to a string' context 'with amqp rpc_backend value' do it_configures 'amqp support' end end shared_examples_for 'a heat base installation' do it { is_expected.to contain_class('heat::logging') } it { is_expected.to contain_class('heat::params') } it 'installs heat common package' do is_expected.to contain_package('heat-common').with( :ensure => 'present', :name => platform_params[:common_package_name], :tag => ['openstack', 'heat-package'], ) end it 'passes purge to resource' do is_expected.to contain_resources('heat_config').with({ :purge => false }) end it 'has db_sync enabled' do is_expected.to contain_class('heat::db::sync') end it 'configures host' do is_expected.to contain_heat_config('DEFAULT/host').with_value('<SERVICE DEFAULT>') end it 'configures max_template_size' do is_expected.to contain_heat_config('DEFAULT/max_template_size').with_value('<SERVICE DEFAULT>') end it 'configures max_json_body_size' do is_expected.to contain_heat_config('DEFAULT/max_json_body_size').with_value('<SERVICE DEFAULT>') end it 'configures project_domain_*' do is_expected.to contain_heat_config('trustee/project_domain_id').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('trustee/project_domain_name').with_value( 'Default' ) end it 'configures user_domain_*' do is_expected.to contain_heat_config('trustee/user_domain_id').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('trustee/user_domain_name').with_value( 'Default' ) end it 'configures auth_plugin' do is_expected.to contain_heat_config('trustee/auth_plugin').with_value( 'password' ) end it 'configures auth_url' do is_expected.to contain_heat_config('trustee/auth_url').with_value( 'http://127.0.0.1:35357/' ) end it 'configures username' do is_expected.to contain_heat_config('trustee/username').with_value( 'heat' ) end it 'configures ' do is_expected.to contain_heat_config('trustee/password').with_secret( true ) end it 'configures auth_uri for clients_keystone' do is_expected.to contain_heat_config('clients_keystone/auth_uri').with_value( 'http://127.0.0.1:35357/' ) end it 'configures keystone_ec2_uri' do is_expected.to contain_heat_config('ec2authtoken/auth_uri').with_value( params[:keystone_ec2_uri] ) end it 'configures yaql_limit_iterators' do is_expected.to contain_heat_config('yaql/limit_iterators').with_value( params[:yaql_limit_iterators] ) end it 'configures yaql_memory_quota' do is_expected.to contain_heat_config('yaql/memory_quota').with_value( params[:yaql_memory_quota] ) end it { is_expected.to contain_heat_config('paste_deploy/flavor').with_value('keystone') } it 'configures notification_driver' do is_expected.to contain_heat_config('oslo_messaging_notifications/transport_url').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_notifications/driver').with_value('<SERVICE DEFAULT>') end it 'sets default value for http_proxy_to_wsgi middleware' do is_expected.to contain_heat_config('oslo_middleware/enable_proxy_headers_parsing').with_value('<SERVICE DEFAULT>') end it 'sets clients_heat url' do is_expected.to contain_heat_config('clients_heat/url').with_value('<SERVICE DEFAULT>') end it_configures "with default auth method" end shared_examples_for 'rabbit without HA support (with backward compatibility)' do it 'configures rabbit' do is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_userid').with_value( params[:rabbit_userid] ) is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_password').with_value( params[:rabbit_password] ) is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_password').with_secret( true ) is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_virtual_host').with_value( params[:rabbit_virtual_host] ) is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_reconnect_delay').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_failover_strategy').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_compression').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/heartbeat_timeout_threshold').with_value('0') is_expected.to contain_heat_config('oslo_messaging_rabbit/heartbeat_rate').with_value('<SERVICE DEFAULT>') end it { is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_host').with_value( params[:rabbit_host] ) } it { is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_port').with_value( params[:rabbit_port] ) } it { is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_hosts').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_heat_config('DEFAULT/rpc_response_timeout').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_heat_config('oslo_messaging_rabbit/amqp_durable_queues').with_value('<SERVICE DEFAULT>') } end shared_examples_for 'rabbit without HA support (without backward compatibility)' do it 'configures rabbit' do is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_userid').with_value( params[:rabbit_userid] ) is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_password').with_secret( true ) is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_password').with_value( params[:rabbit_password] ) is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_virtual_host').with_value( params[:rabbit_virtual_host] ) is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_reconnect_delay').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_failover_strategy').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_compression').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/heartbeat_timeout_threshold').with_value('0') is_expected.to contain_heat_config('oslo_messaging_rabbit/heartbeat_rate').with_value('<SERVICE DEFAULT>') end it { is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_host').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_port').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_hosts').with_value( params[:rabbit_hosts].join(',') ) } it { is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_heat_config('oslo_messaging_rabbit/amqp_durable_queues').with_value('<SERVICE DEFAULT>') } end shared_examples_for 'rabbit with HA support' do it 'configures rabbit' do is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_userid').with_value( params[:rabbit_userid] ) is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_password').with_value( params[:rabbit_password] ) is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_password').with_secret( true ) is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_virtual_host').with_value( params[:rabbit_virtual_host] ) is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_reconnect_delay').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_failover_strategy').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_compression').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/heartbeat_timeout_threshold').with_value('0') is_expected.to contain_heat_config('oslo_messaging_rabbit/heartbeat_rate').with_value('<SERVICE DEFAULT>') end it { is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_host').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_port').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_hosts').with_value( params[:rabbit_hosts].join(',') ) } it { is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('true') } it { is_expected.to contain_heat_config('oslo_messaging_rabbit/amqp_durable_queues').with_value(true) } end shared_examples_for 'single rabbit_host with ha queues' do let :params do req_params.merge({'rabbit_ha_queues' => true}) end it 'should contain rabbit_ha_queues' do is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('true') end end shared_examples_for 'rabbit with heartbeat configured' do it 'configures rabbit' do is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_userid').with_value( params[:rabbit_userid] ) is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_password').with_value( params[:rabbit_password] ) is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_password').with_secret( true ) is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_virtual_host').with_value( params[:rabbit_virtual_host] ) is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_reconnect_delay').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_failover_strategy').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_compression').with_value('<SERVICE DEFAULT>') end it { is_expected.to contain_heat_config('oslo_messaging_rabbit/heartbeat_timeout_threshold').with_value('60') } it { is_expected.to contain_heat_config('oslo_messaging_rabbit/heartbeat_rate').with_value('10') } end shared_examples_for 'with SSL enabled with kombu' do before do params.merge!( :rabbit_use_ssl => true, :kombu_ssl_ca_certs => '/path/to/ssl/ca/certs', :kombu_ssl_certfile => '/path/to/ssl/cert/file', :kombu_ssl_keyfile => '/path/to/ssl/keyfile', :kombu_ssl_version => 'TLSv1' ) end it do is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('true') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('/path/to/ssl/ca/certs') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('/path/to/ssl/cert/file') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('/path/to/ssl/keyfile') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('TLSv1') end end shared_examples_for 'with SSL enabled without kombu' do before do params.merge!( :rabbit_use_ssl => true ) end it do is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('true') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('<SERVICE DEFAULT>') end end shared_examples_for 'with SSL disabled' do before do params.merge!( :rabbit_use_ssl => false, ) end it do is_expected.to contain_heat_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('false') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('<SERVICE DEFAULT>') is_expected.to contain_heat_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('<SERVICE DEFAULT>') end end shared_examples_for 'with SSL wrongly configured' do before do params.merge!( :rabbit_use_ssl => false ) end context 'without required parameters' do context 'with rabbit_use_ssl => false and kombu_ssl_ca_certs parameter' do before { params.merge!(:kombu_ssl_ca_certs => '/path/to/ssl/ca/certs')} it_raises 'a Puppet::Error', /The kombu_ssl_ca_certs parameter requires rabbit_use_ssl to be set to true/ end context 'with rabbit_use_ssl => false and kombu_ssl_certfile parameter' do before { params.merge!(:kombu_ssl_certfile => '/path/to/ssl/cert/file')} it_raises 'a Puppet::Error', /The kombu_ssl_certfile parameter requires rabbit_use_ssl to be set to true/ end context 'with rabbit_use_ssl => false and kombu_ssl_keyfile parameter' do before { params.merge!(:kombu_ssl_keyfile => '/path/to/ssl/keyfile')} it_raises 'a Puppet::Error', /The kombu_ssl_keyfile parameter requires rabbit_use_ssl to be set to true/ end end end shared_examples_for 'with ec2authtoken auth uri set' do before do params.merge!( :keystone_ec2_uri => 'http://1.2.3.4:35357/v2.0/ec2tokens' ) end it do is_expected.to contain_heat_config('ec2authtoken/auth_uri').with_value('http://1.2.3.4:35357/v2.0/ec2tokens') end end shared_examples_for 'with region_name set' do before do params.merge!( :region_name => "East", ) end it 'has region_name set when specified' do is_expected.to contain_heat_config('DEFAULT/region_name_for_services').with_value('East') end end shared_examples_for 'without region_name set' do it 'doesnt have region_name set by default' do is_expected.to contain_heat_config('DEFAULT/region_name_for_services').with_value('<SERVICE DEFAULT>') end end shared_examples_for "with default auth method" do it 'configures auth_uri, identity_uri, admin_tenant_name, admin_user, admin_password' do is_expected.to contain_heat_config('keystone_authtoken/auth_uri').with_value("http://127.0.0.1:5000/") is_expected.to contain_heat_config('keystone_authtoken/auth_url').with_value("http://127.0.0.1:35357/") is_expected.to contain_heat_config('keystone_authtoken/project_name').with_value("services") is_expected.to contain_heat_config('keystone_authtoken/username').with_value("heat") is_expected.to contain_heat_config('keystone_authtoken/password').with_secret( true ) end end shared_examples_for "with custom keystone project_domain_* and user_domain_*" do before do params.merge!({ :keystone_project_domain_id => 'domain1', :keystone_user_domain_id => 'domain1', :keystone_project_domain_name => 'domain1', :keystone_user_domain_name => 'domain1', }) end it 'configures project_domain_* and user_domain_*' do is_expected.to contain_heat_config('trustee/project_domain_name').with_value("domain1"); is_expected.to contain_heat_config('trustee/user_domain_name').with_value("domain1"); is_expected.to contain_heat_config('trustee/project_domain_id').with_value("domain1"); is_expected.to contain_heat_config('trustee/user_domain_id').with_value("domain1"); end end shared_examples_for "with enable_stack_adopt and enable_stack_abandon set" do before do params.merge!({ :enable_stack_adopt => true, :enable_stack_abandon => true, }) end it 'sets enable_stack_adopt and enable_stack_abandon' do is_expected.to contain_heat_config('DEFAULT/enable_stack_adopt').with_value(true); is_expected.to contain_heat_config('DEFAULT/enable_stack_abandon').with_value(true); end end shared_examples_for 'with notification_driver set to a string' do before do params.merge!( :notification_transport_url => 'rabbit://rabbit_user:password@localhost:5673', :notification_driver => 'bar.foo.rpc_notifier', ) end it 'has notification_driver set when specified' do is_expected.to contain_heat_config('oslo_messaging_notifications/transport_url').with_value('rabbit://rabbit_user:password@localhost:5673') is_expected.to contain_heat_config('oslo_messaging_notifications/driver').with_value('bar.foo.rpc_notifier') end end shared_examples_for 'amqp support' do context 'with default parameters' do before { params.merge!( :rpc_backend => 'amqp' ) } it { is_expected.to contain_heat_config('DEFAULT/rpc_backend').with_value('amqp') } it { is_expected.to contain_heat_config('oslo_messaging_amqp/server_request_prefix').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_heat_config('oslo_messaging_amqp/broadcast_prefix').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_heat_config('oslo_messaging_amqp/group_request_prefix').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_heat_config('oslo_messaging_amqp/container_name').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_heat_config('oslo_messaging_amqp/idle_timeout').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_heat_config('oslo_messaging_amqp/trace').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_heat_config('oslo_messaging_amqp/ssl_ca_file').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_heat_config('oslo_messaging_amqp/ssl_cert_file').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_heat_config('oslo_messaging_amqp/ssl_key_file').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_heat_config('oslo_messaging_amqp/ssl_key_password').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_heat_config('oslo_messaging_amqp/allow_insecure_clients').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_heat_config('oslo_messaging_amqp/sasl_mechanisms').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_heat_config('oslo_messaging_amqp/sasl_config_dir').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_heat_config('oslo_messaging_amqp/sasl_config_name').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_heat_config('oslo_messaging_amqp/username').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_heat_config('oslo_messaging_amqp/password').with_value('<SERVICE DEFAULT>') } end context 'with overriden amqp parameters' do before { params.merge!( :rpc_backend => 'amqp', :amqp_idle_timeout => '60', :amqp_trace => true, :amqp_ssl_ca_file => '/path/to/ca.cert', :amqp_ssl_cert_file => '/path/to/certfile', :amqp_ssl_key_file => '/path/to/key', :amqp_username => 'amqp_user', :amqp_password => 'password', ) } it { is_expected.to contain_heat_config('DEFAULT/rpc_backend').with_value('amqp') } it { is_expected.to contain_heat_config('oslo_messaging_amqp/server_request_prefix').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_heat_config('oslo_messaging_amqp/broadcast_prefix').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_heat_config('oslo_messaging_amqp/group_request_prefix').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_heat_config('oslo_messaging_amqp/container_name').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_heat_config('oslo_messaging_amqp/idle_timeout').with_value('60') } it { is_expected.to contain_heat_config('oslo_messaging_amqp/trace').with_value('true') } it { is_expected.to contain_heat_config('oslo_messaging_amqp/ssl_ca_file').with_value('/path/to/ca.cert') } it { is_expected.to contain_heat_config('oslo_messaging_amqp/ssl_cert_file').with_value('/path/to/certfile') } it { is_expected.to contain_heat_config('oslo_messaging_amqp/ssl_key_file').with_value('/path/to/key') } it { is_expected.to contain_heat_config('oslo_messaging_amqp/allow_insecure_clients').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_heat_config('oslo_messaging_amqp/sasl_mechanisms').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_heat_config('oslo_messaging_amqp/sasl_config_dir').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_heat_config('oslo_messaging_amqp/sasl_config_name').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_heat_config('oslo_messaging_amqp/username').with_value('amqp_user') } it { is_expected.to contain_heat_config('oslo_messaging_amqp/password').with_value('password') } end end context 'on Debian platforms' do let :facts do @default_facts.merge({ :osfamily => 'Debian', }) end let :platform_params do { :common_package_name => 'heat-common' } end it_configures 'heat' end context 'on RedHat platforms' do let :facts do @default_facts.merge({ :osfamily => 'RedHat', }) end let :platform_params do { :common_package_name => 'openstack-heat-common' } end it_configures 'heat' end end
hoperays/openstack-ha-puppet-module
swift/spec/classes/swift_proxy_cache_spec.rb
require 'spec_helper' describe 'swift::proxy::cache' do let :facts do { :operatingsystem => 'Ubuntu', :osfamily => 'Debian', :processorcount => 1 } end describe 'with defaults' do let :pre_condition do 'class { "memcached": max_memory => 1 }' end it 'should have the required classes' do is_expected.to contain_class('swift::deps') is_expected.to contain_class('swift::proxy::cache') end it 'should properly configure the swift_cache fragment' do is_expected.to contain_concat_fragment('swift_cache').with_content(/\[filter:cache\]\nuse = egg:swift#memcache/) is_expected.to contain_concat_fragment('swift_cache').with_content(/memcache_servers = 127\.0\.0\.1:11211/) end end describe 'without memcached being included' do it 'should raise an error' do expect { catalogue }.to raise_error(Puppet::Error) end end describe 'with overridden memcache server' do let :params do {:memcache_servers => '10.0.0.1:1'} end it 'should properly configure the swift_cache fragment' do is_expected.to contain_concat_fragment('swift_cache').with_content(/\[filter:cache\]\nuse = egg:swift#memcache/) is_expected.to contain_concat_fragment('swift_cache').with_content(/memcache_servers = 10\.0\.0\.1:1/) end end describe 'with overridden memcache server array' do let :params do {:memcache_servers => ['10.0.0.1:1', '10.0.0.2:2']} end it 'should properly configure the swift_cache fragment' do is_expected.to contain_concat_fragment('swift_cache').with_content(/\[filter:cache\]\nuse = egg:swift#memcache/) is_expected.to contain_concat_fragment('swift_cache').with_content(/memcache_servers = 10\.0\.0\.1:1,10\.0\.0\.2:2/) end end end
hoperays/openstack-ha-puppet-module
gnocchi/spec/classes/gnocchi_storage_spec.rb
require 'spec_helper' describe 'gnocchi::storage' do let :params do { :package_ensure => 'latest' } end shared_examples_for 'gnocchi-storage' do it { is_expected.to contain_class('gnocchi::params') } it 'installs gnocchi-carbonara package' do is_expected.to contain_package('gnocchi-carbonara').with( :ensure => 'latest', :name => platform_params[:carbonara_package_name], :tag => ['openstack', 'gnocchi-package'], ) end context 'with coordination' do before do params.merge!({ :coordination_url => 'redis://localhost:6379' }) end it 'configures backend_url' do is_expected.to contain_gnocchi_config('storage/coordination_url').with_value('redis://localhost:6379') end end end on_supported_os({ :supported_os => OSDefaults.get_supported_os }).each do |os,facts| context "on #{os}" do let (:facts) do facts.merge!(OSDefaults.get_facts()) end let(:platform_params) do case facts[:osfamily] when 'Debian' { :carbonara_package_name => 'gnocchi-carbonara' } when 'RedHat' { :carbonara_package_name => 'openstack-gnocchi-carbonara' } end end it_behaves_like 'gnocchi-storage' end end end
hoperays/openstack-ha-puppet-module
nova/lib/puppet/provider/nova_flavor/openstack.rb
<reponame>hoperays/openstack-ha-puppet-module require File.join(File.dirname(__FILE__), '..','..','..', 'puppet/provider/nova') Puppet::Type.type(:nova_flavor).provide( :openstack, :parent => Puppet::Provider::Nova ) do desc <<-EOT Manage Nova flavor EOT @credentials = Puppet::Provider::Openstack::CredentialsV3.new def initialize(value={}) super(value) @property_flush = {} end def create opts = [@resource[:name]] opts << (@resource[:is_public] == :true ? '--public' : '--private') (opts << '--id' << @resource[:id]) if @resource[:id] (opts << '--ram' << @resource[:ram]) if @resource[:ram] (opts << '--disk' << @resource[:disk]) if @resource[:disk] (opts << '--ephemeral' << @resource[:ephemeral]) if @resource[:ephemeral] (opts << '--vcpus' << @resource[:vcpus]) if @resource[:vcpus] (opts << '--swap' << @resource[:swap]) if @resource[:swap] (opts << '--rxtx-factor' << @resource[:rxtx_factor]) if @resource[:rxtx_factor] @property_hash = self.class.request('flavor', 'create', opts) if @resource[:properties] prop_opts = [@resource[:name]] prop_opts << props_to_s(@resource[:properties]) self.class.request('flavor', 'set', prop_opts) end @property_hash[:ensure] = :present end def exists? @property_hash[:ensure] == :present end def destroy self.class.request('flavor', 'delete', @property_hash[:id]) end mk_resource_methods def is_public=(value) fail('is_public is read only') end def id=(value) fail('id is read only') end def ram=(value) fail('ram is read only') end def disk=(value) fail('disk is read only') end def vcpus=(value) fail('vcpus is read only') end def swap=(value) fail('swap is read only') end def rxtx_factor=(value) fail('rxtx_factor is read only') end def properties=(value) @property_flush[:properties] = value end def self.instances request('flavor', 'list', ['--long', '--all']).collect do |attrs| properties = Hash[attrs[:properties].scan(/(\S+)='([^']*)'/)] rescue nil new( :ensure => :present, :name => attrs[:name], :id => attrs[:id], :ram => attrs[:ram], :disk => attrs[:disk], :ephemeral => attrs[:ephemeral], :vcpus => attrs[:vcpus], :is_public => attrs[:is_public].downcase.chomp == 'true'? true : false, :swap => attrs[:swap], :rxtx_factor => attrs[:rxtx_factor], :properties => properties ) end end def self.prefetch(resources) flavors = instances resources.keys.each do |name| if provider = flavors.find{ |flavor| flavor.name == name } resources[name].provider = provider end end end def flush unless @property_flush.empty? opts = [@resource[:name]] opts << props_to_s(@property_flush[:properties]) self.class.request('flavor', 'set', opts) @property_flush.clear end end private def props_to_s(props) props.flat_map{ |k, v| ['--property', "#{k}=#{v}"] } end end
hoperays/openstack-ha-puppet-module
aodh/spec/classes/aodh_api_spec.rb
<filename>aodh/spec/classes/aodh_api_spec.rb require 'spec_helper' describe 'aodh::api' do let :pre_condition do "class { 'aodh': } include ::aodh::db" end let :params do { :enabled => true, :manage_service => true, :keystone_password => '<PASSWORD>', :package_ensure => 'latest', :port => '8042', :host => '0.0.0.0', } end shared_examples_for 'aodh-api' do it { is_expected.to contain_class('aodh::params') } it { is_expected.to contain_class('aodh::policy') } it 'installs aodh-api package' do is_expected.to contain_package('aodh-api').with( :ensure => 'latest', :name => platform_params[:api_package_name], :tag => ['openstack', 'aodh-package'], ) end it 'configures api' do is_expected.to contain_aodh_config('api/host').with_value( params[:host] ) is_expected.to contain_aodh_config('api/port').with_value( params[:port] ) is_expected.to contain_aodh_config('oslo_middleware/enable_proxy_headers_parsing').with_value('<SERVICE DEFAULT>') end [{:enabled => true}, {:enabled => false}].each do |param_hash| context "when service should be #{param_hash[:enabled] ? 'enabled' : 'disabled'}" do before do params.merge!(param_hash) end it 'configures aodh-api service' do is_expected.to contain_service('aodh-api').with( :ensure => (params[:manage_service] && params[:enabled]) ? 'running' : 'stopped', :name => platform_params[:api_service_name], :enable => params[:enabled], :hasstatus => true, :hasrestart => true, :require => 'Class[Aodh::Db]', :tag => 'aodh-service', ) end end end context 'with sync_db set to true' do before do params.merge!( :sync_db => true) end it { is_expected.to contain_class('aodh::db::sync') } end context 'with enable_proxy_headers_parsing' do before do params.merge!({:enable_proxy_headers_parsing => true }) end it { is_expected.to contain_aodh_config('oslo_middleware/enable_proxy_headers_parsing').with_value(true) } end context 'with deprecated parameters' do before do params.merge!({ :keystone_user => 'dummy', :keystone_password => '<PASSWORD>', :keystone_tenant => 'tenant', :keystone_auth_uri => 'https://10.0.0.1:5000/deprecated', :keystone_identity_uri => 'https://10.0.0.1:35357/deprecated', :keystone_auth_url => 'https://10.0.0.1:35357/deprecated', :memcached_servers => ['memcached01:11211','memcached02:11211'], :keystone_project_domain_name => 'domainX', :keystone_user_domain_name => 'domainX', :keystone_auth_type => 'auth', }) end it 'configures keystone_authtoken middleware' do is_expected.to contain_aodh_config( 'keystone_authtoken/auth_uri').with_value('https://10.0.0.1:5000/deprecated') is_expected.to contain_aodh_config( 'keystone_authtoken/username').with_value(params[:keystone_user]) is_expected.to contain_aodh_config( 'keystone_authtoken/password').with_value(params[:keystone_password]).with_secret(true) is_expected.to contain_aodh_config( 'keystone_authtoken/auth_url').with_value(params[:keystone_identity_uri]) is_expected.to contain_aodh_config( 'keystone_authtoken/project_name').with_value(params[:keystone_tenant]) is_expected.to contain_aodh_config( 'keystone_authtoken/user_domain_name').with_value(params[:keystone_user_domain_name]) is_expected.to contain_aodh_config( 'keystone_authtoken/project_domain_name').with_value(params[:keystone_project_domain_name]) is_expected.to contain_aodh_config( 'keystone_authtoken/auth_type').with_value(params[:keystone_auth_type]) is_expected.to contain_aodh_config( 'keystone_authtoken/memcached_servers').with_value('memcached01:11211,memcached02:11211') end end context 'with disabled service managing' do before do params.merge!({ :manage_service => false, :enabled => false }) end it 'configures aodh-api service' do is_expected.to contain_service('aodh-api').with( :ensure => nil, :name => platform_params[:api_service_name], :enable => false, :hasstatus => true, :hasrestart => true, :tag => 'aodh-service', ) end end context 'when running aodh-api in wsgi' do before do params.merge!({ :service_name => 'httpd' }) end let :pre_condition do "include ::apache include ::aodh::db class { 'aodh': }" end it 'configures aodh-api service with Apache' do is_expected.to contain_service('aodh-api').with( :ensure => 'stopped', :name => platform_params[:api_service_name], :enable => false, :tag => 'aodh-service', ) end end context 'when service_name is not valid' do before do params.merge!({ :service_name => 'foobar' }) end let :pre_condition do "include ::apache include ::aodh::db class { 'aodh': }" end it_raises 'a Puppet::Error', /Invalid service_name/ end context "with deprecated keystone options" do before do params.merge!({ :keystone_user => 'user', :keystone_password => '<PASSWORD>', :keystone_tenant => 'tenant', :keystone_project_domain_name => 'domainx', :keystone_user_domain_name => 'domainx', :keystone_auth_type => 'password', :keystone_auth_uri => 'https://foo.bar:5000', :keystone_auth_url => 'https://foo.bar:35357/deprecated', :keystone_identity_uri => 'https://foo.bar:35357/deprecated', }) end it 'configures auth_uri but deprecates old auth settings' do is_expected.to contain_aodh_config('keystone_authtoken/auth_uri').with_value("https://foo.bar:5000"); is_expected.to contain_aodh_config('keystone_authtoken/auth_url').with_value("https://foo.bar:35357/deprecated"); is_expected.to contain_aodh_config('keystone_authtoken/username').with_value('user') is_expected.to contain_aodh_config('keystone_authtoken/password').with_value('<PASSWORD>') is_expected.to contain_aodh_config('keystone_authtoken/project_name').with_value('tenant') is_expected.to contain_aodh_config('keystone_authtoken/user_domain_name').with_value('domainx') is_expected.to contain_aodh_config('keystone_authtoken/project_domain_name').with_value('domainx') is_expected.to contain_aodh_config('keystone_authtoken/auth_type').with_value('password') end end end on_supported_os({ :supported_os => OSDefaults.get_supported_os }).each do |os,facts| context "on #{os}" do let (:facts) do facts.merge!(OSDefaults.get_facts({ :fqdn => 'some.host.tld', :processorcount => 2, :concat_basedir => '/var/lib/puppet/concat' })) end let(:platform_params) do case facts[:osfamily] when 'Debian' { :api_package_name => 'aodh-api', :api_service_name => 'aodh-api' } when 'RedHat' { :api_package_name => 'openstack-aodh-api', :api_service_name => 'openstack-aodh-api' } end end it_configures 'aodh-api' end end end
hoperays/openstack-ha-puppet-module
swift/spec/classes/swift_proxy_ceilometer_spec.rb
require 'spec_helper' describe 'swift::proxy::ceilometer' do let :facts do OSDefaults.get_facts({ :osfamily => 'Debian' }) end let :pre_condition do 'concat { "/etc/swift/proxy-server.conf": } class { "swift": swift_hash_path_suffix => "dummy" }' end describe "when using default parameters" do it { is_expected.to contain_concat_fragment('swift_ceilometer').with_content(/[filter:ceilometer]/) } it { is_expected.to contain_concat_fragment('swift_ceilometer').with_content(/paste.filter_factory = ceilometermiddleware.swift:filter_factory/) } it { is_expected.to contain_concat_fragment('swift_ceilometer').with_content(/url = rabbit:\/\/guest:guest@127.0.0.1:5672\//) } it { is_expected.to contain_user('swift').with_groups('ceilometer') } it { is_expected.to contain_file('/var/log/ceilometer/swift-proxy-server.log').with(:owner => 'swift', :group => 'swift', :mode => '0664') } end describe "when overriding default parameters" do let :params do { :group => 'www-data', :rabbit_user => 'user_1', :rabbit_password => '<PASSWORD>', :rabbit_host => '1.1.1.1', :rabbit_port => '5673', :rabbit_virtual_host => 'rabbit', :driver => 'messagingv2', :topic => 'notifications', :control_exchange => 'swift', :nonblocking_notify => true, } end context 'with single rabbit host' do it { is_expected.to contain_user('swift').with_groups('www-data') } it { is_expected.to contain_concat_fragment('swift_ceilometer').with_content(/[filter:ceilometer]/) } it { is_expected.to contain_concat_fragment('swift_ceilometer').with_content(/paste.filter_factory = ceilometermiddleware.swift:filter_factory/) } it { is_expected.to contain_concat_fragment('swift_ceilometer').with_content(/url = rabbit:\/\/user_1:user_1_passw@1.1.1.1:5673\/rabbit/) } it { is_expected.to contain_concat_fragment('swift_ceilometer').with_content(/driver = messagingv2/) } it { is_expected.to contain_concat_fragment('swift_ceilometer').with_content(/topic = notifications/) } it { is_expected.to contain_concat_fragment('swift_ceilometer').with_content(/control_exchange = swift/) } it { is_expected.to contain_concat_fragment('swift_ceilometer').with_content(/nonblocking_notify = true/) } end context 'with multiple rabbit hosts' do before do params.merge!({ :rabbit_hosts => ['127.0.0.1:5672', '127.0.0.2:5672'] }) end it { is_expected.to contain_user('swift').with_groups('www-data') } it { is_expected.to contain_concat_fragment('swift_ceilometer').with_content(/[filter:ceilometer]/) } it { is_expected.to contain_concat_fragment('swift_ceilometer').with_content(/paste.filter_factory = ceilometermiddleware.swift:filter_factory/) } it { is_expected.to contain_concat_fragment('swift_ceilometer').with_content(/url = rabbit:\/\/user_1:user_1_passw@127.0.0.1:5672,user_1:user_1_passw@127.0.0.2:5672\/rabbit/) } it { is_expected.to contain_concat_fragment('swift_ceilometer').with_content(/driver = messagingv2/) } it { is_expected.to contain_concat_fragment('swift_ceilometer').with_content(/topic = notifications/) } it { is_expected.to contain_concat_fragment('swift_ceilometer').with_content(/control_exchange = swift/) } it { is_expected.to contain_concat_fragment('swift_ceilometer').with_content(/nonblocking_notify = true/) } end end end
hoperays/openstack-ha-puppet-module
cinder/spec/classes/cinder_volume_hp3par_iscsi_spec.rb
<reponame>hoperays/openstack-ha-puppet-module require 'spec_helper' describe 'cinder::volume::hp3par_iscsi' do let :req_params do { :hp3par_api_url => 'https://192.168.3.11:8080/api/v1', :hp3par_username => '3paradm', :hp3par_password => 'password', :hp3par_iscsi_ips => '192.168.127.12', :san_ip => '192.168.3.11', :san_login => '3paradm', :san_password => 'password', } end let :params do req_params end describe 'hp3par_iscsi volume driver' do it 'configure hp3par_iscsi volume driver' do is_expected.to contain_cinder_config('DEFAULT/volume_driver').with_value('cinder.volume.drivers.hpe.hpe_3par_iscsi.HPE3PARISCSIDriver') is_expected.to contain_cinder_config('DEFAULT/hpe3par_api_url').with_value('https://192.168.3.11:8080/api/v1') is_expected.to contain_cinder_config('DEFAULT/hpe3par_username').with_value('3paradm') is_expected.to contain_cinder_config('DEFAULT/hpe3par_password').with_value('password') is_expected.to contain_cinder_config('DEFAULT/hpe3par_iscsi_ips').with_value('192.168.127.12') is_expected.to contain_cinder_config('DEFAULT/san_ip').with_value('192.168.3.11') is_expected.to contain_cinder_config('DEFAULT/san_login').with_value('3paradm') is_expected.to contain_cinder_config('DEFAULT/san_password').with_value('password') end end describe 'hp3par_iscsi volume driver with additional configuration' do before :each do params.merge!({:extra_options => {'hpe3par_iscsi_backend/param1' => {'value' => 'value1'}}}) end it 'configure hp3par_iscsi volume with additional configuration' do is_expected.to contain_cinder__backend__hpe3par_iscsi('DEFAULT').with({ :extra_options => {'hpe3par_iscsi_backend/param1' => {'value' => 'value1'}} }) end end end
hoperays/openstack-ha-puppet-module
pacemaker/lib/pacemaker/xml/debug.rb
<reponame>hoperays/openstack-ha-puppet-module module Pacemaker # debug related functions # "cluster_debug_report" the main debug text generation function # "safe_methods" are used to debug providers without making any actual changes to the system module Debug # check if debug is enabled either in the pacemaker options # or the resource has the 'debug' parameter and it's enabled # @return [TrueClass,FalseClass] def debug_mode_enabled? return true if pacemaker_options[:debug_enabled] return true if @resource && @resource.parameters.keys.include?(:debug) && @resource[:debug] false end # Call a Puppet shell command method with wrappers # If debug is enabled, show what would be executed and don't actually # run the command. Used to debug commands that should modify the system # and don't return any data. Should never be use with commands that retrieve data. # If a command have failed, show command and the arguments and the raise the exception. # The actual commands methods should be created by the provider's "commands" helper. # @param cmd [Symbol, String] command name # @param args [Array] command arguments # @return [String,NilClass] def safe_method(cmd, *args) cmd = cmd.to_sym unless cmd.is_a? Symbol command_line = ([cmd.to_s] + args).join ' ' if debug_mode_enabled? debug "Exec: #{command_line}" return end begin send cmd, *args rescue StandardError => exception debug "Command execution have failed: #{command_line}" raise exception end end # safe cibadmin command # @param args [Array] command arguments # @return [String,NilClass] def cibadmin_safe(*args) safe_method :cibadmin, *args end # safe crm_node command # @param args [Array] command arguments # @return [String,NilClass] def crm_node_safe(*args) safe_method :crm_node, *args end # safe cmapctl command # @param args [Array] command arguments # @return [String,NilClass] def cmapctl_safe(*args) safe_method :cmapctl, *args end # safe crm_resource command # @param args [Array] command arguments # @return [String,NilClass] def crm_resource_safe(*args) safe_method :crm_resource, *args end # safe crm_attribute command # @param args [Array] command arguments # @return [String,NilClass] def crm_attribute_safe(*args) safe_method :crm_attribute, *args end ################################################################################ # form a cluster status report for debugging # "(L)" - location constraint for this primitive is present on this node # "(F)" - the primitive is not running and have failed on this node # "(M)" - this primitive is not managed # @param tag [String] log comment tag to to trace calls # @return [String] def cluster_debug_report(tag = nil) return unless cib? report = "\n" report += 'Pacemaker debug block start' report += " at '#{tag}'" if tag report += "\n" primitives_status_by_node.each do |primitive, data| primitive_name = primitive next unless primitives.key? primitive primitive_name = primitives[primitive]['name'] if primitives[primitive]['name'] primitive_type = 'Simple' primitive_type = 'Clone' if primitive_is_clone? primitive primitive_type = 'Master' if primitive_is_master? primitive report += "-> #{primitive_type} primitive: '#{primitive_name}'" report += ' (M)' unless primitive_is_managed? primitive report += "\n" nodes = [] data.keys.sort.each do |node_name| node_status_string = data.fetch node_name node_status_string = '?' unless node_status_string.is_a? String node_status_string = node_status_string.upcase node_block = "#{node_name}: #{node_status_string}" node_block += ' (F)' if primitive_has_failures?(primitive, node_name) && (!primitive_is_running? primitive, node_name) node_block += ' (L)' if service_location_exists? primitive_full_name(primitive), node_name nodes << node_block end report += ' ' + nodes.join(' | ') + "\n" end pacemaker_options[:debug_show_properties].each do |p| report += "* #{p}: #{cluster_property_value p}\n" if cluster_property_defined? p end report += 'Pacemaker debug block end' report += " at '#{tag}'" if tag report + "\n" end end end
hoperays/openstack-ha-puppet-module
sahara/spec/classes/sahara_db_sync_spec.rb
require 'spec_helper' describe 'sahara::db::sync' do shared_examples_for 'sahara-dbsync' do context 'default patameters' do it 'runs sahara-dbmanage' do is_expected.to contain_exec('sahara-dbmanage').with( :command => 'sahara-db-manage --config-file /etc/sahara/sahara.conf upgrade head', :path => '/usr/bin', :user => 'sahara', :refreshonly => 'true', :logoutput => 'on_failure', :tag => 'openstack-db', ) end end context 'overriding extra_params' do let :params do { :extra_params => '--config-file /etc/sahara/sahara01.conf', } end it { is_expected.to contain_exec('sahara-dbmanage').with( :command => 'sahara-db-manage --config-file /etc/sahara/sahara01.conf upgrade head', :path => '/usr/bin', :user => 'sahara', :refreshonly => 'true', :logoutput => 'on_failure', :tag => 'openstack-db', ) } end end on_supported_os({ :supported_os => OSDefaults.get_supported_os }).each do |os,facts| context "on #{os}" do let (:facts) do facts.merge(OSDefaults.get_facts({ :processorcount => 8, :concat_basedir => '/var/lib/puppet/concat' })) end it_configures 'sahara-dbsync' end end end
hoperays/openstack-ha-puppet-module
glance/spec/classes/glance_backend_swift_spec.rb
require 'spec_helper' describe 'glance::backend::swift' do shared_examples_for 'glance::backend::swift' do let :params do { :swift_store_user => 'user', :swift_store_key => 'key', } end let :pre_condition do 'class { "glance::api": keystone_password => "<PASSWORD>" }' end describe 'when default parameters' do it 'configures glance-api.conf' do is_expected.to contain_glance_api_config('glance_store/default_store').with_value('swift') is_expected.to contain_glance_api_config('glance_store/swift_store_large_object_size').with_value('<SERVICE DEFAULT>') is_expected.to contain_glance_api_config('glance_store/swift_store_container').with_value('<SERVICE DEFAULT>') is_expected.to contain_glance_api_config('glance_store/swift_store_create_container_on_put').with_value('<SERVICE DEFAULT>') is_expected.to contain_glance_api_config('glance_store/swift_store_endpoint_type').with_value('internalURL') is_expected.to contain_glance_api_config('glance_store/swift_store_region').with_value('<SERVICE DEFAULT>') is_expected.to contain_glance_api_config('glance_store/swift_store_config_file').with_value('/etc/glance/glance-swift.conf') is_expected.to contain_glance_api_config('glance_store/default_swift_reference').with_value('ref1') is_expected.to contain_glance_swift_config('ref1/key').with_value('key') is_expected.to contain_glance_swift_config('ref1/user').with_value('user') is_expected.to contain_glance_swift_config('ref1/auth_version').with_value('2') is_expected.to contain_glance_swift_config('ref1/auth_address').with_value('http://127.0.0.1:5000/v2.0/') is_expected.to contain_glance_swift_config('ref1/user_domain_id').with_value('default') is_expected.to contain_glance_swift_config('ref1/project_domain_id').with_value('default') end it 'not configures glance-glare.conf' do is_expected.to_not contain_glance_glare_config('glance_store/default_store').with_value('swift') is_expected.to_not contain_glance_glare_config('glance_store/swift_store_large_object_size').with_value('<SERVICE DEFAULT>') is_expected.to_not contain_glance_glare_config('glance_store/swift_store_container').with_value('<SERVICE DEFAULT>') is_expected.to_not contain_glance_glare_config('glance_store/swift_store_create_container_on_put').with_value('<SERVICE DEFAULT>') is_expected.to_not contain_glance_glare_config('glance_store/swift_store_endpoint_type').with_value('internalURL') is_expected.to_not contain_glance_glare_config('glance_store/swift_store_region').with_value('<SERVICE DEFAULT>') is_expected.to_not contain_glance_glare_config('glance_store/swift_store_config_file').with_value('/etc/glance/glance-swift.conf') is_expected.to_not contain_glance_glare_config('glance_store/default_swift_reference').with_value('ref1') end end describe 'when overriding parameters' do let :params do { :swift_store_user => 'user2', :swift_store_key => 'key2', :swift_store_auth_version => '1', :swift_store_auth_project_domain_id => 'proj_domain', :swift_store_auth_user_domain_id => 'user_domain', :swift_store_large_object_size => '100', :swift_store_auth_address => '127.0.0.2:8080/v1.0/', :swift_store_container => 'swift', :swift_store_create_container_on_put => true, :swift_store_endpoint_type => 'publicURL', :swift_store_region => 'RegionTwo', :default_swift_reference => 'swift_creds', :glare_enabled => true, } end it 'configures glance-api.conf' do is_expected.to contain_glance_api_config('glance_store/swift_store_container').with_value('swift') is_expected.to contain_glance_api_config('glance_store/swift_store_create_container_on_put').with_value(true) is_expected.to contain_glance_api_config('glance_store/swift_store_large_object_size').with_value('100') is_expected.to contain_glance_api_config('glance_store/swift_store_endpoint_type').with_value('publicURL') is_expected.to contain_glance_api_config('glance_store/swift_store_region').with_value('RegionTwo') is_expected.to contain_glance_api_config('glance_store/default_swift_reference').with_value('swift_creds') is_expected.to contain_glance_swift_config('swift_creds/key').with_value('key2') is_expected.to contain_glance_swift_config('swift_creds/user').with_value('user2') is_expected.to contain_glance_swift_config('swift_creds/auth_version').with_value('1') is_expected.to contain_glance_swift_config('swift_creds/auth_address').with_value('127.0.0.2:8080/v1.0/') is_expected.to contain_glance_swift_config('swift_creds/user_domain_id').with_value('user_domain') is_expected.to contain_glance_swift_config('swift_creds/project_domain_id').with_value('proj_domain') end it 'configures glance-glare.conf' do is_expected.to contain_glance_glare_config('glance_store/swift_store_container').with_value('swift') is_expected.to contain_glance_glare_config('glance_store/swift_store_create_container_on_put').with_value(true) is_expected.to contain_glance_glare_config('glance_store/swift_store_large_object_size').with_value('100') is_expected.to contain_glance_glare_config('glance_store/swift_store_endpoint_type').with_value('publicURL') is_expected.to contain_glance_glare_config('glance_store/swift_store_region').with_value('RegionTwo') is_expected.to contain_glance_glare_config('glance_store/default_swift_reference').with_value('swift_creds') end end end on_supported_os({ :supported_os => OSDefaults.get_supported_os }).each do |os,facts| context "on #{os}" do let (:facts) do facts.merge!(OSDefaults.get_facts()) end it_configures 'glance::backend::swift' end end end
hoperays/openstack-ha-puppet-module
heat/spec/acceptance/basic_heat_spec.rb
require 'spec_helper_acceptance' describe 'basic heat' do context 'default parameters' do it 'should work with no errors' do pp= <<-EOS include ::openstack_integration include ::openstack_integration::repos include ::openstack_integration::rabbitmq include ::openstack_integration::mysql include ::openstack_integration::keystone rabbitmq_user { 'heat': admin => true, password => '<PASSWORD>', provider => 'rabbitmqctl', require => Class['rabbitmq'], } rabbitmq_user_permissions { 'heat@/': configure_permission => '.*', write_permission => '.*', read_permission => '.*', provider => 'rabbitmqctl', require => Class['rabbitmq'], } class { '::heat::keystone::authtoken': password => '<PASSWORD>', } # heat resources class { '::heat': rabbit_userid => 'heat', rabbit_password => '<PASSWORD>', rabbit_host => '127.0.0.1', database_connection => 'mysql+pymysql://heat:a_big_secret@127.0.0.1/heat?charset=utf8', debug => true, } class { '::heat::db::mysql': password => '<PASSWORD>', } class { '::heat::keystone::auth': password => '<PASSWORD>', configure_delegated_roles => true, } class { '::heat::keystone::domain': domain_password => '<PASSWORD>', } class { '::heat::client': } class { '::heat::api': } class { '::heat::engine': auth_encryption_key => '<KEY>', } class { '::heat::api_cloudwatch': } class { '::heat::api_cfn': } class { '::heat::cron::purge_deleted': } EOS # Run it twice and test for idempotency apply_manifest(pp, :catch_failures => true) apply_manifest(pp, :catch_changes => true) end describe port(8000) do it { is_expected.to be_listening.with('tcp') } end describe port(8003) do it { is_expected.to be_listening.with('tcp') } end describe port(8004) do it { is_expected.to be_listening.with('tcp') } end describe cron do it { is_expected.to have_entry('1 0 * * * heat-manage purge_deleted -g days 1 >>/var/log/heat/heat-purge_deleted.log 2>&1').with_user('heat') } end end end
hoperays/openstack-ha-puppet-module
cinder/spec/classes/cinder_backup_google_spec.rb
<gh_stars>0 # # Copyright (C) 2016 Intel # # Author: <NAME> <<EMAIL>> # # 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. # # Unit tests for cinder::backup::google class # require 'spec_helper' describe 'cinder::backup::google' do let :default_params do { :backup_gcs_bucket => '<SERVICE DEFAULT>', :backup_gcs_object_size => '<SERVICE DEFAULT>', :backup_gcs_block_size => '<SERVICE DEFAULT>', :backup_gcs_reader_chunk_size => '<SERVICE DEFAULT>', :backup_gcs_writer_chunk_size => '<SERVICE DEFAULT>', :backup_gcs_num_retries => '<SERVICE DEFAULT>', :backup_gcs_retry_error_codes => '<SERVICE DEFAULT>', :backup_gcs_bucket_location => '<SERVICE DEFAULT>', :backup_gcs_storage_class => '<SERVICE DEFAULT>', :backup_gcs_credential_file => '<SERVICE DEFAULT>', :backup_gcs_project_id => '<SERVICE DEFAULT>', :backup_gcs_user_agent => '<SERVICE DEFAULT>', :backup_gcs_enable_progress_timer => '<SERVICE DEFAULT>' } end let :params do {} end shared_examples_for 'cinder backup with google cloud storage' do let :p do default_params.merge(params) end it 'configures cinder.conf' do is_expected.to contain_cinder_config('DEFAULT/backup_driver').with_value('cinder.backup.drivers.google') is_expected.to contain_cinder_config('DEFAULT/backup_gcs_bucket').with_value(p[:backup_gcs_bucket]) is_expected.to contain_cinder_config('DEFAULT/backup_gcs_object_size').with_value(p[:backup_gcs_object_size]) is_expected.to contain_cinder_config('DEFAULT/backup_gcs_block_size').with_value(p[:backup_gcs_block_size]) is_expected.to contain_cinder_config('DEFAULT/backup_gcs_reader_chunk_size').with_value(p[:backup_gcs_reader_chunk_size]) is_expected.to contain_cinder_config('DEFAULT/backup_gcs_writer_chunk_size').with_value(p[:backup_gcs_writer_chunk_size]) is_expected.to contain_cinder_config('DEFAULT/backup_gcs_num_retries').with_value(p[:backup_gcs_num_retries]) is_expected.to contain_cinder_config('DEFAULT/backup_gcs_retry_error_codes').with_value(p[:backup_gcs_retry_error_codes]) is_expected.to contain_cinder_config('DEFAULT/backup_gcs_bucket_location').with_value(p[:backup_gcs_bucket_location]) is_expected.to contain_cinder_config('DEFAULT/backup_gcs_storage_class').with_value(p[:backup_gcs_storage_class]) is_expected.to contain_cinder_config('DEFAULT/backup_gcs_credential_file').with_value(p[:backup_gcs_credential_file]) is_expected.to contain_cinder_config('DEFAULT/backup_gcs_project_id').with_value(p[:backup_gcs_project_id]) is_expected.to contain_cinder_config('DEFAULT/backup_gcs_user_agent').with_value(p[:backup_gcs_user_agent]) is_expected.to contain_cinder_config('DEFAULT/backup_gcs_enable_project_timer').with_value(p[:backup_gcs_enable_progress_timer]) end context 'when overriding default parameters' do before :each do params.merge!(:backup_gcs_bucket => 'bigbucket') params.merge!(:backup_gcs_object_size => '1992') params.merge!(:backup_gcs_block_size => '12') params.merge!(:backup_gcs_reader_chunk_size => '27') params.merge!(:backup_gcs_writer_chunk_size => '-1') params.merge!(:backup_gcs_num_retries => '42') params.merge!(:backup_gcs_retry_error_codes => '430') params.merge!(:backup_gcs_bucket_location => 'NO') params.merge!(:backup_gcs_storage_class => 'FARLINE') params.merge!(:backup_gcs_credential_file => '/etc/file') params.merge!(:backup_gcs_project_id => 'me') params.merge!(:backup_gcs_user_agent => '<PASSWORD>') params.merge!(:backup_gcs_enable_progress_timer => 'false') end it 'should replace default parameters with new values' do is_expected.to contain_cinder_config('DEFAULT/backup_gcs_bucket').with_value(p[:backup_gcs_bucket]) is_expected.to contain_cinder_config('DEFAULT/backup_gcs_object_size').with_value(p[:backup_gcs_object_size]) is_expected.to contain_cinder_config('DEFAULT/backup_gcs_block_size').with_value(p[:backup_gcs_block_size]) is_expected.to contain_cinder_config('DEFAULT/backup_gcs_reader_chunk_size').with_value(p[:backup_gcs_reader_chunk_size]) is_expected.to contain_cinder_config('DEFAULT/backup_gcs_writer_chunk_size').with_value(p[:backup_gcs_writer_chunk_size]) is_expected.to contain_cinder_config('DEFAULT/backup_gcs_num_retries').with_value(p[:backup_gcs_num_retries]) is_expected.to contain_cinder_config('DEFAULT/backup_gcs_retry_error_codes').with_value(p[:backup_gcs_retry_error_codes]) is_expected.to contain_cinder_config('DEFAULT/backup_gcs_bucket_location').with_value(p[:backup_gcs_bucket_location]) is_expected.to contain_cinder_config('DEFAULT/backup_gcs_storage_class').with_value(p[:backup_gcs_storage_class]) is_expected.to contain_cinder_config('DEFAULT/backup_gcs_credential_file').with_value(p[:backup_gcs_credential_file]) is_expected.to contain_cinder_config('DEFAULT/backup_gcs_project_id').with_value(p[:backup_gcs_project_id]) is_expected.to contain_cinder_config('DEFAULT/backup_gcs_user_agent').with_value(p[:backup_gcs_user_agent]) is_expected.to contain_cinder_config('DEFAULT/backup_gcs_enable_project_timer').with_value(p[:backup_gcs_enable_progress_timer]) end end end on_supported_os({ :supported_os => OSDefaults.get_supported_os }).each do |os,facts| context "on #{os}" do let (:facts) do facts.merge(OSDefaults.get_facts({:processorcount => 8})) end it_configures 'cinder backup with google cloud storage' end end end
hoperays/openstack-ha-puppet-module
sahara/spec/classes/sahara_init_spec.rb
# # Unit tests for sahara::init # require 'spec_helper' describe 'sahara' do let :params do { :admin_password => '<PASSWORD>', :purge_config => false, } end shared_examples_for 'sahara' do it { is_expected.to contain_class('sahara::params') } it { is_expected.to contain_class('sahara::db') } it { is_expected.to contain_class('sahara::logging') } it { is_expected.to contain_class('sahara::policy') } it { is_expected.to contain_class('mysql::bindings::python') } it { is_expected.to contain_exec('sahara-dbmanage') } it 'passes purge to resource' do is_expected.to contain_resources('sahara_config').with({ :purge => false }) end end shared_examples_for 'sahara config' do context 'with default params' do it { is_expected.to contain_sahara_config('DEFAULT/use_neutron').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('DEFAULT/use_floating_ips').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('DEFAULT/host').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('DEFAULT/port').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('keystone_authtoken/auth_uri').with_value('http://127.0.0.1:5000/v2.0/') } it { is_expected.to contain_sahara_config('keystone_authtoken/identity_uri').with_value('http://127.0.0.1:35357/') } it { is_expected.to contain_sahara_config('keystone_authtoken/admin_user').with_value('sahara') } it { is_expected.to contain_sahara_config('keystone_authtoken/admin_tenant_name').with_value('services') } it { is_expected.to contain_sahara_config('keystone_authtoken/admin_password').with_value('secrete').with_secret(true) } it { is_expected.to contain_sahara_config('keystone_authtoken/memcached_servers').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('DEFAULT/plugins').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/kombu_reconnect_delay').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/kombu_compression').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/kombu_failover_strategy').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('DEFAULT/transport_url').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('DEFAULT/control_exchange').with_value('<SERVICE DEFAULT>') } end context 'with passing params' do let :params do { :use_neutron => 'true', :host => 'localhost', :port => '8387', :auth_uri => 'http://8.8.8.8:5000/v2.0/', :identity_uri => 'http://8.8.8.8:35357/', :admin_user => 'sahara-user', :admin_tenant_name => 'sahara-tenant', :admin_password => '<PASSWORD>', :memcached_servers => '1.1.1.1:11211', :plugins => ['plugin1', 'plugin2'], :default_transport_url => 'rabbit://guest2:pass@localhost2:5673', :control_exchange => 'openstack', } end it { is_expected.to contain_sahara_config('DEFAULT/use_neutron').with_value('true') } it { is_expected.to contain_sahara_config('DEFAULT/host').with_value('localhost') } it { is_expected.to contain_sahara_config('DEFAULT/port').with_value('8387') } it { is_expected.to contain_sahara_config('keystone_authtoken/auth_uri').with_value('http://8.8.8.8:5000/v2.0/') } it { is_expected.to contain_sahara_config('keystone_authtoken/identity_uri').with_value('http://8.8.8.8:35357/') } it { is_expected.to contain_sahara_config('keystone_authtoken/admin_user').with_value('sahara-user') } it { is_expected.to contain_sahara_config('keystone_authtoken/admin_tenant_name').with_value('sahara-tenant') } it { is_expected.to contain_sahara_config('keystone_authtoken/admin_password').with_value('new_password').with_secret(true) } it { is_expected.to contain_sahara_config('keystone_authtoken/memcached_servers').with_value('1.1.1.1:11211') } it { is_expected.to contain_sahara_config('DEFAULT/plugins').with_value('plugin1,plugin2') } it { is_expected.to contain_sahara_config('DEFAULT/transport_url').with_value('rabbit://guest2:pass@localhost2:5673') } it { is_expected.to contain_sahara_config('DEFAULT/control_exchange').with_value('openstack') } end end shared_examples_for 'sahara rpc_backend' do context 'with rabbit rpc' do before do params.merge!({ :rpc_backend => 'rabbit' }) end it { is_expected.to contain_sahara_config('DEFAULT/rpc_backend').with_value('rabbit') } context 'when defaults with rabbit pass specified' do it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_password').with_value('<SERVICE DEFAULT>').with_secret(true) } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_userid').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_host').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_port').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_virtual_host').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/amqp_durable_queues').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_hosts').with_value('<SERVICE DEFAULT>') } end context 'when passing params' do before do params.merge!({ :rabbit_password => '<PASSWORD>', :rabbit_userid => 'guest2', :rabbit_host => 'localhost2', :rabbit_port => '5673', :rabbit_ha_queues => 'true', :amqp_durable_queues => 'true', :kombu_reconnect_delay => '1.0', :kombu_compression => 'gzip', :kombu_failover_strategy => 'round-robin', }) end it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_userid').with_value('guest2') } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_password').with_value('<PASSWORD>').with_secret(true) } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_host').with_value('localhost2') } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_port').with_value('5673') } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('true') } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/amqp_durable_queues').with_value('true') } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_hosts').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/kombu_reconnect_delay').with_value('1.0') } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/kombu_compression').with_value('gzip') } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/kombu_failover_strategy').with_value('round-robin') } end context 'with rabbit ssl cert parameters' do before do params.merge!({ :rabbit_password => '<PASSWORD>', :rabbit_use_ssl => true, :kombu_ssl_ca_certs => '/etc/ca.cert', :kombu_ssl_certfile => '/etc/certfile', :kombu_ssl_keyfile => '/etc/key', :kombu_ssl_version => 'TLSv1', }) end it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('true') } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('/etc/ca.cert') } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('/etc/certfile') } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('/etc/key') } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('TLSv1') } end context 'with rabbit ssl disabled' do before do params.merge!({ :rabbit_password => '<PASSWORD>', :rabbit_use_ssl => false, }) end it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('false') } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('<SERVICE DEFAULT>') } end context 'when passing params for single rabbit host' do before do params.merge!({ :rabbit_password => '<PASSWORD>', :rabbit_userid => 'guest2', :rabbit_host => 'localhost2', :rabbit_port => '5673', :rabbit_ha_queues => true, }) end it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_userid').with_value('guest2') } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_host').with_value('localhost2') } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_port').with_value('5673') } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('true') } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_hosts').with_value('<SERVICE DEFAULT>') } end context 'when passing params for multiple rabbit hosts' do before do params.merge!({ :rabbit_password => '<PASSWORD>', :rabbit_userid => 'guest3', :rabbit_hosts => ['nonlocalhost3:5673', 'nonlocalhost4:5673'] }) end it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_userid').with_value('guest3') } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_hosts').with_value('nonlocalhost3:5673,nonlocalhost4:5673') } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('true') } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_port').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('oslo_messaging_rabbit/rabbit_host').with_value('<SERVICE DEFAULT>') } end end context 'with zmq rpc' do before do params.merge!({ :rpc_backend => 'zmq' }) end it { is_expected.to contain_sahara_config('DEFAULT/rpc_backend').with_value('zmq') } context 'with default params' do it { is_expected.to contain_sahara_config('DEFAULT/rpc_zmq_bind_address').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('DEFAULT/rpc_zmq_contexts').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('DEFAULT/rpc_zmq_topic_backlog').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('DEFAULT/rpc_zmq_ipc_dir').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('DEFAULT/rpc_zmq_host').with_value('sahara') } it { is_expected.to contain_sahara_config('DEFAULT/rpc_cast_timeout').with_value('<SERVICE DEFAULT>') } end context 'when passing params' do before do params.merge!({ :zeromq_bind_address => '*', :zeromq_host => 'localhost', :cast_timeout => '30', :rpc_backend => 'zmq', }) end it { is_expected.to contain_sahara_config('DEFAULT/rpc_zmq_bind_address').with_value('*') } it { is_expected.to contain_sahara_config('DEFAULT/rpc_zmq_host').with_value('localhost') } it { is_expected.to contain_sahara_config('DEFAULT/rpc_cast_timeout').with_value('30') } end end context 'with amqp rpc' do before do params.merge!({ :rpc_backend => 'amqp' }) end context 'with default parameters' do it { is_expected.to contain_sahara_config('DEFAULT/rpc_backend').with_value('amqp') } it { is_expected.to contain_sahara_config('oslo_messaging_amqp/server_request_prefix').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('oslo_messaging_amqp/broadcast_prefix').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('oslo_messaging_amqp/group_request_prefix').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('oslo_messaging_amqp/container_name').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('oslo_messaging_amqp/idle_timeout').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('oslo_messaging_amqp/trace').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('oslo_messaging_amqp/ssl_ca_file').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('oslo_messaging_amqp/ssl_cert_file').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('oslo_messaging_amqp/ssl_key_file').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('oslo_messaging_amqp/ssl_key_password').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('oslo_messaging_amqp/allow_insecure_clients').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('oslo_messaging_amqp/sasl_mechanisms').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('oslo_messaging_amqp/sasl_config_dir').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('oslo_messaging_amqp/sasl_config_name').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('oslo_messaging_amqp/username').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_sahara_config('oslo_messaging_amqp/password').with_value('<SERVICE DEFAULT>') } end context 'when pass parameters' do before do params.merge!({ :amqp_idle_timeout => '60', :amqp_trace => true, :amqp_ssl_ca_file => '/etc/ca.cert', :amqp_ssl_cert_file => '/etc/certfile', :amqp_ssl_key_file => '/etc/key', :amqp_username => 'amqp_user', :amqp_password => 'password', }) end it { is_expected.to contain_sahara_config('DEFAULT/rpc_backend').with_value('amqp') } it { is_expected.to contain_sahara_config('oslo_messaging_amqp/idle_timeout').with_value('60') } it { is_expected.to contain_sahara_config('oslo_messaging_amqp/trace').with_value('true') } it { is_expected.to contain_sahara_config('oslo_messaging_amqp/ssl_ca_file').with_value('/etc/ca.cert') } it { is_expected.to contain_sahara_config('oslo_messaging_amqp/ssl_cert_file').with_value('/etc/certfile') } it { is_expected.to contain_sahara_config('oslo_messaging_amqp/ssl_key_file').with_value('/etc/key') } it { is_expected.to contain_sahara_config('oslo_messaging_amqp/username').with_value('amqp_user') } it { is_expected.to contain_sahara_config('oslo_messaging_amqp/password').with_value('password') } end end end shared_examples_for 'sahara ssl' do context 'without ssl' do it { is_expected.to_not contain_sahara_config('ssl/ca_file') } it { is_expected.to_not contain_sahara_config('ssl/cert_file') } it { is_expected.to_not contain_sahara_config('ssl/key_file') } end context 'with ssl' do let :params do { :use_ssl => true, :ca_file => '/tmp/ca_file', :cert_file => '/tmp/cert_file', :key_file => '/tmp/key_file', } end it { is_expected.to contain_sahara_config('ssl/ca_file').with_value('/tmp/ca_file') } it { is_expected.to contain_sahara_config('ssl/cert_file').with_value('/tmp/cert_file') } it { is_expected.to contain_sahara_config('ssl/key_file').with_value('/tmp/key_file') } end context 'with ssl but without cert_file' do let :params do { :use_ssl => true, } end it_raises 'a Puppet::Error', /The cert_file parameter is required when use_ssl is set to true/ end context 'with ssl but without key_file' do let :params do { :use_ssl => true, :cert_file => '/tmp/cert_file', } end it_raises 'a Puppet::Error', /The key_file parameter is required when use_ssl is set to true/ end end on_supported_os({ :supported_os => OSDefaults.get_supported_os }).each do |os,facts| context "on #{os}" do let (:facts) do facts.merge(OSDefaults.get_facts) end it_configures 'sahara' it_configures 'sahara config' it_configures 'sahara ssl' it_configures 'sahara rpc_backend' end end end
hoperays/openstack-ha-puppet-module
ceilometer/spec/classes/ceilometer_db_sync_spec.rb
require 'spec_helper' describe 'ceilometer::db::sync' do shared_examples_for 'ceilometer-dbsync' do it 'runs ceilometer-dbsync' do is_expected.to contain_exec('ceilometer-dbsync').with( :command => 'ceilometer-dbsync --config-file=/etc/ceilometer/ceilometer.conf ', :path => '/usr/bin', :refreshonly => 'true', :user => 'ceilometer', :logoutput => 'on_failure' ) end describe 'overriding extra_params' do let :params do { :extra_params => '--config-file=/etc/ceilometer/ceilometer_01.conf', } end it { is_expected.to contain_exec('ceilometer-dbsync').with( :command => 'ceilometer-dbsync --config-file=/etc/ceilometer/ceilometer.conf --config-file=/etc/ceilometer/ceilometer_01.conf', :path => '/usr/bin', :user => 'ceilometer', :refreshonly => 'true', :logoutput => 'on_failure' ) } end end on_supported_os({ :supported_os => OSDefaults.get_supported_os }).each do |os,facts| context "on #{os}" do let (:facts) do facts.merge(OSDefaults.get_facts({ :processorcount => 8, :concat_basedir => '/var/lib/puppet/concat' })) end it_configures 'ceilometer-dbsync' end end end
hoperays/openstack-ha-puppet-module
cinder/spec/defines/cinder_backend_vmdk_spec.rb
<filename>cinder/spec/defines/cinder_backend_vmdk_spec.rb require 'spec_helper' describe 'cinder::backend::vmdk' do let(:title) { 'hippo' } let :facts do OSDefaults.get_facts({}) end let :params do { :host_ip => '172.16.16.16', :host_password => '<PASSWORD>', :host_username => 'user', :api_retry_count => '<SERVICE DEFAULT>', :max_object_retrieval => '<SERVICE DEFAULT>', :image_transfer_timeout_secs => '<SERVICE DEFAULT>' } end let :optional_params do { :volume_folder => 'cinder-volume-folder', :api_retry_count => 5, :max_object_retrieval => 200, :task_poll_interval => 10, :image_transfer_timeout_secs => 3600, :wsdl_location => 'http://127.0.0.1:8080/vmware/SDK/wsdl/vim25/vimService.wsdl' } end it 'should configure vmdk driver in cinder.conf' do is_expected.to contain_cinder_config('hippo/volume_backend_name').with_value('hippo') is_expected.to contain_cinder_config('hippo/volume_driver').with_value('cinder.volume.drivers.vmware.vmdk.VMwareVcVmdkDriver') is_expected.to contain_cinder_config('hippo/vmware_host_ip').with_value(params[:host_ip]) is_expected.to contain_cinder_config('hippo/vmware_host_username').with_value(params[:host_username]) is_expected.to contain_cinder_config('hippo/vmware_host_password').with_value(params[:host_password]) is_expected.to contain_cinder_config('hippo/vmware_volume_folder').with_value('cinder-volumes') is_expected.to contain_cinder_config('hippo/vmware_api_retry_count').with_value(params[:api_retry_count]) is_expected.to contain_cinder_config('hippo/vmware_max_object_retrieval').with_value(params[:max_object_retrieval]) is_expected.to contain_cinder_config('hippo/vmware_task_poll_interval').with_value(5) is_expected.to contain_cinder_config('hippo/vmware_image_transfer_timeout_secs').with_value(params[:image_transfer_timeout_secs]) is_expected.to contain_cinder_config('hippo/vmware_wsdl_location').with_value('<SERVICE DEFAULT>') end it 'installs suds python package' do is_expected.to contain_package('python-suds').with( :ensure => 'present') end context 'with optional parameters' do before :each do params.merge!(optional_params) end it 'should configure vmdk driver in cinder.conf' do is_expected.to contain_cinder_config('hippo/vmware_volume_folder').with_value(params[:volume_folder]) is_expected.to contain_cinder_config('hippo/vmware_api_retry_count').with_value(params[:api_retry_count]) is_expected.to contain_cinder_config('hippo/vmware_max_object_retrieval').with_value(params[:max_object_retrieval]) is_expected.to contain_cinder_config('hippo/vmware_task_poll_interval').with_value(params[:task_poll_interval]) is_expected.to contain_cinder_config('hippo/vmware_image_transfer_timeout_secs').with_value(params[:image_transfer_timeout_secs]) is_expected.to contain_cinder_config('hippo/vmware_wsdl_location').with_value(params[:wsdl_location]) is_expected.to contain_cinder_config('hippo/host').with_value("vmdk:#{params[:host_ip]}-#{params[:volume_folder]}") end end context 'vmdk backend with additional configuration' do before do params.merge!({:extra_options => {'hippo/param1' => { 'value' => 'value1' }}}) end it 'configure vmdk backend with additional configuration' do is_expected.to contain_cinder_config('hippo/param1').with({ :value => 'value1' }) end end context 'vmdk backend with cinder type' do before do params.merge!({:manage_volume_type => true}) end it 'should create type with properties' do should contain_cinder_type('hippo').with(:ensure => :present, :properties => ['volume_backend_name=hippo']) end end end
hoperays/openstack-ha-puppet-module
glance/spec/classes/glance_registry_authtoken_spec.rb
<filename>glance/spec/classes/glance_registry_authtoken_spec.rb require 'spec_helper' describe 'glance::registry::authtoken' do let :params do { :password => '<PASSWORD>', } end shared_examples 'glance_registry authtoken' do context 'with default parameters' do it 'configure keystone_authtoken' do is_expected.to contain_glance_registry_config('keystone_authtoken/username').with_value('glance') is_expected.to contain_glance_registry_config('keystone_authtoken/password').with_value('glance_registry_password') is_expected.to contain_glance_registry_config('keystone_authtoken/auth_url').with_value('http://127.0.0.1:35357') is_expected.to contain_glance_registry_config('keystone_authtoken/project_name').with_value('services') is_expected.to contain_glance_registry_config('keystone_authtoken/user_domain_name').with_value('<SERVICE DEFAULT>') is_expected.to contain_glance_registry_config('keystone_authtoken/project_domain_name').with_value('<SERVICE DEFAULT>') is_expected.to contain_glance_registry_config('keystone_authtoken/insecure').with_value('<SERVICE DEFAULT>') is_expected.to contain_glance_registry_config('keystone_authtoken/auth_section').with_value('<SERVICE DEFAULT>') is_expected.to contain_glance_registry_config('keystone_authtoken/auth_type').with_value('password') is_expected.to contain_glance_registry_config('keystone_authtoken/auth_uri').with_value('http://127.0.0.1:5000') is_expected.to contain_glance_registry_config('keystone_authtoken/auth_version').with_value('<SERVICE DEFAULT>') is_expected.to contain_glance_registry_config('keystone_authtoken/cache').with_value('<SERVICE DEFAULT>') is_expected.to contain_glance_registry_config('keystone_authtoken/cafile').with_value('<SERVICE DEFAULT>') is_expected.to contain_glance_registry_config('keystone_authtoken/certfile').with_value('<SERVICE DEFAULT>') is_expected.to contain_glance_registry_config('keystone_authtoken/check_revocations_for_cached').with_value('<SERVICE DEFAULT>') is_expected.to contain_glance_registry_config('keystone_authtoken/delay_auth_decision').with_value('<SERVICE DEFAULT>') is_expected.to contain_glance_registry_config('keystone_authtoken/enforce_token_bind').with_value('<SERVICE DEFAULT>') is_expected.to contain_glance_registry_config('keystone_authtoken/hash_algorithms').with_value('<SERVICE DEFAULT>') is_expected.to contain_glance_registry_config('keystone_authtoken/http_connect_timeout').with_value('<SERVICE DEFAULT>') is_expected.to contain_glance_registry_config('keystone_authtoken/http_request_max_retries').with_value('<SERVICE DEFAULT>') is_expected.to contain_glance_registry_config('keystone_authtoken/include_service_catalog').with_value('<SERVICE DEFAULT>') is_expected.to contain_glance_registry_config('keystone_authtoken/keyfile').with_value('<SERVICE DEFAULT>') is_expected.to contain_glance_registry_config('keystone_authtoken/memcache_pool_conn_get_timeout').with_value('<SERVICE DEFAULT>') is_expected.to contain_glance_registry_config('keystone_authtoken/memcache_pool_dead_retry').with_value('<SERVICE DEFAULT>') is_expected.to contain_glance_registry_config('keystone_authtoken/memcache_pool_maxsize').with_value('<SERVICE DEFAULT>') is_expected.to contain_glance_registry_config('keystone_authtoken/memcache_pool_socket_timeout').with_value('<SERVICE DEFAULT>') is_expected.to contain_glance_registry_config('keystone_authtoken/memcache_pool_unused_timeout').with_value('<SERVICE DEFAULT>') is_expected.to contain_glance_registry_config('keystone_authtoken/memcache_secret_key').with_value('<SERVICE DEFAULT>') is_expected.to contain_glance_registry_config('keystone_authtoken/memcache_security_strategy').with_value('<SERVICE DEFAULT>') is_expected.to contain_glance_registry_config('keystone_authtoken/memcache_use_advanced_pool').with_value('<SERVICE DEFAULT>') is_expected.to contain_glance_registry_config('keystone_authtoken/memcached_servers').with_value('<SERVICE DEFAULT>') is_expected.to contain_glance_registry_config('keystone_authtoken/region_name').with_value('<SERVICE DEFAULT>') is_expected.to contain_glance_registry_config('keystone_authtoken/revocation_cache_time').with_value('<SERVICE DEFAULT>') is_expected.to contain_glance_registry_config('keystone_authtoken/signing_dir').with_value('<SERVICE DEFAULT>') is_expected.to contain_glance_registry_config('keystone_authtoken/token_cache_time').with_value('<SERVICE DEFAULT>') end end context 'when overriding parameters' do before do params.merge!({ :auth_uri => 'https://10.0.0.1:9999/', :username => 'myuser', :password => '<PASSWORD>', :auth_url => 'http://:127.0.0.1:35357', :project_name => 'service_project', :user_domain_name => 'domainX', :project_domain_name => 'domainX', :insecure => false, :auth_section => 'new_section', :auth_type => 'password', :auth_version => 'v3', :cache => 'somevalue', :cafile => '/opt/stack/data/cafile.pem', :certfile => 'certfile.crt', :check_revocations_for_cached => false, :delay_auth_decision => false, :enforce_token_bind => 'permissive', :hash_algorithms => 'md5', :http_connect_timeout => '300', :http_request_max_retries => '3', :include_service_catalog => true, :keyfile => 'keyfile', :memcache_pool_conn_get_timeout => '9', :memcache_pool_dead_retry => '302', :memcache_pool_maxsize => '11', :memcache_pool_socket_timeout => '2', :memcache_pool_unused_timeout => '61', :memcache_secret_key => 'secret_key', :memcache_security_strategy => 'ENCRYPT', :memcache_use_advanced_pool => true, :memcached_servers => ['memcached01:11211','memcached02:11211'], :manage_memcache_package => true, :region_name => 'region2', :revocation_cache_time => '11', :signing_dir => '/var/cache', :token_cache_time => '301', }) end it 'configure keystone_authtoken' do is_expected.to contain_glance_registry_config('keystone_authtoken/auth_uri').with_value('https://10.0.0.1:9999/') is_expected.to contain_glance_registry_config('keystone_authtoken/username').with_value(params[:username]) is_expected.to contain_glance_registry_config('keystone_authtoken/password').with_value(params[:password]).with_secret(true) is_expected.to contain_glance_registry_config('keystone_authtoken/auth_url').with_value(params[:auth_url]) is_expected.to contain_glance_registry_config('keystone_authtoken/project_name').with_value(params[:project_name]) is_expected.to contain_glance_registry_config('keystone_authtoken/user_domain_name').with_value(params[:user_domain_name]) is_expected.to contain_glance_registry_config('keystone_authtoken/project_domain_name').with_value(params[:project_domain_name]) is_expected.to contain_glance_registry_config('keystone_authtoken/insecure').with_value(params[:insecure]) is_expected.to contain_glance_registry_config('keystone_authtoken/auth_section').with_value(params[:auth_section]) is_expected.to contain_glance_registry_config('keystone_authtoken/auth_type').with_value(params[:auth_type]) is_expected.to contain_glance_registry_config('keystone_authtoken/auth_version').with_value(params[:auth_version]) is_expected.to contain_glance_registry_config('keystone_authtoken/cache').with_value(params[:cache]) is_expected.to contain_glance_registry_config('keystone_authtoken/cafile').with_value(params[:cafile]) is_expected.to contain_glance_registry_config('keystone_authtoken/certfile').with_value(params[:certfile]) is_expected.to contain_glance_registry_config('keystone_authtoken/check_revocations_for_cached').with_value(params[:check_revocations_for_cached]) is_expected.to contain_glance_registry_config('keystone_authtoken/delay_auth_decision').with_value(params[:delay_auth_decision]) is_expected.to contain_glance_registry_config('keystone_authtoken/enforce_token_bind').with_value(params[:enforce_token_bind]) is_expected.to contain_glance_registry_config('keystone_authtoken/hash_algorithms').with_value(params[:hash_algorithms]) is_expected.to contain_glance_registry_config('keystone_authtoken/http_connect_timeout').with_value(params[:http_connect_timeout]) is_expected.to contain_glance_registry_config('keystone_authtoken/http_request_max_retries').with_value(params[:http_request_max_retries]) is_expected.to contain_glance_registry_config('keystone_authtoken/include_service_catalog').with_value(params[:include_service_catalog]) is_expected.to contain_glance_registry_config('keystone_authtoken/keyfile').with_value(params[:keyfile]) is_expected.to contain_glance_registry_config('keystone_authtoken/memcache_pool_conn_get_timeout').with_value(params[:memcache_pool_conn_get_timeout]) is_expected.to contain_glance_registry_config('keystone_authtoken/memcache_pool_dead_retry').with_value(params[:memcache_pool_dead_retry]) is_expected.to contain_glance_registry_config('keystone_authtoken/memcache_pool_maxsize').with_value(params[:memcache_pool_maxsize]) is_expected.to contain_glance_registry_config('keystone_authtoken/memcache_pool_socket_timeout').with_value(params[:memcache_pool_socket_timeout]) is_expected.to contain_glance_registry_config('keystone_authtoken/memcache_pool_unused_timeout').with_value(params[:memcache_pool_unused_timeout]) is_expected.to contain_glance_registry_config('keystone_authtoken/memcache_secret_key').with_value(params[:memcache_secret_key]) is_expected.to contain_glance_registry_config('keystone_authtoken/memcache_security_strategy').with_value(params[:memcache_security_strategy]) is_expected.to contain_glance_registry_config('keystone_authtoken/memcache_use_advanced_pool').with_value(params[:memcache_use_advanced_pool]) is_expected.to contain_glance_registry_config('keystone_authtoken/memcached_servers').with_value('memcached01:11211,memcached02:11211') is_expected.to contain_glance_registry_config('keystone_authtoken/region_name').with_value(params[:region_name]) is_expected.to contain_glance_registry_config('keystone_authtoken/revocation_cache_time').with_value(params[:revocation_cache_time]) is_expected.to contain_glance_registry_config('keystone_authtoken/signing_dir').with_value(params[:signing_dir]) is_expected.to contain_glance_registry_config('keystone_authtoken/token_cache_time').with_value(params[:token_cache_time]) end it 'installs python memcache package' do is_expected.to contain_package('python-memcache') end end end on_supported_os({ :supported_os => OSDefaults.get_supported_os }).each do |os,facts| context "on #{os}" do let (:facts) do facts.merge!(OSDefaults.get_facts()) end it_configures 'glance_registry authtoken' end end end
hoperays/openstack-ha-puppet-module
cinder/spec/classes/cinder_ceilometer_spec.rb
require 'spec_helper' describe 'cinder::ceilometer' do describe 'with default parameters' do let :facts do OSDefaults.get_facts({}) end it 'contains default values' do is_expected.to contain_cinder_config('oslo_messaging_notifications/transport_url').with( :value => '<SERVICE DEFAULT>') is_expected.to contain_cinder_config('oslo_messaging_notifications/driver').with( :value => 'messagingv2') end end end
hoperays/openstack-ha-puppet-module
openstacklib/spec/functions/os_transport_url_spec.rb
require 'spec_helper' describe 'os_transport_url' do it 'refuses String' do is_expected.to run.with_params('foo').\ and_raise_error(Puppet::ParseError, /Requires an hash/) end it 'refuses Array' do is_expected.to run.with_params(['foo']).\ and_raise_error(Puppet::ParseError, /Requires an hash/) end it 'refuses without at least one argument' do is_expected.to run.with_params().\ and_raise_error(ArgumentError, /Wrong number of arguments/) end it 'refuses too many arguments' do is_expected.to run.with_params('foo', 'bar').\ and_raise_error(ArgumentError, /Wrong number of arguments/) end it 'refuses hosts params passed as String' do is_expected.to run.with_params({ 'transport'=> 'rabbit', 'hosts' => '127.0.0.1', }).and_raise_error(Puppet::ParseError, /hosts should be a Array/) end it 'fails if missing host' do is_expected.to run.with_params({ 'transport'=> 'rabbit', }).and_raise_error(Puppet::ParseError, /host or hosts is required/) end context 'creates the correct transport URI' do it 'with a single host array for hosts' do is_expected.to run.with_params({ 'transport' => 'rabbit', 'hosts' => [ '127.0.0.1' ], 'port' => '5672', 'username' => 'guest', 'password' => '<PASSWORD>', 'virtual_host' => 'virt', 'ssl' => '1', 'query' => { 'read_timeout' => '60' }, }).and_return('rabbit://guest:s3cr3t@127.0.0.1:5672/virt?read_timeout=60&ssl=1') end it 'with all params for a single host' do is_expected.to run.with_params({ 'transport' => 'rabbit', 'host' => '127.0.0.1', 'port' => '5672', 'username' => 'guest', 'password' => '<PASSWORD>', 'virtual_host' => 'virt', 'ssl' => '1', 'query' => { 'read_timeout' => '60' }, }).and_return('rabbit://guest:s3cr3t@127.0.0.1:5672/virt?read_timeout=60&ssl=1') end it 'with only required params for a single host' do is_expected.to run.with_params({ 'transport' => 'rabbit', 'host' => '127.0.0.1', }).and_return('rabbit://127.0.0.1/') end it 'with a single ipv6 address' do is_expected.to run.with_params({ 'transport' => 'rabbit', 'host' => 'fe80::ca5b:76ff:fe4b:be3b', 'port' => '5672' }).and_return('rabbit://[fe80::ca5b:76ff:fe4b:be3b]:5672/') end it 'with all params with multiple hosts' do is_expected.to run.with_params({ 'transport' => 'rabbit', 'hosts' => ['1.1.1.1', '2.2.2.2'], 'port' => '5672', 'username' => 'guest', 'password' => '<PASSWORD>', 'virtual_host' => 'virt', 'query' => { 'read_timeout' => '60' }, }).and_return('rabbit://guest:s3cr3t@1.1.1.1:5672,guest:s3cr3t@2.2.2.2:5672/virt?read_timeout=60') end it 'with only required params for multiple hosts' do is_expected.to run.with_params({ 'transport' => 'rabbit', 'hosts' => [ '1.1.1.1', '2.2.2.2' ], 'port' => '5672', 'username' => 'guest', 'password' => '<PASSWORD>', }).and_return('rabbit://guest:s3cr3t@1.1.1.1:5672,guest:s3cr3t@2.2.2.2:5672/') end it 'with multiple ipv6 hosts' do is_expected.to run.with_params({ 'transport' => 'rabbit', 'hosts' => [ 'fe80::ca5b:76ff:fe4b:be3b', 'fe80::ca5b:76ff:fe4b:be3c' ], 'port' => '5672', 'username' => 'guest', 'password' => '<PASSWORD>', }).and_return('rabbit://guest:s3cr3t@[fe80::ca5b:76ff:fe4b:be3b]:5672,guest:s3cr3t@[fe80::ca5b:76ff:fe4b:be3c]:5672/') end it 'with a mix of ipv4 and ipv6 hosts' do is_expected.to run.with_params({ 'transport' => 'rabbit', 'hosts' => [ 'fe80::ca5b:76ff:fe4b:be3b', '1.1.1.1' ], 'port' => '5672', 'username' => 'guest', 'password' => '<PASSWORD>', }).and_return('rabbit://guest:s3cr3t@[fe80::ca5b:76ff:fe4b:be3b]:5672,guest:s3cr3t@1.1.1.1:5672/') end it 'without port' do is_expected.to run.with_params({ 'transport' => 'rabbit', 'host' => '127.0.0.1', 'username' => 'guest', 'password' => '<PASSWORD>', 'virtual_host' => 'virt', 'query' => { 'read_timeout' => '60' }, }).and_return('rabbit://guest:s3cr3t@127.0.0.1/virt?read_timeout=60') end it 'without port and query' do is_expected.to run.with_params({ 'transport' => 'rabbit', 'host' => '127.0.0.1', 'username' => 'guest', 'password' => '<PASSWORD>', 'virtual_host' => 'virt', }).and_return('rabbit://guest:s3cr3t@127.0.0.1/virt') end it 'without username and password' do is_expected.to run.with_params({ 'transport' => 'rabbit', 'host' => '127.0.0.1', 'port' => '5672', 'virtual_host' => 'virt', 'query' => { 'read_timeout' => '60' }, }).and_return('rabbit://127.0.0.1:5672/virt?read_timeout=60') end it 'with username set to undef' do is_expected.to run.with_params({ 'transport' => 'rabbit', 'host' => '127.0.0.1', 'port' => '5672', 'username' => :undef, 'virtual_host' => 'virt', 'query' => { 'read_timeout' => '60' }, }).and_return('rabbit://127.0.0.1:5672/virt?read_timeout=60') end it 'with username set to an empty string' do is_expected.to run.with_params({ 'transport' => 'rabbit', 'host' => '127.0.0.1', 'port' => '5672', 'username' => '', 'virtual_host' => 'virt', 'query' => { 'read_timeout' => '60' }, }).and_return('rabbit://127.0.0.1:5672/virt?read_timeout=60') end it 'without password' do is_expected.to run.with_params({ 'transport' => 'rabbit', 'host' => '127.0.0.1', 'port' => '5672', 'username' => 'guest', 'virtual_host' => 'virt', 'query' => { 'read_timeout' => '60' }, }).and_return('rabbit://guest@127.0.0.1:5672/virt?read_timeout=60') end it 'with password set to undef' do is_expected.to run.with_params({ 'transport' => 'rabbit', 'host' => '127.0.0.1', 'port' => '5672', 'username' => 'guest', 'password' => :undef, 'virtual_host' => 'virt', 'query' => { 'read_timeout' => '60' }, }).and_return('rabbit://guest@127.0.0.1:5672/virt?read_timeout=60') end it 'with password set to an empty string' do is_expected.to run.with_params({ 'transport' => 'rabbit', 'host' => '127.0.0.1', 'port' => '5672', 'username' => 'guest', 'password' => '', 'virtual_host' => 'virt', 'query' => { 'read_timeout' => '60' }, }).and_return('rabbit://guest@127.0.0.1:5672/virt?read_timeout=60') end it 'with ssl overrides ssl in quert hash' do is_expected.to run.with_params({ 'transport' => 'rabbit', 'host' => '127.0.0.1', 'port' => '5672', 'username' => 'guest', 'password' => '', 'virtual_host' => 'virt', 'ssl' => '1', 'query' => { 'read_timeout' => '60' , 'ssl' => '0'}, }).and_return('rabbit://guest@127.0.0.1:5672/virt?read_timeout=60&ssl=1') end it 'with ssl as boolean string' do is_expected.to run.with_params({ 'transport' => 'rabbit', 'host' => '127.0.0.1', 'port' => '5672', 'username' => 'guest', 'password' => '', 'virtual_host' => 'virt', 'ssl' => 'true', 'query' => { 'read_timeout' => '60' }, }).and_return('rabbit://guest@127.0.0.1:5672/virt?read_timeout=60&ssl=1') is_expected.to run.with_params({ 'transport' => 'rabbit', 'host' => '127.0.0.1', 'port' => '5672', 'username' => 'guest', 'password' => '', 'virtual_host' => 'virt', 'ssl' => 'false', 'query' => { 'read_timeout' => '60' }, }).and_return('rabbit://guest@127.0.0.1:5672/virt?read_timeout=60&ssl=0') is_expected.to run.with_params({ 'transport' => 'rabbit', 'host' => '127.0.0.1', 'port' => '5672', 'username' => 'guest', 'password' => '', 'virtual_host' => 'virt', 'ssl' => 'True', 'query' => { 'read_timeout' => '60' }, }).and_return('rabbit://guest@127.0.0.1:5672/virt?read_timeout=60&ssl=1') is_expected.to run.with_params({ 'transport' => 'rabbit', 'host' => '127.0.0.1', 'port' => '5672', 'username' => 'guest', 'password' => '', 'virtual_host' => 'virt', 'ssl' => 'False', 'query' => { 'read_timeout' => '60' }, }).and_return('rabbit://guest@127.0.0.1:5672/virt?read_timeout=60&ssl=0') end it 'with alternative transport and single host array for hosts' do is_expected.to run.with_params({ 'transport' => 'amqp', 'hosts' => [ '127.0.0.1' ], 'port' => '5672', 'username' => 'guest', 'password' => '<PASSWORD>', }).and_return('amqp://guest:s3cr3t@127.0.0.1:5672/') end end end
hoperays/openstack-ha-puppet-module
neutron/spec/acceptance/basic_neutron_spec.rb
<filename>neutron/spec/acceptance/basic_neutron_spec.rb<gh_stars>0 require 'spec_helper_acceptance' describe 'basic neutron' do context 'default parameters' do it 'should work with no errors' do pp= <<-EOS include ::openstack_integration include ::openstack_integration::repos include ::openstack_integration::rabbitmq include ::openstack_integration::mysql include ::openstack_integration::keystone rabbitmq_user { 'neutron': admin => true, password => '<PASSWORD>', provider => 'rabbitmqctl', require => Class['rabbitmq'], } rabbitmq_user_permissions { 'neutron@/': configure_permission => '.*', write_permission => '.*', read_permission => '.*', provider => 'rabbitmqctl', require => Class['rabbitmq'], } Rabbitmq_user_permissions['neutron@/'] -> Service<| tag == 'neutron-service' |> # Neutron resources class { '::neutron': rabbit_user => 'neutron', rabbit_password => '<PASSWORD>', rabbit_host => '127.0.0.1', allow_overlapping_ips => true, core_plugin => 'ml2', debug => true, service_plugins => ['router', 'metering'], } class { '::neutron::db::mysql': password => '<PASSWORD>', } class { '::neutron::keystone::auth': password => '<PASSWORD>', } class { '::neutron::plugins::ml2': type_drivers => ['vxlan'], tenant_network_types => ['vxlan'], mechanism_drivers => ['openvswitch'], } class { '::neutron::server': database_connection => 'mysql+pymysql://neutron:a_big_secret@127.0.0.1/neutron?charset=utf8', password => '<PASSWORD>', auth_url => 'http://127.0.0.1:35357/', sync_db => true, service_providers => [ 'LOADBALANCERV2:Haproxy:neutron_lbaas.drivers.haproxy.plugin_driver.HaproxyOnHostPluginDriver' ], } class { '::neutron::client': } class { '::neutron::quota': } class { '::neutron::agents::dhcp': debug => true } class { '::neutron::agents::l3': debug => true } class { '::neutron::agents::lbaas': debug => true, } class { '::neutron::agents::metering': debug => true } class { '::neutron::agents::ml2::ovs': local_ip => '127.0.0.1', tunnel_types => ['vxlan'], # Prior to Newton, the neutron-openvswitch-agent used 'ovs-ofctl' of_interface driver by default. # In Newton, 'of_interface' defaults to 'native'. # This mostly eliminates spawning ovs-ofctl and improves performance a little. # Current openstack-selinux does not allow the Ryu controller to listen on 6633 port. # So in the meantime, let's use old interface: of_interface => 'ovs-ofctl', ovsdb_interface => 'vsctl', } class { '::neutron::services::lbaas::haproxy': } class { '::neutron::services::lbaas::octavia': } EOS # Run it twice and test for idempotency apply_manifest(pp, :catch_failures => true) apply_manifest(pp, :catch_changes => true) end describe 'test Neutron OVS agent bridges' do it 'should list OVS bridges' do shell("ovs-vsctl show") do |r| expect(r.stdout).to match(/br-int/) expect(r.stdout).to match(/br-tun/) end end end end end
hoperays/openstack-ha-puppet-module
glance/spec/classes/glance_notify_rabbitmq_spec.rb
<gh_stars>0 require 'spec_helper' describe 'glance::notify::rabbitmq' do shared_examples_for 'glance::notify::rabbitmq' do describe 'when defaults with rabbit pass specified' do it { is_expected.to contain_glance_api_config('DEFAULT/transport_url').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_api_config('oslo_messaging_notifications/transport_url').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_api_config('oslo_messaging_notifications/driver').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/rabbit_password').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/rabbit_password').with_value('<SERVICE DEFAULT>').with_secret(true) } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/rabbit_userid').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/rabbit_host').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/rabbit_port').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/rabbit_hosts').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/amqp_durable_queues').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/rabbit_virtual_host').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/default_notification_exchange').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_api_config('oslo_messaging_notifications/topics').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/heartbeat_timeout_threshold').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/heartbeat_rate').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/kombu_reconnect_delay').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_registry_config('DEFAULT/transport_url').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_registry_config('oslo_messaging_notifications/transport_url').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_registry_config('oslo_messaging_notifications/driver').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/rabbit_password').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/rabbit_password').with_value('<SERVICE DEFAULT>').with_secret(true) } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/rabbit_userid').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/rabbit_host').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/rabbit_port').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/rabbit_hosts').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/amqp_durable_queues').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/rabbit_virtual_host').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/default_notification_exchange').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_registry_config('oslo_messaging_notifications/topics').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/heartbeat_timeout_threshold').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/heartbeat_rate').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/kombu_reconnect_delay').with_value('<SERVICE DEFAULT>') } end describe 'when passing params and use ssl' do let :params do { :rabbit_password => '<PASSWORD>', :rabbit_userid => 'guest2', :rabbit_host => 'localhost2', :rabbit_port => '5673', :rabbit_use_ssl => true, :rabbit_durable_queues => true, :kombu_reconnect_delay => '5.0' } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/rabbit_userid').with_value('guest2') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/rabbit_host').with_value('localhost2') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/rabbit_port').with_value('5673') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('true') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/rabbit_durable_queues').with_value(true) } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/kombu_reconnect_delay').with_value('5.0') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/rabbit_userid').with_value('guest2') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/rabbit_host').with_value('localhost2') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/rabbit_port').with_value('5673') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value(true) } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/rabbit_durable_queues').with_value(true) } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/kombu_reconnect_delay').with_value('5.0') } end end describe 'with rabbit ssl cert parameters' do let :params do { :rabbit_use_ssl => true, :kombu_ssl_ca_certs => '/etc/ca.cert', :kombu_ssl_certfile => '/etc/certfile', :kombu_ssl_keyfile => '/etc/key', :kombu_ssl_version => 'TLSv1', } end it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value(true) } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('/etc/ca.cert') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('/etc/certfile') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('/etc/key') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('TLSv1') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value(true) } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('/etc/ca.cert') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('/etc/certfile') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('/etc/key') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('TLSv1') } end describe 'with rabbit ssl disabled' do let :params do { :rabbit_use_ssl => false, } end it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value(false) } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value(false) } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('<SERVICE DEFAULT>') } end describe 'when passing params for single rabbit host' do let :params do { :rabbit_password => '<PASSWORD>', :rabbit_userid => 'guest2', :rabbit_host => 'localhost2', :rabbit_port => '5673', :rabbit_use_ssl => true, :amqp_durable_queues => true, } end it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/rabbit_userid').with_value('guest2') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/rabbit_host').with_value('localhost2') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/rabbit_port').with_value('5673') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/rabbit_hosts').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value(true) } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/amqp_durable_queues').with_value(true) } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/rabbit_userid').with_value('guest2') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/rabbit_host').with_value('localhost2') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/rabbit_port').with_value('5673') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/rabbit_hosts').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value(true) } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/amqp_durable_queues').with_value(true) } end describe 'when passing params for multiple rabbit hosts' do let :params do { :rabbit_password => '<PASSWORD>', :rabbit_userid => 'guest3', :rabbit_hosts => ['nonlocalhost3:5673', 'nonlocalhost4:5673'] } end it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/rabbit_userid').with_value('guest3') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/rabbit_hosts').with_value('nonlocalhost3:5673,nonlocalhost4:5673') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value(true) } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/rabbit_port').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/rabbit_host').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/rabbit_userid').with_value('guest3') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/rabbit_hosts').with_value('nonlocalhost3:5673,nonlocalhost4:5673') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value(true) } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/rabbit_port').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/rabbit_host').with_value('<SERVICE DEFAULT>') } end describe 'a single rabbit_host with enable ha queues' do let :params do { :rabbit_password => '<PASSWORD>', :rabbit_userid => 'guest3', :rabbit_ha_queues => true, } end it 'should contain rabbit_ha_queues' do is_expected.to contain_glance_api_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('true') is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('true') end end describe 'when passing params for rabbitmq heartbeat' do let :params do { :rabbit_heartbeat_timeout_threshold => '60', :rabbit_heartbeat_rate => '10', } end it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/heartbeat_timeout_threshold').with_value('60') } it { is_expected.to contain_glance_api_config('oslo_messaging_rabbit/heartbeat_rate').with_value('10') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/heartbeat_timeout_threshold').with_value('60') } it { is_expected.to contain_glance_registry_config('oslo_messaging_rabbit/heartbeat_rate').with_value('10') } end describe 'when passing params transport_url' do let :params do { :default_transport_url => 'rabbit://user:pass@host:1234/virt', } end it { is_expected.to contain_glance_api_config('DEFAULT/transport_url').with_value('rabbit://user:pass@host:1234/virt') } it { is_expected.to contain_glance_registry_config('DEFAULT/transport_url').with_value('rabbit://user:pass@host:1234/virt') } end end on_supported_os({ :supported_os => OSDefaults.get_supported_os }).each do |os,facts| context "on #{os}" do let (:facts) do facts.merge!(OSDefaults.get_facts()) end it_configures 'glance::notify::rabbitmq' end end end
hoperays/openstack-ha-puppet-module
trove/spec/classes/trove_quota_spec.rb
require 'spec_helper' describe 'trove::quota' do describe 'with default parameters' do it 'contains default values' do is_expected.to contain_trove_config('DEFAULT/max_instances_per_tenant').with( :value => 5) is_expected.to contain_trove_config('DEFAULT/max_accepted_volume_size').with( :value => 5) is_expected.to contain_trove_config('DEFAULT/max_volumes_per_tenant').with( :value => 20) is_expected.to contain_trove_config('DEFAULT/max_backups_per_tenant').with( :value => 50) is_expected.to contain_trove_config('DEFAULT/quota_driver').with( :value => 'trove.quota.quota.DbQuotaDriver') end end describe 'with overridden parameters' do let :params do { :max_instances_per_tenant => 10, :max_accepted_volume_size => 10, :max_volumes_per_tenant => 100, :max_backups_per_tenant => 100, } end it 'contains overrided values' do is_expected.to contain_trove_config('DEFAULT/max_instances_per_tenant').with( :value => 10) is_expected.to contain_trove_config('DEFAULT/max_accepted_volume_size').with( :value => 10) is_expected.to contain_trove_config('DEFAULT/max_volumes_per_tenant').with( :value => 100) is_expected.to contain_trove_config('DEFAULT/max_backups_per_tenant').with( :value => 100) end end end
hoperays/openstack-ha-puppet-module
cinder/spec/classes/cinder_volume_glusterfs_spec.rb
<gh_stars>0 require 'spec_helper' describe 'cinder::volume::glusterfs' do shared_examples_for 'glusterfs volume driver' do let :params do { :glusterfs_shares => ['10.10.10.10:/volumes', '10.10.10.11:/volumes'], :glusterfs_shares_config => '/etc/cinder/other_shares.conf', :glusterfs_sparsed_volumes => true, :glusterfs_mount_point_base => '/cinder_mount_point', } end it 'configures glusterfs volume driver' do is_expected.to contain_cinder_config('DEFAULT/volume_driver').with_value('cinder.volume.drivers.glusterfs.GlusterfsDriver') is_expected.to contain_cinder_config('DEFAULT/glusterfs_shares_config').with_value('/etc/cinder/other_shares.conf') is_expected.to contain_cinder_config('DEFAULT/glusterfs_sparsed_volumes').with_value(true) is_expected.to contain_cinder_config('DEFAULT/glusterfs_mount_point_base').with_value('/cinder_mount_point') is_expected.to contain_cinder_config('DEFAULT/glusterfs_backup_mount_point').with_value('<SERVICE DEFAULT>') is_expected.to contain_cinder_config('DEFAULT/glusterfs_backup_share').with_value('<SERVICE DEFAULT>') is_expected.to contain_file('/etc/cinder/other_shares.conf').with( :content => "10.10.10.10:/volumes\n10.10.10.11:/volumes\n", :require => 'Anchor[cinder::install::end]', :notify => 'Anchor[cinder::service::begin]' ) end context 'glusterfs volume driver with additional configuration' do before do params.merge!({:extra_options => {'glusterfs_backend/param1' => { 'value' => 'value1' }}}) end it 'configure glusterfs volume with additional configuration' do is_expected.to contain_cinder__backend__glusterfs('DEFAULT').with({ :extra_options => {'glusterfs_backend/param1' => {'value' => 'value1'}} }) end end end on_supported_os({ :supported_os => OSDefaults.get_supported_os }).each do |os,facts| context "on #{os}" do let (:facts) do facts.merge(OSDefaults.get_facts({:processorcount => 8})) end it_configures 'glusterfs volume driver' end end end
hoperays/openstack-ha-puppet-module
vswitch/spec/classes/vswitch_dpdk_spec.rb
<reponame>hoperays/openstack-ha-puppet-module require 'spec_helper' describe 'vswitch::dpdk' do let :default_params do { :package_ensure => 'present', :core_list => '1,2', :memory_channels => '2', } end let :redhat_platform_params do { :ovs_dpdk_package_name => 'openvswitch', :ovs_service_name => 'openvswitch', :provider => 'ovs_redhat', } end shared_examples_for 'vswitch dpdk' do it 'contains params' do is_expected.to contain_class('vswitch::params') end it 'configures service' do is_expected.to contain_service('openvswitch').with( :ensure => true, :enable => true, :name => platform_params[:ovs_service_name], :hasstatus => platform_params[:service_hasstatus], :status => platform_params[:service_status], ) end it 'install package' do is_expected.to contain_package(platform_params[:ovs_dpdk_package_name]).with( :name => platform_params[:ovs_dpdk_package_name], :ensure => params[:package_ensure], :before => 'Service[openvswitch]', ) end end shared_examples_for 'vswitch dpdk mandatory params' do it 'configures dpdk options for ovs' do is_expected.to contain_file_line('/etc/sysconfig/openvswitch').with( :path => '/etc/sysconfig/openvswitch', :match => '^DPDK_OPTIONS.*', :line => 'DPDK_OPTIONS = "-l 1,2 -n 2 "', :before => 'Service[openvswitch]', ) end end shared_examples_for 'vswitch dpdk additional params' do context 'when passing socket mem' do before :each do params.merge!(:socket_mem => '1024') end it 'configures dpdk options with socket memory' do is_expected.to contain_file_line('/etc/sysconfig/openvswitch').with( :path => '/etc/sysconfig/openvswitch', :match => '^DPDK_OPTIONS.*', :line => 'DPDK_OPTIONS = "-l 1,2 -n 2 --socket-mem 1024 "', :before => 'Service[openvswitch]', ) end end context 'when providing valid driver type facts' do before :each do params.merge!(:driver_type => 'test') end it 'configures dpdk options with pci address for driver test' do is_expected.to contain_file_line('/etc/sysconfig/openvswitch').with( :path => '/etc/sysconfig/openvswitch', :match => '^DPDK_OPTIONS.*', :line => 'DPDK_OPTIONS = "-l 1,2 -n 2 -w 0000:00:05.0 -w 0000:00:05.1"', :before => 'Service[openvswitch]', ) end end end shared_examples_for 'vswitch dpdk for modprobe' do it 'should have dpdk driver modules file' do is_expected.to contain_kmod__load('vfio-pci') end end context 'on redhat with only mandatory parameters' do let :params do default_params end let :facts do OSDefaults.get_facts({ :osfamily => 'Redhat', :ovs_version => '1.4.2', }) end let :platform_params do redhat_platform_params end it_configures 'vswitch dpdk' it_configures 'vswitch dpdk mandatory params' end context 'on redhat with additonal parameters' do let :params do default_params end let :facts do OSDefaults.get_facts({ :osfamily => 'Redhat', :ovs_version => '1.4.2', :pci_address_driver_test => '0000:00:05.0,0000:00:05.1' }) end let :platform_params do redhat_platform_params end it_configures 'vswitch dpdk' it_configures 'vswitch dpdk additional params' it_configures 'vswitch dpdk for modprobe' end end
hoperays/openstack-ha-puppet-module
ceilometer/spec/classes/ceilometer_agent_central_spec.rb
require 'spec_helper' describe 'ceilometer::agent::central' do let :pre_condition do "class { 'ceilometer': telemetry_secret => 's3cr3t' }" end let :params do { :enabled => true, :manage_service => true, :package_ensure => 'latest', :coordination_url => 'redis://localhost:6379' } end shared_examples_for 'ceilometer-agent-central' do it { is_expected.to contain_class('ceilometer::params') } it 'installs ceilometer-agent-central package' do is_expected.to contain_package('ceilometer-agent-central').with( :ensure => 'latest', :name => platform_params[:agent_package_name], :before => ['Service[ceilometer-agent-central]'], :tag => ['openstack', 'ceilometer-package'], ) end it 'ensures ceilometer-common is installed before the service' do is_expected.to contain_package('ceilometer-common').with( :before => /Service\[ceilometer-agent-central\]/ ) end [{:enabled => true}, {:enabled => false}].each do |param_hash| context "when service should be #{param_hash[:enabled] ? 'enabled' : 'disabled'}" do before do params.merge!(param_hash) end it 'configures ceilometer-agent-central service' do is_expected.to contain_service('ceilometer-agent-central').with( :ensure => (params[:manage_service] && params[:enabled]) ? 'running' : 'stopped', :name => platform_params[:agent_service_name], :enable => params[:enabled], :hasstatus => true, :hasrestart => true, :tag => 'ceilometer-service', ) end end end it 'configures central agent' do is_expected.to contain_ceilometer_config('coordination/backend_url').with_value( params[:coordination_url] ) end context 'with disabled service managing' do before do params.merge!({ :manage_service => false, :enabled => false }) end it 'configures ceilometer-agent-central service' do is_expected.to contain_service('ceilometer-agent-central').with( :ensure => nil, :name => platform_params[:agent_service_name], :enable => false, :hasstatus => true, :hasrestart => true, :tag => 'ceilometer-service', ) end end end context 'on Debian platforms' do let :facts do @default_facts.merge({ :osfamily => 'Debian' }) end let :platform_params do { :agent_package_name => 'ceilometer-agent-central', :agent_service_name => 'ceilometer-agent-central' } end it_configures 'ceilometer-agent-central' end context 'on RedHat platforms' do let :facts do @default_facts.merge({ :osfamily => 'RedHat' }) end let :platform_params do { :agent_package_name => 'openstack-ceilometer-central', :agent_service_name => 'openstack-ceilometer-central' } end it_configures 'ceilometer-agent-central' end end
hoperays/openstack-ha-puppet-module
ceilometer/spec/classes/ceilometer_api_spec.rb
require 'spec_helper' describe 'ceilometer::api' do let :pre_condition do "class { 'ceilometer': telemetry_secret => 's3cr3t' } include ::ceilometer::db" end let :params do { :enabled => true, :manage_service => true, :keystone_password => '<PASSWORD>', :host => '0.0.0.0', :port => '8777', :package_ensure => 'latest', } end shared_examples_for 'ceilometer-api' do it { is_expected.to contain_class('ceilometer::params') } it { is_expected.to contain_class('ceilometer::policy') } it { is_expected.to contain_class('ceilometer::keystone::authtoken') } it 'installs ceilometer-api package' do is_expected.to contain_package('ceilometer-api').with( :ensure => 'latest', :name => platform_params[:api_package_name], :tag => ['openstack', 'ceilometer-package'], ) end it 'configures api' do is_expected.to contain_ceilometer_config('api/host').with_value( params[:host] ) is_expected.to contain_ceilometer_config('api/port').with_value( params[:port] ) is_expected.to contain_ceilometer_config('api/workers').with_value('<SERVICE DEFAULT>') is_expected.to contain_ceilometer_config('oslo_middleware/enable_proxy_headers_parsing').with_value('<SERVICE DEFAULT>') end [{:enabled => true}, {:enabled => false}].each do |param_hash| context "when service should be #{param_hash[:enabled] ? 'enabled' : 'disabled'}" do before do params.merge!(param_hash) end it 'configures ceilometer-api service' do is_expected.to contain_service('ceilometer-api').with( :ensure => (params[:manage_service] && params[:enabled]) ? 'running' : 'stopped', :name => platform_params[:api_service_name], :enable => params[:enabled], :hasstatus => true, :hasrestart => true, :require => 'Class[Ceilometer::Db]', :tag => 'ceilometer-service', ) end end end context 'with deprecated parameters' do before do params.merge!({ :auth_uri => 'https://10.0.0.1:5000/deprecated', :keystone_user => 'myuser', :keystone_password => '<PASSWORD>', :identity_uri => 'http://10.0.0.1:35357/deprecated', :keystone_tenant => 'service_project', :memcached_servers => ['memcached01:11211','memcached02:11211'], }) end it 'configures keystone_authtoken middleware' do is_expected.to contain_ceilometer_config( 'keystone_authtoken/auth_uri').with_value(params[:auth_uri]) is_expected.to contain_ceilometer_config( 'keystone_authtoken/username').with_value(params[:keystone_user]) is_expected.to contain_ceilometer_config( 'keystone_authtoken/password').with_value(params[:keystone_password]).with_secret(true) is_expected.to contain_ceilometer_config( 'keystone_authtoken/auth_url').with_value(params[:identity_uri]) is_expected.to contain_ceilometer_config( 'keystone_authtoken/project_name').with_value(params[:keystone_tenant]) is_expected.to contain_ceilometer_config( 'keystone_authtoken/memcached_servers').with_value('memcached01:11211,memcached02:11211') end end context 'with enable_proxy_headers_parsing' do before do params.merge!({:enable_proxy_headers_parsing => true }) end it { is_expected.to contain_ceilometer_config('oslo_middleware/enable_proxy_headers_parsing').with_value(true) } end context 'with disabled service managing' do before do params.merge!({ :manage_service => false, :enabled => false }) end it 'configures ceilometer-api service' do is_expected.to contain_service('ceilometer-api').with( :ensure => nil, :name => platform_params[:api_service_name], :enable => false, :hasstatus => true, :hasrestart => true, :tag => 'ceilometer-service', ) end end context 'when running ceilometer-api in wsgi' do before do params.merge!({ :service_name => 'httpd' }) end let :pre_condition do "include ::apache include ::ceilometer::db class { 'ceilometer': telemetry_secret => 's3cr3t' }" end it 'configures ceilometer-api service with Apache' do is_expected.to contain_service('ceilometer-api').with( :ensure => 'stopped', :name => platform_params[:api_service_name], :enable => false, :tag => 'ceilometer-service', ) end end context 'when service_name is not valid' do before do params.merge!({ :service_name => 'foobar' }) end let :pre_condition do "include ::apache include ::ceilometer::db class { 'ceilometer': telemetry_secret => 's3cr3t' }" end it_raises 'a Puppet::Error', /Invalid service_name/ end end context 'on Debian platforms' do let :facts do @default_facts.merge({ :osfamily => 'Debian', :operatingsystem => 'Debian', :operatingsystemrelease => '8.0', :concat_basedir => '/var/lib/puppet/concat', :fqdn => 'some.host.tld', :processorcount => 2 }) end let :platform_params do { :api_package_name => 'ceilometer-api', :api_service_name => 'ceilometer-api' } end it_configures 'ceilometer-api' end context 'on RedHat platforms' do let :facts do @default_facts.merge({ :osfamily => 'RedHat', :operatingsystem => 'RedHat', :operatingsystemrelease => '7.1', :operatingsystemmajrelease => '7', :fqdn => 'some.host.tld', :concat_basedir => '/var/lib/puppet/concat', :processorcount => 2 }) end let :platform_params do { :api_package_name => 'openstack-ceilometer-api', :api_service_name => 'openstack-ceilometer-api' } end it_configures 'ceilometer-api' end end
hoperays/openstack-ha-puppet-module
vswitch/spec/unit/puppet/lib/type/vs_config_spec.rb
require 'spec_helper' describe Puppet::Type.type(:vs_config) do it "should support present as a value for ensure" do expect do described_class.new(:name => 'foo', :ensure => :present) end.to_not raise_error end it "should support absent as a value for ensure" do expect do described_class.new(:name => 'foo', :ensure => :absent) end.to_not raise_error end it "should have a :value parameter" do expect(described_class.attrtype(:value)).to eq(:property) end it "should accept only string values" do expect do described_class.new({:name => "foo", :value => 123, :ensure => :present}) end.to raise_error(Puppet::Error) end it "should munge array values" do expect( described_class.new({:name => "foo", :value => "[2, 1, 3, 0]", :ensure => :present})[:value] ).to eq "[0,1,2,3]" end end
hoperays/openstack-ha-puppet-module
cinder/spec/classes/cinder_db_sync_spec.rb
require 'spec_helper' describe 'cinder::db::sync' do shared_examples_for 'cinder-dbsync' do it 'runs cinder-manage db_sync' do is_expected.to contain_exec('cinder-manage db_sync').with( :command => 'cinder-manage db sync', :user => 'cinder', :path => '/usr/bin', :refreshonly => 'true', :logoutput => 'on_failure' ) end describe "overriding extra_params" do let :params do { :extra_params => '--config-file /etc/cinder/cinder.conf', } end it { is_expected.to contain_exec('cinder-manage db_sync').with( :command => 'cinder-manage --config-file /etc/cinder/cinder.conf db sync', :user => 'cinder', :path => '/usr/bin', :refreshonly => 'true', :logoutput => 'on_failure' ) } end end on_supported_os({ :supported_os => OSDefaults.get_supported_os }).each do |os,facts| context "on #{os}" do let (:facts) do facts.merge(OSDefaults.get_facts({ :processorcount => 8, :concat_basedir => '/var/lib/puppet/concat' })) end it_configures 'cinder-dbsync' end end end
hoperays/openstack-ha-puppet-module
ceilometer/spec/classes/ceilometer_db_spec.rb
<gh_stars>0 require 'spec_helper' describe 'ceilometer::db' do shared_examples 'ceilometer::db' do context 'with default parameters' do it { is_expected.to contain_ceilometer_config('database/db_max_retries').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_class('ceilometer::params') } it { is_expected.to contain_class('ceilometer::db::sync') } it { is_expected.to contain_ceilometer_config('database/connection').with_value('mysql://ceilometer:ceilometer@localhost/ceilometer').with_secret(true) } it { is_expected.to contain_ceilometer_config('database/idle_timeout').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_ceilometer_config('database/min_pool_size').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_ceilometer_config('database/max_retries').with_value('<SERVICE DEFAULT>') } it { is_expected.to contain_ceilometer_config('database/retry_interval').with_value('<SERVICE DEFAULT>') } end context 'with specific parameters' do let :params do { :database_db_max_retries => '-1', :database_connection => 'mongodb://localhost:1234/ceilometer', :database_idle_timeout => '3601', :database_min_pool_size => '2', :database_max_retries => '11', :database_retry_interval => '11', :sync_db => false } end it { is_expected.to contain_ceilometer_config('database/db_max_retries').with_value('-1') } it { is_expected.not_to contain_class('ceilometer::db::sync') } it { is_expected.to contain_ceilometer_config('database/connection').with_value('mongodb://localhost:1234/ceilometer').with_secret(true) } it { is_expected.to contain_ceilometer_config('database/idle_timeout').with_value('3601') } it { is_expected.to contain_ceilometer_config('database/min_pool_size').with_value('2') } it { is_expected.to contain_ceilometer_config('database/max_retries').with_value('11') } it { is_expected.to contain_ceilometer_config('database/retry_interval').with_value('11') } end context 'with pymysql connection' do let :params do { :database_connection => 'mysql+pymysql://ceilometer:ceilometer@localhost/ceilometer' } end it { is_expected.to contain_class('ceilometer::params') } it { is_expected.to contain_class('ceilometer::db::sync') } it { is_expected.to contain_ceilometer_config('database/connection').with_value('mysql+pymysql://ceilometer:ceilometer@localhost/ceilometer').with_secret(true) } end context 'with mongodb backend' do let :params do { :database_connection => 'mongodb://localhost:1234/ceilometer' } end it 'install the proper backend package' do is_expected.to contain_package('db_backend_package').with( :ensure => 'present', :name => 'python-pymongo', :tag => 'openstack' ) end end context 'with incorrect database_connection string' do let :params do { :database_connection => 'redis://ceilometer:ceilometer@localhost/ceilometer', } end it_raises 'a Puppet::Error', /validate_re/ end context 'with postgresql backend' do let :params do { :database_connection => 'postgresql://ceilometer:ceilometer@localhost/ceilometer', } end it 'install the proper backend package' do is_expected.to contain_package('python-psycopg2').with(:ensure => 'present') end end context 'with incorrect pymysql database_connection string' do let :params do { :database_connection => 'foo+pymysql://ceilometer:ceilometer@localhost/ceilometer', } end it_raises 'a Puppet::Error', /validate_re/ end end context 'on Debian platforms' do let :facts do @default_facts.merge({ :osfamily => 'Debian', :operatingsystem => 'Debian', :operatingsystemrelease => 'jessie', }) end it_configures 'ceilometer::db' context 'using pymysql driver' do let :params do { :database_connection => 'mysql+pymysql:///ceilometer:ceilometer@localhost/ceilometer', } end it 'install the proper backend package' do is_expected.to contain_package('db_backend_package').with( :ensure => 'present', :name => 'python-pymysql', :tag => 'openstack' ) end end context 'with sqlite backend' do let :params do { :database_connection => 'sqlite:///var/lib/ceilometer.db', } end it 'install the proper backend package' do is_expected.to contain_package('db_backend_package').with( :ensure => 'present', :name => 'python-pysqlite2', :tag => 'openstack' ) end end end context 'on Redhat platforms' do let :facts do @default_facts.merge({ :osfamily => 'RedHat', :operatingsystemrelease => '7.1', }) end it_configures 'ceilometer::db' context 'using pymysql driver' do let :params do { :database_connection => 'mysql+pymysql:///ceilometer:ceilometer@localhost/ceilometer', } end it { is_expected.not_to contain_package('db_backend_package') } end end end
hoperays/openstack-ha-puppet-module
aodh/spec/acceptance/aodh_wsgi_apache_spec.rb
require 'spec_helper_acceptance' describe 'basic aodh' do context 'default parameters' do it 'should work with no errors' do pp= <<-EOS include ::openstack_integration include ::openstack_integration::repos include ::openstack_integration::rabbitmq include ::openstack_integration::mysql include ::openstack_integration::keystone rabbitmq_user { 'aodh': admin => true, password => '<PASSWORD>', provider => 'rabbitmqctl', require => Class['rabbitmq'], } rabbitmq_user_permissions { 'aodh@/': configure_permission => '.*', write_permission => '.*', read_permission => '.*', provider => 'rabbitmqctl', require => Class['rabbitmq'], } # https://bugs.launchpad.net/aodh/+bug/1557154 Rabbitmq_user_permissions['aodh@/'] -> Service<| tag == 'aodh-service' |> class { '::aodh': rabbit_userid => 'aodh', rabbit_password => '<PASSWORD>', debug => true, rabbit_host => '127.0.0.1', database_connection => 'mysql://aodh:a_big_secret@127.0.0.1/aodh?charset=utf8', } class { '::aodh::db::mysql': password => '<PASSWORD>', } class { '::aodh::keystone::auth': password => '<PASSWORD>', } class { '::aodh::keystone::authtoken': password => '<PASSWORD>', } class { '::aodh::api': enabled => true, service_name => 'httpd', } include ::apache class { '::aodh::wsgi::apache': ssl => false, } class { '::aodh::auth': auth_url => 'http://127.0.0.1:5000/v2.0', auth_password => '<PASSWORD>', } class { '::aodh::client': } class { '::aodh::notifier': } class { '::aodh::listener': } class { '::aodh::evaluator': } class { '::aodh::db::sync': } EOS # Run it twice and test for idempotency apply_manifest(pp, :catch_failures => true) apply_manifest(pp, :catch_changes => true) end describe port(8042) do it { is_expected.to be_listening } end end end
hoperays/openstack-ha-puppet-module
ceilometer/spec/classes/ceilometer_dispatcher_gnocchi_spec.rb
require 'spec_helper' describe 'ceilometer::dispatcher::gnocchi' do let :pre_condition do "class { 'ceilometer': telemetry_secret => 's3cr3t' }" end let :params do {} end shared_examples_for 'ceilometer-gnocchi-dispatcher' do it 'configures gnocchi dispatcher' do is_expected.to contain_ceilometer_config('dispatcher_gnocchi/filter_service_activity').with_value('<SERVICE DEFAULT>') is_expected.to contain_ceilometer_config('dispatcher_gnocchi/filter_project').with_value('<SERVICE DEFAULT>') is_expected.to contain_ceilometer_config('dispatcher_gnocchi/url').with_value('<SERVICE DEFAULT>') is_expected.to contain_ceilometer_config('dispatcher_gnocchi/archive_policy').with_value('<SERVICE DEFAULT>') is_expected.to contain_ceilometer_config('dispatcher_gnocchi/resources_definition_file').with_value('<SERVICE DEFAULT>') end context 'when overriding parameters' do before do params.merge!(:filter_service_activity => false, :filter_project => 'gnocchi_swift', :url => 'http://foo', :archive_policy => 'high', :resources_definition_file => 'foo') end it { is_expected.to contain_ceilometer_config('dispatcher_gnocchi/filter_service_activity').with_value('false') } it { is_expected.to contain_ceilometer_config('dispatcher_gnocchi/filter_project').with_value('gnocchi_swift') } it { is_expected.to contain_ceilometer_config('dispatcher_gnocchi/url').with_value('http://foo') } it { is_expected.to contain_ceilometer_config('dispatcher_gnocchi/archive_policy').with_value('high') } it { is_expected.to contain_ceilometer_config('dispatcher_gnocchi/resources_definition_file').with_value('foo') } end end context 'on Debian platforms' do let :facts do @default_facts.merge({ :osfamily => 'Debian' }) end it_configures 'ceilometer-gnocchi-dispatcher' end context 'on RedHat platforms' do let :facts do @default_facts.merge({ :osfamily => 'RedHat' }) end it_configures 'ceilometer-gnocchi-dispatcher' end end
dbrandt1990/CLI_Data_Gem_BoardGames
lib/board_games/cli.rb
require_relative './game.rb' require_relative './api.rb' require 'colorize' class BoardGames::CLI def call create_games_list list_games(@games) menu(@games) goodbye end def create_games_list BoardGames::API.new().create_game_objects @games = BoardGames::Game.all puts "Sorry, there was an error loading the games list.".red if @games == [] end def list_games(games, number = 10) puts "\n\t======== Current Top #{number.to_s.green} boardgames ========".bold games.each_with_index do |game, i| if i < number puts "\t\t\s\s\s\s#{i + 1}. #{game.name}" end end end def help_message puts "\n- #{'filter'.green} = opens menu to filter game list" puts "- #{'list'.green} = reprint current game list in console" puts "- #{'list more'.green} = adds 10 games to the current game list" puts "- #{'less'.green}= removes 10 games from current game list, minnimum of 10" puts "- #{'exit'.green} = leaves filtered list, if filter is applied, else exits CLI and clears console" end def filter_menu puts "\n-------WELCOME TO THE FILTER MENU--------\n".green puts "TYPE A COMMAND FROM BELOW AND HIT ENTER: ---price ---year ---players ---playtime ---age".yellow input = gets.strip.downcase input_valid = true case input when "price" puts "\nType a maximum price #{'ex: 20'.red}" input = gets.strip filtered_games = @games.select{|game| game.price.to_f <= input.to_f} when "year" puts "\nType a year and see the if any of the top 100 games came out that year!" input = gets.strip filtered_games = @games.select{|game| game.year_published.to_i <= input.to_i} when "players" puts "\nType the min and max number of players #{'ex: 1-5'.red}" input = gets.strip.split('-') filtered_games = @games.select{|game| players = game.players.split('-') players[0].to_i >= input[0].to_i && players[1].to_i <= input[1].to_i} when "playtime" puts "\nType the min and max playtime in minutes #{'ex: 60-90'.red}" input = gets.strip.split('-') filtered_games = @games.select{|game| pt = game.playtime.split('-') pt[0].to_i >= input[0].to_i && pt[1].to_i <= input[1].to_i} when "age" puts "\nType the minnimum age requirement you'd like" input = gets.strip.downcase filtered_games ||= @games.select{|game| game.min_age.to_i <= input.to_i} when "help" help_message filter_menu else input_valid = false puts "INVALID INPUT".red puts "Type #{'help'.yellow} for a list of commands" filter_menu end if input_valid list_games(filtered_games) menu(filtered_games, filter_mode = 1) end end def menu(games, filter_mode = 0) number = 10 #default 10, if 'more'/'less' is typed, add/remove 10 to this to change the length of game list. filter_mode == 2 ? input = "exit" : input = nil # start with nil input to allow while loop to begin, or set to exit after exiting so the loop will end while input != "exit" puts "\n\t\tType 'exit' to remove filter".blue if filter_mode == 1 puts "\nEnter the number of the game you'd like to know more about, or type #{'help'.yellow} for a list of commands:" input = gets.strip.downcase if input == "filter" if filter_mode == 0 filter_menu else filter_menu input = "exit" end elsif input == "help" help_message elsif input == "list" list_games(games, number) elsif input == "list more" number + 10 <= games.length - 1 ? number += 10 : number = games.length - 1 list_games(games, number) if number == 100 puts "\n!!!THE LIST ONLY GOES TO 100!!!\n".yellow end elsif input == "less" number -= 10 if number > 10 list_games(games, number) elsif input == "exit" && filter_mode == 0 || filter_mode == 2 system("clear") elsif input == "exit" && filter_mode == 1 list_games(@games) puts "\t\tDisplaying unfiltered list".blue menu(@games, filter_mode = 2) #maybe try t oput this (displaying and getting more info from games) to it's own method, so it could be used in the filter menu elsif games[input.to_i - 1] && input.to_i !=0 && input.to_i <= number game = games[input.to_i - 1] puts "\n 'CLICK TO SEE IMAGE #{game.image.cyan}" puts "\nName: #{game.name}" puts "Price: $#{game.price}" puts "Year: #{game.year_published}" puts "Players: #{game.players}" puts "Playtime: #{game.playtime} minutes" puts "Ages: #{game.min_age}+" puts "\nTO FIND OUT MORE ABOUT THIS GAME, TYPE #{"'more'".yellow} or press #{"'ENTER'".green} and type a new command.\n\n" input = gets.strip.downcase if input == "more" puts "\t\t\t=== #{game.name.upcase.bold.green.underline} ===" puts "\n#{game.description} \n\n" puts "\nCheck the rulebook out here: #{game.rules_url.cyan}\n\n" if game.rules_url elsif input == "help" help_message elsif input == "list" list_games(games, number) end else puts "INVALID INPUT".red puts "Type #{'help'.yellow} for a list of commands" end end end def goodbye puts "\t\t\ === See you next time! ===" end end
dbrandt1990/CLI_Data_Gem_BoardGames
lib/board_games/version.rb
<filename>lib/board_games/version.rb # frozen_string_literal: true module BoardGames VERSION = "0.1.0" end
dbrandt1990/CLI_Data_Gem_BoardGames
lib/board_games.rb
require_relative './board_games/version' require_relative './board_games/cli' require_relative './board_games/game' require_relative './board_games/api'
dbrandt1990/CLI_Data_Gem_BoardGames
lib/board_games/game.rb
class BoardGames::Game attr_reader :image, :name, :price, :year_published, :players, :playtime, :min_age, :description, :rules_url @@all = [] def initialize(image ="N/A", name ="N/A", price ="N/A", year_published ="N/A", players ="N/A", playtime ="N/A", min_age ="N/A", description ="N/A", rules_url ="No Rulebook PDF availible :(") @image = image @name = name @price = price @year_published = year_published @players = players @playtime = playtime @min_age = min_age @description = description @rules_url = rules_url @@all << self end def self.all @@all end end
dbrandt1990/CLI_Data_Gem_BoardGames
lib/board_games/api.rb
require_relative './game.rb' require 'httparty' class BoardGames::API include HTTParty def fetch_games url = "https://api.boardgameatlas.com/api/search?order_by=popularity&ascending=false&client_id=1vQCAipPrG" doc = HTTParty.get(url) data = doc.parsed_response #usting index of 1 to get into games list, data is {'games'[{gameobjects}]} data["games"] end def create_game_objects fetch_games.each_with_index do |game, i| image = game['image_url'] name = game['name'] price = game['price'] year_published = game['year_published'] players = "#{game['min_players']}-#{game['max_players']}" playtime = "#{game['min_playtime']}-#{game['max_playtime']}" min_age = "#{game['min_age']}" description = game['description_preview'].gsub('"',"'").strip rules_url = game['rules_url'] BoardGames::Game.new(image, name, price, year_published, players, playtime, min_age, description, rules_url) end end end
aemadrid/moneta
spec/moneta_redis_spec.rb
require File.dirname(__FILE__) + '/spec_helper' require "moneta/redis" describe "Moneta::Redis" do before(:each) do @native_expires = true @cache = Moneta::Redis.new @cache.clear end it_should_behave_like "a read/write Moneta cache" end
aemadrid/moneta
spec/moneta_mongodb_spec.rb
<filename>spec/moneta_mongodb_spec.rb require File.dirname(__FILE__) + '/spec_helper' require "moneta/mongodb" describe "Moneta::MongoDB" do before(:each) do @native_expires = true @cache = Moneta::MongoDB.new @cache.clear end it_should_behave_like "a read/write Moneta cache" end
aemadrid/moneta
lib/moneta/berkeley.rb
begin require 'bdb' rescue LoadError puts "You need bdb gem to use Bdb moneta store" exit end module Moneta class Berkeley def initialize(options={}) file = options[:file] @db = Bdb::Db.new() @db.open(nil, file, nil, Bdb::Db::BTREE, Bdb::DB_CREATE, 0) unless options[:skip_expires] @expiration = Moneta::Berkeley.new(:file => "#{file}_expiration", :skip_expires => true ) self.extend(Expires) # # specific Berkeley expiration fonctionality. Berkeley DB can't store Time object, only String. # self.extend(BerkeleyExpires) end end module BerkeleyExpires # # This specific extension convert Time into integer and then into string. # def check_expired(key) if @expiration[key] && Time.now > Time.at(@expiration[key].to_i) @expiration.delete(key) self.delete(key) end end private def update_options(key, options) if options[:expires_in] @expiration[key] = (Time.now + options[:expires_in]).to_i.to_s end end end module Implementation def key?(key) nil | self[key] end alias has_key? key? def []=(key,value) @db[key] = value end def store(key, value, options={}) @db[key] = value end def [](key) @db[key] end def fetch(key, default) self[key] || default end def delete(key) value = self[key] @db.del(nil,key,0) if value value end def clear @db.truncate(nil) end end include Implementation end end
aemadrid/moneta
benchmarks/various.rb
#!/usr/bin/env ruby require 'benchmark' # Hacked arrays # Array modifications class HackedArray < Array # Random keys/values attr_reader :keys_used def random_key(no_repeat = true, clean_keys_used = false) @keys_used = [] if clean_keys_used or @keys_used.nil? or @keys_used.size == self.size begin key = rand(self.size) end while no_repeat and @keys_used.include?(key) @keys_used << key return key end def random_value(no_repeat = true, clean_keys_used = false) values_at(random_key(no_repeat, clean_keys_used)).first end alias_method :random, :random_value def random_subset(n, no_repeat = true, clean_keys_used = true) (1..n).map{|x| random_value(no_repeat, (clean_keys_used && x == 1))} end def self.new_from_string(str) res = new str.split('').each{|x| res << x} res end end stores = { 'Redis' => { }, 'Memcached' => { :class_name => "Memcache", :server => "localhost:11211", :namespace => 'moneta_bench' }, 'MemcacheDB' => { :class_name => "Memcache", :server => "localhost:21201", :namespace => 'moneta_bench' }, # 'Tyrant' => { :host => 'localhost', :port => 1978 }, # Breaks for any n > 50 on my machine 'MongoDB' => { :host => 'localhost', :port => 27017, :db => 'moneta_bench' }, } stats, keys, data, errors, summary = {}, [], HackedArray.new, HackedArray.new, HackedArray.new dict = HackedArray.new_from_string 'abcdefghijklnopq123456789' n = ARGV[0] ? ARGV[0].to_i : 100 m = ARGV[1] ? ARGV[1].to_i : 10 c = ARGV[2] ? ARGV[2].to_i : 3 vlen_min, vlen_max, vlen_ttl, vlen_avg = 99999, 0, 0, 0 ds = dict.size puts "======================================================================" puts "Comparison of write/read between Moneta Stores" puts "======================================================================" puts "Data loading..." n.times do |x| klen = 6 + rand(3) vlen = (rand(m) + 1) * (rand(m) + rand(m) + 1) key = dict.random_subset(klen).join keys << key value = key * vlen data << [key, value] vs = value.size vlen_min = vs if vs < vlen_min vlen_max = vs if vs > vlen_max vlen_ttl = vlen_ttl + vs end vlen_avg = vlen_ttl / n puts "----------------------------------------------------------------------" #puts data.inspect puts "Total keys: #{keys.size}, unique: #{keys.uniq.size}" #puts keys.sort.inspect puts "----------------------------------------------------------------------" puts " Minimum Maximum Total Average xps " puts "----------------------------------------------------------------------" puts "Lenght Stats % 10i % 10i % 10i % 10i % 10.4f " % [vlen_min, vlen_max, vlen_ttl, vlen_avg] require "../lib/moneta" stores.each do |name, options| cname = options.delete(:class_name) || name puts "======================================================================" puts name puts "----------------------------------------------------------------------" require "../lib/moneta/#{cname.downcase}" klass = Moneta.const_get(cname) @cache = klass.new(options) stats[name] = { :writes => [], :reads => [], :totals => [], :avgs => [], } c.times do |round| @cache.clear print "[#{round + 1}] R" m1 = Benchmark.measure do n.times do key, value = data.random @cache[key] = value end end stats[name][:writes] << m1.real print "W " m2 = Benchmark.measure do n.times do key, value = data.random res = @cache[key] errors << [name, key, value, res] unless res == value end end stats[name][:reads] << m2.real stats[name][:totals] << (m1.real + m2.real) stats[name][:avgs] << (m1.real + m2.real) end print "\n" puts "----------------------------------------------------------------------" puts " Minimum Maximum Total Average xps " puts "----------------------------------------------------------------------" tcmin, tcmax, tctot, tcavg = 99999, 0, 0, 0 [:writes, :reads].each do |sname| cmin, cmax, ctot, cavg = 99999, 0, 0, 0 stats[name][sname].each do |val| cmin = val if val < cmin tcmin = val if val < tcmin cmax = val if val > cmax tcmax = val if val > tcmax ctot = ctot + val tctot = tctot + val end cavg = ctot / c puts "%-14.14s % 10.4f % 10.4f % 10.4f % 10.4f % 10.4f " % ["#{name} #{sname}", cmin, cmax, ctot, cavg, n / cavg] end tcavg = tctot / (c * 2) puts "%-14.14s % 10.4f % 10.4f % 10.4f % 10.4f % 10.4f " % ["#{name} avgs", tcmin, tcmax, tctot, tcavg, n / tcavg] summary << [name, tcmin, tcmax, tctot, tcavg, n / tcavg] end puts "----------------------------------------------------------------------" if errors.size > 0 puts "Errors : #{errors.size}" # puts errors.inspect else puts "No errors in reading!" end puts "======================================================================" puts "Summary :: #{c} runs, #{n} keys" puts "======================================================================" puts " Minimum Maximum Total Average xps " puts "----------------------------------------------------------------------" summary.each do |sry| puts "%-14.14s % 10.4f % 10.4f % 10.4f % 10.4f % 10.4f " % sry end puts "======================================================================" puts "THE END" puts "======================================================================" #====================================================================== #Summary :: 3 runs, 1000 keys #====================================================================== # Minimum Maximum Total Average xps #---------------------------------------------------------------------- #MemcacheDB 0.6202 2.7850 7.0099 1.1683 855.9366 #Memcached 0.4483 0.6563 3.3251 0.5542 1804.4385 #Redis 0.3282 0.5221 2.2965 0.3828 2612.6444 #MongoDB 0.6660 1.0539 5.1667 0.8611 1161.2745 #======================================================================
aemadrid/moneta
spec/moneta_berkeley_spec.rb
<filename>spec/moneta_berkeley_spec.rb require File.dirname(__FILE__) + '/spec_helper' require 'moneta/berkeley' describe "Moneta::Berkelay" do before(:each) do @cache = Moneta::Berkeley.new(:file => File.join(File.dirname(__FILE__), "berkeley_test.db")) @cache.clear end after(:all) do File.delete(File.join(File.dirname(__FILE__), "berkeley_test.db")) File.delete(File.join(File.dirname(__FILE__), "berkeley_test.db_expiration")) end it_should_behave_like "a read/write Moneta cache" end
jetruby/spree_sale_prices
spec/models/variant_spec.rb
<gh_stars>1-10 require 'spec_helper' describe Spree::Variant do it 'can put a variant on a standard sale' do variant = create(:variant) expect(variant.on_sale?).to be false variant.put_on_sale 10.95 expect(variant.on_sale?).to be true expect(variant.original_price).to eql 19.99 expect(variant.price).to eql 10.95 end it 'changes the price of all attached prices' do variant = create(:multi_price_variant) variant.put_on_sale 10.95 expect(variant.prices.count).not_to eql 0 variant.prices.each do |p| expect(p.price).to eql BigDecimal.new(10.95, 4) end end it 'changes the price for each specific currency' do variant = create(:multi_price_variant, prices_count: 5) variant.prices.each do |p| variant.put_on_sale 10.95, { currencies: [ p.currency ] } expect(variant.price_in(p.currency).price).to eq BigDecimal.new(10.95, 4) expect(variant.original_price_in(p.currency).price).to eql BigDecimal.new(19.99, 4) end end it 'changes the price for multiple currencies' do variant = create(:multi_price_variant, prices_count: 5) some_prices = variant.prices.sample(3) variant.put_on_sale(10.95, { currencies: some_prices.map(&:currency) # TODO: does not work yet, because sale_prices take the calculator instance away from each other #calculator_type: Spree::Calculator::PercentOffSalePriceCalculator.new }) some_prices.each do |p| expect(variant.price_in(p.currency).price).to be_within(0.01).of(10.95) expect(variant.original_price_in(p.currency).price).to eql BigDecimal.new(19.99, 4) end end it 'can set the original price to something different without changing the sale price' do variant = create(:multi_price_variant, prices_count: 5) variant.put_on_sale(10.95) variant.prices.each do |p| p.original_price = 12.90 end variant.prices.each do |p| expect(p.on_sale?).to be true expect(p.price).to eq BigDecimal.new(10.95, 4) expect(p.sale_price).to eq BigDecimal.new(10.95, 4) expect(p.original_price).to eq BigDecimal.new(12.90, 4) end end it 'is not on sale anymore if the original price is lower than the sale price' do variant = create(:multi_price_variant, prices_count: 5) variant.put_on_sale(10.95) variant.prices.each do |p| p.original_price = 9.90 end variant.prices.each do |p| expect(p.on_sale?).to be false expect(p.price).to eq BigDecimal.new(9.90, 4) expect(p.sale_price).to eq nil expect(p.original_price).to eq BigDecimal.new(9.90, 4) end end context 'with a valid sale' do before(:each) do @variant = create(:multi_price_variant, prices_count: 5) @variant.put_on_sale(10.95) # sale is started and enabled at this point for all currencies end it 'can stop and start a sale for all currencies' do @variant.stop_sale @variant.prices.each do |p| expect(@variant.on_sale_in?(p.currency)).to be false end @variant.start_sale @variant.prices.each do |p| expect(@variant.on_sale_in?(p.currency)).to be true end end it 'can disable and enable a sale for all currencies' do @variant.disable_sale @variant.prices.each do |p| expect(@variant.on_sale_in?(p.currency)).to be false end @variant.enable_sale @variant.prices.each do |p| expect(@variant.on_sale_in?(p.currency)).to be true end end it 'can stop and start a sale for specific currencies' do price_groups = @variant.prices.in_groups(2) @variant.stop_sale(price_groups.first.map(&:currency)) price_groups.first.each do |p| expect(@variant.on_sale_in?(p.currency)).to be false end price_groups.second.each do |p| expect(@variant.on_sale_in?(p.currency)).to be true end @variant.start_sale(1.second.ago, price_groups.first.map(&:currency)) @variant.prices.each do |p| expect(@variant.on_sale_in?(p.currency)).to be true end end it 'can disable and enable a sale for specific currencies' do price_groups = @variant.prices.in_groups(2) @variant.disable_sale(price_groups.first.map(&:currency)) price_groups.first.each do |p| expect(@variant.on_sale_in?(p.currency)).to be false end price_groups.second.each do |p| expect(@variant.on_sale_in?(p.currency)).to be true end @variant.enable_sale(price_groups.first.map(&:currency)) @variant.prices.each do |p| expect(@variant.on_sale_in?(p.currency)).to be true end end end end
jetruby/spree_sale_prices
db/migrate/20140309000000_change_data_type_for_value.rb
class ChangeDataTypeForValue < ActiveRecord::Migration def change change_column :spree_sale_prices, :value, :decimal, precision: 10, scale: 2, null: false end end
jetruby/spree_sale_prices
lib/spree_sale_prices.rb
<gh_stars>1-10 require 'spree_core' require 'spree_sale_prices/engine'
jetruby/spree_sale_prices
spec/models/product_spec.rb
require 'spec_helper' describe Spree::Product do it 'can put a product on sale' do product = create(:product) expect(product.price).to eql 19.99 expect(product.original_price).to eql 19.99 expect(product.on_sale?).to be false product.put_on_sale 10.95 expect(product.price).to eql 10.95 expect(product.original_price).to eql 19.99 expect(product.on_sale?).to be true end end
jetruby/spree_sale_prices
app/models/spree/calculator/dollar_amount_sale_price_calculator.rb
<filename>app/models/spree/calculator/dollar_amount_sale_price_calculator.rb module Spree # <b>DEPRECATED:</b> Please use <tt>Calculator::FixedAmountSalePriceCalculator</tt> instead. class Calculator::DollarAmountSalePriceCalculator < Spree::Calculator warn '[DEPRECATION] `DollarAmountSalePriceCalculator` is deprecated. Please use `FixedAmountSalePriceCalculator` instead. (%s)' % Kernel.caller.first def self.description "Calculates the sale price for a Variant by returning the provided fixed sale price" end def compute(sale_price) sale_price.value end end end
jetruby/spree_sale_prices
app/overrides/admin_product_tabs.rb
<gh_stars>1-10 Deface::Override.new(virtual_path: "spree/admin/shared/_product_tabs", name: "add_sale_prices_tab", insert_bottom: "[data-hook='admin_product_tabs']", text: "<%= content_tag :li, :class => ('active' if current == 'Product Sale Prices') do %><%= link_to_with_icon 'money', Spree.t(:product_sale_prices), admin_product_sale_prices_path(@product) %><% end %>", disabled: false)
boost/consyncful
consyncful.gemspec
<reponame>boost/consyncful # frozen_string_literal: true lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'consyncful/version' Gem::Specification.new do |spec| spec.name = 'consyncful' spec.version = Consyncful::VERSION spec.authors = ['<NAME>', '<NAME>', '<NAME>'] spec.email = ['<EMAIL>', '<EMAIL>', '<EMAIL>'] spec.summary = 'Contentful to local database synchronisation for Rails' spec.homepage = 'https://github.com/boost/consyncful' spec.license = 'MIT' # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host' # to allow pushing to a single host or delete this section to allow pushing to any host. # if spec.respond_to?(:metadata) # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'" # else # raise "RubyGems 2.0 or newer is required to protect against " \ # "public gem pushes." # end spec.files = `git ls-files -z`.split("\x0").reject do |f| f.match(%r{^(test|spec|features)/}) end spec.bindir = 'exe' spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ['lib'] spec.add_development_dependency 'bundler', '~> 2' spec.add_development_dependency 'database_cleaner' spec.add_development_dependency 'rake', '~> 13.0' spec.add_development_dependency 'rspec', '~> 3.0' spec.add_development_dependency 'rubocop', '0.79.0' spec.add_dependency 'contentful', ['>=2.11.1', '<3.0.0'] spec.add_dependency 'hooks', '>=0.4.1' spec.add_dependency 'mongoid', ['>=7.0.2', '<8.0.0'] spec.add_dependency 'rainbow' end
boost/consyncful
lib/consyncful/item_mapper.rb
<reponame>boost/consyncful # frozen_string_literal: true module Consyncful ## # Responsible for mapping an update received from Contentful's syncronisation API # into useful fields for Consyncful::PersistedItem to store in the database. class ItemMapper def initialize(item) @item = item end def deletion? @item.is_a?(Contentful::DeletedEntry) || @item.is_a?(Contentful::DeletedAsset) end def type case @item.type when 'Entry' then @item.content_type.id when 'Asset' then 'asset' end end def id @item.id end def mapped_fields(default_locale) fields = generic_fields fields.merge!(localized_fields(default_locale)) fields.merge!(localized_asset_fields(default_locale)) if type == 'asset' fields end private def generic_fields { created_at: @item.created_at, updated_at: @item.updated_at, revision: @item.revision, contentful_type: type, synced_at: Time.current } end def localized_fields(default_locale) fields = {} @item.fields_with_locales.each do |field, value_with_locales| value_with_locales.each do |locale_code, value| next if value.is_a? Contentful::File # assets are handeled below field_name = localized_field_name(field, locale_code, default_locale) field_name, value = mapped_field_entry_for(field_name, value) fields[field_name] = value end end fields end def localized_asset_fields(default_locale) fields = {} files_by_locale = @item.raw.dig('fields', 'file') || {} files_by_locale.each do |locale_code, details| field_name = localized_field_name('file', locale_code, default_locale) fields[field_name.to_sym] = details end fields end # Suffixes the field with the locale unless it's the default locale. def localized_field_name(field, locale_code, default_locale) return field if locale_code.to_s == default_locale.to_s "#{field}_#{locale_code.to_s.underscore}".to_sym end def reference_value?(value) single_reference?(value) || many_reference?(value) end def single_reference?(value) value.is_a?(Contentful::BaseResource) end def many_reference?(value) value.is_a?(Array) && single_reference?(value.first) end def mapped_field_entry_for(field, value) if single_reference?(value) [ActiveSupport::Inflector.foreign_key(field).to_sym, value.id] elsif many_reference?(value) ids_field_name = field.to_s.singularize + '_ids' # fk field name [ids_field_name.to_sym, value.map(&:id)] else [field, value] end end end end
boost/consyncful
lib/consyncful/stats.rb
<gh_stars>1-10 # frozen_string_literal: true require 'rainbow' module Consyncful ## # Responsible for recording changes during a sync for outputting in logs class Stats def initialize @stats = { records_added: 0, records_updated: 0, records_deleted: 0 } end def record_added @stats[:records_added] += 1 end def record_updated @stats[:records_updated] += 1 end def record_deleted @stats[:records_deleted] += 1 end def print_stats puts Rainbow("Added: #{@stats[:records_added]}, \ updated: #{@stats[:records_updated]}, \ deleted: #{@stats[:records_deleted]}").blue end end end
boost/consyncful
lib/consyncful/tasks/consyncful.rake
<filename>lib/consyncful/tasks/consyncful.rake # frozen_string_literal: true namespace :consyncful do task update: [:environment] do Consyncful::Sync.latest.run end task refresh: [:environment] do Consyncful::Sync.fresh.run end task :sync, [:seconds] => %i[environment update_model_names] do |_task, args| seconds = args[:seconds].to_i seconds = 15 if seconds.zero? loop do Consyncful::Sync.latest.run sleep(seconds) end end task update_model_names: [:environment] do if Object.const_defined?('Zeitwerk::Loader') && Rails.application.config.autoloader.to_s == 'zeitwerk' Zeitwerk::Loader.eager_load_all else Rails.application.eager_load! end puts Rainbow('Updating model names:').blue Consyncful::Base.model_map.each do |contentful_name, constant| puts Rainbow("#{contentful_name}: #{constant}").yellow Consyncful::Base.where(contentful_type: contentful_name).update_all(_type: constant.to_s) end Consyncful::Base.where(:contentful_type.nin => Consyncful::Base.model_map.keys).update_all(_type: 'Consyncful::Base') end end