def _test_remove_userdata(compress=True, use_cloudinit=True):
    ud = _get_sample_userdata(compress=compress, use_cloudinit=use_cloudinit)
    unbundled = userdata.unbundle_userdata(ud, decompress=compress)
    new_ud = userdata.remove_from_userdata(ud, ['sc_0'], decompress=compress)
    new_ud = userdata.unbundle_userdata(new_ud, decompress=compress)
    assert 'sc_0' in unbundled
    del unbundled['sc_0']
    assert unbundled == new_ud
Exemple #2
0
def _test_remove_userdata(compress=True, use_cloudinit=True):
    ud = _get_sample_userdata(compress=compress, use_cloudinit=use_cloudinit)
    unbundled = userdata.unbundle_userdata(ud, decompress=compress)
    new_ud = userdata.remove_from_userdata(ud, ['sc_0'], decompress=compress)
    new_ud = userdata.unbundle_userdata(new_ud, decompress=compress)
    assert 'sc_0' in unbundled
    del unbundled['sc_0']
    assert unbundled == new_ud
def _test_append_userdata(compress=True, use_cloudinit=True):
    ud = _get_sample_userdata(compress=compress, use_cloudinit=use_cloudinit)
    unbundled = userdata.unbundle_userdata(ud, decompress=compress)
    new_script = '#!/bin/bash\ndate'
    new_fname = 'newfile.sh'
    assert new_fname not in unbundled
    unbundled[new_fname] = new_script
    new_fobj = utils.string_to_file(new_script, new_fname)
    new_ud = userdata.append_to_userdata(ud, [new_fobj], decompress=compress)
    new_unbundled = userdata.unbundle_userdata(new_ud, decompress=compress)
    assert new_unbundled == unbundled
Exemple #4
0
def _test_append_userdata(compress=True, use_cloudinit=True):
    ud = _get_sample_userdata(compress=compress, use_cloudinit=use_cloudinit)
    unbundled = userdata.unbundle_userdata(ud, decompress=compress)
    new_script = '#!/bin/bash\ndate'
    new_fname = 'newfile.sh'
    assert new_fname not in unbundled
    unbundled[new_fname] = new_script
    new_fobj = utils.string_to_file(new_script, new_fname)
    new_ud = userdata.append_to_userdata(ud, [new_fobj], decompress=compress)
    new_unbundled = userdata.unbundle_userdata(new_ud, decompress=compress)
    assert new_unbundled == unbundled
Exemple #5
0
 def user_data(self):
     if not self._user_data:
         try:
             raw = self._get_user_data()
             self._user_data = userdata.unbundle_userdata(raw)
         except IOError, e:
             parent_cluster = self.parent_cluster
             if self.parent_cluster:
                 raise exception.IncompatibleCluster(parent_cluster)
             else:
                 raise exception.BaseException(
                     "Error occurred unbundling userdata: %s" % e)
def _test_bundle_userdata(compress=False, use_cloudinit=True):
    ud = _get_sample_userdata(compress=compress, use_cloudinit=use_cloudinit)
    unbundled = userdata.unbundle_userdata(ud, decompress=compress)
    if use_cloudinit:
        cloud_cfg = unbundled.get('starcluster_cloud_config.txt')
        assert cloud_cfg.startswith('#cloud-config')
    else:
        enable_root = unbundled.get('starcluster_enable_root_login.sh')
        assert enable_root == userdata.ENABLE_ROOT_LOGIN_SCRIPT
    # ignored files should have #!/bin/false prepended automagically
    ilines = unbundled.get('sc_0').splitlines()
    assert ilines[0] == '#!/bin/false'
    # removing the auto-inserted #!/bin/false should get us back to the
    # original ignored script
    ignored_mod = '\n'.join(ilines[1:])
    assert IGNORED == ignored_mod
    # check that second file is bscript
    assert unbundled.get('sc_1') == BASH_SCRIPT
Exemple #7
0
def _test_bundle_userdata(compress=False, use_cloudinit=True):
    ud = _get_sample_userdata(compress=compress, use_cloudinit=use_cloudinit)
    unbundled = userdata.unbundle_userdata(ud, decompress=compress)
    if use_cloudinit:
        cloud_cfg = unbundled.get('starcluster_cloud_config.txt')
        assert cloud_cfg.startswith('#cloud-config')
    else:
        enable_root = unbundled.get('starcluster_enable_root_login.sh')
        assert enable_root == userdata.ENABLE_ROOT_LOGIN_SCRIPT
    # ignored files should have #!/bin/false prepended automagically
    ilines = unbundled.get('sc_0').splitlines()
    assert ilines[0] == '#!/bin/false'
    # removing the auto-inserted #!/bin/false should get us back to the
    # original ignored script
    ignored_mod = '\n'.join(ilines[1:])
    assert IGNORED == ignored_mod
    # check that second file is bscript
    assert unbundled.get('sc_1') == BASH_SCRIPT