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
=== modified file 'substrate.py'
--- substrate.py 2016-09-27 14:01:01 +0000
+++ substrate.py 2016-09-27 14:01:01 +0000
@@ -529,6 +529,24 @@
529 return self._maas(529 return self._maas(
530 self.profile, 'vlan', 'delete', str(fabric_id), str(vid))530 self.profile, 'vlan', 'delete', str(fabric_id), str(vid))
531531
532 def interfaces(self, system_id):
533 """Return list of interfaces belonging to node with given system_id."""
534 return self._maas(self.profile, 'interfaces', 'read', system_id)
535
536 def interface_create_vlan(self, system_id, parent, vlan_id):
537 """Create a vlan interface on machine with given system_id."""
538 args = [
539 self.profile, 'interfaces', 'create-vlan', system_id,
540 'parent=' + str(parent), 'vlan=' + str(vlan_id),
541 ]
542 # TODO(gz): Add support for optional parameters as needed.
543 return self._maas(*args)
544
545 def delete_interface(self, system_id, interface_id):
546 """Delete interface on node with given system_id with interface_id."""
547 return self._maas(
548 self.profile, 'interface', 'delete', system_id, str(interface_id))
549
532550
533class MAAS1Account(MAASAccount):551class MAAS1Account(MAASAccount):
534 """Represent a MAAS 1.X account."""552 """Represent a MAAS 1.X account."""
535553
=== modified file 'tests/test_substrate.py'
--- tests/test_substrate.py 2016-09-27 14:01:01 +0000
+++ tests/test_substrate.py 2016-09-27 14:01:01 +0000
@@ -947,6 +947,40 @@
947 ('maas', 'mas', 'vlan', 'delete', '0', '4096'))947 ('maas', 'mas', 'vlan', 'delete', '0', '4096'))
948 self.assertEqual(None, result)948 self.assertEqual(None, result)
949949
950 def test_interfaces(self):
951 config = get_maas_env().config
952 account = MAASAccount(
953 config['name'], config['maas-server'], config['maas-oauth'])
954 with patch('subprocess.check_output', autospec=True,
955 return_value='[]') as co_mock:
956 interfaces = account.interfaces('node-xyz')
957 co_mock.assert_called_once_with((
958 'maas', 'mas', 'interfaces', 'read', 'node-xyz'))
959 self.assertEqual([], interfaces)
960
961 def test_interface_create_vlan(self):
962 config = get_maas_env().config
963 account = MAASAccount(
964 config['name'], config['maas-server'], config['maas-oauth'])
965 with patch('subprocess.check_output', autospec=True,
966 return_value='{"id": 10}') as co_mock:
967 interface = account.interface_create_vlan('node-xyz', 1, 5000)
968 co_mock.assert_called_once_with((
969 'maas', 'mas', 'interfaces', 'create-vlan', 'node-xyz', 'parent=1',
970 'vlan=5000'))
971 self.assertEqual({'id': 10}, interface)
972
973 def test_delete_interface(self):
974 config = get_maas_env().config
975 account = MAASAccount(
976 config['name'], config['maas-server'], config['maas-oauth'])
977 with patch('subprocess.check_output', autospec=True,
978 return_value='') as co_mock:
979 result = account.delete_interface('node-xyz', 10)
980 co_mock.assert_called_once_with(
981 ('maas', 'mas', 'interface', 'delete', 'node-xyz', '10'))
982 self.assertEqual(None, result)
983
950984
951class TestMAAS1Account(TestCase):985class TestMAAS1Account(TestCase):
952986

Subscribers

People subscribed via source and target branches