diff options
author | Scott Moser <smoser@ubuntu.com> | 2013-02-07 09:12:36 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2013-02-07 09:12:36 -0500 |
commit | 88a369c5324e74a2d1bb8dd0bdf8fdc9a95393c8 (patch) | |
tree | b23bcf31dfc1021781514333fdd865baf1e8620f /tests/unittests/test_datasource/test_nocloud.py | |
parent | bf0db8d0793c9c18871cbbafbbad9c127b0bd8ee (diff) | |
download | vyos-cloud-init-88a369c5324e74a2d1bb8dd0bdf8fdc9a95393c8.tar.gz vyos-cloud-init-88a369c5324e74a2d1bb8dd0bdf8fdc9a95393c8.zip |
add test_nocloud unit tests, fix one issue found
Diffstat (limited to 'tests/unittests/test_datasource/test_nocloud.py')
-rw-r--r-- | tests/unittests/test_datasource/test_nocloud.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/unittests/test_datasource/test_nocloud.py b/tests/unittests/test_datasource/test_nocloud.py new file mode 100644 index 00000000..850d3214 --- /dev/null +++ b/tests/unittests/test_datasource/test_nocloud.py @@ -0,0 +1,56 @@ +from cloudinit.sources import DataSourceNoCloud + +from mocker import MockerTestCase + + +class TestNoCloudDataSource(MockerTestCase): + + def setUp(self): + super(TestNoCloudDataSource, self).setUp() + + def test_parse_cmdline_data_valid(self): + parse = DataSourceNoCloud.parse_cmdline_data + + ds_id = "ds=nocloud" + pairs = ( + ("root=/dev/sda1 %(ds_id)s", {}), + ("%(ds_id)s; root=/dev/foo", {}), + ("%(ds_id)s", {}), + ("%(ds_id)s;", {}), + ("%(ds_id)s;s=SEED", {'seedfrom': 'SEED'}), + ("%(ds_id)s;seedfrom=SEED;local-hostname=xhost", + {'seedfrom': 'SEED', 'local-hostname': 'xhost'}), + ("%(ds_id)s;h=xhost", + {'local-hostname': 'xhost'}), + ("%(ds_id)s;h=xhost;i=IID", + {'local-hostname': 'xhost', 'instance-id': 'IID'}), + ) + + for (fmt, expected) in pairs: + fill = {} + cmdline = fmt % {'ds_id': ds_id} + ret = parse(ds_id=ds_id, fill=fill, cmdline=cmdline) + self.assertEqual(expected, fill) + self.assertTrue(ret) + + def test_parse_cmdline_data_none(self): + parse = DataSourceNoCloud.parse_cmdline_data + + ds_id = "ds=foo" + cmdlines = ( + "root=/dev/sda1 ro", + "console=/dev/ttyS0 root=/dev/foo", + "", + "ds=foocloud", + "ds=foo-net", + "ds=nocloud;s=SEED", + ) + + for cmdline in cmdlines: + fill = {} + ret = parse(ds_id=ds_id, fill=fill, cmdline=cmdline) + self.assertEqual(fill, {}) + self.assertFalse(ret) + + +# vi: ts=4 expandtab |