diff options
author | 2017-08-24 01:04:20 +0000 | |
---|---|---|
committer | 2017-08-24 01:04:20 +0000 | |
commit | 5ed1f7ebbe7a9ae6138f56051a15e7774f6e71b9 (patch) | |
tree | 3ca6aed6937399682d6f34092097bc87710497ee /yardstick | |
parent | faf7ef045dbb08d00e0a19374c6075d85ff5ad60 (diff) | |
parent | b8f0aedae524539e9d0d069c07662e288046bc6f (diff) |
Merge "Add common openstack opertation scenarios: volume & floating ip"
Diffstat (limited to 'yardstick')
-rw-r--r-- | yardstick/benchmark/scenarios/lib/delete_floating_ip.py | 54 | ||||
-rw-r--r-- | yardstick/benchmark/scenarios/lib/delete_keypair.py | 56 | ||||
-rw-r--r-- | yardstick/benchmark/scenarios/lib/delete_volume.py | 55 | ||||
-rw-r--r-- | yardstick/benchmark/scenarios/lib/detach_volume.py | 54 | ||||
-rw-r--r-- | yardstick/common/openstack_utils.py | 49 |
5 files changed, 268 insertions, 0 deletions
diff --git a/yardstick/benchmark/scenarios/lib/delete_floating_ip.py b/yardstick/benchmark/scenarios/lib/delete_floating_ip.py new file mode 100644 index 000000000..4314952fb --- /dev/null +++ b/yardstick/benchmark/scenarios/lib/delete_floating_ip.py @@ -0,0 +1,54 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +from __future__ import print_function +from __future__ import absolute_import + +import logging + +from yardstick.benchmark.scenarios import base +import yardstick.common.openstack_utils as op_utils + +LOG = logging.getLogger(__name__) + + +class DeleteFloatingIp(base.Scenario): + """Delete an OpenStack floating ip """ + + __scenario_type__ = "DeleteFloatingIp" + + def __init__(self, scenario_cfg, context_cfg): + self.scenario_cfg = scenario_cfg + self.context_cfg = context_cfg + self.options = self.scenario_cfg['options'] + + self.floating_ip_id = self.options.get("floating_ip_id", None) + + self.nova_client = op_utils.get_nova_client() + self.setup_done = False + + def setup(self): + """scenario setup""" + + self.setup_done = True + + def run(self, result): + """execute the test""" + + if not self.setup_done: + self.setup() + + status = op_utils.delete_floating_ip(nova_client=self.nova_client, + floatingip_id=self.floating_ip_id) + if status: + result.update({"delete_floating_ip": 1}) + LOG.info("Delete floating ip successful!") + else: + result.update({"delete_floating_ip": 0}) + LOG.error("Delete floating ip failed!") diff --git a/yardstick/benchmark/scenarios/lib/delete_keypair.py b/yardstick/benchmark/scenarios/lib/delete_keypair.py new file mode 100644 index 000000000..135139959 --- /dev/null +++ b/yardstick/benchmark/scenarios/lib/delete_keypair.py @@ -0,0 +1,56 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +from __future__ import print_function +from __future__ import absolute_import + +import logging + +from yardstick.benchmark.scenarios import base +import yardstick.common.openstack_utils as op_utils + +LOG = logging.getLogger(__name__) + + +class DeleteKeypair(base.Scenario): + """Delete an OpenStack keypair""" + + __scenario_type__ = "DeleteKeypair" + + def __init__(self, scenario_cfg, context_cfg): + self.scenario_cfg = scenario_cfg + self.context_cfg = context_cfg + self.options = self.scenario_cfg['options'] + + self.key_name = self.options.get("key_name", "yardstick_key") + + self.nova_client = op_utils.get_nova_client() + + self.setup_done = False + + def setup(self): + """scenario setup""" + + self.setup_done = True + + def run(self, result): + """execute the test""" + + if not self.setup_done: + self.setup() + + status = op_utils.delete_keypair(self.nova_client, + self.key_name) + + if status: + result.update({"delete_keypair": 1}) + LOG.info("Delete keypair successful!") + else: + result.update({"delete_keypair": 0}) + LOG.info("Delete keypair failed!") diff --git a/yardstick/benchmark/scenarios/lib/delete_volume.py b/yardstick/benchmark/scenarios/lib/delete_volume.py new file mode 100644 index 000000000..ea2b85812 --- /dev/null +++ b/yardstick/benchmark/scenarios/lib/delete_volume.py @@ -0,0 +1,55 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +from __future__ import print_function +from __future__ import absolute_import + +import logging + +from yardstick.benchmark.scenarios import base +import yardstick.common.openstack_utils as op_utils + +LOG = logging.getLogger(__name__) + + +class DeleteVolume(base.Scenario): + """Delete an OpenStack volume""" + + __scenario_type__ = "DeleteVolume" + + def __init__(self, scenario_cfg, context_cfg): + self.scenario_cfg = scenario_cfg + self.context_cfg = context_cfg + self.options = self.scenario_cfg['options'] + + self.volume_id = self.options.get("volume_id", None) + + self.cinder_client = op_utils.get_cinder_client() + + self.setup_done = False + + def setup(self): + """scenario setup""" + + self.setup_done = True + + def run(self, result): + """execute the test""" + + if not self.setup_done: + self.setup() + + status = op_utils.delete_volume(self.cinder_client, self.volume_id) + + if status: + result.update({"delete_volume": 1}) + LOG.info("Delete volume successful!") + else: + result.update({"delete_volume": 0}) + LOG.info("Delete volume failed!") diff --git a/yardstick/benchmark/scenarios/lib/detach_volume.py b/yardstick/benchmark/scenarios/lib/detach_volume.py new file mode 100644 index 000000000..0b02a3a81 --- /dev/null +++ b/yardstick/benchmark/scenarios/lib/detach_volume.py @@ -0,0 +1,54 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +from __future__ import print_function +from __future__ import absolute_import + +import logging + +from yardstick.benchmark.scenarios import base +import yardstick.common.openstack_utils as op_utils + +LOG = logging.getLogger(__name__) + + +class DetachVolume(base.Scenario): + """Detach a volume from an instance""" + + __scenario_type__ = "DetachVolume" + + def __init__(self, scenario_cfg, context_cfg): + self.scenario_cfg = scenario_cfg + self.context_cfg = context_cfg + self.options = self.scenario_cfg['options'] + + self.server_id = self.options.get("server_id", "TestServer") + self.volume_id = self.options.get("volume_id", None) + + self.setup_done = False + + def setup(self): + """scenario setup""" + + self.setup_done = True + + def run(self, result): + """execute the test""" + + if not self.setup_done: + self.setup() + + status = op_utils.detach_volume(self.server_id, self.volume_id) + + if status: + result.update({"detach_volume": 1}) + LOG.info("Detach volume from server successful!") + else: + result.update({"detach_volume": 0}) + LOG.info("Detach volume from server failed!") diff --git a/yardstick/common/openstack_utils.py b/yardstick/common/openstack_utils.py index 76acc9508..c862a6ba2 100644 --- a/yardstick/common/openstack_utils.py +++ b/yardstick/common/openstack_utils.py @@ -11,6 +11,7 @@ from __future__ import absolute_import import os import time +import sys import logging from keystoneauth1 import loading @@ -423,6 +424,15 @@ def delete_flavor(flavor_id): # pragma: no cover return True +def delete_keypair(nova_client, key): # pragma: no cover + try: + nova_client.keypairs.delete(key=key) + return True + except Exception: + log.exception("Error [delete_keypair(nova_client)]") + return False + + # ********************************************* # NEUTRON # ********************************************* @@ -479,6 +489,15 @@ def create_floating_ip(neutron_client, extnet_id): # pragma: no cover return {'fip_addr': fip_addr, 'fip_id': fip_id} +def delete_floating_ip(nova_client, floatingip_id): # pragma: no cover + try: + nova_client.floating_ips.delete(floatingip_id) + return True + except Exception: + log.error("Error [delete_floating_ip(nova_client, '%s')]" % floatingip_id) + return False + + def get_security_groups(neutron_client): # pragma: no cover try: security_groups = neutron_client.list_security_groups()[ @@ -667,3 +686,33 @@ def create_volume(cinder_client, volume_name, volume_size, log.exception("Error [create_volume(cinder_client, %s)]", (volume_name, volume_size)) return None + + +def delete_volume(cinder_client, volume_id, forced=False): # pragma: no cover + try: + if forced: + try: + cinder_client.volumes.detach(volume_id) + except: + log.error(sys.exc_info()[0]) + cinder_client.volumes.force_delete(volume_id) + else: + while True: + volume = get_cinder_client().volumes.get(volume_id) + if volume.status.lower() == 'available': + break + cinder_client.volumes.delete(volume_id) + return True + except Exception: + log.exception("Error [delete_volume(cinder_client, '%s')]" % volume_id) + return False + + +def detach_volume(server_id, volume_id): # pragma: no cover + try: + get_nova_client().volumes.delete_server_volume(server_id, volume_id) + return True + except Exception: + log.exception("Error [detach_server_volume(nova_client, '%s', '%s')]", + server_id, volume_id) + return False |