a48353a4f012b84c3cc8b4ad7420059fffe95b6c
[yardstick.git] / yardstick / tests / unit / benchmark / scenarios / lib / test_check_connectivity.py
1 ##############################################################################
2 # Copyright (c) 2017 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 # Unittest for yardstick.benchmark.scenarios.lib.check_connectivity.CheckConnectivity
11
12 from __future__ import absolute_import
13
14 import mock
15 import unittest
16
17 from yardstick.benchmark.scenarios.lib import check_connectivity
18
19
20 class CheckConnectivityTestCase(unittest.TestCase):
21
22     def setUp(self):
23         self.ctx = {
24             'host': {
25                 'ip': '172.16.0.137',
26                 'user': 'root',
27                 'key_filename': 'mykey.key',
28                 'ssh_port': '22'
29             },
30             'target': {
31                 'ipaddr': '172.16.0.138'
32             }
33         }
34
35     @mock.patch('yardstick.benchmark.scenarios.lib.check_connectivity.ssh')
36     def test_check_connectivity(self, mock_ssh):
37
38         args = {
39             'options': {'src_ip_addr': '192.168.23.2',
40                         'dest_ip_addr': '192.168.23.10',
41                         'ssh_user': 'root',
42                         'ssh_passwd': 'root',
43                         'ssh_port': '22',
44                         'ssh_timeout': 600,
45                         'ping_parameter': "-s 2048"
46                         },
47             'sla': {'status': 'True',
48                     'action': 'assert'}
49         }
50
51         # TODO(elfoley): Properly check the outputs
52         result = {}  # pylint: disable=unused-variable
53
54         obj = check_connectivity.CheckConnectivity(args, {})
55         obj.setup()
56         mock_ssh.SSH.execute.return_value = (0, '100', '')
57
58     @mock.patch('yardstick.benchmark.scenarios.lib.check_connectivity.ssh')
59     def test_check_connectivity_key(self, mock_ssh):
60
61         args = {
62             'options': {'ssh_user': 'root',
63                         'ssh_key': '/root/.ssh/id_rsa',
64                         'ssh_port': '22',
65                         'ssh_timeout': 600,
66                         'ping_parameter': "-s 2048"
67                         },
68             'sla': {'status': 'True',
69                     'action': 'assert'}
70         }
71
72         # TODO(elfoley): Properly check the outputs
73         result = {}  # pylint: disable=unused-variable
74
75         obj = check_connectivity.CheckConnectivity(args, self.ctx)
76         obj.setup()
77
78         mock_ssh.SSH.execute.return_value = (0, '100', '')