Serverspecのwindows版を触ってみる
はじめに
出ないか出ないかと待ちわびていたServerspecのWindows版が公開されたようなので使ってみる。
serverspec/WindowsSupport.md at e0079bda2dbdbf2aa5c8312e430ab7db840a6810 · serverspec/serverspec
環境構築
まず、serverspecのアップデートから。
kaakaa_hoe@[serverspec_win]$ gem update serverspec
アップデートするとserverspec-initコマンドの出力が変化して、Windowsを選択できるようになった。
kaakaa_hoe@[serverspec_win]$ serverspec-init Select OS type: 1) UN*X 2) Windows Select number: 2 Select a backend type: 1) WinRM 2) Cmd (local) Select number: 1 + spec/ + spec/localhost/ + spec/localhost/httpd_spec.rb + spec/spec_helper.rb + Rakefile kaakaa_hoe@[serverspec_win]$
リモートのテストをするので、2番めの質問には 1) WinRM を選択。
最初のテスト
このコマンドでサンプルのhttpdのテストが生成されるんだけど、そのサンプルがUnixテストのままっぽいので書き換えておく。
require 'spec_helper' describe file('c:/windows') do it { should be_directory } end
とりあえず動かすだけなのでこんなもん。
あと、spec_helper.rbにリモート端末の情報を設定しておく。
require 'serverspec' require 'winrm' include Serverspec::Helper::WinRM include Serverspec::Helper::Windows RSpec.configure do |c| user = 'kaakaa_hoe' pass = '********' endpoint = "http://192.168.3.5:5985/wsman" c.winrm = ::WinRM::WinRMWebService.new(endpoint, :ssl, :user => user, :pass => pass, :basic_auth_only => true) c.winrm.set_timeout 300 # 5 minutes max timeout for any operation end
書き換えたのはuser/pass/endpoint辺り。
実行
ここまで出来たので実行。
kaakaa_hoe@[serverspec_win]$ rake spec /Users/kaakaa_hoe/.rvm/rubies/ruby-2.0.0-p0/bin/ruby -S rspec spec/localhost/httpd_spec.rb WARNING: Could not load IOV methods. Check your GSSAPI C library for an update WARNING: Could not load AEAD methods. Check your GSSAPI C library for an update F Failures: 1) File "c:/Users/kaakaa_hoe/Document" should be directory Failure/Error: it { should be_directory } HTTPClient::ConnectTimeoutError: execution expired execution expired # ./spec/localhost/httpd_spec.rb:4:in `block (2 levels) in' Finished in 1 minute 0.01 seconds 1 example, 1 failure Failed examples: rspec ./spec/localhost/httpd_spec.rb:4 # File "c:/Users/kaakaa_hoe/Document" should be directory /Users/kaakaa_hoe/.rvm/rubies/ruby-2.0.0-p0/bin/ruby -S rspec spec/localhost/httpd_spec.rb failed kaakaa_hoe@[serverspec_win]$ vi spec/localhost/httpd_spec.rb
まぁ、そうなりますわな。
WinRMが何なのかよく分からないので、その辺りから攻めていくことに。
WinRM起動
とりあえずググって見つかったこのサイトを読んでみると、WinRMを使うために設定が必要そう。
WinRM を構成してみよう! - 管理者は見た!〜AD と ILM 一家の秘密〜 - Site Home - TechNet Blogs
WinRMが起動して無かったのでエラーになってたみたい。
ここに書いてある通りにリモートWin8マシンでWinRMを起動して、もう一度serverspec実行。
kaakaa_hoe@[serverspec_win]$ rake spec /Users/kaakaa_hoe/.rvm/rubies/ruby-2.0.0-p0/bin/ruby -S rspec spec/localhost/httpd_spec.rb WARNING: Could not load IOV methods. Check your GSSAPI C library for an update WARNING: Could not load AEAD methods. Check your GSSAPI C library for an update F Failures: 1) File "c:/Users/kaakaa_hoe/Document" should be directory Failure/Error: it { should be_directory } WinRM::WinRMHTTPTransportError: Bad HTTP response returned from server (401). Bad HTTP response returned from server (401). # ./spec/localhost/httpd_spec.rb:4:in `block (2 levels) in' Finished in 0.03639 seconds 1 example, 1 failure Failed examples: rspec ./spec/localhost/httpd_spec.rb:4 # File "c:/Users/kaakaa_hoe/Document" should be directory /Users/kaakaa_hoe/.rvm/rubies/ruby-2.0.0-p0/bin/ruby -S rspec spec/localhost/httpd_spec.rb failed kaakaa_hoe@[serverspec_win]$
エラーメッセージが変わった。
401なので認証関連がエラーらしい。
WinRM Basic認証許可
ココに書いてあるコマンドで認証許可設定出来そうな雰囲気。
VMware vCenter Orchestrator Plug-In Documentation Center
色々打ってみたけど、たぶんリモートマシンで以下のコマンドだけ打てば大丈夫だと思います。
c:\> winrm set winrm/config/service/auth @{Basic="true"} c:\> winrm set winrm/config/service @{AllowUnencrypted="true"}
クライアントとしてBasic認証と暗号化してないメッセージを受け付けるよう設定。
ここまで設定して、再々度serverspec実行。
kaakaa_hoe@[serverspec_win]$ rake spec /Users/kaakaa_hoe/.rvm/rubies/ruby-2.0.0-p0/bin/ruby -S rspec spec/localhost/httpd_spec.rb WARNING: Could not load IOV methods. Check your GSSAPI C library for an update WARNING: Could not load AEAD methods. Check your GSSAPI C library for an update . Finished in 0.99033 seconds 1 example, 0 failures kaakaa_hoe@[serverspec_win]$
行けました。
はてなダイアリーの記事をMarkdown形式に一括変換
はじめに
はてな記法があまり好きになれないのとフロントエンドを触るために、ブログをGithub Pagesに移行しようと思っている。
middleman-blogをgithubでホストする
middlemanを使えば好きなエディタで記事書けるし、記法も最近よく使うMarkdownを使えるので便利そうだな、と。
そのために今まではてなで書いてきた記事を、Markdown形式にして移行できないか調べてみた。
調査
とりあえずはてなの記事を取得するのはAtomPub使えば良さそう。
はてなダイアリーAtomPub - Hatena Developer Center
認証突破にはwsseを使う。
RubyでAtompubのWSSE認証 - Panty's
取得したAtomの解析にはREXMLを。
XML処理 REXMLの使い方 - プログラムメモ
記事HTMLをMarkdown形式に変更するにはPandocを使うと良さそう。
Pandoc - About pandoc
Rubyのラッパーもあるし。
alphabetum/pandoc-ruby
成果物
作ってみた。
kaakaa/hatena2md
とりあえず大まかには変換できてるけど、middleman-blogに読み込ませると表示がおかしな部分が多々…。まぁ、昔の記事へのリンク貼っておけば良いか。
あと、middleman-blog用のMarkdownなのでタイトルやタグなどのヘッダがついてます。