diff options
author | Scott Moser <smoser@ubuntu.com> | 2012-04-04 21:35:32 -0400 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2012-04-04 21:35:32 -0400 |
commit | 7b2fc4e014e6b7a43e6b8fc719d82c3d0b0a8bed (patch) | |
tree | 12859523160be456f76e0d0c33010bd6f0452ce8 /tests/unittests/test__init__.py | |
parent | b39abf5bbe51d62d1ef1dd1e813720eafc1ddc85 (diff) | |
download | vyos-cloud-init-7b2fc4e014e6b7a43e6b8fc719d82c3d0b0a8bed.tar.gz vyos-cloud-init-7b2fc4e014e6b7a43e6b8fc719d82c3d0b0a8bed.zip |
initial checkin of kernel commandline cloud-config url support
Diffstat (limited to 'tests/unittests/test__init__.py')
-rw-r--r-- | tests/unittests/test__init__.py | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/tests/unittests/test__init__.py b/tests/unittests/test__init__.py index e157fa77..4f60f0ea 100644 --- a/tests/unittests/test__init__.py +++ b/tests/unittests/test__init__.py @@ -2,8 +2,8 @@ from mocker import MockerTestCase, ANY, ARGS, KWARGS import os from cloudinit import (partwalker_handle_handler, handler_handle_part, - handler_register) -from cloudinit.util import write_file, logexc + handler_register, get_cmdline_url) +from cloudinit.util import write_file, logexc, readurl class TestPartwalkerHandleHandler(MockerTestCase): @@ -193,3 +193,50 @@ class TestHandlerHandlePart(MockerTestCase): handler_handle_part(mod_mock, self.data, self.ctype, self.filename, self.payload, self.frequency) + + +class TestCmdlineUrl(MockerTestCase): + def test_invalid_content(self): + url = "http://example.com/foo" + key = "mykey" + payload = "0" + cmdline = "ro %s=%s bar=1" % (key, url) + + mock_readurl = self.mocker.replace(readurl, passthrough=False) + mock_readurl(url) + self.mocker.result(payload) + + self.mocker.replay() + + self.assertEqual((key, url, None), + get_cmdline_url(names=[key], starts="xxxxxx", cmdline=cmdline)) + + def test_valid_content(self): + url = "http://example.com/foo" + key = "mykey" + payload = "xcloud-config\nmydata: foo\nbar: wark\n" + cmdline = "ro %s=%s bar=1" % (key, url) + + mock_readurl = self.mocker.replace(readurl, passthrough=False) + mock_readurl(url) + self.mocker.result(payload) + + self.mocker.replay() + + self.assertEqual((key, url, payload), + get_cmdline_url(names=[key], starts="xcloud-config", + cmdline=cmdline)) + + def test_no_key_found(self): + url = "http://example.com/foo" + key = "mykey" + cmdline = "ro %s=%s bar=1" % (key, url) + + self.mocker.replace(readurl, passthrough=False) + self.mocker.replay() + + self.assertEqual((None, None, None), + get_cmdline_url(names=["does-not-appear"], + starts="#cloud-config", cmdline=cmdline)) + +# vi: ts=4 expandtab |