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 subprocess.call(["touch", "/tmp/yardstick.out"])
44 self.assertIsNone(yardstick_ns_cli.generate_final_report(test_case))
46 def test_generate_kpi_results(self):
47 yardstick_ns_cli = YardstickNSCli()
49 tgen = {"cpu": {"ipc": 0}}
50 self.assertIsNone(yardstick_ns_cli.generate_kpi_results(tkey, tgen))
52 def test_generate_nfvi_results(self):
53 yardstick_ns_cli = YardstickNSCli()
54 nfvi = {"collect_stats": {"cpu": {"ipc": 0, "Hz": 2.6}}}
55 self.assertIsNone(yardstick_ns_cli.generate_nfvi_results(nfvi))
57 def test_handle_list_options(self):
58 yardstick_ns_cli = YardstickNSCli()
59 CLI_PATH = os.path.dirname(os.path.realpath(__file__))
60 repo_dir = CLI_PATH + "/../../"
61 test_path = os.path.join(repo_dir, "../samples/vnf_samples/nsut/")
62 args = {"list_vnfs": True, "list": False}
63 self.assertRaises(SystemExit, yardstick_ns_cli.handle_list_options,
65 args = {"list_vnfs": False, "list": True}
66 self.assertRaises(SystemExit,
67 yardstick_ns_cli.handle_list_options,
71 yardstick_ns_cli = YardstickNSCli()
72 yardstick_ns_cli.parse_arguments = mock.Mock(return_value=0)
73 yardstick_ns_cli.handle_list_options = mock.Mock(return_value=0)
74 yardstick_ns_cli.terminate_if_less_options = mock.Mock(return_value=0)
75 yardstick_ns_cli.run_test = mock.Mock(return_value=0)
76 self.assertIsNone(yardstick_ns_cli.main())
78 def test_parse_arguments(self):
79 yardstick_ns_cli = YardstickNSCli()
80 self.assertRaises(SystemExit, yardstick_ns_cli.parse_arguments)
82 def test_run_test(self):
84 CLI_PATH = os.path.dirname(os.path.realpath(__file__))
85 YARDSTICK_REPOS_DIR = os.path.join(CLI_PATH + "/../../")
86 test_path = os.path.join(YARDSTICK_REPOS_DIR,
87 "../samples/vnf_samples/nsut/")
88 yardstick_ns_cli = YardstickNSCli()
89 subprocess.check_output = mock.Mock(return_value=0)
91 "test": "tc_baremetal_rfc2544_ipv4_1flow_1518B.yaml"}
92 self.assertEqual(None, yardstick_ns_cli.run_test(args, test_path))
94 args = {"vnf": "vpe1"}
95 self.assertEqual(None, yardstick_ns_cli.run_test(args, test_path))
98 "test": "tc_baremetal_rfc2544_ipv4_1flow_1518B.yaml."}
99 self.assertEqual(None, yardstick_ns_cli.run_test(args, test_path))
102 self.assertEqual(None, yardstick_ns_cli.run_test(args, test_path))
105 def test_terminate_if_less_options(self):
106 yardstick_ns_cli = YardstickNSCli()
107 args = {"vnf": False}
108 self.assertRaises(SystemExit,
109 yardstick_ns_cli.terminate_if_less_options, args)
111 def test_validate_input(self):
112 yardstick_ns_cli = YardstickNSCli()
113 self.assertEqual(1, yardstick_ns_cli.validate_input("", 4))
114 NSBperf.input = lambda _: 'yes'
115 self.assertEqual(1, yardstick_ns_cli.validate_input(5, 4))
116 subprocess.call = mock.Mock(return_value=0)
117 self.assertEqual(0, yardstick_ns_cli.validate_input(2, 4))
118 subprocess.call = mock.Mock(return_value=0)