← Back to team overview

cloud-init-dev team mailing list archive

Re: [Merge] lp:~gfidente/cloud-init/try_fqdn_from_hosts into lp:cloud-init

 


Diff comments:

> 
> === modified file 'tests/unittests/test_util.py'
> --- tests/unittests/test_util.py	2016-03-14 13:45:11 +0000
> +++ tests/unittests/test_util.py	2016-05-14 00:02:24 +0000
> @@ -69,6 +83,85 @@
>          self.assertEqual([], result)
>  
>  
> +class TestGetHostnameFqdn(helpers.TestCase):
> +    def setUp(self):
> +        super(TestGetHostnameFqdn, self).setUp()
> +        tmp_h, self.tmp_path = tempfile.mkstemp()
> +        self.f = os.fdopen(tmp_h, "w")

Can u change this to self.addCleanup(os.remove, self.tmp_path)

> +        self.f.write("9.10.11.12 cloudname.clouddomain cloudname\n")
> +        self.f.close()
> +        self.cloud = FakeCloudWithDomain()
> +        self.cloud_no_domain = FakeCloudWithoutDomain()
> +
> +    def tearDown(self):
> +        super(TestGetHostnameFqdn, self).tearDown()
> +        os.remove(self.tmp_path)
> +
> +    def test_with_fqdn(self):
> +        """Results based only on fqdn config key"""
> +        cfg = {'fqdn': 'thisname.thisdomain'}
> +        hostname, fqdn = util.get_hostname_fqdn(cfg, self.cloud, self.tmp_path)
> +        self.assertEqual("thisname", hostname)
> +        self.assertEqual("thisname.thisdomain", fqdn)
> +
> +    def test_with_dotted_hostname(self):
> +        """Results based only on hostname config key"""
> +        cfg = {'hostname': 'thisname.thisdomain'}
> +        hostname, fqdn = util.get_hostname_fqdn(cfg, self.cloud, self.tmp_path)
> +        self.assertEqual("thisname", hostname)
> +        self.assertEqual("thisname.thisdomain", fqdn)
> +
> +    def test_with_short_hostname(self):
> +        """The hostname is from config key, the fqdn from cloud"""
> +        cfg = {'hostname': 'thisname'}
> +        hostname, fqdn = util.get_hostname_fqdn(cfg, self.cloud, self.tmp_path)
> +        self.assertEqual("thisname", hostname)
> +        self.assertEqual("cloudname.clouddomain", fqdn)
> +
> +    def test_from_cloud(self):
> +        """Results based only on cloud"""
> +        cfg = {}
> +        hostname, fqdn = util.get_hostname_fqdn(cfg, self.cloud, self.tmp_path)
> +        self.assertEqual("cloudname", hostname)
> +        self.assertEqual("cloudname.clouddomain", fqdn)
> +
> +    def test_from_cloud_without_domain(self):
> +        """The hostname is from cloud, the fqdn mapped from hosts file"""
> +        cfg = {}
> +        hostname, fqdn = util.get_hostname_fqdn(cfg,
> +                                                self.cloud_no_domain,
> +                                                self.tmp_path)
> +        self.assertEqual("cloudname", hostname)
> +        self.assertEqual("cloudname.clouddomain", fqdn)
> +
> +
> +class TestGetFqdnFromHosts(helpers.TestCase):
> +    def setUp(self):
> +        super(TestGetFqdnFromHosts, self).setUp()
> +        tmp_h, self.tmp_path = tempfile.mkstemp()
> +        self.f = os.fdopen(tmp_h, "w")
> +        self.f.write("# comment\n")
> +        self.f.write("1.2.3.4 name.domain name\n")
> +        self.f.write("5.6.7.8 myname.mydomain myname # comment\n")
> +        self.f.close()
> +
> +    def tearDown(self):
> +        super(TestGetFqdnFromHosts, self).tearDown()
> +        os.remove(self.tmp_path)

Same as above.

https://docs.python.org/2.7/library/unittest.html#unittest.TestCase.addCleanup

> +
> +    def test_fqdn_found(self):
> +        """Test fqdn is returned when hostname is found"""
> +        hostname = "myname"
> +        fqdn = util.get_fqdn_from_hosts(hostname, self.tmp_path)
> +        self.assertEqual("myname.mydomain", fqdn)
> +
> +    def test_fqdn_not_found(self):
> +        """Test None is returned when hostname is not found"""
> +        hostname = "unnamed"
> +        fqdn = util.get_fqdn_from_hosts(hostname, self.tmp_path)
> +        self.assertEqual(None, fqdn)
> +
> +
>  class TestWriteFile(helpers.TestCase):
>      def setUp(self):
>          super(TestWriteFile, self).setUp()


-- 
https://code.launchpad.net/~gfidente/cloud-init/try_fqdn_from_hosts/+merge/294680
Your team cloud init development team is requested to review the proposed merge of lp:~gfidente/cloud-init/try_fqdn_from_hosts into lp:cloud-init.


References