Add support for Python 3
[yardstick.git] / yardstick / benchmark / scenarios / networking / vtc_throughput.py
1 #############################################################################
2 # Copyright (c) 2015 Ericsson AB and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 from __future__ import absolute_import
11 import logging
12 import os
13
14 from yardstick.benchmark.scenarios import base
15 from experimental_framework import api as api
16
17 LOG = logging.getLogger(__name__)
18
19
20 class VtcThroughput(base.Scenario):
21     """Execute Instantiation Validation TC on the vTC
22     """
23     __scenario_type__ = "vtc_throughput"
24
25     def __init__(self, scenario_cfg, context_cfg):
26         self.scenario_cfg = scenario_cfg
27         self.context_cfg = context_cfg
28         self.options = None
29         self.setup_done = False
30
31     def setup(self):
32         '''scenario setup'''
33
34         self.options = self.scenario_cfg['options']
35         self.setup_done = True
36
37     def run(self, result):
38         """execute test"""
39
40         if not self.setup_done:
41             self.setup()
42
43         heat_template = 'vTC.yaml'
44         iterations = 1
45
46         openstack_credentials = {
47             'ip_controller': '0.0.0.0',
48             'heat_url': '***',
49             'auth_uri': os.environ.get('OS_AUTH_URL'),
50             'user': os.environ.get('OS_USERNAME'),
51             'password': os.environ.get('OS_PASSWORD'),
52             'project': os.environ.get('OS_TENANT_NAME')
53         }
54         heat_template_parameters = {
55             'default_net': self.options['default_net_name'],
56             'default_subnet': self.options['default_subnet_name'],
57             'source_net': self.options['vlan_net_1_name'],
58             'source_subnet': self.options['vlan_subnet_1_name'],
59             'destination_net': self.options['vlan_net_2_name'],
60             'destination_subnet': self.options['vlan_subnet_2_name']
61         }
62         deployment_configuration = {
63             'vnic_type': [self.options['vnic_type']],
64             'vtc_flavor': [self.options['vtc_flavor']]
65         }
66
67         test_case = dict()
68         test_case['name'] = 'rfc2544_throughput_benchmark.' \
69                             'RFC2544ThroughputBenchmark'
70         test_case['params'] = dict()
71         test_case['params']['packet_size'] = str(self.options['packet_size'])
72         test_case['params']['vlan_sender'] = str(self.options['vlan_sender'])
73         test_case['params']['vlan_receiver'] = \
74             str(self.options['vlan_receiver'])
75
76         res = dict()
77         try:
78             res = api.FrameworkApi.execute_framework(
79                 [test_case],
80                 iterations,
81                 heat_template,
82                 heat_template_parameters,
83                 deployment_configuration,
84                 openstack_credentials)
85         except Exception:
86             LOG.exception("Exception")
87         LOG.info('Got output: %s', res)
88         result.update(res)