diff options
-rw-r--r-- | nfvbench/chain_runner.py | 4 | ||||
-rw-r--r-- | nfvbench/cleanup.py | 34 | ||||
-rw-r--r-- | nfvbench/compute.py | 12 | ||||
-rw-r--r-- | nfvbench/utils.py | 38 |
4 files changed, 54 insertions, 34 deletions
diff --git a/nfvbench/chain_runner.py b/nfvbench/chain_runner.py index 7b1153f..7bb3bbc 100644 --- a/nfvbench/chain_runner.py +++ b/nfvbench/chain_runner.py @@ -210,8 +210,8 @@ class ChainRunner(object): LOG.info('Clean up skipped.') try: self.traffic_client.close() - except Exception: - LOG.exception() + except Exception as exc: + LOG.exception(exc) if self.stats_manager: self.stats_manager.close() except Exception: diff --git a/nfvbench/cleanup.py b/nfvbench/cleanup.py index 6cb2713..23cdf56 100644 --- a/nfvbench/cleanup.py +++ b/nfvbench/cleanup.py @@ -15,7 +15,6 @@ # import sys -import time from neutronclient.neutron import client as nclient from novaclient.client import Client @@ -24,6 +23,7 @@ from tabulate import tabulate from . import credentials from .log import LOG +from . import utils class ComputeCleaner(object): @@ -36,13 +36,6 @@ class ComputeCleaner(object): self.servers = [server for server in all_servers if server.name.startswith(instance_prefix)] - def instance_exists(self, server): - try: - self.nova_client.servers.get(server.id) - except NotFound: - return False - return True - def get_resource_list(self): return [["Instance", server.name, server.id] for server in self.servers] @@ -59,29 +52,8 @@ class ComputeCleaner(object): if self.clean_needed(clean_options): if self.servers: for server in self.servers: - try: - LOG.info('Deleting instance %s...', server.name) - self.nova_client.servers.delete(server.id) - except Exception: - LOG.exception("Instance %s deletion failed", server.name) - LOG.info(' Waiting for %d instances to be fully deleted...', len(self.servers)) - retry_count = 15 + len(self.servers) * 5 - while True: - retry_count -= 1 - self.servers = [server for server in self.servers if - self.instance_exists(server)] - if not self.servers: - break - - if retry_count: - LOG.info(' %d yet to be deleted by Nova, retries left=%d...', - len(self.servers), retry_count) - time.sleep(2) - else: - LOG.warning( - ' instance deletion verification time-out: %d still not deleted', - len(self.servers)) - break + utils.delete_server(self.nova_client, server) + utils.waiting_servers_deletion(self.nova_client, self.servers) class NetworkCleaner(object): diff --git a/nfvbench/compute.py b/nfvbench/compute.py index f6f179d..883dc28 100644 --- a/nfvbench/compute.py +++ b/nfvbench/compute.py @@ -23,8 +23,10 @@ except ImportError: from glanceclient.v1.apiclient.exceptions import NotFound as GlanceImageNotFound import keystoneauth1 import novaclient +from novaclient.exceptions import NotFound from .log import LOG +from . import utils class Compute(object): @@ -147,9 +149,17 @@ class Compute(object): servers_list = self.novaclient.servers.list() return servers_list + def instance_exists(self, server): + try: + self.novaclient.servers.get(server) + except NotFound: + return False + return True + def delete_server(self, server): """Delete a server from its object reference.""" - self.novaclient.servers.delete(server) + utils.delete_server(self.novaclient, server) + utils.waiting_servers_deletion(self.novaclient, [server]) def find_flavor(self, flavor_type): """Find a flavor by name.""" diff --git a/nfvbench/utils.py b/nfvbench/utils.py index 6da14ed..80a0817 100644 --- a/nfvbench/utils.py +++ b/nfvbench/utils.py @@ -13,6 +13,7 @@ # under the License. import glob +import time from math import gcd from math import isnan import os @@ -26,6 +27,7 @@ from functools import wraps import json from .log import LOG from nfvbench.traffic_gen.traffic_utils import multiplier_map +from novaclient.exceptions import NotFound class TimeoutError(Exception): pass @@ -251,3 +253,39 @@ def find_max_size(max_size, tuples, flow): if flow % i == 0: return int(i) return 1 + + +def delete_server(nova_client, server): + try: + LOG.info('Deleting instance %s...', server.name) + nova_client.servers.delete(server.id) + except Exception: + LOG.exception("Instance %s deletion failed", server.name) + + +def instance_exists(nova_client, server): + try: + nova_client.servers.get(server.id) + except NotFound: + return False + return True + + +def waiting_servers_deletion(nova_client, servers): + LOG.info(' Waiting for %d instances to be fully deleted...', len(servers)) + retry_count = 15 + len(servers) * 5 + while True: + retry_count -= 1 + servers = [server for server in servers if instance_exists(nova_client, server)] + if not servers: + break + + if retry_count: + LOG.info(' %d yet to be deleted by Nova, retries left=%d...', + len(servers), retry_count) + time.sleep(2) + else: + LOG.warning( + ' instance deletion verification time-out: %d still not deleted', + len(servers)) + break |