def test_cloud_init_user_multipart(): # http://cloudinit.readthedocs.org/en/latest/topics/examples.html cc = """#cloud-config # # This is an example file to automatically configure resolv.conf when the # instance boots for the first time. # # Ensure that your yaml is valid and pass this as user-data when starting # the instance. Also be sure that your cloud.cfg file includes this # configuration module in the appropirate section. # manage-resolv-conf: true resolv_conf: nameservers: ['8.8.4.4', '8.8.8.8'] searchdomains: - foo.example.com - bar.example.com domain: example.com options: rotate: true timeout: 1""" # https://help.ubuntu.com/community/CloudInit bh = """#!/bin/sh echo "Hello World!" echo "This will run as soon as possible in the boot sequence" """ conn = BaseOsConnection(fake_name, this_url = fake_url) # Create a mime multipart monster msg = MIMEMultipart() msg.attach(MIMEText(cc, _subtype = "cloud-config")) msg.attach(MIMEText(bh, _subtype = "cloud-boothook")) expect = [ ('text/x-shellscript', 'part-000', REACTOR_PRE_SCRIPT % { 'url': fake_url, }), ('text/cloud-config', 'part-001', cc), ('text/cloud-boothook', 'part-002', bh), ('text/x-shellscript', 'part-003', REACTOR_POST_SCRIPT % { 'url': fake_url, 'timeout': 300 }), ('text/x-windows-reactor', 'part-004', REACTOR_WIN_BLOB % { 'url': fake_url, }), ] assert walk_userdata(conn._user_data(msg.as_string())) == expect
def test_cloud_init_user_multipart(): # http://cloudinit.readthedocs.org/en/latest/topics/examples.html cc = """#cloud-config # # This is an example file to automatically configure resolv.conf when the # instance boots for the first time. # # Ensure that your yaml is valid and pass this as user-data when starting # the instance. Also be sure that your cloud.cfg file includes this # configuration module in the appropirate section. # manage-resolv-conf: true resolv_conf: nameservers: ['8.8.4.4', '8.8.8.8'] searchdomains: - foo.example.com - bar.example.com domain: example.com options: rotate: true timeout: 1""" # https://help.ubuntu.com/community/CloudInit bh = """#!/bin/sh echo "Hello World!" echo "This will run as soon as possible in the boot sequence" """ conn = BaseOsConnection(fake_name, this_url=fake_url) # Create a mime multipart monster msg = MIMEMultipart() msg.attach(MIMEText(cc, _subtype="cloud-config")) msg.attach(MIMEText(bh, _subtype="cloud-boothook")) expect = [ ('text/x-shellscript', 'part-000', REACTOR_PRE_SCRIPT % { 'url': fake_url, }), ('text/cloud-config', 'part-001', cc), ('text/cloud-boothook', 'part-002', bh), ('text/x-shellscript', 'part-003', REACTOR_POST_SCRIPT % { 'url': fake_url, 'timeout': 300 }), ('text/x-windows-reactor', 'part-004', REACTOR_WIN_BLOB % { 'url': fake_url, }), ] assert walk_userdata(conn._user_data(msg.as_string())) == expect
def test_basic_cloud_init(): conn = BaseOsConnection(fake_name, this_url=fake_url) # What will cloud-init see. Note: single script results in "not multipart" expect = [ ('text/x-shellscript', 'part-000', REACTOR_PRE_SCRIPT % { 'url': fake_url, }), ('text/x-shellscript', 'part-001', REACTOR_POST_SCRIPT % { 'url': fake_url, 'timeout': 300 }), ('text/x-windows-reactor', 'part-002', REACTOR_WIN_BLOB % { 'url': fake_url, }), ] assert walk_userdata(conn._user_data()) == expect
def test_cloud_init_user_script(): script = "#/bin/sh\ntouch /tmp/foo" conn = BaseOsConnection(fake_name, this_url=fake_url) expect = [ ('text/x-shellscript', 'part-000', REACTOR_PRE_SCRIPT % { 'url': fake_url, }), ('text/plain', 'part-001', script), ('text/x-shellscript', 'part-002', REACTOR_POST_SCRIPT % { 'url': fake_url, 'timeout': 300 }), ('text/x-windows-reactor', 'part-003', REACTOR_WIN_BLOB % { 'url': fake_url, }), ] assert walk_userdata(conn._user_data(script)) == expect