diff options
author | Ben Howard <ben.howard@canonical.com> | 2015-01-14 12:24:09 -0700 |
---|---|---|
committer | Ben Howard <ben.howard@canonical.com> | 2015-01-14 12:24:09 -0700 |
commit | 28c8aa7270a04adea69065477b13cfc0dd244acc (patch) | |
tree | 76f2535102b42f25995e25a5829ede283510cf03 /tests/unittests/test_util.py | |
parent | 62e9e73e3ed8467fc4d4d95f76ed0443c50f176c (diff) | |
download | vyos-cloud-init-28c8aa7270a04adea69065477b13cfc0dd244acc.tar.gz vyos-cloud-init-28c8aa7270a04adea69065477b13cfc0dd244acc.zip |
Drop reliance on dmidecode executable.
Diffstat (limited to 'tests/unittests/test_util.py')
-rw-r--r-- | tests/unittests/test_util.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/unittests/test_util.py b/tests/unittests/test_util.py index 35e92445..6ae41bd6 100644 --- a/tests/unittests/test_util.py +++ b/tests/unittests/test_util.py @@ -310,4 +310,32 @@ class TestMountinfoParsing(helpers.ResourceUsingTestCase): expected = ('none', 'tmpfs', '/run/lock') self.assertEqual(expected, util.parse_mount_info('/run/lock', lines)) + +class TestReadDMIData(helpers.FilesystemMockingTestCase): + + def _patchIn(self, root): + self.restore() + self.patchOS(root) + self.patchUtils(root) + + def _write_key(self, key, content): + new_root = self.makeDir() + self._patchIn(new_root) + util.ensure_dir(os.path.join('sys', 'class', 'dmi', 'id')) + + dmi_key = "/sys/class/dmi/id/{}".format(key) + util.write_file(dmi_key, content) + + def test_key(self): + key_content = "TEST-KEY-DATA" + self._write_key("key", key_content) + self.assertEquals(key_content, util.read_dmi_data("key")) + + def test_key_mismatch(self): + self._write_key("test", "ABC") + self.assertNotEqual("123", util.read_dmi_data("test")) + + def test_no_key(self): + self.assertFalse(util.read_dmi_data("key")) + # vi: ts=4 expandtab |