Merge "Change PTL informatin in INFO"
[bottlenecks.git] / testsuites / vstf / vstf_scripts / 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(
52             flows_settings.settings,
53             tool_settings.settings,
54             tester_settings.settings)
55         perf = pf.Performance(self.conn, provider)
56         tests = perf_settings.settings
57         for scenario, cases in tests.items():
58             if not cases:
59                 continue
60
61             config_file = os.path.join(self.base_path, scenario + '.json')
62
63             LOG.info(config_file)
64
65             env = Builder(self.conn, config_file)
66             env.build()
67
68             for case in cases:
69                 casetag = case['case']
70                 tool = case['tool']
71                 protocol = case['protocol']
72                 profile = case['profile']
73                 ttype = case['type']
74                 sizes = case['sizes']
75
76                 flow_producer.create(scenario, casetag)
77                 result = perf.run(tool, protocol, ttype, sizes)
78                 self.assertEqual(True, isinstance(result, dict))
79                 LOG.info(result)
80
81     @unittest.skip('for now')
82     def test_perf_settings(self):
83         perf_settings = PerfSettings()
84         self.assertEqual(True, perf_settings.input())
85
86     def test_tool_settings(self):
87         tool_settings = ToolSettings()
88         value = {
89             "time": 20,
90             "threads": 1
91         }
92         tool_settings.set_pktgen(value)
93         tool_settings.set_netperf(value)
94         tool_settings.set_iperf(value)
95         tool_settings.set_qperf(value)
96         LOG.info(tool_settings.settings)
97
98     def test_flow_settings(self):
99         tests = {
100             "Tn": ["Tn-1", "Tn-2", "Tn-3", "Tn-4"],
101             "Tnv": ["Tnv-1", "Tnv-2", "Tnv-3", "Tnv-4"],
102             "Ti": ["Ti-1", "Ti-2", "Ti-3", "Ti-4", "Ti-5", "Ti-6"],
103             "Tu": ["Tu-1", "Tu-2", "Tu-3", "Tu-4", "Tu-5", "Tu-6"]
104         }
105         flows_settings = FlowsSettings(path=self.perf_path)
106         flow_producer = FlowsProducer(self.conn, flows_settings)
107
108         for scenario, cases in tests.items():
109             if not cases:
110                 continue
111
112             config_file = os.path.join(self.base_path, scenario + '.json')
113
114             LOG.info(config_file)
115
116             env = Builder(self.conn, config_file)
117             env.build()
118
119             for case in cases:
120                 LOG.info(case)
121                 flow_producer.create(scenario, case)
122                 LOG.info(flows_settings.settings)
123
124
125 if __name__ == "__main__":
126     setup_logging(
127         level=logging.INFO,
128         log_file="/var/log/vstf/vstf-unit-test.log",
129         clevel=logging.INFO)
130     unittest.main()