Merge lp:~gz/juju-ci-tools/maas_substrate_interfaces into lp:juju-ci-tools

Proposed by Martin Packman
Status: Merged
Approved by: Martin Packman
Approved revision: 1616
Merged at revision: 1620
Proposed branch: lp:~gz/juju-ci-tools/maas_substrate_interfaces
Merge into: lp:juju-ci-tools
Prerequisite: lp:~gz/juju-ci-tools/maas_substrate_vlans
Diff against target: 72 lines (+52/-0)
2 files modified
substrate.py (+18/-0)
tests/test_substrate.py (+34/-0)
To merge this branch: bzr merge lp:~gz/juju-ci-tools/maas_substrate_interfaces
Reviewer Review Type Date Requested Status
Aaron Bentley (community) Needs Fixing
Review via email: mp+306885@code.launchpad.net

Description of the change

Add interfaces management methods to maas substrate

Just the subset of commands we need at present, interfaces can apply to more than just machines but we only care about the machine/vlan case at present.

To post a comment you must log in.
Revision history for this message
Aaron Bentley (abentley) wrote :

The interfaces method needs slightly more testing.

review: Needs Fixing
Revision history for this message
Martin Packman (gz) wrote :

Replied to comments, not making more changes at this point in the chain but suggestions will be done later.

Revision history for this message
Aaron Bentley (abentley) :
review: Needs Fixing

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'substrate.py'
2--- substrate.py 2016-09-27 14:01:01 +0000
3+++ substrate.py 2016-09-27 14:01:01 +0000
4@@ -529,6 +529,24 @@
5 return self._maas(
6 self.profile, 'vlan', 'delete', str(fabric_id), str(vid))
7
8+ def interfaces(self, system_id):
9+ """Return list of interfaces belonging to node with given system_id."""
10+ return self._maas(self.profile, 'interfaces', 'read', system_id)
11+
12+ def interface_create_vlan(self, system_id, parent, vlan_id):
13+ """Create a vlan interface on machine with given system_id."""
14+ args = [
15+ self.profile, 'interfaces', 'create-vlan', system_id,
16+ 'parent=' + str(parent), 'vlan=' + str(vlan_id),
17+ ]
18+ # TODO(gz): Add support for optional parameters as needed.
19+ return self._maas(*args)
20+
21+ def delete_interface(self, system_id, interface_id):
22+ """Delete interface on node with given system_id with interface_id."""
23+ return self._maas(
24+ self.profile, 'interface', 'delete', system_id, str(interface_id))
25+
26
27 class MAAS1Account(MAASAccount):
28 """Represent a MAAS 1.X account."""
29
30=== modified file 'tests/test_substrate.py'
31--- tests/test_substrate.py 2016-09-27 14:01:01 +0000
32+++ tests/test_substrate.py 2016-09-27 14:01:01 +0000
33@@ -947,6 +947,40 @@
34 ('maas', 'mas', 'vlan', 'delete', '0', '4096'))
35 self.assertEqual(None, result)
36
37+ def test_interfaces(self):
38+ config = get_maas_env().config
39+ account = MAASAccount(
40+ config['name'], config['maas-server'], config['maas-oauth'])
41+ with patch('subprocess.check_output', autospec=True,
42+ return_value='[]') as co_mock:
43+ interfaces = account.interfaces('node-xyz')
44+ co_mock.assert_called_once_with((
45+ 'maas', 'mas', 'interfaces', 'read', 'node-xyz'))
46+ self.assertEqual([], interfaces)
47+
48+ def test_interface_create_vlan(self):
49+ config = get_maas_env().config
50+ account = MAASAccount(
51+ config['name'], config['maas-server'], config['maas-oauth'])
52+ with patch('subprocess.check_output', autospec=True,
53+ return_value='{"id": 10}') as co_mock:
54+ interface = account.interface_create_vlan('node-xyz', 1, 5000)
55+ co_mock.assert_called_once_with((
56+ 'maas', 'mas', 'interfaces', 'create-vlan', 'node-xyz', 'parent=1',
57+ 'vlan=5000'))
58+ self.assertEqual({'id': 10}, interface)
59+
60+ def test_delete_interface(self):
61+ config = get_maas_env().config
62+ account = MAASAccount(
63+ config['name'], config['maas-server'], config['maas-oauth'])
64+ with patch('subprocess.check_output', autospec=True,
65+ return_value='') as co_mock:
66+ result = account.delete_interface('node-xyz', 10)
67+ co_mock.assert_called_once_with(
68+ ('maas', 'mas', 'interface', 'delete', 'node-xyz', '10'))
69+ self.assertEqual(None, result)
70+
71
72 class TestMAAS1Account(TestCase):
73

Subscribers

People subscribed via source and target branches