def test_determine_cluster_interfaces_catches_non_OK_response(self): self.patch(MAASClient, 'get').return_value = MockResponse(httplib.NOT_FOUND, "error text") mocked_logging = self.patch(detect_module.logger, 'error') determine_cluster_interfaces(self.knowledge) mocked_logging.assert_called_once()
def test_determine_cluster_interfaces_catchs_HTTPError_in_MASClient(self): self.patch(MAASClient, 'get').side_effect = urllib2.HTTPError( mock.sentinel, mock.sentinel, mock.sentinel, mock.sentinel, mock.sentinel) mocked_logging = self.patch(detect_module.logger, 'error') determine_cluster_interfaces(self.knowledge) mocked_logging.assert_called_once()
def test_probe_interface_returns_empty_set_when_nothing_detected(self): eth0_addr = factory.getRandomIPAddress() self.patch_fake_interfaces_list([("eth0", eth0_addr)]) self.patch(detect_module, 'probe_dhcp').return_value = set() interfaces = determine_cluster_interfaces(self.knowledge) results = probe_interface(*interfaces[0]) self.assertEqual(set(), results)
def test_determine_cluster_interfaces_returns_interface_names(self): eth0_addr = factory.getRandomIPAddress() wlan0_addr = factory.getRandomIPAddress() self.patch_fake_interfaces_list([("eth0", eth0_addr), ("wlan0", wlan0_addr)]) self.assertEqual([("eth0", eth0_addr), ("wlan0", wlan0_addr)], determine_cluster_interfaces(self.knowledge))
def test_probe_interface_returns_populated_set(self): # Test that the detected DHCP server is returned. eth0_addr = factory.getRandomIPAddress() self.patch_fake_interfaces_list([("eth0", eth0_addr)]) self.patch(detect_module, 'probe_dhcp').return_value = {'10.2.2.2'} interfaces = determine_cluster_interfaces(self.knowledge) results = probe_interface(*interfaces[0]) self.assertEqual({'10.2.2.2'}, results)
def test_probe_interface_filters_interface_own_ip(self): # Test that the interface shows the detected DHCP server except # if it is the same IP as the interface's. eth0_addr = factory.getRandomIPAddress() self.patch_fake_interfaces_list([("eth0", eth0_addr)]) detected_dhcp = eth0_addr self.patch(detect_module, 'probe_dhcp').return_value = {detected_dhcp} interfaces = determine_cluster_interfaces(self.knowledge) results = probe_interface(*interfaces[0]) self.assertEqual(set(), results)