Browse Source

Add a unit test for lagopus_lib

This adds a unit test for networking_lagopus.agent.lagopus_lib
and also fixes tox.ini.

Change-Id: I6d9c86836ea82b5a5d14ec70813e43705b904e26
Hirofumi Ichihara 1 year ago
parent
commit
3742a770c7

+ 1
- 1
networking_lagopus/agent/lagopus_lib.py View File

@@ -108,7 +108,7 @@ class LagopusCommand(object):
108 108
 
109 109
     @log_helpers.log_method_call
110 110
     def bridge_add_port(self, bridge_name, port_name, ofport):
111
-        cmd = ("bridge %s config -port %s %s\n" %
111
+        cmd = ("bridge %s config -port %s %d\n" %
112 112
                (bridge_name, port_name, ofport))
113 113
         self._lagosh(cmd)
114 114
 

+ 132
- 0
networking_lagopus/tests/unit/agent/test_lagopus_lib.py View File

@@ -0,0 +1,132 @@
1
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
2
+# not use this file except in compliance with the License. You may obtain
3
+# a copy of the License at
4
+#
5
+#      http://www.apache.org/licenses/LICENSE-2.0
6
+#
7
+# Unless required by applicable law or agreed to in writing, software
8
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10
+# License for the specific language governing permissions and limitations
11
+# under the License.
12
+
13
+import mock
14
+
15
+from neutron.tests import base
16
+
17
+from networking_lagopus.agent import lagopus_lib
18
+
19
+
20
+class TestLagopusLib(base.BaseTestCase):
21
+
22
+    def setUp(self):
23
+        super(TestLagopusLib, self).setUp()
24
+        self.lagosh = mock.patch.object(lagopus_lib.LagopusCommand, "_lagosh",
25
+                                        return_value=None).start()
26
+        self.lagopus_client = lagopus_lib.LagopusCommand()
27
+
28
+    def test_show_interfaces(self):
29
+        expected_cmd = "interface\n"
30
+        self.lagopus_client.show_interfaces()
31
+        self.lagosh.assert_called_with(expected_cmd)
32
+
33
+    def test_show_ports(self):
34
+        expected_cmd = "port\n"
35
+        self.lagopus_client.show_ports()
36
+        self.lagosh.assert_called_with(expected_cmd)
37
+
38
+    def test_show_bridges(self):
39
+        expected_cmd = "bridge\n"
40
+        self.lagopus_client.show_bridges()
41
+        self.lagosh.assert_called_with(expected_cmd)
42
+
43
+    def test_show_channels(self):
44
+        expected_cmd = "channel\n"
45
+        self.lagopus_client.show_channels()
46
+        self.lagosh.assert_called_with(expected_cmd)
47
+
48
+    def test_create_controller(self):
49
+        name = "test-controller"
50
+        channel = "test-channel"
51
+        expected_cmd = ("controller %s create -channel %s -role equal "
52
+                        "-connection-type main\n") % (name, channel)
53
+        self.lagopus_client.create_controller(name, channel)
54
+        self.lagosh.assert_called_with(expected_cmd)
55
+
56
+    def test_create_bridge(self):
57
+        name = "test-bridge"
58
+        controller = "test-controller"
59
+        dpid = 1
60
+        expected_cmd_bridge_create = ("bridge %s create -controller %s "
61
+                                      "-dpid %d -l2-bridge True "
62
+                                      "-mactable-ageing-time 300 "
63
+                                      "-mactable-max-entries "
64
+                                      "8192\n") % (name, controller, dpid)
65
+        expected_cmd_bridge_enable = "bridge %s enable\n" % name
66
+        self.lagopus_client.create_bridge(name, controller, dpid)
67
+        expected_calls = [mock.call(expected_cmd_bridge_create),
68
+                          mock.call(expected_cmd_bridge_enable)]
69
+        self.lagosh.assert_has_calls(expected_calls)
70
+
71
+    def test_create_vhost_interface(self):
72
+        name = "test-interface"
73
+        device = "test-device"
74
+        expected_cmd = ("interface %s create -type ethernet-dpdk-phy "
75
+                        "-device %s\n") % (name, device)
76
+        self.lagopus_client.create_vhost_interface(name, device)
77
+        self.lagosh.assert_called_with(expected_cmd)
78
+
79
+    def test_create_pipe_interface(self):
80
+        name = "test-interface"
81
+        device = "test-device"
82
+        expected_cmd = ("interface %s create -type ethernet-dpdk-phy "
83
+                        "-device %s\n") % (name, device)
84
+        self.lagopus_client.create_pipe_interface(name, device)
85
+        self.lagosh.assert_called_with(expected_cmd)
86
+
87
+    def test_create_rawsock_interface(self):
88
+        name = "test-interface"
89
+        device = "test-device"
90
+        expected_cmd = ("interface %s create -type ethernet-rawsock "
91
+                        "-device %s\n") % (name, device)
92
+        self.lagopus_client.create_rawsock_interface(name, device)
93
+        self.lagosh.assert_called_with(expected_cmd)
94
+
95
+    def test_create_port(self):
96
+        port = "test-port"
97
+        interface = "test-interface"
98
+        expected_cmd = "port %s create -interface %s\n" % (port, interface)
99
+        self.lagopus_client.create_port(port, interface)
100
+        self.lagosh.assert_called_with(expected_cmd)
101
+
102
+    def test_destroy_port(self):
103
+        port = "test-port"
104
+        expected_cmd = "port %s destroy\n" % port
105
+        self.lagopus_client.destroy_port(port)
106
+        self.lagosh.assert_called_with(expected_cmd)
107
+
108
+    def test_destroy_interface(self):
109
+        interface = "test-interface"
110
+        expected_cmd = "interface %s destroy\n" % interface
111
+        self.lagopus_client.destroy_interface(interface)
112
+        self.lagosh.assert_called_with(expected_cmd)
113
+
114
+    def test_bridge_add_port(self):
115
+        bridge_name = "test-bridge"
116
+        port_name = "test-port"
117
+        ofport = 1
118
+        expected_cmd = ("bridge %s config -port %s %d\n" %
119
+                        (bridge_name, port_name, ofport))
120
+        self.lagopus_client.bridge_add_port(bridge_name,
121
+                                            port_name,
122
+                                            ofport)
123
+        self.lagosh.assert_called_with(expected_cmd)
124
+
125
+    def test_bridge_del_port(self):
126
+        bridge_name = "test-bridge"
127
+        port_name = "test-port"
128
+        expected_cmd = ("bridge %s config -port -%s\n" %
129
+                        (bridge_name, port_name))
130
+        self.lagopus_client.bridge_del_port(bridge_name,
131
+                                            port_name)
132
+        self.lagosh.assert_called_with(expected_cmd)

+ 2
- 0
tox.ini View File

@@ -13,6 +13,8 @@ setenv =
13 13
    OS_STDERR_CAPTURE=1
14 14
    OS_TEST_TIMEOUT=60
15 15
 deps = -r{toxinidir}/test-requirements.txt
16
+       -r{toxinidir}/requirements.txt
17
+       -egit+https://git.openstack.org/openstack/neutron.git#egg=neutron
16 18
 commands = stestr run {posargs}
17 19
 
18 20
 [testenv:pep8]

Loading…
Cancel
Save