def test_option_245_not_found_returns_None(self): """A valid lease, but no option 245 should return None.""" populate_dir( self.lease_d, {'9': self.azure_lease.replace("OPTION_245", "OPTION_999")}) self.assertIsNone(wa_shim._networkd_get_value_from_leases( self.lease_d))
def test_missing_special_azure_line(self): """wa_shim find_endpoint uses default endpoint if leasefile is found but does not contain DHCP Option 245 (whose value is the endpoint) """ self.load_file.return_value = '' self.dhcp_options.return_value = {'eth0': {'key': 'value'}} self.assertEqual(wa_shim.find_endpoint(), "168.63.129.16")
def test_latest_lease_used(self): encoded_addresses = ['5:4:3:2', '4:3:2:1'] file_content = '\n'.join([self._build_lease_content(encoded_address) for encoded_address in encoded_addresses]) self.load_file.return_value = file_content self.assertEqual(encoded_addresses[-1].replace(':', '.'), wa_shim.find_endpoint("foobar"))
def test_option_245_not_found_returns_None(self): """A valid lease, but no option 245 should return None.""" populate_dir( self.lease_d, {'9': self.azure_lease.replace("OPTION_245", "OPTION_999")}) self.assertIsNone( wa_shim._networkd_get_value_from_leases(self.lease_d))
def test_latest_lease_used(self, m_is_freebsd): m_is_freebsd.return_value = False # To avoid hitting load_file encoded_addresses = ['5:4:3:2', '4:3:2:1'] file_content = '\n'.join([self._build_lease_content(encoded_address) for encoded_address in encoded_addresses]) self.load_file.return_value = file_content self.assertEqual(encoded_addresses[-1].replace(':', '.'), wa_shim.find_endpoint("foobar"))
def test_multiple_returns_first(self): """Somewhat arbitrarily return the first address when multiple. Most important at the moment is that this is consistent behavior rather than changing randomly as in order of a dictionary.""" myval = "624c3601" populate_dir( self.lease_d, {'9': self.azure_lease, '2': self.azure_lease.replace("624c3620", myval)}) self.assertEqual( myval, wa_shim._networkd_get_value_from_leases(self.lease_d))
def test_option_245_is_found_in_single(self): """A single valid lease with 245 option should return it.""" populate_dir(self.lease_d, {'9': self.azure_lease}) self.assertEqual('624c3620', wa_shim._networkd_get_value_from_leases(self.lease_d))
def test_no_valid_leases_is_none(self): """No valid leases should return None.""" self.assertIsNone(wa_shim._networkd_get_value_from_leases( self.lease_d))
def test_packed_string_containing_a_colon(self): ip_address, encoded_address = '100.72.58.108', 'dH:l' self.assertEqual(ip_address, wa_shim.get_ip_from_lease_value(encoded_address))
def test_packed_string_with_escaped_quote(self): ip_address, encoded_address = '100.72.34.108', 'dH\\"l' self.assertEqual(ip_address, wa_shim.get_ip_from_lease_value(encoded_address))
def test_packed_string(self): ip_address, encoded_address = '98.76.54.32', 'bL6 ' self.assertEqual(ip_address, wa_shim.get_ip_from_lease_value(encoded_address))
def test_hex_string_with_single_character_part(self): ip_address, encoded_address = '4.3.2.1', '4:3:2:1' self.assertEqual(ip_address, wa_shim.get_ip_from_lease_value(encoded_address))
def test_hex_string(self): ip_address, encoded_address = '98.76.54.32', '62:4c:36:20' self.assertEqual(ip_address, wa_shim.get_ip_from_lease_value(encoded_address))
def test_hex_string_with_single_character_part(self): ip_address, encoded_address = '4.3.2.1', '4:3:2:1' self.assertEqual( ip_address, wa_shim.get_ip_from_lease_value(encoded_address))
def test_hex_string(self): ip_address, encoded_address = '98.76.54.32', '62:4c:36:20' self.assertEqual( ip_address, wa_shim.get_ip_from_lease_value(encoded_address))
def test_packed_string(self): ip_address, encoded_address = '98.76.54.32', 'bL6 ' self.assertEqual( ip_address, wa_shim.get_ip_from_lease_value(encoded_address))
def test_packed_string_with_escaped_quote(self): ip_address, encoded_address = '100.72.34.108', 'dH\\"l' self.assertEqual( ip_address, wa_shim.get_ip_from_lease_value(encoded_address))
def test_option_245_is_found_in_single(self): """A single valid lease with 245 option should return it.""" populate_dir(self.lease_d, {'9': self.azure_lease}) self.assertEqual( '624c3620', wa_shim._networkd_get_value_from_leases(self.lease_d))
def test_no_valid_leases_is_none(self): """No valid leases should return None.""" self.assertIsNone( wa_shim._networkd_get_value_from_leases(self.lease_d))
def test_packed_string_containing_a_colon(self): ip_address, encoded_address = '100.72.58.108', 'dH:l' self.assertEqual( ip_address, wa_shim.get_ip_from_lease_value(encoded_address))
def test_missing_file(self): """wa_shim find_endpoint uses default endpoint if leasefile not found """ self.assertEqual(wa_shim.find_endpoint(), "168.63.129.16")
def test_from_dhcp_client(self): self.dhcp_options.return_value = {"eth0": {"unknown_245": "5:4:3:2"}} self.assertEqual('5.4.3.2', wa_shim.find_endpoint(None))