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',
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(),
from mock import patch
from ceph_deploy.hosts import remotes
-
+from ceph_deploy.hosts.remotes import platform_information
class FakeExists(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'