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):
31 def test_handler(self, *args):
32 subprocess.call = mock.Mock(return_value=0)
33 self.assertRaises(SystemExit, NSBperf.sigint_handler)
36 class TestYardstickNSCli(unittest.TestCase):
37 def test___init__(self):
38 yardstick_ns_cli = YardstickNSCli()
39 self.assertIsNotNone(yardstick_ns_cli)
41 def test_generate_final_report(self):
42 yardstick_ns_cli = YardstickNSCli()
43 test_case = "tc_baremetal_rfc2544_ipv4_1flow_1518B.yaml"
44 if os.path.isfile("/tmp/yardstick.out"):
45 os.remove('/tmp/yardstick.out')
46 self.assertIsNone(yardstick_ns_cli.generate_final_report(test_case))
48 def test_generate_kpi_results(self):
49 yardstick_ns_cli = YardstickNSCli()
51 tgen = {"cpu": {"ipc": 0}}
52 self.assertIsNone(yardstick_ns_cli.generate_kpi_results(tkey, tgen))
54 def test_generate_nfvi_results(self):
55 yardstick_ns_cli = YardstickNSCli()
56 nfvi = {"collect_stats": {"cpu": {"ipc": 0, "Hz": 2.6}}}
57 self.assertIsNone(yardstick_ns_cli.generate_nfvi_results(nfvi))
59 def test_handle_list_options(self):
60 yardstick_ns_cli = YardstickNSCli()
61 CLI_PATH = os.path.dirname(os.path.realpath(__file__))
62 repo_dir = CLI_PATH + "/../../../"
63 test_path = os.path.join(repo_dir, "../samples/vnf_samples/nsut/")
64 args = {"list_vnfs": True, "list": False}
65 self.assertRaises(SystemExit, yardstick_ns_cli.handle_list_options,
67 args = {"list_vnfs": False, "list": True}
68 self.assertRaises(SystemExit,
69 yardstick_ns_cli.handle_list_options,
73 yardstick_ns_cli = YardstickNSCli()
74 yardstick_ns_cli.parse_arguments = mock.Mock(return_value=0)
75 yardstick_ns_cli.handle_list_options = mock.Mock(return_value=0)
76 yardstick_ns_cli.terminate_if_less_options = mock.Mock(return_value=0)
77 yardstick_ns_cli.run_test = mock.Mock(return_value=0)
78 self.assertIsNone(yardstick_ns_cli.main())
80 def test_parse_arguments(self):
81 yardstick_ns_cli = YardstickNSCli()
82 self.assertRaises(SystemExit, yardstick_ns_cli.parse_arguments)
84 def test_run_test(self):
86 CLI_PATH = os.path.dirname(os.path.realpath(__file__))
87 YARDSTICK_REPOS_DIR = os.path.join(CLI_PATH + "/../../")
88 test_path = os.path.join(YARDSTICK_REPOS_DIR,
89 "../samples/vnf_samples/nsut/")
90 yardstick_ns_cli = YardstickNSCli()
91 subprocess.check_output = mock.Mock(return_value=0)
93 "test": "tc_baremetal_rfc2544_ipv4_1flow_1518B.yaml"}
94 self.assertEqual(None, yardstick_ns_cli.run_test(args, test_path))
96 args = {"vnf": "vpe1"}
97 self.assertEqual(None, yardstick_ns_cli.run_test(args, test_path))
100 "test": "tc_baremetal_rfc2544_ipv4_1flow_1518B.yaml."}
101 self.assertEqual(None, yardstick_ns_cli.run_test(args, test_path))
104 self.assertEqual(None, yardstick_ns_cli.run_test(args, test_path))
107 def test_terminate_if_less_options(self):
108 yardstick_ns_cli = YardstickNSCli()
109 args = {"vnf": False}
110 self.assertRaises(SystemExit,
111 yardstick_ns_cli.terminate_if_less_options, args)
113 def test_validate_input(self):
114 yardstick_ns_cli = YardstickNSCli()
115 self.assertEqual(1, yardstick_ns_cli.validate_input("", 4))
116 NSBperf.input = lambda _: 'yes'
117 self.assertEqual(1, yardstick_ns_cli.validate_input(5, 4))
118 subprocess.call = mock.Mock(return_value=0)
119 self.assertEqual(0, yardstick_ns_cli.validate_input(2, 4))
120 subprocess.call = mock.Mock(return_value=0)