Coverage for manila/tests/network/linux/test_ovs_lib.py: 100%

32 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2026-02-18 22:19 +0000

1# Copyright 2014 Mirantis Inc. 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); you may 

4# not use this file except in compliance with the License. You may obtain 

5# a copy of the License at 

6# 

7# http://www.apache.org/licenses/LICENSE-2.0 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 

11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 

12# License for the specific language governing permissions and limitations 

13# under the License. 

14 

15from unittest import mock 

16 

17from manila.network.linux import ovs_lib 

18from manila import test 

19 

20 

21class OVS_Lib_Test(test.TestCase): 

22 """A test suite to exercise the OVS libraries.""" 

23 

24 def setUp(self): 

25 super(OVS_Lib_Test, self).setUp() 

26 self.BR_NAME = "br-int" 

27 self.TO = "--timeout=2" 

28 

29 self.br = ovs_lib.OVSBridge(self.BR_NAME) 

30 self.execute_p = mock.patch('manila.utils.execute') 

31 self.execute = self.execute_p.start() 

32 

33 def tearDown(self): 

34 self.execute_p.stop() 

35 super(OVS_Lib_Test, self).tearDown() 

36 

37 def test_reset_bridge(self): 

38 self.br.reset_bridge() 

39 self.execute.assert_has_calls([mock.call("ovs-vsctl", self.TO, "--", 

40 "--if-exists", "del-br", 

41 self.BR_NAME, 

42 run_as_root=True), 

43 mock.call("ovs-vsctl", self.TO, 

44 "add-br", 

45 self.BR_NAME, 

46 run_as_root=True)]) 

47 

48 def test_delete_port(self): 

49 pname = "tap5" 

50 self.br.delete_port(pname) 

51 self.execute.assert_called_once_with("ovs-vsctl", self.TO, "--", 

52 "--if-exists", "del-port", 

53 self.BR_NAME, pname, 

54 run_as_root=True) 

55 

56 def test_port_id_regex(self): 

57 result = ('external_ids : {attached-mac="fa:16:3e:23:5b:f2",' 

58 ' iface-id="5c1321a7-c73f-4a77-95e6-9f86402e5c8f",' 

59 ' iface-status=active}\nname :' 

60 ' "dhc5c1321a7-c7"\nofport : 2\n') 

61 match = self.br.re_id.search(result) 

62 vif_mac = match.group('vif_mac') 

63 vif_id = match.group('vif_id') 

64 port_name = match.group('port_name') 

65 ofport = int(match.group('ofport')) 

66 self.assertEqual('fa:16:3e:23:5b:f2', vif_mac) 

67 self.assertEqual('5c1321a7-c73f-4a77-95e6-9f86402e5c8f', vif_id) 

68 self.assertEqual('dhc5c1321a7-c7', port_name) 

69 self.assertEqual(2, ofport)