3 # Copyright (c) 2016-2017 Intel Corporation
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 from __future__ import absolute_import
24 from yardstick.cmd.NSBperf import YardstickNSCli
25 from yardstick.cmd import NSBperf
28 @mock.patch('six.moves.input', return_value='0')
29 class TestHandler(unittest.TestCase):
30 def test_handler(self, test):
31 subprocess.call = mock.Mock(return_value=0)
32 self.assertRaises(SystemExit, NSBperf.handler)
35 class TestYardstickNSCli(unittest.TestCase):
36 def test___init__(self):
37 yardstick_ns_cli = YardstickNSCli()
38 self.assertIsNotNone(yardstick_ns_cli)
40 def test_generate_final_report(self):
41 yardstick_ns_cli = YardstickNSCli()
42 test_case = "tc_baremetal_rfc2544_ipv4_1flow_1518B.yaml"
43 if os.path.isfile("/tmp/yardstick.out"):
44 os.remove('/tmp/yardstick.out')
45 self.assertIsNone(yardstick_ns_cli.generate_final_report(test_case))
47 def test_generate_kpi_results(self):
48 yardstick_ns_cli = YardstickNSCli()
50 tgen = {"cpu": {"ipc": 0}}
51 self.assertIsNone(yardstick_ns_cli.generate_kpi_results(tkey, tgen))
53 def test_generate_nfvi_results(self):
54 yardstick_ns_cli = YardstickNSCli()
55 nfvi = {"collect_stats": {"cpu": {"ipc": 0, "Hz": 2.6}}}
56 self.assertIsNone(yardstick_ns_cli.generate_nfvi_results(nfvi))
58 def test_handle_list_options(self):
59 yardstick_ns_cli = YardstickNSCli()
60 CLI_PATH = os.path.dirname(os.path.realpath(__file__))
61 repo_dir = CLI_PATH + "/../../"
62 test_path = os.path.join(repo_dir, "../samples/vnf_samples/nsut/")
63 args = {"list_vnfs": True, "list": False}
64 self.assertRaises(SystemExit, yardstick_ns_cli.handle_list_options,
66 args = {"list_vnfs": False, "list": True}
67 self.assertRaises(SystemExit,
68 yardstick_ns_cli.handle_list_options,
72 yardstick_ns_cli = YardstickNSCli()
73 yardstick_ns_cli.parse_arguments = mock.Mock(return_value=0)
74 yardstick_ns_cli.handle_list_options = mock.Mock(return_value=0)
75 yardstick_ns_cli.terminate_if_less_options = mock.Mock(return_value=0)
76 yardstick_ns_cli.run_test = mock.Mock(return_value=0)
77 self.assertIsNone(yardstick_ns_cli.main())
79 def test_parse_arguments(self):
80 yardstick_ns_cli = YardstickNSCli()
81 self.assertRaises(SystemExit, yardstick_ns_cli.parse_arguments)
83 def test_run_test(self):
85 CLI_PATH = os.path.dirname(os.path.realpath(__file__))
86 YARDSTICK_REPOS_DIR = os.path.join(CLI_PATH + "/../../")
87 test_path = os.path.join(YARDSTICK_REPOS_DIR,
88 "../samples/vnf_samples/nsut/")
89 yardstick_ns_cli = YardstickNSCli()
90 subprocess.check_output = mock.Mock(return_value=0)
92 "test": "tc_baremetal_rfc2544_ipv4_1flow_1518B.yaml"}
93 self.assertEqual(None, yardstick_ns_cli.run_test(args, test_path))
95 args = {"vnf": "vpe1"}
96 self.assertEqual(None, yardstick_ns_cli.run_test(args, test_path))
99 "test": "tc_baremetal_rfc2544_ipv4_1flow_1518B.yaml."}
100 self.assertEqual(None, yardstick_ns_cli.run_test(args, test_path))
103 self.assertEqual(None, yardstick_ns_cli.run_test(args, test_path))
106 def test_terminate_if_less_options(self):
107 yardstick_ns_cli = YardstickNSCli()
108 args = {"vnf": False}
109 self.assertRaises(SystemExit,
110 yardstick_ns_cli.terminate_if_less_options, args)
112 def test_validate_input(self):
113 yardstick_ns_cli = YardstickNSCli()
114 self.assertEqual(1, yardstick_ns_cli.validate_input("", 4))
115 NSBperf.input = lambda _: 'yes'
116 self.assertEqual(1, yardstick_ns_cli.validate_input(5, 4))
117 subprocess.call = mock.Mock(return_value=0)
118 self.assertEqual(0, yardstick_ns_cli.validate_input(2, 4))
119 subprocess.call = mock.Mock(return_value=0)