Fix Rally test case error

Transform plain function into scenario plugin is deprecated.
Now scenarios must be represented by classes, this patch
change update all scenarios from functions to classes.

Change-Id: I60f6fd175d67b72cd93bee5f4a70ee29cc062a70
Closes-Bug: #1710828
This commit is contained in:
Liping Mao (limao) 2017-07-26 23:11:38 +08:00
parent 5cc622f42a
commit f0abb5a579
2 changed files with 23 additions and 20 deletions

View File

@ -13,19 +13,16 @@
# License for the specific language governing permissions and limitations
# under the License.
import docker
import utils
from rally.plugins.openstack import scenario
class Kuryr(utils.KuryrScenario):
"""Benchmark scenarios for Kuryr."""
@scenario.configure(name="Kuryr.list_networks")
class KuryrListNetworks(utils.KuryrScenario):
def __init__(self, context=None, admin_clients=None, clients=None):
super(Kuryr, self).__init__(context, admin_clients, clients)
@scenario.configure()
def list_networks(self, network_list_args=None):
def run(self, network_list_args=None):
"""List the networks.
Measure the "docker network ls" command performance under kuryr.
@ -38,10 +35,14 @@ class Kuryr(utils.KuryrScenario):
:param network_list_args: dict: names, ids
"""
self.docker_client = docker.APIClient(base_url='tcp://0.0.0.0:2375')
self._list_networks(network_list_args or {})
@scenario.configure()
def create_and_delete_networks_with_kuryr(self, network_create_args=None):
@scenario.configure(name="Kuryr.create_and_delete_networks_with_kuryr")
class KuryrCreateDeleteNetworksWithKuryr(utils.KuryrScenario):
def run(self, network_create_args=None):
"""Create and delete a network with kuryr.
Measure the "docker network create" and "docker network rm" command
@ -49,13 +50,16 @@ class Kuryr(utils.KuryrScenario):
:param network_create_args: dict as options to create the network
"""
self.docker_client = docker.APIClient(base_url='tcp://0.0.0.0:2375')
network = self._create_network(is_kuryr=True,
network_create_args=network_create_args or {})
self._delete_network(network)
@scenario.configure()
def create_and_delete_networks_without_kuryr(self,
network_create_args=None):
@scenario.configure(name="Kuryr.create_and_delete_networks_without_kuryr")
class KuryrCreateDeleteNetworksWithoutKuryr(utils.KuryrScenario):
def run(self, network_create_args=None):
"""Create and delete a network without kuryr.
Measure the "docker network create" and "docker network rm" command
@ -63,17 +67,22 @@ class Kuryr(utils.KuryrScenario):
:param network_create_args: dict as options to create the network
"""
self.docker_client = docker.APIClient(base_url='tcp://0.0.0.0:2375')
network = self._create_network(is_kuryr=False,
network_create_args=network_create_args or {})
self._delete_network(network)
@scenario.configure()
def start_and_stop_containers(self, container_create_args=None):
@scenario.configure(name="Kuryr.start_and_stop_containers")
class KuryrStartStopContainers(utils.KuryrScenario):
def run(self, container_create_args=None):
"""Start and stop container on docker network.
Measure the "docker run" , "docker stop", "docker rm"
command performance.
"""
self.docker_client = docker.APIClient(base_url='tcp://0.0.0.0:2375')
container_id = self._start_container(container_create_args or {})
self._stop_container(container_id)
# TODO(yedongcan) We will hit the Docker bug:

View File

@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import docker
from rally.common import logging
from rally.plugins.openstack import scenario
from rally.task import atomic
@ -25,10 +23,6 @@ LOG = logging.getLogger(__name__)
class KuryrScenario(scenario.OpenStackScenario):
"""Base class for Kuryr scenarios with basic atomic actions."""
def __init__(self, context=None, admin_clients=None, clients=None):
super(KuryrScenario, self).__init__(context, admin_clients, clients)
self.docker_client = docker.APIClient(base_url='tcp://0.0.0.0:2375')
@atomic.action_timer("kuryr.list_networks")
def _list_networks(self, network_list_args):
"""Return user networks list.