summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2017-03-30 16:46:43 -0400
committergit-ubuntu importer <ubuntu-devel-discuss@lists.ubuntu.com>2017-03-31 10:56:42 +0000
commit9bf73ec48325846266c38879cec649290c496e72 (patch)
treee5f408f7929e8c9af5e57579beae5e09f2160e7b /tests
parent0621e2f9206715e126e31a187c2615d0de71812c (diff)
downloadcloud-init-git-9bf73ec48325846266c38879cec649290c496e72.tar.gz
0.7.9-87-gd23543eb-0ubuntu1 (patches unapplied)
Imported using git-ubuntu import.
Diffstat (limited to 'tests')
-rw-r--r--tests/cloud_tests/configs/modules/set_password_list.yaml3
-rw-r--r--tests/cloud_tests/configs/modules/set_password_list_string.yaml3
-rw-r--r--tests/cloud_tests/testcases/base.py4
-rw-r--r--tests/unittests/test_datasource/test_gce.py14
-rw-r--r--tests/unittests/test_net.py67
5 files changed, 89 insertions, 2 deletions
diff --git a/tests/cloud_tests/configs/modules/set_password_list.yaml b/tests/cloud_tests/configs/modules/set_password_list.yaml
index a1eadd75..a2a89c9d 100644
--- a/tests/cloud_tests/configs/modules/set_password_list.yaml
+++ b/tests/cloud_tests/configs/modules/set_password_list.yaml
@@ -21,11 +21,14 @@ cloud_config: |
# sha256 gojanego
passwd: "$5$iW$XsxmWCdpwIW8Yhv.Jn/R3uk6A4UaicfW5Xp7C9p9pg."
lock_passwd: false
+ - name: "mikey"
+ lock_passwd: false
chpasswd:
list:
- tom:mypassword123!
- dick:RANDOM
- harry:RANDOM
+ - mikey:$5$xZ$B2YGGEx2AOf4PeW48KC6.QyT1W2B4rZ9Qbltudtha89
collect_scripts:
shadow: |
#!/bin/bash
diff --git a/tests/cloud_tests/configs/modules/set_password_list_string.yaml b/tests/cloud_tests/configs/modules/set_password_list_string.yaml
index cbb71bee..c2a0f631 100644
--- a/tests/cloud_tests/configs/modules/set_password_list_string.yaml
+++ b/tests/cloud_tests/configs/modules/set_password_list_string.yaml
@@ -21,11 +21,14 @@ cloud_config: |
# sha256 gojanego
passwd: "$5$iW$XsxmWCdpwIW8Yhv.Jn/R3uk6A4UaicfW5Xp7C9p9pg."
lock_passwd: false
+ - name: "mikey"
+ lock_passwd: false
chpasswd:
list: |
tom:mypassword123!
dick:RANDOM
harry:RANDOM
+ mikey:$5$xZ$B2YGGEx2AOf4PeW48KC6.QyT1W2B4rZ9Qbltudtha89
collect_scripts:
shadow: |
#!/bin/bash
diff --git a/tests/cloud_tests/testcases/base.py b/tests/cloud_tests/testcases/base.py
index 51ce2b41..64d5507a 100644
--- a/tests/cloud_tests/testcases/base.py
+++ b/tests/cloud_tests/testcases/base.py
@@ -98,6 +98,9 @@ class PasswordListTest(CloudTestCase):
self.assertEqual([], dupes)
self.assertEqual(jane_enc, users['jane'])
+ mikey_enc = "$5$xZ$B2YGGEx2AOf4PeW48KC6.QyT1W2B4rZ9Qbltudtha89"
+ self.assertEqual(mikey_enc, users['mikey'])
+
# shadow entry is $N$salt$, so we encrypt with the same format
# and salt and expect the result.
tom = "mypassword123!"
@@ -124,6 +127,7 @@ class PasswordListTest(CloudTestCase):
self.assertIn('dick:', out)
self.assertIn('harry:', out)
self.assertIn('jane:', out)
+ self.assertIn('mikey:', out)
def test_sshd_config(self):
"""Test sshd config allows passwords"""
diff --git a/tests/unittests/test_datasource/test_gce.py b/tests/unittests/test_datasource/test_gce.py
index 4f83454e..3eaa58e3 100644
--- a/tests/unittests/test_datasource/test_gce.py
+++ b/tests/unittests/test_datasource/test_gce.py
@@ -5,6 +5,7 @@
# This file is part of cloud-init. See LICENSE file for license information.
import httpretty
+import mock
import re
from base64 import b64encode, b64decode
@@ -71,6 +72,11 @@ class TestDataSourceGCE(test_helpers.HttprettyTestCase):
self.ds = DataSourceGCE.DataSourceGCE(
settings.CFG_BUILTIN, None,
helpers.Paths({}))
+ self.m_platform_reports_gce = mock.patch(
+ 'cloudinit.sources.DataSourceGCE.platform_reports_gce',
+ return_value=True)
+ self.m_platform_reports_gce.start()
+ self.addCleanup(self.m_platform_reports_gce.stop)
super(TestDataSourceGCE, self).setUp()
def test_connection(self):
@@ -153,7 +159,13 @@ class TestDataSourceGCE(test_helpers.HttprettyTestCase):
def test_only_last_part_of_zone_used_for_availability_zone(self):
_set_mock_metadata()
- self.ds.get_data()
+ r = self.ds.get_data()
+ self.assertEqual(True, r)
self.assertEqual('bar', self.ds.availability_zone)
+ def test_get_data_returns_false_if_not_on_gce(self):
+ self.m_platform_reports_gce.return_value = False
+ self.assertEqual(False, self.ds.get_data())
+
+
# vi: ts=4 expandtab
diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
index 4f07d804..bfd04ba0 100644
--- a/tests/unittests/test_net.py
+++ b/tests/unittests/test_net.py
@@ -974,12 +974,14 @@ iface eth0 inet dhcp
class TestNetplanNetRendering(CiTestCase):
+ @mock.patch("cloudinit.net.netplan._clean_default")
@mock.patch("cloudinit.net.sys_dev_path")
@mock.patch("cloudinit.net.read_sys_net")
@mock.patch("cloudinit.net.get_devicelist")
def test_default_generation(self, mock_get_devicelist,
mock_read_sys_net,
- mock_sys_dev_path):
+ mock_sys_dev_path,
+ mock_clean_default):
tmp_dir = self.tmp_dir()
_setup_test(tmp_dir, mock_get_devicelist,
mock_read_sys_net, mock_sys_dev_path)
@@ -1013,6 +1015,69 @@ network:
set-name: eth1000
"""
self.assertEqual(expected.lstrip(), contents.lstrip())
+ self.assertEqual(1, mock_clean_default.call_count)
+
+
+class TestNetplanCleanDefault(CiTestCase):
+ snapd_known_path = 'etc/netplan/00-snapd-config.yaml'
+ snapd_known_content = textwrap.dedent("""\
+ # This is the initial network config.
+ # It can be overwritten by cloud-init or console-conf.
+ network:
+ version: 2
+ ethernets:
+ all-en:
+ match:
+ name: "en*"
+ dhcp4: true
+ all-eth:
+ match:
+ name: "eth*"
+ dhcp4: true
+ """)
+ stub_known = {
+ 'run/systemd/network/10-netplan-all-en.network': 'foo-en',
+ 'run/systemd/network/10-netplan-all-eth.network': 'foo-eth',
+ 'run/systemd/generator/netplan.stamp': 'stamp',
+ }
+
+ def test_clean_known_config_cleaned(self):
+ content = {self.snapd_known_path: self.snapd_known_content, }
+ content.update(self.stub_known)
+ tmpd = self.tmp_dir()
+ files = sorted(populate_dir(tmpd, content))
+ netplan._clean_default(target=tmpd)
+ found = [t for t in files if os.path.exists(t)]
+ self.assertEqual([], found)
+
+ def test_clean_unknown_config_not_cleaned(self):
+ content = {self.snapd_known_path: self.snapd_known_content, }
+ content.update(self.stub_known)
+ content[self.snapd_known_path] += "# user put a comment\n"
+ tmpd = self.tmp_dir()
+ files = sorted(populate_dir(tmpd, content))
+ netplan._clean_default(target=tmpd)
+ found = [t for t in files if os.path.exists(t)]
+ self.assertEqual(files, found)
+
+ def test_clean_known_config_cleans_only_expected(self):
+ astamp = "run/systemd/generator/another.stamp"
+ anet = "run/systemd/network/10-netplan-all-lo.network"
+ ayaml = "etc/netplan/01-foo-config.yaml"
+ content = {
+ self.snapd_known_path: self.snapd_known_content,
+ astamp: "stamp",
+ anet: "network",
+ ayaml: "yaml",
+ }
+ content.update(self.stub_known)
+
+ tmpd = self.tmp_dir()
+ files = sorted(populate_dir(tmpd, content))
+ netplan._clean_default(target=tmpd)
+ found = [t for t in files if os.path.exists(t)]
+ expected = [util.target_path(tmpd, f) for f in (astamp, anet, ayaml)]
+ self.assertEqual(sorted(expected), found)
class TestNetplanPostcommands(CiTestCase):