ようへいの日々精進XP

よかろうもん

Infrataster の DNS プラグインメモ

tl;dr

加齢と共に目視チェックが辛くなってきた年寄りインフラエンジニアには Infrataster がうってつけだと思って、Infrataster の DNS プラグインを使ってみたのでメモ。


Infrataster と Infrataster の DNS プラグイン


memo

試した環境

% sw_vers
ProductName:    Mac OS X
ProductVersion: 10.11.6
BuildVersion:   15G19a

% bundle exec gem list | grep infrataster
infrataster (0.3.2)
infrataster-plugin-dns (0.0.2)

準備

こちらを参考にさせて頂いて準備。

  • Gemfile
source 'https://rubygems.org'
gem 'infrataster-plugin-dns'
  • bundle install
bundle install --path vendor/bundle
  • spec/spec_helper.rb
require "infrataster/rspec"
require "infrataster-plugin-dns"

Infrataster::Server.define(
  :dns01,
  "8.8.8.8"
)

Infrataster::Server.define(
  :dns02,
  "8.8.4.4"
)

spec ファイル

  • spec/inokara-com_spec.rb
require "spec_helper"

%w(dns01 dns02).each do |dns|

  # こんな書き方するのが正しいのか判らないけど
  describe server(dns.to_sym) do
    describe dns("inokara.com") do
      it { is_expected.to have_dns.with_type("NS").and_domainname(/dns.ne.jp/) }
    end

    %w(
      kome.inokara.com
    ).each do |domain|
      describe dns(domain) do
        it { is_expected.to have_entry.with_type("CNAME").and_domainname(/s3-website-ap-northeast-1/) }
      end
    end
  end

end
  • spec/test-inokara-com_spec.rb
require "spec_helper"

%w(dns01 dns02).each do |dns|

  # こんな書き方するのが正しいのか判らないけど
  describe server(dns.to_sym) do
    describe dns("test.inokara.com") do
      it { is_expected.to have_dns.with_type("NS").and_domainname(/awsdns/) }
    end
 
    %w(
      pm25.test.inokara.com
    ).each do |domain|
      describe dns(domain) do
        it { is_expected.to have_entry.with_type("A").and_address(/54.231/) }
      end
    end
  end

end

テスト

  • run
bundle exec rspec spec
  • output
server 'dns01'
  dns 'inokara.com'
    should have the correct dns entries with {:type=>"NS", :domainname=>/dns.ne.jp/}
  dns 'kome.inokara.com'
    should have the correct dns entries with {:type=>"CNAME", :domainname=>/s3-website-ap-northeast-1/}

server 'dns02'
  dns 'inokara.com'
    should have the correct dns entries with {:type=>"NS", :domainname=>/dns.ne.jp/}
  dns 'kome.inokara.com'
    should have the correct dns entries with {:type=>"CNAME", :domainname=>/s3-website-ap-northeast-1/}

server 'dns01'
  dns 'test.inokara.com'
    should have the correct dns entries with {:type=>"NS", :domainname=>/awsdns/}
  dns 'pm25.test.inokara.com'
    should have the correct dns entries with {:type=>"A", :address=>/54.231/}

server 'dns02'
  dns 'test.inokara.com'
    should have the correct dns entries with {:type=>"NS", :domainname=>/awsdns/}
  dns 'pm25.test.inokara.com'
    should have the correct dns entries with {:type=>"A", :address=>/54.231/}

Finished in 0.59681 seconds (files took 1.07 seconds to load)
8 examples, 0 failures

いい感じ。


ということで

DNS 移行時際のテスト等に非常に有効だと思う。また、プロジェクト終盤に疲弊した状態にはこのような(シェルスクリプトだってイイと思う)機械的な確認の方が安全なのは言うまでも無い。特に自分のような年寄りが関わっている場合にはなおさら。

素敵なインフラテストライフを。