mirror of
https://github.com/clearlinux/WALinuxAgent.git
synced 2026-09-06 22:01:34 +00:00
Fix extension version compare
This commit is contained in:
@@ -30,6 +30,7 @@ from azurelinuxagent.exception import ExtensionError
|
||||
import azurelinuxagent.utils.fileutil as fileutil
|
||||
import azurelinuxagent.utils.restutil as restutil
|
||||
import azurelinuxagent.utils.shellutil as shellutil
|
||||
from azurelinuxagent.utils.textutil import Version
|
||||
|
||||
#HandlerEnvironment.json schema version
|
||||
HANDLER_ENVIRONMENT_VERSION = 1.0
|
||||
@@ -163,7 +164,8 @@ def get_installed_version(target_name):
|
||||
name, version = parse_extension_dirname(dir_name)
|
||||
#Here we need to ensure names are exactly the same.
|
||||
if name == target_name:
|
||||
if installed_version is None or installed_version < version:
|
||||
if installed_version is None or \
|
||||
Version(installed_version) < Version(version):
|
||||
installed_version = version
|
||||
return installed_version
|
||||
|
||||
@@ -216,14 +218,14 @@ class ExtensionInstance(object):
|
||||
def handle_enable(self):
|
||||
target_version = self.get_target_version()
|
||||
if self.installed:
|
||||
if target_version > self.curr_version:
|
||||
if Version(target_version) > Version(self.curr_version):
|
||||
self.upgrade(target_version)
|
||||
elif target_version == self.curr_version:
|
||||
elif Version(target_version) == Version(self.curr_version):
|
||||
self.enable()
|
||||
else:
|
||||
raise ExtensionError("A newer version has already been installed")
|
||||
else:
|
||||
if target_version > self.get_version():
|
||||
if Version(target_version) > Version(self.curr_version):
|
||||
#This will happen when auto upgrade policy is enabled
|
||||
self.logger.info("Auto upgrade to new version:{0}",
|
||||
target_version)
|
||||
@@ -509,21 +511,23 @@ class ExtensionInstance(object):
|
||||
if major is None:
|
||||
raise ExtensionError("Wrong version format: {0}".format(version))
|
||||
|
||||
packages = [x for x in self.pkg_list.versions if x.version.startswith(major + ".")]
|
||||
packages = sorted(packages, key=lambda x: x.version, reverse=True)
|
||||
packages = [x for x in self.pkg_list.versions \
|
||||
if x.version.startswith(major + ".")]
|
||||
packages = sorted(packages, key=lambda x: Version(x.version),
|
||||
reverse=True)
|
||||
if len(packages) <= 0:
|
||||
raise ExtensionError("Can't find version: {0}.*".format(major))
|
||||
|
||||
return packages[0].version
|
||||
|
||||
def get_package_uris(self):
|
||||
version = self.get_version()
|
||||
version = self.curr_version
|
||||
packages = self.pkg_list.versions
|
||||
if packages is None:
|
||||
raise ExtensionError("Package uris is None.")
|
||||
|
||||
for package in packages:
|
||||
if package.version == version:
|
||||
if Version(package.version) == Version(version):
|
||||
return package.uris
|
||||
|
||||
raise ExtensionError("Can't get package uris for {0}.".format(version))
|
||||
|
||||
@@ -22,6 +22,7 @@ import string
|
||||
import struct
|
||||
import xml.dom.minidom as minidom
|
||||
import sys
|
||||
from distutils.version import LooseVersion
|
||||
|
||||
def parse_doc(xml_text):
|
||||
"""
|
||||
@@ -223,4 +224,4 @@ def gen_password_hash(password, crypt_id, salt_len):
|
||||
salt = "${0}${1}".format(crypt_id, salt)
|
||||
return crypt.crypt(password, salt)
|
||||
|
||||
|
||||
Version = LooseVersion
|
||||
|
||||
+18
-1
@@ -25,6 +25,7 @@ import unittest
|
||||
import os
|
||||
from azurelinuxagent.future import text
|
||||
import azurelinuxagent.utils.textutil as textutil
|
||||
from azurelinuxagent.utils.textutil import Version
|
||||
|
||||
class TestTextUtil(unittest.TestCase):
|
||||
def test_get_password_hash(self):
|
||||
@@ -44,6 +45,22 @@ class TestTextUtil(unittest.TestCase):
|
||||
data = textutil.remove_bom(data)
|
||||
self.assertEquals(u"h", data[0])
|
||||
|
||||
|
||||
def test_version_compare(self) :
|
||||
self.assertTrue(Version("1.0") < Version("1.1"))
|
||||
self.assertTrue(Version("1.9") < Version("1.10"))
|
||||
self.assertTrue(Version("1.9.9") < Version("1.10.0"))
|
||||
self.assertTrue(Version("1.0.0.0") < Version("1.2.0.0"))
|
||||
|
||||
self.assertTrue(Version("1.0") <= Version("1.1"))
|
||||
self.assertTrue(Version("1.1") > Version("1.0"))
|
||||
self.assertTrue(Version("1.1") >= Version("1.0"))
|
||||
|
||||
self.assertTrue(Version("1.0") == Version("1.0"))
|
||||
self.assertTrue(Version("1.0") >= Version("1.0"))
|
||||
self.assertTrue(Version("1.0") <= Version("1.0"))
|
||||
|
||||
self.assertTrue(Version("1.9") < "1.10")
|
||||
self.assertTrue("1.9" < Version("1.10"))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user