LoginSignup
1
5

More than 5 years have passed since last update.

TaskCatを試してみた

Last updated at Posted at 2018-11-01

投稿内容は私個人の意見であり、所属企業・部門見解を代表するものではありません。

TaskCatとは

GitHubより

TaskCat is a tool that tests AWS CloudFormation templates. It deploys your AWS CloudFormation template in multiple AWS Regions and generates a report with a pass/fail grade for each region. You can specify the regions and number of Availability Zones you want to include in the test, and pass in parameter values from your AWS CloudFormation template. TaskCat is implemented as a Python class that you import, instantiate, and run.
TestCat was developed by the AWS QuickStart team to test AWS CloudFormation templates that automatically deploy workloads on AWS. We’re pleased to make the tool available to all developers who want to validate their custom AWS CloudFormation templates across AWS Regions

TaskCatは、AWS CloudFormationテンプレートをテストするツールです。複数のAWSリージョンにAWS CloudFormationテンプレートをデプロイし、各地域の合格/不合格グレードのレポートを生成します。テストに含める領域と空き領域の数を指定し、AWS CloudFormationテンプレートからパラメータ値を渡すことができます。 TaskCatは、インポート、インスタンス化、および実行するPythonクラスとして実装されています。
TestCatは、AWSクイックスタートチームによって開発され、AWSにワークロードを自動的にデプロイするAWS CloudFormationテンプレートをテストします。 AWS地域のカスタムAWS CloudFormationテンプレートを検証したいすべての開発者がこのツールを利用できるようになりました

複数リージョンに同じテンプレートでデプロイする際に簡単にテストできるPython製のツールです。AWSは、よくある構成やソリューションごとにQuickStartというCloudFormationテンプレートを提供していますが、元々TaskCatは、QuickStartチームが自身のテンプレートファイルをテストするために開発したものです。

テスト対象のCloudFormationのテンプレートファイル、パラメータファイルとTaskCatの設定ファイルを入力として、TaskCatを実行すると、設定ファイルで指定したリージョンでCloudFormationのStackが作成されます。

TaskCat.png

使い方

TaskCatのGitHubレポジトリにサンプルプロジェクトがあるため、そちらを使って試してみたいと思います。

1 TaskCatのインストールと確認

$ pip install taskcat
$ taskcat
 _            _             _   
| |_ __ _ ___| | _____ __ _| |_ 
| __/ _` / __| |/ / __/ _` | __|
| || (_| \__ \   < (_| (_| | |_ 
 \__\__,_|___/_|\_\___\__,_|\__|

version 0.7.19

[INFO   ] : A newer version of taskcat is available (0.7.27)
[INFO   ] : To upgrade pip version    [ pip install --upgrade taskcat]
[INFO   ] : To upgrade docker version [ docker pull taskcat/taskcat ]

usage: taskcat [-h] [-c CONFIG_YML] [-P BOTO_PROFILE] [-A AWS_ACCESS_KEY]

2 サンプルプロジェクトをgit clone

$ git clone https://github.com/aws-quickstart/taskcat.git

3 ファイルの確認(設定ファイル)

$ cat taskcat/examples/sample-taskcat-project/ci/taskcat.yml 
---
global:
  owner: owner@company.com
  qsname: sample-taskcat-project
  s3bucket: <ログ出力用のS3>
  regions:
    - ap-northeast-1
    - ap-northeast-2
    - ap-southeast-1
    - ap-southeast-2
    - eu-central-1
    - eu-west-1
    - sa-east-1
    - us-east-1
    - us-west-1
    - us-west-2
  reporting: true
tests:
  taskcat-json:
    parameter_input: debug-input.json
    regions:
      - us-east-1
      - ap-northeast-1
    template_file: debug.template

testセクションでテストシナリオを記載していきます。上記の例は、CloudFormationのパラメータを「debug-input.json」に記述しています。テスト対象のテンプレートファイルが、「debug.template」になります。リージョンは、CloudFormationを実行するリージョンを指定します。

4 ファイルの確認(パラメータファイル)

cat taskcat/examples/sample-taskcat-project/ci/debug-input.json 
[
    {
        "ParameterKey": "AvailabilityZones",
        "ParameterValue": "$[taskcat_genaz_3]"
    },
    {
        "ParameterKey": "StackName",
        "ParameterValue": "TestStack"
    },

$[**]は、環境変数で例えばリージョンによってAZ構成に差異がありますが、そういった差異を吸収することができます。詳細は以下に記載があります。
https://aws-quickstart.github.io/input-files.html

5 テスト実行

taskcat -c taskcat/examples/sample-taskcat-project/ci/taskcat.yml
 _            _             _   
| |_ __ _ ___| | _____ __ _| |_ 
| __/ _` / __| |/ / __/ _` | __|
| || (_| \__ \   < (_| (_| | |_ 
 \__\__,_|___/_|\_\___\__,_|\__|


version 0.7.19


[INFO   ] : A newer version of taskcat is available (0.7.27)
[INFO   ] : To upgrade pip version    [ pip install --upgrade taskcat]
[INFO   ] : To upgrade docker version [ docker pull taskcat/taskcat ]




[taskcat] :AWS AccountNumber:    [xxxxxxxxxxx]
[taskcat] :Authenticated via:    [environment]

-略-


[INFO   ] :All stacks deleted successfully. Deep clean-up not required.
[INFO   ] :Retaining assets in s3bucket [***]

実行すると、debug-input.jsonで指定したリージョンにCloudFormationのスタックが作成され、完了後削除されます。-nオプションを指定するとスタックが削除されず残ります。

6 実行結果の確認

cat taskcat_outputs/tCaT-tag-taskcat-json-517b6132-us-east-1-cfnlogs.txt 
-----------------------------------------------------------------------------
Region: us-east-1
StackName: tCaT-tag-taskcat-json-517b6132
*****************************************************************************
ResourceStatusReason:  
Stack launch was successful
*****************************************************************************
*****************************************************************************
Events:  
ResourceStatus      TimeStamp                         ResourceStatusReason         ResourceType                LogicalResourceId
------------------  --------------------------------  ---------------------------  --------------------------  ------------------------------
CREATE_COMPLETE     2018-11-01 05:35:11.387000+00:00                               AWS::CloudFormation::Stack  tCaT-tag-taskcat-json-517b6132
CREATE_COMPLETE     2018-11-01 05:35:08.638000+00:00                               Custom::GenerateID          GetID
CREATE_IN_PROGRESS  2018-11-01 05:35:08.279000+00:00  Resource creation Initiated  Custom::GenerateID          GetID
CREATE_IN_PROGRESS  2018-11-01 05:35:05.547000+00:00                               Custom::GenerateID          GetID
CREATE_COMPLETE     2018-11-01 05:35:02.450000+00:00                               AWS::Lambda::Function       GenID
CREATE_IN_PROGRESS  2018-11-01 05:35:02.153000+00:00  Resource creation Initiated  AWS::Lambda::Function       GenID
CREATE_IN_PROGRESS  2018-11-01 05:35:01.538000+00:00                               AWS::Lambda::Function       GenID
CREATE_COMPLETE     2018-11-01 05:34:58.447000+00:00                               AWS::IAM::Role              LambdaExecutionRole
CREATE_IN_PROGRESS  2018-11-01 05:34:46.150000+00:00  Resource creation Initiated  AWS::IAM::Role              LambdaExecutionRole
CREATE_IN_PROGRESS  2018-11-01 05:34:45.774000+00:00                               AWS::IAM::Role              LambdaExecutionRole
CREATE_IN_PROGRESS  2018-11-01 05:34:42.088000+00:00  User Initiated               AWS::CloudFormation::Stack  tCaT-tag-taskcat-json-517b6132
*****************************************************************************
-----------------------------------------------------------------------------
Tested on: Thursday, 01. November 2018 02:35PM
-----------------------------------------------------------------------------

参考

1
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
5