JIRA: BOTTLENECKS-29
[bottlenecks.git] / vstf / vstf / controller / unittest / test_perf.py
1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd 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
11 import unittest
12 import os
13 import logging
14
15 from vstf.controller.unittest import model
16 from vstf.controller.settings.flows_settings import FlowsSettings
17 from vstf.controller.settings.tool_settings import ToolSettings
18 from vstf.controller.settings.perf_settings import PerfSettings
19 from vstf.controller.sw_perf.perf_provider import PerfProvider
20 from vstf.controller.sw_perf.flow_producer import FlowsProducer
21 from vstf.controller.settings.tester_settings import TesterSettings
22 from vstf.controller.env_build.env_build import EnvBuildApi as Builder
23 from vstf.common.log import setup_logging
24 import vstf.controller.sw_perf.performance as pf
25
26 LOG = logging.getLogger(__name__)
27
28
29 class TestPerf(model.Test):
30     
31     def setUp(self):
32         LOG.info("start performance unit test.")
33         super(TestPerf, self).setUp()
34         self.dir = os.path.dirname(__file__)
35         self.perf_path = os.path.join(self.dir, '../../../etc/vstf/perf')
36         self.base_path = os.path.join(self.dir, '../../../etc/vstf/env')
37
38     def teardown(self):
39         LOG.info("stop performance unit test.")
40
41     @unittest.skip('for now')
42     def test_batch_perf(self):
43
44         LOG.info(self.perf_path)
45         LOG.info(self.base_path)
46         perf_settings = PerfSettings(path=self.perf_path)
47         flows_settings = FlowsSettings(path=self.perf_path)
48         tool_settings = ToolSettings(path=self.base_path)
49         tester_settings = TesterSettings(path=self.base_path)
50         flow_producer = FlowsProducer(self.conn, flows_settings)
51         provider = PerfProvider(flows_settings.settings, tool_settings.settings, tester_settings.settings)
52         perf = pf.Performance(self.conn, provider)
53         tests = perf_settings.settings
54         for scenario, cases in tests.items():
55             if not cases:
56                 continue
57
58             config_file = os.path.join(self.base_path, scenario + '.json')
59
60             LOG.info(config_file)
61
62             env = Builder(self.conn, config_file)
63             env.build()
64
65             for case in cases:
66                 casetag = case['case']
67                 tool = case['tool']
68                 protocol = case['protocol']
69                 profile = case['profile']
70                 ttype = case['type']
71                 sizes = case['sizes']
72
73                 flow_producer.create(scenario, casetag)
74                 result = perf.run(tool, protocol, ttype, sizes)
75                 self.assertEqual(True, isinstance(result, dict))
76                 LOG.info(result)
77
78     @unittest.skip('for now')
79     def test_perf_settings(self):
80         perf_settings = PerfSettings()
81         self.assertEqual(True, perf_settings.input())
82
83     def test_tool_settings(self):
84         tool_settings = ToolSettings()
85         value = {
86             "time": 20,
87             "threads": 1
88         }
89         tool_settings.set_pktgen(value)
90         tool_settings.set_netperf(value)
91         tool_settings.set_iperf(value)
92         tool_settings.set_qperf(value)
93         LOG.info(tool_settings.settings)
94
95     def test_flow_settings(self):
96         tests = {
97             "Tn": ["Tn-1", "Tn-2", "Tn-3", "Tn-4"],
98             "Tnv": ["Tnv-1", "Tnv-2", "Tnv-3", "Tnv-4"],
99             "Ti": ["Ti-1", "Ti-2", "Ti-3", "Ti-4", "Ti-5", "Ti-6"],
100             "Tu": ["Tu-1", "Tu-2", "Tu-3", "Tu-4", "Tu-5", "Tu-6"]
101         }
102         flows_settings = FlowsSettings(path=self.perf_path)
103         flow_producer = FlowsProducer(self.conn, flows_settings)
104
105         for scenario, cases in tests.items():
106             if not cases:
107                 continue
108
109             config_file = os.path.join(self.base_path, scenario + '.json')
110
111             LOG.info(config_file)
112
113             env = Builder(self.conn, config_file)
114             env.build()
115
116             for case in cases:
117                 LOG.info(case)
118                 flow_producer.create(scenario, case)
119                 LOG.info(flows_settings.settings)
120
121
122 if __name__ == "__main__":
123     setup_logging(level=logging.INFO, log_file="/var/log/vstf/vstf-unit-test.log", clevel=logging.INFO)
124     unittest.main()