Merge pull request #47939 from steveno/make_postgres_version_compare_more_robust

Make postgres version compare more robust
This commit is contained in:
Nicole Thomas 2018-06-08 16:02:32 -04:00 committed by GitHub
commit e456f84d95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 3 deletions

View File

@ -1465,10 +1465,10 @@ def is_available_extension(name,
def _pg_is_older_ext_ver(a, b): def _pg_is_older_ext_ver(a, b):
'''Return true if version a is lesser than b '''Return true if version a is lesser than b
TODO: be more intelligent to test versions
Compare versions of extensions using salt.utils.versions.LooseVersion
''' '''
return a < b return _LooseVersion(a) < _LooseVersion(b)
def is_installed_extension(name, def is_installed_extension(name,

View File

@ -1479,3 +1479,22 @@ class PostgresTestCase(TestCase, LoaderModuleMockMixin):
name = '/var/lib/pgsql/data' name = '/var/lib/pgsql/data'
ret = postgres.datadir_exists(name) ret = postgres.datadir_exists(name)
self.assertTrue(ret) self.assertTrue(ret)
def test_pg_is_older_ext_ver(self):
'''
Test Checks if postgres extension version string is older
'''
self.assertTrue(postgres._pg_is_older_ext_ver('8.5', '9.5'))
self.assertTrue(postgres._pg_is_older_ext_ver('8.5', '8.6'))
self.assertTrue(postgres._pg_is_older_ext_ver('8.5.2', '8.5.3'))
self.assertFalse(postgres._pg_is_older_ext_ver('9.5', '8.5'))
self.assertTrue(postgres._pg_is_older_ext_ver('9.5', '9.6'))
self.assertTrue(postgres._pg_is_older_ext_ver('9.5.0', '9.5.1'))
self.assertTrue(postgres._pg_is_older_ext_ver('9.5', '9.5.1'))
self.assertFalse(postgres._pg_is_older_ext_ver('9.5.1', '9.5'))
self.assertFalse(postgres._pg_is_older_ext_ver('9.5b', '9.5a'))
self.assertTrue(postgres._pg_is_older_ext_ver('10a', '10b'))
self.assertTrue(postgres._pg_is_older_ext_ver('1.2.3.4', '1.2.3.5'))
self.assertTrue(postgres._pg_is_older_ext_ver('10dev', '10next'))
self.assertFalse(postgres._pg_is_older_ext_ver('10next', '10dev'))