From 2f105a555b05c0098c4d73eecdbbe88119ec7246 Mon Sep 17 00:00:00 2001 From: O'Shaughnessy Evans Date: Mon, 26 Jun 2017 14:42:40 -0700 Subject: [PATCH 1/3] for python3, ensure that packer inspect output is plain text --- packer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packer.py b/packer.py index a50758f..0a68826 100644 --- a/packer.py +++ b/packer.py @@ -115,7 +115,8 @@ def inspect(self, mrf=True): result = self.packer_cmd() if mrf: - result.parsed_output = self._parse_inspection_output(result.stdout) + result.parsed_output = self._parse_inspection_output( + result.stdout.decode('utf-8')) else: result.parsed_output = None return result From b5edc9266fca8b5d6801f35da1002ac489ae81aa Mon Sep 17 00:00:00 2001 From: O'Shaughnessy Evans Date: Mon, 26 Jun 2017 17:56:43 -0700 Subject: [PATCH 2/3] look up latest Amazon Linux AMI for Packer AWS module testing, add var file to checks --- Makefile | 5 ++++- tester.py | 4 ++-- tests/resources/packerfile.json | 4 ++-- tests/test_packer.py | 9 +++++---- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 4cc3f79..1f89029 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,9 @@ files: git log --oneline --decorate --color > CHANGELOG test: + @install -d var + @echo "Looking up latest Amazon Linux AMI" + aws --profile=stelligent-labs ec2 describe-images --owners amazon --filters 'Name=virtualization-type,Values=hvm' 'Name=root-device-type,Values=ebs' 'Name=architecture,Values=x86_64' 'Name=is-public,Values=true' 'Name=name,Values=amzn-ami-hvm-*-gp2' --query 'Images[*].{aws_source_ami:ImageId,created:CreationDate,description:Description}' |jq 'sort_by(.created)[-1]' |tee var/amazon-linux.json pip install tox==1.7.1 tox @@ -37,4 +40,4 @@ prepare: python scripts/make-release.py publish: - python setup.py sdist upload \ No newline at end of file + python setup.py sdist upload diff --git a/tester.py b/tester.py index b537f08..ba60adb 100644 --- a/tester.py +++ b/tester.py @@ -7,14 +7,14 @@ only = [] # vars = {"variable1": "y", "variable2": "value"} vars = {} -vars_file = '/x' +var_file = 'packer/var/amazon-linux.json' p = packer.Installer('packer_executables/', 'packer_0.7.5_linux_amd64.zip') # If we installed packer using the provided installer, it will return # packer's executable path. We can use it below: # packer_exec = p.install() packer_exec = 'packer' -p = packer.Packer(packerfile, exc=exc, only=only, vars=vars, +p = packer.Packer(packerfile, exc=exc, only=only, vars=vars, var_file=var_file, exec_path=packer_exec) # print(p.version()) # validation = p.validate(syntax_only=True) diff --git a/tests/resources/packerfile.json b/tests/resources/packerfile.json index 36e6493..e83e79a 100644 --- a/tests/resources/packerfile.json +++ b/tests/resources/packerfile.json @@ -5,7 +5,7 @@ "aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}", "aws_secret_key": "{{env `AWS_ACCESS_KEY`}}", "aws_source_ami": "", - "instance_type": "m3.large", + "instance_type": "t2.large", "virtualbox_source_image": "", "insecure_private_key": "./keys/insecure_private_key" }, @@ -80,4 +80,4 @@ "format": "tar.gz" } ] -} \ No newline at end of file +} diff --git a/tests/test_packer.py b/tests/test_packer.py index 424e01d..d327a8d 100644 --- a/tests/test_packer.py +++ b/tests/test_packer.py @@ -7,24 +7,25 @@ TEST_RESOURCES_DIR = 'tests/resources' TEST_PACKERFILE = os.path.join(TEST_RESOURCES_DIR, 'packerfile.json') TEST_BAD_PACKERFILE = os.path.join(TEST_RESOURCES_DIR, 'badpackerfile.json') +TEST_VARFILE = 'var/amazon-linux.json') class TestBase(testtools.TestCase): def test_build(self): - p = packer.Packer(TEST_PACKERFILE) + p = packer.Packer(TEST_PACKERFILE, var_file=TEST_VARFILE) p.build() def test_fix(self): - p = packer.Packer(TEST_PACKERFILE) + p = packer.Packer(TEST_PACKERFILE, var_file=TEST_VARFILE) p.fix() def test_inspect(self): - p = packer.Packer(TEST_PACKERFILE) + p = packer.Packer(TEST_PACKERFILE, var_file=TEST_VARFILE) p.inspect() def test_validate(self): - p = packer.Packer(TEST_PACKERFILE) + p = packer.Packer(TEST_PACKERFILE, var_file=TEST_VARFILE) p.validate() def test_version(self): From 131992c52f3c125feee627170e89bde8740dcbca Mon Sep 17 00:00:00 2001 From: O'Shaughnessy Evans Date: Mon, 26 Jun 2017 17:57:29 -0700 Subject: [PATCH 3/3] remove profile from aws ec2 call --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 1f89029..5fb4a99 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ files: test: @install -d var @echo "Looking up latest Amazon Linux AMI" - aws --profile=stelligent-labs ec2 describe-images --owners amazon --filters 'Name=virtualization-type,Values=hvm' 'Name=root-device-type,Values=ebs' 'Name=architecture,Values=x86_64' 'Name=is-public,Values=true' 'Name=name,Values=amzn-ami-hvm-*-gp2' --query 'Images[*].{aws_source_ami:ImageId,created:CreationDate,description:Description}' |jq 'sort_by(.created)[-1]' |tee var/amazon-linux.json + aws ec2 describe-images --owners amazon --filters 'Name=virtualization-type,Values=hvm' 'Name=root-device-type,Values=ebs' 'Name=architecture,Values=x86_64' 'Name=is-public,Values=true' 'Name=name,Values=amzn-ami-hvm-*-gp2' --query 'Images[*].{aws_source_ami:ImageId,created:CreationDate,description:Description}' |jq 'sort_by(.created)[-1]' |tee var/amazon-linux.json pip install tox==1.7.1 tox