Merge lp:~gnuoy/charm-helpers/get-hwaddr into lp:charm-helpers

Proposed by Liam Young
Status: Merged
Approved by: Gareth Woolridge
Approved revision: 106
Merged at revision: 104
Proposed branch: lp:~gnuoy/charm-helpers/get-hwaddr
Merge into: lp:charm-helpers
Diff against target: 73 lines (+23/-5)
3 files modified
charmhelpers/core/host.py (+10/-0)
tests/contrib/charmsupport/test_nrpe.py (+4/-5)
tests/core/test_host.py (+9/-0)
To merge this branch: bzr merge lp:~gnuoy/charm-helpers/get-hwaddr
Reviewer Review Type Date Requested Status
Gareth Woolridge Approve
Review via email: mp+197172@code.launchpad.net

Description of the change

* Fix to tests broken by previous nrpe update
* Function with test to get the hardware address for a given nic

To post a comment you must log in.
lp:~gnuoy/charm-helpers/get-hwaddr updated
106. By Liam Young

Fix copy/pasta error in test_get_nic_hwaddr (s/mtu/hwaddr)

Revision history for this message
Gareth Woolridge (moon127) wrote :

Looks good to me with the update to the test as discussed.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/core/host.py'
2--- charmhelpers/core/host.py 2013-11-14 10:37:18 +0000
3+++ charmhelpers/core/host.py 2013-11-29 11:25:06 +0000
4@@ -279,3 +279,13 @@
5 if 'mtu' in words:
6 mtu = words[words.index("mtu") + 1]
7 return mtu
8+
9+
10+def get_nic_hwaddr(nic):
11+ cmd = ['ip', '-o', '-0', 'addr', 'show', nic]
12+ ip_output = subprocess.check_output(cmd)
13+ hwaddr = ""
14+ words = ip_output.split()
15+ if 'link/ether' in words:
16+ hwaddr = words[words.index('link/ether') + 1]
17+ return hwaddr
18
19=== modified file 'tests/contrib/charmsupport/test_nrpe.py'
20--- tests/contrib/charmsupport/test_nrpe.py 2013-06-19 15:18:16 +0000
21+++ tests/contrib/charmsupport/test_nrpe.py 2013-11-29 11:25:06 +0000
22@@ -126,7 +126,7 @@
23 """
24 expected = [
25 '# check myservice\n',
26- 'command[check_myservice]=/check_http http://localhost\n',
27+ 'command[check_myservice]=/usr/lib/nagios/plugins/check_http http://localhost\n',
28 service_file_contents,
29 ]
30 actual = [x[0][0] for x in outfile.write.call_args_list]
31@@ -199,15 +199,14 @@
32 check = nrpe.Check('shortname', 'description', 'check_http -x -y -z')
33
34 self.assertEqual('', check.check_cmd)
35- self.assertEqual(3, self.patched['exists'].call_count)
36+ self.assertEqual(2, self.patched['exists'].call_count)
37 expected = [
38- '/check_http',
39- '/usr/lib/test_charm_dir/files/nrpe-external-master/check_http',
40 '/usr/lib/nagios/plugins/check_http',
41+ '/usr/local/lib/nagios/plugins/check_http',
42 ]
43 actual = [x[0][0] for x in self.patched['exists'].call_args_list]
44 self.assertEqual(expected, actual)
45- self.check_call_counts(exists=3, log=1)
46+ self.check_call_counts(exists=2, log=1)
47 expected = 'Check command not found: check_http'
48 self.assertEqual(expected, self.patched['log'].call_args[0][0])
49
50
51=== modified file 'tests/core/test_host.py'
52--- tests/core/test_host.py 2013-11-14 10:37:18 +0000
53+++ tests/core/test_host.py 2013-11-29 11:25:06 +0000
54@@ -34,6 +34,8 @@
55 link/ether e4:11:5b:ab:a7:3c brd ff:ff:ff:ff:ff:ff
56 """)
57
58+IP_LINE_HWADDR = ("""2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000\ link/ether e4:11:5b:ab:a7:3c brd ff:ff:ff:ff:ff:ff""")
59+
60 IP_LINES = IP_LINE_ETH0 + IP_LINE_ETH1
61
62
63@@ -681,3 +683,10 @@
64 nic = "eth0"
65 mtu = host.get_nic_mtu(nic)
66 self.assertEqual(mtu, '1500')
67+
68+ @patch('subprocess.check_output')
69+ def test_get_nic_hwaddr(self, check_output):
70+ check_output.return_value = IP_LINE_HWADDR
71+ nic = "eth0"
72+ hwaddr = host.get_nic_hwaddr(nic)
73+ self.assertEqual(hwaddr, 'e4:11:5b:ab:a7:3c')

Subscribers

People subscribed via source and target branches