From 2a654827fbc0030fc5c138c7af464a54fb6ae9b2 Mon Sep 17 00:00:00 2001 From: Alexander Verhaar Date: Tue, 1 Feb 2022 14:29:12 +0100 Subject: [PATCH] Make integration tests working with python3 --- cosmic-core/test/integration/tests/cosmic/SshClient.py | 2 +- cosmic-core/test/integration/tests/cosmic/base.py | 10 +++++----- .../test/integration/tests/cosmic/cosmicTestCase.py | 2 +- .../test/integration/tests/cosmic/cosmicTestClient.py | 6 +++--- .../test/integration/tests/cosmic/dbConnection.py | 4 ++-- cosmic-core/test/integration/tests/cosmic/utils.py | 8 ++++---- .../tests/test_password_and_dnsmasq_service.py | 2 +- .../test/integration/tests/test_password_server.py | 2 +- .../test/integration/tests/test_vm_migration.py | 2 +- 9 files changed, 19 insertions(+), 19 deletions(-) diff --git a/cosmic-core/test/integration/tests/cosmic/SshClient.py b/cosmic-core/test/integration/tests/cosmic/SshClient.py index 00e99f1a13..e7da3a330b 100644 --- a/cosmic-core/test/integration/tests/cosmic/SshClient.py +++ b/cosmic-core/test/integration/tests/cosmic/SshClient.py @@ -11,7 +11,7 @@ SFTPClient ) -from codes import ( +from .codes import ( SUCCESS, FAILED, INVALID_INPUT diff --git a/cosmic-core/test/integration/tests/cosmic/base.py b/cosmic-core/test/integration/tests/cosmic/base.py index d7c2f637ee..bcb36853c4 100644 --- a/cosmic-core/test/integration/tests/cosmic/base.py +++ b/cosmic-core/test/integration/tests/cosmic/base.py @@ -5,8 +5,8 @@ import base64 from abc import ABCMeta, abstractmethod -from common import * -from utils import * +from .common import * +from .utils import * class BaseAbstract: @@ -503,7 +503,7 @@ def create(cls, api_client, services=None, templateid=None, accountid=None, doma # TODO: This is probably not correct, fix it cmd['details[0]["memory"]'] = custommemory - if rootdisksize >= 0: + if rootdisksize and rootdisksize >= 0: cmd['details[0]["rootdisksize"]'] = rootdisksize if group: @@ -655,7 +655,7 @@ def validateState(self, api_client, state, timeout=600, interval=5): @staticmethod def state_check_function(objects, state): - return str(objects[0].state).lower().decode("string_escape") == str(state).lower() + return str(objects[0].state).lower() == str(state).lower() def resetSshKey(self, api_client, **kwargs): """Resets SSH key""" @@ -3638,7 +3638,7 @@ def create(cls, api_client, services=None, vpcofferingid=None, zoneid=None, netw if "cidr" in services: cmd['cidr'] = services["cidr"] if account: - if isinstance(account, basestring): + if isinstance(account, str): cmd['account'] = account else: cmd['account'] = account.name diff --git a/cosmic-core/test/integration/tests/cosmic/cosmicTestCase.py b/cosmic-core/test/integration/tests/cosmic/cosmicTestCase.py index bcceb3c037..b579f02dc6 100644 --- a/cosmic-core/test/integration/tests/cosmic/cosmicTestCase.py +++ b/cosmic-core/test/integration/tests/cosmic/cosmicTestCase.py @@ -2,7 +2,7 @@ import time -from cosmicTestClient import CosmicTestClient +from .cosmicTestClient import CosmicTestClient class cosmicTestCase(unittest.TestCase): diff --git a/cosmic-core/test/integration/tests/cosmic/cosmicTestClient.py b/cosmic-core/test/integration/tests/cosmic/cosmicTestClient.py index 31f4ab14e5..e7d28b2f82 100644 --- a/cosmic-core/test/integration/tests/cosmic/cosmicTestClient.py +++ b/cosmic-core/test/integration/tests/cosmic/cosmicTestClient.py @@ -6,9 +6,9 @@ import copy from cs import CloudStack -from cosmicLog import CosmicLog -from dbConnection import DbConnection -from utils import * +from .cosmicLog import CosmicLog +from .dbConnection import DbConnection +from .utils import * class Cosmic(CloudStack): diff --git a/cosmic-core/test/integration/tests/cosmic/dbConnection.py b/cosmic-core/test/integration/tests/cosmic/dbConnection.py index c9f6a80280..0b27325249 100644 --- a/cosmic-core/test/integration/tests/cosmic/dbConnection.py +++ b/cosmic-core/test/integration/tests/cosmic/dbConnection.py @@ -47,7 +47,7 @@ def executeSqlFromFile(self, fileName=None): if __name__ == "__main__": db = DbConnection() - print db.execute("update vm_template set name='fjkd' where id=200") + print(db.execute("update vm_template set name='fjkd' where id=200")) for i in range(10): result = db.execute("select job_status, created, last_updated from async_job where id=%d" % i) - print result + print(result) diff --git a/cosmic-core/test/integration/tests/cosmic/utils.py b/cosmic-core/test/integration/tests/cosmic/utils.py index 560463e306..e63e566803 100644 --- a/cosmic-core/test/integration/tests/cosmic/utils.py +++ b/cosmic-core/test/integration/tests/cosmic/utils.py @@ -3,10 +3,10 @@ import sys import time import traceback -import urlparse -from SshClient import SshClient -from codes import * +from urllib.parse import urlparse +from .SshClient import SshClient +from .codes import * class AttrDict(dict): @@ -129,7 +129,7 @@ def attr(*args, **kwargs): def wrap_ob(ob): for name in args: setattr(ob, name, True) - for name, value in kwargs.iteritems(): + for name, value in kwargs.items(): setattr(ob, name, value) return ob diff --git a/cosmic-core/test/integration/tests/test_password_and_dnsmasq_service.py b/cosmic-core/test/integration/tests/test_password_and_dnsmasq_service.py index 582e905581..4eb472b67a 100755 --- a/cosmic-core/test/integration/tests/test_password_and_dnsmasq_service.py +++ b/cosmic-core/test/integration/tests/test_password_and_dnsmasq_service.py @@ -276,7 +276,7 @@ def _test_password_server_logs(self, vm, router): router_state = self.get_router_state(router) if router.isredundantrouter and router_state != "MASTER": - print "Found router in non-MASTER state '" + router.redundantstate + "' so skipping test." + print("Found router in non-MASTER state '" + router.redundantstate + "' so skipping test.") return True # Get the related passwd server logs for our vm diff --git a/cosmic-core/test/integration/tests/test_password_server.py b/cosmic-core/test/integration/tests/test_password_server.py index 9fa42dc270..01b4068423 100755 --- a/cosmic-core/test/integration/tests/test_password_server.py +++ b/cosmic-core/test/integration/tests/test_password_server.py @@ -220,7 +220,7 @@ def _test_password_server_logs(self, vm, router): router_state = self.get_router_state(router) if router.isredundantrouter and router_state != "MASTER": - print "Found router in non-MASTER state '" + router.redundantstate + "' so skipping test." + print("Found router in non-MASTER state '" + router.redundantstate + "' so skipping test.") return True # Get the related passwd server logs for our vm diff --git a/cosmic-core/test/integration/tests/test_vm_migration.py b/cosmic-core/test/integration/tests/test_vm_migration.py index 209ebcca23..1d0847f9e5 100644 --- a/cosmic-core/test/integration/tests/test_vm_migration.py +++ b/cosmic-core/test/integration/tests/test_vm_migration.py @@ -109,4 +109,4 @@ def test_02_migrate_back(self): def get_dest_hypervisor(self, hostid=None): if hostid is None: hostid = self.vm.hostid - return filter(lambda x: x.id != hostid, self.hosts) + return list(filter(lambda x: x.id != hostid, self.hosts))