def test_format_cloud_init_with_data(self): """The format cloud init creates a user-data cloud-init config file. It can be used to pass an additional data dictionary as well for use by the launched machine. """ packages = ["python-lxml"] scripts = ["wget http://lwn.net > /tmp/out"] repositories = ["ppa:juju/pkgs"] output = format_cloud_init( ["zebra"], packages=packages, scripts=scripts, repositories=repositories, data={"magic": [1, 2, 3]}) lines = output.split("\n") self.assertEqual(lines.pop(0), "#cloud-config") config = load("\n".join(lines)) self.assertEqual(config["ssh_authorized_keys"], ["zebra"]) self.assertTrue(config["apt-update"]) self.assertTrue(config["apt-upgrade"]) formatted_repos = [dict(source=r) for r in repositories] self.assertEqual(config["apt_sources"], formatted_repos) self.assertEqual(config["runcmd"], scripts) self.assertEqual(config["machine-data"]["magic"], [1, 2, 3])
def test_format_cloud_init_with_data(self): """The format cloud init creates a user-data cloud-init config file. It can be used to pass an additional data dictionary as well for use by the launched machine. """ packages = ["python-lxml"] scripts = ["wget http://lwn.net > /tmp/out"] repositories = ["ppa:juju/pkgs"] output = format_cloud_init(["zebra"], packages=packages, scripts=scripts, repositories=repositories, data={"magic": [1, 2, 3]}) lines = output.split("\n") self.assertEqual(lines.pop(0), "#cloud-config") config = load("\n".join(lines)) self.assertEqual(config["ssh_authorized_keys"], ["zebra"]) self.assertTrue(config["apt-update"]) self.assertTrue(config["apt-upgrade"]) formatted_repos = [dict(source=r) for r in repositories] self.assertEqual(config["apt_sources"], formatted_repos) self.assertEqual(config["runcmd"], scripts) self.assertEqual(config["machine-data"]["magic"], [1, 2, 3])
def render(self): """Get content for a cloud-init file with appropriate specifications. :rtype: str :raises: :exc:`juju.errors.CloudInitError` if there isn't enough information to create a useful cloud-init. """ self._validate() return format_cloud_init( self._ssh_keys, packages=self._collect_packages(), repositories=self._collect_repositories(), scripts=self._collect_scripts(), data=self._collect_machine_data())