示例#1
0
    def test_sensitve_variables(self):
        expected_json = """
                {
                  "variables": {
                    "my_secret": "{{env `MY_SECRET`}}",
                    "not_a_secret": "plaintext",
                    "foo": "bar"
                  },
                  "sensitive-variables": [
                    "my_secret",
                    "foo"
                  ]
                }
                """

        t = Template()
        vars = [
            EnvVar("my_secret", "MY_SECRET"),
            UserVar("not_a_secret", "plaintext"),
            UserVar("foo", "bar"),
        ]
        t.add_variable(vars)
        t.add_sensitive_variable("my_secret")
        t.add_sensitive_variable("foo")

        to_json = t.to_json()
        assert to_json == json.dumps(json.loads(expected_json),
                                     sort_keys=True,
                                     indent=2,
                                     separators=(',', ': '))
示例#2
0
    def test_user_variable(self):
        var = UserVar("MY_TEST_USER", "testValue")

        assert var.title == "MY_TEST_USER"
        assert var.data == "testValue"
        assert var.ref().data == "{{user `MY_TEST_USER`}}"
        assert Ref(var).data == "{{user `MY_TEST_USER`}}"
示例#3
0
    def test_variable_duplicate_entries(self):
        t = Template()
        vars = [
            UserVar("my_var"),
            UserVar("my_var"),
        ]
        with pytest.raises(ValueError) as excinfo:
            t.add_variable(vars)
        assert 'duplicate key "my_var" detected' == str(excinfo.value)

        with pytest.raises(ValueError) as excinfo:
            t.add_variable(UserVar("my_var"))
        assert 'duplicate key "my_var" detected' == str(excinfo.value)
示例#4
0
    def test_template_variables(self):
        t = Template()

        t.add_variable(UserVar("my_var", "my_value"))

        d = t.to_dict()
        assert d['variables'] == {'my_var': 'my_value'}
示例#5
0
    def test_variable_no_duplicate_entries(self):
        expected_json = """
                {
                  "variables": {
                     "my_var1": "a value",
                     "my_var2": ""
                  }
                }
                """

        t = Template()
        vars = [
            UserVar("my_var1", "a value"),
            UserVar("my_var2"),
        ]
        t.add_variable(vars)

        to_json = t.to_json()
        assert to_json == json.dumps(json.loads(expected_json),
                                     sort_keys=True,
                                     indent=2,
                                     separators=(',', ': '))
示例#6
0
class TestPacker(unittest.TestCase):

    aws_access_key = UserVar("aws_access_key", "")
    aws_secret_key = UserVar("aws_secret_key", "")
    user_variables = [aws_access_key, aws_secret_key]
    builders = [
        builder.AmazonEbs(access_key=Ref(aws_access_key),
                          secret_key=Ref(aws_secret_key),
                          region="us-east-1",
                          source_ami_filter=builder.AmazonSourceAmiFilter(
                              filters={
                                  "virtualization-type": "hvm",
                                  "name":
                                  "*ubuntu-xenial-16.04-amd64-server-*",
                                  "root-device-type": "ebs"
                              },
                              owners=["099720109477"],
                              most_recent=True),
                          instance_type="t2.micro",
                          ami_name="packer-example {{timestamp}}",
                          ssh_username="******")
    ]
    template = Template()
    template.add_variable(user_variables)
    template.add_builder(builders)

    def test_validate(self):
        output = packer.validate(TestPacker.template)
        assert output.return_code == 0
        assert "successfully" in output.output

    def test_build(self):
        output = packer.build(TestPacker.template)
        assert output.return_code == 0
        assert "successful" in output.output

    def test_inspect(self):
        output = packer.inspect(TestPacker.template)
        assert output.return_code == 0
示例#7
0
import imp, json, requests, sys
from packerlicious import builder, post_processor, provisioner, \
        Ref, Template, UserVar
from packerpy import PackerExecutable

boot_command_prefix = \
    UserVar("boot_command_prefix","<esc><esc><enter><wait>")
build_cpus = UserVar("build_cpus","2")
cpus = UserVar("cpus","2") 
disk_size = UserVar("disk_size","81920")
headless = UserVar("headless","false")
hostname = UserVar("hostname","vagrant")
#iso_checksum_url = \
#    UserVar("iso_checksum_url", \
#        "http://archive.ubuntu.com/ubuntu/dists/bionic-updates/main/installer-amd64/current/images/SHA256SUMS")
iso_checksum_url = \
    UserVar("iso_checksum_url", \
        "http://cdimage.ubuntu.com/releases/18.04.4/release/SHA256SUMS")
#iso_url = \
#    UserVar("iso_url", \
#        "http://archive.ubuntu.com/ubuntu/dists/bionic-updates/main/installer-amd64/current/images/netboot/mini.iso")
iso_url = \
    UserVar("iso_url", \
        "./iso/ubuntu-18.04.4-server-amd64.iso")
        #"http://cdimage.ubuntu.com/releases/18.04.4/release/ubuntu-18.04.4-server-amd64.iso")
locale = UserVar("locale","en_NZ")
memory = UserVar("memory","2048")
preseed = UserVar("preseed","server.cfg")
ssh_password = UserVar("ssh_password","vagrant")
ssh_username = UserVar("ssh_username","vagrant")
time_zone = UserVar("time_zone","Pacific/Auckland")
# https://www.packer.io/intro/getting-started/build-image.html#the-template
from packerlicious import builder, Ref, Template, UserVar

aws_access_key = UserVar("aws_access_key", "")
aws_secret_key = UserVar("aws_secret_key", "")
user_variables = [aws_access_key, aws_secret_key]

builders = [
    builder.AmazonEbs(access_key=Ref(aws_access_key),
                      secret_key=Ref(aws_secret_key),
                      region="us-east-1",
                      source_ami_filter=builder.AmazonSourceAmiFilter(
                          filters={
                              "virtualization-type": "hvm",
                              "name": "*ubuntu-xenial-16.04-amd64-server-*",
                              "root-device-type": "ebs"
                          },
                          owners=["099720109477"],
                          most_recent=True),
                      instance_type="t2.micro",
                      ami_name="packer-example {{timestamp}}",
                      ssh_username="******")
]

t = Template()
t.add_variable(user_variables)
t.add_builder(builders)

t.to_json()
示例#9
0
from packerlicious import builder, post_processor, provisioner, \
        Ref, Template, UserVar
from packerpy import PackerExecutable

from dotenv import load_dotenv
load_dotenv()

import os
token = os.environ.get("cloud_token")

cloud_token = UserVar("cloud_token", token)

user_variables = [cloud_token]

builders = [builder.Null(communicator="none")]

post_processors = [[
    post_processor.Artifice(files=["builds/ubuntu1804-desktop-base.box"]),
    post_processor.VagrantCloud(box_tag="catosplace/ubuntu1804-desktop-base",
                                access_token=Ref(cloud_token),
                                version="1.0.2"),
    #post_processor.Checksum(
    #    checksum_types = [ "md5", "sha1", "sha256" ]
    #),
]]

t = Template()
t.add_variable(user_variables)
t.add_builder(builders)
t.add_post_processor(post_processors)