Skip to content

Commit

Permalink
test: create_hostname_file set to false in all /etc/hostname distros
Browse files Browse the repository at this point in the history
This config adds unit tests for all the non-BSD updated cc_set_hostname
calls for the create_hostname_file being set to False (i.e. testing that
the file is not created)
  • Loading branch information
catmsred committed Aug 24, 2023
1 parent da58505 commit fac2306
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions tests/unittests/config/test_cc_set_hostname.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,5 +259,95 @@ def test_ignore_empty_previous_artifact_file(self):
contents = util.load_file("/etc/hostname")
self.assertEqual("blah", contents.strip())

def test_create_hostname_file_false(self):
cfg = {
"hostname": "foo",
"fqdn": "foo.blah.yahoo.com",
"create_hostname_file": False,
}
distro = self._fetch_distro("debian")
paths = helpers.Paths({"cloud_dir": self.tmp})
ds = None
cc = cloud.Cloud(ds, paths, {}, distro, None)
self.patchUtils(self.tmp)
cc_set_hostname.handle("cc_set_hostname", cfg, cc, [])
with self.assertRaises(FileNotFoundError):
util.load_file("/etc/hostname")

def test_create_hostname_file_false_arch(self):
cfg = {
"hostname": "foo",
"fqdn": "foo.blah.yahoo.com",
"create_hostname_file": False,
}
distro = self._fetch_distro("arch")
paths = helpers.Paths({"cloud_dir": self.tmp})
ds = None
cc = cloud.Cloud(ds, paths, {}, distro, None)
self.patchUtils(self.tmp)
cc_set_hostname.handle("cc_set_hostname", cfg, cc, [])
with self.assertRaises(FileNotFoundError):
util.load_file("/etc/hostname")

def test_create_hostname_file_false_alpine(self):
cfg = {
"hostname": "foo",
"fqdn": "foo.blah.yahoo.com",
"create_hostname_file": False,
}
distro = self._fetch_distro("alpine")
paths = helpers.Paths({"cloud_dir": self.tmp})
ds = None
cc = cloud.Cloud(ds, paths, {}, distro, None)
self.patchUtils(self.tmp)
cc_set_hostname.handle("cc_set_hostname", cfg, cc, [])
with self.assertRaises(FileNotFoundError):
util.load_file("/etc/hostname")

def test_create_hostname_file_false_gentoo(self):
cfg = {
"hostname": "foo",
"fqdn": "foo.blah.yahoo.com",
"create_hostname_file": False,
}
distro = self._fetch_distro("gentoo")
paths = helpers.Paths({"cloud_dir": self.tmp})
ds = None
cc = cloud.Cloud(ds, paths, {}, distro, None)
self.patchUtils(self.tmp)
cc_set_hostname.handle("cc_set_hostname", cfg, cc, [])
with self.assertRaises(FileNotFoundError):
util.load_file("/etc/hostname")

def test_create_hostname_file_false_photon(self):
cfg = {
"hostname": "foo",
"fqdn": "foo.blah.yahoo.com",
"create_hostname_file": False,
}
distro = self._fetch_distro("photon")
paths = helpers.Paths({"cloud_dir": self.tmp})
ds = None
cc = cloud.Cloud(ds, paths, {}, distro, None)
self.patchUtils(self.tmp)
cc_set_hostname.handle("cc_set_hostname", cfg, cc, [])
with self.assertRaises(FileNotFoundError):
util.load_file("/etc/hostname")

def test_create_hostname_file_false_rhel(self):
cfg = {
"hostname": "foo",
"fqdn": "foo.blah.yahoo.com",
"create_hostname_file": False,
}
distro = self._fetch_distro("rhel")
paths = helpers.Paths({"cloud_dir": self.tmp})
ds = None
cc = cloud.Cloud(ds, paths, {}, distro, None)
self.patchUtils(self.tmp)
cc_set_hostname.handle("cc_set_hostname", cfg, cc, [])
with self.assertRaises(FileNotFoundError):
util.load_file("/etc/hostname")


# vi: ts=4 expandtab

0 comments on commit fac2306

Please sign in to comment.