def test_update_array_interface_ssh_pass(self): """Verify get_interface_settings gives the right static configuration response.""" initial = { "state": "enable", "controller": "A", "name": "wan0", "address": "192.168.1.1", "subnet_mask": "255.255.255.1", "config_method": "static", "ssh": True } iface = { "dns_servers": [{ "ipv4Address": "10.1.0.20", "addressType": "ipv4" }, { "ipv4Address": "10.1.0.50", "addressType": "ipv4" }], "subnet_mask": "255.255.255.0", "link_status": "up", "ntp_servers": None, "ntp_config_method": "disabled", "controllerRef": "070000000000000000000001", "config_method": "configStatic", "enabled": True, "gateway": "10.1.1.1", "alias": "creG1g-AP-a", "controllerSlot": 1, "dns_config_method": "stat", "id": "2800070000000000000000000001000000000000", "address": "10.1.1.111", "ipv6Enabled": False, "channel": 1 } settings = {"controllerRef": "070000000000000000000001", "ssh": False} self._set_args(initial) mgmt_interface = MgmtInterface() with mock.patch(self.REQ_FUNC, return_value=(200, None)): update = mgmt_interface.update_array(settings, iface) self.assertTrue(update)
def test_get_enable_interface_settings_disabled_pass(self): """Validate get_enable_interface_settings updates properly.""" initial = { "state": "disable", "controller": "A", "name": "wan0", "address": "192.168.1.1", "subnet_mask": "255.255.255.1", "config_method": "static" } iface = {"enabled": True} expected_iface = {} self._set_args(initial) mgmt_interface = MgmtInterface() update, expected_iface, body = mgmt_interface.get_enable_interface_settings( iface, expected_iface, False, {}) self.assertTrue(update and not expected_iface["enabled"] and not body["ipv4Enabled"])
def test_controller_property_fail(self): """Verify controllers endpoint request failure causes AnsibleFailJson exception.""" initial = { "state": "enable", "controller": "A", "channel": "1", "address": "192.168.1.1", "subnet_mask": "255.255.255.1", "config_method": "static" } controller_request = [{ "physicalLocation": { "slot": 2 }, "controllerRef": "070000000000000000000002", "networkSettings": { "remoteAccessEnabled": True } }, { "physicalLocation": { "slot": 1 }, "controllerRef": "070000000000000000000001", "networkSettings": { "remoteAccessEnabled": False } }] expected = { 'A': { 'controllerRef': '070000000000000000000001', 'controllerSlot': 1, 'ssh': False }, 'B': { 'controllerRef': '070000000000000000000002', 'controllerSlot': 2, 'ssh': True } } self._set_args(initial) mgmt_interface = MgmtInterface() with self.assertRaisesRegexp( AnsibleFailJson, r"Failed to retrieve the controller settings."): with mock.patch(self.REQ_FUNC, return_value=Exception): response = mgmt_interface.controllers
def test_controller_property_pass(self): """Verify dictionary return from controller property.""" initial = { "state": "enable", "controller": "A", "channel": "1", "address": "192.168.1.1", "subnet_mask": "255.255.255.1", "config_method": "static" } controller_request = [{ "physicalLocation": { "slot": 2 }, "controllerRef": "070000000000000000000002", "networkSettings": { "remoteAccessEnabled": True } }, { "physicalLocation": { "slot": 1 }, "controllerRef": "070000000000000000000001", "networkSettings": { "remoteAccessEnabled": False } }] expected = { 'A': { 'controllerRef': '070000000000000000000001', 'controllerSlot': 1, 'ssh': False }, 'B': { 'controllerRef': '070000000000000000000002', 'controllerSlot': 2, 'ssh': True } } self._set_args(initial) mgmt_interface = MgmtInterface() with mock.patch(self.REQ_FUNC, return_value=(200, controller_request)): response = mgmt_interface.controllers self.assertTrue(response == expected)
def test_interface_property_request_exception_fail(self): """Verify ethernet-interfaces endpoint request failure results in AnsibleFailJson exception.""" initial = { "state": "enable", "controller": "A", "channel": "1", "address": "192.168.1.1", "subnet_mask": "255.255.255.1", "config_method": "static" } controller_request = [{ "physicalLocation": { "slot": 2 }, "controllerRef": "070000000000000000000002", "networkSettings": { "remoteAccessEnabled": True } }, { "physicalLocation": { "slot": 1 }, "controllerRef": "070000000000000000000001", "networkSettings": { "remoteAccessEnabled": False } }] self._set_args(initial) mgmt_interface = MgmtInterface() with self.assertRaisesRegexp( AnsibleFailJson, r"Failed to retrieve defined management interfaces."): with mock.patch(self.REQ_FUNC, side_effect=[Exception, (200, controller_request)]): iface = mgmt_interface.interface
def test_update_pass(self): """Validate update method completes.""" initial = { "state": "enable", "controller": "A", "channel": "1", "address": "192.168.1.1", "subnet_mask": "255.255.255.1", "config_method": "static", "ssh": "yes" } controller_request = [{ "physicalLocation": { "slot": 2 }, "controllerRef": "070000000000000000000002", "networkSettings": { "remoteAccessEnabled": True } }, { "physicalLocation": { "slot": 1 }, "controllerRef": "070000000000000000000001", "networkSettings": { "remoteAccessEnabled": False } }] expected = { "dns_servers": [{ "ipv4Address": "10.1.0.20", "addressType": "ipv4" }, { "ipv4Address": "10.1.0.50", "addressType": "ipv4" }], "subnet_mask": "255.255.255.0", "ntp_servers": None, "ntp_config_method": "disabled", "controllerRef": "070000000000000000000001", "config_method": "configStatic", "enabled": True, "gateway": "10.1.1.1", "alias": "creG1g-AP-a", "controllerSlot": 1, "dns_config_method": "stat", "id": "2800070000000000000000000001000000000000", "address": "10.1.1.111", "ipv6Enabled": False, "channel": 1 } self._set_args(initial) mgmt_interface = MgmtInterface() with self.assertRaisesRegexp( AnsibleExitJson, r"The interface settings have been updated."): with mock.patch(self.REQ_FUNC, side_effect=[(200, None), (200, controller_request), (200, self.TEST_DATA), (200, controller_request), (200, self.TEST_DATA)]): mgmt_interface.update()
def test_update_array_request_error_fail(self): """Verify exception is thrown when request results in an error.""" initial = { "state": "disable", "controller": "A", "name": "wan0", "address": "192.168.1.1", "subnet_mask": "255.255.255.1", "config_method": "static", "ssh": True } iface = { "dns_servers": [{ "ipv4Address": "10.1.0.20", "addressType": "ipv4" }, { "ipv4Address": "10.1.0.50", "addressType": "ipv4" }], "subnet_mask": "255.255.255.0", "ntp_servers": None, "ntp_config_method": "disabled", "controllerRef": "070000000000000000000001", "config_method": "configStatic", "enabled": True, "gateway": "10.1.1.1", "alias": "creG1g-AP-a", "controllerSlot": 1, "dns_config_method": "stat", "id": "2800070000000000000000000001000000000000", "address": "10.1.1.111", "ipv6Enabled": False, "channel": 1 } settings = {"controllerRef": "070000000000000000000001", "ssh": False} self._set_args(initial) mgmt_interface = MgmtInterface() with self.assertRaisesRegexp( AnsibleFailJson, r"We failed to configure the management interface."): with mock.patch(self.REQ_FUNC, return_value=(300, dict(ipv4Enabled=False, retcode="4", errorMessage=""))): mgmt_interface.update_array(settings, iface)
def test_update_array_ipv4_ipv6_disabled_fail(self): """Verify exception is thrown when both ipv4 and ipv6 would be disabled at the same time.""" initial = { "state": "disable", "controller": "A", "name": "wan0", "address": "192.168.1.1", "subnet_mask": "255.255.255.1", "config_method": "static", "ssh": True } iface = { "dns_servers": [{ "ipv4Address": "10.1.0.20", "addressType": "ipv4" }, { "ipv4Address": "10.1.0.50", "addressType": "ipv4" }], "subnet_mask": "255.255.255.0", "ntp_servers": None, "ntp_config_method": "disabled", "controllerRef": "070000000000000000000001", "config_method": "configStatic", "enabled": True, "gateway": "10.1.1.1", "alias": "creG1g-AP-a", "controllerSlot": 1, "dns_config_method": "stat", "id": "2800070000000000000000000001000000000000", "address": "10.1.1.11", "ipv6Enabled": False, "channel": 1 } settings = {"controllerRef": "070000000000000000000001", "ssh": False} self._set_args(initial) mgmt_interface = MgmtInterface() with self.assertRaisesRegexp( AnsibleFailJson, r"This storage-system already has IPv6 connectivity disabled." ): with mock.patch(self.REQ_FUNC, return_value=(422, dict(ipv4Enabled=False, retcode="4", errorMessage=""))): mgmt_interface.update_array(settings, iface)
def test_interface_property_no_match_fail(self): """Verify return value from interface property.""" initial = { "state": "enable", "controller": "A", "name": "wrong_name", "address": "192.168.1.1", "subnet_mask": "255.255.255.1", "config_method": "static" } controller_request = [{ "physicalLocation": { "slot": 2 }, "controllerRef": "070000000000000000000002", "networkSettings": { "remoteAccessEnabled": True } }, { "physicalLocation": { "slot": 1 }, "controllerRef": "070000000000000000000001", "networkSettings": { "remoteAccessEnabled": False } }] expected = { "dns_servers": [{ "ipv4Address": "10.1.0.20", "addressType": "ipv4" }, { "ipv4Address": "10.1.0.50", "addressType": "ipv4" }], "subnet_mask": "255.255.255.0", "ntp_servers": None, "ntp_config_method": "disabled", "controllerRef": "070000000000000000000001", "config_method": "configStatic", "enabled": True, "gateway": "10.1.1.1", "alias": "creG1g-AP-a", "controllerSlot": 1, "dns_config_method": "stat", "id": "2800070000000000000000000001000000000000", "address": "10.1.1.111", "ipv6Enabled": False, "channel": 1 } self._set_args(initial) mgmt_interface = MgmtInterface() with self.assertRaisesRegexp( AnsibleFailJson, r"We could not find an interface matching"): with mock.patch(self.REQ_FUNC, side_effect=[(200, self.TEST_DATA), (200, controller_request)]): iface = mgmt_interface.interface