From: Andrew Woodward Date: Thu, 9 Jan 2014 00:24:37 +0000 (-0800) Subject: Add test to properly catch debian/sid strings from version X-Git-Tag: v1.3.5~13^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=201c5d0649ffe2fa404cc1a4f11d002bd09a6eef;p=ceph-deploy.git Add test to properly catch debian/sid strings from version strings for wheezy/sid and jessie/sid aren't caught by the version number test already implmented. Adds test to check if codename is still empty and version contains a slash if so, and minor is sid, we set codename to sid. Otherwise we set codename to major. Adds test cases for platform_information to test expected usage patterns and covers some common os strings. Futher assessment may then made to see if we should then refuse jessie or sid Signed-off-by: Andrew Woodward --- diff --git a/ceph_deploy/hosts/remotes.py b/ceph_deploy/hosts/remotes.py index 2f5e544..f6f9008 100644 --- a/ceph_deploy/hosts/remotes.py +++ b/ceph_deploy/hosts/remotes.py @@ -6,9 +6,10 @@ import tempfile import platform -def platform_information(): +def platform_information(_linux_distribution=None): """ detect platform information from remote host """ - distro, release, codename = platform.linux_distribution() + linux_distribution = _linux_distribution or platform.linux_distribution + distro, release, codename = linux_distribution() if not codename and 'debian' in distro.lower(): # this could be an empty string in Debian debian_codenames = { '8': 'jessie', @@ -18,6 +19,15 @@ def platform_information(): major_version = release.split('.')[0] codename = debian_codenames.get(major_version, '') + # In order to support newer jessie/sid or wheezy/sid strings we test this + # if sid is buried in the minor, we should use sid anyway. + if not codename and '/' in release: + major, minor = release.split('/') + if minor == 'sid': + codename = minor + else: + codename = major + return ( str(distro).rstrip(), str(release).rstrip(), diff --git a/ceph_deploy/tests/test_remotes.py b/ceph_deploy/tests/test_remotes.py index 42d23b1..7138429 100644 --- a/ceph_deploy/tests/test_remotes.py +++ b/ceph_deploy/tests/test_remotes.py @@ -1,6 +1,6 @@ from mock import patch from ceph_deploy.hosts import remotes - +from ceph_deploy.hosts.remotes import platform_information class FakeExists(object): @@ -30,3 +30,56 @@ class TestWhich(object): path = remotes.which('ls') assert path is None +class TestPlatformInformation(object): + """ tests various inputs that remotes.platform_information handles + + you can test your OS string by comparing the results with the output from: + python -c "import platform; print platform.linux_distribution()" + """ + + def setup(self): + pass + + def test_handles_deb_version_num(self): + def fake_distro(): return ('debian', '8.4', '') + distro, release, codename = platform_information(fake_distro) + assert distro == 'debian' + assert release == '8.4' + assert codename == 'jessie' + + def test_handles_deb_version_slash(self): + def fake_distro(): return ('debian', 'wheezy/something', '') + distro, release, codename = platform_information(fake_distro) + assert distro == 'debian' + assert release == 'wheezy/something' + assert codename == 'wheezy' + + def test_handles_deb_version_slash_sid(self): + def fake_distro(): return ('debian', 'jessie/sid', '') + distro, release, codename = platform_information(fake_distro) + assert distro == 'debian' + assert release == 'jessie/sid' + assert codename == 'sid' + + def test_handles_no_codename(self): + def fake_distro(): return ('SlaOS', '99.999', '') + distro, release, codename = platform_information(fake_distro) + assert distro == 'SlaOS' + assert release == '99.999' + assert codename == '' + + # Normal distro strings + def test_hanles_centos_64(self): + def fake_distro(): return ('CentOS', '6.4', 'Final') + distro, release, codename = platform_information(fake_distro) + assert distro == 'CentOS' + assert release == '6.4' + assert codename == 'Final' + + + def test_handles_ubuntu_percise(self): + def fake_distro(): return ('Ubuntu', '12.04', 'precise') + distro, release, codename = platform_information(fake_distro) + assert distro == 'Ubuntu' + assert release == '12.04' + assert codename == 'precise'