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
=== modified file 'charmhelpers/core/host.py'
--- charmhelpers/core/host.py 2013-11-14 10:37:18 +0000
+++ charmhelpers/core/host.py 2013-11-29 11:25:06 +0000
@@ -279,3 +279,13 @@
279 if 'mtu' in words:279 if 'mtu' in words:
280 mtu = words[words.index("mtu") + 1]280 mtu = words[words.index("mtu") + 1]
281 return mtu281 return mtu
282
283
284def get_nic_hwaddr(nic):
285 cmd = ['ip', '-o', '-0', 'addr', 'show', nic]
286 ip_output = subprocess.check_output(cmd)
287 hwaddr = ""
288 words = ip_output.split()
289 if 'link/ether' in words:
290 hwaddr = words[words.index('link/ether') + 1]
291 return hwaddr
282292
=== modified file 'tests/contrib/charmsupport/test_nrpe.py'
--- tests/contrib/charmsupport/test_nrpe.py 2013-06-19 15:18:16 +0000
+++ tests/contrib/charmsupport/test_nrpe.py 2013-11-29 11:25:06 +0000
@@ -126,7 +126,7 @@
126"""126"""
127 expected = [127 expected = [
128 '# check myservice\n',128 '# check myservice\n',
129 'command[check_myservice]=/check_http http://localhost\n',129 'command[check_myservice]=/usr/lib/nagios/plugins/check_http http://localhost\n',
130 service_file_contents,130 service_file_contents,
131 ]131 ]
132 actual = [x[0][0] for x in outfile.write.call_args_list]132 actual = [x[0][0] for x in outfile.write.call_args_list]
@@ -199,15 +199,14 @@
199 check = nrpe.Check('shortname', 'description', 'check_http -x -y -z')199 check = nrpe.Check('shortname', 'description', 'check_http -x -y -z')
200200
201 self.assertEqual('', check.check_cmd)201 self.assertEqual('', check.check_cmd)
202 self.assertEqual(3, self.patched['exists'].call_count)202 self.assertEqual(2, self.patched['exists'].call_count)
203 expected = [203 expected = [
204 '/check_http',
205 '/usr/lib/test_charm_dir/files/nrpe-external-master/check_http',
206 '/usr/lib/nagios/plugins/check_http',204 '/usr/lib/nagios/plugins/check_http',
205 '/usr/local/lib/nagios/plugins/check_http',
207 ]206 ]
208 actual = [x[0][0] for x in self.patched['exists'].call_args_list]207 actual = [x[0][0] for x in self.patched['exists'].call_args_list]
209 self.assertEqual(expected, actual)208 self.assertEqual(expected, actual)
210 self.check_call_counts(exists=3, log=1)209 self.check_call_counts(exists=2, log=1)
211 expected = 'Check command not found: check_http'210 expected = 'Check command not found: check_http'
212 self.assertEqual(expected, self.patched['log'].call_args[0][0])211 self.assertEqual(expected, self.patched['log'].call_args[0][0])
213212
214213
=== modified file 'tests/core/test_host.py'
--- tests/core/test_host.py 2013-11-14 10:37:18 +0000
+++ tests/core/test_host.py 2013-11-29 11:25:06 +0000
@@ -34,6 +34,8 @@
34 link/ether e4:11:5b:ab:a7:3c brd ff:ff:ff:ff:ff:ff34 link/ether e4:11:5b:ab:a7:3c brd ff:ff:ff:ff:ff:ff
35""")35""")
3636
37IP_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""")
38
37IP_LINES = IP_LINE_ETH0 + IP_LINE_ETH139IP_LINES = IP_LINE_ETH0 + IP_LINE_ETH1
3840
3941
@@ -681,3 +683,10 @@
681 nic = "eth0"683 nic = "eth0"
682 mtu = host.get_nic_mtu(nic)684 mtu = host.get_nic_mtu(nic)
683 self.assertEqual(mtu, '1500')685 self.assertEqual(mtu, '1500')
686
687 @patch('subprocess.check_output')
688 def test_get_nic_hwaddr(self, check_output):
689 check_output.return_value = IP_LINE_HWADDR
690 nic = "eth0"
691 hwaddr = host.get_nic_hwaddr(nic)
692 self.assertEqual(hwaddr, 'e4:11:5b:ab:a7:3c')

Subscribers

People subscribed via source and target branches